changeset 390:1727bec9ca2f

did: finish importing system
author Sam <sam@basx.dev>
date Wed, 06 Dec 2023 00:05:55 +0700
parents ae8a6c6ff468
children 68198310770b
files scripts/blender_gltf_converter.py semicongine.nimble semicongine/build.nim simporter.nim
diffstat 4 files changed, 74 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- 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__":
--- 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 <sam@basx.dev>"
 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"
+
--- 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}"
--- /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