-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy path__init__.py
437 lines (354 loc) · 13 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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
bl_info = {
"name": "Torque DTS format",
"author": "port",
"version": (0, 2, 0),
"blender": (2, 74, 0),
"location": "File > Import-Export",
"description": "Import-Export DTS, Import DTS mesh, UV's, "
"materials and textures",
"warning": "",
"support": 'COMMUNITY',
"category": "Import-Export"}
if "bpy" in locals():
import importlib
if "import_dts" in locals():
importlib.reload(import_dts)
if "import_dsq" in locals():
importlib.reload(import_dsq)
if "export_dts" in locals():
importlib.reload(export_dts)
if "export_dsq" in locals():
importlib.reload(export_dsq)
is_developer = False
try:
from .developer import is_developer
except ImportError:
pass
if is_developer:
debug_prop_options = set()
else:
debug_prop_options = {'HIDDEN'}
import bpy
from bpy.props import (BoolProperty,
FloatProperty,
IntProperty,
StringProperty,
EnumProperty,
PointerProperty,
)
from bpy_extras.io_utils import (ImportHelper,
ExportHelper,
)
class ImportDTS(bpy.types.Operator, ImportHelper):
"""Load a Torque DTS File"""
bl_idname = "import_scene.dts"
bl_label = "Import DTS"
bl_options = {'PRESET', 'UNDO'}
filename_ext = ".dts"
filter_glob = StringProperty(
default="*.dts",
options={'HIDDEN'},
)
reference_keyframe = BoolProperty(
name="Reference keyframe",
description="Set a keyframe with the reference pose for blend animations",
default=True,
)
import_sequences = BoolProperty(
name="Import sequences",
description="Automatically add keyframes for embedded sequences",
default=True,
)
use_armature = BoolProperty(
name="Experimental: Skeleton as armature",
description="Import bones into an armature instead of empties. Does not work with 'Import sequences'",
default=False,
)
debug_report = BoolProperty(
name="Write debug report",
description="Dump out all the information from the DTS to a file",
options=debug_prop_options,
default=False,
)
def execute(self, context):
from . import import_dts
keywords = self.as_keywords(ignore=("filter_glob", "split_mode"))
return import_dts.load(self, context, **keywords)
class ImportDSQ(bpy.types.Operator, ImportHelper):
"""Load a Torque DSQ File"""
bl_idname = "import_scene.dsq"
bl_label = "Import DSQ"
bl_options = {'PRESET', 'UNDO'}
filename_ext = ".dsq"
filter_glob = StringProperty(
default="*.dsq",
options={'HIDDEN'},
)
debug_report = BoolProperty(
name="Write debug report",
description="Dump out all the information from the DSQ to a file",
options=debug_prop_options,
default=False,
)
def execute(self, context):
from . import import_dsq
keywords = self.as_keywords(ignore=("filter_glob", "split_mode"))
return import_dsq.load(self, context, **keywords)
class ExportDTS(bpy.types.Operator, ExportHelper):
"""Save a Torque DTS File"""
bl_idname = "export_scene.dts"
bl_label = 'Export DTS'
bl_options = {'PRESET'}
filename_ext = ".dts"
filter_glob = StringProperty(
default="*.dts",
options={'HIDDEN'},
)
select_object = BoolProperty(
name="Selected objects only",
description="Export selected objects (empties, meshes) only",
default=False,
)
select_marker = BoolProperty(
name="Selected markers only",
description="Export selected timeline markers only, used for sequences",
default=False,
)
blank_material = BoolProperty(
name="Blank material",
description="Add a blank material to meshes with none assigned",
default=True,
)
generate_texture = EnumProperty(
name="Generate textures",
description="Automatically generate solid color textures for materials",
default="disabled",
items=(
("disabled", "Disabled", "Do not generate any textures"),
("custom-missing", "Custom (if missing)", "Generate textures for non-default material names if not already present"),
("custom-always", "Custom (always)", "Generate textures for non-default material names"),
("all-missing", "All (if missing)", "Generate textures for all materials if not already present"),
("all-always", "All (always)", "Generate textures for all materials"))
)
raw_colors = BoolProperty(
name="Use raw material colors",
description="Use raw rgb material colors when generating textures",
default = False,
)
dsq_compat = BoolProperty(
name="Export with DSQ compatibility",
description="Use to ensure imported and reexported models work with previously existing DSQ's. Do not enable if you are not reexporting an imported model.",
default=False,
)
apply_modifiers = BoolProperty(
name="Apply modifiers",
description="Apply modifiers to meshes",
default=True,
)
debug_report = BoolProperty(
name="Write debug report",
description="Dump out all the information from the DTS to a file",
options=debug_prop_options,
default=False,
)
check_extension = True
def execute(self, context):
from . import export_dts
keywords = self.as_keywords(ignore=("check_existing", "filter_glob"))
return export_dts.save(self, context, **keywords)
class ExportDSQ(bpy.types.Operator, ExportHelper):
"""Save many Torque DSQ Files"""
bl_idname = "export_scene.dsq"
bl_label = 'Export DSQ'
bl_options = {'PRESET'}
filename_ext = ".dsq"
filter_glob = StringProperty(
default="*.dsq",
options={'HIDDEN'},
)
select_marker = BoolProperty(
name="Selection only",
description="Export selected timeline markers only",
default=False,
)
debug_report = BoolProperty(
name="Write debug report",
description="Dump out all the information from the DSQ to a file",
options=debug_prop_options,
default=False,
)
check_extension = True
def execute(self, context):
from . import export_dsq
keywords = self.as_keywords(ignore=("check_existing", "filter_glob"))
return export_dsq.save(self, context, **keywords)
class SplitMeshIndex(bpy.types.Operator):
"""Split a mesh into new meshes limiting the number of indices"""
bl_idname = "mesh.split_mesh_vindex"
bl_label = "Split mesh by indices"
bl_options = {"REGISTER", "UNDO"}
def execute(self, context):
limit = 10922
ob = context.active_object
if ob is None or ob.type != "MESH":
self.report({"ERROR"}, "Select a mesh object first")
return {"FINISHED"}
me = ob.data
out_me = None
out_ob = None
def split():
nonlocal out_me
nonlocal out_ob
if out_me is not None:
out_me.validate()
out_me.update()
out_me = bpy.data.meshes.new(ob.name)
out_ob = bpy.data.objects.new(ob.name, out_me)
context.scene.objects.link(out_ob)
# For now, copy all verts over. See what happens?
out_me.vertices.add(len(me.vertices))
for vert, out_vert in zip(me.vertices, out_me.vertices):
out_vert.co = vert.co
out_vert.normal = vert.normal
split()
for poly in me.polygons:
if poly.loop_total >= limit:
continue
if len(out_me.loops) + poly.loop_total > limit:
split()
loop_start = len(out_me.loops)
out_me.loops.add(poly.loop_total)
out_me.polygons.add(1)
out_poly = out_me.polygons[-1]
out_poly.loop_start = loop_start
out_poly.loop_total = poly.loop_total
out_poly.use_smooth = poly.use_smooth
for loop_index, out_loop_index in zip(poly.loop_indices, out_poly.loop_indices):
loop = me.loops[loop_index]
out_loop = out_me.loops[out_loop_index]
out_loop.normal = loop.normal
out_loop.vertex_index = loop.vertex_index
out_me.validate()
out_me.update()
return {"FINISHED"}
class HideBlockheadNodes(bpy.types.Operator):
"""Set all non-default Blockhead model apparel meshes as hidden"""
bl_idname = "mesh.hide_blockhead_nodes"
bl_label = "Hide Blockhead nodes on selection"
bl_options = {"REGISTER", "UNDO"}
blacklist = (
"copHat",
"knitHat",
"pack",
"quiver",
"femChest",
"epauletsRankB",
"epauletsRankC",
"epauletsRankD",
"epauletsRankA",
"skirtHip",
"skirtTrimRight",
"RHook",
"RarmSlim",
"LHook",
"LarmSlim",
"PointyHelmet",
"Helmet",
"bicorn",
"scoutHat",
"FlareHelmet",
"triPlume",
"plume",
"septPlume",
"tank",
"armor",
"cape",
"Bucket",
"epaulets",
"ShoulderPads",
"Rski",
"Rpeg",
"Lski",
"Lpeg",
"skirtTrimLeft",
"Visor",
)
def execute(self, context):
for ob in context.scene.objects:
if ob.select and ob.type == "MESH" and ob.name in self.blacklist:
ob.hide = True
return {"FINISHED"}
class TorqueMaterialProperties(bpy.types.PropertyGroup):
blend_mode = EnumProperty(
name="Blend mode",
items=(
("ADDITIVE", "Additive", "White is white, black is transparent"),
("SUBTRACTIVE", "Subtractive", "White is black, black is transparent"),
("NONE", "None", "I don't know how to explain this, try it yourself"),
),
default="ADDITIVE")
s_wrap = BoolProperty(name="S-Wrap", default=True)
t_wrap = BoolProperty(name="T-Wrap", default=True)
no_mipmaps = BoolProperty(name="No Mipmaps", default=True)
mip_bzero = BoolProperty(name="Mipmap Zero Border", default=False)
use_ifl = BoolProperty(name="IFL")
ifl_name = StringProperty(name="Name")
class TorqueMaterialPanel(bpy.types.Panel):
bl_idname = "MATERIAL_PT_torque"
bl_label = "Torque"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "material"
bl_options = {'DEFAULT_CLOSED'}
@classmethod
def poll(cls, context):
return (context.material is not None)
def draw(self, context):
layout = self.layout
obj = context.material
sublayout = layout.row()
sublayout.enabled = obj.use_transparency
sublayout.prop(obj.torque_props, "blend_mode", expand=True)
row = layout.row()
row.prop(obj.torque_props, "use_ifl")
sublayout = row.column()
sublayout.enabled = obj.torque_props.use_ifl
sublayout.prop(obj.torque_props, "ifl_name", text="")
sublayout = layout.column()
sublayout.enabled = obj.torque_props.use_ifl
row = layout.row()
sublayout = row.column()
sublayout.prop(obj.torque_props, "s_wrap")
sublayout = row.column()
sublayout.prop(obj.torque_props, "t_wrap")
row = layout.row()
sublayout = row.column()
sublayout.prop(obj.torque_props, "no_mipmaps")
sublayout = row.column()
sublayout.enabled = not obj.torque_props.no_mipmaps
sublayout.prop(obj.torque_props, "mip_bzero")
def menu_func_import_dts(self, context):
self.layout.operator(ImportDTS.bl_idname, text="Torque (.dts)")
def menu_func_import_dsq(self, context):
self.layout.operator(ImportDSQ.bl_idname, text="Torque Sequences (.dsq)")
def menu_func_export_dts(self, context):
self.layout.operator(ExportDTS.bl_idname, text="Torque (.dts)")
def menu_func_export_dsq(self, context):
self.layout.operator(ExportDSQ.bl_idname, text="Torque Sequences (.dsq)")
def register():
bpy.utils.register_module(__name__)
bpy.types.Material.torque_props = PointerProperty(
type=TorqueMaterialProperties)
bpy.types.INFO_MT_file_import.append(menu_func_import_dts)
bpy.types.INFO_MT_file_import.append(menu_func_import_dsq)
bpy.types.INFO_MT_file_export.append(menu_func_export_dts)
bpy.types.INFO_MT_file_export.append(menu_func_export_dsq)
def unregister():
bpy.utils.unregister_module(__name__)
del bpy.types.Material.torque_props
bpy.types.INFO_MT_file_import.remove(menu_func_import_dts)
bpy.types.INFO_MT_file_import.remove(menu_func_import_dsq)
bpy.types.INFO_MT_file_export.remove(menu_func_export_dts)
bpy.types.INFO_MT_file_export.remove(menu_func_export_dsq)
if __name__ == "__main__":
register()