2 "name": "Msp GL datafiles",
3 "author": "Mikko Rasa",
4 "location": "File > Export",
5 "description": "Export Msp GL data",
6 "category": "Import-Export" }
10 for sub in "armature", "export_armature", "export_mesh", "export_object", "export_scene", "mesh", "outfile", "properties", "util":
12 imp.reload(locals()[sub])
15 from bpy_extras.io_utils import ExportHelper
17 class ExportMspGLBase(ExportHelper):
18 show_progress = bpy.props.BoolProperty(name="Show progress", description="Display progress indicator while exporting", default=True)
20 def execute(self, context):
21 exporter = self.create_exporter()
22 self.prepare_exporter(exporter)
23 exporter.export(context, self.filepath)
26 def create_exporter(self):
27 raise Exception("create_exporter must be overridden")
29 def prepare_exporter(self, exporter):
30 for k, v in self.as_keywords().items():
31 setattr(exporter, k, v)
33 class ExportMspGLMeshBase(ExportMspGLBase):
34 use_strips = bpy.props.BoolProperty(name="Use strips", description="Combine faces into triangle strips", default=True)
35 use_degen_tris = bpy.props.BoolProperty(name="Use degen tris", description="Concatenate triangle strips with degenerate triangles", default=False)
36 max_strip_len = bpy.props.IntProperty(name="Max strip length", description="Maximum length for a triangle strip", default=1024, min=4, max=16384)
37 optimize_cache = bpy.props.BoolProperty(name="Optimize cache", description="Optimize element order for vertex cache", default=True)
38 cache_size = bpy.props.IntProperty(name="Cache size", description="Simulated vertex cache size used in optimization", default=64, min=8, max=1024)
39 export_lines = bpy.props.BoolProperty(name="Export lines", description="Export edges without faces as lines", default=False)
40 export_uv = bpy.props.EnumProperty(name="Export UV", description="Export UV coordinates", default="UNIT0",
41 items=(("NONE", "None", "No UV coordinates are exported"),
42 ("UNIT0", "Unit 0", "UV coordinates for unit 0 are exported"),
43 ("ALL", "All", "All UV coordinates are exported")))
44 tbn_vecs = bpy.props.BoolProperty(name="TBN vectors", description="Compute tangent and binormal vectors for vertices", default=False)
45 tbn_uvtex = bpy.props.StringProperty(name="TBN UV layer", description="UV layer to use as basis for TBN vectors", default="")
46 compound = bpy.props.BoolProperty(name="Compound", description="Combine all selected objects into one for exporting", default=False)
47 smoothing = bpy.props.EnumProperty(name="Smoothing", description="Smoothing method to use", default="MSPGL",
48 items=(("NONE", "None", "No smoothing"),
49 ("BLENDER", "Blender", "Use Blender's vertex normals"),
50 ("MSPGL", "MspGL", "Compute vertex normals internally")))
51 export_groups = bpy.props.BoolProperty(name="Vertex groups", description="Export vertex groups and weights", default=False)
53 def draw(self, context):
54 col = self.layout.column()
55 col.prop(self, "export_lines")
56 col.prop(self, "compound")
57 col.prop(self, "smoothing")
58 col.prop(self, "export_groups")
59 self.general_col = col
61 self.layout.separator()
63 col = self.layout.column()
64 col.label("Triangle strips")
65 col.prop(self, "use_strips")
66 col.prop(self, "use_degen_tris")
67 col.prop(self, "max_strip_len")
69 self.layout.separator()
71 col = self.layout.column()
72 col.label("Texturing")
73 col.prop(self, "export_uv")
74 col.prop(self, "tbn_vecs")
75 col.prop(self, "tbn_uvtex")
76 self.texturing_col = col
78 self.layout.separator()
80 col = self.layout.column()
81 col.label("Vertex cache")
82 col.prop(self, "optimize_cache")
83 col.prop(self, "cache_size")
85 class ExportMspGLMesh(bpy.types.Operator, ExportMspGLMeshBase):
86 bl_idname = "export_mesh.mspgl_mesh"
87 bl_label = "Export Msp GL mesh"
89 filename_ext = ".mesh"
91 def create_exporter(self):
92 from .export_mesh import MeshExporter
95 class ExportMspGLObject(bpy.types.Operator, ExportMspGLMeshBase):
96 bl_idname = "export_mesh.mspgl_object"
97 bl_label = "Export Msp GL object"
99 filename_ext = ".object"
101 external_tech = bpy.props.BoolProperty(name="External technique", description="Use an external technique specified in the object's properties", default=True)
103 textures = bpy.props.EnumProperty(name="Textures", description="Export textures", default="REF",
104 items=(("NONE", "None", "Ignore textures"),
105 ("REF", "Referenced", "Reference external data"),
106 ("INLINE", "Inline", "Embed textures in the object")))
107 material_tex = bpy.props.BoolProperty(name="Material texture", description="Generate a texture based on material colors", default=False)
108 srgb_colors = bpy.props.BoolProperty(name="sRGB colors", description="Export material colors as sRGB instead of linear", default=True)
110 separate_mesh = bpy.props.BoolProperty(name="Separate mesh", description="Write mesh data into a separate file", default=False)
111 separate_tech = bpy.props.BoolProperty(name="Separate technique", description="Write technique data into a separate file", default=False)
112 shared_tech = bpy.props.BoolProperty(name="Shared technique", description="Use material name for technique file to enable sharing", default=True)
114 def create_exporter(self):
115 from .export_object import ObjectExporter
116 return ObjectExporter()
118 def draw(self, context):
119 super().draw(context)
121 col = self.general_col
122 col.prop(self, "external_tech")
124 col = self.texturing_col
125 col.prop(self, "textures")
126 col.prop(self, "material_tex")
127 col.prop(self, "srgb_colors")
129 self.layout.separator();
131 col = self.layout.column()
133 col.prop(self, "separate_mesh")
134 col.prop(self, "separate_tech")
135 if self.separate_tech:
136 col.prop(self, "shared_tech")
138 class ExportMspGLArmature(bpy.types.Operator, ExportMspGLBase):
139 bl_idname = "export.mspgl_armature"
140 bl_label = "Export Msp GL armature"
142 filename_ext = ".arma"
144 def create_exporter(self):
145 from .export_armature import ArmatureExporter
146 return ArmatureExporter()
148 class ExportMspGLScene(bpy.types.Operator, ExportMspGLBase):
149 bl_idname = "export_scene.mspgl_scene"
150 bl_label = "Export Msp GL scene"
152 filename_ext = ".scene"
154 external_tech = bpy.props.BoolProperty(name="External techniques", description="Use external techniques specified in objects' properties", default=True)
155 resource_collection = bpy.props.BoolProperty(name="Resource collection", description="Put resources to a single collection file", default=True)
157 def create_exporter(self):
158 from .export_scene import SceneExporter
159 return SceneExporter()
161 def draw(self, context):
162 col = self.layout.column()
163 col.prop(self, "resource_collection")
165 def menu_func_export(self, context):
166 self.layout.operator(ExportMspGLMesh.bl_idname, text="Msp GL mesh")
167 self.layout.operator(ExportMspGLObject.bl_idname, text="Msp GL object")
168 self.layout.operator(ExportMspGLArmature.bl_idname, text="Msp GL armature")
169 self.layout.operator(ExportMspGLScene.bl_idname, text="Msp GL scene")
171 from .properties import MspGLProperties
174 bpy.utils.register_module(__name__)
176 bpy.types.INFO_MT_file_export.append(menu_func_export)
178 from .properties import register_properties
179 register_properties();
182 bpy.utils.unregister_module(__name__)
184 bpy.types.INFO_MT_file_export.remove(menu_func_export)
186 if __name__=="__main__":