]> git.tdb.fi Git - libs/gl.git/blob - blender/io_mspgl/__init__.py
Add an option to export a separate mesh file when exporting an object
[libs/gl.git] / blender / io_mspgl / __init__.py
1 bl_info = {
2         "name": "Msp GL datafiles",
3         "author": "Mikko Rasa",
4         "location": "File > Export",
5         "description": "Export Msp GL data",
6         "category": "Import-Export" }
7
8 if "bpy" in locals():
9         import imp
10         for sub in "armature", "export_armature", "export_mesh", "export_object", "mesh", "outfile", "util":
11                 if sub in locals():
12                         imp.reload(locals()[sub])
13
14 import bpy
15 from bpy_extras.io_utils import ExportHelper
16
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)
22                 return {"FINISHED"}
23
24         def create_exporter(self):
25                 raise Exception("create_exporter must be overridden")
26
27         def prepare_exporter(self, exporter):
28                 for k, v in self.as_keywords().items():
29                         setattr(exporter, k, v)
30
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)
50
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
58                 self.layout.separator()
59
60                 col = self.layout.column()
61                 col.label("Triangle strips")
62                 col.prop(self, "use_strips")
63                 col.prop(self, "use_degen_tris")
64                 col.prop(self, "max_strip_len")
65
66                 self.layout.separator()
67
68                 col = self.layout.column()
69                 col.label("Texturing")
70                 col.prop(self, "export_uv")
71                 col.prop(self, "tbn_vecs")
72                 col.prop(self, "tbn_uvtex")
73                 self.texturing_col = col
74
75                 self.layout.separator()
76
77                 col = self.layout.column()
78                 col.label("Vertex cache")
79                 col.prop(self, "optimize_cache")
80                 col.prop(self, "cache_size")
81
82 class ExportMspGLMesh(bpy.types.Operator, ExportMspGLMeshBase):
83         bl_idname = "export_mesh.mspgl_mesh"
84         bl_label = "Export Msp GL mesh"
85
86         filename_ext = ".mesh"
87
88         def create_exporter(self):
89                 from .export_mesh import MeshExporter
90                 return MeshExporter()
91
92 class ExportMspGLObject(bpy.types.Operator, ExportMspGLMeshBase):
93         bl_idname = "export_mesh.mspgl_object"
94         bl_label = "Export Msp GL object"
95
96         filename_ext = ".object"
97
98         textures = bpy.props.EnumProperty(name="Textures", description="Export textures", default="REF",
99                 items=(("NONE", "None", "Ignore textures"),
100                         ("REF", "Referenced", "Reference external data"),
101                         ("INLINE", "Inline", "Embed textures in the object")))
102         material_tex = bpy.props.BoolProperty(name="Material texture", description="Generate a texture based on material colors", default=False)
103         srgb_colors = bpy.props.BoolProperty(name="sRGB colors", description="Export material colors as sRGB instead of linear", default=True)
104
105         separate_mesh = bpy.props.BoolProperty(name="Separate mesh", description="Write mesh data into a separate file", default=False)
106
107         def create_exporter(self):
108                 from .export_object import ObjectExporter
109                 return ObjectExporter()
110
111         def draw(self, context):
112                 super().draw(context)
113
114                 col = self.texturing_col
115                 col.prop(self, "textures")
116                 col.prop(self, "material_tex")
117                 col.prop(self, "srgb_colors")
118
119                 self.layout.separator();
120
121                 col = self.layout.column()
122                 col.label("Files")
123                 col.prop(self, "separate_mesh")
124
125 class ExportMspGLArmature(bpy.types.Operator, ExportMspGLBase):
126         bl_idname = "export.mspgl_armature"
127         bl_label = "Export Msp GL armature"
128
129         filename_ext = ".armature"
130
131         def create_exporter(self):
132                 from .export_armature import ArmatureExporter
133                 return ArmatureExporter()
134
135 def menu_func_export(self, context):
136         self.layout.operator(ExportMspGLMesh.bl_idname, text="Msp GL mesh")
137         self.layout.operator(ExportMspGLObject.bl_idname, text="Msp GL object")
138         self.layout.operator(ExportMspGLArmature.bl_idname, text="Msp GL armature")
139
140 def register():
141         bpy.utils.register_module(__name__)
142
143         bpy.types.INFO_MT_file_export.append(menu_func_export)
144
145 def unregister():
146         bpy.utils.unregister_module(__name__)
147
148         bpy.types.INFO_MT_file_export.remove(menu_func_export)
149
150 if __name__=="__main__":
151         register()