forked from helluvamesh/GYAZ-Export-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.py
530 lines (472 loc) · 24.7 KB
/
ui.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
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any laTter version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####
##########################################################################################################
##########################################################################################################
import bpy
from bpy.types import Panel, Operator, UIList
class UI_UL_GYAZ_ExtraBones (UIList):
def draw_item (self, context, layout, data, set, icon, active_data, active_propname, index):
icon = 'BONE_DATA' if bpy.context.active_object.data.bones.get (set.source) is not None else 'ERROR'
row = layout.row (align=True)
row.prop (set, "name", icon=icon, emboss=False)
if bpy.context.scene.gyaz_export.extra_bones_long_rows:
row.separator ()
row.prop (set, "parent", text='', icon='NODETREE', emboss=False)
row.operator ('object.gyaz_export_set_parent_as_active_bone', text='', icon='EYEDROPPER', emboss=False).ui_index = index
row.separator ()
row.prop_search (set, "source", bpy.context.active_object.data, "bones", icon='GROUP_BONE')
row.operator ('object.gyaz_export_set_source_as_active_bone', text='', icon='EYEDROPPER').ui_index = index
class UI_UL_GYAZ_ExportBones (UIList):
def draw_item (self, context, layout, data, set, icon, active_data, active_propname, index):
row = layout.row (align=True)
row.prop_search (set, "name", bpy.context.active_object.data, "bones")
row.operator ('object.gyaz_export_set_name_as_active_bone', text='', icon='EYEDROPPER').ui_index = index
row.operator ('object.gyaz_export_remove_item_from_export_bones', text='', icon='REMOVE').ui_index = index
class UI_UL_GYAZ_ExportActions (UIList):
def draw_item (self, context, layout, data, set, icon, active_data, active_propname, index):
row = layout.row (align=True)
row.prop_search (set, "name", bpy.data, "actions", text='')
row.operator ('object.gyaz_export_set_active_action_to_export', text='', icon='EYEDROPPER').ui_index=index
row.operator ('object.gyaz_export_remove_item_from_actions', text='', icon='REMOVE').ui_index=index
class SCENE_PT_GYAZ_Export_Bones (Panel):
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
bl_label = 'Export Bones'
# add ui elements here
def draw (self, context):
if bpy.context.active_object.type == 'ARMATURE':
scene = bpy.context.scene
rig = bpy.context.active_object
lay = self.layout
owner = scene.gyaz_export
col = lay.column (align=True)
col.label (text='Bone Presets:')
row = col.row (align=True)
row.prop (owner, "active_preset", text='')
row.operator ('object.gyaz_export_save_preset', text='', icon='ADD')
row.operator ('object.gyaz_export_remove_preset', text='', icon='REMOVE')
col = lay.column (align=True)
col.use_property_split = True
col.use_property_decorate = False
col.prop (owner, 'root_mode')
if owner.root_mode == 'BONE':
col.prop_search (owner, 'root_bone_name', rig.data, "bones", icon='BONE_DATA', text='Bone')
col = lay.column (align=True)
row = col.row (align=True)
row.label (text='Extra Bones:')
row.prop (owner, "extra_bones")
if len (owner.extra_bones) > 0:
col.prop (owner, 'constraint_extra_bones')
col.prop (owner, 'rename_vert_groups_to_extra_bones')
col.prop (owner, 'extra_bones_long_rows')
extra_bones = owner.extra_bones
col = lay.column (align=True)
row = col.row (align=True)
row.operator ('object.gyaz_export_functions', text='', icon='ADD').ui_mode = 'ADD_TO_EXTRA_BONES'
row.operator ('object.gyaz_export_remove_item_from_extra_bones', text='', icon='REMOVE')
row.separator ()
op = row.operator ('object.gyaz_export_move_extra_bone_item', text='', icon='TRIA_UP').mode = 'UP'
op = row.operator ('object.gyaz_export_move_extra_bone_item', text='', icon='TRIA_DOWN').mode = 'DOWN'
row.separator ()
row.operator ('object.gyaz_export_functions', text='', icon='X').ui_mode = 'REMOVE_ALL_FROM_EXTRA_BONES'
row.separator ()
row.operator ('object.gyaz_export_read_selected_pose_bones', text='', icon='EYEDROPPER').mode='EXTRA_BONES'
if len (owner.extra_bones) > 0:
index = owner.extra_bones_active_index
item = extra_bones[index]
if len (owner.extra_bones) > 0:
lay.template_list ("UI_UL_GYAZ_ExtraBones", "", # type and unique id
owner, "extra_bones", # pointer to the CollectionProperty
owner, "extra_bones_active_index", # pointer to the active identifier
rows = 1, maxrows = 1)
col = lay.column (align=True)
if not owner.extra_bones_long_rows:
col.label (text='Source, Parent:')
col = col.column (align=True)
row = col.row (align=True)
row.prop_search (item, "source", rig.data, "bones", icon='GROUP_BONE')
row.operator ('object.gyaz_export_set_source_as_active_bone', text='', icon='EYEDROPPER').ui_index = index
row = col.row (align=True)
row.prop (item, "parent", text='', icon='NODETREE')
row.operator ('object.gyaz_export_set_parent_as_active_bone', text='', icon='EYEDROPPER').ui_index = index
else:
col.label (text='(New Name, Parent, Source)')
col = lay.column (align=True)
row = col.row (align=True)
row.label (text='Export Bones:')
row.prop (owner, "export_bones")
col.prop (owner, "export_all_bones")
col.separator ()
if not owner.export_all_bones:
row = col.row (align=True)
row.operator ('object.gyaz_export_functions', text='', icon='ADD').ui_mode = 'ADD_TO_EXPORT_BONES'
row.operator ('object.gyaz_export_functions', text='', icon='X').ui_mode = 'REMOVE_ALL_FROM_EXPORT_BONES'
row.separator ()
row.operator ('object.gyaz_export_read_selected_pose_bones', text='', icon='EYEDROPPER').mode='EXPORT_BONES'
row.separator ()
lay.template_list ("UI_UL_GYAZ_ExportBones", "", # type and unique id
owner, "export_bones", # pointer to the CollectionProperty
owner, "export_bones_active_index", # pointer to the active identifier
rows = 1, maxrows = 1)
# when the buttons should show up
@classmethod
def poll(cls, context):
mode = bpy.context.mode
obj = bpy.context.active_object
good_to_go = False
if obj is not None:
if obj.type == 'ARMATURE':
if mode == 'OBJECT' or mode == 'POSE':
good_to_go = True
if good_to_go:
return True
else:
return False
class SCENE_PT_GYAZ_Export_Animation (Panel):
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
bl_label = 'Export Animations'
# add ui elements here
def draw (self, context):
scene = bpy.context.scene
owner = scene.gyaz_export
lay = self.layout
lay.row().prop (owner, "action_export_mode", expand=True)
if owner.action_export_mode == 'BY_NAME':
row = lay.row (align=True)
row.operator ('object.gyaz_export_functions', text='', icon='ADD').ui_mode='ADD_TO_EXPORT_ACTIONS'
row.operator ('object.gyaz_export_functions', text='', icon='X').ui_mode='REMOVE_ALL_FROM_EXPORT_ACTIONS'
lay.template_list ("UI_UL_GYAZ_ExportActions", "", # type and unique id
owner, "actions", # pointer to the CollectionProperty
owner, "actions_active_index", # pointer to the active identifier
rows = 1, maxrows = 1)
obj = context.active_object
if obj is not None:
if obj.animation_data is not None:
action = obj.animation_data.action
if action is not None:
col = lay.column(align=True)
col.label(text="Active Action:")
row = col.row(align=True)
row.prop(action.gyaz_export, "start")
row.prop(action.gyaz_export, "end")
# when the buttons should show up
@classmethod
def poll(cls, context):
mode = bpy.context.mode
obj = bpy.context.active_object
good_to_go = False
if obj is not None:
if obj.type == 'ARMATURE':
if mode == 'OBJECT' or mode == 'POSE':
good_to_go = True
if good_to_go:
return True
else:
return False
class SCENE_PT_GYAZ_Export (Panel):
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
bl_label = 'Export'
# add ui elements here
def draw (self, context):
scene = bpy.context.scene
owner = scene.gyaz_export
lay = self.layout
lay.use_property_split = True
lay.use_property_decorate = False
row = lay.row (align=True)
row.prop (owner, "show_options", text='', icon='TRIA_DOWN' if owner.show_options else 'TRIA_RIGHT', emboss=False)
row.label (text='Options:')
if owner.show_options:
row.prop (owner, "show_debug_props", text='', icon='SOLO_OFF' if not owner.show_debug_props else 'SOLO_ON', emboss=False)
col = lay.column (align=True)
col.prop (owner, "texture_format_mode")
col.prop (owner, "texture_format_override", text='Override')
col.prop (owner, "texture_compression", text='Compression')
col = lay.column (align=True)
col.prop (owner, "use_prefixes")
col.prop (owner, "check_for_second_uv_map")
col.prop (owner, "detect_mirrored_uvs")
col.prop (owner, "allow_quads")
col.prop (owner, "add_end_bones")
col.prop (owner, "mesh_smoothing")
col = lay.column (align=True)
col.prop (owner, "primary_bone_axis")
col.prop (owner, "secondary_bone_axis")
if owner.show_debug_props:
col = lay.column ()
col = lay.column (align=True)
col.label (text='Debug:')
col.prop (owner, "dont_reload_scene")
obj = bpy.context.active_object
if obj is not None:
col = lay.column (align=True)
col.label (text='Destination:')
row = col.row (align=True)
row.use_property_split = False
row.prop (owner, 'export_folder_mode', expand=True)
relative = owner.export_folder_mode == 'RELATIVE_FOLDER'
path = '//' + owner.relative_folder_name if relative else owner.export_folder
row.operator ('object.gyaz_export_open_folder_in_explorer', text='', icon='VIEWZOOM').path=path
if relative:
lay.prop (owner, "relative_folder_name")
else:
lay.prop (owner, "export_folder", text="")
lay.label (text='Asset Type:')
col = lay.column (align=True)
col.use_property_split = False
if obj.type == 'ARMATURE':
asset_type = owner.skeletal_asset_type
col.prop (owner, 'skeletal_asset_type', expand=True)
else:
asset_type = owner.rigid_asset_type
col.prop (owner, 'rigid_asset_type', expand=True)
col = lay.column (align=True)
if asset_type == 'STATIC_MESHES':
col.prop (owner, "static_mesh_gather_from_collection")
if owner.static_mesh_gather_from_collection:
col.prop (owner, "static_mesh_gather_nested")
col.prop (owner, "use_static_mesh_organizing_folder")
col.prop (owner, "static_mesh_clear_transforms")
col.prop (owner, "static_mesh_vcolors")
col.prop (owner, "export_collision")
col.prop (owner, "export_sockets")
col.prop (owner, "export_lods")
if owner.check_for_second_uv_map:
col.prop (owner, "ignore_missing_second_uv_map")
col.prop (owner, "export_textures")
if owner.export_textures:
col.prop (owner, "export_only_textures")
col.prop (owner, "static_mesh_pack_objects")
if owner.static_mesh_pack_objects:
row = col.row (align=True)
row.label (icon='BLANK1')
row.prop (owner, "static_mesh_pack_name")
elif asset_type == 'SKELETAL_MESHES':
col.prop (owner, "skeletal_mesh_limit_bone_influences")
col.prop (owner, "use_skeletal_organizing_folder")
col.prop (owner, "skeletal_clear_transforms")
col.prop (owner, "skeletal_mesh_vcolors")
col.prop (owner, "skeletal_shapes")
col.prop (owner, "export_textures")
if owner.export_textures:
col.prop (owner, "export_only_textures")
col.prop (owner, "skeletal_mesh_pack_objects")
elif asset_type == 'ANIMATIONS':
col.prop (owner, "use_skeletal_organizing_folder")
col.prop (owner, 'use_anim_object_name_override')
if owner.use_anim_object_name_override:
row = col.row (align=True)
row.label (text='', icon='BLANK1')
row.prop (owner, 'anim_object_name_override')
col.prop (owner, "skeletal_clear_transforms")
col.prop (owner, "skeletal_shapes")
col.prop (owner, "frame_range_mode")
col.split()
col.alignment = "RIGHT"
col.label (text="{0} fps".format(scene.render.fps))
elif asset_type == 'RIGID_ANIMATIONS':
col.prop (owner, "rigid_anim_gather_from_collection")
if owner.rigid_anim_gather_from_collection:
col.prop (owner, "rigid_anim_gather_nested")
col.prop (owner, "use_rigid_anim_organizing_folder")
col.prop (owner, "rigid_anim_vcolors")
col.prop (owner, "rigid_anim_shapes")
row = col.row ()
row.enabled = True if not owner.rigid_anim_cubes or owner.rigid_anim_cubes and owner.rigid_anim_pack_objects else False
row.prop (owner, "export_textures")
row = col.row ()
rule1 = True if not owner.rigid_anim_pack_objects else False
row.enabled = rule1
row.prop (owner, "rigid_anim_cubes")
row = col.row ()
row.enabled = rule1
row.prop (owner, "frame_range_mode")
col.prop (owner, "rigid_anim_pack_objects")
if owner.rigid_anim_pack_objects:
row = col.row (align=True)
row.label (icon='BLANK1')
row.prop (owner, "rigid_anim_pack_name")
message1 = True
else:
message1 = False
col.label (text='Animation Name:')
row = col.row (align=True)
row.label (icon='BLANK1')
row.prop (owner, "rigid_anim_name")
if message1:
col.label (text="Scene start-end forced", icon='INFO')
col.split()
col.alignment = "RIGHT"
col.label (text="{0} fps".format(scene.render.fps))
row = lay.row (align=True)
row.scale_y = 2
row.operator ('object.gyaz_export_export', text='EXPORT', icon='EXPORT')
row.operator ('object.gyaz_export_select_file_in_explorer', text='', icon='VIEWZOOM').path=owner.path_to_last_export
# when the buttons should show up
@classmethod
def poll(cls, context):
obj = bpy.context.active_object
mode = bpy.context.mode
if obj is not None:
return mode == 'OBJECT' or mode == 'POSE' or mode == 'PAINT_TEXTURE' or mode == 'PAINT_VERTEX'
class SCENE_PT_GYAZ_Export_Filter (Panel):
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
bl_label = 'Export Filter'
# add ui elements here
def draw (self, context):
scene = bpy.context.scene
owner = scene.gyaz_export
lay = self.layout
obj = bpy.context.active_object
asset_type = owner.skeletal_asset_type if obj.type == 'ARMATURE' else owner.rigid_asset_type
# utility
row = lay.row (align=True)
row.scale_x = 1.5
row.operator ('object.gyaz_export_mark_all_selected_for_export', text='', icon='CHECKBOX_HLT')
row.operator ('object.gyaz_export_mark_all_selected_not_for_export', text='', icon='CHECKBOX_DEHLT')
row.separator ()
row.operator ('object.gyaz_export_mark_all_for_export', text='', icon='SCENE_DATA')
row.operator ('object.gyaz_export_mark_all_not_for_export', text='', icon='CHECKBOX_DEHLT')
row.separator ()
row.operator ('object.gyaz_export_set_filter_type', text=owner.filter_type)
col = lay.column (align=True)
col.prop (owner, "filter_string", text='', icon='VIEWZOOM')
filter = str.lower (owner.filter_string)
type = owner.filter_type
if asset_type == 'STATIC_MESHES' or asset_type == 'RIGID_ANIMATIONS':
col = lay.column (align=True)
for obj in bpy.context.selected_objects:
if obj.type == 'MESH':
show = False
name = str.lower (obj.name)
if type == 'IN':
if filter in name:
show = True
elif type == 'END':
if name.endswith (filter):
show = True
elif type == 'START':
if name.startswith (filter):
show = True
if show:
col.prop (obj.gyaz_export, "export", text=obj.name, emboss=True, toggle=True)
elif asset_type == 'SKELETAL_MESHES' or asset_type == 'ANIMATIONS':
col = lay.column (align=True)
for child in bpy.context.active_object.children:
if child.type == 'MESH':
show = False
name = str.lower (child.name)
if type == 'IN':
if filter in name:
show = True
elif type == 'END':
if name.endswith (filter):
show = True
elif type == 'START':
if name.startswith (filter):
show = True
if show:
col.prop (child.gyaz_export, "export", text=child.name, emboss=True, toggle=True)
# when the buttons should show up
@classmethod
def poll(cls, context):
ao = bpy.context.active_object
mode = bpy.context.mode
if ao is not None:
return mode == 'OBJECT' or mode == 'POSE' or mode == 'PAINT_TEXTURE' or mode == 'PAINT_VERTEX'
class SCENE_PT_GYAZ_Export_Extras (Panel):
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_EEVEE', 'BLENDER_WORKBENCH'}
bl_label = 'Export Extras'
# add ui elements here
def draw (self, context):
lay = self.layout
lay.operator ('import_scene.fbx', text='Import FBX')
owner = bpy.context.scene.gyaz_export_shapes
show = owner.show_props
row = lay.row(align=True)
row.prop (owner, 'show_props', icon='TRIA_DOWN' if show else 'TRIA_RIGHT', text="", emboss=False)
row.label (text='Shape Keys in UVs')
if show:
lay.prop (owner, 'encode_normals')
col = lay.column (align=True)
col.label (text='Base:')
col.prop (owner, 'base_mesh', text='')
col = lay.column (align=True)
col.label (text='Shape 1:')
col.prop (owner, 'shape_key_mesh_1', text='')
col = lay.column (align=True)
col.label (text='Shape 2:')
col.prop (owner, 'shape_key_mesh_2', text='')
if not owner.encode_normals:
col = lay.column (align=True)
col.label (text='Shape 3:')
col.prop (owner, 'shape_key_mesh_3', text='')
col = lay.column (align=True)
col.label (text='Shape 4:')
col.prop (owner, 'shape_key_mesh_4', text='')
col = lay.column (align=True)
col.label (text='Shape 5:')
col.prop (owner, 'shape_key_mesh_5', text='')
else:
col = lay.column (align=True)
col.label (text='Shape 3 (No Normals):')
col.prop (owner, 'shape_key_mesh_3', text='')
col = lay.column (align=True)
col.label (text='Shape Normal To Vert Color:')
col.prop (owner, 'shape_nor_to_vert_col', text='')
lay.separator ()
lay.operator ('object.gyaz_export_encode_shape_keys_in_uv_channels', text='Encode', icon='SHAPEKEY_DATA')
lay.separator ()
row = lay.row (align=True)
row.scale_y = 2
row.operator ('object.gyaz_export_export', text='EXPORT', icon='EXPORT')
row.operator ('object.gyaz_export_select_file_in_explorer', text='', icon='VIEWZOOM').path=bpy.context.scene.gyaz_export.path_to_last_export
def register():
bpy.utils.register_class (UI_UL_GYAZ_ExtraBones)
bpy.utils.register_class (UI_UL_GYAZ_ExportBones)
bpy.utils.register_class (UI_UL_GYAZ_ExportActions)
bpy.utils.register_class (SCENE_PT_GYAZ_Export_Bones)
bpy.utils.register_class (SCENE_PT_GYAZ_Export_Animation)
bpy.utils.register_class (SCENE_PT_GYAZ_Export)
bpy.utils.register_class (SCENE_PT_GYAZ_Export_Filter)
bpy.utils.register_class (SCENE_PT_GYAZ_Export_Extras)
def unregister():
bpy.utils.unregister_class (UI_UL_GYAZ_ExtraBones)
bpy.utils.unregister_class (UI_UL_GYAZ_ExportBones)
bpy.utils.unregister_class (UI_UL_GYAZ_ExportActions)
bpy.utils.unregister_class (SCENE_PT_GYAZ_Export_Bones)
bpy.utils.unregister_class (SCENE_PT_GYAZ_Export_Animation)
bpy.utils.unregister_class (SCENE_PT_GYAZ_Export)
bpy.utils.unregister_class (SCENE_PT_GYAZ_Export_Filter)
bpy.utils.unregister_class (SCENE_PT_GYAZ_Export_Extras)
if __name__ == "__main__":
register()