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 def execute(self, context):
19 exporter = self.create_exporter()
20 self.prepare_exporter(exporter)
21 exporter.export(context, self.filepath)
24 def create_exporter(self):
25 raise Exception("create_exporter must be overridden")
27 def prepare_exporter(self, exporter):
28 for k, v in self.as_keywords().items():
29 setattr(exporter, k, v)
31 class ExportMspGLMeshBase(ExportMspGLBase):
32 use_strips = bpy.props.BoolProperty(name="Use strips", description="Combine faces into triangle strips", default=True)
33 use_degen_tris = bpy.props.BoolProperty(name="Use degen tris", description="Concatenate triangle strips with degenerate triangles", default=False)
34 max_strip_len = bpy.props.IntProperty(name="Max strip length", description="Maximum length for a triangle strip", default=1024, min=4, max=16384)
35 optimize_cache = bpy.props.BoolProperty(name="Optimize cache", description="Optimize element order for vertex cache", default=True)
36 cache_size = bpy.props.IntProperty(name="Cache size", description="Simulated vertex cache size used in optimization", default=64, min=8, max=1024)
37 export_lines = bpy.props.BoolProperty(name="Export lines", description="Export edges without faces as lines", default=False)
38 export_uv = bpy.props.EnumProperty(name="Export UV", description="Export UV coordinates", default="UNIT0",
39 items=(("NONE", "None", "No UV coordinates are exported"),
40 ("UNIT0", "Unit 0", "UV coordinates for unit 0 are exported"),
41 ("ALL", "All", "All UV coordinates are exported")))
42 tbn_vecs = bpy.props.BoolProperty(name="TBN vectors", description="Compute tangent and binormal vectors for vertices", default=False)
43 tbn_uvtex = bpy.props.StringProperty(name="TBN UV layer", description="UV layer to use as basis for TBN vectors", default="")
44 compound = bpy.props.BoolProperty(name="Compound", description="Combine all selected objects into one for exporting", default=False)
45 smoothing = bpy.props.EnumProperty(name="Smoothing", description="Smoothing method to use", default="MSPGL",
46 items=(("NONE", "None", "No smoothing"),
47 ("BLENDER", "Blender", "Use Blender's vertex normals"),
48 ("MSPGL", "MspGL", "Compute vertex normals internally")))
49 export_groups = bpy.props.BoolProperty(name="Vertex groups", description="Export vertex groups and weights", default=False)
51 def draw(self, context):
52 col = self.layout.column()
53 col.prop(self, "export_lines")
54 col.prop(self, "compound")
55 col.prop(self, "smoothing")
56 col.prop(self, "export_groups")
57 self.general_col = col
59 self.layout.separator()
61 col = self.layout.column()
62 col.label("Triangle strips")
63 col.prop(self, "use_strips")
64 col.prop(self, "use_degen_tris")
65 col.prop(self, "max_strip_len")
67 self.layout.separator()
69 col = self.layout.column()
70 col.label("Texturing")
71 col.prop(self, "export_uv")
72 col.prop(self, "tbn_vecs")
73 col.prop(self, "tbn_uvtex")
74 self.texturing_col = col
76 self.layout.separator()
78 col = self.layout.column()
79 col.label("Vertex cache")
80 col.prop(self, "optimize_cache")
81 col.prop(self, "cache_size")
83 class ExportMspGLMesh(bpy.types.Operator, ExportMspGLMeshBase):
84 bl_idname = "export_mesh.mspgl_mesh"
85 bl_label = "Export Msp GL mesh"
87 filename_ext = ".mesh"
89 def create_exporter(self):
90 from .export_mesh import MeshExporter
93 class ExportMspGLObject(bpy.types.Operator, ExportMspGLMeshBase):
94 bl_idname = "export_mesh.mspgl_object"
95 bl_label = "Export Msp GL object"
97 filename_ext = ".object"
99 external_tech = bpy.props.BoolProperty(name="External technique", description="Use an external technique specified in the object's properties", default=True)
101 textures = bpy.props.EnumProperty(name="Textures", description="Export textures", default="REF",
102 items=(("NONE", "None", "Ignore textures"),
103 ("REF", "Referenced", "Reference external data"),
104 ("INLINE", "Inline", "Embed textures in the object")))
105 material_tex = bpy.props.BoolProperty(name="Material texture", description="Generate a texture based on material colors", default=False)
106 srgb_colors = bpy.props.BoolProperty(name="sRGB colors", description="Export material colors as sRGB instead of linear", default=True)
108 separate_mesh = bpy.props.BoolProperty(name="Separate mesh", description="Write mesh data into a separate file", default=False)
109 separate_tech = bpy.props.BoolProperty(name="Separate technique", description="Write technique data into a separate file", default=False)
110 shared_tech = bpy.props.BoolProperty(name="Shared technique", description="Use material name for technique file to enable sharing", default=True)
112 def create_exporter(self):
113 from .export_object import ObjectExporter
114 return ObjectExporter()
116 def draw(self, context):
117 super().draw(context)
119 col = self.general_col
120 col.prop(self, "external_tech")
122 col = self.texturing_col
123 col.prop(self, "textures")
124 col.prop(self, "material_tex")
125 col.prop(self, "srgb_colors")
127 self.layout.separator();
129 col = self.layout.column()
131 col.prop(self, "separate_mesh")
132 col.prop(self, "separate_tech")
133 if self.separate_tech:
134 col.prop(self, "shared_tech")
136 class ExportMspGLArmature(bpy.types.Operator, ExportMspGLBase):
137 bl_idname = "export.mspgl_armature"
138 bl_label = "Export Msp GL armature"
140 filename_ext = ".arma"
142 def create_exporter(self):
143 from .export_armature import ArmatureExporter
144 return ArmatureExporter()
146 class ExportMspGLScene(bpy.types.Operator, ExportMspGLBase):
147 bl_idname = "export.mspgl_scene"
148 bl_label = "Export Msp GL scene"
150 filename_ext = ".scene"
152 external_tech = bpy.props.BoolProperty(name="External techniques", description="Use external techniques specified in objects' properties", default=True)
153 resource_collection = bpy.props.BoolProperty(name="Resource collection", description="Put resources to a single collection file", default=True)
155 def create_exporter(self):
156 from .export_scene import SceneExporter
157 return SceneExporter()
159 def draw(self, context):
160 col = self.layout.column()
161 col.prop(self, "resource_collection")
163 def menu_func_export(self, context):
164 self.layout.operator(ExportMspGLMesh.bl_idname, text="Msp GL mesh")
165 self.layout.operator(ExportMspGLObject.bl_idname, text="Msp GL object")
166 self.layout.operator(ExportMspGLArmature.bl_idname, text="Msp GL armature")
167 self.layout.operator(ExportMspGLScene.bl_idname, text="Msp GL scene")
169 from .properties import MspGLProperties
172 bpy.utils.register_module(__name__)
174 bpy.types.INFO_MT_file_export.append(menu_func_export)
176 from .properties import register_properties
177 register_properties();
180 bpy.utils.unregister_module(__name__)
182 bpy.types.INFO_MT_file_export.remove(menu_func_export)
184 if __name__=="__main__":