]> git.tdb.fi Git - libs/gl.git/blob - blender/io_mesh_mspgl/__init__.py
Split mesh and object export into separate operators
[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 class ExportMspGLMesh(bpy.types.Operator, ExportMspGLBase):
48         bl_idname = "export_mesh.mspgl_mesh"
49         bl_label = "Export Msp GL mesh"
50
51         filename_ext = ".mesh"
52
53 class ExportMspGLObject(bpy.types.Operator, ExportMspGLBase):
54         bl_idname = "export_mesh.mspgl_object"
55         bl_label = "Export Msp GL object"
56
57         filename_ext = ".object"
58
59         material_tex = bpy.props.BoolProperty(name="Material texture", description="Generate a texture based on material colors", default=False)
60
61         def prepare_exporter(self, exporter):
62                 super().prepare_exporter(exporter)
63                 exporter.object = True
64
65 def menu_func_export(self, context):
66         self.layout.operator(ExportMspGLMesh.bl_idname, text="Msp GL mesh")
67         self.layout.operator(ExportMspGLObject.bl_idname, text="Msp GL object")
68
69 def register():
70         bpy.utils.register_module(__name__)
71
72         bpy.types.INFO_MT_file_export.append(menu_func_export)
73
74 def unregister():
75         bpy.utils.unregister_module(__name__)
76
77         bpy.types.INFO_MT_file_export.remove(menu_func_export)
78
79 if __name__=="__main__":
80         register()