-
Notifications
You must be signed in to change notification settings - Fork 0
/
AnimationTransferMaster-Broken.py
197 lines (150 loc) · 6.17 KB
/
AnimationTransferMaster-Broken.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
import pymel.core as pm
import pymel.core.datatypes as dt
import LoadMyUI as myUI
maxTime = pm.playbackOptions(q = True, max = True)
minTime = pm.playbackOptions(q = True, min = True)
timeLen = int((maxTime - minTime) + 2)
getBindPose = 0
firstPass = 0
sourceCount = 0
targetCount = 0
#Math results stored in lists
isolatedRotation = []
worldSpaceRotation = []
translatedRotation = []
sJointRotation = []
sJointOrientation = []
tJointRotation = []
newSourceList = []
newTargetList = []
def printTree(node, aList):
for child in node.getChildren():
if aList == 'source':
myUI.sourceTree.append(child)
if aList == 'target':
myUI.targetTree.append(child)
printTree(child, aList)
def calcSourceParentBP(child, parentBindPose):
parent = child.getParent()
if parent:
parentBindPose = calcSourceParentBP(parent, parentBindPose)
#parentBindPose = (parent.getRotation().asMatrix() * parent.getOrientation().asMatrix()) * parentBindPose
parentBindPose = (dt.EulerRotation(parent.rotate.get(t = 0)).asMatrix() * dt.EulerRotation(parent.jointOrient.get(t = 0)).asMatrix()) * parentBindPose
return parentBindPose
def sourceTree(sourceTreeItem, currTime, listLength):
global sourceCount
global getBindPose
global newSourceList
global sJointRotation
global sJointOrientation
print 'sourceTreeItem'
print sourceTreeItem
childIndex = 0
if sourceCount != 0:
for items in range(listLength):
if getBindPose == 0:
print 'inside bindPose'
sJointRotation.append(sourceTreeItem.getRotation().asMatrix())
sJointOrientation.append(sourceTreeItem.getOrientation().asMatrix())
print 'before if count'
print sourceCount
print sourceCount
print 'sJointRotation'
print sJointRotation
#k1 calculation
isolatedRotation.append(sJointRotation[childIndex].inverse() * sourceTreeItem.getRotation().asMatrix())
#k2 calculation
#pm.currentTime(0)
parentBindPose = 1
sourceParentBP = calcSourceParentBP(sourceTreeItem, parentBindPose)
#pm.currentTime(currTime)
print 'Before worldspacerotation'
print sourceTreeItem
worldSpaceRotation.append(sourceTreeItem.getOrientation().asMatrix().inverse() * sourceParentBP.inverse() * isolatedRotation[childIndex] * sourceParentBP * sourceTreeItem.getOrientation().asMatrix())
sourceCount += 1
print 'listLength'
print listLength
if listLength > sourceCount:
print 'SourceList in if'
print sourceCount
sourceTree (newSourceList[sourceCount], currTime, listLength)
elif listLength == sourceCount:
print 'SourceList in if'
print sourceCount
sourceTree (newSourceList[sourceCount], currTime, listLength)
else:
print 'first'
print listLength
sourceCount += 1
sourceTree(newSourceList[sourceCount], currTime, listLength)
def targetTree(targetTreeItem, currTime, listLength):
global targetCount
global newTargetList
global getBindPose
global tJointRotation
if targetCount != 0:
for items in range(listLength):
if getBindPose == 0:
tJointRotation.append(targetTreeItem.getRotation().asMatrix())
pm.setKeyframe(targetTreeItem)
#pm.currentTime(0)
parentBindPose = 1
targetParentBP = calcSourceParentBP(targetTreeItem, parentBindPose)
pm.currentTime(currTime)
translatedRotation.append(targetTreeItem.getOrientation().asMatrix() * targetParentBP * worldSpaceRotation[targetCount] * targetParentBP.inverse() * targetTreeItem.getOrientation().asMatrix().inverse())
translatedRotation[targetCount] = tJointRotation[targetCount] * translatedRotation[targetCount]
targetTreeItem.setRotation(dt.degrees(dt.EulerRotation(translatedRotation[targetCount])))
targetCount += 1
if listLength != targetCount:
targetTree (targetList[targetCount], currTime, listLength)
#Calculate the rotation for the node and set keyframe if node is still in the list
checkViable = checkInList(node, aList)
if checkVialbe == 1:
pm.setKeyFrame()
else:
targetCount += 1
targetTree(targetList[targetCount], currTime, listLength)
def setNewLists(sourceList, targetList, sourceRoot, targetRoot):
global sourceCount
global targetCount
global getBindPose
global newSourceList
global newTargetList
newSourceList.append(sourceRoot)
newSourceList.extend(sourceList)
newTargetList.append(targetRoot)
newTargetList.extend(targetList)
sListLength = len(sourceList)
tListLength = len(targetList)
print 'sListLength'
print sListLength
print 'tListLength'
print tListLength
for frames in range(timeLen):
pm.currentTime(frames)
cleanUpLists()
sourceTree(newSourceList[sourceCount], frames, sListLength)
targetTree(newTargetList[targetCount], frames, tListLength)
getBindPose = 1
copyPasteRootAttribs(sourceRoot, targetRoot)
pm.setKeyframe(targetRoot)
print 'Frame: ' + str(frames) + ' calculated of: ' + str(timeLen - 1)
def checkInList(node, listLength):
found = 0
selectedJntName = node.name()
for item in range(listLength):
temp = [item]
if temp == selectedJntName:
found = 1
return found
else:
found = 0
return found
def cleanUpLists():
del isolatedRotation[:]
del worldSpaceRotation[:]
del translatedRotation[:]
def copyPasteRootAttribs(rootJointS, rootJointT):
rootJointT.setRotation(rootJointS.getRotation())
rootJointT.setTranslation(rootJointS.getTranslation())
rootJointT.setOrientation(rootJointS.getOrientation())