5 class ExportHelper(bpy_extras.io_utils.ExportHelper):
6 def set_extension(self, ext):
7 ext_changed = (ext!=self.filename_ext)
9 if self.filepath.endswith(self.filename_ext):
10 self.filepath = self.filepath[:-len(self.filename_ext)]
11 self.filename_ext = ext
14 class ExportMspGLData(bpy.types.Operator):
15 bl_idname = "export.mspgl_data"
16 bl_label = "Export Msp GL data"
17 bl_description = "Export object data in Msp GL format"
19 filepath: bpy.props.StringProperty(name="File path", description="File path for exporting the data", subtype='FILE_PATH')
20 collection: bpy.props.BoolProperty(name="As a collection", description="Export all data as a single collection file", default=False)
21 shared_resources: bpy.props.BoolProperty(name="Shared resources", description="Use global names for resource files to enable sharing", default=True)
22 debug_mode: bpy.props.BoolProperty(name="Debug mode", description="Enable debugging output to console")
25 def poll(cls, context):
26 return len(context.selected_objects)>0
28 def invoke(self, context, event):
29 blend_filepath = context.blend_data.filepath
31 self.filepath = os.path.splitext(blend_filepath)[0]+".mdc"
33 self.filepath = "data.mdc"
34 context.window_manager.fileselect_add(self)
35 return {'RUNNING_MODAL'}
37 def execute(self, context):
38 from .context import ExportContext
39 from .export import DataExporter
41 ex_ctx = ExportContext(context, verbose=self.debug_mode)
42 exporter = DataExporter()
43 ex_ctx.export(exporter.export_to_file, self.filepath,
44 collection=self.collection,
45 shared_resources=self.shared_resources)
48 def draw(self, context):
49 col = self.layout.column()
50 col.label(text="Files")
51 col.prop(self, "collection")
52 col.prop(self, "shared_resources")
54 self.layout.separator()
56 col = self.layout.column()
57 col.prop(self, "debug_mode")
59 class ExportMspGLAnimation(bpy.types.Operator, ExportHelper):
60 bl_idname = "export.mspgl_animation"
61 bl_label = "Export Msp GL animation"
62 bl_description = "Export one or more animations in Msp GL format"
64 filename_ext = ".anim"
66 export_all: bpy.props.BoolProperty(name="Export all animations", description="Export all animations present on the selected objects' NLA tracks")
67 collection: bpy.props.BoolProperty(name="As a collection", description="Export the animations as a single collection file", default=True)
68 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)
69 debug_mode: bpy.props.BoolProperty(name="Debug mode", description="Enable debugging output to console")
71 def check(self, context):
72 ext_changed = self.set_extension(".mdc" if self.export_all and self.collection else ".anim")
73 super_result = super().check(context)
74 return ext_changed or super_result
76 def execute(self, context):
77 from .context import ExportContext
78 from .export_animation import AnimationExporter
80 ex_ctx = ExportContext(context, verbose=self.debug_mode)
81 exporter = AnimationExporter()
82 ex_ctx.export(exporter.export_to_file, self.filepath,
83 export_all=self.export_all,
84 collection=self.collection,
85 looping_threshold=looping_threshold)
88 def draw(self, context):
89 col = self.layout.column()
90 col.prop(self, "export_all")
92 col.prop(self, "collection")
93 col.prop(self, "looping_threshold")
95 self.layout.separator()
97 col = self.layout.column()
98 col.prop(self, "debug_mode")
100 class ExportMspGLScene(bpy.types.Operator, ExportHelper):
101 bl_idname = "export_scene.mspgl_scene"
102 bl_label = "Export Msp GL scene"
103 bl_description = "Export the active scene in Msp GL format"
105 filename_ext = ".scene"
107 selected_only: bpy.props.BoolProperty(name="Selected objects only", description="Only export the selected objects", default=False)
108 visible_only: bpy.props.BoolProperty(name="Visible only", description="Only export objects in visible collections", default=True)
109 collection: bpy.props.BoolProperty(name="As a collection", description="Export the scene and all resources as a single collection file", default=False)
110 skip_existing: bpy.props.BoolProperty(name="Skip existing files", description="Skip resources that already exist as files", default=True)
111 debug_mode: bpy.props.BoolProperty(name="Debug mode", description="Enable debugging output to console")
113 def invoke(self, context, event):
114 self.filepath = context.scene.name+".scene"
115 return super().invoke(context, event)
117 def check(self, context):
118 ext_changed = self.set_extension(".mdc" if self.collection else ".scene")
119 super_result = super().check(context)
120 return ext_changed or super_result
122 def execute(self, context):
123 from .context import ExportContext
124 from .export_scene import SceneExporter
126 ex_ctx = ExportContext(context, verbose=self.debug_mode)
127 exporter = SceneExporter()
128 ex_ctx.export(exporter.export_to_file, self.filepath,
129 selected_only=self.selected_only,
130 visible_only=self.visible_only,
131 collection=self.collection,
132 skip_existing=self.skip_existing)
135 def draw(self, context):
136 col = self.layout.column()
137 col.prop(self, "selected_only")
138 col.prop(self, "visible_only")
139 col.prop(self, "collection")
141 col.prop(self, "skip_existing")
143 self.layout.separator()
145 col = self.layout.column()
146 col.prop(self, "debug_mode")
148 class ExportMspGLProject(bpy.types.Operator):
149 bl_idname = "export.mspgl_project"
150 bl_label = "Export Msp GL project"
151 bl_description = "Export the entire project in Msp GL format"
153 directory: bpy.props.StringProperty(name="Directory", description="Directory for exporting the data", subtype='FILE_PATH')
154 debug_mode: bpy.props.BoolProperty(name="Debug mode", description="Enable debugging output to console")
156 def invoke(self, context, event):
157 blend_filepath = context.blend_data.filepath
159 self.directory = os.path.split(blend_filepath)[0]
160 context.window_manager.fileselect_add(self)
161 return {'RUNNING_MODAL'}
163 def execute(self, context):
164 from .context import ExportContext
165 from .export import ProjectExporter
167 ex_ctx = ExportContext(context, verbose=self.debug_mode)
168 exporter = ProjectExporter()
169 ex_ctx.export(exporter.export_to_directory, self.directory)
172 def draw(self, context):
173 col = self.layout.column()
174 col.prop(self, "debug_mode")
176 class AddRenderMethod(bpy.types.Operator):
177 bl_idname = "material.add_render_method"
178 bl_label = "Add Render Method"
179 bl_description = "Add a new render method to the material"
181 def execute(self, context):
182 mat = context.active_object.active_material
183 mat.render_methods.add()
184 mat.active_render_method_index = len(mat.uniforms)-1
188 class RemoveRenderMethod(bpy.types.Operator):
189 bl_idname = "material.remove_render_method"
190 bl_label = "Remove Render Method"
191 bl_description = "Remove the selected render method from the material"
193 def execute(self, context):
194 mat = context.active_object.active_material
195 mat.render_methods.remove(mat.active_render_method_index)
196 mat.active_render_method_index = min(mat.active_render_method_index, len(mat.render_methods)-1)
200 class AddUniform(bpy.types.Operator):
201 bl_idname = "material.add_uniform"
202 bl_label = "Add Uniform"
203 bl_description = "Add a new uniform value to the material"
205 def execute(self, context):
206 mat = context.active_object.active_material
208 mat.active_uniform_index = len(mat.uniforms)-1
212 class RemoveUniform(bpy.types.Operator):
213 bl_idname = "material.remove_uniform"
214 bl_label = "Remove Uniform"
215 bl_description = "Remove the selected uniform from the material"
217 def execute(self, context):
218 mat = context.active_object.active_material
219 mat.uniforms.remove(mat.active_uniform_index)
220 mat.active_uniform_index = min(mat.active_uniform_index, len(mat.uniforms)-1)
224 classes = [ExportMspGLData, ExportMspGLAnimation, ExportMspGLScene, ExportMspGLProject, AddRenderMethod,
225 RemoveRenderMethod, AddUniform, RemoveUniform]
227 def register_operators():
229 bpy.utils.register_class(c)
231 def unregister_operators():
233 bpy.utils.unregister_class(c)