def totalRetarget(performer_obj, enduser_obj, scene, s_frame, e_frame): perf_arm = performer_obj.data end_arm = enduser_obj.data advanced = end_arm.advancedRetarget step = end_arm.frameStep try: enduser_obj.animation_data.action = bpy.data.actions.new("temp") enduser_obj.animation_data.action.use_fake_user = True except: print("no need to create new action") print("creating Dictionary") feetBones, root = createDictionary(perf_arm, end_arm) print("cleaning stuff up") perf_obj_mat, enduser_obj_mat = cleanAndStoreObjMat(performer_obj, enduser_obj) if not advanced: turnOffIK(enduser_obj) print("Creating intermediate armature (for first pass)") inter_obj = createIntermediate(performer_obj, enduser_obj, root, s_frame, e_frame, scene, step) print("First pass: retargeting from intermediate to end user") retargetEnduser(inter_obj, enduser_obj, root, s_frame, e_frame, scene, step) else: prepareForBake(enduser_obj) print("Retargeting pose (Advanced Retarget)") nla.bake(s_frame, e_frame, action=enduser_obj.animation_data.action, only_selected=True, do_pose=True, do_object=False, step=step) name = performer_obj.animation_data.action.name enduser_obj.animation_data.action.name = "Base " + name print("Second pass: retargeting root translation and clean up") stride_bone = copyTranslation(performer_obj, enduser_obj, feetBones, root, s_frame, e_frame, scene, enduser_obj_mat) if not advanced: IKRetarget(performer_obj, enduser_obj, s_frame, e_frame, scene, step) bpy.ops.object.select_name(name=stride_bone.name, extend=False) restoreObjMat(performer_obj, enduser_obj, perf_obj_mat, enduser_obj_mat, stride_bone, scene, s_frame) bpy.ops.object.mode_set(mode='OBJECT') if not advanced: bpy.ops.object.select_name(name=inter_obj.name, extend=False) bpy.ops.object.delete() else: cleanTempConstraints(enduser_obj) bpy.ops.object.select_name(name=enduser_obj.name, extend=False) if not name in [tracks.name for tracks in end_arm.mocapNLATracks]: NLATracks = end_arm.mocapNLATracks.add() NLATracks.name = name else: NLATracks = end_arm.mocapNLATracks[name] end_arm.active_mocap = name print("retargeting done!")
def bakeAllConstraints(obj, s_frame, e_frame, bones): for bone in bones: bone.bone.select = False selectedBones = [] # Marks bones that need a full bake simpleBake = [] # Marks bones that need only a location bake for end_bone in bones: if end_bone.name in [m_constraint.real_constraint_bone for m_constraint in obj.data.mocap_constraints]: #For all bones that have a constraint: ik = retarget.hasIKConstraint(end_bone) cons_obj = getConsObj(end_bone) if ik: #If it's an auto generated IK: if ik.chain_count == 0: selectedBones += bones # Chain len 0, bake everything else: selectedBones += [end_bone] + end_bone.parent_recursive[:ik.chain_count - 1] # Bake the chain else: #It's either an FK bone which we should just bake #OR a user created IK target bone simpleBake += [end_bone] for bone in selectedBones: bone.bone.select = True NLATracks = obj.data.mocapNLATracks[obj.data.active_mocap] obj.animation_data.action = bpy.data.actions[NLATracks.auto_fix_track] constraintTrack = obj.animation_data.nla_tracks[NLATracks.auto_fix_track] constraintStrip = constraintTrack.strips[0] constraintStrip.action_frame_start = s_frame constraintStrip.action_frame_end = e_frame constraintStrip.frame_start = s_frame constraintStrip.frame_end = e_frame if selectedBones: #Use bake function from NLA Bake Action operator nla.bake(s_frame, e_frame, action=constraintStrip.action, only_selected=True, do_pose=True, do_object=False) if simpleBake: #Do a "simple" bake, location only, world space only. locBake(s_frame, e_frame, simpleBake)