-
Notifications
You must be signed in to change notification settings - Fork 0
/
TekkenAnimHelper.py
1390 lines (1119 loc) · 46.2 KB
/
TekkenAnimHelper.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
import struct
import bpy
import numpy as np
from math import pi, asin, atan2
from copy import deepcopy
halfpi = pi / 2
def quaternionToRotationMatrix(Q):
# Extract the values from Q
q0 = Q[0]
q1 = Q[1]
q2 = Q[2]
q3 = Q[3]
# First row of the rotation matrix
r00 = 2 * (q0 * q0 + q1 * q1) - 1
r01 = 2 * (q1 * q2 - q0 * q3)
r02 = 2 * (q1 * q3 + q0 * q2)
# Second row of the rotation matrix
r10 = 2 * (q1 * q2 + q0 * q3)
r11 = 2 * (q0 * q0 + q2 * q2) - 1
r12 = 2 * (q2 * q3 - q0 * q1)
# Third row of the rotation matrix
r20 = 2 * (q1 * q3 - q0 * q2)
r21 = 2 * (q2 * q3 + q0 * q1)
r22 = 2 * (q0 * q0 + q3 * q3) - 1
# 3x3 rotation matrix
rot_matrix = np.array([[r00, r01, r02],
[r10, r11, r12],
[r20, r21, r22]])
return rot_matrix
def get_quaternion_from_euler(roll, pitch, yaw):
qx = np.sin(roll/2) * np.cos(pitch/2) * np.cos(yaw/2) - np.cos(roll/2) * np.sin(pitch/2) * np.sin(yaw/2)
qy = np.cos(roll/2) * np.sin(pitch/2) * np.cos(yaw/2) + np.sin(roll/2) * np.cos(pitch/2) * np.sin(yaw/2)
qz = np.cos(roll/2) * np.cos(pitch/2) * np.sin(yaw/2) - np.sin(roll/2) * np.sin(pitch/2) * np.cos(yaw/2)
qw = np.cos(roll/2) * np.cos(pitch/2) * np.cos(yaw/2) + np.sin(roll/2) * np.sin(pitch/2) * np.sin(yaw/2)
return [qx, qy, qz, qw]
def clamp(num, min_value, max_value):
return max(min(num, max_value), min_value)
def getRotationFromMatrix(te, mode = 0):
m11 = te[ 0 ][0]
m12 = te[ 0 ][1]
m13 = te[ 0 ][2]
m21 = te[ 1 ][0]
m22 = te[ 1 ][1]
m23 = te[ 1 ][2]
m31 = te[ 2 ][0]
m32 = te[ 2 ][1]
m33 = te[ 2 ][2]
if mode == 0: #XYZ
y = asin( clamp( m13, - 1, 1 ) )
if abs( m13 ) < 0.9999999:
x = atan2( - m23, m33 )
z = atan2( - m12, m11 )
else:
x = atan2( m32, m22 )
z = 0
elif mode == 1: #YXZ
x = asin( - clamp( m23, - 1, 1 ) )
if abs( m23 ) < 0.9999999:
y = atan2( m13, m33 )
z = atan2( m21, m22 )
else:
y = atan2( - m31, m11 )
z = 0
elif mode == 2: #ZXY
x = asin( clamp( m32, - 1, 1 ) )
if abs( m32 ) < 0.9999999:
y = atan2( - m31, m33 )
z = atan2( - m12, m22 )
else:
y = 0
z = atan2( m21, m11 )
elif mode == 3: #ZYX
y = asin( - clamp( m31, - 1, 1 ) )
if abs( m31 ) < 0.9999999:
x = atan2( m32, m33 )
z = atan2( m21, m11 )
else:
x = 0
z = atan2( - m12, m22 )
elif mode == 4: #YZX
z = asin( clamp( m21, - 1, 1 ) )
if abs( m21 ) < 0.9999999:
x = atan2( - m23, m22 )
y = atan2( - m31, m11 )
else:
x = 0
y = atan2( m13, m33 )
elif mode == 5: #XZY
z = asin( - clamp( m12, - 1, 1 ) )
if abs( m12 ) < 0.9999999:
x = atan2( m32, m22 )
y = atan2( m13, m11 )
else:
x = atan2( - m23, m33 )
y = 0
return x, y, z
# --------
class TekkenAnimation:
def _getHeaderSizeFromArgs_(bone_count):
return bone_count * 0x4 + 0x8
def _getFramesizeFromArgs_(bone_count):
return bone_count * 0xC
def __init__(self, data=None, type="body"):
if data == None:
self.data = TekkenAnimation.createAnim(type)
else:
self.data = data
self.type = self.byte(0)
self.bone_count = self.byte(2)
self.length = self.getLength()
self.offset = self.getOffset()
self.frame_size = self.getFramesize()
self.field_count = int(self.frame_size / 4)
self.recalculateSize() #Crop or add missing bytes if needed
def createAnim(type="body"):
if type not in ["body", "hand", "face"]:
raise KeyError(type + " is not an acceptable animation type. Try 'body', 'hand' or 'face'.")
data = []
bone_count = {
"body": 0x17,
"hand": 0x13,
"face": 0x5A,
}.get(type)
data += [0xC8, 0] #anim type
data += [bone_count, 0]
data += [0x1, 0, 0, 0] #anim length: 1 frame
if type == "body":
for i in range(bone_count):
boneInfo = 0x07
if i in [0, 1, 6]:
boneInfo = 0x0B
elif i == 2:
boneInfo = 0x05
elif i in [11, 15, 18, 21]:
boneInfo = 0x06
data += [boneInfo, 0, 0, 0]
elif type == "hand":
for i in range(bone_count):
data += [0x07, 0, 0, 0]
elif type == "face":
for i in range(bone_count):
boneInfo = 0xB
if 0x57 <= i <= 0x5A:
boneInfo = 0x3
elif i & 1 == 1:
boneInfo = 0x7
data += [boneInfo, 0, 0, 0]
return data
def recalculateSize(self):
pastSize = len(self.data)
self.size = self.calculateSize()
if self.size > pastSize:
self.data += [0] * (self.size - pastSize)
elif self.size < pastSize:
self.data = self.data[:self.size]
def calculateSize(self):
return self.getOffset() + (self.getFramesize() * self.length)
def getOffset(self):
return self.bone_count * 0x4 + 0x8
def getFramesize(self):
return self.bone_count * 0xC #= * 3 fields * 4 bytes each
def setLength(self, length):
self.length = length
self.writeInt(length, 4)
def getLength(self):
return self.int(4)
def bToInt(self, offset, length):
return int.from_bytes(bytes(self.data[offset:offset+length]), 'little')
def int(self, offset):
return self.bToInt(offset, 4)
def short(self, offset):
return self.bToInt(offset, 2)
def byte(self, offset):
return self.bToInt(offset, 1)
def float(self, offset):
return struct.unpack('f', bytes(self.data[offset:offset + 4]))[0]
def writeInt(self, value, offset):
for i in range(4):
byteValue = (value >> (i * 8)) & 0xFF
self.data[offset + i] = byteValue
def writeFloat(self, value, offset):
byteData = struct.pack('f', value)
for i in range(4):
self.data[offset + i] = int(byteData[i])
def getFieldOffset(self, frame, fieldId):
if fieldId > self.field_count:
raise
return self.offset + (frame * self.frame_size) + (4 * fieldId)
def getField(self, frame, fieldId):
if fieldId > self.field_count:
raise
return self.float(self.getFieldOffset(frame, fieldId))
def setField(self, value, frame, fieldId):
if fieldId > self.field_count:
raise
self.writeFloat(value, self.offset + (frame * self.frame_size) + (4 * fieldId))
def __get_visual_rotations__(armature, bones):
poses = {}
for prefix in ["L_", "R_"]: # set default values
for bone in ["UpLeg", "Leg", "Foot", "Hand", "ForeArm", "Arm", "Shoulder"]:
b = prefix + bone
#rot_source = bones[b].rotation_euler
rot_source = getEulerVisualRotation(b, armature.name)
poses[b] = { 'x': rot_source.x, 'y': rot_source.y, 'z': rot_source.z}
#to be used if you have IK for those bones too
"""
for b in ["BASE", "Hip", "Head", "Neck", "Spine1"]:
#rot_source = bones[b].rotation_euler
rot_source = getEulerVisualRotation(b, armature.name)
poses[b] = { 'x': rot_source.x, 'y': rot_source.y, 'z': rot_source.z}
"""
return poses
def getEulerVisualRotation(boneName, armatureName):
bone = bpy.data.armatures[armatureName].bones[boneName]
bone_ml = bone.matrix_local
bone_pose = bpy.data.objects[armatureName].pose.bones[boneName]
bone_pose_m = bone_pose.matrix
if bone.parent:
#
parent = bone.parent
parent_ml = parent.matrix_local
parent_pose = bone_pose.parent
parent_pose_m = parent_pose.matrix
object_diff = parent_ml.inverted() @ bone_ml
pose_diff = parent_pose_m.inverted() @ bone_pose_m
local_diff = object_diff.inverted() @ pose_diff
else:
local_diff = bone_ml.inverted() @ bone_pose_m
return local_diff.to_quaternion().to_euler(bone_pose.rotation_mode)
# expects x y z blender rotation, outputs tekken rotation
def convertArmToTekkenXYZ(x, y, z):
x, y, z = -x, -z, y
orig_quat = get_quaternion_from_euler(halfpi, 0, halfpi)
orig_mat = quaternionToRotationMatrix(orig_quat)
orig_mat = np.linalg.inv(orig_mat)
quat = get_quaternion_from_euler(x, y, z)
mat = quaternionToRotationMatrix(quat)
mat = np.matmul(mat, orig_mat)
x, y, z = getRotationFromMatrix(mat, mode=3)
return x, -y, -z
# expects x y z tekken rotation, outputs blender rotation
def convertArmToBlenderXYZ(x, y, z):
orig_quat = get_quaternion_from_euler(-halfpi, halfpi, 0)
orig_mat = quaternionToRotationMatrix(orig_quat)
orig_mat = np.linalg.inv(orig_mat)
quat = get_quaternion_from_euler(x, y, z)
mat = quaternionToRotationMatrix(quat)
mat = np.matmul(mat, orig_mat)
x, y, z = getRotationFromMatrix(mat, mode=1)
return -z, y, -x
# expects x y z Blender rotation, outputs unreal rotation
def convertCameraToUnrealRot(x, y, z):
x, y, z = -x, -z, y
orig_quat = get_quaternion_from_euler(-halfpi, 0, -halfpi)
orig_mat = quaternionToRotationMatrix(orig_quat)
orig_mat = np.linalg.inv(orig_mat)
quat = get_quaternion_from_euler(x, y, z)
mat = quaternionToRotationMatrix(quat)
mat = np.matmul(mat, orig_mat)
x, y, z = getRotationFromMatrix(mat, mode=1)
return x, y, z
# expects x y z Unreal rotation, outputs blender rotation
def convertCameraToBlenderRot(x, y, z):
x, y, z = y, x, z
orig_quat = get_quaternion_from_euler(1.57, 0, 1.57)
orig_mat = quaternionToRotationMatrix(orig_quat)
quat = get_quaternion_from_euler(x, y, z)
mat = quaternionToRotationMatrix(quat)
mat = np.matmul(mat, orig_mat)
x, y, z = getRotationFromMatrix(mat, mode=5)
return -x + pi, -z, y
def getAnimFrameFromBones(armature, keepEndPos=False):
bones = armature.pose.bones
visualRots = __get_visual_rotations__(armature, bones)
position = [
-(bones["BODY_SCALE__group"].location.z * 1000), #x
#(bones["BODY_SCALE__group"].location.y) * 1000, y
bones["BODY_SCALE__group"].location.x * 1000 #z
]
offset1 = 0
offset2 = 1150 + (bones["BODY_SCALE__group"].location.y) * 1000
offset3 = 0
movement1 = 0
#movement2 = 0
movement3 = 0
if keepEndPos == 0:
offset1, offset3 = position
else:
movement1, movement3 = position
RotX = bones["BASE"].rotation_euler.z * -1
RotY = bones["BASE"].rotation_euler.y
RotZ = bones["BASE"].rotation_euler.x
UpperBody1 = bones["Spine1"].rotation_euler.z * -1
UpperBody2 = bones["Spine1"].rotation_euler.y
UpperBody3 = bones["Spine1"].rotation_euler.x + (halfpi)
LowerBody1 = bones["Hip"].rotation_euler.z * -1
LowerBody2 = bones["Hip"].rotation_euler.y
LowerBody3 = bones["Hip"].rotation_euler.x - (halfpi)
Neck1 = bones["Neck"].rotation_euler.z * -1
Neck2 = bones["Neck"].rotation_euler.y
Neck3 = bones["Neck"].rotation_euler.x
Head1 = bones["Head"].rotation_euler.z + (halfpi)
Head2 = bones["Head"].rotation_euler.x
Head3 = bones["Head"].rotation_euler.y + (halfpi)
#to be used if you have IK for those bones too
"""
RotX = visualRots["BASE"]['z'] * -1
RotY = visualRots["BASE"]['y']
RotZ = visualRots["BASE"]['x']
UpperBody1 = visualRots["Spine1"]['z'] * -1
UpperBody2 = visualRots["Spine1"]['y']
UpperBody3 = visualRots["Spine1"]['x'] + (halfpi)
LowerBody1 = visualRots["Hip"]['z'] * -1
LowerBody2 = visualRots["Hip"]['y']
LowerBody3 = visualRots["Hip"]['x'] - (halfpi)
Neck1 = visualRots["Neck"]['z'] * -1
Neck2 = visualRots["Neck"]['y']
Neck3 = visualRots["Neck"]['x']
Head1 = visualRots["Head"]['z'] + (halfpi)
Head2 = visualRots["Head"]['x']
Head3 = visualRots["Head"]['y'] + (halfpi)
"""
# --------- SHOULDER ------------
#x, y, z = bones["R_Shoulder"].rotation_euler
x, y, z = visualRots["R_Shoulder"]['x'], visualRots["R_Shoulder"]['y'], visualRots["R_Shoulder"]['z']
x, y, z = convertArmToTekkenXYZ(x, y, z)
RightInnerShoulder1 = x + pi
RightInnerShoulder2 = y
RightInnerShoulder3 = z
# --------- ARM IK -----------
RightOuterShoulder1 = visualRots["R_Arm"]['x'] * -1 - halfpi
RightOuterShoulder2 = visualRots["R_Arm"]['z'] * -1
RightOuterShoulder3 = visualRots["R_Arm"]['y'] * -1
RightElbow1 = visualRots["R_ForeArm"]['x'] * -1
RightElbow2 = visualRots["R_ForeArm"]['y']
RightElbow3 = visualRots["R_ForeArm"]['z'] * -1
RightHand1 = visualRots["R_Hand"]['x'] + halfpi
RightHand2 = visualRots["R_Hand"]['z'] * -1
RightHand3 = visualRots["R_Hand"]['y']
# --------- SHOULDER ------------
# x, y, z = bones["L_Shoulder"].rotation_euler
x, y, z = visualRots["L_Shoulder"]['x'], visualRots["L_Shoulder"]['y'], visualRots["L_Shoulder"]['z']
x, y, z = convertArmToTekkenXYZ(x, y, z)
LeftInnerShoulder1 = x + pi
LeftInnerShoulder2 = y + pi
LeftInnerShoulder3 = z * -1
# --------- ARM IK -----------
LeftOuterShoulder1 = visualRots["L_Arm"]['x'] - halfpi
LeftOuterShoulder2 = visualRots["L_Arm"]['z']
LeftOuterShoulder3 = visualRots["L_Arm"]['y'] * -1
LeftElbow1 = visualRots["L_ForeArm"]['x']
LeftElbow2 = visualRots["L_ForeArm"]['y']
LeftElbow3 = visualRots["L_ForeArm"]['z']
LeftHand1 = visualRots["L_Hand"]['x'] * -1 + halfpi
LeftHand2 = visualRots["L_Hand"]['z'] * -1
LeftHand3 = visualRots["L_Hand"]['y'] * -1
#---------------- LEG IK -----------------
RightHip1 = visualRots["R_UpLeg"]['z'] * -1
RightHip2 = visualRots["R_UpLeg"]['y']
RightHip3 = visualRots["R_UpLeg"]['x']
RightKnee1 = visualRots["R_Leg"]['z'] * -1
RightKnee2 = visualRots["R_Leg"]['y']
RightKnee3 = visualRots["R_Leg"]['x']
RightFoot1 = visualRots["R_Foot"]['z'] * -1
RightFoot2 = visualRots["R_Foot"]['y']
RightFoot3 = visualRots["R_Foot"]['x']
LeftHip1 = visualRots["L_UpLeg"]['z'] * -1
LeftHip2 = visualRots["L_UpLeg"]['y']
LeftHip3 = visualRots["L_UpLeg"]['x']
LeftKnee1 = visualRots["L_Leg"]['z'] * -1
LeftKnee2 = visualRots["L_Leg"]['y']
LeftKnee3 = visualRots["L_Leg"]['x']
LeftFoot1 = visualRots["L_Foot"]['z'] * -1
LeftFoot2 = visualRots["L_Foot"]['y']
LeftFoot3 = visualRots["L_Foot"]['x']
# ------ end --------
return [
movement1, #Offset = movement x
0, #movement2, #Offset = height
movement3, #Offset = movement z
offset1, #JumpStrength = pos x
offset2, #JumpStrength = pos y
offset3, #JumpStrength = pos Z
0, #Unknown = field 7
0, #Unknown = field 8
0, #Unknown = field 9
RotX, #Mesh = rotx
RotY, #Mesh = roty
RotZ, #Mesh = rotz
UpperBody1, # = spine1 x
UpperBody2, # = spine1 x
UpperBody3, # = spine1 z
LowerBody1, # = hip x
LowerBody2, # = hip y
LowerBody3, # = hip z
0, #SpineFlexure # = spine 2
0, #SpineFlexure # = field 20
0, #SpineFlexure # = field 21
Neck1, # = neck 22
Neck2, # = neck 23
Neck3, # = neck 24
Head1, # = neck 25
Head2, # = neck 26
Head3, # = neck 27
RightInnerShoulder1, #RightInnerShoulder
RightInnerShoulder2, #RightInnerShoulder
RightInnerShoulder3, #RightInnerShoulder
RightOuterShoulder1, #RightOuterShoulder
RightOuterShoulder2, #RightOuterShoulder
RightOuterShoulder3, #RightOuterShoulder
RightElbow1, #RightElbow
RightElbow2, #RightElbow
RightElbow3, #RightElbow
RightHand1, #RightHand
RightHand2, #RightHand
RightHand3, #RightHand
LeftInnerShoulder1, #LeftInnerShoulder
LeftInnerShoulder2, #LeftInnerShoulder
LeftInnerShoulder3, #LeftInnerShoulder
LeftOuterShoulder1, #LeftOuterShoulder
LeftOuterShoulder2, #LeftOuterShoulder
LeftOuterShoulder3, #LeftOuterShoulder
LeftElbow1, #LeftElbow
LeftElbow2, #LeftElbow
LeftElbow3, #LeftElbow
LeftHand1, #LeftHand
LeftHand2, #LeftHand
LeftHand3, #LeftHand
RightHip1, #RightHip
RightHip2, #RightHip
RightHip3, #RightHip
RightKnee1, #RightKnee
RightKnee2, #RightKnee
RightKnee3, #RightKnee
RightFoot1, #RightFoot
RightFoot2, #RightFoot
RightFoot3, #RightFoot
LeftHip1, #LeftHip
LeftHip2, #LeftHip
LeftHip3, #LeftHip
LeftKnee1, #LeftKnee
LeftKnee2, #LeftKnee
LeftKnee3, #LeftKnee
LeftFoot1, #LeftFoot
LeftFoot2, #LeftFoot
LeftFoot3, #LeftFoot
]
def getHandAnimFrameFromBones(armature):
return getLeftHandAnimFrameFromBones(armature), getRightHandAnimFrameFromBones(armature)
def getLeftHandAnimFrameFromBones(armature):
bones = armature.pose.bones
FingerBase_x = bones["L_FingerBase"].rotation_euler.x * -1
FingerBase_y = bones["L_FingerBase"].rotation_euler.y
FingerBase_z = bones["L_FingerBase"].rotation_euler.z * -1
Thumb1_x = bones["L_Thumb1"].rotation_euler.x * -1
Thumb1_y = bones["L_Thumb1"].rotation_euler.z * -1
Thumb1_z = bones["L_Thumb1"].rotation_euler.y * -1
Thumb2_x = bones["L_Thumb2"].rotation_euler.x * -1
Thumb2_y = bones["L_Thumb2"].rotation_euler.z * -1
Thumb2_z = bones["L_Thumb2"].rotation_euler.y * -1
Thumb3_x = bones["L_Thumb3"].rotation_euler.x * -1
Thumb3_y = bones["L_Thumb3"].rotation_euler.z * -1
Thumb3_z = bones["L_Thumb3"].rotation_euler.y * -1
Index1_x = bones["L_Index1"].rotation_euler.x * -1
Index1_y = bones["L_Index1"].rotation_euler.y
Index1_z = bones["L_Index1"].rotation_euler.z * -1
Index2_x = bones["L_Index2"].rotation_euler.x * -1
Index2_y = bones["L_Index2"].rotation_euler.y
Index2_z = bones["L_Index2"].rotation_euler.z * -1
Index3_x = bones["L_Index3"].rotation_euler.x * -1
Index3_y = bones["L_Index3"].rotation_euler.y
Index3_z = bones["L_Index3"].rotation_euler.z * -1
Middle_x = bones["L_Middle"].rotation_euler.x * -1
Middle_y = bones["L_Middle"].rotation_euler.y
Middle_z = bones["L_Middle"].rotation_euler.z * -1
Middle1_x = bones["L_Middle1"].rotation_euler.x * -1
Middle1_y = bones["L_Middle1"].rotation_euler.y
Middle1_z = bones["L_Middle1"].rotation_euler.z * -1
Middle2_x = bones["L_Middle2"].rotation_euler.x * -1
Middle2_y = bones["L_Middle2"].rotation_euler.y
Middle2_z = bones["L_Middle2"].rotation_euler.z * -1
Middle3_x = bones["L_Middle3"].rotation_euler.x * -1
Middle3_y = bones["L_Middle3"].rotation_euler.y
Middle3_z = bones["L_Middle3"].rotation_euler.z * -1
Ring_x = bones["L_Ring"].rotation_euler.x * -1
Ring_y = bones["L_Ring"].rotation_euler.y
Ring_z = bones["L_Ring"].rotation_euler.z * -1
Ring1_x = bones["L_Ring1"].rotation_euler.x * -1
Ring1_y = bones["L_Ring1"].rotation_euler.y
Ring1_z = bones["L_Ring1"].rotation_euler.z * -1
Ring2_x = bones["L_Ring2"].rotation_euler.x * -1
Ring2_y = bones["L_Ring2"].rotation_euler.y
Ring2_z = bones["L_Ring2"].rotation_euler.z * -1
Ring3_x = bones["L_Ring3"].rotation_euler.x * -1
Ring3_y = bones["L_Ring3"].rotation_euler.y
Ring3_z = bones["L_Ring3"].rotation_euler.z * -1
Pinky_x = bones["L_Pinky"].rotation_euler.x * -1
Pinky_y = bones["L_Pinky"].rotation_euler.y
Pinky_z = bones["L_Pinky"].rotation_euler.z * -1
Pinky1_x = bones["L_Pinky1"].rotation_euler.x * -1
Pinky1_y = bones["L_Pinky1"].rotation_euler.y
Pinky1_z = bones["L_Pinky1"].rotation_euler.z * -1
Pinky2_x = bones["L_Pinky2"].rotation_euler.x * -1
Pinky2_y = bones["L_Pinky2"].rotation_euler.y
Pinky2_z = bones["L_Pinky2"].rotation_euler.z * -1
Pinky3_x = bones["L_Pinky3"].rotation_euler.x * -1
Pinky3_y = bones["L_Pinky3"].rotation_euler.y
Pinky3_z = bones["L_Pinky3"].rotation_euler.z * -1
return [
FingerBase_x, #L_FingerBase
FingerBase_y,
FingerBase_z,
Thumb1_x, #L_Thumb1
Thumb1_y,
Thumb1_z,
Thumb2_x, #L_Thumb2
Thumb2_y,
Thumb2_z,
Thumb3_x, #L_Thumb3
Thumb3_y,
Thumb3_z,
Index1_x, #L_Index1
Index1_y,
Index1_z,
Index2_x, #L_Index2
Index2_y,
Index2_z,
Index3_x, #L_Index3
Index3_y,
Index3_z,
Middle_x, #Middle
Middle_y,
Middle_z,
Middle1_x, #Middle1
Middle1_y,
Middle1_z,
Middle2_x, #Middle2
Middle2_y,
Middle2_z,
Middle3_x, #Middle3
Middle3_y,
Middle3_z,
Ring_x, #Ring
Ring_y,
Ring_z,
Ring1_x, #Ring1
Ring1_y,
Ring1_z,
Ring2_x, #Ring2
Ring2_y,
Ring2_z,
Ring3_x, #Ring3
Ring3_y,
Ring3_z,
Pinky_x, #Pinky
Pinky_y,
Pinky_z,
Pinky1_x, #Pinky1
Pinky1_y,
Pinky1_z,
Pinky2_x, #Pinky2
Pinky2_y,
Pinky2_z,
Pinky3_x, #Pinky3
Pinky3_y,
Pinky3_z
]
def getRightHandAnimFrameFromBones(armature):
bones = armature.pose.bones
FingerBase_x = bones["R_FingerBase"].rotation_euler.x
FingerBase_y = bones["R_FingerBase"].rotation_euler.y
FingerBase_z = bones["R_FingerBase"].rotation_euler.z
Thumb1_x = bones["R_Thumb1"].rotation_euler.x
Thumb1_y = bones["R_Thumb1"].rotation_euler.z
Thumb1_z = bones["R_Thumb1"].rotation_euler.y * -1
Thumb2_x = bones["R_Thumb2"].rotation_euler.x
Thumb2_y = bones["R_Thumb2"].rotation_euler.z
Thumb2_z = bones["R_Thumb2"].rotation_euler.y * -1
Thumb3_x = bones["R_Thumb3"].rotation_euler.x
Thumb3_y = bones["R_Thumb3"].rotation_euler.z
Thumb3_z = bones["R_Thumb3"].rotation_euler.y * -1
Index1_x = bones["R_Index1"].rotation_euler.x
Index1_y = bones["R_Index1"].rotation_euler.y
Index1_z = bones["R_Index1"].rotation_euler.z
Index2_x = bones["R_Index2"].rotation_euler.x
Index2_y = bones["R_Index2"].rotation_euler.y
Index2_z = bones["R_Index2"].rotation_euler.z
Index3_x = bones["R_Index3"].rotation_euler.x
Index3_y = bones["R_Index3"].rotation_euler.y
Index3_z = bones["R_Index3"].rotation_euler.z * -1
Middle_x = bones["R_Middle"].rotation_euler.x
Middle_y = bones["R_Middle"].rotation_euler.y
Middle_z = bones["R_Middle"].rotation_euler.z
Middle1_x = bones["R_Middle1"].rotation_euler.x * -1
Middle1_y = bones["R_Middle1"].rotation_euler.y
Middle1_z = bones["R_Middle1"].rotation_euler.z * -1
Middle2_x = bones["R_Middle2"].rotation_euler.x
Middle2_y = bones["R_Middle2"].rotation_euler.y
Middle2_z = bones["R_Middle2"].rotation_euler.z
Middle3_x = bones["R_Middle3"].rotation_euler.x * -1
Middle3_y = bones["R_Middle3"].rotation_euler.y
Middle3_z = bones["R_Middle3"].rotation_euler.z * -1
Ring_x = bones["R_Ring"].rotation_euler.x
Ring_y = bones["R_Ring"].rotation_euler.y
Ring_z = bones["R_Ring"].rotation_euler.z
Ring1_x = bones["R_Ring1"].rotation_euler.x
Ring1_y = bones["R_Ring1"].rotation_euler.y
Ring1_z = bones["R_Ring1"].rotation_euler.z
Ring2_x = bones["R_Ring2"].rotation_euler.x
Ring2_y = bones["R_Ring2"].rotation_euler.y
Ring2_z = bones["R_Ring2"].rotation_euler.z
Ring3_x = bones["R_Ring3"].rotation_euler.x
Ring3_y = bones["R_Ring3"].rotation_euler.y
Ring3_z = bones["R_Ring3"].rotation_euler.z
Pinky_x = bones["R_Pinky"].rotation_euler.x
Pinky_y = bones["R_Pinky"].rotation_euler.y
Pinky_z = bones["R_Pinky"].rotation_euler.z
Pinky1_x = bones["R_Pinky1"].rotation_euler.x
Pinky1_y = bones["R_Pinky1"].rotation_euler.y
Pinky1_z = bones["R_Pinky1"].rotation_euler.z
Pinky2_x = bones["R_Pinky2"].rotation_euler.x
Pinky2_y = bones["R_Pinky2"].rotation_euler.y
Pinky2_z = bones["R_Pinky2"].rotation_euler.z
Pinky3_x = bones["R_Pinky3"].rotation_euler.x
Pinky3_y = bones["R_Pinky3"].rotation_euler.y
Pinky3_z = bones["R_Pinky3"].rotation_euler.z
return [
FingerBase_x, #R_FingerBase
FingerBase_y,
FingerBase_z,
Thumb1_x, #Thumb1
Thumb1_y,
Thumb1_z,
Thumb2_x, #Thumb2
Thumb2_y,
Thumb2_z,
Thumb3_x, #Thumb3
Thumb3_y,
Thumb3_z,
Index1_x, #Index1
Index1_y,
Index1_z,
Index2_x, #Index2
Index2_y,
Index2_z,
Index3_x, #Index3
Index3_y,
Index3_z,
Middle_x, #Middle
Middle_y,
Middle_z,
Middle1_x, #Middle1
Middle1_y,
Middle1_z,
Middle2_x, #Middle2
Middle2_y,
Middle2_z,
Middle3_x, #Middle3
Middle3_y,
Middle3_z,
Ring_x, #Ring
Ring_y,
Ring_z,
Ring1_x, #Ring1
Ring1_y,
Ring1_z,
Ring2_x, #Ring2
Ring2_y,
Ring2_z,
Ring3_x, #Ring3
Ring3_y,
Ring3_z,
Pinky_x, #Pinky
Pinky_y,
Pinky_z,
Pinky1_x, #Pinky1
Pinky1_y,
Pinky1_z,
Pinky2_x, #Pinky2
Pinky2_y,
Pinky2_z,
Pinky3_x, #Pinky3
Pinky3_y,
Pinky3_z
]
face_bonesTransformTypes = {
#zxy
"Bero1_Joint": 1, #-zyx
"Bero1_Joint_pos": 1,
"Bero2_Joint": 1,
"Bero3_Joint": 1,
"M_LipD_Joint": -1, #xyz
"L_LipD_Joint": -1,
"R_LipD_Joint": -1,
"L_LipE_Joint": -1,
"R_LipE_Joint": -1,
}
face_bonesRotationTypes = {
"Jaw_Joint": 1
}
def getBonePos(boneName, location, defaultBonePos):
x, y, z = location
type = face_bonesTransformTypes.get(boneName, 0)
if type == 0:
x, y, z = z, x, y
elif type == 1:
x, y, z = -z, y, x
x = x * 1000 + defaultBonePos['x']
y = y * 1000 + defaultBonePos['y']
z = z * 1000 + defaultBonePos['z']
return (x, y, z)
def getBoneRot(boneName, rotation, defaultBonePos):
x, y, z = rotation
type = face_bonesRotationTypes.get(boneName, 0)
if type == 1:
x, y, z = x, z * -1, y
return (x + defaultBonePos['rot_x'],
y + defaultBonePos['rot_y'],
z + defaultBonePos['rot_z'])
def getFaceAnimFrameFromBones(armature, face_base_pose):
bones = armature.pose.bones
correctedBones = deepcopy(face_base_pose)
for boneName in face_base_pose:
x, y, z = getBonePos(boneName, bones[boneName].location, face_base_pose[boneName])
correctedBones[boneName]['x'] = x
correctedBones[boneName]['y'] = y
correctedBones[boneName]['z'] = z
x, y, z = getBoneRot(boneName, bones[boneName].rotation_euler, face_base_pose[boneName])
correctedBones[boneName]['rot_x'] = x
correctedBones[boneName]['rot_y'] = y
correctedBones[boneName]['rot_z'] = z
"""
Bero1_Joint_scale_x = bones["Bero1_Joint"].scale.x
Bero1_Joint_scale_y = bones["Bero1_Joint"].scale.y
Bero1_Joint_scale_z = bones["Bero1_Joint"].scale.z
Bero2_Joint_x = bones["Bero2_Joint"].location.x * 1000
Bero2_Joint_y = bones["Bero2_Joint"].location.y * 1000
Bero2_Joint_z = bones["Bero2_Joint"].location.z * 1000
Bero2_Joint_rot_x = bones["Bero2_Joint"].rotation_euler.x
Bero2_Joint_rot_y = bones["Bero2_Joint"].rotation_euler.y
Bero2_Joint_rot_z = bones["Bero2_Joint"].rotation_euler.z
Bero2_Joint_scale_x = bones["Bero2_Joint"].scale.x
Bero2_Joint_scale_y = bones["Bero2_Joint"].scale.y
Bero2_Joint_scale_z = bones["Bero2_Joint"].scale.z
Bero3_Joint_x = bones["Bero3_Joint"].location.x * 1000 + 18.521000
Bero3_Joint_y = bones["Bero3_Joint"].location.y * 1000 + 0.000100
Bero3_Joint_z = bones["Bero3_Joint"].location.z * 1000 + -0.000200
Bero3_Joint_rot_x = bones["Bero3_Joint"].rotation_euler.x
Bero3_Joint_rot_y = bones["Bero3_Joint"].rotation_euler.y
Bero3_Joint_rot_z = bones["Bero3_Joint"].rotation_euler.z
Bero3_Joint_scale_x = bones["Bero3_Joint"].scale.x
Bero3_Joint_scale_y = bones["Bero3_Joint"].scale.y
Bero3_Joint_scale_z = bones["Bero3_Joint"].scale.z
"""
return [
correctedBones["L_Mayu1_Joint"]["x"], #L_Mayu1_Joint
correctedBones["L_Mayu1_Joint"]["y"],
correctedBones["L_Mayu1_Joint"]["z"],
correctedBones["L_Mayu1_Joint"]["rot_x"],
correctedBones["L_Mayu1_Joint"]["rot_y"],
correctedBones["L_Mayu1_Joint"]["rot_z"],
correctedBones["L_Mayu2_Joint"]["x"], #L_Mayu2_Joint
correctedBones["L_Mayu2_Joint"]["y"],
correctedBones["L_Mayu2_Joint"]["z"],
correctedBones["L_Mayu2_Joint"]["rot_x"],
correctedBones["L_Mayu2_Joint"]["rot_y"],
correctedBones["L_Mayu2_Joint"]["rot_z"],
correctedBones["L_Mayu3_Joint"]["x"], #L_Mayu3_Joint
correctedBones["L_Mayu3_Joint"]["y"],
correctedBones["L_Mayu3_Joint"]["z"],
correctedBones["L_Mayu3_Joint"]["rot_x"],
correctedBones["L_Mayu3_Joint"]["rot_y"],
correctedBones["L_Mayu3_Joint"]["rot_z"],
correctedBones["R_Mayu1_Joint"]["x"], #R_Mayu1_Joint
correctedBones["R_Mayu1_Joint"]["y"],
correctedBones["R_Mayu1_Joint"]["z"],
correctedBones["R_Mayu1_Joint"]["rot_x"],
correctedBones["R_Mayu1_Joint"]["rot_y"],
correctedBones["R_Mayu1_Joint"]["rot_z"],
correctedBones["R_Mayu2_Joint"]["x"], #R_Mayu2_Joint
correctedBones["R_Mayu2_Joint"]["y"],
correctedBones["R_Mayu2_Joint"]["z"],
correctedBones["R_Mayu2_Joint"]["rot_x"],
correctedBones["R_Mayu2_Joint"]["rot_y"],
correctedBones["R_Mayu2_Joint"]["rot_z"],
correctedBones["R_Mayu3_Joint"]["x"], #R_Mayu3_Joint
correctedBones["R_Mayu3_Joint"]["y"],
correctedBones["R_Mayu3_Joint"]["z"],
correctedBones["R_Mayu3_Joint"]["rot_x"],
correctedBones["R_Mayu3_Joint"]["rot_y"],
correctedBones["R_Mayu3_Joint"]["rot_z"],
correctedBones["L_Eyecorner"]["x"], #L_Eyecorner
correctedBones["L_Eyecorner"]["y"],
correctedBones["L_Eyecorner"]["z"],
correctedBones["L_Eyecorner"]["rot_x"],
correctedBones["L_Eyecorner"]["rot_y"],
correctedBones["L_Eyecorner"]["rot_z"],
correctedBones["R_Eyecorner"]["x"], #R_Eyecorner
correctedBones["R_Eyecorner"]["y"],
correctedBones["R_Eyecorner"]["z"],
correctedBones["R_Eyecorner"]["rot_x"],