]> git.tdb.fi Git - libs/gl.git/blob - blender/io_mspgl/__init__.py
Move most properties from exporters to the relevant types
[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", "export_scene", "mesh", "outfile", "properties", "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         show_progress = bpy.props.BoolProperty(name="Show progress", description="Display progress indicator while exporting", default=True)
19
20         def execute(self, context):
21                 exporter = self.create_exporter()
22                 self.prepare_exporter(exporter)
23                 exporter.export(context, self.filepath)
24                 return {"FINISHED"}
25
26         def create_exporter(self):
27                 raise Exception("create_exporter must be overridden")
28
29         def prepare_exporter(self, exporter):
30                 for k, v in self.as_keywords().items():
31                         setattr(exporter, k, v)
32
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         compound = bpy.props.BoolProperty(name="Compound", description="Combine all selected objects into one for exporting", default=False)
40
41         def draw(self, context):
42                 col = self.layout.column()
43                 col.prop(self, "compound")
44                 self.general_col = col
45
46                 self.layout.separator()
47
48                 col = self.layout.column()
49                 col.label("Triangle strips")
50                 col.prop(self, "use_strips")
51                 col.prop(self, "use_degen_tris")
52                 col.prop(self, "max_strip_len")
53
54                 self.layout.separator()
55
56                 col = self.layout.column()
57                 col.label("Vertex cache")
58                 col.prop(self, "optimize_cache")
59                 col.prop(self, "cache_size")
60
61 class ExportMspGLMesh(bpy.types.Operator, ExportMspGLMeshBase):
62         bl_idname = "export_mesh.mspgl_mesh"
63         bl_label = "Export Msp GL mesh"
64
65         filename_ext = ".mesh"
66
67         def create_exporter(self):
68                 from .export_mesh import MeshExporter
69                 return MeshExporter()
70
71 class ExportMspGLObject(bpy.types.Operator, ExportMspGLMeshBase):
72         bl_idname = "export_mesh.mspgl_object"
73         bl_label = "Export Msp GL object"
74
75         filename_ext = ".object"
76
77         external_tech = bpy.props.BoolProperty(name="External technique", description="Use an external technique specified in the object's properties", default=True)
78
79         textures = bpy.props.EnumProperty(name="Textures", description="Export textures", default="REF",
80                 items=(("NONE", "None", "Ignore textures"),
81                         ("REF", "Referenced", "Reference external data"),
82                         ("INLINE", "Inline", "Embed textures in the object")))
83
84         separate_mesh = bpy.props.BoolProperty(name="Separate mesh", description="Write mesh data into a separate file", default=False)
85         shared_mesh = bpy.props.BoolProperty(name="Shared mesh", description="Use mesh name for mesh file to enable sharing", default=True)
86         separate_tech = bpy.props.BoolProperty(name="Separate technique", description="Write technique data into a separate file", default=False)
87         shared_tech = bpy.props.BoolProperty(name="Shared technique", description="Use material name for technique file to enable sharing", default=True)
88
89         export_lods = bpy.props.BoolProperty(name="Export LoDs", description="Export all levels of detail", default=True)
90
91         def create_exporter(self):
92                 from .export_object import ObjectExporter
93                 return ObjectExporter()
94
95         def draw(self, context):
96                 super().draw(context)
97
98                 col = self.general_col
99                 col.prop(self, "external_tech")
100                 col.prop(self, "export_lods")
101                 col.prop(self, "textures")
102
103                 self.layout.separator();
104
105                 col = self.layout.column()
106                 col.label("Files")
107                 col.prop(self, "separate_mesh")
108                 if self.separate_mesh:
109                         col.prop(self, "shared_mesh")
110                 col.prop(self, "separate_tech")
111                 if self.separate_tech:
112                         col.prop(self, "shared_tech")
113
114 class ExportMspGLArmature(bpy.types.Operator, ExportMspGLBase):
115         bl_idname = "export.mspgl_armature"
116         bl_label = "Export Msp GL armature"
117
118         filename_ext = ".arma"
119
120         def create_exporter(self):
121                 from .export_armature import ArmatureExporter
122                 return ArmatureExporter()
123
124 class ExportMspGLScene(bpy.types.Operator, ExportMspGLBase):
125         bl_idname = "export_scene.mspgl_scene"
126         bl_label = "Export Msp GL scene"
127
128         filename_ext = ".scene"
129
130         external_tech = bpy.props.BoolProperty(name="External techniques", description="Use external techniques specified in objects' properties", default=True)
131         resource_collection = bpy.props.BoolProperty(name="Resource collection", description="Put resources to a single collection file", default=True)
132
133         def create_exporter(self):
134                 from .export_scene import SceneExporter
135                 return SceneExporter()
136
137         def draw(self, context):
138                 col = self.layout.column()
139                 col.prop(self, "resource_collection")
140
141 def menu_func_export(self, context):
142         self.layout.operator(ExportMspGLMesh.bl_idname, text="Msp GL mesh")
143         self.layout.operator(ExportMspGLObject.bl_idname, text="Msp GL object")
144         self.layout.operator(ExportMspGLArmature.bl_idname, text="Msp GL armature")
145         self.layout.operator(ExportMspGLScene.bl_idname, text="Msp GL scene")
146
147 from .properties import MspGLMeshProperties, MspGLObjectProperties
148
149 def register():
150         bpy.utils.register_module(__name__)
151
152         bpy.types.INFO_MT_file_export.append(menu_func_export)
153
154         from .properties import register_properties
155         register_properties();
156
157 def unregister():
158         bpy.utils.unregister_module(__name__)
159
160         bpy.types.INFO_MT_file_export.remove(menu_func_export)
161
162 if __name__=="__main__":
163         register()