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)
24 def poll(cls, context):
25 return len(context.selected_objects)>0
27 def invoke(self, context, event):
28 blend_filepath = context.blend_data.filepath
30 self.filepath = os.path.splitext(blend_filepath)[0]+".mdc"
32 self.filepath = "data.mdc"
33 context.window_manager.fileselect_add(self)
34 return {'RUNNING_MODAL'}
36 def execute(self, context):
37 from .export import DataExporter
38 exporter = DataExporter()
39 exporter.collection = self.collection
40 exporter.shared_resources = self.shared_resources
41 exporter.export_to_file(context, self.filepath)
44 def draw(self, context):
45 col = self.layout.column()
46 col.label(text="Files")
47 col.prop(self, "collection")
48 col.prop(self, "shared_resources")
50 class ExportMspGLAnimation(bpy.types.Operator, ExportHelper):
51 bl_idname = "export.mspgl_animation"
52 bl_label = "Export Msp GL animation"
53 bl_description = "Export one or more animations in Msp GL format"
55 filename_ext = ".anim"
57 export_all: bpy.props.BoolProperty(name="Export all animations", description="Export all animations present on the selected objects' NLA tracks")
58 collection: bpy.props.BoolProperty(name="As a collection", description="Export the animations as a single collection file", default=True)
59 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)
61 def check(self, context):
62 ext_changed = self.set_extension(".mdc" if self.export_all and self.collection else ".anim")
63 super_result = super().check(context)
64 return ext_changed or super_result
66 def execute(self, context):
67 from .export_animation import AnimationExporter
68 exporter = AnimationExporter()
69 exporter.export_all = self.export_all
70 exporter.collection = self.collection
71 exporter.looping_threshold = self.looping_threshold
72 exporter.export_to_file(context, self.filepath)
75 def draw(self, context):
76 col = self.layout.column()
77 col.prop(self, "export_all")
79 col.prop(self, "collection")
80 col.prop(self, "looping_threshold")
82 class ExportMspGLScene(bpy.types.Operator, ExportHelper):
83 bl_idname = "export_scene.mspgl_scene"
84 bl_label = "Export Msp GL scene"
85 bl_description = "Export the active scene in Msp GL format"
87 filename_ext = ".scene"
89 selected_only: bpy.props.BoolProperty(name="Selected objects only", description="Only export the selected objects", default=False)
90 visible_only: bpy.props.BoolProperty(name="Visible only", description="Only export objects in visible collections", default=True)
91 collection: bpy.props.BoolProperty(name="As a collection", description="Export the scene and all resources as a single collection file", default=False)
92 skip_existing: bpy.props.BoolProperty(name="Skip existing files", description="Skip resources that already exist as files", default=True)
94 def invoke(self, context, event):
95 self.filepath = context.scene.name+".scene"
96 return super().invoke(context, event)
98 def check(self, context):
99 ext_changed = self.set_extension(".mdc" if self.collection else ".scene")
100 super_result = super().check(context)
101 return ext_changed or super_result
103 def execute(self, context):
104 from .export_scene import SceneExporter
105 exporter = SceneExporter()
106 exporter.selected_only = self.selected_only
107 exporter.visible_only = self.visible_only
108 exporter.collection = self.collection
109 exporter.skip_existing = self.skip_existing
110 exporter.export_to_file(context, self.filepath)
113 def draw(self, context):
114 col = self.layout.column()
115 col.prop(self, "selected_only")
116 col.prop(self, "visible_only")
117 col.prop(self, "collection")
119 col.prop(self, "skip_existing")
121 class ExportMspGLProject(bpy.types.Operator):
122 bl_idname = "export.mspgl_project"
123 bl_label = "Export Msp GL project"
124 bl_description = "Export the entire project in Msp GL format"
126 directory: bpy.props.StringProperty(name="Directory", description="Directory for exporting the data", subtype='FILE_PATH')
128 def invoke(self, context, event):
129 blend_filepath = context.blend_data.filepath
131 self.directory = os.path.split(blend_filepath)[0]
132 context.window_manager.fileselect_add(self)
133 return {'RUNNING_MODAL'}
135 def execute(self, context):
136 from .export import ProjectExporter
137 exporter = ProjectExporter()
138 exporter.export_to_directory(context, self.directory)
141 class AddRenderMethod(bpy.types.Operator):
142 bl_idname = "material.add_render_method"
143 bl_label = "Add Render Method"
144 bl_description = "Add a new render method to the material"
146 def execute(self, context):
147 mat = context.active_object.active_material
148 mat.render_methods.add()
149 mat.active_render_method_index = len(mat.uniforms)-1
153 class RemoveRenderMethod(bpy.types.Operator):
154 bl_idname = "material.remove_render_method"
155 bl_label = "Remove Render Method"
156 bl_description = "Remove the selected render method from the material"
158 def execute(self, context):
159 mat = context.active_object.active_material
160 mat.render_methods.remove(mat.active_render_method_index)
161 mat.active_render_method_index = min(mat.active_render_method_index, len(mat.render_methods)-1)
165 class AddUniform(bpy.types.Operator):
166 bl_idname = "material.add_uniform"
167 bl_label = "Add Uniform"
168 bl_description = "Add a new uniform value to the material"
170 def execute(self, context):
171 mat = context.active_object.active_material
173 mat.active_uniform_index = len(mat.uniforms)-1
177 class RemoveUniform(bpy.types.Operator):
178 bl_idname = "material.remove_uniform"
179 bl_label = "Remove Uniform"
180 bl_description = "Remove the selected uniform from the material"
182 def execute(self, context):
183 mat = context.active_object.active_material
184 mat.uniforms.remove(mat.active_uniform_index)
185 mat.active_uniform_index = min(mat.active_uniform_index, len(mat.uniforms)-1)
189 classes = [ExportMspGLData, ExportMspGLAnimation, ExportMspGLScene, ExportMspGLProject, AddRenderMethod,
190 RemoveRenderMethod, AddUniform, RemoveUniform]
192 def register_operators():
194 bpy.utils.register_class(c)
196 def unregister_operators():
198 bpy.utils.unregister_class(c)