-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate.py
2150 lines (1866 loc) · 87.1 KB
/
generate.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) 2024 Roni Raihan
# Some code functions, generated by AI ChatGPT < https://chat.openai.com/ >
# 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 3 of the License, or
# (at your option) any later 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, see < https://www.gnu.org/licenses/ >.
import bpy
from bpy.props import (
FloatProperty,
FloatVectorProperty,
EnumProperty,
IntProperty,
BoolProperty,
CollectionProperty
)
#from . import operatorvrm
#-----------------------------------------------------------------------
list_tulang_hilang = []
list_parent_hilang = []
class info_rig_masalah(bpy.types.Operator):
bl_idname = "obj.info_masalah_rig"
bl_label = "Info"
bl_options = {'REGISTER', 'UNDO'}
fb0 : bpy.props.StringProperty(name= "Bone", default= "")
fb1 : bpy.props.StringProperty(name= "Bone", default= "")
fb2 : bpy.props.StringProperty(name= "Bone", default= "")
fb3 : bpy.props.StringProperty(name= "Bone", default= "")
fb4 : bpy.props.StringProperty(name= "Bone", default= "")
fb5 : bpy.props.StringProperty(name= "Bone", default= "")
fb6 : bpy.props.StringProperty(name= "Bone", default= "")
fb7 : bpy.props.StringProperty(name= "Bone", default= "")
fb8 : bpy.props.StringProperty(name= "Bone", default= "")
fb9 : bpy.props.StringProperty(name= "Bone", default= "")
def execute(self, context):
bpy.ops.obj.cek_rig()
return {'FINISHED'}
def invoke(self, context, event):
bpy.ops.obj.cek_rig()
return context.window_manager.invoke_popup(self)
#return {'FINISHED'}
def draw(self, context):
global list_tulang_hilang
global list_parent_hilang
dmta = bpy.context.scene.vrm_meta
layout = self.layout
if dmta.find_bone and dmta.find_parent:
layout.label(text= "Bone none have mising part", icon= 'CHECKMARK')
else:
row = layout.row()
if not dmta.find_bone:
jumlah_bone = len(list_tulang_hilang)
text_mising_bone = ("Mising required bone (%i Bone) :" % (jumlah_bone))
layout.label(text= text_mising_bone, icon= 'ERROR')
box = layout.box()
kotak = box.column()
kotak.scale_y = 0.9
kotak.label(text= "Tips:", icon= 'QUESTION')
kotak.label(text= "Add bones with this name in Armature Rig Main", icon= 'BLANK1')
dalam = kotak.box()
sd = dalam.column()
dalam = sd.row()
kumpul = dalam.column()
if jumlah_bone > 0:
self.fb0 = list_tulang_hilang[0]
kumpul.prop(self, "fb0", text = "")
if jumlah_bone > 1:
self.fb1 = list_tulang_hilang[1]
kumpul.prop(self, "fb1", text = "")
if jumlah_bone > 2:
self.fb2 = list_tulang_hilang[2]
kumpul.prop(self, "fb2", text = "")
if jumlah_bone > 3:
self.fb3 = list_tulang_hilang[3]
kumpul.prop(self, "fb3", text = "")
if jumlah_bone > 4:
self.fb4 = list_tulang_hilang[4]
kumpul.prop(self, "fb4", text = "")
if jumlah_bone > 5:
kumpul = dalam.split()
kumpul = kumpul.column()
self.fb5 = list_tulang_hilang[5]
kumpul.prop(self, "fb5", text = "")
if jumlah_bone > 6:
self.fb6 = list_tulang_hilang[6]
kumpul.prop(self, "fb6", text = "")
if jumlah_bone > 7:
self.fb7 = list_tulang_hilang[7]
kumpul.prop(self, "fb7", text = "")
if jumlah_bone > 8:
self.fb8 = list_tulang_hilang[8]
kumpul.prop(self, "fb8", text = "")
if jumlah_bone > 9:
self.fb9 = list_tulang_hilang[9]
kumpul.prop(self, "fb9", text = "")
if jumlah_bone > 10:
ld10 = ("And more %i Bone" % (jumlah_bone - 10))
sd.label(text= ld10)
row = layout.row()
if not dmta.find_parent:
jumlah_mispare = len(list_parent_hilang)
text_mispare = ("Bone has incorrect Parent (%i Bone):" % (jumlah_mispare))
layout.label(text= text_mispare, icon= 'ERROR')
box = layout.box()
kotak = box.column()
kotak.scale_y = 0.9
print ("list_parent_hilang", list_parent_hilang)
if jumlah_mispare > 0:
ng = list_parent_hilang[0]['ng']
ka = list_parent_hilang[0]['ka']
al = list_parent_hilang[0]['al']
al2 = list_parent_hilang[0]['al2']
if al2 == al:
daft1 = ("Bone : %s must be parent to Bone: %s or %s" % (ng, ka, al))
if al == ka:
daft1 = ("Bone : %s must be parent to Bone: %s" % (ng, ka))
else:
daft1 = ("Bone : %s must be parent to Bone: %s or %s or %s" % (ng, ka, al, al2))
kotak.label(text= daft1)
if jumlah_mispare > 1:
ng = list_parent_hilang[1]['ng']
ka = list_parent_hilang[1]['ka']
al = list_parent_hilang[1]['al']
al2 = list_parent_hilang[1]['al2']
if al2 == al:
daft2 = ("Bone : %s must be parent to Bone: %s or %s" % (ng, ka, al))
if al == ka:
daft2 = ("Bone : %s must be parent to Bone: %s" % (ng, ka))
else:
daft2 = ("Bone : %s must be parent to Bone: %s or %s or %s" % (ng, ka, al, al2))
kotak.label(text= daft2)
if jumlah_mispare > 2:
ng = list_parent_hilang[2]['ng']
ka = list_parent_hilang[2]['ka']
al = list_parent_hilang[2]['al']
al2 = list_parent_hilang[2]['al2']
if al2 == al:
daft3 = ("Bone : %s must be parent to Bone: %s or %s" % (ng, ka, al))
if al == ka:
daft3 = ("Bone : %s must be parent to Bone: %s" % (ng, ka))
else:
daft3 = ("Bone : %s must be parent to Bone: %s or %s or %s" % (ng, ka, al, al2))
kotak.label(text= daft3)
if jumlah_mispare > 3:
ng = list_parent_hilang[3]['ng']
ka = list_parent_hilang[3]['ka']
al = list_parent_hilang[3]['al']
al2 = list_parent_hilang[3]['al2']
if al2 == al:
daft4 = ("Bone : %s must be parent to Bone: %s or %s" % (ng, ka, al))
if al == ka:
daft4 = ("Bone : %s must be parent to Bone: %s" % (ng, ka))
else:
daft4 = ("Bone : %s must be parent to Bone: %s or %s or %s" % (ng, ka, al, al2))
kotak.label(text= daft4)
if jumlah_mispare > 4:
ng = list_parent_hilang[4]['ng']
ka = list_parent_hilang[4]['ka']
al = list_parent_hilang[4]['al']
al2 = list_parent_hilang[4]['al2']
if al2 == al:
daft5 = ("Bone : %s must be parent to Bone: %s or %s" % (ng, ka, al))
if al == ka:
daft5 = ("Bone : %s must be parent to Bone: %s" % (ng, ka))
else:
daft5 = ("Bone : %s must be parent to Bone: %s or %s or %s" % (ng, ka, al, al2))
kotak.label(text= daft5)
if jumlah_mispare > 5:
more_mispare = jumlah_mispare - 5
text_more_mispare = ("And more %i Bone" % (more_mispare))
kotak.label(text= text_more_mispare)
class cek_struktur_rig(bpy.types.Operator):
bl_idname = "obj.cek_rig"
bl_label = "Cek Rig"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
global list_tulang_hilang
global list_parent_hilang
dmta = bpy.context.scene.vrm_meta
rig = dmta.rig
tulang = rig.data.bones
list_tulang_hilang = []
list_parent_hilang = []
#Mencari tulang yang hilang
tulang_harus = [ #Required bone (https://github.com/vrm-c/vrm-specification/tree/master/specification/0.0#defined-bones)
"root", "hips", "upper_leg.L", "lower_leg.L", "foot.L",
"upper_leg.R", "lower_leg.R", "foot.R", "spine", "chest",
"upper_arm.L", "lower_arm.L", "hand.L", "upper_arm.R",
"lower_arm.R", "hand.R", "neck", "head", "RightEye", "LeftEye"
]
#"Bone", "Bone.003", "Bone.005", "pambalain", "hilang"]
tulang_ada = []
list_tulang_hilang = []
for bone in tulang:
pilih_tulang = [item for item in tulang_harus if item == bone.name]
tulang_ada.extend(pilih_tulang)
list_tulang_hilang = [item for item in tulang_harus if item not in tulang_ada]
if list_tulang_hilang == []:
dmta.find_bone = True
else:
dmta.find_bone = False
#print ("tulang", tulang)
#print ("")
#print ("tulang_harus", tulang_harus)
#print ("")
#print ("tulang_ada", tulang_ada)
#print ("")
#print ("list_tulang_hilang", list_tulang_hilang)
#mencari parent yang hilang (19 bone)
parent_harus = [
#Required bone
{'ng' : 'hips', 'ka' : 'root', 'al' : 'root', 'al2' : 'root'}, #"hips"
{'ng' : 'upper_leg.L', 'ka' : 'hips', 'al' : 'hips', 'al2' : 'hips'}, #"upper_leg.L"
{'ng' : 'lower_leg.L', 'ka' : 'upper_leg.L', 'al' : 'upper_leg.L', 'al2' : 'upper_leg.L'}, #"lower_leg.L"
{'ng' : 'foot.L', 'ka' : 'lower_leg.L', 'al' : 'lower_leg.L', 'al2' : 'lower_leg.L'}, #"foot.L"
{'ng' : 'upper_leg.R', 'ka' : 'hips', 'al' : 'hips', 'al2' : 'hips'}, #"upper_leg.R"
{'ng' : 'lower_leg.R', 'ka' : 'upper_leg.R', 'al' : 'upper_leg.R', 'al2' : 'upper_leg.R'}, #"lower_leg.R"
{'ng' : 'foot.R', 'ka' : 'lower_leg.R', 'al' : 'lower_leg.R', 'al2' : 'lower_leg.R'}, #"foot.R"
{'ng' : 'spine', 'ka' : 'hips', 'al' : 'hips', 'al2' : 'hips'}, #"spine"
{'ng' : 'chest', 'ka' : 'spine', 'al' : 'spine', 'al2' : 'spine'}, #"chest"
{'ng' : 'upper_arm.L', 'ka' : 'shoulder.L', 'al' : 'upperChest', 'al2' : 'chest'}, #"upper_arm.L"
{'ng' : 'lower_arm.L', 'ka' : 'upper_arm.L', 'al' : 'upper_arm.L', 'al2' : 'upper_arm.L'}, #"lower_arm.L"
{'ng' : 'hand.L', 'ka' : 'lower_arm.L', 'al' : 'lower_arm.L', 'al2' : 'lower_arm.L'}, #"hand.L"
{'ng' : 'upper_arm.R', 'ka' : 'shoulder.R', 'al' : 'upperChest', 'al2' : 'chest'}, #"upper_arm.R"
{'ng' : 'lower_arm.R', 'ka' : 'upper_arm.R', 'al' : 'upper_arm.R', 'al2' : 'upper_arm.R'}, #"lower_arm.R"
{'ng' : 'hand.R', 'ka' : 'lower_arm.R', 'al' : 'lower_arm.R', 'al2' : 'lower_arm.R'}, #"hand.R"
{'ng' : 'neck', 'ka' : 'chest', 'al' : 'upperChest', 'al2' : 'upperChest'}, #"neck"
{'ng' : 'head', 'ka' : 'neck', 'al' : 'neck', 'al2' : 'neck'}, #"head"
{'ng' : 'RightEye', 'ka' : 'head', 'al' : 'head', 'al2' : 'head'}, #"RightEye"
{'ng' : 'LeftEye', 'ka' : 'head', 'al' : 'head', 'al2' : 'head'}, #"LeftEye"
#Optional bone
{'ng' : 'shoulder.R', 'ka' : 'chest', 'al' : 'upperChest', 'al2' : 'upperChest'}, #shoulder.R
{'ng' : 'shoulder.L', 'ka' : 'chest', 'al' : 'upperChest', 'al2' : 'upperChest'}, #shoulder.L
{'ng' : 'upperChest', 'ka' : 'chest', 'al' : 'chest', 'al2' : 'chest'}, #upperChest
]
list_parent_hilang = [] #
if tulang_ada: #memeriksa daftar tulang yang ada
for item in parent_harus: #untuk setiap item di parent_harus lakukan
ng = item['ng']
ka = item['ka']
al = item['al']
al2 = item['al2']
for bone in tulang:
if bone.name == ng: #memilih tulang yang diperiksa
if bone.parent:
#if bone.parent.name.startswith(ka) or bone.parent.name.startswith(al) or bone.parent.name.startswith(al2): #memeriksa parent
if bone.parent.name == ka or bone.parent.name == al or bone.parent.name == al2:
continue
else: #jika parent salah
pilih_bone_salah_parent = [{'ng' : ng, 'ka' : ka, 'al' : al, 'al2' : al2}]
list_parent_hilang.extend(pilih_bone_salah_parent)
else:
pilih_bone_salah_parent = [{'ng' : ng, 'ka' : ka, 'al' : al, 'al2' : al2}]
list_parent_hilang.extend(pilih_bone_salah_parent)
if list_parent_hilang == []: #jika tidak ada bone yang salah parent
dmta.find_parent = True #parent lengkap
else:
dmta.find_parent = False #parent tidak lengkap
#print ("find_bone", dmta.find_bone)
#print ("find_parent", dmta.find_parent)
#print ("")
#print ("list_parent_hilang", list_parent_hilang)
#emplementasi info
# for item in list_parent_hilang:
# ngaran_tulang = item['ngaranya']
# ngaran_parent = item['kasananya']
# infonya = ["Bone :", ngaran_tulang, "must be parent to bone", ngaran_parent]
# print ("")
# print (item)
# print ("")
# print (infonya)
return {'FINISHED'}
class buat_mhv(bpy.types.Operator):
bl_idname = "obj.generate_mhv"
bl_label = "Generate Preexport"
bl_options = {'REGISTER', 'UNDO'}
def persiapkan(self, context, dmta, rig, model, semua_obj, anakan_rig, anakan_model, vl, list_obj_dis, list_obj_allow):
# print (" ")
# print ("mempersiapkan")
bpy.ops.view3d.snap_cursor_to_center()
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.origin_set(type='ORIGIN_CURSOR', center='MEDIAN')
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.transform_apply(location=False, rotation=True, scale=False)
bpy.ops.object.transform_apply(location=False, rotation=False, scale=True)
bpy.ops.object.select_all(action='DESELECT')
#Buat daftar object yang tanpa vertex grub
list_mesh = [obj for obj in list_obj_allow if obj.type == 'MESH']
#Buat bone extra
bvg_name = "bone_sbcierh_usrbtpb"
if bvg_name not in rig.data.bones:
rig.select_set(True)
bpy.context.view_layer.objects.active = rig
bpy.ops.object.mode_set(mode='EDIT')
bpy.context.scene.cursor.location[0] = 2.1
bpy.context.scene.cursor.location[1] = 2.8
bpy.context.scene.cursor.location[2] = 3
bpy.ops.armature.bone_primitive_add(name= bvg_name)
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
#buat vertex grub pada object di list_mesh
if not list_mesh == []:
for obj in list_mesh:
if len(obj.vertex_groups) == 0:
dapat = bpy.data.objects.get(obj.name)
dapat.vertex_groups.new(name= bvg_name)
bpy.ops.object.select_all(action='DESELECT')
obj.select_set(True)
bpy.context.view_layer.objects.active = dapat
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='DESELECT')
bpy.ops.mesh.select_all(action='SELECT')
bpy.context.object.vertex_groups.active_index = dapat.vertex_groups[bvg_name].index
bpy.context.scene.tool_settings.vertex_group_weight = 1
bpy.ops.object.vertex_group_assign()
bpy.ops.object.mode_set(mode='OBJECT')
bpy.ops.object.select_all(action='DESELECT')
else:
continue
return {'FINISHED'}
def execute(self, context):
dmta = bpy.context.scene.vrm_meta
rig = dmta.rig
model = dmta.model
semua_obj = bpy.context.scene.objects
anakan_rig = rig.children_recursive
anakan_model = model.children_recursive
vl = bpy.context.view_layer.objects
#memilah object yang tidak ikut
list1_1 = list(obj for obj in semua_obj)
list1_2 = list(obj for obj in vl)
list1_3 = [item for item in list1_1 if item not in list1_2]
list2_1 = [rig, model]
list2_2 = [item for item in list1_2 if item not in list2_1]
list2_3 = [item for item in list2_2 if item not in anakan_rig]
list2_4 = [item for item in list2_3 if item not in anakan_model]
list_obj_dis = list1_3 + list2_4
list_obj_allow = [item for item in list1_1 if item not in list_obj_dis]
# print ("list1_3",list1_3)
# print (" ")
# print ("list2_2",list2_2)
# print (" ")
# print ("anakan_rig",anakan_rig)
# print (" ")
# print ("list2_3",list2_3)
# print (" ")
# print ("list2_4",list2_4)
# print (" ")
# print ("list_obj_dis",list_obj_dis)
# print (" ")
# print ("list_obj_allow",list_obj_allow)
#mencek kelengkapan object
if list_obj_allow == []:
dmta.find_obj = False
else :
dmta.find_obj = True
if rig in list_obj_allow:
dmta.find_rig = True
if model in list_obj_allow:
dmta.find_model = True
else:
dmta.find_model = False
else:
dmta.find_rig = False
#mencek kelengkapan bone
bpy.ops.obj.cek_rig()
mod_gagal_aplay = []
for obj in list_obj_allow:
for mod in obj.modifiers:
if obj.data.shape_keys:
#for key in obj.data.shape_keys:
if not mod or not mod.show_viewport:
dmta.amwsk_gagal = False
if mod.type in ('ARMATURE', 'COLLISION'):
dmta.amwsk_gagal = False
else:
mod_gagal_aplay = [mod.type]
dmta.amwsk_gagal = True
#fungsi dijalankan apabila lengkap
if dmta.find_obj and dmta.find_rig and dmta.find_model and dmta.find_bone and dmta.find_parent:
bpy.ops.object.mode_set(mode='OBJECT')
for obj in semua_obj:
obj.hide_set(False)
obj.hide_select = False
bpy.ops.object.select_all(action='DESELECT')
if not list_obj_dis == []:
for obj in list_obj_dis:
obj.hide_viewport = True
model.select_set(True)
rig.select_set(True)
bpy.context.view_layer.objects.active = rig
for obj in list_obj_allow:
obj.select_set(True)
self.persiapkan(context, dmta, rig, model, semua_obj, anakan_rig, anakan_model, vl, list_obj_dis, list_obj_allow)
return {'FINISHED'}
class buat_bsk(bpy.types.Operator):
bl_idname = "obj.generate_bsk"
bl_label = "Generate Main Shape Keys"
bl_options = {'REGISTER', 'UNDO'}
joy : bpy.props.StringProperty(
name= "Joy",
default= "Joy"
)
angry : bpy.props.StringProperty(
name= "Angry",
default= "Angry"
)
sorrow : bpy.props.StringProperty(
name= "Sorrow",
default= "Sorrow"
)
fun : bpy.props.StringProperty(
name= "Fun",
default= "Fun"
)
blink : bpy.props.StringProperty(
name= "Blink All",
default= "Blink"
)
blink_l : bpy.props.StringProperty(
name= "Blink Left",
default= "Blink_L"
)
blink_r : bpy.props.StringProperty(
name= "Blink Right",
default= "Blink_R"
)
brows_up : bpy.props.StringProperty(
name= "Brows Up",
default= "Brows_Up"
)
brows_down : bpy.props.StringProperty(
name= "Brows Down",
default= "Brows_Down"
)
v_a : bpy.props.StringProperty(
name= "A",
default= "A"
)
v_i : bpy.props.StringProperty(
name= "I",
default= "I"
)
v_u : bpy.props.StringProperty(
name= "U",
default= "U"
)
v_e : bpy.props.StringProperty(
name= "E",
default= "E"
)
v_o : bpy.props.StringProperty(
name= "O",
default= "O"
)
lookup : bpy.props.StringProperty(
name= "Look Up",
default= "Look_Up"
)
lookdown : bpy.props.StringProperty(
name= "Look Down",
default= "Look_Down"
)
lookleft : bpy.props.StringProperty(
name= "Look Left",
default= "Look_Left"
)
lookright : bpy.props.StringProperty(
name= "Look Right",
default= "Look_Right"
)
def execute(self, context):
scene = context.scene
meta = bpy.context.scene.vrm_meta
model = scene.vrm_meta.model
model.shape_key_add(name="Basis")
model.shape_key_add(name=self.joy)
model.shape_key_add(name=self.angry)
model.shape_key_add(name=self.sorrow)
model.shape_key_add(name=self.fun)
model.shape_key_add(name=self.blink)
model.shape_key_add(name=self.blink_l)
model.shape_key_add(name=self.blink_r)
model.shape_key_add(name=self.brows_up)
model.shape_key_add(name=self.brows_down)
model.shape_key_add(name=self.lookup)
model.shape_key_add(name=self.lookdown)
model.shape_key_add(name=self.lookleft)
model.shape_key_add(name=self.lookright)
model.shape_key_add(name=self.v_a)
model.shape_key_add(name=self.v_i)
model.shape_key_add(name=self.v_u)
model.shape_key_add(name=self.v_e)
model.shape_key_add(name=self.v_o)
meta.joy = self.joy
meta.angry = self.angry
meta.sorrow = self.sorrow
meta.fun = self.fun
meta.blink = self.blink
meta.blink_l = self.blink_l
meta.blink_r = self.blink_r
meta.brows_up = self.brows_up
meta.brows_down = self.brows_down
meta.lookup = self.lookup
meta.lookdown = self.lookdown
meta.lookleft = self.lookleft
meta.lookright = self.lookright
meta.v_a = self.v_a
meta.v_i = self.v_i
meta.v_u = self.v_u
meta.v_e = self.v_e
meta.v_o = self.v_o
return {'FINISHED'}
def invoke(self, context, event):
return context.window_manager.invoke_props_dialog(self)
def draw(self, context):
scene = context.scene
meta = scene.vrm_meta
layout = self.layout
layout.use_property_split = True
layout.use_property_decorate = False
split = layout.split()
col = split.column()
col.label(text="Expresion:")
col.prop(self, "joy")
col.prop(self, "angry")
col.prop(self, "sorrow")
col.prop(self, "fun")
col.prop(self, "blink")
col.prop(self, "blink_l")
col.prop(self, "blink_r")
col.prop(self, "brows_up")
col.prop(self, "brows_down")
col = split.column(align=True)
col.label(text="Look At:")
col.prop(self, "lookup")
col.prop(self, "lookdown")
col.prop(self, "lookleft")
col.prop(self, "lookright")
row = layout.row()
col.label(text="Mouth Lip-sync:")
col.prop(self, "v_a")
col.prop(self, "v_i")
col.prop(self, "v_u")
col.prop(self, "v_e")
col.prop(self, "v_o")
row = layout.row()
box = layout.box()
kotak = box.column()
kotak.scale_y = 0.9
kotak.label(text="Tips:", icon='QUESTION')
kotak.label(text="Make sure to fill in all the Shape Keys names.", icon='BLANK1')
kotak.label(text="Don't have same name on different Shape Keys.", icon='BLANK1')
class buat_rig(bpy.types.Operator):
bl_idname = "obj.generate_rig"
bl_label = "Generate VRM Armature Tempate"
bl_options = {'REGISTER', 'UNDO'}
nama : bpy.props.StringProperty(name= "Object Name", default= "Armature")
terap: bpy.props.BoolProperty(name = "Set as Rig Main", default = False)
mark_required: bpy.props.BoolProperty(name = "Required Bone", default = False)
mark_optional: bpy.props.BoolProperty(name = "Optional Bone", default = False)
mark_required_normal : bpy.props.FloatVectorProperty(name= "Normal", default=(0.0, 1.0, 0.0), subtype='COLOR')
mark_required_select : bpy.props.FloatVectorProperty(name= "Select", default=(0.0, 0.0, 1.0), subtype='COLOR')
mark_required_active : bpy.props.FloatVectorProperty(name= "Active", default=(0.0, 1.0, 1.0), subtype='COLOR')
mark_optional_normal : bpy.props.FloatVectorProperty(name= "Normal", default=(1.0, 1.0, 0.0), subtype='COLOR')
mark_optional_select : bpy.props.FloatVectorProperty(name= "Select", default=(0.0, 0.0, 1.0), subtype='COLOR')
mark_optional_active : bpy.props.FloatVectorProperty(name= "Active", default=(0.0, 1.0, 1.0), subtype='COLOR')
#Required Bone
root: bpy.props.BoolProperty(name = "Root", default = True)
hips: bpy.props.BoolProperty(name = "Hips", default = True)
spine: bpy.props.BoolProperty(name = "Spine", default = True)
chest: bpy.props.BoolProperty(name = "Chest", default = True)
neck: bpy.props.BoolProperty(name = "Neck", default = True)
head: bpy.props.BoolProperty(name = "Head", default = True)
rightreye: bpy.props.BoolProperty(name = "Right", default = True)
lefteye: bpy.props.BoolProperty(name = "Left", default = True)
upper_arm_r: bpy.props.BoolProperty(name = "Upper", default = True)
lower_arm_r: bpy.props.BoolProperty(name = "Lower", default = True)
hand_r: bpy.props.BoolProperty(name = "Hand", default = True)
upper_arm_l: bpy.props.BoolProperty(name = "Upper", default = True)
lower_arm_l: bpy.props.BoolProperty(name = "Lower", default = True)
hand_l: bpy.props.BoolProperty(name = "Hand", default = True)
upper_leg_r: bpy.props.BoolProperty(name = "Upper", default = True)
lower_leg_r: bpy.props.BoolProperty(name = "Lower", default = True)
foot_r: bpy.props.BoolProperty(name = "Foot", default = True)
upper_leg_l: bpy.props.BoolProperty(name = "Upper", default = True)
lower_leg_l: bpy.props.BoolProperty(name = "Lower", default = True)
foot_l: bpy.props.BoolProperty(name = "Foot", default = True)
#Optional Bone
jaw: bpy.props.BoolProperty(name = "Jaw", default = False)
upperchest: bpy.props.BoolProperty(name = "Upper Chest", default = False)
rightshoulder: bpy.props.BoolProperty(name = "Right", default = True)
leftshoulder: bpy.props.BoolProperty(name = "Left", default = True)
righttoes: bpy.props.BoolProperty(name = "Righ", default = False)
lefttoes: bpy.props.BoolProperty(name = "Left", default = False)
thumb_r: bpy.props.BoolProperty(name = "Thumb", default = False)
index_r: bpy.props.BoolProperty(name = "Index", default = False)
middle_r: bpy.props.BoolProperty(name = "Middle", default = False)
ring_r: bpy.props.BoolProperty(name = "Ring", default = False)
little_r: bpy.props.BoolProperty(name = "Little", default = False)
thumb_l: bpy.props.BoolProperty(name = "Thumb", default = False)
index_l: bpy.props.BoolProperty(name = "Index", default = False)
middle_l: bpy.props.BoolProperty(name = "Middle", default = False)
ring_l: bpy.props.BoolProperty(name = "Ring", default = False)
little_l: bpy.props.BoolProperty(name = "Little", default = False)
def execute(self, context):
meta = bpy.context.scene.vrm_meta
#periksa apakah ada object
if bpy.context.active_object or bpy.context.selected_objects:
mode = bpy.context.active_object.mode
if not mode == 'OBJECT': #periksa mode object dan ubah menjadi `object mode`
bpy.ops.object.mode_set(mode='OBJECT')
#mulai generate
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.object.add(type='ARMATURE', enter_editmode=False, align='WORLD')
armature = bpy.context.active_object
armature.name = self.nama
if self.terap == True:
meta.rig = armature
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.armature.collection_add()
bpy.ops.armature.select_all(action='DESELECT')
armature_data = armature.data
armature_data.collections[0].name = "Required"
#generate bone Required
if self.root:
bpy.ops.armature.bone_primitive_add(name='root')
bone = armature_data.edit_bones.get('root')
bone.head.x = 0
bone.head.y = 0
bone.head.z = 0
bone.tail.x = 0
bone.tail.y = 0
bone.tail.z = 0.3
bone.roll = 0
if self.mark_required:
bone.color.palette = 'CUSTOM'
bone.color.custom.normal = self.mark_required_normal
bone.color.custom.select = self.mark_required_select
bone.color.custom.active = self.mark_required_active
if self.hips:
bpy.ops.armature.bone_primitive_add(name='hips')
bone = armature_data.edit_bones.get('hips')
bone.head.x = 0
bone.head.y = 0
bone.head.z = 0.735
bone.tail.x = 0
bone.tail.y = 0
bone.tail.z = 0.85
bone.roll = 0
if self.mark_required:
bone.color.palette = 'CUSTOM'
bone.color.custom.normal = self.mark_required_normal
bone.color.custom.select = self.mark_required_select
bone.color.custom.active = self.mark_required_active
if self.spine:
bpy.ops.armature.bone_primitive_add(name='spine')
bone = armature_data.edit_bones.get('spine')
bone.head.x = 0
bone.head.y = 0
bone.head.z = 0.85
bone.tail.x = 0
bone.tail.y = 0
bone.tail.z = 1.1
bone.roll = 0
if self.mark_required:
bone.color.palette = 'CUSTOM'
bone.color.custom.normal = self.mark_required_normal
bone.color.custom.select = self.mark_required_select
bone.color.custom.active = self.mark_required_active
if self.chest:
bpy.ops.armature.bone_primitive_add(name='chest')
bone = armature_data.edit_bones.get('chest')
bone.head.x = 0
bone.head.y = 0
bone.head.z = 1.1
bone.tail.x = 0
bone.tail.y = 0
if self.upperchest:
bone.tail.z = 1.3
else:
bone.tail.z = 1.5
bone.roll = 0
if self.mark_required:
bone.color.palette = 'CUSTOM'
bone.color.custom.normal = self.mark_required_normal
bone.color.custom.select = self.mark_required_select
bone.color.custom.active = self.mark_required_active
if self.neck:
bpy.ops.armature.bone_primitive_add(name='neck')
bone = armature_data.edit_bones.get('neck')
bone.head.x = 0
bone.head.y = 0
bone.head.z = 1.5
bone.tail.x = 0
bone.tail.y = 0
bone.tail.z = 1.65
bone.roll = 0
if self.mark_required:
bone.color.palette = 'CUSTOM'
bone.color.custom.normal = self.mark_required_normal
bone.color.custom.select = self.mark_required_select
bone.color.custom.active = self.mark_required_active
if self.head:
bpy.ops.armature.bone_primitive_add(name='head')
bone = armature_data.edit_bones.get('head')
bone.head.x = 0
bone.head.y = 0
bone.head.z = 1.65
bone.tail.x = 0
bone.tail.y = 0
bone.tail.z = 2
bone.roll = 0
if self.mark_required:
bone.color.palette = 'CUSTOM'
bone.color.custom.normal = self.mark_required_normal
bone.color.custom.select = self.mark_required_select
bone.color.custom.active = self.mark_required_active
if self.rightreye:
bpy.ops.armature.bone_primitive_add(name='RightEye')
bone = armature_data.edit_bones.get('RightEye')
bone.head.x = 0.1
bone.head.y = 0.15
bone.head.z = 1.837
bone.tail.x = 0.1
bone.tail.y = 0.2
bone.tail.z = 1.837
bone.roll = 0
if self.mark_required:
bone.color.palette = 'CUSTOM'
bone.color.custom.normal = self.mark_required_normal
bone.color.custom.select = self.mark_required_select
bone.color.custom.active = self.mark_required_active
if self.lefteye:
bpy.ops.armature.bone_primitive_add(name='LeftEye')
bone = armature_data.edit_bones.get('LeftEye')
bone.head.x = -0.1
bone.head.y = 0.15
bone.head.z = 1.837
bone.tail.x = -0.1
bone.tail.y = 0.2
bone.tail.z = 1.837
bone.roll = 0
if self.mark_required:
bone.color.palette = 'CUSTOM'
bone.color.custom.normal = self.mark_required_normal
bone.color.custom.select = self.mark_required_select
bone.color.custom.active = self.mark_required_active
if self.upper_arm_r:
bpy.ops.armature.bone_primitive_add(name='upper_arm.R')
bone = armature_data.edit_bones.get('upper_arm.R')
bone.head.x = 0.32
bone.head.y = 0
bone.head.z = 1.5
bone.tail.x = 0.6
bone.tail.y = 0
bone.tail.z = 1.5
bone.roll = 0
if self.mark_required:
bone.color.palette = 'CUSTOM'
bone.color.custom.normal = self.mark_required_normal
bone.color.custom.select = self.mark_required_select
bone.color.custom.active = self.mark_required_active
if self.lower_arm_r:
bpy.ops.armature.bone_primitive_add(name='lower_arm.R')
bone = armature_data.edit_bones.get('lower_arm.R')
bone.head.x = 0.6
bone.head.y = 0
bone.head.z = 1.5
bone.tail.x = 0.895
bone.tail.y = 0
bone.tail.z = 1.5
bone.roll = 0
if self.mark_required:
bone.color.palette = 'CUSTOM'
bone.color.custom.normal = self.mark_required_normal
bone.color.custom.select = self.mark_required_select
bone.color.custom.active = self.mark_required_active
if self.hand_r:
bpy.ops.armature.bone_primitive_add(name='hand.R')
bone = armature_data.edit_bones.get('hand.R')
bone.head.x = 0.895
bone.head.y = 0
bone.head.z = 1.5
bone.tail.x = 0.995
bone.tail.y = 0
bone.tail.z = 1.5
bone.roll = 0
if self.mark_required:
bone.color.palette = 'CUSTOM'
bone.color.custom.normal = self.mark_required_normal
bone.color.custom.select = self.mark_required_select
bone.color.custom.active = self.mark_required_active
if self.upper_arm_l:
bpy.ops.armature.bone_primitive_add(name='upper_arm.L')
bone = armature_data.edit_bones.get('upper_arm.L')
bone.head.x = -0.32
bone.head.y = 0
bone.head.z = 1.5
bone.tail.x = -0.6
bone.tail.y = 0
bone.tail.z = 1.5
bone.roll = 0
if self.mark_required:
bone.color.palette = 'CUSTOM'
bone.color.custom.normal = self.mark_required_normal
bone.color.custom.select = self.mark_required_select
bone.color.custom.active = self.mark_required_active
if self.lower_arm_l:
bpy.ops.armature.bone_primitive_add(name='lower_arm.L')
bone = armature_data.edit_bones.get('lower_arm.L')
bone.head.x = -0.6
bone.head.y = 0
bone.head.z = 1.5
bone.tail.x = -0.895
bone.tail.y = 0
bone.tail.z = 1.5
bone.roll = 0
if self.mark_required:
bone.color.palette = 'CUSTOM'
bone.color.custom.normal = self.mark_required_normal
bone.color.custom.select = self.mark_required_select
bone.color.custom.active = self.mark_required_active
if self.hand_l:
bpy.ops.armature.bone_primitive_add(name='hand.L')
bone = armature_data.edit_bones.get('hand.L')
bone.head.x = -0.895
bone.head.y = 0
bone.head.z = 1.5
bone.tail.x = -0.995
bone.tail.y = 0
bone.tail.z = 1.5
bone.roll = 0
if self.mark_required:
bone.color.palette = 'CUSTOM'
bone.color.custom.normal = self.mark_required_normal
bone.color.custom.select = self.mark_required_select
bone.color.custom.active = self.mark_required_active
if self.upper_leg_r:
bpy.ops.armature.bone_primitive_add(name='upper_leg.R')
bone = armature_data.edit_bones.get('upper_leg.R')
bone.head.x = 0.1235
bone.head.y = 0
bone.head.z = 0.735
bone.tail.x = 0.1235
bone.tail.y = 0
bone.tail.z = 0.4
bone.roll = 0
if self.mark_required:
bone.color.palette = 'CUSTOM'
bone.color.custom.normal = self.mark_required_normal
bone.color.custom.select = self.mark_required_select
bone.color.custom.active = self.mark_required_active
if self.lower_leg_r:
bpy.ops.armature.bone_primitive_add(name='lower_leg.R')
bone = armature_data.edit_bones.get('lower_leg.R')
bone.head.x = 0.1235
bone.head.y = 0
bone.head.z = 0.4
bone.tail.x = 0.1235
bone.tail.y = 0
bone.tail.z = 0.0625
bone.roll = 0
if self.mark_required:
bone.color.palette = 'CUSTOM'
bone.color.custom.normal = self.mark_required_normal
bone.color.custom.select = self.mark_required_select
bone.color.custom.active = self.mark_required_active
if self.foot_r:
bpy.ops.armature.bone_primitive_add(name='foot.R')
bone = armature_data.edit_bones.get('foot.R')
bone.head.x = 0.1235
bone.head.y = 0
bone.head.z = 0.0625
bone.tail.x = 0.1235
bone.tail.y = 0.144
bone.tail.z = 0
bone.roll = 0
if self.mark_required:
bone.color.palette = 'CUSTOM'