Skip to content

Commit 4bbd793

Browse files
committed
Add support for Linux-native studiomdl
1 parent 577849c commit 4bbd793

File tree

2 files changed

+39
-17
lines changed

2 files changed

+39
-17
lines changed

addon/types/model_export/model.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,25 @@
77
from pathlib import Path
88
from traceback import print_exc
99
from ... utils import common
10+
from ... utils import game
1011
from . smd import SMD
1112
from . fbx import export_fbx
1213

1314

1415
class Model:
15-
def __init__(self, game, model):
16+
def __init__(self, gamedef, model):
1617
self.prefs = common.get_prefs(bpy.context)
1718
self.wine = Path(self.prefs.wine)
1819

19-
self.game = Path(game.game)
20-
self.bin = Path(game.bin)
20+
self.game = Path(gamedef.game)
21+
self.bin = Path(gamedef.bin)
2122
if model.static and model.static_prop_combine:
2223
self.modelsrc = self.game.parent.parent.joinpath('content', self.game.name, 'models')
2324
else:
24-
self.modelsrc = Path(game.modelsrc)
25-
self.models = Path(game.models)
26-
self.mapsrc = Path(game.mapsrc)
27-
self.mesh_type = game.mesh_type
25+
self.modelsrc = Path(gamedef.modelsrc)
26+
self.models = Path(gamedef.models)
27+
self.mapsrc = Path(gamedef.mapsrc)
28+
self.mesh_type = gamedef.mesh_type
2829

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

37-
studiomdl = self.bin.joinpath('studiomdl.exe')
38+
studiomdl = game.get_studiomdl_path(gamedef)
3839
quickmdl = self.bin.joinpath('quickmdl.exe')
3940
self.studiomdl = quickmdl if quickmdl.is_file() else studiomdl
4041
self.hlmv = self.bin.joinpath('hlmv.exe')
@@ -362,7 +363,7 @@ def view_model(self):
362363
# Use wine to run HLMV on Linux.
363364
# Wine tends to complain about the paths we feed HLMV.
364365
# So we use relatve paths working from the base directory of the game.
365-
if (os.name == 'posix') and (self.studiomdl.suffix == '.exe'):
366+
if (os.name == 'posix') and (self.hlmv.suffix == '.exe'):
366367
cwd = self.game.parent
367368
args = [str(self.wine), str(self.hlmv.relative_to(cwd)), '-game',
368369
str(self.game.relative_to(cwd)), str(mdl.relative_to(cwd))]

addon/utils/game.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
1+
import os
12
from pathlib import Path
23
from ..utils.common import resolve
34

4-
55
def update_game(self, context):
66
self['game'] = resolve(self.game)
77
game = Path(self.game)
88

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

12-
if not bin.joinpath('studiomdl.exe').is_file():
13-
for path in bin.iterdir():
14-
if path.is_dir() and path.joinpath('studiomdl.exe').is_file():
15-
bin = path
16-
break
12+
# If we're not on the old-style pattern bin/<something> layout, check for platform subdirs
13+
actualbin = None
14+
if not bin.joinpath('studiomdl.exe').is_file() and not bin.joinpath('studiomdl').is_file():
15+
def check_subdir(subdirs, studiomdl):
16+
for subdir in subdirs:
17+
path = bin.joinpath(subdir)
18+
if path.is_dir() and path.joinpath(studiomdl).is_file():
19+
return path
20+
return None
21+
22+
# For linux, prefer the native binaries (if possible)
23+
if os.name == 'posix':
24+
actualbin = check_subdir(['linux32', 'linux64'], 'studiomdl')
25+
# Resolve windows paths
26+
if actualbin is None:
27+
actualbin = check_subdir(['win32', 'win64'], 'studiomdl.exe')
28+
29+
if actualbin is not None:
30+
bin = actualbin
1731

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

4054
def verify(game):
4155
gameinfo = Path(game.game).joinpath('gameinfo.txt')
42-
studiomdl = Path(game.bin).joinpath('studiomdl.exe')
43-
return gameinfo.is_file() and studiomdl.is_file()
56+
return gameinfo.is_file() and get_studiomdl_path(game).is_file()
57+
58+
def get_studiomdl_path(game):
59+
if os.name == 'posix' and (game.bin.endswith('linux32') or game.bin.endswith('linux64')):
60+
path = Path(game.bin).joinpath('studiomdl')
61+
if path.is_file():
62+
return path
63+
return Path(game.bin).joinpath('studiomdl.exe')
64+

0 commit comments

Comments
 (0)