forked from soupday/cc_blender_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpanels.py
1955 lines (1629 loc) · 82.7 KB
/
panels.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
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (C) 2021 Victor Soupday
# This file is part of CC/iC Blender Tools <https://github.com/soupday/cc_blender_tools>
#
# CC/iC Blender Tools 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 3 of the License, or
# (at your option) any later version.
#
# CC/iC Blender Tools 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 CC/iC Blender Tools. If not, see <https://www.gnu.org/licenses/>.
from cmath import exp
import bpy
import textwrap
from . import addon_updater_ops
from . import rigging, rigify_mapping_data, characters, sculpting, physics, modifiers, channel_mixer, nodeutils, utils, params, vars
PIPELINE_TAB_NAME = "CC/iC Pipeline"
CREATE_TAB_NAME = "CC/iC Create"
# Panel button functions and operator
#
def context_character(context, exact = False):
props = bpy.context.scene.CC3ImportProps
chr_cache = props.get_context_character_cache(context, exact = exact)
obj = None
mat = None
obj_cache = None
mat_cache = None
if chr_cache:
obj = context.object
mat = utils.context_material(context)
obj_cache = chr_cache.get_object_cache(obj)
mat_cache = chr_cache.get_material_cache(mat)
return chr_cache, obj, mat, obj_cache, mat_cache
# Panel functions and classes
#
def fake_drop_down(row, label, prop_name, prop_bool_value):
props = bpy.context.scene.CC3ImportProps
if prop_bool_value:
row.prop(props, prop_name, icon="TRIA_DOWN", icon_only=True, emboss=False)
else:
row.prop(props, prop_name, icon="TRIA_RIGHT", icon_only=True, emboss=False)
row.label(text=label)
return prop_bool_value
def get_layout_width(region_type = "UI"):
ui_shelf = None
area = bpy.context.area
width = 15
for region in area.regions:
if region.type == region_type:
ui_shelf = region
width = int(ui_shelf.width / 8)
return width
def wrapped_text_box(layout, info_text, width, alert = False):
wrapper = textwrap.TextWrapper(width=width)
info_list = wrapper.wrap(info_text)
box = layout.box()
box.alert = alert
for text in info_list:
box.label(text=text)
def character_info_box(chr_cache, chr_rig, layout, show_name = True, show_type = True, show_type_selector = True):
props = bpy.context.scene.CC3ImportProps
prefs = bpy.context.preferences.addons[__name__.partition(".")[0]].preferences
is_character = False
is_non_standard = True
is_morph = False
if chr_cache:
character_name = chr_cache.character_name
is_non_standard = chr_cache.is_non_standard()
if chr_cache.is_standard():
type_text = f"Standard ({chr_cache.generation})"
else:
if "NonStandard" in chr_cache.generation:
generation = chr_cache.generation[11:]
if not generation:
generation = "Any"
type_text = f"Non-Standard ({generation})"
else:
type_text = f"Non-Standard ({chr_cache.generation})"
is_character = True
if chr_cache.is_morph():
is_morph = True
is_non_standard = False
type_text = "Obj/Morph"
elif chr_rig:
character_name = chr_rig.name
type_text = "Generic"
is_non_standard = True
is_character = True
if is_character:
box = layout.box()
if show_name:
box.row().label(text=f"Character: {character_name}")
if show_type:
box.row().label(text=f"Type: {type_text}")
if show_type_selector:
if is_non_standard:
row = box.row()
if chr_cache:
row.prop(chr_cache, "non_standard_type", expand=True)
elif chr_rig:
row.prop(prefs, "export_non_standard_mode", expand=True)
else:
box = layout.box()
box.row().label(text=f"No Character")
def pipeline_export_group(chr_cache, chr_rig, layout):
props = bpy.context.scene.CC3ImportProps
prefs = bpy.context.preferences.addons[__name__.partition(".")[0]].preferences
character_info_box(chr_cache, chr_rig, layout)
if chr_cache and chr_cache.rigified:
row = layout.row()
row.alert = True
row.label(text="Export from Rigging & Animation", icon="ERROR")
# export to CC3
character_export_button(chr_cache, chr_rig, layout)
layout.separator()
# export to Unity
character_export_unity_button(chr_cache, layout)
def rigify_export_group(chr_cache, layout):
props = bpy.context.scene.CC3ImportProps
prefs = bpy.context.preferences.addons[__name__.partition(".")[0]].preferences
row = layout.row()
row.label(text="Include T-Pose")
row.prop(props, "bake_unity_t_pose", text="")
row = layout.row()
row.scale_y = 2
if props.export_rigify_mode == "MESH":
row.operator("cc3.exporter", icon="ARMATURE_DATA", text="Export Mesh").param = "EXPORT_RIGIFY"
elif props.export_rigify_mode == "MOTION":
row.operator("cc3.exporter", icon="ARMATURE_DATA", text="Export Motion").param = "EXPORT_RIGIFY"
else:
row.operator("cc3.exporter", icon="ARMATURE_DATA", text="Export Mesh & Motion").param = "EXPORT_RIGIFY"
layout.row().prop(props, "export_rigify_mode", expand=True)
def character_export_button(chr_cache, chr_rig, layout):
# export to CC3
text = "Export to CC3/4"
icon = "MOD_ARMATURE"
standard_export = chr_cache and chr_cache.is_standard()
non_standard_export = (chr_cache and chr_cache.is_non_standard()) or (chr_rig and not standard_export)
if chr_cache:
row = layout.row()
row.scale_y = 2
if chr_cache and utils.is_file_ext(chr_cache.import_type, "OBJ"):
text = "Export Morph Target"
icon = "ARROW_LEFTRIGHT"
op = row.operator("cc3.exporter", icon=icon, text=text).param = "EXPORT_CC3"
if not chr_cache.can_export():
row.enabled = False
if not chr_cache.import_has_key:
if utils.is_file_ext(chr_cache.import_type, "FBX"):
layout.row().label(text="No Fbx-Key file!", icon="ERROR")
elif utils.is_file_ext(chr_cache.import_type, "OBJ"):
layout.row().label(text="No Obj-Key file!", icon="ERROR")
elif chr_rig:
row = layout.row()
row.scale_y = 2
text = "Export Non-Standard"
icon = "MONKEY"
op = row.operator("cc3.exporter", icon=icon, text=text).param = "EXPORT_NON_STANDARD"
else:
row = layout.row()
row.scale_y = 2
row.operator("cc3.exporter", icon=icon, text=text).param = "EXPORT_CC3"
row.enabled = False
row = layout.row()
row.alert = True
row.label(text="No current character!", icon="ERROR")
def character_export_unity_button(chr_cache, layout):
props = bpy.context.scene.CC3ImportProps
prefs = bpy.context.preferences.addons[__name__.partition(".")[0]].preferences
column = layout.column()
# export button
row = column.row()
row.scale_y = 2
if props.is_unity_project():
row.operator("cc3.exporter", icon="CUBE", text="Update Unity Project").param = "UPDATE_UNITY"
else:
row.operator("cc3.exporter", icon="CUBE", text="Export To Unity").param = "EXPORT_UNITY"
# export mode
column.row().prop(prefs, "export_unity_mode", expand=True)
# disable if no character, or not an fbx import
if not chr_cache or not utils.is_file_ext(chr_cache.import_type, "FBX") or chr_cache.rigified:
column.enabled = False
class ARMATURE_UL_List(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
if self.layout_type in {'DEFAULT', 'COMPACT'}:
layout.label(text=item.name if item else "", translate=False, icon_value=icon)
elif self.layout_type in {'GRID'}:
layout.alignment = 'CENTER'
layout.label(text="", icon_value=icon)
def filter_items(self, context, data, propname):
filtered = []
ordered = []
items = getattr(data, propname)
filtered = [self.bitflag_filter_item] * len(items)
for i, item in enumerate(items):
item_name = utils.strip_name(item.name)
allowed = False
if item.type == "ARMATURE": # only list armatures
if "_Rigify" not in item_name: # don't list rigified armatures
if "_Retarget" not in item_name: # don't list retarget armatures
if len(item.data.bones) > 0:
for allowed_bone in rigify_mapping_data.ALLOWED_RIG_BONES: # only list armatures of the allowed sources
if allowed_bone in item.data.bones:
allowed = True
if not allowed:
filtered[i] &= ~self.bitflag_filter_item
else:
if self.filter_name and self.filter_name != "*":
if self.filter_name not in item.name:
filtered[i] &= ~self.bitflag_filter_item
return filtered, ordered
class ACTION_UL_List(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
if self.layout_type in {'DEFAULT', 'COMPACT'}:
layout.label(text=item.name if item else "", translate=False, icon_value=icon)
elif self.layout_type in {'GRID'}:
layout.alignment = 'CENTER'
layout.label(text="", icon_value=icon)
def filter_items(self, context, data, propname):
props = bpy.context.scene.CC3ImportProps
filtered = []
ordered = []
arm_name = None
arm_object = utils.collection_at_index(props.armature_list_index, bpy.data.objects)
if arm_object and arm_object.type == "ARMATURE":
arm_name = arm_object.name
items = getattr(data, propname)
filtered = [self.bitflag_filter_item] * len(items)
item : bpy.types.Action
for i, item in enumerate(items):
if props.armature_action_filter and arm_object:
if arm_name and item.name.startswith(arm_name + "|A|"):
if self.filter_name and self.filter_name != "*":
if self.filter_name not in item.name:
filtered[i] &= ~self.bitflag_filter_item
elif arm_name and item.name.startswith(arm_name + "|") and not item.name.startswith(arm_name + "|K"):
if self.filter_name and self.filter_name != "*":
if self.filter_name not in item.name:
filtered[i] &= ~self.bitflag_filter_item
else:
filtered[i] &= ~self.bitflag_filter_item
else:
if len(item.fcurves) == 0: # no fcurves, no animation...
filtered[i] &= ~self.bitflag_filter_item
elif item.fcurves[0].data_path.startswith("key_blocks"): # only shapekey actions have key blocks...
filtered[i] &= ~self.bitflag_filter_item
else:
if self.filter_name and self.filter_name != "*":
if self.filter_name not in item.name:
filtered[i] &= ~self.bitflag_filter_item
return filtered, ordered
class UNITY_ACTION_UL_List(bpy.types.UIList):
def draw_item(self, context, layout, data, item, icon, active_data, active_propname, index):
if self.layout_type in {'DEFAULT', 'COMPACT'}:
layout.label(text=item.name if item else "", translate=False, icon_value=icon)
elif self.layout_type in {'GRID'}:
layout.alignment = 'CENTER'
layout.label(text="", icon_value=icon)
def filter_items(self, context, data, propname):
filtered = []
ordered = []
items = getattr(data, propname)
filtered = [self.bitflag_filter_item] * len(items)
item : bpy.types.Action
for i, item in enumerate(items):
if "_Unity" in item.name and "|A|" in item.name:
if len(item.fcurves) == 0: # no fcurves, no animation...
filtered[i] &= ~self.bitflag_filter_item
elif item.fcurves[0].data_path.startswith("key_blocks"): # only shapekey actions have key blocks...
filtered[i] &= ~self.bitflag_filter_item
if self.filter_name and self.filter_name != "*":
if self.filter_name not in item.name:
filtered[i] &= ~self.bitflag_filter_item
else:
filtered[i] &= ~self.bitflag_filter_item
return filtered, ordered
class CC3CharacterSettingsPanel(bpy.types.Panel):
bl_idname = "CC3_PT_Character_Settings_Panel"
bl_label = "Character Build Settings"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = PIPELINE_TAB_NAME
bl_options = {"DEFAULT_CLOSED"}
def draw(self, context):
layout = self.layout
props = bpy.context.scene.CC3ImportProps
prefs = bpy.context.preferences.addons[__name__.partition(".")[0]].preferences
chr_cache, obj, mat, obj_cache, mat_cache = context_character(context)
mesh_in_selection = False
for obj in bpy.context.selected_objects:
if obj.type == "MESH":
mesh_in_selection = True
box = layout.box()
#op = box.operator("cc3.importer", icon="IMPORT", text="Import Character")
#op.param ="IMPORT"
# import details
if chr_cache:
if fake_drop_down(box.row(), "Import Details", "stage1_details", props.stage1_details):
box.label(text="Name: " + chr_cache.character_name)
box.label(text="Type: " + chr_cache.import_type.upper())
split = box.split(factor=0.4)
col_1 = split.column()
col_2 = split.column()
col_1.label(text="Generation")
col_2.prop(chr_cache, "generation", text="")
col_1.label(text="Key File")
col_2.prop(chr_cache, "import_has_key", text="")
box.prop(chr_cache, "import_file", text="")
for obj_cache in chr_cache.object_cache:
if obj_cache.object:
box.prop(obj_cache, "object", text="")
box.label(text="Collision Mesh")
box.prop(chr_cache, "collision_body", text="")
else:
box.label(text="Name: " + chr_cache.character_name)
else:
box.label(text="No Character")
# Build Settings
layout.box().label(text="Build Settings", icon="TOOL_SETTINGS")
if prefs.physics == "ENABLED":
layout.prop(props, "physics_mode", expand=True)
layout.prop(prefs, "render_target", expand=True)
layout.prop(prefs, "refractive_eyes", expand=True)
split = layout.split(factor=0.9)
col_1 = split.column()
col_2 = split.column()
col_1.label(text="De-duplicate Materials")
col_2.prop(prefs, "import_deduplicate", text="")
col_1.label(text="Auto Convert Generic")
col_2.prop(prefs, "import_auto_convert", text="")
# Cycles Prefs
if prefs.render_target == "CYCLES":
box = layout.box()
if fake_drop_down(box.row(),
"Cycles Prefs",
"cycles_options",
props.cycles_options):
column = box.column()
split = column.split(factor=0.5)
col_1 = split.column()
col_2 = split.column()
col_1.label(text = "Skin SSS")
col_2.prop(prefs, "cycles_sss_skin_v118", text = "")
col_1.label(text = "Hair SSS")
col_2.prop(prefs, "cycles_sss_hair_v118", text = "")
col_1.label(text = "Teeth SSS")
col_2.prop(prefs, "cycles_sss_teeth", text = "")
col_1.label(text = "Tongue SSS")
col_2.prop(prefs, "cycles_sss_tongue", text = "")
col_1.label(text = "Eyes SSS")
col_2.prop(prefs, "cycles_sss_eyes", text = "")
col_1.label(text = "Default SSS")
col_2.prop(prefs, "cycles_sss_default", text = "")
# Build Button
if chr_cache:
box = layout.box()
box.row().label(text="Rebuild Materials", icon="MOD_BUILD")
row = box.row()
row.scale_y = 2
if chr_cache.setup_mode == "ADVANCED":
op = row.operator("cc3.importer", icon="SHADING_TEXTURE", text="Rebuild Advanced Materials")
else:
op = row.operator("cc3.importer", icon="NODE_MATERIAL", text="Rebuild Basic Materials")
op.param ="BUILD"
row = box.row()
row.prop(chr_cache, "setup_mode", expand=True)
row = box.row()
row.prop(props, "build_mode", expand=True)
box.row().operator("cc3.importer", icon="MOD_BUILD", text="Rebuild Node Groups").param ="REBUILD_NODE_GROUPS"
# Material Setup
layout.box().label(text="Object & Material Setup", icon="MATERIAL")
column = layout.column()
if not mesh_in_selection:
column.enabled = False
if obj is not None:
column.template_list("MATERIAL_UL_weightedmatslots", "", obj, "material_slots", obj, "active_material_index", rows=1)
split = column.split(factor=0.5)
col_1 = split.column()
col_2 = split.column()
if chr_cache and obj_cache:
if obj is not None:
obj_cache = chr_cache.get_object_cache(obj)
if obj_cache is not None:
col_1.label(text="Object Type")
col_2.prop(obj_cache, "object_type", text = "")
if mat is not None:
mat_cache = chr_cache.get_material_cache(mat)
if mat_cache is not None:
col_1.label(text="Material Type")
col_2.prop(mat_cache, "material_type", text = "")
col_1.label(text="Set By:")
col_1.prop(props, "quick_set_mode", expand=True)
col_1.label(text="")
op = col_2.operator("cc3.setmaterials", icon="SHADING_SOLID", text="Opaque")
op.param = "OPAQUE"
op = col_2.operator("cc3.setmaterials", icon="SHADING_WIRE", text="Blend")
op.param = "BLEND"
op = col_2.operator("cc3.setmaterials", icon="SHADING_RENDERED", text="Hashed")
op.param = "HASHED"
op = col_2.operator("cc3.setmaterials", icon="SHADING_TEXTURE", text="Clipped")
op.param = "CLIP"
split = column.split(factor=0.5)
col_1 = split.column()
col_2 = split.column()
col_1.separator()
col_2.separator()
op = col_1.operator("cc3.setmaterials", icon="NORMALS_FACE", text="Single Sided")
op.param = "SINGLE_SIDED"
op = col_2.operator("cc3.setmaterials", icon="XRAY", text="Double Sided")
op.param = "DOUBLE_SIDED"
class CC3ObjectManagementPanel(bpy.types.Panel):
bl_idname = "CC3_PT_Object_Management_Panel"
bl_label = "Object Management"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = CREATE_TAB_NAME
bl_options = {"DEFAULT_CLOSED"}
def draw(self, context):
layout = self.layout
props = bpy.context.scene.CC3ImportProps
prefs = bpy.context.preferences.addons[__name__.partition(".")[0]].preferences
chr_cache, obj, mat, obj_cache, mat_cache = context_character(context, exact = True)
chr_rig = None
if chr_cache:
chr_rig = chr_cache.get_armature()
elif context.selected_objects:
chr_rig = utils.get_generic_character_rig(context.selected_objects)
mesh_in_selection = False
all_mesh_in_selection = True
for obj in bpy.context.selected_objects:
if obj.type == "MESH":
mesh_in_selection = True
else:
all_mesh_in_selection = False
missing_object = False
removable_object = False
missing_material = False
weight_transferable = False
show_clean_up = chr_cache is not None
if bpy.context.selected_objects and bpy.context.active_object:
if chr_cache and obj_cache is None and obj and obj.type == "MESH":
missing_object = True
if obj != chr_rig and obj.parent != chr_rig:
missing_object = True
if chr_cache and obj_cache and obj.parent == chr_rig:
if (obj_cache.object_type != "BODY" and obj_cache.object_type != "EYE" and
obj_cache.object_type != "TEETH" and obj_cache.object_type != "TONGUE"):
removable_object = True
if chr_cache and obj and obj.type == "MESH" and not chr_cache.has_all_materials(obj.data.materials):
missing_material = True
if all_mesh_in_selection: # and arm.data.pose_position == "REST":
weight_transferable = True
if obj_cache and obj_cache.object_type == "BODY":
weight_transferable = False
column = layout.column()
# Converting
column.box().label(text="Converting", icon="DRIVER")
character_info_box(chr_cache, chr_rig, column)
row = column.row()
row.operator("cc3.character", icon="MESH_MONKEY", text="Convert to Non-standard").param = "CONVERT_TO_NON_STANDARD"
if not chr_cache or chr_cache.is_non_standard():
row.enabled = False
row = column.row()
if chr_rig:
row.operator("cc3.character", icon="COMMUNITY", text="Convert from Generic").param = "CONVERT_FROM_GENERIC"
else:
row.operator("cc3.character", icon="COMMUNITY", text="Convert from Objects").param = "CONVERT_FROM_GENERIC"
if chr_cache or not bpy.context.selected_objects:
row.enabled = False
column.separator()
# Accessory Management
column.box().label(text="Accessories", icon="GROUP_BONE")
accessory_root = characters.get_accessory_root(chr_cache, obj)
if accessory_root:
#column.box().label(text = f"Accessory: {accessory_root.name}")
box = column.box()
split = box.split(factor=0.375)
col_1 = split.column()
col_2 = split.column()
col_1.label(text="Accessory:")
col_2.prop(accessory_root, "name", text="")
col_1.label(text="Parent:")
col_2.prop(accessory_root, "parent", text="")
else:
split = None
if chr_cache and chr_rig:
split = column.split(factor=0.375)
col_1 = split.column()
col_2 = split.column()
col_1.label(text="Parent:")
col_2.prop_search(chr_cache, "accessory_parent_bone", chr_rig.data, "bones", text="")
row = column.row()
row.operator("cc3.character", icon="CONSTRAINT_BONE", text="Convert to Accessory").param = "CONVERT_ACCESSORY"
if not chr_cache or not obj or obj.type != "MESH" or (obj_cache and obj_cache.object_type == "BODY"):
row.enabled = False
if split:
split.enabled = False
column.separator()
# Checking
column.box().label(text="Checking", icon="SHADERFX")
row = column.row()
row.operator("cc3.exporter", icon="CHECKMARK", text="Check Export").param = "CHECK_EXPORT"
row = column.row()
row.operator("cc3.character", icon="REMOVE", text="Clean Up Data").param = "CLEAN_UP_DATA"
if not show_clean_up:
row.enabled = False
column.separator()
# Export Settings
column.box().label(text="Export Settings", icon="EXPORT")
split = column.split(factor=0.5)
split.column().label(text = "Texture Size")
split.column().prop(prefs, "export_texture_size", text = "")
column.separator()
# Objects & Materials
column.box().label(text="Objects & Materials", icon="OBJECT_HIDDEN")
row = column.row()
row.operator("cc3.character", icon="ADD", text="Add To Character").param = "ADD_PBR"
if not missing_object:
row.enabled = False
row = column.row()
row.operator("cc3.character", icon="REMOVE", text="Remove From Character").param = "REMOVE_OBJECT"
if not removable_object:
row.enabled = False
row = column.row()
row.operator("cc3.character", icon="ADD", text="Add New Materials").param = "ADD_MATERIALS"
if not missing_material:
row.enabled = False
column.separator()
# Armature & Weights
column.box().label(text = "Armature & Weights", icon = "ARMATURE_DATA")
if chr_rig:
column.row().prop(chr_rig.data, "pose_position", expand=True)
row = column.row()
row.operator("cc3.character", icon="MOD_DATA_TRANSFER", text="Transfer Weights").param = "TRANSFER_WEIGHTS"
if not weight_transferable:
row.enabled = False
row = column.row()
row.operator("cc3.character", icon="ORIENTATION_NORMAL", text="Normalize Weights").param = "NORMALIZE_WEIGHTS"
if not weight_transferable:
row.enabled = False
class CC3HairPanel(bpy.types.Panel):
bl_idname = "CC3_PT_Hair_Panel"
bl_label = "Blender Hair"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = CREATE_TAB_NAME
bl_options = {"DEFAULT_CLOSED"}
def draw(self, context):
layout = self.layout
props = bpy.context.scene.CC3ImportProps
prefs = bpy.context.preferences.addons[__name__.partition(".")[0]].preferences
chr_cache, obj, mat, obj_cache, mat_cache = context_character(context, exact = True)
# Exporting Blender Curve Hair
column = layout.column()
column.box().label(text="Exporting", icon="EXPORT")
column.row().operator("cc3.export_hair", icon=utils.check_icon("HAIR"), text="Export Hair")
column.row().prop(prefs, "hair_export_group_by", expand=True)
if not bpy.context.selected_objects:
column.enabled = False
return
# Spring Bone Hair Rig
column = layout.column()
column.box().label(text="Hair Rig", icon="EXPORT")
column.row().operator("cc3.hair", icon=utils.check_icon("HAIR"), text="Test 2").param = "TEST2"
# Hair curve extraction
column = layout.column()
column.box().label(text="Extract Curves", icon="EXPORT")
column.row().prop(prefs, "hair_curve_dir", text="")
column.row().prop(prefs, "hair_curve_dir_threshold", text="Alignment Threshold", slider=True)
column.row().operator("cc3.hair", icon=utils.check_icon("HAIR"), text="Test").param = "TEST"
if not bpy.context.selected_objects:
column.enabled = False
class CC3MaterialParametersPanel(bpy.types.Panel):
bl_idname = "CC3_PT_Parameters_Panel"
bl_label = "Material Parameters"
bl_space_type = "VIEW_3D"
bl_region_type = "UI"
bl_category = PIPELINE_TAB_NAME
bl_options = {"DEFAULT_CLOSED"}
def draw(self, context):
layout = self.layout
props = bpy.context.scene.CC3ImportProps
prefs = bpy.context.preferences.addons[__name__.partition(".")[0]].preferences
chr_cache, obj, mat, obj_cache, mat_cache = context_character(context)
shader = "NONE"
parameters = None
if mat_cache:
parameters = mat_cache.parameters
# Parameters
if chr_cache and mat_cache and fake_drop_down(layout.box().row(),
"Adjust Parameters",
"stage4",
props.stage4):
# material selector
#column = layout.column()
#obj_cache = mat_cache = None
#mat_type = "NONE"
#if obj is not None:
# column.template_list("MATERIAL_UL_weightedmatslots", "", obj, "material_slots", obj, "active_material_index", rows=1)
column = layout.column()
row = column.row()
row.prop(props, "update_mode", expand=True)
linked = props.update_mode == "UPDATE_LINKED"
has_key = chr_cache.import_has_key
if chr_cache.setup_mode == "ADVANCED":
shader = params.get_shader_name(mat_cache)
bsdf_node, shader_node, mix_node = nodeutils.get_shader_nodes(mat, shader)
matrix = params.get_shader_def(shader)
if matrix and "ui" in matrix.keys():
ui_matrix = matrix["ui"]
column.separator()
box = column.box()
box.row().label(text = matrix["label"] + " Parameters", icon="MOD_HUE_SATURATION")
box.row().label(text = f"Material: {mat.name}", icon="SHADING_TEXTURE")
for ui_row in ui_matrix:
split = False
col_1 = None
col_2 = None
if ui_row[0] == "HEADER":
column.box().label(text= ui_row[1], icon=utils.check_icon(ui_row[2]))
elif ui_row[0] == "PROP":
show_prop = True
label = ui_row[1]
prop = ui_row[2]
is_slider = ui_row[3]
conditions = ui_row[4:]
alert = False
if len(label) > 0 and label.startswith("*"):
if has_key:
alert = True
label = label[1:]
if shader:
for condition in conditions:
if condition == "HAS_VERTEX_COLORS":
cond_res = len(obj.data.vertex_colors) > 0
elif condition[0] == '#':
cond_res = chr_cache.render_target == condition[1:]
elif condition[0] == '!':
condition = condition[1:]
cond_res = not nodeutils.has_connected_input(shader_node, condition)
else:
cond_res = nodeutils.has_connected_input(shader_node, condition)
if not cond_res:
show_prop = False
if show_prop:
if not split:
row = column.row()
split = row.split(factor=0.5)
col_1 = row.column()
col_2 = row.column()
split = True
col_1.alert = alert
col_1.label(text=label)
#col_2.alert = alert
col_2.prop(parameters, prop, text="", slider=is_slider)
elif ui_row[0] == "OP":
show_op = True
label = ui_row[1]
op_id = ui_row[2]
icon = utils.check_icon(ui_row[3])
param = ui_row[4]
conditions = ui_row[5:]
if shader:
for condition in conditions:
if condition[0] == '!':
condition = condition[1:]
cond_res = not nodeutils.has_connected_input(shader_node, condition)
else:
cond_res = nodeutils.has_connected_input(shader_node, condition)
if not cond_res:
show_op = False
if show_op:
row = column.row()
row.operator(op_id, icon=icon, text=label).param = param
split = False
elif ui_row[0] == "SPACER":
if not split:
row = column.row()
split = row.split(factor=0.5)
col_1 = row.column()
col_2 = row.column()
split = True
col_1.separator()
col_2.separator()
else:
basic_params = chr_cache.basic_parameters
bsdf_node = nodeutils.get_shader_nodes(mat, shader)[0]
column.separator()
column.box().label(text = "Basic Parameters:", icon="MOD_HUE_SATURATION")
actor_core = False
if chr_cache.generation == "ActorCore":
actor_core = True
if not actor_core:
column.box().label(text= "Skin", icon="OUTLINER_OB_ARMATURE")
split = column.split(factor=0.5)
col_1 = split.column()
col_2 = split.column()
col_1.label(text="Skin AO")
col_2.prop(basic_params, "skin_ao", text="", slider=True)
col_1.label(text="Skin Specular")
col_2.prop(basic_params, "skin_specular", text="", slider=True)
col_1.label(text="Skin Roughness")
col_2.prop(basic_params, "skin_roughness", text="", slider=True)
column.box().label(text= "Eyes", icon="MATSPHERE")
split = column.split(factor=0.5)
col_1 = split.column()
col_2 = split.column()
col_1.label(text="Eye Brightness")
col_2.prop(basic_params, "eye_brightness", text="", slider=True)
col_1.label(text="Eye Specular")
col_2.prop(basic_params, "eye_specular", text="", slider=True)
col_1.label(text="Eye Roughness")
col_2.prop(basic_params, "eye_roughness", text="", slider=True)
col_1.label(text="Eye Normal")
col_2.prop(basic_params, "eye_normal", text="", slider=True)
column.box().label(text= "Eye Occlusion", icon="PROP_CON")
split = column.split(factor=0.5)
col_1 = split.column()
col_2 = split.column()
col_1.label(text="Eye Occlusion")
col_2.prop(basic_params, "eye_occlusion", text="", slider=True)
col_1.label(text="Eye Occlusion Hardness")
col_2.prop(basic_params, "eye_occlusion_power", text="", slider=True)
column.box().label(text= "Tearline", icon="MATFLUID")
split = column.split(factor=0.5)
col_1 = split.column()
col_2 = split.column()
col_1.label(text="Tearline Alpha")
col_2.prop(basic_params, "tearline_alpha", text="", slider=True)
col_1.label(text="Tearline Roughness")
col_2.prop(basic_params, "tearline_roughness", text="", slider=True)
column.box().label(text= "Teeth", icon="RIGID_BODY")
split = column.split(factor=0.5)
col_1 = split.column()
col_2 = split.column()
col_1.label(text="Teeth Specular")
col_2.prop(basic_params, "teeth_specular", text="", slider=True)
col_1.label(text="Teeth Roughness")
col_2.prop(basic_params, "teeth_roughness", text="", slider=True)
column.box().label(text= "Tongue", icon="INVERSESQUARECURVE")
split = column.split(factor=0.5)
col_1 = split.column()
col_2 = split.column()
col_1.label(text="Tongue Specular")
col_2.prop(basic_params, "tongue_specular", text="", slider=True)
col_1.label(text="Tongue Roughness")
col_2.prop(basic_params, "tongue_roughness", text="", slider=True)
column.box().label(text= "Hair", icon="OUTLINER_OB_HAIR")
split = column.split(factor=0.5)
col_1 = split.column()
col_2 = split.column()
col_1.label(text="Hair AO")
col_2.prop(basic_params, "hair_ao", text="", slider=True)
col_1.label(text="Hair Specular")
col_2.prop(basic_params, "hair_specular", text="", slider=True)
col_1.label(text="Scalp Specular")
col_2.prop(basic_params, "scalp_specular", text="", slider=True)
col_1.label(text="Hair Bump Height (mm)")
col_2.prop(basic_params, "hair_bump", text="", slider=True)
if actor_core:
column.box().label(text= "Actor Core", icon="USER")
else:
column.box().label(text= "Default", icon="CUBE")
split = column.split(factor=0.5)
col_1 = split.column()
col_2 = split.column()
col_1.label(text="Default AO")
col_2.prop(basic_params, "default_ao", text="", slider=True)
col_1.label(text="Default Specular")
col_2.prop(basic_params, "default_specular", text="", slider=True)
if not actor_core:
col_1.label(text="Default Bump Height (mm)")
col_2.prop(basic_params, "default_bump", text="", slider=True)
# Channel Mixers
if chr_cache and mat_cache and chr_cache.setup_mode == "ADVANCED":
mixer_settings = mat_cache.mixer_settings
if chr_cache and mat_cache and fake_drop_down(layout.box().row(),
"Texture Channel Mixer",
"stage_remapper",
props.stage_remapper):
column = layout.column()
show_channels = False
for mixer_ref in channel_mixer.MIXER_CHANNELS:
if type(mixer_ref) == str:
if mixer_ref == "RGB_HEADER":
column.box().label(text="RGB Mask", icon="RESTRICT_COLOR_ON")
column.label(text = "RGB Mask Image:")
if mixer_settings.rgb_image:
column.template_ID_preview(mixer_settings, "rgb_image", open="image.open")
show_channels = True
else:
column.template_ID(mixer_settings, "rgb_image", open="image.open", live_icon=True)
show_channels = False
elif mixer_ref == "ID_HEADER":
column.separator()
column.box().label(text="Color ID Mask", icon="GROUP_VCOL")
column.label(text = "Color ID Mask Image:")
if mixer_settings.id_image:
column.template_ID_preview(mixer_settings, "id_image", open="image.open")
show_channels = True
else:
column.template_ID(mixer_settings, "id_image", open="image.open", live_icon=True)
show_channels = False
elif show_channels:
mixer_label = mixer_ref[0]
mixer_on_prop = mixer_ref[1]
mixer_type_channel = mixer_ref[2]
mixer_type, mixer_channel = mixer_type_channel.split("_")
mixer = mixer_settings.get_mixer(mixer_type, mixer_channel)
column = layout.column()
box = column.box()
split = box.split(factor=0.75)
col_1 = split.column()
col_2 = split.column()
expanded = False
if mixer:
expanded = mixer.expanded
row = col_1.row()