diff --git a/addon/types/model_export/model.py b/addon/types/model_export/model.py index 27bc798..3da8843 100644 --- a/addon/types/model_export/model.py +++ b/addon/types/model_export/model.py @@ -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) @@ -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') @@ -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'): 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))] diff --git a/addon/utils/game.py b/addon/utils/game.py index fe8b312..184b5e4 100644 --- a/addon/utils/game.py +++ b/addon/utils/game.py @@ -1,7 +1,7 @@ +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) @@ -9,11 +9,25 @@ def update_game(self, context): 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/ 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')) @@ -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') +