Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for Linux-native studiomdl #85

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions addon/types/model_export/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,25 @@
from pathlib import Path
from traceback import print_exc
from ... utils import common
from ... utils import game
from . smd import SMD
from . fbx import export_fbx


class Model:
def __init__(self, game, model):
def __init__(self, gamedef, model):
self.prefs = common.get_prefs(bpy.context)
self.wine = Path(self.prefs.wine)

self.game = Path(game.game)
self.bin = Path(game.bin)
self.game = Path(gamedef.game)
self.bin = Path(gamedef.bin)
if model.static and model.static_prop_combine:
self.modelsrc = self.game.parent.parent.joinpath('content', self.game.name, 'models')
else:
self.modelsrc = Path(game.modelsrc)
self.models = Path(game.models)
self.mapsrc = Path(game.mapsrc)
self.mesh_type = game.mesh_type
self.modelsrc = Path(gamedef.modelsrc)
self.models = Path(gamedef.models)
self.mapsrc = Path(gamedef.mapsrc)
self.mesh_type = gamedef.mesh_type

self.name = Path(model.name).with_suffix('').as_posix()
self.stem = common.clean_filename(Path(self.name).stem)
Expand All @@ -34,7 +35,7 @@ def __init__(self, game, model):
directory = self.modelsrc.joinpath(self.name)
self.directory = common.verify_folder(directory)

studiomdl = self.bin.joinpath('studiomdl.exe')
studiomdl = game.get_studiomdl_path(gamedef)
quickmdl = self.bin.joinpath('quickmdl.exe')
self.studiomdl = quickmdl if quickmdl.is_file() else studiomdl
self.hlmv = self.bin.joinpath('hlmv.exe')
Expand Down Expand Up @@ -362,7 +363,7 @@ def view_model(self):
# Use wine to run HLMV on Linux.
# Wine tends to complain about the paths we feed HLMV.
# So we use relatve paths working from the base directory of the game.
if (os.name == 'posix') and (self.studiomdl.suffix == '.exe'):
if (os.name == 'posix') and (self.hlmv.suffix == '.exe'):
bonjorno7 marked this conversation as resolved.
Show resolved Hide resolved
cwd = self.game.parent
args = [str(self.wine), str(self.hlmv.relative_to(cwd)), '-game',
str(self.game.relative_to(cwd)), str(mdl.relative_to(cwd))]
Expand Down
37 changes: 29 additions & 8 deletions addon/utils/game.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
import os
from pathlib import Path
from ..utils.common import resolve


def update_game(self, context):
self['game'] = resolve(self.game)
game = Path(self.game)

if game.joinpath('gameinfo.txt').is_file():
bin = game.parent.joinpath('bin')

if not bin.joinpath('studiomdl.exe').is_file():
for path in bin.iterdir():
if path.is_dir() and path.joinpath('studiomdl.exe').is_file():
bin = path
break
# If we're not on the old-style pattern bin/<something> layout, check for platform subdirs
actualbin = None
if not bin.joinpath('studiomdl.exe').is_file() and not bin.joinpath('studiomdl').is_file():
def check_subdir(subdirs, studiomdl):
for subdir in subdirs:
path = bin.joinpath(subdir)
if path.is_dir() and path.joinpath(studiomdl).is_file():
return path
return None

# For linux, prefer the native binaries (if possible)
if os.name == 'posix':
actualbin = check_subdir(['linux32', 'linux64'], 'studiomdl')
# Resolve windows paths
if actualbin is None:
actualbin = check_subdir(['win32', 'win64'], 'studiomdl.exe')

if actualbin is not None:
bin = actualbin

self['bin'] = str(bin)
self['modelsrc'] = str(game.joinpath('modelsrc'))
Expand All @@ -39,5 +53,12 @@ def update_mapsrc(self, context):

def verify(game):
gameinfo = Path(game.game).joinpath('gameinfo.txt')
studiomdl = Path(game.bin).joinpath('studiomdl.exe')
return gameinfo.is_file() and studiomdl.is_file()
return gameinfo.is_file() and get_studiomdl_path(game).is_file()

def get_studiomdl_path(game):
if os.name == 'posix' and (game.bin.endswith('linux32') or game.bin.endswith('linux64')):
path = Path(game.bin).joinpath('studiomdl')
if path.is_file():
return path
return Path(game.bin).joinpath('studiomdl.exe')