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 def set_extension(self, ext):
21 ext_changed = (ext!=self.filename_ext)
23 if self.filepath.endswith(self.filename_ext):
24 self.filepath = self.filepath[:-len(self.filename_ext)]
25 self.filename_ext = ext
28 def execute(self, context):
29 exporter = self.create_exporter()
30 self.prepare_exporter(exporter)
31 exporter.export_to_file(context, self.filepath)
34 def create_exporter(self):
35 raise Exception("create_exporter must be overridden")
37 def prepare_exporter(self, exporter):
38 for k, v in self.as_keywords().items():
39 setattr(exporter, k, v)
41 class ExportMspGLData(bpy.types.Operator):
42 bl_idname = "export.mspgl_data"
43 bl_label = "Export Msp GL data"
44 bl_description = "Export object data in Msp GL format"
46 filepath: bpy.props.StringProperty(name="File path", description="File path for exporting the data", subtype='FILE_PATH')
47 collection: bpy.props.BoolProperty(name="As a collection", description="Export all data as a single collection file", default=False)
48 shared_resources: bpy.props.BoolProperty(name="Shared resources", description="Use global names for resource files to enable sharing", default=True)
51 def poll(cls, context):
52 return len(context.selected_objects)>0
54 def invoke(self, context, event):
55 blend_filepath = context.blend_data.filepath
57 self.filepath = os.path.splitext(blend_filepath)[0]+".mdc"
59 self.filepath = "data.mdc"
60 context.window_manager.fileselect_add(self)
61 return {'RUNNING_MODAL'}
63 def execute(self, context):
64 from .export import DataExporter
65 exporter = DataExporter()
66 exporter.collection = self.collection
67 exporter.shared_resources = self.shared_resources
68 exporter.export_to_file(context, self.filepath)
71 def draw(self, context):
72 col = self.layout.column()
73 col.label(text="Files")
74 col.prop(self, "collection")
75 col.prop(self, "shared_resources")
77 class ExportMspGLAnimation(bpy.types.Operator, ExportMspGLBase):
78 bl_idname = "export.mspgl_animation"
79 bl_label = "Export Msp GL animation"
80 bl_description = "Export one or more animations in Msp GL format"
82 filename_ext = ".anim"
84 export_all: bpy.props.BoolProperty(name="Export all animations", description="Export all animations present on the selected objects' NLA tracks")
85 collection: bpy.props.BoolProperty(name="As a collection", description="Export the animations as a single collection file", default=True)
86 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)
88 def check(self, context):
89 ext_changed = self.set_extension(".mdc" if self.export_all and self.collection else ".anim")
90 super_result = super().check(context)
91 return ext_changed or super_result
93 def create_exporter(self):
94 from .export_animation import AnimationExporter
95 return AnimationExporter()
97 def draw(self, context):
98 col = self.layout.column()
99 col.prop(self, "export_all")
101 col.prop(self, "collection")
102 col.prop(self, "looping_threshold")
104 class ExportMspGLScene(bpy.types.Operator, ExportMspGLBase):
105 bl_idname = "export_scene.mspgl_scene"
106 bl_label = "Export Msp GL scene"
107 bl_description = "Export the active scene in Msp GL format"
109 filename_ext = ".scene"
111 selected_only: bpy.props.BoolProperty(name="Selected objects only", description="Only export the selected objects", default=False)
112 visible_only: bpy.props.BoolProperty(name="Visible only", description="Only export objects in visible collections", default=True)
113 collection: bpy.props.BoolProperty(name="As a collection", description="Export the scene and all resources as a single collection file", default=False)
114 skip_existing: bpy.props.BoolProperty(name="Skip existing files", description="Skip resources that already exist as files", default=True)
116 def invoke(self, context, event):
117 self.filepath = context.scene.name+".scene"
118 return super().invoke(context, event)
120 def check(self, context):
121 ext_changed = self.set_extension(".mdc" if self.collection else ".scene")
122 super_result = super().check(context)
123 return ext_changed or super_result
125 def create_exporter(self):
126 from .export_scene import SceneExporter
127 return SceneExporter()
129 def draw(self, context):
130 col = self.layout.column()
131 col.prop(self, "selected_only")
132 col.prop(self, "visible_only")
133 col.prop(self, "collection")
135 col.prop(self, "skip_existing")
137 class AddUniform(bpy.types.Operator):
138 bl_idname = "material.add_uniform"
139 bl_label = "Add Uniform"
140 bl_description = "Add a new uniform value to the material"
142 def execute(self, context):
143 mat = context.active_object.active_material
145 mat.active_uniform_index = len(mat.uniforms)-1
149 class RemoveUniform(bpy.types.Operator):
150 bl_idname = "material.remove_uniform"
151 bl_label = "Remove Uniform"
152 bl_description = "Remove the selected uniform from the material"
154 def execute(self, context):
155 mat = context.active_object.active_material
156 mat.uniforms.remove(mat.active_uniform_index)
157 mat.active_uniform_index = min(mat.active_uniform_index, len(mat.uniforms)-1)
161 def menu_func_export(self, context):
162 self.layout.operator(ExportMspGLData.bl_idname, text="Msp GL data")
163 self.layout.operator(ExportMspGLAnimation.bl_idname, text="Msp GL animation")
164 self.layout.operator(ExportMspGLScene.bl_idname, text="Msp GL scene")
166 classes = [ExportMspGLData, ExportMspGLAnimation, ExportMspGLScene, AddUniform, RemoveUniform]
170 bpy.utils.register_class(c)
172 bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
174 from .properties import register_properties
175 register_properties()
179 bpy.utils.unregister_class(c)
181 bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
183 from .properties import unregister_properties
184 unregister_properties()