2 "name": "Msp GL datafiles",
4 "author": "Mikko Rasa",
5 "location": "File > Export",
6 "description": "Export Msp GL data",
7 "category": "Import-Export" }
11 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":
13 imp.reload(locals()[sub])
17 from bpy_extras.io_utils import ExportHelper
19 class ExportMspGLBase(ExportHelper):
20 show_progress: bpy.props.BoolProperty(name="Show progress", description="Display progress indicator while exporting", default=True)
22 def set_extension(self, ext):
23 ext_changed = (ext!=self.filename_ext)
25 if self.filepath.endswith(self.filename_ext):
26 self.filepath = self.filepath[:-len(self.filename_ext)]
27 self.filename_ext = ext
30 def execute(self, context):
31 exporter = self.create_exporter()
32 self.prepare_exporter(exporter)
33 exporter.export_to_file(context, self.filepath)
36 def create_exporter(self):
37 raise Exception("create_exporter must be overridden")
39 def prepare_exporter(self, exporter):
40 for k, v in self.as_keywords().items():
41 setattr(exporter, k, v)
43 class ExportMspGLData(bpy.types.Operator):
44 bl_idname = "export.mspgl_data"
45 bl_label = "Export Msp GL data"
46 bl_description = "Export object data in Msp GL format"
48 filepath: bpy.props.StringProperty(name="File path", description="File path for exporting the data", subtype='FILE_PATH')
49 collection: bpy.props.BoolProperty(name="As a collection", description="Export all data as a single collection file", default=False)
50 shared_resources: bpy.props.BoolProperty(name="Shared resources", description="Use global names for resource files to enable sharing", default=True)
53 def poll(cls, context):
54 return len(context.selected_objects)>0
56 def invoke(self, context, event):
57 blend_filepath = context.blend_data.filepath
59 self.filepath = os.path.splitext(blend_filepath)[0]+".mdc"
61 self.filepath = "data.mdc"
62 context.window_manager.fileselect_add(self)
63 return {'RUNNING_MODAL'}
65 def execute(self, context):
66 from .export import DataExporter
67 exporter = DataExporter()
68 exporter.collection = self.collection
69 exporter.shared_resources = self.shared_resources
70 exporter.export_to_file(context, self.filepath)
73 def draw(self, context):
74 col = self.layout.column()
75 col.label(text="Files")
76 col.prop(self, "collection")
77 col.prop(self, "shared_resources")
79 class ExportMspGLAnimation(bpy.types.Operator, ExportMspGLBase):
80 bl_idname = "export.mspgl_animation"
81 bl_label = "Export Msp GL animation"
82 bl_description = "Export one or more animations in Msp GL format"
84 filename_ext = ".anim"
86 export_all: bpy.props.BoolProperty(name="Export all animations", description="Export all animations present on the selected objects' NLA tracks")
87 collection: bpy.props.BoolProperty(name="As a collection", description="Export the animations as a single collection file", default=True)
88 looping_threshold: bpy.props.FloatProperty(name="Looping threshold", description="Tolerance for curve beginning and end values for looping", min=0.0, soft_max=1.0, precision=4, default=0.001)
90 def check(self, context):
91 ext_changed = self.set_extension(".mdc" if self.export_all and self.collection else ".anim")
92 super_result = super().check(context)
93 return ext_changed or super_result
95 def create_exporter(self):
96 from .export_animation import AnimationExporter
97 return AnimationExporter()
99 def draw(self, context):
100 col = self.layout.column()
101 col.prop(self, "export_all")
103 col.prop(self, "collection")
104 col.prop(self, "looping_threshold")
106 class ExportMspGLScene(bpy.types.Operator, ExportMspGLBase):
107 bl_idname = "export_scene.mspgl_scene"
108 bl_label = "Export Msp GL scene"
109 bl_description = "Export the active scene in Msp GL format"
111 filename_ext = ".scene"
113 selected_only: bpy.props.BoolProperty(name="Selected objects only", description="Only export the selected objects")
114 visible_collections: bpy.props.BoolProperty(name="Visible collections only", description="Only export objects in visible collections", default=True)
115 resource_collection: bpy.props.BoolProperty(name="Resource collection", description="Put resources to a single collection file", default=True)
116 skip_existing: bpy.props.BoolProperty(name="Skip existing files", description="Skip resources that already exist as files", default=True)
118 def create_exporter(self):
119 from .export_scene import SceneExporter
120 return SceneExporter()
122 def draw(self, context):
123 col = self.layout.column()
124 col.prop(self, "selected_only")
125 col.prop(self, "visible_collections")
126 col.prop(self, "resource_collection")
127 if self.resource_collection:
128 col.prop(self, "skip_existing")
130 class AddUniform(bpy.types.Operator):
131 bl_idname = "material.add_uniform"
132 bl_label = "Add Uniform"
133 bl_description = "Add a new uniform value to the material"
135 def execute(self, context):
136 mat = context.active_object.active_material
138 mat.active_uniform_index = len(mat.uniforms)-1
142 class RemoveUniform(bpy.types.Operator):
143 bl_idname = "material.remove_uniform"
144 bl_label = "Remove Uniform"
145 bl_description = "Remove the selected uniform from the material"
147 def execute(self, context):
148 mat = context.active_object.active_material
149 mat.uniforms.remove(mat.active_uniform_index)
150 mat.active_uniform_index = min(mat.active_uniform_index, len(mat.uniforms)-1)
154 def menu_func_export(self, context):
155 self.layout.operator(ExportMspGLData.bl_idname, text="Msp GL data")
156 self.layout.operator(ExportMspGLAnimation.bl_idname, text="Msp GL animation")
157 self.layout.operator(ExportMspGLScene.bl_idname, text="Msp GL scene")
159 classes = [ExportMspGLData, ExportMspGLAnimation, ExportMspGLScene, AddUniform, RemoveUniform]
163 bpy.utils.register_class(c)
165 bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
167 from .properties import register_properties
168 register_properties()
172 bpy.utils.unregister_class(c)
174 bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
176 from .properties import unregister_properties
177 unregister_properties()