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", "scene", "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", default=False)
114 visible_only: bpy.props.BoolProperty(name="Visible only", description="Only export objects in visible collections", default=True)
115 collection: bpy.props.BoolProperty(name="As a collection", description="Export the scene and all resources as a single collection file", default=False)
116 skip_existing: bpy.props.BoolProperty(name="Skip existing files", description="Skip resources that already exist as files", default=True)
118 def invoke(self, context, event):
119 self.filepath = context.scene.name+".scene"
120 return super().invoke(context, event)
122 def check(self, context):
123 ext_changed = self.set_extension(".mdc" if self.collection else ".scene")
124 super_result = super().check(context)
125 return ext_changed or super_result
127 def create_exporter(self):
128 from .export_scene import SceneExporter
129 return SceneExporter()
131 def draw(self, context):
132 col = self.layout.column()
133 col.prop(self, "selected_only")
134 col.prop(self, "visible_only")
135 col.prop(self, "collection")
137 col.prop(self, "skip_existing")
139 class AddUniform(bpy.types.Operator):
140 bl_idname = "material.add_uniform"
141 bl_label = "Add Uniform"
142 bl_description = "Add a new uniform value to the material"
144 def execute(self, context):
145 mat = context.active_object.active_material
147 mat.active_uniform_index = len(mat.uniforms)-1
151 class RemoveUniform(bpy.types.Operator):
152 bl_idname = "material.remove_uniform"
153 bl_label = "Remove Uniform"
154 bl_description = "Remove the selected uniform from the material"
156 def execute(self, context):
157 mat = context.active_object.active_material
158 mat.uniforms.remove(mat.active_uniform_index)
159 mat.active_uniform_index = min(mat.active_uniform_index, len(mat.uniforms)-1)
163 def menu_func_export(self, context):
164 self.layout.operator(ExportMspGLData.bl_idname, text="Msp GL data")
165 self.layout.operator(ExportMspGLAnimation.bl_idname, text="Msp GL animation")
166 self.layout.operator(ExportMspGLScene.bl_idname, text="Msp GL scene")
168 classes = [ExportMspGLData, ExportMspGLAnimation, ExportMspGLScene, AddUniform, RemoveUniform]
172 bpy.utils.register_class(c)
174 bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
176 from .properties import register_properties
177 register_properties()
181 bpy.utils.unregister_class(c)
183 bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
185 from .properties import unregister_properties
186 unregister_properties()