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_animation", "export_armature", "export_camera", "export_material", "export_mesh", "export_object", "export_scene", "export_texture", "material", "mesh", "properties", "util":
13 imp.reload(locals()[sub])
16 from bpy_extras.io_utils import ExportHelper
18 class ExportMspGLBase(ExportHelper):
19 show_progress: bpy.props.BoolProperty(name="Show progress", description="Display progress indicator while exporting", default=True)
21 def set_extension(self, ext):
22 ext_changed = (ext!=self.filename_ext)
24 if self.filepath.endswith(self.filename_ext):
25 self.filepath = self.filepath[:-len(self.filename_ext)]
26 self.filename_ext = ext
29 def execute(self, context):
30 exporter = self.create_exporter()
31 self.prepare_exporter(exporter)
32 exporter.export_to_file(context, self.filepath)
35 def create_exporter(self):
36 raise Exception("create_exporter must be overridden")
38 def prepare_exporter(self, exporter):
39 for k, v in self.as_keywords().items():
40 setattr(exporter, k, v)
42 class ExportMspGLMeshBase(ExportMspGLBase):
43 export_all: bpy.props.BoolProperty(name="Export all selected", description="Export all selected objects (use generated filenames)", default=False)
44 use_strips: bpy.props.BoolProperty(name="Use strips", description="Combine faces into triangle strips", default=True)
45 use_degen_tris: bpy.props.BoolProperty(name="Use degen tris", description="Concatenate triangle strips with degenerate triangles", default=False)
47 def draw(self, context):
48 self.general_col = self.layout.column()
50 col = self.layout.column()
51 if len(context.selected_objects)>1:
52 col.label(text="Object selection")
53 col.prop(self, "export_all")
54 col.label(text="Triangle strips")
55 col.prop(self, "use_strips")
56 col.prop(self, "use_degen_tris")
58 class ExportMspGLMesh(bpy.types.Operator, ExportMspGLMeshBase):
59 bl_idname = "export_mesh.mspgl_mesh"
60 bl_label = "Export Msp GL mesh"
61 bl_description = "Export one or more meshes in Msp GL format"
63 filename_ext = ".mesh"
65 def create_exporter(self):
66 from .export_mesh import MeshExporter
69 class ExportMspGLObject(bpy.types.Operator, ExportMspGLMeshBase):
70 bl_idname = "export_mesh.mspgl_object"
71 bl_label = "Export Msp GL object"
72 bl_description = "Export one or more objects in Msp GL format"
74 filename_ext = ".object"
76 collection: bpy.props.BoolProperty(name="As a collection", description="Write all data into a single collection file", default=False)
77 shared_resources: bpy.props.BoolProperty(name="Shared resources", description="Use global names for resource files to enable sharing", default=True)
79 export_lods: bpy.props.BoolProperty(name="Export LoDs", description="Export all levels of detail", default=True)
80 use_textures: bpy.props.BoolProperty(name="Use textures", description="Use textures in the exported object", default=True)
82 def check(self, context):
83 ext_changed = self.set_extension(".mdc" if self.collection else ".object")
84 super_result = super().check(context)
85 return ext_changed or super_result
87 def create_exporter(self):
88 from .export_object import ObjectExporter
89 return ObjectExporter()
91 def draw(self, context):
94 self.general_col.prop(self, "export_lods")
95 self.general_col.prop(self, "use_textures")
97 col = self.layout.column()
98 col.label(text="Files")
99 col.prop(self, "collection")
100 col.prop(self, "shared_resources")
102 class ExportMspGLArmature(bpy.types.Operator, ExportMspGLBase):
103 bl_idname = "export.mspgl_armature"
104 bl_label = "Export Msp GL armature"
105 bl_description = "Export an armature in Msp GL format"
107 filename_ext = ".arma"
109 def create_exporter(self):
110 from .export_armature import ArmatureExporter
111 return ArmatureExporter()
113 class ExportMspGLAnimation(bpy.types.Operator, ExportMspGLBase):
114 bl_idname = "export.mspgl_animation"
115 bl_label = "Export Msp GL animation"
116 bl_description = "Export one or more animations in Msp GL format"
118 filename_ext = ".anim"
120 export_all: bpy.props.BoolProperty(name="Export all animations", description="Export all animations present on the selected objects' NLA tracks")
121 collection: bpy.props.BoolProperty(name="As a collection", description="Export the animations as a single collection file", default=True)
122 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)
124 def check(self, context):
125 ext_changed = self.set_extension(".mdc" if self.export_all and self.collection else ".anim")
126 super_result = super().check(context)
127 return ext_changed or super_result
129 def create_exporter(self):
130 from .export_animation import AnimationExporter
131 return AnimationExporter()
133 def draw(self, context):
134 col = self.layout.column()
135 col.prop(self, "export_all")
137 col.prop(self, "collection")
138 col.prop(self, "looping_threshold")
140 class ExportMspGLScene(bpy.types.Operator, ExportMspGLBase):
141 bl_idname = "export_scene.mspgl_scene"
142 bl_label = "Export Msp GL scene"
143 bl_description = "Export the active scene in Msp GL format"
145 filename_ext = ".scene"
147 selected_only: bpy.props.BoolProperty(name="Selected objects only", description="Only export the selected objects")
148 visible_collections: bpy.props.BoolProperty(name="Visible collections only", description="Only export objects in visible collections", default=True)
149 resource_collection: bpy.props.BoolProperty(name="Resource collection", description="Put resources to a single collection file", default=True)
150 skip_existing: bpy.props.BoolProperty(name="Skip existing files", description="Skip resources that already exist as files", default=True)
152 def create_exporter(self):
153 from .export_scene import SceneExporter
154 return SceneExporter()
156 def draw(self, context):
157 col = self.layout.column()
158 col.prop(self, "selected_only")
159 col.prop(self, "visible_collections")
160 col.prop(self, "resource_collection")
161 if self.resource_collection:
162 col.prop(self, "skip_existing")
164 class ExportMspGLCamera(bpy.types.Operator, ExportMspGLBase):
165 bl_idname = "export.mspgl_camera"
166 bl_label = "Export Msp GL camera"
167 bl_description = "Export a camera in Msp GL format"
169 filename_ext = ".camera"
171 def create_exporter(self):
172 from .export_camera import CameraExporter
173 return CameraExporter()
175 class AddUniform(bpy.types.Operator):
176 bl_idname = "material.add_uniform"
177 bl_label = "Add Uniform"
178 bl_description = "Add a new uniform value to the material"
180 def execute(self, context):
181 mat = context.active_object.active_material
183 mat.active_uniform_index = len(mat.uniforms)-1
187 class RemoveUniform(bpy.types.Operator):
188 bl_idname = "material.remove_uniform"
189 bl_label = "Remove Uniform"
190 bl_description = "Remove the selected uniform from the material"
192 def execute(self, context):
193 mat = context.active_object.active_material
194 mat.uniforms.remove(mat.active_uniform_index)
195 mat.active_uniform_index = min(mat.active_uniform_index, len(mat.uniforms)-1)
199 def menu_func_export(self, context):
200 self.layout.operator(ExportMspGLMesh.bl_idname, text="Msp GL mesh")
201 self.layout.operator(ExportMspGLObject.bl_idname, text="Msp GL object")
202 self.layout.operator(ExportMspGLArmature.bl_idname, text="Msp GL armature")
203 self.layout.operator(ExportMspGLAnimation.bl_idname, text="Msp GL animation")
204 self.layout.operator(ExportMspGLScene.bl_idname, text="Msp GL scene")
205 self.layout.operator(ExportMspGLCamera.bl_idname, text="Msp GL camera")
207 classes = [ExportMspGLMesh, ExportMspGLObject, ExportMspGLArmature, ExportMspGLAnimation, ExportMspGLScene, ExportMspGLCamera, AddUniform, RemoveUniform]
211 bpy.utils.register_class(c)
213 bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
215 from .properties import register_properties
216 register_properties()
220 bpy.utils.unregister_class(c)
222 bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
224 from .properties import unregister_properties
225 unregister_properties()