]> git.tdb.fi Git - libs/gl.git/blob - blender/io_mspgl/__init__.py
bb13c48873f2cf28008b2886a7a4ba6b79ce95ea
[libs/gl.git] / blender / io_mspgl / __init__.py
1 bl_info = {
2         "name": "Msp GL datafiles",
3         "blender": (2, 80, 0),
4         "author": "Mikko Rasa",
5         "location": "File > Export",
6         "description": "Export Msp GL data",
7         "category": "Import-Export" }
8
9 if "bpy" in locals():
10         import imp
11         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":
12                 if sub in locals():
13                         imp.reload(locals()[sub])
14
15 import bpy
16 from bpy_extras.io_utils import ExportHelper
17
18 class ExportMspGLBase(ExportHelper):
19         show_progress = bpy.props.BoolProperty(name="Show progress", description="Display progress indicator while exporting", default=True)
20
21         def execute(self, context):
22                 exporter = self.create_exporter()
23                 self.prepare_exporter(exporter)
24                 exporter.export_to_file(context, self.filepath)
25                 return {"FINISHED"}
26
27         def create_exporter(self):
28                 raise Exception("create_exporter must be overridden")
29
30         def prepare_exporter(self, exporter):
31                 for k, v in self.as_keywords().items():
32                         setattr(exporter, k, v)
33
34 class ExportMspGLMeshBase(ExportMspGLBase):
35         use_strips = bpy.props.BoolProperty(name="Use strips", description="Combine faces into triangle strips", default=True)
36         use_degen_tris = bpy.props.BoolProperty(name="Use degen tris", description="Concatenate triangle strips with degenerate triangles", default=False)
37
38         def draw(self, context):
39                 self.general_col = self.layout.column()
40
41                 col = self.layout.column()
42                 col.label(text="Triangle strips")
43                 col.prop(self, "use_strips")
44                 col.prop(self, "use_degen_tris")
45
46 class ExportMspGLMesh(bpy.types.Operator, ExportMspGLMeshBase):
47         bl_idname = "export_mesh.mspgl_mesh"
48         bl_label = "Export Msp GL mesh"
49
50         filename_ext = ".mesh"
51
52         def create_exporter(self):
53                 from .export_mesh import MeshExporter
54                 return MeshExporter()
55
56 class ExportMspGLObject(bpy.types.Operator, ExportMspGLMeshBase):
57         bl_idname = "export_mesh.mspgl_object"
58         bl_label = "Export Msp GL object"
59
60         filename_ext = ".object"
61
62         single_file = bpy.props.BoolProperty(name="Single file", description="Write all data into a single file", default=True)
63         shared_resources = bpy.props.BoolProperty(name="Shared resources", description="Use global names for resource files to enable sharing", default=True)
64
65         export_lods = bpy.props.BoolProperty(name="Export LoDs", description="Export all levels of detail", default=True)
66         use_textures = bpy.props.BoolProperty(name="Use textures", description="Use textures in the exported object", default=True)
67
68         def create_exporter(self):
69                 from .export_object import ObjectExporter
70                 return ObjectExporter()
71
72         def draw(self, context):
73                 super().draw(context)
74
75                 self.general_col.prop(self, "export_lods")
76                 self.general_col.prop(self, "use_textures")
77
78                 col = self.layout.column()
79                 col.label(text="Files")
80                 col.prop(self, "single_file")
81                 if not self.single_file:
82                         col.prop(self, "shared_resources")
83
84 class ExportMspGLArmature(bpy.types.Operator, ExportMspGLBase):
85         bl_idname = "export.mspgl_armature"
86         bl_label = "Export Msp GL armature"
87
88         filename_ext = ".arma"
89
90         def create_exporter(self):
91                 from .export_armature import ArmatureExporter
92                 return ArmatureExporter()
93
94 class ExportMspGLAnimation(bpy.types.Operator, ExportMspGLBase):
95         bl_idname = "export.mspgl_animation"
96         bl_label = "Export Msp GL animation"
97
98         filename_ext = ".anim"
99
100         export_all = bpy.props.BoolProperty(name="Export all animations", description="Export all animations present on the selected objects' NLA tracks")
101         collection = bpy.props.BoolProperty(name="As a collection", description="Export the animations as a single collection file", default=True)
102         looping_threshold = bpy.props.FloatProperty(name="Looping threshold", description="Tolerance for curve beginning and end values for looping", min=0.0, soft_max=1.0, precision=4, default=0.001)
103
104         def check(self, context):
105                 result = False
106
107                 ext = ".mdc" if self.export_all and self.collection else ".anim"
108                 ext_changed = (ext!=self.filename_ext)
109                 if ext_changed:
110                         if self.filepath.endswith(self.filename_ext):
111                                 self.filepath = self.filepath[:-len(self.filename_ext)]
112                         self.filename_ext = ext
113
114                 super_result = super().check(context)
115
116                 return ext_changed or super_result
117
118         def create_exporter(self):
119                 from .export_animation import AnimationExporter
120                 return AnimationExporter()
121
122         def draw(self, context):
123                 col = self.layout.column()
124                 col.prop(self, "export_all")
125                 if self.export_all:
126                         col.prop(self, "collection")
127                 col.prop(self, "looping_threshold")
128
129 class ExportMspGLScene(bpy.types.Operator, ExportMspGLBase):
130         bl_idname = "export_scene.mspgl_scene"
131         bl_label = "Export Msp GL scene"
132
133         filename_ext = ".scene"
134
135         selected_only = bpy.props.BoolProperty(name="Selected objects only", description="Only export the selected objects")
136         visible_collections = bpy.props.BoolProperty(name="Visible collections only", description="Only export objects in visible collections", default=True)
137         resource_collection = bpy.props.BoolProperty(name="Resource collection", description="Put resources to a single collection file", default=True)
138         skip_existing = bpy.props.BoolProperty(name="Skip existing files", description="Skip resources that already exist as files", default=True)
139
140         def create_exporter(self):
141                 from .export_scene import SceneExporter
142                 return SceneExporter()
143
144         def draw(self, context):
145                 col = self.layout.column()
146                 col.prop(self, "selected_only")
147                 col.prop(self, "visible_collections")
148                 col.prop(self, "resource_collection")
149                 if self.resource_collection:
150                         col.prop(self, "skip_existing")
151
152 class ExportMspGLCamera(bpy.types.Operator, ExportMspGLBase):
153         bl_idname = "export.mspgl_camera"
154         bl_label = "Export Msp GL camera"
155
156         filename_ext = ".camera"
157
158         def create_exporter(self):
159                 from .export_camera import CameraExporter
160                 return CameraExporter()
161
162 def menu_func_export(self, context):
163         self.layout.operator(ExportMspGLMesh.bl_idname, text="Msp GL mesh")
164         self.layout.operator(ExportMspGLObject.bl_idname, text="Msp GL object")
165         self.layout.operator(ExportMspGLArmature.bl_idname, text="Msp GL armature")
166         self.layout.operator(ExportMspGLAnimation.bl_idname, text="Msp GL animation")
167         self.layout.operator(ExportMspGLScene.bl_idname, text="Msp GL scene")
168         self.layout.operator(ExportMspGLCamera.bl_idname, text="Msp GL camera")
169
170 classes = [ExportMspGLMesh, ExportMspGLObject, ExportMspGLArmature, ExportMspGLAnimation, ExportMspGLScene, ExportMspGLCamera]
171
172 def register():
173         for c in classes:
174                 bpy.utils.register_class(c)
175
176         bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
177
178         from .properties import register_properties
179         register_properties()
180
181 def unregister():
182         for c in classes:
183                 bpy.utils.unregister_class(c)
184
185         bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
186
187         from .properties import unregister_properties
188         unregister_properties()