Pārlūkot izejas kodu

Added function to make integration with builds systems less fragile

Geoffrey Irons 7 gadi atpakaļ
vecāks
revīzija
6e6f1b7c7e
2 mainītis faili ar 42 papildinājumiem un 17 dzēšanām
  1. 38 0
      io_scene_godot/__init__.py
  2. 4 17
      tests/scenes/export_blends.py

+ 38 - 0
io_scene_godot/__init__.py

@@ -179,5 +179,43 @@ def unregister():
     bpy.types.INFO_MT_file_export.remove(menu_func)
 
 
+def export(filename, overrides=None):
+    """A function to allow build systems to invoke this script more easily
+    with a call to io_scene_godot.export(filename).
+    The overrides property allows the config of the exporter to be controlled
+    keys should be the various properties defined in the ExportGodot class.
+    Eg:
+    io_scene_godot.export(
+        filename,
+        {
+            'material_search_path':'EXPORT_DIR',
+            'use_mesh_modifiers':True,
+        }
+    )
+
+    Anything not overridden will use the default properties
+    """
+
+    default_settings = dict()
+    for attr_name in ExportGodot.__dict__:
+        attr = ExportGodot.__dict__[attr_name]
+        # This introspection is not very robust and may break in future blende
+        # versions. This is becase for some reason you can't compare against
+        # bpy.types.Property because. well, they end up not being subclasses
+        # of that!!!
+        if issubclass(type(attr), tuple):
+            default_settings[attr_name] = attr[1]['default']
+    if overrides is not None:
+        default_settings.update(overrides)
+
+    class FakeOp:
+        """Fake blender operator"""
+        def __init__(self):
+            self.report = print
+
+    from . import export_godot
+    export_godot.save(FakeOp(), bpy.context, filename, **default_settings)
+
+
 if __name__ == "__main__":
     register()

+ 4 - 17
tests/scenes/export_blends.py

@@ -9,21 +9,8 @@ from io_scene_godot import export_godot
 
 def export_escn(out_file):
     """Fake the export operator call"""
-    class op:
-        def __init__(self):
-            self.report = print
-            
-    res = export_godot.save(op(), bpy.context, out_file, 
-        object_types={"EMPTY", "CAMERA", "LAMP", "ARMATURE", "MESH", "CURVE"},
-        export_shape_key=True,
-        use_active_layers=False,
-        use_export_selected=False,
-        use_mesh_modifiers=True,
-        use_export_animation=True,
-        use_seperate_animation_player=False,
-        material_search_paths = 'PROJECT_DIR'
-    )
-
+    import io_scene_godot
+    io_scene_godot.export(out_file, {})
 
 
 def main():
@@ -33,11 +20,11 @@ def main():
         if full_path.endswith(".blend"):
             print("Exporting {}".format(full_path))
             bpy.ops.wm.open_mainfile(filepath=full_path)
-            
+
             out_path, blend_name = os.path.split(full_path)
             out_path = os.path.normpath(os.path.join(out_path, '../exports/'))
             out_path = os.path.join(
-                out_path, 
+                out_path,
                 blend_name.replace('.blend', '.escn')
                 )
             print(out_path)