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 enduser_obj.animation_data_create() 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)") bake_action(s_frame, e_frame, action=enduser_obj.animation_data.action, only_selected=True, do_pose=True, do_object=False, frame_step=step) name = performer_obj.animation_data.action.name[:10] #We trim the name down to 10 chars because of Action Name length maximum 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: print("hry") bpy.ops.object.select_all(action='DESELECT') bpy.context.scene.objects.active = enduser_obj bpy.ops.object.select_pattern(pattern=enduser_obj.name, extend=False) IKRetarget(performer_obj, enduser_obj, s_frame, e_frame, scene, step) bpy.ops.object.select_pattern(pattern=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_pattern(pattern=inter_obj.name, extend=False) bpy.ops.object.delete() else: cleanTempConstraints(enduser_obj) bpy.ops.object.select_pattern(pattern=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 anim_utils.bake_action( obj, 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)
def execute(self, context): from bpy_extras import anim_utils action = None if self.use_current_action: obj = context.object if obj.animation_data: action = obj.animation_data.action action = anim_utils.bake_action( self.frame_start, self.frame_end, frame_step=self.step, only_selected=self.only_selected, do_pose="POSE" in self.bake_types, do_object="OBJECT" in self.bake_types, do_visual_keying=self.visual_keying, do_constraint_clear=self.clear_constraints, do_parents_clear=self.clear_parents, do_clean=True, action=action, ) if action is None: self.report({"INFO"}, "Nothing to bake") return {"CANCELLED"} return {"FINISHED"}
def execute(self, context): from bpy_extras import anim_utils action = None if self.use_current_action: obj = context.object if obj.animation_data: action = obj.animation_data.action action = anim_utils.bake_action( self.frame_start, self.frame_end, frame_step=self.step, only_selected=self.only_selected, do_pose='POSE' in self.bake_types, do_object='OBJECT' in self.bake_types, do_visual_keying=self.visual_keying, do_constraint_clear=self.clear_constraints, do_parents_clear=self.clear_parents, do_clean=True, action=action, ) if action is None: self.report({'INFO'}, "Nothing to bake") return {'CANCELLED'} return {'FINISHED'}
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 anim_utils.bake_action( obj, 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)
def process_action_bpy(self, action): print("processing action " + action.name) new_name = action.name + BAKED_SUFFIX actions = bpy.data.actions new_action = actions.get(new_name) if new_action: # reuse old action (segfault when deleting actions) fcurves = new_action.fcurves groups = new_action.groups for fcurve in fcurves: fcurves.remove(fcurve) for group in groups: groups.remove(group) else: # create new action new_action = actions.new(new_name) # save it new_action.use_fake_user = True frame_range = action.frame_range from bpy_extras import anim_utils anim_utils.bake_action( round(frame_range[0]), round(frame_range[1]) + 1, frame_step=1, only_selected=False, do_pose=True, do_object=False, do_visual_keying=True, do_constraint_clear=False, do_parents_clear=False, do_clean=True, action=new_action, )
def process_action_bpy(self, action): print("processing action " + action.name) new_name = action.name + BAKED_SUFFIX actions = bpy.data.actions new_action = actions.get(new_name) if new_action: # reuse old action (segfault when deleting actions) fcurves = new_action.fcurves groups = new_action.groups for fcurve in fcurves: fcurves.remove(fcurve) for group in groups: groups.remove(group) else: # create new action new_action = actions.new(new_name) # save it new_action.use_fake_user = True frame_range = action.frame_range from bpy_extras import anim_utils anim_utils.bake_action(round(frame_range[0]), round(frame_range[1]) + 1, frame_step=1, only_selected=False, do_pose=True, do_object=False, do_visual_keying=True, do_constraint_clear=False, do_parents_clear=False, do_clean=True, action = new_action )
def execute(self, context): from bpy_extras import anim_utils action = anim_utils.bake_action(self.frame_start, self.frame_end, frame_step=self.step, only_selected=self.only_selected, do_pose='POSE' in self.bake_types, do_object='OBJECT' in self.bake_types, do_constraint_clear=self.clear_constraints, do_clean=True, ) if action is None: self.report({'INFO'}, "Nothing to bake") return {'CANCELLED'} return {'FINISHED'}
def execute(self, context): from bpy_extras import anim_utils action = anim_utils.bake_action(self.frame_start, self.frame_end, self.step, self.only_selected, 'POSE' in self.bake_types, 'OBJECT' in self.bake_types, self.clear_consraints, True, ) if action is None: self.report({'INFO'}, "Nothing to bake") return {'CANCELLED'} return {'FINISHED'}
def execute(self, context): from bpy_extras import anim_utils action = anim_utils.bake_action(self.frame_start, self.frame_end, frame_step=self.step, only_selected=self.only_selected, do_pose='POSE' in self.bake_types, do_object='OBJECT' in self.bake_types, do_constraint_clear=self.clear_constraints, do_parents_clear=self.clear_parents, do_clean=True, ) if action is None: self.report({'INFO'}, "Nothing to bake") return {'CANCELLED'} return {'FINISHED'}
def execute(self, context): from bpy_extras import anim_utils action = anim_utils.bake_action( self.frame_start, self.frame_end, self.step, self.only_selected, "POSE" in self.bake_types, "OBJECT" in self.bake_types, self.clear_consraints, True, ) if action is None: self.report({"INFO"}, "Nothing to bake") return {"CANCELLED"} return {"FINISHED"}