Skip to content

Commit

Permalink
Auto compile feature
Browse files Browse the repository at this point in the history
  • Loading branch information
REDxEYE committed Jan 29, 2021
1 parent b610f94 commit 1b1b2f1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
2 changes: 1 addition & 1 deletion SourceIO
29 changes: 26 additions & 3 deletions convert_s1_to_s2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os


os.environ['NO_BPY'] = '1'

from pathlib import Path
Expand Down Expand Up @@ -171,12 +170,33 @@ def get_full_math(mat_name):
vmat_file.write('}\n')
else:
print('\033[91mUnsupported Source1 shader!\033[0m')
return s2_vmodel


from subprocess import Popen, PIPE


def compile_model(vmdl_path, base_path):
resource_compiler = base_path.parent.parent.parent / 'game' / 'bin' / 'win64' / 'resourcecompiler.exe'
if resource_compiler.exists() and resource_compiler.is_file():
print('\033[92mResourceCompiler Detected\033[0m')
print(f'\033[94mCompiling model:\033[0m {vmdl_path}')
pipe = Popen([str(resource_compiler), str(vmdl_path)], stdout=PIPE)
while True:
line = pipe.stdout.readline().decode('utf-8')
if not line:
break
print(line.rstrip())


args = argparse.ArgumentParser(description='Convert Source1 models to Source2')
args.add_argument('-a', '--addon', type=str, required=False, help='path to source2 add-on folder', dest='s2_addon_path')
args.add_argument('-m', '--model', type=str, nargs='+', required=False, help='path to source1 model or folder',
dest='s1_model_path')
args.add_argument('-c', '--compile', action='store_const', const=True, default=False, required=False,
help='Automatically compile (if resourcecompiler detected)',
dest='auto_compile')

args = args.parse_args()

output_folder = Path(args.s2_addon_path or input("Path to Source2 add-on folder: ").replace('"', ''))
Expand All @@ -186,6 +206,9 @@ def get_full_math(mat_name):
file = Path(file)
if file.is_dir():
for glob_file in file.rglob('*.mdl'):
convert_model(glob_file, output_folder)
vmdl_file = convert_model(glob_file, output_folder)
compile_model(vmdl_file, output_folder)
elif file.is_file() and file.exists():
convert_model(file, output_folder)
vmdl_file = convert_model(file, output_folder)
if args.auto_compile:
compile_model(vmdl_file, output_folder)

0 comments on commit 1b1b2f1

Please sign in to comment.