if "bpy" in locals():
import imp
- for sub in "animation", "armature", "datafile", "export", "export_animation", "export_armature", "export_camera", "export_material", "export_mesh", "export_object", "export_scene", "export_texture", "material", "mesh", "properties", "util":
+ for sub in "animation", "armature", "datafile", "export", "export_animation", "export_armature", "export_camera", "export_material", "export_mesh", "export_object", "export_scene", "export_texture", "material", "mesh", "properties", "scene", "util":
if sub in locals():
imp.reload(locals()[sub])
import os
import bpy
-from bpy_extras.io_utils import ExportHelper
-
-class ExportMspGLBase(ExportHelper):
- show_progress: bpy.props.BoolProperty(name="Show progress", description="Display progress indicator while exporting", default=True)
+import bpy_extras
+class ExportHelper(bpy_extras.io_utils.ExportHelper):
def set_extension(self, ext):
ext_changed = (ext!=self.filename_ext)
if ext_changed:
self.filename_ext = ext
return ext_changed
- def execute(self, context):
- exporter = self.create_exporter()
- self.prepare_exporter(exporter)
- exporter.export_to_file(context, self.filepath)
- return {"FINISHED"}
-
- def create_exporter(self):
- raise Exception("create_exporter must be overridden")
-
- def prepare_exporter(self, exporter):
- for k, v in self.as_keywords().items():
- setattr(exporter, k, v)
-
class ExportMspGLData(bpy.types.Operator):
bl_idname = "export.mspgl_data"
bl_label = "Export Msp GL data"
col.prop(self, "collection")
col.prop(self, "shared_resources")
-class ExportMspGLAnimation(bpy.types.Operator, ExportMspGLBase):
+class ExportMspGLAnimation(bpy.types.Operator, ExportHelper):
bl_idname = "export.mspgl_animation"
bl_label = "Export Msp GL animation"
bl_description = "Export one or more animations in Msp GL format"
super_result = super().check(context)
return ext_changed or super_result
- def create_exporter(self):
+ def execute(self, context):
from .export_animation import AnimationExporter
- return AnimationExporter()
+ exporter = AnimationExporter()
+ exporter.export_all = self.export_all
+ exporter.collection = self.collection
+ exporter.looping_threshold = self.looping_threshold
+ exporter.export_to_file(context, self.filepath)
+ return {'FINISHED'}
def draw(self, context):
col = self.layout.column()
col.prop(self, "collection")
col.prop(self, "looping_threshold")
-class ExportMspGLScene(bpy.types.Operator, ExportMspGLBase):
+class ExportMspGLScene(bpy.types.Operator, ExportHelper):
bl_idname = "export_scene.mspgl_scene"
bl_label = "Export Msp GL scene"
bl_description = "Export the active scene in Msp GL format"
super_result = super().check(context)
return ext_changed or super_result
- def create_exporter(self):
+ def execute(self, context):
from .export_scene import SceneExporter
- return SceneExporter()
+ exporter = SceneExporter()
+ exporter.selected_only = self.selected_only
+ exporter.visible_only = self.visible_only
+ exporter.collection = self.collection
+ exporter.skip_existing = self.skip_existing
+ exporter.export_to_file(context, self.filepath)
+ return {'FINISHED'}
def draw(self, context):
col = self.layout.column()
if self.collection:
col.prop(self, "skip_existing")
+class ExportMspGLProject(bpy.types.Operator):
+ bl_idname = "export.mspgl_project"
+ bl_label = "Export Msp GL project"
+ bl_description = "Export the entire project in Msp GL format"
+
+ directory: bpy.props.StringProperty(name="Directory", description="Directory for exporting the data", subtype='FILE_PATH')
+
+ def invoke(self, context, event):
+ blend_filepath = context.blend_data.filepath
+ if blend_filepath:
+ self.directory = os.path.split(blend_filepath)[0]
+ context.window_manager.fileselect_add(self)
+ return {'RUNNING_MODAL'}
+
+ def execute(self, context):
+ from .export import ProjectExporter
+ exporter = ProjectExporter()
+ exporter.export_to_directory(context, self.directory)
+ return {'FINISHED'}
+
class AddUniform(bpy.types.Operator):
bl_idname = "material.add_uniform"
bl_label = "Add Uniform"
self.layout.operator(ExportMspGLData.bl_idname, text="Msp GL data")
self.layout.operator(ExportMspGLAnimation.bl_idname, text="Msp GL animation")
self.layout.operator(ExportMspGLScene.bl_idname, text="Msp GL scene")
+ self.layout.operator(ExportMspGLProject.bl_idname, text="Msp GL project")
-classes = [ExportMspGLData, ExportMspGLAnimation, ExportMspGLScene, AddUniform, RemoveUniform]
+classes = [ExportMspGLData, ExportMspGLAnimation, ExportMspGLScene, ExportMspGLProject, AddUniform, RemoveUniform]
def register():
for c in classes: