]> git.tdb.fi Git - libs/gl.git/blob - blender/io_mesh_mspgl/__init__.py
Use a custom drawing function to group the properties in a sensible way
[libs/gl.git] / blender / io_mesh_mspgl / __init__.py
1 bl_info = {
2         "name": "Msp GL format",
3         "author": "Mikko Rasa",
4         "location": "File > Export",
5         "description": "Export Msp GL meshes and objects",
6         "category": "Import-Export" }
7
8 if "bpy" in locals():
9         import imp
10         for sub in "export_mspgl", "mesh", "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         use_strips = bpy.props.BoolProperty(name="Use strips", description="Combine faces into triangle strips", default=True)
19         use_degen_tris = bpy.props.BoolProperty(name="Use degen tris", description="Concatenate triangle strips with degenerate triangles", default=False)
20         max_strip_len = bpy.props.IntProperty(name="Max strip length", description="Maximum length for a triangle strip", default=1024, min=4, max=16384)
21         optimize_cache = bpy.props.BoolProperty(name="Optimize cache", description="Optimize element order for vertex cache", default=True)
22         cache_size = bpy.props.IntProperty(name="Cache size", description="Simulated vertex cache size used in optimization", default=64, min=8, max=1024)
23         export_lines = bpy.props.BoolProperty(name="Export lines", description="Export edges without faces as lines", default=False)
24         export_uv = bpy.props.EnumProperty(name="Export UV", description="Export UV coordinates", default="UNIT0",
25                 items=(("NONE", "None", "No UV coordinates are exported"),
26                         ("UNIT0", "Unit 0", "UV coordinates for unit 0 are exported"),
27                         ("ALL", "All", "All UV coordinates are exported")))
28         tbn_vecs = bpy.props.BoolProperty(name="TBN vectors", description="Compute tangent and binormal vectors for vertices", default=False)
29         tbn_uvtex = bpy.props.StringProperty(name="TBN UV layer", description="UV layer to use as basis for TBN vectors", default="")
30         compound = bpy.props.BoolProperty(name="Compound", description="Combine all selected objects into one for exporting", default=False)
31         smoothing = bpy.props.EnumProperty(name="Smoothing", description="Smoothing method to use", default="MSPGL",
32                 items=(("NONE", "None", "No smoothing"),
33                         ("BLENDER", "Blender", "Use Blender's vertex normals"),
34                         ("MSPGL", "MspGL", "Compute vertex normals internally")))
35
36         def execute(self, context):
37                 from . import export_mspgl
38                 exporter = export_mspgl.Exporter()
39                 self.prepare_exporter(exporter)
40                 exporter.export(context, self.filepath)
41                 return {"FINISHED"}
42
43         def prepare_exporter(self, exporter):
44                 for k, v in self.as_keywords().items():
45                         setattr(exporter, k, v)
46
47         def draw(self, context):
48                 col = self.layout.column()
49                 col.prop(self, "export_lines")
50                 col.prop(self, "compound")
51                 col.prop(self, "smoothing")
52                 self.layout.separator()
53                 col = self.layout.column()
54                 col.label("Triangle strips")
55                 col.prop(self, "use_strips")
56                 col.prop(self, "use_degen_tris")
57                 col.prop(self, "max_strip_len")
58                 self.layout.separator()
59                 col = self.layout.column()
60                 col.label("Vertex cache")
61                 col.prop(self, "optimize_cache")
62                 col.prop(self, "cache_size")
63                 self.layout.separator()
64                 col = self.layout.column()
65                 col.label("TBN vectors")
66                 col.prop(self, "tbn_vecs")
67                 col.prop(self, "tbn_uvtex")
68
69 class ExportMspGLMesh(bpy.types.Operator, ExportMspGLBase):
70         bl_idname = "export_mesh.mspgl_mesh"
71         bl_label = "Export Msp GL mesh"
72
73         filename_ext = ".mesh"
74
75 class ExportMspGLObject(bpy.types.Operator, ExportMspGLBase):
76         bl_idname = "export_mesh.mspgl_object"
77         bl_label = "Export Msp GL object"
78
79         filename_ext = ".object"
80
81         textures = bpy.props.EnumProperty(name="Textures", description="Export textures", default="REF",
82                 items=(("NONE", "None", "Ignore textures"),
83                         ("REF", "Referenced", "Reference external data"),
84                         ("INLINE", "Inline", "Embed textures in the object")))
85         material_tex = bpy.props.BoolProperty(name="Material texture", description="Generate a texture based on material colors", default=False)
86
87         def prepare_exporter(self, exporter):
88                 super().prepare_exporter(exporter)
89                 exporter.object = True
90
91         def draw(self, context):
92                 super().draw(context)
93                 self.layout.separator()
94                 col = self.layout.column()
95                 col.label("Texturing")
96                 col.prop(self, "textures")
97                 col.prop(self, "material_tex")
98
99 def menu_func_export(self, context):
100         self.layout.operator(ExportMspGLMesh.bl_idname, text="Msp GL mesh")
101         self.layout.operator(ExportMspGLObject.bl_idname, text="Msp GL object")
102
103 def register():
104         bpy.utils.register_module(__name__)
105
106         bpy.types.INFO_MT_file_export.append(menu_func_export)
107
108 def unregister():
109         bpy.utils.unregister_module(__name__)
110
111         bpy.types.INFO_MT_file_export.remove(menu_func_export)
112
113 if __name__=="__main__":
114         register()