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 execute(self, context):
22 exporter = self.create_exporter()
23 self.prepare_exporter(exporter)
24 exporter.export_to_file(context, self.filepath)
27 def create_exporter(self):
28 raise Exception("create_exporter must be overridden")
30 def prepare_exporter(self, exporter):
31 for k, v in self.as_keywords().items():
32 setattr(exporter, k, v)
34 class ExportMspGLMeshBase(ExportMspGLBase):
35 use_strips = bpy.props.BoolProperty(name="Use strips", description="Combine faces into triangle strips", default=True)
36 use_degen_tris = bpy.props.BoolProperty(name="Use degen tris", description="Concatenate triangle strips with degenerate triangles", default=False)
38 def draw(self, context):
39 self.general_col = self.layout.column()
41 col = self.layout.column()
42 col.label(text="Triangle strips")
43 col.prop(self, "use_strips")
44 col.prop(self, "use_degen_tris")
46 class ExportMspGLMesh(bpy.types.Operator, ExportMspGLMeshBase):
47 bl_idname = "export_mesh.mspgl_mesh"
48 bl_label = "Export Msp GL mesh"
50 filename_ext = ".mesh"
52 def create_exporter(self):
53 from .export_mesh import MeshExporter
56 class ExportMspGLObject(bpy.types.Operator, ExportMspGLMeshBase):
57 bl_idname = "export_mesh.mspgl_object"
58 bl_label = "Export Msp GL object"
60 filename_ext = ".object"
62 single_file = bpy.props.BoolProperty(name="Single file", description="Write all data into a single file", default=True)
63 shared_resources = bpy.props.BoolProperty(name="Shared resources", description="Use global names for resource files to enable sharing", default=True)
65 export_lods = bpy.props.BoolProperty(name="Export LoDs", description="Export all levels of detail", default=True)
66 use_textures = bpy.props.BoolProperty(name="Use textures", description="Use textures in the exported object", default=True)
68 def create_exporter(self):
69 from .export_object import ObjectExporter
70 return ObjectExporter()
72 def draw(self, context):
75 self.general_col.prop(self, "export_lods")
76 self.general_col.prop(self, "use_textures")
78 col = self.layout.column()
79 col.label(text="Files")
80 col.prop(self, "single_file")
81 if not self.single_file:
82 col.prop(self, "shared_resources")
84 class ExportMspGLArmature(bpy.types.Operator, ExportMspGLBase):
85 bl_idname = "export.mspgl_armature"
86 bl_label = "Export Msp GL armature"
88 filename_ext = ".arma"
90 def create_exporter(self):
91 from .export_armature import ArmatureExporter
92 return ArmatureExporter()
94 class ExportMspGLAnimation(bpy.types.Operator, ExportMspGLBase):
95 bl_idname = "export.mspgl_animation"
96 bl_label = "Export Msp GL animation"
98 filename_ext = ".anim"
100 export_all = bpy.props.BoolProperty(name="Export all animations", description="Export all animations present on the selected objects' NLA tracks")
101 collection = bpy.props.BoolProperty(name="As a collection", description="Export the animations as a single collection file", default=True)
102 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)
104 def check(self, context):
107 ext = ".mdc" if self.export_all and self.collection else ".anim"
108 ext_changed = (ext!=self.filename_ext)
110 if self.filepath.endswith(self.filename_ext):
111 self.filepath = self.filepath[:-len(self.filename_ext)]
112 self.filename_ext = ext
114 super_result = super().check(context)
116 return ext_changed or super_result
118 def create_exporter(self):
119 from .export_animation import AnimationExporter
120 return AnimationExporter()
122 def draw(self, context):
123 col = self.layout.column()
124 col.prop(self, "export_all")
126 col.prop(self, "collection")
127 col.prop(self, "looping_threshold")
129 class ExportMspGLScene(bpy.types.Operator, ExportMspGLBase):
130 bl_idname = "export_scene.mspgl_scene"
131 bl_label = "Export Msp GL scene"
133 filename_ext = ".scene"
135 selected_only = bpy.props.BoolProperty(name="Selected objects only", description="Only export the selected objects")
136 visible_collections = bpy.props.BoolProperty(name="Visible collections only", description="Only export objects in visible collections", default=True)
137 resource_collection = bpy.props.BoolProperty(name="Resource collection", description="Put resources to a single collection file", default=True)
138 skip_existing = bpy.props.BoolProperty(name="Skip existing files", description="Skip resources that already exist as files", default=True)
140 def create_exporter(self):
141 from .export_scene import SceneExporter
142 return SceneExporter()
144 def draw(self, context):
145 col = self.layout.column()
146 col.prop(self, "selected_only")
147 col.prop(self, "visible_collections")
148 col.prop(self, "resource_collection")
149 if self.resource_collection:
150 col.prop(self, "skip_existing")
152 class ExportMspGLCamera(bpy.types.Operator, ExportMspGLBase):
153 bl_idname = "export.mspgl_camera"
154 bl_label = "Export Msp GL camera"
156 filename_ext = ".camera"
158 def create_exporter(self):
159 from .export_camera import CameraExporter
160 return CameraExporter()
162 def menu_func_export(self, context):
163 self.layout.operator(ExportMspGLMesh.bl_idname, text="Msp GL mesh")
164 self.layout.operator(ExportMspGLObject.bl_idname, text="Msp GL object")
165 self.layout.operator(ExportMspGLArmature.bl_idname, text="Msp GL armature")
166 self.layout.operator(ExportMspGLAnimation.bl_idname, text="Msp GL animation")
167 self.layout.operator(ExportMspGLScene.bl_idname, text="Msp GL scene")
168 self.layout.operator(ExportMspGLCamera.bl_idname, text="Msp GL camera")
170 classes = [ExportMspGLMesh, ExportMspGLObject, ExportMspGLArmature, ExportMspGLAnimation, ExportMspGLScene, ExportMspGLCamera]
174 bpy.utils.register_class(c)
176 bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
178 from .properties import register_properties
179 register_properties()
183 bpy.utils.unregister_class(c)
185 bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
187 from .properties import unregister_properties
188 unregister_properties()