소스 검색

SDK:
- make blender import scripts more generic and easy to extend

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10246 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

nor..67 12 년 전
부모
커밋
bb7df0690d
2개의 변경된 파일43개의 추가작업 그리고 49개의 파일을 삭제
  1. 21 24
      jme3-blender/src/com/jme3/gde/blender/scripts/import_3ds.py
  2. 22 25
      jme3-blender/src/com/jme3/gde/blender/scripts/import_dae.py

+ 21 - 24
jme3-blender/src/com/jme3/gde/blender/scripts/import_3ds.py

@@ -1,30 +1,30 @@
-# This script is an example of how you can run blender from the command line
-# (in background mode with no interface) to automate tasks, in this example it
-# creates a text object, camera and light, then renders and/or saves it.
-# This example also shows how you can parse command line options to scripts.
+# This script invokes blender to import and save external model formats as
+# .blend files to be processed further.
 #
-# Example usage for this test.
-#  blender --background --factory-startup --python $HOME/background_job.py -- \
-#          --text="Hello World" \
-#          --render="/tmp/hello" \
-#          --save="/tmp/hello.blend"
-#
-# Notice:
-# '--factory-startup' is used to avoid the user default settings from
-#                     interfearing with automated scene generation.
-#
-# '--' causes blender to ignore all following arguments so python can use them.
+# Example usage for this importer:
+#  blender --background --factory-startup --python $HOME/import_3ds.py -- \
+#          --i="/tmp/hello.3ds" \
+#          --o="/tmp/hello.blend" \
 #
 # See blender --help for details.
 
 import bpy
 
-
-def convert_file(file_path, save_path):
+# Imports a file using importer
+def import_file(file_path):
+    # Import the model
     bpy.ops.import_scene.autodesk_3ds(filepath = file_path)
 
+# Clear existing objects.
+def clear_scene():
     scene = bpy.context.scene
+    scene.camera = None
+    for obj in scene.objects:
+        scene.objects.unlink(obj)
 
+# Save current scene as .blend file
+def save_file(save_path):
+    # Check if output file exists already
     try:
         f = open(save_path, 'w')
         f.close()
@@ -35,6 +35,7 @@ def convert_file(file_path, save_path):
         import traceback
         traceback.print_exc()
 
+    # Save .blend file
     if ok:
         bpy.ops.wm.save_as_mainfile(filepath=save_path)
 
@@ -70,14 +71,10 @@ def main():
         parser.print_help()
         return
 
-    # Clear existing objects.
-    scene = bpy.context.scene
-    scene.camera = None
-    for obj in scene.objects:
-        scene.objects.unlink(obj)
-
     # Run the conversion
-    convert_file(args.file_path, args.save_path)
+    clear_scene()
+    import_file(args.file_path)
+    save_file(args.save_path)
 
     print("batch job finished, exiting")
 

+ 22 - 25
jme3-blender/src/com/jme3/gde/blender/scripts/import_dae.py

@@ -1,30 +1,30 @@
-# This script is an example of how you can run blender from the command line
-# (in background mode with no interface) to automate tasks, in this example it
-# creates a text object, camera and light, then renders and/or saves it.
-# This example also shows how you can parse command line options to scripts.
+# This script invokes blender to import and save external model formats as
+# .blend files to be processed further.
 #
-# Example usage for this test.
-#  blender --background --factory-startup --python $HOME/background_job.py -- \
-#          --text="Hello World" \
-#          --render="/tmp/hello" \
-#          --save="/tmp/hello.blend"
-#
-# Notice:
-# '--factory-startup' is used to avoid the user default settings from
-#                     interfearing with automated scene generation.
-#
-# '--' causes blender to ignore all following arguments so python can use them.
+# Example usage for this importer:
+#  blender --background --factory-startup --python $HOME/import_3ds.py -- \
+#          --i="/tmp/hello.3ds" \
+#          --o="/tmp/hello.blend" \
 #
 # See blender --help for details.
 
 import bpy
 
-
-def convert_file(file_path, save_path):
+# Imports a file using importer
+def import_file(file_path):
+    # Import the model
     bpy.ops.wm.collada_import(filepath = file_path)
 
+# Clear existing objects.
+def clear_scene():
     scene = bpy.context.scene
+    scene.camera = None
+    for obj in scene.objects:
+        scene.objects.unlink(obj)
 
+# Save current scene as .blend file
+def save_file(save_path):
+    # Check if output file exists already
     try:
         f = open(save_path, 'w')
         f.close()
@@ -35,6 +35,7 @@ def convert_file(file_path, save_path):
         import traceback
         traceback.print_exc()
 
+    # Save .blend file
     if ok:
         bpy.ops.wm.save_as_mainfile(filepath=save_path)
 
@@ -54,7 +55,7 @@ def main():
     # When --help or no args are given, print this help
     usage_text = \
     "Run blender in background mode with this script:"
-    "  blender --background --python " + __file__ + " -- [options]"
+    "  blender --background --factory-startup --python " + __file__ + " -- [options]"
 
     parser = argparse.ArgumentParser(description=usage_text)
 
@@ -70,14 +71,10 @@ def main():
         parser.print_help()
         return
 
-    # Clear existing objects.
-    scene = bpy.context.scene
-    scene.camera = None
-    for obj in scene.objects:
-        scene.objects.unlink(obj)
-
     # Run the conversion
-    convert_file(args.file_path, args.save_path)
+    clear_scene()
+    import_file(args.file_path)
+    save_file(args.save_path)
 
     print("batch job finished, exiting")