]> git.tdb.fi Git - libs/gl.git/blob - blender/io_mspgl/__init__.py
Remove the show_progress flag
[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", "export_animation", "export_armature", "export_camera", "export_material", "export_mesh", "export_object", "export_scene", "export_texture", "material", "mesh", "properties", "scene", "util":
12                 if sub in locals():
13                         imp.reload(locals()[sub])
14
15 import os
16 import bpy
17 from bpy_extras.io_utils import ExportHelper
18
19 class ExportMspGLBase(ExportHelper):
20         def set_extension(self, ext):
21                 ext_changed = (ext!=self.filename_ext)
22                 if ext_changed:
23                         if self.filepath.endswith(self.filename_ext):
24                                 self.filepath = self.filepath[:-len(self.filename_ext)]
25                         self.filename_ext = ext
26                 return ext_changed
27
28         def execute(self, context):
29                 exporter = self.create_exporter()
30                 self.prepare_exporter(exporter)
31                 exporter.export_to_file(context, self.filepath)
32                 return {"FINISHED"}
33
34         def create_exporter(self):
35                 raise Exception("create_exporter must be overridden")
36
37         def prepare_exporter(self, exporter):
38                 for k, v in self.as_keywords().items():
39                         setattr(exporter, k, v)
40
41 class ExportMspGLData(bpy.types.Operator):
42         bl_idname = "export.mspgl_data"
43         bl_label = "Export Msp GL data"
44         bl_description = "Export object data in Msp GL format"
45
46         filepath: bpy.props.StringProperty(name="File path", description="File path for exporting the data", subtype='FILE_PATH')
47         collection: bpy.props.BoolProperty(name="As a collection", description="Export all data as a single collection file", default=False)
48         shared_resources: bpy.props.BoolProperty(name="Shared resources", description="Use global names for resource files to enable sharing", default=True)
49
50         @classmethod
51         def poll(cls, context):
52                 return len(context.selected_objects)>0
53
54         def invoke(self, context, event):
55                 blend_filepath = context.blend_data.filepath
56                 if blend_filepath:
57                         self.filepath = os.path.splitext(blend_filepath)[0]+".mdc"
58                 else:
59                         self.filepath = "data.mdc"
60                 context.window_manager.fileselect_add(self)
61                 return {'RUNNING_MODAL'}
62
63         def execute(self, context):
64                 from .export import DataExporter
65                 exporter = DataExporter()
66                 exporter.collection = self.collection
67                 exporter.shared_resources = self.shared_resources
68                 exporter.export_to_file(context, self.filepath)
69                 return {'FINISHED'}
70
71         def draw(self, context):
72                 col = self.layout.column()
73                 col.label(text="Files")
74                 col.prop(self, "collection")
75                 col.prop(self, "shared_resources")
76
77 class ExportMspGLAnimation(bpy.types.Operator, ExportMspGLBase):
78         bl_idname = "export.mspgl_animation"
79         bl_label = "Export Msp GL animation"
80         bl_description = "Export one or more animations in Msp GL format"
81
82         filename_ext = ".anim"
83
84         export_all: bpy.props.BoolProperty(name="Export all animations", description="Export all animations present on the selected objects' NLA tracks")
85         collection: bpy.props.BoolProperty(name="As a collection", description="Export the animations as a single collection file", default=True)
86         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)
87
88         def check(self, context):
89                 ext_changed = self.set_extension(".mdc" if self.export_all and self.collection else ".anim")
90                 super_result = super().check(context)
91                 return ext_changed or super_result
92
93         def create_exporter(self):
94                 from .export_animation import AnimationExporter
95                 return AnimationExporter()
96
97         def draw(self, context):
98                 col = self.layout.column()
99                 col.prop(self, "export_all")
100                 if self.export_all:
101                         col.prop(self, "collection")
102                 col.prop(self, "looping_threshold")
103
104 class ExportMspGLScene(bpy.types.Operator, ExportMspGLBase):
105         bl_idname = "export_scene.mspgl_scene"
106         bl_label = "Export Msp GL scene"
107         bl_description = "Export the active scene in Msp GL format"
108
109         filename_ext = ".scene"
110
111         selected_only: bpy.props.BoolProperty(name="Selected objects only", description="Only export the selected objects", default=False)
112         visible_only: bpy.props.BoolProperty(name="Visible only", description="Only export objects in visible collections", default=True)
113         collection: bpy.props.BoolProperty(name="As a collection", description="Export the scene and all resources as a single collection file", default=False)
114         skip_existing: bpy.props.BoolProperty(name="Skip existing files", description="Skip resources that already exist as files", default=True)
115
116         def invoke(self, context, event):
117                 self.filepath = context.scene.name+".scene"
118                 return super().invoke(context, event)
119
120         def check(self, context):
121                 ext_changed = self.set_extension(".mdc" if self.collection else ".scene")
122                 super_result = super().check(context)
123                 return ext_changed or super_result
124
125         def create_exporter(self):
126                 from .export_scene import SceneExporter
127                 return SceneExporter()
128
129         def draw(self, context):
130                 col = self.layout.column()
131                 col.prop(self, "selected_only")
132                 col.prop(self, "visible_only")
133                 col.prop(self, "collection")
134                 if self.collection:
135                         col.prop(self, "skip_existing")
136
137 class AddUniform(bpy.types.Operator):
138         bl_idname = "material.add_uniform"
139         bl_label = "Add Uniform"
140         bl_description = "Add a new uniform value to the material"
141
142         def execute(self, context):
143                 mat = context.active_object.active_material
144                 mat.uniforms.add()
145                 mat.active_uniform_index = len(mat.uniforms)-1
146
147                 return {"FINISHED"}
148
149 class RemoveUniform(bpy.types.Operator):
150         bl_idname = "material.remove_uniform"
151         bl_label = "Remove Uniform"
152         bl_description = "Remove the selected uniform from the material"
153
154         def execute(self, context):
155                 mat = context.active_object.active_material
156                 mat.uniforms.remove(mat.active_uniform_index)
157                 mat.active_uniform_index = min(mat.active_uniform_index, len(mat.uniforms)-1)
158
159                 return {"FINISHED"}
160
161 def menu_func_export(self, context):
162         self.layout.operator(ExportMspGLData.bl_idname, text="Msp GL data")
163         self.layout.operator(ExportMspGLAnimation.bl_idname, text="Msp GL animation")
164         self.layout.operator(ExportMspGLScene.bl_idname, text="Msp GL scene")
165
166 classes = [ExportMspGLData, ExportMspGLAnimation, ExportMspGLScene, AddUniform, RemoveUniform]
167
168 def register():
169         for c in classes:
170                 bpy.utils.register_class(c)
171
172         bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
173
174         from .properties import register_properties
175         register_properties()
176
177 def unregister():
178         for c in classes:
179                 bpy.utils.unregister_class(c)
180
181         bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
182
183         from .properties import unregister_properties
184         unregister_properties()