-
Notifications
You must be signed in to change notification settings - Fork 60
/
OpenPoseToRig.py
1861 lines (1676 loc) · 91.7 KB
/
OpenPoseToRig.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
bl_info = {
"name": "OpenPose To Rig",
"description": "Tools for moving openpose motions to a rig",
"author": "Nick Keeline",
"version": (0, 0, 0),
"blender": (2, 83, 0),
"location": "3D View > Tools",
"warning": "", # used for warning icon and text in addons panel
"wiki_url": "",
"tracker_url": "",
"category": "Motion Capture"
}
import bpy
import json
import os.path
from os import path
import math
import mathutils
####################################################################################
####################################################################################
####################################################################################
# Functions for converting and manipulation of points.
####################################################################################
####################################################################################
####################################################################################
def combineRReliability(pt1, pt2):
rel1 = pt1[2]
rel2 = pt2[2]
if rel1 < rel2:
relOut = rel1
else:
relOut = rel2
return relOut
def GetPoint (Array, index):
baseIndex = index*3
x = float(Array[baseIndex])
y = float(Array[baseIndex + 1])
reliability = float(Array[baseIndex + 2])
return [x,y,reliability]
#this equation rotates the a point around a center, needed to take head tilt out of facial capture.
def rotatePoint(point, center, angle):
#got equation from https://www.gamefromscratch.com/post/2012/11/24/GameDev-math-recipes-Rotating-one-point-around-another-point.aspx
angle = math.radians(angle ) #Convert to radians
rotatedX = math.cos(angle) * (point[0] - center[0]) - math.sin(angle) * (point[1]-center[1]) + center[0];
rotatedY = math.sin(angle) * (point[0] - center[0]) + math.cos(angle) * (point[1] - center[1]) + center[1];
return [rotatedX,rotatedY,point[2]]
def AverageTwoPoints(pt1, pt2):
avgX = (pt1[0] + pt2[0])/2
avgY = (pt1[1] + pt2[1])/2
return [avgX, avgY,combineRReliability(pt1,pt2)]
def DifferenceBetweenPoint(pt1, pt2):
diffX = (pt1[0] - pt2[0])
diffY = (pt1[1] - pt2[1])
return [diffX, diffY,combineRReliability(pt1,pt2)]
def InverseXandY(pt):
x = pt[0]*-1
y = pt[1]*-1
return [x, y, pt[2]]
def InverseX(pt):
x = pt[0]*-1
y = pt[1]
return [x, y, pt[2]]
def multiply(pt, val):
x = pt[0]*val
y = pt[1]*val
return [x, y, pt[2]]
####################################################################################
####################################################################################
####################################################################################
# This class get's data from open pose data provided and has a bunch of methods that
#get bone angles and position used to postion a bone or get another bones rotation.
####################################################################################
####################################################################################
####################################################################################
class PersonJSONData:
def __init__(self, pose, face, EarLobeToEarLobedistanceInBlenderUnits, TieEyelidsTogether):
self.poseStart = pose
self.faceStart = face
self.poseCurrent = pose
self.faceCurrent = face
self.TieEyelidsTogether = TieEyelidsTogether
#distance is distance between ears
self.distancBetweenEars = abs(GetPoint(pose, 18)[0] - GetPoint(pose, 18)[1])
self.StartNosePosition = GetPoint(pose, 0)
self.StartFaceNosePosition = GetPoint(face, 30)
self.StartFaceChinPosition = GetPoint(face, 8)
self.StartRightEyePosition = GetPoint(pose, 15)
self.StartLeftEyePosition = GetPoint(pose, 16)
#self.StartRightEyePosition = GetPoint(face, 68)
#self.StartLeftEyePosition = GetPoint(face, 69)
self.LastGoodHeadTilt = 0
self.StartHeadTilt = self.getHeadTiltSideToSide()
self.EarLobeToEarLobedistanceInBlenderUnits = EarLobeToEarLobedistanceInBlenderUnits
def SetCurrentPose(self, pose, face):
self.poseCurrent = pose
self.faceCurrent = face
#given a point return it correct for head tilt at the current point in time.
def GetCurrentPointHeadTiltCorrected(self, Point):
angle = self.getHeadTiltSideToSide()
#point 8 is the nose we rotate around it by the tilt of the head
PointCorrrected = rotatePoint(GetPoint(self.faceCurrent, 8), Point,(angle*-1))
return PointCorrrected
#this method returns a start point corrected for the head tilt at start, good for returning a point
#In Space at start of capture corrected for head tilt at start of capture.
def GetStartPointHeadTiltCorrected(self, Point):
angle = self.StartHeadTilt
#point 8 is the nose we rotate around it by the tilt of the head
PointCorrrected = rotatePoint(GetPoint(self.faceStart, 8), Point,(angle*-1))
return PointCorrrected
def GetDistanceBetweenTwoCurrentPoints(self, Pnt1, Pnt2):
x2 = Pnt2[0]
x1 = Pnt1[0]
y2 = Pnt2[1]
y1 = Pnt1[1]
dist = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
return dist
def ConvertPixelPointToBlenderUnits(self, pnt):
pntx = pnt[0] * (self.EarLobeToEarLobedistanceInBlenderUnits/self.distancBetweenEars)
pnty = pnt[1] * (self.EarLobeToEarLobedistanceInBlenderUnits/self.distancBetweenEars)
reliability = pnt[2]
return [pntx,pnty,reliability]
def getHeadTiltSideToSide(self):
#We get the tils by taking the angle difference between the left and right years
leftEar = GetPoint(self.poseCurrent, 18)
rightEar = GetPoint(self.poseCurrent, 17)
deltaY = leftEar[1] - rightEar[1]
deltaX = leftEar[0] - rightEar[0]
if leftEar[2] < .1 or rightEar[2] < .1:
tiltOut = self.LastGoodHeadTilt
else:
tilt = math.atan(deltaY/deltaX)
tiltOut = math.degrees(tilt*-1)
self.LastGoodHeadTilt = tiltOut
return tiltOut
def getHeadTiltUpDown(self):
#get the angle by using the nose vertical translation and approximating the distance
#between the nose and the head pivot using the ear to ear distance from the start.
CurrentNosePosition = GetPoint(self.poseCurrent, 0)
deltaY = CurrentNosePosition[1] - self.StartNosePosition[1]
tilt = math.atan(deltaY/self.distancBetweenEars)
return math.degrees(tilt)
def getHeadTiltLeftRight(self):
#get the angle by using the nose horizontal translation and approximating the distance
#between the nose and the head pivot using the ear to ear distance from the start.
CurrentNosePosition = GetPoint(self.poseCurrent, 0)
deltaX = CurrentNosePosition[0] - self.StartNosePosition[0]
tilt = math.atan(deltaX/self.distancBetweenEars)
return math.degrees(tilt)
def getJawTiltUpDown(self):
#To get the jaw tilt up down we rotate the point around the nose by the head tilt angle
#Then we
NoseToJawStartDist = self.GetDistanceBetweenTwoCurrentPoints(GetPoint(self.faceStart, 8),GetPoint(self.faceStart, 30))
NoseToJawCurrentDist = self.GetDistanceBetweenTwoCurrentPoints(GetPoint(self.faceCurrent, 8),GetPoint(self.faceCurrent, 30))
JawDelta = NoseToJawStartDist - NoseToJawCurrentDist
#approximate the distance from the tip of your jaw to it's pivot by taking the distance between the ears and subtracting an eigth
PivottoEndOfJaw = self.distancBetweenEars - .125*self.distancBetweenEars
Jawtilt = math.atan(JawDelta/PivottoEndOfJaw)
return math.degrees(Jawtilt)
#This takes two points and averages them in the start frame and the current frame. It then
def getFacePosition(self, ptnum1, ptnum2, RelativeTo):
ptAvgStart = AverageTwoPoints(GetPoint(self.faceStart, ptnum1),GetPoint(self.faceStart, ptnum2))
ptAvgCurrent = AverageTwoPoints(GetPoint(self.faceCurrent, ptnum1),GetPoint(self.faceCurrent, ptnum2))
if RelativeTo == "LEFTEYE":
ptDiffCurrent = DifferenceBetweenPoint(ptAvgCurrent,GetPoint(self.poseCurrent, 16))
#ptDiffCurrent = DifferenceBetweenPoint(ptAvgCurrent,GetPoint(self.faceCurrent, 69))
ptDiffStart = DifferenceBetweenPoint(ptAvgStart,self.StartLeftEyePosition)
elif RelativeTo == "RIGHTEYE":
ptDiffCurrent = DifferenceBetweenPoint(ptAvgCurrent,GetPoint(self.poseCurrent, 15))
#ptDiffCurrent = DifferenceBetweenPoint(ptAvgCurrent,GetPoint(self.faceCurrent, 68))
ptDiffStart = DifferenceBetweenPoint(ptAvgStart,self.StartRightEyePosition)
elif RelativeTo == "CHIN":
ptDiffCurrent = DifferenceBetweenPoint(ptAvgCurrent,GetPoint(self.faceCurrent, 8))
ptDiffStart = DifferenceBetweenPoint(ptAvgStart,self.StartFaceChinPosition)
elif RelativeTo == "upperlip":
ptDiffCurrent = DifferenceBetweenPoint(ptAvgCurrent,GetPoint(self.faceCurrent, 51))
ptDiffStart = DifferenceBetweenPoint(ptAvgStart,self.StartFaceChinPosition)
else:
ptDiffCurrent = DifferenceBetweenPoint(ptAvgCurrent,GetPoint(self.faceCurrent, 30))
ptDiffStart = DifferenceBetweenPoint(ptAvgStart,self.StartFaceNosePosition)
#StartPos = self.GetStartPointHeadTiltCorrected(ptDiffStart)
#CurrentPos = self.GetCurrentPointHeadTiltCorrected(ptDiffCurrent)
#DeltaPixels = DifferenceBetweenPoint(GetPoint(self.faceStart, ptnum1),GetPoint(self.faceCurrent, ptnum1))
#DeltaPixels = DifferenceBetweenPoint(ptAvgStart, ptAvgCurrent)
DeltaPixels = DifferenceBetweenPoint(ptDiffStart, ptDiffCurrent)
#DeltaPixels = DifferenceBetweenPoint(StartPos,CurrentPos)
return DeltaPixels
def getJawPosition(self, correction, ref):
if ref == 'DEFAULT':
thisref = "NOSE"
else:
thisref = ref
output = self.ConvertPixelPointToBlenderUnits(self.getFacePosition(8,8, thisref))
return multiply(output, correction)
def getLowerLipCenterPosition(self, correction, ref):
if ref == 'DEFAULT':
thisref = "NOSE"
else:
thisref = ref
output = self.ConvertPixelPointToBlenderUnits(self.getFacePosition(57,66, thisref))
return multiply(output, correction)
def getLowerLipCenterLeftPosition(self, correction, ref):
if ref == 'DEFAULT':
thisref = "NOSE"
else:
thisref = ref
output = self.ConvertPixelPointToBlenderUnits(self.getFacePosition(65,65, thisref))
return multiply(output, correction)
def getLowerLipCenterRightPosition(self, correction, ref):
if ref == 'DEFAULT':
thisref = "NOSE"
else:
thisref = ref
output = self.ConvertPixelPointToBlenderUnits(self.getFacePosition(67,67, thisref))
return multiply(output, correction)
def getUpperLipCenterPosition(self, correction, ref):
if ref == 'DEFAULT':
thisref = "NOSE"
else:
thisref = ref
output = self.ConvertPixelPointToBlenderUnits(self.getFacePosition(62,62, thisref))
return multiply(output, correction)
def getUpperLipCenterLeftPosition(self, correction, ref):
if ref == 'DEFAULT':
thisref = "NOSE"
else:
thisref = ref
output = self.ConvertPixelPointToBlenderUnits(self.getFacePosition(52,63, thisref))
return multiply(output, correction)
def getUpperLipCenterRightPosition(self, correction, ref):
if ref == 'DEFAULT':
thisref = "NOSE"
else:
thisref = ref
output = self.ConvertPixelPointToBlenderUnits(self.getFacePosition(50,61, thisref))
return multiply(output, correction)
def getUpperLipOuterLeftPosition(self, correction, ref):
if ref == 'DEFAULT':
thisref = "NOSE"
else:
thisref = ref
output = self.ConvertPixelPointToBlenderUnits(self.getFacePosition(63,63, thisref))
return multiply(output, correction)
def getUpperLipOuterRightPosition(self, correction, ref):
if ref == 'DEFAULT':
thisref = "NOSE"
else:
thisref = ref
output = self.ConvertPixelPointToBlenderUnits(self.getFacePosition(61,61, thisref))
return multiply(output, correction)
def getLowerLipOuterLeftPosition(self, correction, ref):
if ref == 'DEFAULT':
thisref = "NOSE"
else:
thisref = ref
output = self.ConvertPixelPointToBlenderUnits(self.getFacePosition(65,65, thisref))
return multiply(output, correction)
def getLowerLipOuterRightPosition(self, correction, ref):
if ref == 'DEFAULT':
thisref = "NOSE"
else:
thisref = ref
output = self.ConvertPixelPointToBlenderUnits(self.getFacePosition(67,67, thisref))
return multiply(output, correction)
def getLipLeftPosition(self, correction, ref):
if ref == 'DEFAULT':
thisref = "NOSE"
else:
thisref = ref
output = self.ConvertPixelPointToBlenderUnits(self.getFacePosition(54,64, thisref))
return multiply(output, correction)
def getLipRightPosition(self, correction, ref):
if ref == 'DEFAULT':
thisref = "NOSE"
else:
thisref = ref
output = self.ConvertPixelPointToBlenderUnits(self.getFacePosition(48,60, thisref))
return multiply(output, correction)
def getEyeBrowLeftOuter(self, correction, ref):
if ref == 'DEFAULT':
thisref = "LEFTEYE"
else:
thisref = ref
output = self.ConvertPixelPointToBlenderUnits(self.getFacePosition(25,26, thisref))
return multiply(output, correction)
def getEyeBrowLeftCenter(self, correction, ref):
if ref == 'DEFAULT':
thisref = "LEFTEYE"
else:
thisref = ref
output = self.ConvertPixelPointToBlenderUnits(self.getFacePosition(24,24, thisref))
return multiply(output, correction)
def getEyeBrowLeftInner(self, correction, ref):
if ref == 'DEFAULT':
thisref = "LEFTEYE"
else:
thisref = ref
output = self.ConvertPixelPointToBlenderUnits(self.getFacePosition(22,23, thisref))
return multiply(output, correction)
def getEyeBrowRightOuter(self, correction, ref):
if ref == 'DEFAULT':
thisref = "RIGHTEYE"
else:
thisref = ref
output = self.ConvertPixelPointToBlenderUnits(self.getFacePosition(17,18, thisref))
return multiply(output, correction)
def getEyeBrowRightCenter(self, correction, ref):
if ref == 'DEFAULT':
thisref = "RIGHTEYE"
else:
thisref = ref
output = self.ConvertPixelPointToBlenderUnits(self.getFacePosition(19,19, thisref))
return multiply(output, correction)
def getEyeBrowRightInner(self, correction, ref):
if ref == 'DEFAULT':
thisref = "RIGHTEYE"
else:
thisref = ref
output = self.ConvertPixelPointToBlenderUnits(self.getFacePosition(20,21, thisref))
return multiply(output, correction)
def getEyelidRight(self, correction, ref):
if ref == 'DEFAULT':
thisref = "RIGHTEYE"
else:
thisref = ref
if self.TieEyelidsTogether:
eyeR = self.getFacePosition(37,38, "RIGHTEYE")
eyeL = self.getFacePosition(43,44, "LEFTEYE")
output = self.ConvertPixelPointToBlenderUnits(AverageTwoPoints(eyeR,eyeL))
else:
output = self.ConvertPixelPointToBlenderUnits(self.getFacePosition(37,38, thisref))
return multiply(output, correction)
def getEyelidLeft(self, correction, ref):
if ref == 'DEFAULT':
thisref = "LEFTEYE"
else:
thisref = ref
if self.TieEyelidsTogether:
eyeR = self.getFacePosition(37,38, "RIGHTEYE")
eyeL = self.getFacePosition(43,44, "LEFTEYE")
output = self.ConvertPixelPointToBlenderUnits(AverageTwoPoints(eyeR,eyeL))
else:
output = self.ConvertPixelPointToBlenderUnits(self.getFacePosition(43,44, thisref))
return multiply(output, correction)
def getEyelidLowerRight(self, correction, ref):
if ref == 'DEFAULT':
thisref = "RIGHTEYE"
else:
thisref = ref
output = self.ConvertPixelPointToBlenderUnits(self.getFacePosition(40,41, thisref))
return multiply(output, correction)
def getEyelidLowerLeft(self, correction, ref):
if ref == 'DEFAULT':
thisref = "LEFTEYE"
else:
thisref = ref
output = self.ConvertPixelPointToBlenderUnits(self.getFacePosition(46,47, thisref))
return multiply(output, correction)
####################################################################################
####################################################################################
####################################################################################
#Rig bone mappping data. This is the data on what map to each bone. Each Bone
# can be saved to a file, so this object just contains the bones mapping info only
####################################################################################
####################################################################################
####################################################################################
class BoneJSONData:
def __init__(SourceBoneLocationName, DestinationBoneName, BoneModificationType, ApplyToX, ApplyToY, DirectionQuatToApplyXandY):
#This is the source from JSON like head_bone that designates where this bone is getting it's information from in the JSON file
self.SourceBoneLocationName = SourceBoneLocationName
#This is the name for the rig bone name.
self.DestinationBoneName = DestinationBoneName
#keyframe type is either 'LOC' for location or 'ROT' for rotation
self.BoneModificationType = BoneModificationType
#boolean true/false saying do you want to apply X (horizontal) data from JSON)
self.ApplyToX = ApplyToX
#boolean true/false saying do you want to apply Y (vertiacl) data from JSON)
self.ApplyToY = ApplyToY
#This quaternion will rotat the bone then translate it in the rotated direction then rotate it back at the end.
self.DirectionQuatToApplyXandY = DirectionQuatToApplyXandY
def GetJSONDataAsString(self):
# a Python object (dict):
DataDictionary = {
"SourceBoneLocationName": self.SourceBoneLocationName,
"DestinationBoneName": self.DestinationBoneName,
"BoneModificationType": self.BoneModificationType,
"ApplyToX": self.ApplyToX,
"ApplyToY": self.ApplyToY,
"DirectionQuatToApplyXandY": self.DirectionQuatToApplyXandY,
}
# convert into JSON:
return json.dumps(DataDictionary)
def SetJSONDataFromSTring(self,JSONString):
# parse JSONString:
y = json.loads(JSONString)
self.SourceBoneLocationName = y["SourceBoneLocationName"]
self.DestinationBoneName = y["DestinationBoneName"]
self.BoneModificationType = y["BoneModificationType"]
self.ApplyToX = y["ApplyToX"]
self.ApplyToY = y["ApplyToY"]
self.DirectionQuatToApplyXandY = y["DirectionQuatToApplyXandY"]
####################################################################################
####################################################################################
####################################################################################
# This Class is a Bone class for every Bone in the Armature we want to modify
# with the JSON Data Object. Each bone contains an location it belongs to like
# face, body , hand etc and a bone modification type like rotation or
####################################################################################
####################################################################################
####################################################################################
class BoneToMap:
def __init__(Armature, SourceBoneLocationName, DestinationBoneName, BoneModificationType, BoneDataName, ApplyToX, ApplyToY, ApplyToZ):
#This is the source from JSON like head_bone that designates where this bone is getting it's information from in the JSON file
self.SourceBoneLocationName = SourceBoneLocationName
#This is the destination bone name on the rig to apply the modifications to.
self.BoneName = BoneName
self.Bone = Armature.pose.bones[BoneName]
self.BoneDataName = BoneDataName
#keyframe type is either 'LOC' for location or 'ROT' for rotation
self.BoneModificationType = BoneModificationType
self.ApplyToX = ApplyToX
self.ApplyToY = ApplyToY
self.ApplyToZ = ApplyToZ
def SetBoneLocation(self, X, Y, Z):
if self.ApplyToX:
self.Bone.location.x = X
if self.ApplyToY:
self.Bone.location.y = Y
if self.ApplyToZ:
self.Bone.location.z = Z
def SetBoneRotationEuler(self, X, Y, Z):
self.Bone.rotation_mode = 'XYZ'
self.Bone.rotation_euler = head_angle
def KeyFrame(self):
if BoneModificationType == 'LOC':
self.Bone.keyframe_insert(data_path='location',frame= FinalFrameNumber)
if BoneModificationType == 'ROT':
self.Bone.keyframe_insert(data_path='rotation_euler',frame= FinalFrameNumber)
####################################################################################
####################################################################################
####################################################################################
# This class Basically calls all other classes and holds an array of bones and operates
# on them with the data object to move the bones and keyframe.
####################################################################################
####################################################################################
####################################################################################
#class RigModificationProcess:
# def __init__(Rigname, Rig):
# self.RigName = RigName
# self.Rig = Rig
# self.FaceBones = []
# def AddFaceBone(self, DestinationBoneName, BoneModificationType, BoneLocationType):
# NewBone = BoneToMap(DestinationBoneName, BoneModificationType, BoneLocationType)
# self.FaceBones.append(NewBone)
#
#
# def AddBodyBone(self, DestinationBoneName, BoneModificationType, BoneLocationType):
# NewBone = BoneToMap(DestinationBoneName, BoneModificationType, BoneLocationType)
# self.FaceBones.append(NewBone)
# ------------------------------------------------------------------------
# store properties in the active scene
# ------------------------------------------------------------------------
#DestArmName = "rig"
##Go Into Edit mode and get delta x between earlobes
##we know the pixel distance between ears in open pse so knowing it for the character
##biveus the converation between pixels and blender units.
#EarLobeToEarLobedistanceInBlenderUnits = .178654
#StartFrameNumber = 0
#mouth_KeyFrame_Every_Nth_Frame = 3
#eyes_KeyFrame_Every_Nth_Frame = 15
##number of frames to transfer, make really t
#NumberOfFramesToTransfer = 1400
#keyFrame = True
##eyelids are kind of inaccurate, so let's tie them together if
##your not going ot wink in the video, a little more natrualif true.
#TieEyelidsTogether = True
##If the eyelid moves more than this amount of blender units, we keyframe,
##that way we catch fast blinks, but eliminate jitter in eyelid...
#EyelidBlinkTHreshold = .01
class OpenPoseToRigifySettings(bpy.types.PropertyGroup):
facial_capture: bpy.props.BoolProperty(
name="Facial Capture",
description="As We read in the JSON files do we apply facial capture to the character",
default = True
)
body_capture: bpy.props.BoolProperty(
name="Apply Body Capture",
description="As We read in the JSON files do we apply body capture to the character",
default = True
)
tie_eyelids_together: bpy.props.BoolProperty(
name="Tie Eyelids Together",
description="Ties the characters Eyelids Together, NO WINKING",
default = True
)
number_of_frames_to_apply: bpy.props.IntProperty(
name = "Number of Samples",
description="Number of Samples to read in and apply",
default = 10000,
min = 0,
max = 10000
)
start_frame_to_apply: bpy.props.IntProperty(
name = "Starting Frame",
description="Frame to Apply Motion Capture To",
default = 0,
min = 0,
max = 10000
)
mouth_keyframe_every_n_frames: bpy.props.IntProperty(
name = "Mouth Keyframe Number",
description="Frame to Apply a Keyframe to, 1 is every frame",
default = 3,
min = 1,
max = 100
)
eye_keyframe_every_n_frames: bpy.props.IntProperty(
name = "Eye Keyframe Number",
description="Frame to Apply a Keyframe to, 1 is every frame",
default = 15,
min = 1,
max = 100
)
ear_to_ear_conversion_distance: bpy.props.FloatProperty(
name = "Ear to Ear Distance",
description = "The distance in blender units between each ear of the character",
default = .16,
min = 0.001,
max = 1000.0
)
eyelid_noise_removal_distance: bpy.props.FloatProperty(
name = "Ignore Eyelid Flutter",
description = "Blender Units to ignore eyelid jitter, higher values makes eyelids flutter less.",
default = .01,
min = 0.00001,
precision = 6,
max = 1000.0
)
rig_name: bpy.props.StringProperty(
name="Rig Name",
description="Rig Name to Apply Capture To",
default="",
maxlen=1024
)
first_JSON_file_to_read_in: bpy.props.StringProperty(
name="First JSON Capture File",
description="Choose the first JSON file to read in:",
default="",
maxlen=1024,
subtype='FILE_PATH'
)
bone_mapping_file: bpy.props.StringProperty(
name="Bone Mapping File to Read and Save",
description="Select a File to Read In:",
default="",
maxlen=1024,
subtype='FILE_PATH'
)
#list_index: bpy.props.IntProperty(name = "Index for my_list", default = 0)
#class ListIndex(bpy.types.IntProperty):
#list_index: bpy.props.IntProperty(name = "Index for my_list", default = 0)
# bpy.types.Scene.list_index = IntProperty(name = "Index for my_list", default = 0)
#class MyBoneMapIndex(bpy.types.PropertyGroup):
# use an annotation
#bone_index : bpy.props.IntProperty(name = "Index for my_list", default = 0)
#class MyBoneMapIndex(bpy.types.IntProperty):
# use an annotation
#bpy.props.IntProperty(name = "Index for my_list", default = 0)
class BoneMappingListItem(bpy.types.PropertyGroup):
#"""Group of properties representing a bone mapping from OpenPose to a Rig"""
name : bpy.props.StringProperty()
label : bpy.props.StringProperty()
description : bpy.props.StringProperty()
SourceBoneType: bpy.props.EnumProperty(
name="Type Of Bone",
description="Is this a face, body or hand bone",
items=[ ('FACE', "Face", ""),
('BODY', "Body", ""),
('HAND', "Hand", "")
]
)
SourceBoneLocationNameFace: bpy.props.EnumProperty(
name="Source Bone Name Face",
description="This is the source from JSON like head_bone that designates where this bone is getting it's information from in the JSON file",
items=[ ('head', "head", ""),
('Jaw', "Jaw", ""),
('LowerLipCenter', "LowerLipCenter", ""),
('LowerLipCenterLeft', "LowerLipCenterLeft", ""),
('LowerLipCenterRight', "LowerLipCenterRight", ""),
('UpperLipCenter', "UpperLipCenter", ""),
('UpperLipCenterLeft', "UpperLipCenterLeft", ""),
('UpperLipCenterRight', "UpperLipCenterRight", ""),
('UpperLipOuterLeft', "UpperLipOuterLeft", ""),
('UpperLipOuterRight', "UpperLipOuterRight", ""),
('LowerLipOuterLeft', "LowerLipOuterLeft", ""),
('LowerLipOuterRight', "LowerLipOuterRight", ""),
('LipLeft', "LipLeft", ""),
('LipRight', "LipRight", ""),
('EyeBrowLeftOuter', "EyeBrowLeftOuter", ""),
('EyeBrowLeftCenter', "EyeBrowLeftCenter", ""),
('EyeBrowLeftInner', "EyeBrowLeftInner", ""),
('EyeBrowRightOuter', "EyeBrowRightOuter", ""),
('EyeBrowRightCenter', "EyeBrowRightCenter", ""),
('EyeBrowRightInner', "EyeBrowRightInner", ""),
('EyelidRight', "EyelidRight", ""),
('EyelidLeft', "EyelidLeft", ""),
('EyelidLowerRight', "EyelidLowerRight", ""),
('EyelidLowerLeft', "EyelidLowerLeft", "")
]
)
OpenPoseFaceMovementReference: bpy.props.EnumProperty(
name="Face Reference",
description="This is the reference point on the face the script will calculate offset from. So basically it's the anchor point on the face used to measure distnance from.",
items=[ ('DEFAULT', "Default", ""),
('RIGHTEYE', "Right Eye", ""),
('LEFTEYE', "Left Eye", ""),
('NOSE', "Nose", ""),
('CHIN', "Chin", "")
]
)
SourceBoneLocationNameBody: bpy.props.EnumProperty(
name="Source Bone Name Body",
description="This is the source from JSON like head_bone that designates where this bone is getting it's information from in the JSON file",
items=[ ('CHEST', "Chest", ""),
('BICEPRIGHT', "Bicep Right", ""),
('FOREARMRIGHT', "ForeArm Right", "")
]
)
SourceBoneLocationNameHand: bpy.props.EnumProperty(
name="Source Bone Name Hand",
description="This is the source from JSON like head_bone that designates where this bone is getting it's information from in the JSON file",
items=[ ('INDEXTIP', "Index Tip", ""),
('INDEXCENTER', "Index Center", ""),
('INDEXBASE', "Index Base", ""),
('PALM', "Palm", "")
]
)
DestinationBoneName: bpy.props.StringProperty(
name="Destination Bone Name",
description="This is the name for the rig bone name.",
default="",
maxlen=1024
)
BoneModificationType: bpy.props.EnumProperty(
name="Bone Modification Type",
description="Translate the bone method either location or rotation",
items=[ ('LOC', "Location", ""),
('ROT', "Rotation", ""),
]
)
BoneGain: bpy.props.FloatProperty(
name="Bone Gain",
description="The amount of gain to apply to the bone, values greater than one make it move more.",
default = 1
)
ApplyToX: bpy.props.BoolProperty(
name="Apply Horizontal",
description="Applies the horizontal translation or rotatiation of the openpose points to the bone",
default = True
)
BoneHorizontalAxis: bpy.props.EnumProperty(
name="Horizontal Axis",
description="Axis to Apply horizontal translation or rotation to.",
items=[ ('PLUSX', "+X", ""),
('PLUSY', "+Y", ""),
('PLUSZ', "+Z", ""),
('NEGX', "-X", ""),
('NEGY', "-Y", ""),
('NEGZ', "-Z", "")
]
)
ApplyTranslationAlongMoreAxisHorizontal: bpy.props.BoolProperty(
name="Translate along more Axis Horizontal",
description="This will take the translation along the axis above selected and move the other two axis proportionally by an amount",
default = False
)
TranslationAlongMoreAxisHorizontal: bpy.props.FloatVectorProperty(
name="Move other axis Horizontally",
description="Move the bone in the direction you want it to go and put it's x, y and z in here to have it move in this direction when openpose horizontal motion occurs",
subtype = 'TRANSLATION',
unit = 'LENGTH',
default = (0.0, 0.0, 0.0),
size = 3
)
ApplyToY: bpy.props.BoolProperty(
name="Apply Vertical",
description="Applies the vertical translation or rotatiation of the openpose points to the bone",
default = True
)
BoneVerticalAxis: bpy.props.EnumProperty(
name="Vertical Axis",
description="Axis to Apply vertical translation or rotation to.",
items=[ ('PLUSX', "+X", ""),
('PLUSY', "+Y", ""),
('PLUSZ', "+Z", ""),
('NEGX', "-X", ""),
('NEGY', "-Y", ""),
('NEGZ', "-Z", "")
]
)
ApplyTranslationAlongMoreAxisVertical: bpy.props.BoolProperty(
name="Translate along more Axis Vertical",
description="This will take the translation along the axis above selected and move the other two axis proportionally by an amount",
default = False
)
TranslationAlongMoreAxisVertical: bpy.props.FloatVectorProperty(
name="Move other axis Vertically",
description="Move the bone in the direction you want it to go and put it's x, y and z in here to have it move in this direction when openpose Vertical motion occurs",
subtype = 'TRANSLATION',
unit = 'LENGTH',
default = (0.0, 0.0, 0.0),
size = 3
)
ApplyToZ: bpy.props.BoolProperty(
name="Apply Twist",
description="Applies the twist translation or rotatiation of the openpose points to the bone",
default = False
)
BoneTwistAxis: bpy.props.EnumProperty(
name="Twist Axis",
description="Axis to Apply twist translation or rotation to.",
items=[ ('PLUSX', "+X", ""),
('PLUSY', "+Y", ""),
('PLUSZ', "+Z", ""),
('NEGX', "-X", ""),
('NEGY', "-Y", ""),
('NEGZ', "-Z", "")
]
)
# ApplyRollCorrection: bpy.props.BoolProperty(
# name="Apply Roll Correction",
# description="Apply a Roll Correction to the Bone if we don't have an axis that is straight up and down to the openpose capture.",
# default = False
# )
#
#
# RollCorrection: bpy.props.FloatProperty(
# name="1st Roll Correction",
# description="The Angle to roll the bone before applying a transform to it.",
# subtype = 'ANGLE',
# unit = 'ROTATION',
# default = 0
# )
#
# BoneRollCorrectionAxis: bpy.props.EnumProperty(
# name="Roll 1st Correction Axis",
# description="Axis to Apply vertical translation or rotation to.",
# items=[ ('PLUSX', "X", ""),
# ('PLUSY', "Y", ""),
# ('PLUSZ', "Z", "")
# ]
# )
#
# ApplyRollCorrection2: bpy.props.BoolProperty(
# name="Apply 2nd Roll Correction",
# description="Apply a 2nd Roll Correction to the Bone if we don't have an axis that is straight up and down to the openpose capture.",
# default = False
# )
#
#
# RollCorrection2: bpy.props.FloatProperty(
# name="2nd Roll Correction",
# description="The Angle to roll the bone before applying a transform to it.",
# subtype = 'ANGLE',
# unit = 'ROTATION',
# default = 0
# )
#
# BoneRollCorrectionAxis2: bpy.props.EnumProperty(
# name="Roll Correction Axis",
# description="Axis to Apply vertical translation or rotation to.",
# items=[ ('PLUSX', "X", ""),
# ('PLUSY', "Y", ""),
# ('PLUSZ', "Z", "")
# ]
# )
UseCustomKeyFrameNumber: bpy.props.BoolProperty(
name="Use Custom Keyframe Number",
description="Override the global keyframe number to remove noise or increase sensitivity.",
default = False
)
CustomBonKeyFrameNumber: bpy.props.IntProperty(
name="Keyframe Bone Every N Frames",
description="Keyframe this bone every n Frames",
default = 5,
min = 1,
max = 100
)
# RemoveParentBonesTranslationEffectCorrection: bpy.props.BoolProperty(
# name="Removes the effects of a Parent Bone",
# description="If the jaw Bone moves a lip bone, this correction moves the lower lip back together so we can then translate them with respect to the nose.",
# default = False
# )
#
# ParentBoneCorrectionName: bpy.props.StringProperty(
# name="Name of Parent Bone to this one.",
# description="This is the name for the parent bone that is effecting this one.",
# default="",
# maxlen=1024
# )
#
# ParentCorrectionType: bpy.props.EnumProperty(
# name="Parent Bone Type of Motion to Nullify",
# description="The parent bones motion type that will be nulled out in the child bone",
# items=[ ('LOC', "Location", ""),
# ('ROT', "Rotation", ""),
# ]
# )
#
# ParentCorrectionVerticalAxis: bpy.props.EnumProperty(
# name="Parent Axis to remove motion or Angle from child",
# description="Axis to Apply vertical translation or rotation to.",
# items=[ ('PLUSX', "X", ""),
# ('PLUSY', "Y", ""),
# ('PLUSZ', "Z", "")
# ]
# )
#
#
# VerticalParentTranslationRemovalAmount: bpy.props.FloatProperty(
# name="Parent Bones Translation Amount",
# description="If the parent bone is moved by this amount, move the child back up by the below amount.",
# subtype = 'DISTANCE',
# default = 0
# )
#
#
# VerticalParentRotationAmount: bpy.props.FloatProperty(
# name="Rotation in degrees of parent bone to correct out.",
# description="If the parent bone is rotated along the above axis by this amount, translate the child the below amount vertically.",
# subtype = 'ANGLE',
# default = 0
# )
#
#
# VerticalTranslationRemovalAmount: bpy.props.FloatProperty(
# name="This Bones translation to null out angle above.",
# description="If the parent bone moves the above amount move it vertically back by this amount.",
# subtype = 'DISTANCE',
# default = 0
# )
#
# ParentCorrectionHorizontalAxis: bpy.props.EnumProperty(
# name="Parent Axis to remove motion or Angle from child",
# description="Axis to Apply horizontal translation or rotation to.",
# items=[ ('PLUSX', "X", ""),
# ('PLUSY', "Y", ""),
# ('PLUSZ', "Z", "")
# ]
# )
#
#
# HorizontalParentTranslationRemovalAmount: bpy.props.FloatProperty(
# name="Parent Bones Translation Amount",
# description="If the parent bone is moved by this amount, move the child back up by the below amount.",
# subtype = 'DISTANCE',
# default = 0
# )
#
#
# HorizontalParentRotationAmount: bpy.props.FloatProperty(
# name="Rotation in degrees of parent bone to correct out.",
# description="If the parent bone is rotated along the above axis by this amount, translate the child the below amount Horizontally.",
# subtype = 'ANGLE',
# default = 0
# )
#
#
# HorizontalTranslationRemovalAmount: bpy.props.FloatProperty(
# name="This Bones translation to null out angle above.",
# description="If the parent bone moves the above amount move it horizontally back by this amount.",
# subtype = 'DISTANCE',
# default = 0
# )
# DirectionQuatToApplyXandY: bpy.props.FloatVectorProperty(
# name="Rotation Correction",
# description="This quaternion will rotat the bone then translate it in the rotated direction then rotate it back at the end.",
# #default = Quaternion(1,0,0,0)
# subtype = 'QUATERNION',
# size = 4
# )
# ------------------------------------------------------------------------
# operators
# ------------------------------------------------------------------------
####################################################################################
####################################################################################