]> git.tdb.fi Git - libs/gl.git/blob - blender/io_mspgl/__init__.py
Move material and texture export to their own classes
[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", "datafile", "export_armature", "export_material", "export_mesh", "export_object", "export_scene", "export_texture", "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         textures = bpy.props.EnumProperty(name="Textures", description="Export textures", default="REF",
62                 items=(("NONE", "None", "Ignore textures"),
63                         ("REF", "Referenced", "Reference external data"),
64                         ("INLINE", "Inline", "Embed textures in the object")))
65
66         separate_mesh = bpy.props.BoolProperty(name="Separate mesh", description="Write mesh data into a separate file", default=False)
67         separate_tech = bpy.props.BoolProperty(name="Separate technique", description="Write technique data into a separate file", default=False)
68         shared_resources = bpy.props.BoolProperty(name="Shared resources", description="Use global names for resource files to enable sharing", default=True)
69
70         export_lods = bpy.props.BoolProperty(name="Export LoDs", description="Export all levels of detail", default=True)
71
72         def create_exporter(self):
73                 from .export_object import ObjectExporter
74                 return ObjectExporter()
75
76         def draw(self, context):
77                 super().draw(context)
78
79                 col = self.general_col
80                 col.prop(self, "export_lods")
81                 col.prop(self, "textures")
82                 col.separator()
83
84                 self.layout.separator()
85
86                 col = self.layout.column()
87                 col.label("Files")
88                 col.prop(self, "separate_mesh")
89                 col.prop(self, "separate_tech")
90                 if self.separate_mesh or self.separate_tech:
91                         col.prop(self, "shared_resources")
92
93 class ExportMspGLArmature(bpy.types.Operator, ExportMspGLBase):
94         bl_idname = "export.mspgl_armature"
95         bl_label = "Export Msp GL armature"
96
97         filename_ext = ".arma"
98
99         def create_exporter(self):
100                 from .export_armature import ArmatureExporter
101                 return ArmatureExporter()
102
103 class ExportMspGLScene(bpy.types.Operator, ExportMspGLBase):
104         bl_idname = "export_scene.mspgl_scene"
105         bl_label = "Export Msp GL scene"
106
107         filename_ext = ".scene"
108
109         resource_collection = bpy.props.BoolProperty(name="Resource collection", description="Put resources to a single collection file", default=True)
110
111         def create_exporter(self):
112                 from .export_scene import SceneExporter
113                 return SceneExporter()
114
115         def draw(self, context):
116                 col = self.layout.column()
117                 col.prop(self, "resource_collection")
118
119 def menu_func_export(self, context):
120         self.layout.operator(ExportMspGLMesh.bl_idname, text="Msp GL mesh")
121         self.layout.operator(ExportMspGLObject.bl_idname, text="Msp GL object")
122         self.layout.operator(ExportMspGLArmature.bl_idname, text="Msp GL armature")
123         self.layout.operator(ExportMspGLScene.bl_idname, text="Msp GL scene")
124
125 from .properties import MspGLMeshProperties, MspGLObjectProperties
126
127 def register():
128         bpy.utils.register_module(__name__)
129
130         bpy.types.INFO_MT_file_export.append(menu_func_export)
131
132         from .properties import register_properties
133         register_properties()
134
135 def unregister():
136         bpy.utils.unregister_module(__name__)
137
138         bpy.types.INFO_MT_file_export.remove(menu_func_export)
139
140 if __name__=="__main__":
141         register()