]> git.tdb.fi Git - libs/gl.git/blob - blender/io_mspgl/__init__.py
f0cb6579266c6ecdf1850676c36689934137eabe
[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 "animation", "armature", "datafile", "export_animation", "export_armature", "export_camera", "export_material", "export_mesh", "export_object", "export_scene", "export_texture", "material", "mesh", "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_to_file(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
37         def draw(self, context):
38                 self.general_col = self.layout.column()
39
40                 col = self.layout.column()
41                 col.label("Triangle strips")
42                 col.prop(self, "use_strips")
43                 col.prop(self, "use_degen_tris")
44
45 class ExportMspGLMesh(bpy.types.Operator, ExportMspGLMeshBase):
46         bl_idname = "export_mesh.mspgl_mesh"
47         bl_label = "Export Msp GL mesh"
48
49         filename_ext = ".mesh"
50
51         def create_exporter(self):
52                 from .export_mesh import MeshExporter
53                 return MeshExporter()
54
55 class ExportMspGLObject(bpy.types.Operator, ExportMspGLMeshBase):
56         bl_idname = "export_mesh.mspgl_object"
57         bl_label = "Export Msp GL object"
58
59         filename_ext = ".object"
60
61         single_file = bpy.props.BoolProperty(name="Single file", description="Write all data into a single file", default=True)
62         shared_resources = bpy.props.BoolProperty(name="Shared resources", description="Use global names for resource files to enable sharing", default=True)
63
64         export_lods = bpy.props.BoolProperty(name="Export LoDs", description="Export all levels of detail", default=True)
65         use_textures = bpy.props.BoolProperty(name="Use textures", description="Use textures in the exported object", default=True)
66
67         def create_exporter(self):
68                 from .export_object import ObjectExporter
69                 return ObjectExporter()
70
71         def draw(self, context):
72                 super().draw(context)
73
74                 self.general_col.prop(self, "export_lods")
75                 self.general_col.prop(self, "use_textures")
76
77                 col = self.layout.column()
78                 col.label("Files")
79                 col.prop(self, "single_file")
80                 if not self.single_file:
81                         col.prop(self, "shared_resources")
82
83 class ExportMspGLArmature(bpy.types.Operator, ExportMspGLBase):
84         bl_idname = "export.mspgl_armature"
85         bl_label = "Export Msp GL armature"
86
87         filename_ext = ".arma"
88
89         def create_exporter(self):
90                 from .export_armature import ArmatureExporter
91                 return ArmatureExporter()
92
93 class ExportMspGLAnimation(bpy.types.Operator, ExportMspGLBase):
94         bl_idname = "export.mspgl_animation"
95         bl_label = "Export Msp GL animation"
96
97         filename_ext = ".anim"
98
99         export_all = bpy.props.BoolProperty(name="Export all animations", description="Export all animations present on the selected objects' NLA tracks")
100         collection = bpy.props.BoolProperty(name="As a collection", description="Export the animations as a single collection file", default=True)
101
102         def check(self, context):
103                 result = False
104
105                 ext = ".mdc" if self.export_all and self.collection else ".anim"
106                 ext_changed = (ext!=self.filename_ext)
107                 if ext_changed:
108                         if self.filepath.endswith(self.filename_ext):
109                                 self.filepath = self.filepath[:-len(self.filename_ext)]
110                         self.filename_ext = ext
111
112                 super_result = super().check(context)
113
114                 return ext_changed or super_result
115
116         def create_exporter(self):
117                 from .export_animation import AnimationExporter
118                 return AnimationExporter()
119
120         def draw(self, context):
121                 col = self.layout.column()
122                 col.prop(self, "export_all")
123                 if self.export_all:
124                         col.prop(self, "collection")
125
126 class ExportMspGLScene(bpy.types.Operator, ExportMspGLBase):
127         bl_idname = "export_scene.mspgl_scene"
128         bl_label = "Export Msp GL scene"
129
130         filename_ext = ".scene"
131
132         resource_collection = bpy.props.BoolProperty(name="Resource collection", description="Put resources to a single collection file", default=True)
133
134         def create_exporter(self):
135                 from .export_scene import SceneExporter
136                 return SceneExporter()
137
138         def draw(self, context):
139                 col = self.layout.column()
140                 col.prop(self, "resource_collection")
141
142 class ExportMspGLCamera(bpy.types.Operator, ExportMspGLBase):
143         bl_idname = "export.mspgl_camera"
144         bl_label = "Export Msp GL camera"
145
146         filename_ext = ".camera"
147
148         def create_exporter(self):
149                 from .export_camera import CameraExporter
150                 return CameraExporter()
151
152 def menu_func_export(self, context):
153         self.layout.operator(ExportMspGLMesh.bl_idname, text="Msp GL mesh")
154         self.layout.operator(ExportMspGLObject.bl_idname, text="Msp GL object")
155         self.layout.operator(ExportMspGLArmature.bl_idname, text="Msp GL armature")
156         self.layout.operator(ExportMspGLAnimation.bl_idname, text="Msp GL animation")
157         self.layout.operator(ExportMspGLScene.bl_idname, text="Msp GL scene")
158         self.layout.operator(ExportMspGLCamera.bl_idname, text="Msp GL camera")
159
160 from .properties import MspGLMeshProperties, MspGLObjectProperties
161
162 def register():
163         bpy.utils.register_module(__name__)
164
165         bpy.types.INFO_MT_file_export.append(menu_func_export)
166
167         from .properties import register_properties
168         register_properties()
169
170 def unregister():
171         bpy.utils.unregister_module(__name__)
172
173         bpy.types.INFO_MT_file_export.remove(menu_func_export)
174
175 if __name__=="__main__":
176         register()