# HG changeset patch # User Sam # Date 1701795955 -25200 # Node ID 1727bec9ca2f000aebb437e842bb8e48348526c4 # Parent ae8a6c6ff4681766455cbc9846257494ab029a79 did: finish importing system diff -r ae8a6c6ff468 -r 1727bec9ca2f scripts/blender_gltf_converter.py --- a/scripts/blender_gltf_converter.py Tue Dec 05 22:46:32 2023 +0700 +++ b/scripts/blender_gltf_converter.py Wed Dec 06 00:05:55 2023 +0700 @@ -5,19 +5,19 @@ def runner(): - argv = sys.argv - print(sys.argv) script_args = sys.argv[sys.argv.index("--") + 1 :] - inputfile = script_args[0] - outputfile = script_args[1] - if not os.path.exists(inputfile): - print(f"Input file '{inputfile}' does not exists") - quit(1) - if not outputfile.endswith(".glb"): - print(f"Output file '{outputfile}' is not a *.glb file") + for i in range(0, len(script_args), 2): + inputfile = script_args[i] + outputfile = script_args[i + 1] + if not os.path.exists(inputfile): + print(f"Input file '{inputfile}' does not exists") + quit(1) + if not outputfile.endswith(".glb"): + print(f"Output file '{outputfile}' is not a *.glb file") + quit(1) - bpy.ops.wm.open_mainfile(filepath=inputfile) - bpy.ops.export_scene.gltf(filepath=outputfile[:-4], export_apply=True) + bpy.ops.wm.open_mainfile(filepath=inputfile) + bpy.ops.export_scene.gltf(filepath=outputfile[:-4], export_apply=True) if __name__ == "__main__": diff -r ae8a6c6ff468 -r 1727bec9ca2f semicongine.nimble --- a/semicongine.nimble Tue Dec 05 22:46:32 2023 +0700 +++ b/semicongine.nimble Wed Dec 06 00:05:55 2023 +0700 @@ -1,11 +1,13 @@ # Package +# name = "semicongine" version = "0.3.0" author = "Sam " description = "Game engine, for games that run on semiconductor engines" license = "MIT" -srcDir = "src" backend = "c" +bin = @["simporter"] +installDirs = @["semicongine"] # Dependencies @@ -13,3 +15,4 @@ requires "winim" requires "x11" requires "zippy" + diff -r ae8a6c6ff468 -r 1727bec9ca2f semicongine/build.nim --- a/semicongine/build.nim Tue Dec 05 22:46:32 2023 +0700 +++ b/semicongine/build.nim Wed Dec 06 00:05:55 2023 +0700 @@ -42,11 +42,3 @@ exec &"powershell Compress-Archive * {outputfile}" cd(oldcwd) return outdir - -proc semicongine_import_mesh*(blender_file: string, output_file: string) = - assert blender_file.fileExists - let converter_script = currentSourcePath.parentDir().parentDir().joinPath("scripts/blender_gltf_converter.py") - exec &"blender --background --python {converter_script} -- {blender_file} {output_file}" - -proc semicongine_import_audio*(in_file: string, output_file: string) = - exec &"ffmpeg -i {in_file} -ar {AUDIO_SAMPLE_RATE} {output_file}" diff -r ae8a6c6ff468 -r 1727bec9ca2f simporter.nim --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/simporter.nim Wed Dec 06 00:05:55 2023 +0700 @@ -0,0 +1,59 @@ +import std/os +import std/paths +import std/dirs +import std/osproc +import std/cmdline +import std/strutils +import std/strformat + +import ./semicongine/core/audiotypes + +proc import_meshes*(files: seq[(string, string)]) = + let converter_script = currentSourcePath.parentDir().joinPath("scripts/blender_gltf_converter.py") + + var args = @["--background", "--python", converter_script, "--"] + for (input, output) in files: + args.add input + args.add output + + let p = startProcess("blender", args=args, options={poStdErrToStdOut, poUsePath}) + let exitCode = p.waitForExit() + p.close() + if exitCode != 0: + raise newException(OSError, &"blender had exit code {exitCode}") + +proc import_audio*(files: seq[(string, string)]) = + for (input, output) in files: + let p = startProcess("ffmpeg", args=["-y", "-i", input, "-ar", $AUDIO_SAMPLE_RATE, output], options={poStdErrToStdOut, poUsePath}) + let exitCode = p.waitForExit() + p.close() + if exitCode != 0: + raise newException(OSError, &"ffmpeg had exit code {exitCode}") + +when isMainModule: + var meshfiles: seq[(string, string)] + var audiofiles: seq[(string, string)] + + for arg in commandLineParams(): + if arg.count(':') != 1: + raise newException(Exception, &"Argument {arg} requires exactly one colon to separate input from output, but it contains {arg.count(':')} colons.") + let + input_output = arg.split(':', 1) + input = input_output[0] + output = input_output[1] + if not input.fileExists: + raise newException(IOError, &"Not found: {input}") + if not output.fileExists or input.fileNewer(output): + echo &"{output} is outdated" + if input.endsWith("blend"): + meshfiles.add (input, output) + elif input.endsWith("mp3") or input.endsWith("ogg") or input.endsWith("wav"): + audiofiles.add (input, output) + else: + raise newException(Exception, &"unkown file type: {input}") + Path(output.parentDir()).createDir() + else: + echo &"{output} is up-to-date" + + import_meshes meshfiles + import_audio audiofiles