Additional work on animation stitching, now with auto-guess capability. Only a few...
[blender.git] / release / scripts / modules / retarget.py
1 # ##### BEGIN GPL LICENSE BLOCK #####
2 #
3 #  This program is free software; you can redistribute it and/or
4 #  modify it under the terms of the GNU General Public License
5 #  as published by the Free Software Foundation; either version 2
6 #  of the License, or (at your option) any later version.
7 #
8 #  This program is distributed in the hope that it will be useful,
9 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
10 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 #  GNU General Public License for more details.
12 #
13 #  You should have received a copy of the GNU General Public License
14 #  along with this program; if not, write to the Free Software Foundation,
15 #  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 #
17 # ##### END GPL LICENSE BLOCK #####
18
19 # <pep8 compliant>
20
21 import bpy
22 from mathutils import *
23 from math import radians, acos
24 from bl_operators import nla
25 import cProfile
26
27
28 def hasIKConstraint(pose_bone):
29     #utility function / predicate, returns True if given bone has IK constraint
30     ik = [constraint for constraint in pose_bone.constraints if constraint.type == "IK"]
31     if ik:
32         return ik[0]
33     else:
34         return False
35
36
37 def createDictionary(perf_arm, end_arm):
38     # clear any old data
39     for end_bone in end_arm.bones:
40         for mapping in end_bone.reverseMap:
41             end_bone.reverseMap.remove(0)
42
43     for perf_bone in perf_arm.bones:
44         #find its match and add perf_bone to the match's mapping
45         if perf_bone.map:
46             end_bone = end_arm.bones[perf_bone.map]
47             newMap = end_bone.reverseMap.add()
48             newMap.name = perf_bone.name
49             end_bone.foot = perf_bone.foot
50
51     #root is the root of the enduser
52     root = end_arm.bones[0].name
53     feetBones = [bone.name for bone in perf_arm.bones if bone.foot]
54     return feetBones, root
55
56 def loadMapping(perf_arm, end_arm):
57
58     for end_bone in end_arm.bones:
59         #find its match and add perf_bone to the match's mapping
60         if end_bone.reverseMap:
61             for perf_bone in end_bone.reverseMap:
62                 perf_arm.bones[perf_bone.name].map = end_bone.name
63
64 #creation of intermediate armature
65 # the intermediate armature has the hiearchy of the end user,
66 # does not have rotation inheritence
67 # and bone roll is identical to the performer
68 # its purpose is to copy over the rotations
69 # easily while concentrating on the hierarchy changes
70
71
72 def createIntermediate(performer_obj, enduser_obj, root, s_frame, e_frame, scene):
73     #creates and keyframes an empty with its location
74     #the original position of the tail bone
75     #useful for storing the important data in the original motion
76     #i.e. using this empty to IK the chain to that pos / DEBUG
77
78     #Simple 1to1 retarget of a bone
79     def singleBoneRetarget(inter_bone, perf_bone):
80             perf_world_rotation = perf_bone.matrix * performer_obj.matrix_world
81             inter_world_base_rotation = inter_bone.bone.matrix_local * inter_obj.matrix_world
82             inter_world_base_inv = inter_world_base_rotation.inverted()
83             return (inter_world_base_inv.to_3x3() * perf_world_rotation.to_3x3()).to_4x4()
84
85     #uses 1to1 and interpolation/averaging to match many to 1 retarget
86     def manyPerfToSingleInterRetarget(inter_bone, performer_bones_s):
87         retarget_matrices = [singleBoneRetarget(inter_bone, perf_bone) for perf_bone in performer_bones_s]
88         lerp_matrix = Matrix()
89         for i in range(len(retarget_matrices) - 1):
90             first_mat = retarget_matrices[i]
91             next_mat = retarget_matrices[i + 1]
92             lerp_matrix = first_mat.lerp(next_mat, 0.5)
93         return lerp_matrix
94
95     #determines the type of hierachy change needed and calls the
96     #right function
97     def retargetPerfToInter(inter_bone):
98         if inter_bone.bone.reverseMap:
99             perf_bone_name = inter_bone.bone.reverseMap
100                 # 1 to many not supported yet
101                 # then its either a many to 1 or 1 to 1
102             if len(perf_bone_name) > 1:
103                 performer_bones_s = [performer_bones[map.name] for map in perf_bone_name]
104                 #we need to map several performance bone to a single
105                 inter_bone.matrix_basis = manyPerfToSingleInterRetarget(inter_bone, performer_bones_s)
106             else:
107                 perf_bone = performer_bones[perf_bone_name[0].name]
108                 inter_bone.matrix_basis = singleBoneRetarget(inter_bone, perf_bone)
109         inter_bone.keyframe_insert("rotation_quaternion")
110
111     #creates the intermediate armature object
112     inter_obj = enduser_obj.copy()
113     inter_obj.data = inter_obj.data.copy()  # duplicate data
114     bpy.context.scene.objects.link(inter_obj)
115     inter_obj.name = "intermediate"
116     bpy.context.scene.objects.active = inter_obj
117     bpy.ops.object.mode_set(mode='EDIT')
118     #add some temporary connecting bones in case end user bones are not connected to their parents
119     print("creating temp bones")
120     for bone in inter_obj.data.edit_bones:
121         if not bone.use_connect and bone.parent:
122             if inter_obj.data.bones[bone.parent.name].reverseMap or inter_obj.data.bones[bone.name].reverseMap:
123                 newBone = inter_obj.data.edit_bones.new("Temp")
124                 newBone.head = bone.parent.tail
125                 newBone.tail = bone.head
126                 newBone.parent = bone.parent
127                 bone.parent = newBone
128                 bone.use_connect = True
129                 newBone.use_connect = True
130     #resets roll
131     print("retargeting to intermediate")
132     bpy.ops.armature.calculate_roll(type='Z')
133     bpy.ops.object.mode_set(mode="OBJECT")
134     inter_obj.data.name = "inter_arm"
135     inter_arm = inter_obj.data
136     performer_bones = performer_obj.pose.bones
137     inter_bones = inter_obj.pose.bones
138     #clears inheritance
139     for inter_bone in inter_bones:
140         if inter_bone.bone.reverseMap:
141             inter_bone.bone.use_inherit_rotation = False
142         else:
143             inter_bone.bone.use_inherit_rotation = True
144
145     for t in range(s_frame, e_frame):
146         if (t - s_frame) % 10 == 0:
147             print("First pass: retargeting frame {0}/{1}".format(t, e_frame - s_frame))
148         scene.frame_set(t)
149         for bone in inter_bones:
150             retargetPerfToInter(bone)
151
152     return inter_obj
153
154 # this procedure copies the rotations over from the intermediate
155 # armature to the end user one.
156 # As the hierarchies are 1 to 1, this is a simple matter of
157 # copying the rotation, while keeping in mind bone roll, parenting, etc.
158 # TODO: Control Bones: If a certain bone is constrained in a way
159 #       that its rotation is determined by another (a control bone)
160 #       We should determine the right pos of the control bone.
161 #       Scale: ? Should work but needs testing.
162
163
164 def retargetEnduser(inter_obj, enduser_obj, root, s_frame, e_frame, scene):
165     inter_bones = inter_obj.pose.bones
166     end_bones = enduser_obj.pose.bones
167
168     def bakeTransform(end_bone):
169         src_bone = inter_bones[end_bone.name]
170         trg_bone = end_bone
171         bake_matrix = src_bone.matrix
172         rest_matrix = trg_bone.bone.matrix_local
173
174         if trg_bone.parent and trg_bone.bone.use_inherit_rotation:
175             srcParent = src_bone.parent
176             if "Temp" in srcParent.name:
177                 srcParent = srcParent.parent
178             parent_mat = srcParent.matrix
179             parent_rest = trg_bone.parent.bone.matrix_local
180             parent_rest_inv = parent_rest.inverted()
181             parent_mat_inv = parent_mat.inverted()
182             bake_matrix = parent_mat_inv * bake_matrix
183             rest_matrix = parent_rest_inv * rest_matrix
184
185         rest_matrix_inv = rest_matrix.inverted()
186         bake_matrix = rest_matrix_inv * bake_matrix
187         end_bone.matrix_basis = bake_matrix
188         rot_mode = end_bone.rotation_mode
189         if rot_mode == "QUATERNION":
190             end_bone.keyframe_insert("rotation_quaternion")
191         elif rot_mode == "AXIS_ANGLE":
192             end_bone.keyframe_insert("rotation_axis_angle")
193         else:
194             end_bone.keyframe_insert("rotation_euler")
195         if not end_bone.bone.use_connect:
196             end_bone.keyframe_insert("location")
197
198         for bone in end_bone.children:
199             bakeTransform(bone)
200
201     for t in range(s_frame, e_frame):
202         if (t - s_frame) % 10 == 0:
203             print("Second pass: retargeting frame {0}/{1}".format(t, e_frame - s_frame))
204         scene.frame_set(t)
205         end_bone = end_bones[root]
206         end_bone.location = Vector((0, 0, 0))
207         end_bone.keyframe_insert("location")
208         bakeTransform(end_bone)
209
210 #recieves the performer feet bones as a variable
211 # by "feet" I mean those bones that have plants
212 # (they don't move, despite root moving) somewhere in the animation.
213
214
215 def copyTranslation(performer_obj, enduser_obj, perfFeet, root, s_frame, e_frame, scene, enduser_obj_mat):
216
217     perf_bones = performer_obj.pose.bones
218     end_bones = enduser_obj.pose.bones
219
220     perfRoot = perf_bones[0].name
221     endFeet = [perf_bones[perfBone].bone.map for perfBone in perfFeet]
222     locDictKeys = perfFeet + endFeet + [perfRoot]
223
224     def tailLoc(bone):
225         return bone.center + (bone.vector / 2)
226
227     #Step 1 - we create a dict that contains these keys:
228     #(Performer) Hips, Feet
229     #(End user) Feet
230     # where the values are their world position on each frame in range (s,e)
231
232     locDict = {}
233     for key in locDictKeys:
234         locDict[key] = []
235
236     for t in range(scene.frame_start, scene.frame_end):
237         scene.frame_set(t)
238         for bone in perfFeet:
239             locDict[bone].append(tailLoc(perf_bones[bone]))
240         locDict[perfRoot].append(tailLoc(perf_bones[perfRoot]))
241         for bone in endFeet:
242             locDict[bone].append(tailLoc(end_bones[bone]))
243
244     # now we take our locDict and analyze it.
245     # we need to derive all chains
246     
247     def locDeriv(key, t):
248         graph = locDict[key]
249         return graph[t + 1] - graph[t]
250
251     #~ locDeriv = {}
252     #~ for key in locDictKeys:
253         #~ locDeriv[key] = []
254
255     #~ for key in locDict.keys():
256         #~ graph = locDict[key]
257         #~ locDeriv[key] = [graph[t + 1] - graph[t] for t in range(len(graph) - 1)]
258
259     # now find the plant frames, where perfFeet don't move much
260
261     linearAvg = []
262
263     for key in perfFeet:
264         for i in range(len(locDict[key]) - 1):
265             v = locDeriv(key,i)
266             if (v.length < 0.1):
267                 hipV = locDeriv(perfRoot,i)
268                 endV = locDeriv(perf_bones[key].bone.map,i)
269                 #this is a plant frame.
270                 #lets see what the original hip delta is, and the corresponding
271                 #end bone's delta
272                 if endV.length != 0:
273                     linearAvg.append(hipV.length / endV.length)
274
275     action_name = performer_obj.animation_data.action.name
276     #is there a stride_bone?
277     if "stride_bone" in bpy.data.objects:
278         stride_action = bpy.data.actions.new("Stride Bone " + action_name)
279         stride_action.use_fake_user = True
280         stride_bone = enduser_obj.parent
281         stride_bone.animation_data.action = stride_action
282     else:
283         bpy.ops.object.add()
284         stride_bone = bpy.context.active_object
285         stride_bone.name = "stride_bone"
286     print(stride_bone)
287     stride_bone.location = Vector((0, 0, 0))
288     print(linearAvg)
289     if linearAvg:
290         #determine the average change in scale needed
291         avg = sum(linearAvg) / len(linearAvg)
292         scene.frame_set(s_frame)
293         initialPos = (tailLoc(perf_bones[perfRoot]) / avg) + stride_bone.location
294         for t in range(s_frame, e_frame):
295             scene.frame_set(t)
296             #calculate the new position, by dividing by the found ratio between performer and enduser
297             newTranslation = (tailLoc(perf_bones[perfRoot]) / avg)
298             stride_bone.location = enduser_obj_mat * (newTranslation - initialPos)
299             stride_bone.keyframe_insert("location")
300     else:
301         stride_bone.keyframe_insert("location")
302     stride_bone.animation_data.action.name = ("Stride Bone " + action_name)
303
304     return stride_bone
305
306
307 def IKRetarget(performer_obj, enduser_obj, s_frame, e_frame, scene):
308     bpy.ops.object.select_name(name=enduser_obj.name, extend=False)
309     end_bones = enduser_obj.pose.bones
310     for pose_bone in end_bones:
311         ik_constraint = hasIKConstraint(pose_bone)
312         if ik_constraint:
313             target_is_bone = False
314             # set constraint target to corresponding empty if targetless,
315             # if not, keyframe current target to corresponding empty
316             perf_bone = pose_bone.bone.reverseMap[-1].name
317             bpy.ops.object.mode_set(mode='EDIT')
318             orgLocTrg = originalLocationTarget(pose_bone, enduser_obj)
319             bpy.ops.object.mode_set(mode='OBJECT')
320             if not ik_constraint.target:
321                 ik_constraint.target = enduser_obj
322                 ik_constraint.subtarget = pose_bone.name+"IK"
323                 target = orgLocTrg
324
325             # There is a target now
326             if ik_constraint.subtarget:
327                 target = ik_constraint.target.pose.bones[ik_constraint.subtarget]
328                 target.bone.use_local_location = False
329                 target_is_bone = True
330             else:
331                 target = ik_constraint.target
332
333             # bake the correct locations for the ik target bones
334             for t in range(s_frame, e_frame):
335                 scene.frame_set(t)
336                 if target_is_bone:
337                     final_loc = pose_bone.tail - target.bone.matrix_local.to_translation()
338                 else:
339                     final_loc = pose_bone.tail
340                 target.location = final_loc
341                 target.keyframe_insert("location")
342             ik_constraint.mute = False
343     scene.frame_set(s_frame)
344     bpy.ops.object.mode_set(mode='OBJECT')
345
346
347 def turnOffIK(enduser_obj):
348     end_bones = enduser_obj.pose.bones
349     for pose_bone in end_bones:
350         if pose_bone.is_in_ik_chain:
351             pass
352             # TODO:
353             # set stiffness according to place on chain
354             # and values from analysis that is stored in the bone
355             #pose_bone.ik_stiffness_x = 0.5
356             #pose_bone.ik_stiffness_y = 0.5
357             #pose_bone.ik_stiffness_z = 0.5
358         ik_constraint = hasIKConstraint(pose_bone)
359         if ik_constraint:
360             ik_constraint.mute = True
361
362
363 #copy the object matrixes and clear them (to be reinserted later)
364 def cleanAndStoreObjMat(performer_obj, enduser_obj):
365     perf_obj_mat = performer_obj.matrix_world.copy()
366     enduser_obj_mat = enduser_obj.matrix_world.copy()
367     zero_mat = Matrix()
368     performer_obj.matrix_world = zero_mat
369     enduser_obj.matrix_world = zero_mat
370     return perf_obj_mat, enduser_obj_mat
371
372
373 #restore the object matrixes after parenting the auto generated IK empties
374 def restoreObjMat(performer_obj, enduser_obj, perf_obj_mat, enduser_obj_mat, stride_bone):
375     pose_bones = enduser_obj.pose.bones
376     for pose_bone in pose_bones:
377         if pose_bone.name + "Org" in bpy.data.objects:
378             empty = bpy.data.objects[pose_bone.name + "Org"]
379             empty.parent = stride_bone
380     performer_obj.matrix_world = perf_obj_mat
381     enduser_obj.parent = stride_bone
382     enduser_obj.matrix_world = enduser_obj_mat
383
384
385 #create (or return if exists) the related IK empty to the bone
386 def originalLocationTarget(end_bone, enduser_obj):
387     if not end_bone.name + "IK" in enduser_obj.data.bones:
388         newBone = enduser_obj.data.edit_bones.new(end_bone.name + "IK")
389         newBone.head = end_bone.tail
390         newBone.tail = end_bone.tail + Vector((0,0.1,0))
391         #~ empty = bpy.context.active_object
392         #~ empty.name = end_bone.name + "Org"
393         #~ empty.empty_draw_size = 0.1
394         #~ empty.parent = enduser_obj
395     else:
396         newBone = enduser_obj.pose.bones[end_bone.name + "IK"]
397     return newBone
398
399
400 #create the specified NLA setup for base animation, constraints and tweak layer.
401 def NLASystemInitialize(enduser_arm, context):#enduser_obj, name):
402     enduser_obj = context.active_object
403     NLATracks = enduser_arm.mocapNLATracks[enduser_obj.data.active_mocap]
404     name = NLATracks.name
405     anim_data = enduser_obj.animation_data
406     s_frame = 0
407     print(name)
408     if ("Base " + name) in bpy.data.actions:
409         mocapAction = bpy.data.actions[("Base " + name)]
410     else:
411         print("That retargeted anim has no base action")
412     anim_data.use_nla = True
413     for track in anim_data.nla_tracks:
414         anim_data.nla_tracks.remove(track)
415     mocapTrack = anim_data.nla_tracks.new()
416     mocapTrack.name = "Base " + name
417     NLATracks.base_track = mocapTrack.name
418     mocapStrip = mocapTrack.strips.new("Base " + name, s_frame, mocapAction)
419     constraintTrack = anim_data.nla_tracks.new()
420     constraintTrack.name = "Auto fixes " + name
421     NLATracks.auto_fix_track = constraintTrack.name
422     if ("Auto fixes " + name) in bpy.data.actions:
423         constraintAction = bpy.data.actions[("Auto fixes " + name)]
424     else:
425         constraintAction = bpy.data.actions.new("Auto fixes " + name)
426         constraintAction.use_fake_user = True
427     constraintStrip = constraintTrack.strips.new("Auto fixes " + name, s_frame, constraintAction)
428     constraintStrip.extrapolation = "NOTHING"
429     userTrack = anim_data.nla_tracks.new()
430     userTrack.name = "Manual fixes " + name
431     NLATracks.manual_fix_track = userTrack.name
432     if ("Manual fixes " + name) in bpy.data.actions:
433         userAction = bpy.data.actions[("Manual fixes " + name)]
434     else:
435         userAction = bpy.data.actions.new("Manual fixes " + name)
436         userAction.use_fake_user = True
437     userStrip = userTrack.strips.new("Manual fixes " + name, s_frame, userAction)
438     userStrip.extrapolation = "HOLD"
439     #userStrip.blend_type = "MULITPLY" - doesn't work due to work, will be activated soon
440     anim_data.nla_tracks.active = constraintTrack
441     #anim_data.action = constraintAction
442     anim_data.action_extrapolation = "NOTHING"
443     #set the stride_bone's action
444     if "stride_bone" in bpy.data.objects:
445         stride_bone = bpy.data.objects["stride_bone"]
446         if NLATracks.stride_action:
447             stride_bone.animation_data.action = bpy.data.actions[NLATracks.stride_action]
448         else:
449             NLATracks.stride_action = stride_bone.animation_data.action.name
450             stride_bone.animation_data.action.use_fake_user = True
451     anim_data.action = None
452
453
454 def preAdvancedRetargeting(performer_obj, enduser_obj):
455     createDictionary(performer_obj.data, enduser_obj.data)
456     bones = enduser_obj.pose.bones
457     map_bones = [bone for bone in bones if bone.bone.reverseMap]
458     for bone in map_bones:
459         perf_bone = bone.bone.reverseMap[0].name
460         addLocalRot = False;
461         if bone.bone.use_connect or not bone.constraints:
462             locks = bone.lock_location
463             if not (locks[0] or locks[1] or locks[2]):  
464                 cons = bone.constraints.new('COPY_LOCATION')
465                 cons.name = "retargetTemp"
466                 cons.use_x = not locks[0]
467                 cons.use_y = not locks[1]
468                 cons.use_z = not locks[2]
469                 cons.target = performer_obj
470                 cons.subtarget = perf_bone
471                 addLocalRot = True
472
473        
474         cons2 = bone.constraints.new('COPY_ROTATION')
475         cons2.name = "retargetTemp"
476         locks = bone.lock_rotation
477         cons2.use_x = not locks[0]
478         cons2.use_y = not locks[1]
479         cons2.use_z = not locks[2]
480         cons2.target = performer_obj
481         cons2.subtarget = perf_bone
482
483         if addLocalRot:
484             for constraint in bone.constraints:
485                 if constraint.type == 'COPY_ROTATION':
486                     constraint.target_space = 'LOCAL'
487                     constraint.owner_space = 'LOCAL_WITH_PARENT'
488
489
490 def prepareForBake(enduser_obj):
491     bones = enduser_obj.pose.bones
492     for bone in bones:
493         bone.bone.select = False
494     map_bones = [bone for bone in bones if bone.bone.reverseMap]
495     for bone in map_bones:
496         for cons in bone.constraints:
497             if "retargetTemp" in cons.name:
498                 bone.bone.select = True
499
500 def cleanTempConstraints(enduser_obj):
501     bones = enduser_obj.pose.bones
502     map_bones = [bone for bone in bones if bone.bone.reverseMap]
503     for bone in map_bones:
504         for cons in bone.constraints:
505             if "retargetTemp" in cons.name:
506                 bone.constraints.remove(cons)
507
508 #Main function that runs the retargeting sequence.
509 #If advanced == True, we assume constraint's were already created
510 def totalRetarget(performer_obj, enduser_obj, scene, s_frame, e_frame):
511     perf_arm = performer_obj.data
512     end_arm = enduser_obj.data
513     advanced = end_arm.advancedRetarget
514     
515     try:
516         enduser_obj.animation_data.action = bpy.data.actions.new("temp")
517         enduser_obj.animation_data.action.use_fake_user = True
518     except:
519         print("no need to create new action")
520     
521     print("creating Dictionary")
522     feetBones, root = createDictionary(perf_arm, end_arm)
523     print("cleaning stuff up")
524     perf_obj_mat, enduser_obj_mat = cleanAndStoreObjMat(performer_obj, enduser_obj)
525     if not advanced:
526         turnOffIK(enduser_obj)
527         print("Creating intermediate armature (for first pass)")
528         inter_obj = createIntermediate(performer_obj, enduser_obj, root, s_frame, e_frame, scene)
529         print("First pass: retargeting from intermediate to end user")
530         retargetEnduser(inter_obj, enduser_obj, root, s_frame, e_frame, scene)
531     else:
532         prepareForBake(enduser_obj)
533         print("Retargeting pose (Advanced Retarget)")
534         nla.bake(s_frame, e_frame, action=enduser_obj.animation_data.action, only_selected=True, do_pose=True, do_object=False)
535     name = performer_obj.animation_data.action.name
536     enduser_obj.animation_data.action.name = "Base " + name
537     print("Second pass: retargeting root translation and clean up")
538     stride_bone = copyTranslation(performer_obj, enduser_obj, feetBones, root, s_frame, e_frame, scene, enduser_obj_mat)
539     if not advanced:
540         IKRetarget(performer_obj, enduser_obj, s_frame, e_frame, scene)
541         bpy.ops.object.select_name(name=stride_bone.name, extend=False)
542     restoreObjMat(performer_obj, enduser_obj, perf_obj_mat, enduser_obj_mat, stride_bone)
543     bpy.ops.object.mode_set(mode='OBJECT')
544     if not advanced:
545         bpy.ops.object.select_name(name=inter_obj.name, extend=False)
546         bpy.ops.object.delete()
547     else:
548         cleanTempConstraints(enduser_obj)
549     bpy.ops.object.select_name(name=enduser_obj.name, extend=False)
550
551     if not name in [tracks.name for tracks in end_arm.mocapNLATracks]:
552         NLATracks = end_arm.mocapNLATracks.add()
553         NLATracks.name = name
554     else:
555         NLATracks = end_arm.mocapNLATracks[name]
556     end_arm.active_mocap = name
557     print("retargeting done!")
558     
559 def profileWrapper():
560     context = bpy.context
561     scene = context.scene
562     s_frame = scene.frame_start
563     e_frame = scene.frame_end
564     enduser_obj = context.active_object
565     performer_obj = [obj for obj in context.selected_objects if obj != enduser_obj]
566     if enduser_obj is None or len(performer_obj) != 1:
567         print("Need active and selected armatures")
568     else:
569         performer_obj = performer_obj[0]
570         s_frame, e_frame = performer_obj.animation_data.action.frame_range
571         s_frame = int(s_frame)
572         e_frame = int(e_frame)
573         totalRetarget(performer_obj, enduser_obj, scene, s_frame, e_frame)
574
575 if __name__ == "__main__":
576     cProfile.run("profileWrapper()")