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])
19 class ExportHelper(bpy_extras.io_utils.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 class ExportMspGLData(bpy.types.Operator):
29 bl_idname = "export.mspgl_data"
30 bl_label = "Export Msp GL data"
31 bl_description = "Export object data in Msp GL format"
33 filepath: bpy.props.StringProperty(name="File path", description="File path for exporting the data", subtype='FILE_PATH')
34 collection: bpy.props.BoolProperty(name="As a collection", description="Export all data as a single collection file", default=False)
35 shared_resources: bpy.props.BoolProperty(name="Shared resources", description="Use global names for resource files to enable sharing", default=True)
38 def poll(cls, context):
39 return len(context.selected_objects)>0
41 def invoke(self, context, event):
42 blend_filepath = context.blend_data.filepath
44 self.filepath = os.path.splitext(blend_filepath)[0]+".mdc"
46 self.filepath = "data.mdc"
47 context.window_manager.fileselect_add(self)
48 return {'RUNNING_MODAL'}
50 def execute(self, context):
51 from .export import DataExporter
52 exporter = DataExporter()
53 exporter.collection = self.collection
54 exporter.shared_resources = self.shared_resources
55 exporter.export_to_file(context, self.filepath)
58 def draw(self, context):
59 col = self.layout.column()
60 col.label(text="Files")
61 col.prop(self, "collection")
62 col.prop(self, "shared_resources")
64 class ExportMspGLAnimation(bpy.types.Operator, ExportHelper):
65 bl_idname = "export.mspgl_animation"
66 bl_label = "Export Msp GL animation"
67 bl_description = "Export one or more animations in Msp GL format"
69 filename_ext = ".anim"
71 export_all: bpy.props.BoolProperty(name="Export all animations", description="Export all animations present on the selected objects' NLA tracks")
72 collection: bpy.props.BoolProperty(name="As a collection", description="Export the animations as a single collection file", default=True)
73 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)
75 def check(self, context):
76 ext_changed = self.set_extension(".mdc" if self.export_all and self.collection else ".anim")
77 super_result = super().check(context)
78 return ext_changed or super_result
80 def execute(self, context):
81 from .export_animation import AnimationExporter
82 exporter = AnimationExporter()
83 exporter.export_all = self.export_all
84 exporter.collection = self.collection
85 exporter.looping_threshold = self.looping_threshold
86 exporter.export_to_file(context, self.filepath)
89 def draw(self, context):
90 col = self.layout.column()
91 col.prop(self, "export_all")
93 col.prop(self, "collection")
94 col.prop(self, "looping_threshold")
96 class ExportMspGLScene(bpy.types.Operator, ExportHelper):
97 bl_idname = "export_scene.mspgl_scene"
98 bl_label = "Export Msp GL scene"
99 bl_description = "Export the active scene in Msp GL format"
101 filename_ext = ".scene"
103 selected_only: bpy.props.BoolProperty(name="Selected objects only", description="Only export the selected objects", default=False)
104 visible_only: bpy.props.BoolProperty(name="Visible only", description="Only export objects in visible collections", default=True)
105 collection: bpy.props.BoolProperty(name="As a collection", description="Export the scene and all resources as a single collection file", default=False)
106 skip_existing: bpy.props.BoolProperty(name="Skip existing files", description="Skip resources that already exist as files", default=True)
108 def invoke(self, context, event):
109 self.filepath = context.scene.name+".scene"
110 return super().invoke(context, event)
112 def check(self, context):
113 ext_changed = self.set_extension(".mdc" if self.collection else ".scene")
114 super_result = super().check(context)
115 return ext_changed or super_result
117 def execute(self, context):
118 from .export_scene import SceneExporter
119 exporter = SceneExporter()
120 exporter.selected_only = self.selected_only
121 exporter.visible_only = self.visible_only
122 exporter.collection = self.collection
123 exporter.skip_existing = self.skip_existing
124 exporter.export_to_file(context, self.filepath)
127 def draw(self, context):
128 col = self.layout.column()
129 col.prop(self, "selected_only")
130 col.prop(self, "visible_only")
131 col.prop(self, "collection")
133 col.prop(self, "skip_existing")
135 class AddUniform(bpy.types.Operator):
136 bl_idname = "material.add_uniform"
137 bl_label = "Add Uniform"
138 bl_description = "Add a new uniform value to the material"
140 def execute(self, context):
141 mat = context.active_object.active_material
143 mat.active_uniform_index = len(mat.uniforms)-1
147 class RemoveUniform(bpy.types.Operator):
148 bl_idname = "material.remove_uniform"
149 bl_label = "Remove Uniform"
150 bl_description = "Remove the selected uniform from the material"
152 def execute(self, context):
153 mat = context.active_object.active_material
154 mat.uniforms.remove(mat.active_uniform_index)
155 mat.active_uniform_index = min(mat.active_uniform_index, len(mat.uniforms)-1)
159 def menu_func_export(self, context):
160 self.layout.operator(ExportMspGLData.bl_idname, text="Msp GL data")
161 self.layout.operator(ExportMspGLAnimation.bl_idname, text="Msp GL animation")
162 self.layout.operator(ExportMspGLScene.bl_idname, text="Msp GL scene")
164 classes = [ExportMspGLData, ExportMspGLAnimation, ExportMspGLScene, AddUniform, RemoveUniform]
168 bpy.utils.register_class(c)
170 bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
172 from .properties import register_properties
173 register_properties()
177 bpy.utils.unregister_class(c)
179 bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
181 from .properties import unregister_properties
182 unregister_properties()