mirrored from https://projects.blender.org/blender/blender-addons.git
-
Notifications
You must be signed in to change notification settings - Fork 189
/
__init__.py
353 lines (312 loc) · 12.5 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
# SPDX-FileCopyrightText: 2011-2023 Blender Foundation
#
# SPDX-License-Identifier: GPL-2.0-or-later
from bpy_extras.io_utils import (
ImportHelper,
ExportHelper,
orientation_helper,
axis_conversion,
poll_file_object_drop,
)
from bpy.props import (
BoolProperty,
EnumProperty,
FloatProperty,
StringProperty,
CollectionProperty,
)
import bpy
bl_info = {
"name": "Autodesk 3DS format",
"author": "Bob Holcomb, Campbell Barton, Sebastian Schrand",
"version": (2, 5, 1),
"blender": (4, 2, 0),
"location": "File > Import-Export",
"description": "3DS Import/Export meshes, UVs, materials, textures, "
"cameras, lamps & animation",
"warning": "Images must be in file folder, "
"filenames are limited to DOS 8.3 format",
"doc_url": "{BLENDER_MANUAL_URL}/addons/import_export/scene_3ds.html",
"category": "Import-Export",
}
if "bpy" in locals():
import importlib
if "import_3ds" in locals():
importlib.reload(import_3ds)
if "export_3ds" in locals():
importlib.reload(export_3ds)
@orientation_helper(axis_forward='Y', axis_up='Z')
class Import3DS(bpy.types.Operator, ImportHelper):
"""Import from 3DS file format (.3ds)"""
bl_idname = "import_scene.max3ds"
bl_label = 'Import 3DS'
bl_options = {'PRESET', 'UNDO'}
filename_ext = ".3ds"
filter_glob: StringProperty(default="*.3ds", options={'HIDDEN'})
files: CollectionProperty(type=bpy.types.OperatorFileListElement, options={'HIDDEN', 'SKIP_SAVE'})
directory: StringProperty(subtype='DIR_PATH')
constrain_size: FloatProperty(
name="Constrain Size",
description="Scale the model by 10 until it reaches the "
"size constraint (0 to disable)",
min=0.0, max=1000.0,
soft_min=0.0, soft_max=1000.0,
default=10.0,
)
use_scene_unit: BoolProperty(
name="Scene Units",
description="Convert to scene unit length settings",
default=False,
)
use_center_pivot: BoolProperty(
name="Pivot Origin",
description="Move all geometry to pivot origin",
default=False,
)
use_image_search: BoolProperty(
name="Image Search",
description="Search subdirectories for any associated images "
"(Warning, may be slow)",
default=True,
)
object_filter: EnumProperty(
name="Object Filter", options={'ENUM_FLAG'},
items=(('WORLD', "World".rjust(11), "", 'WORLD_DATA', 0x1),
('MESH', "Mesh".rjust(11), "", 'MESH_DATA', 0x2),
('LIGHT', "Light".rjust(12), "", 'LIGHT_DATA', 0x4),
('CAMERA', "Camera".rjust(11), "", 'CAMERA_DATA', 0x8),
('EMPTY', "Empty".rjust(11), "", 'EMPTY_AXIS', 0x10),
),
description="Object types to import",
default={'WORLD', 'MESH', 'LIGHT', 'CAMERA', 'EMPTY'},
)
use_apply_transform: BoolProperty(
name="Apply Transform",
description="Workaround for object transformations "
"importing incorrectly",
default=True,
)
use_keyframes: BoolProperty(
name="Animation",
description="Read the keyframe data",
default=True,
)
use_world_matrix: BoolProperty(
name="World Space",
description="Transform to matrix world",
default=False,
)
use_collection: BoolProperty(
name="Collection",
description="Create a new collection",
default=False,
)
use_cursor: BoolProperty(
name="Cursor Origin",
description="Read the 3D cursor location",
default=False,
)
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
import_include(layout, self)
import_transform(layout, self)
def execute(self, context):
from . import import_3ds
keywords = self.as_keywords(ignore=("axis_forward",
"axis_up",
"filter_glob",
))
global_matrix = axis_conversion(from_forward=self.axis_forward,
from_up=self.axis_up,
).to_4x4()
keywords["global_matrix"] = global_matrix
return import_3ds.load(self, context, **keywords)
def invoke(self, context, event):
return self.invoke_popup(context)
def import_include(layout, operator):
header, body = layout.panel("MAX3DS_import_include", default_closed=False)
header.label(text="Include")
if body:
line = body.row(align=True)
line.prop(operator, "use_image_search")
line.label(text="", icon='OUTLINER_OB_IMAGE' if operator.use_image_search else 'IMAGE_DATA')
body.column().prop(operator, "object_filter")
line = body.row(align=True)
line.prop(operator, "use_keyframes")
line.label(text="", icon='ANIM' if operator.use_keyframes else 'DECORATE_DRIVER')
line = body.row(align=True)
line.prop(operator, "use_collection")
line.label(text="", icon='OUTLINER_COLLECTION' if operator.use_collection else 'GROUP')
line = body.row(align=True)
line.prop(operator, "use_cursor")
line.label(text="", icon='PIVOT_CURSOR' if operator.use_cursor else 'CURSOR')
def import_transform(layout, operator):
header, body = layout.panel("MAX3DS_import_transform", default_closed=False)
header.label(text="Transform")
if body:
body.prop(operator, "constrain_size")
line = body.row(align=True)
line.prop(operator, "use_scene_unit")
line.label(text="", icon='EMPTY_ARROWS' if operator.use_scene_unit else 'EMPTY_DATA')
line = body.row(align=True)
line.prop(operator, "use_center_pivot")
line.label(text="", icon='OVERLAY' if operator.use_center_pivot else 'PIVOT_ACTIVE')
line = body.row(align=True)
line.prop(operator, "use_apply_transform")
line.label(text="", icon='MESH_CUBE' if operator.use_apply_transform else 'MOD_SOLIDIFY')
line = body.row(align=True)
line.prop(operator, "use_world_matrix")
line.label(text="", icon='WORLD' if operator.use_world_matrix else 'META_BALL')
body.prop(operator, "axis_forward")
body.prop(operator, "axis_up")
@orientation_helper(axis_forward='Y', axis_up='Z')
class Export3DS(bpy.types.Operator, ExportHelper):
"""Export to 3DS file format (.3ds)"""
bl_idname = "export_scene.max3ds"
bl_label = 'Export 3DS'
bl_options = {'PRESET', 'UNDO'}
filename_ext = ".3ds"
filter_glob: StringProperty(default="*.3ds", options={'HIDDEN'})
collection: StringProperty(
name="Source Collection",
description="Export objects from this collection",
default="",
)
scale_factor: FloatProperty(
name="Scale Factor",
description="Master scale factor for all objects",
min=0.0, max=100000.0,
soft_min=0.0, soft_max=100000.0,
default=1.0,
)
use_scene_unit: BoolProperty(
name="Scene Units",
description="Take the scene unit length settings into account",
default=False,
)
use_selection: BoolProperty(
name="Selection",
description="Export selected objects only",
default=False,
)
object_filter: EnumProperty(
name="Object Filter", options={'ENUM_FLAG'},
items=(('WORLD', "World".rjust(11), "", 'WORLD_DATA',0x1),
('MESH', "Mesh".rjust(11), "", 'MESH_DATA', 0x2),
('LIGHT', "Light".rjust(12), "", 'LIGHT_DATA',0x4),
('CAMERA', "Camera".rjust(11), "", 'CAMERA_DATA',0x8),
('EMPTY', "Empty".rjust(11), "", 'EMPTY_AXIS',0x10),
('OTHER', "Other".rjust(12), "", 'MATSHADERBALL', 0x20),
),
description="Object types to export",
default={'WORLD', 'MESH', 'LIGHT', 'CAMERA', 'EMPTY', 'OTHER'},
)
use_apply_transform: bpy.props.BoolProperty(
name="Apply Transform",
description="Apply matrix transform before export",
default=True,
)
use_keyframes: BoolProperty(
name="Animation",
description="Write the keyframe data",
default=True,
)
use_hierarchy: BoolProperty(
name="Hierarchy",
description="Export hierarchy chunks",
default=False,
)
use_collection: BoolProperty(
name="Collection",
description="Export active collection only",
default=False,
)
use_cursor: BoolProperty(
name="Cursor Origin",
description="Save the 3D cursor location",
default=False,
)
def draw(self, context):
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
browser = context.space_data.type == 'FILE_BROWSER'
export_include(layout, self, browser)
export_transform(layout, self)
def execute(self, context):
from . import export_3ds
keywords = self.as_keywords(ignore=("axis_forward",
"axis_up",
"filter_glob",
"check_existing",
))
global_matrix = axis_conversion(to_forward=self.axis_forward,
to_up=self.axis_up,
).to_4x4()
keywords["global_matrix"] = global_matrix
return export_3ds.save(self, context, **keywords)
def export_include(layout, operator, browser):
header, body = layout.panel("MAX3DS_export_include", default_closed=False)
header.label(text="Include")
if body:
if browser:
line = body.row(align=True)
line.prop(operator, "use_selection")
line.label(text="", icon='RESTRICT_SELECT_OFF' if operator.use_selection else 'RESTRICT_SELECT_ON')
body.column().prop(operator, "object_filter")
line = body.row(align=True)
line.prop(operator, "use_keyframes")
line.label(text="", icon='ANIM' if operator.use_keyframes else 'DECORATE_DRIVER')
line = body.row(align=True)
line.prop(operator, "use_hierarchy")
line.label(text="", icon='OUTLINER' if operator.use_hierarchy else 'CON_CHILDOF')
if browser:
line = body.row(align=True)
line.prop(operator, "use_collection")
line.label(text="", icon='OUTLINER_COLLECTION' if operator.use_collection else 'GROUP')
line = body.row(align=True)
line.prop(operator, "use_cursor")
line.label(text="", icon='PIVOT_CURSOR' if operator.use_cursor else 'CURSOR')
def export_transform(layout, operator):
header, body = layout.panel("MAX3DS_export_transform", default_closed=False)
header.label(text="Transform")
if body:
body.prop(operator, "scale_factor")
line = body.row(align=True)
line.prop(operator, "use_scene_unit")
line.label(text="", icon='EMPTY_ARROWS' if operator.use_scene_unit else 'EMPTY_DATA')
line = body.row(align=True)
line.prop(operator, "use_apply_transform")
line.label(text="", icon='MESH_CUBE' if operator.use_apply_transform else 'MOD_SOLIDIFY')
body.prop(operator, "axis_forward")
body.prop(operator, "axis_up")
class IO_FH_3ds(bpy.types.FileHandler):
bl_idname = "IO_FH_3ds"
bl_label = "Autodesk 3DS"
bl_import_operator = "import_scene.max3ds"
bl_export_operator = "export_scene.max3ds"
bl_file_extensions = ".3ds;.3DS"
@classmethod
def poll_drop(cls, context):
return poll_file_object_drop(context)
# Add to a menu
def menu_func_export(self, context):
self.layout.operator(Export3DS.bl_idname, text="3D Studio (.3ds)")
def menu_func_import(self, context):
self.layout.operator(Import3DS.bl_idname, text="3D Studio (.3ds)")
def register():
bpy.utils.register_class(Import3DS)
bpy.utils.register_class(Export3DS)
bpy.utils.register_class(IO_FH_3ds)
bpy.types.TOPBAR_MT_file_import.append(menu_func_import)
bpy.types.TOPBAR_MT_file_export.append(menu_func_export)
def unregister():
bpy.utils.unregister_class(Import3DS)
bpy.utils.unregister_class(Export3DS)
bpy.utils.unregister_class(IO_FH_3ds)
bpy.types.TOPBAR_MT_file_import.remove(menu_func_import)
bpy.types.TOPBAR_MT_file_export.remove(menu_func_export)
if __name__ == "__main__":
register()