Beispiel #1
0
/* Applies the appropriate stored pose from the pose-library to the current pose
 *	- assumes that a valid object, with a poselib has been supplied
 *	- gets the string to print in the header
 *  - this code is based on the code for extract_pose_from_action in blenkernel/action.c
 */
static void poselib_apply_pose(tPoseLib_PreviewData *pld)
{
	PointerRNA *ptr = &pld->rna_ptr;
	bArmature *arm = pld->arm;
	bPose *pose = pld->pose;
	bPoseChannel *pchan;
	bAction *act = pld->act;
	bActionGroup *agrp;
	
	KeyframeEditData ked = {{NULL}};
	KeyframeEditFunc group_ok_cb;
	int frame = 1;
	
	/* get the frame */
	if (pld->marker)
		frame = pld->marker->frame;
	else
		return;
	
	
	/* init settings for testing groups for keyframes */
	group_ok_cb = ANIM_editkeyframes_ok(BEZT_OK_FRAMERANGE);
	ked.f1 = ((float)frame) - 0.5f;
	ked.f2 = ((float)frame) + 0.5f;
	
	
	/* start applying - only those channels which have a key at this point in time! */
	for (agrp = act->groups.first; agrp; agrp = agrp->next) {
		/* check if group has any keyframes */
		if (ANIM_animchanneldata_keyframes_loop(&ked, NULL, agrp, ALE_GROUP, NULL, group_ok_cb, NULL)) {
			/* has keyframe on this frame, so try to get a PoseChannel with this name */
			pchan = BKE_pose_channel_find_name(pose, agrp->name);
			
			if (pchan) {
				short ok = 0;
				
				/* check if this bone should get any animation applied */
				if (pld->selcount == 0) {
					/* if no bones are selected, then any bone is ok */
					ok = 1;
				}
				else if (pchan->bone) {
					/* only ok if bone is visible and selected */
					if ((pchan->bone->flag & BONE_SELECTED) &&
					    (pchan->bone->flag & BONE_HIDDEN_P) == 0 &&
					    (pchan->bone->layer & arm->layer))
					{
						ok = 1;
					}
				}
				
				if (ok) 
					animsys_evaluate_action_group(ptr, act, agrp, NULL, (float)frame);
			}
		}
	}
}
Beispiel #2
0
/* For the calculation of the effects of an Action at the given frame on an object 
 * This is currently only used for the Action Constraint 
 */
void what_does_obaction (Object *ob, Object *workob, bPose *pose, bAction *act, char groupname[], float cframe)
{
	bActionGroup *agrp= action_groups_find_named(act, groupname);
	
	/* clear workob */
	clear_workob(workob);
	
	/* init workob */
	copy_m4_m4(workob->obmat, ob->obmat);
	copy_m4_m4(workob->parentinv, ob->parentinv);
	copy_m4_m4(workob->constinv, ob->constinv);
	workob->parent= ob->parent;
	
	workob->rotmode= ob->rotmode;
	
	workob->trackflag= ob->trackflag;
	workob->upflag= ob->upflag;
	
	workob->partype= ob->partype;
	workob->par1= ob->par1;
	workob->par2= ob->par2;
	workob->par3= ob->par3;

	workob->constraints.first = ob->constraints.first;
	workob->constraints.last = ob->constraints.last;
	
	workob->pose= pose;	/* need to set pose too, since this is used for both types of Action Constraint */

	BLI_strncpy(workob->parsubstr, ob->parsubstr, sizeof(workob->parsubstr));
	BLI_strncpy(workob->id.name, "OB<ConstrWorkOb>", sizeof(workob->id.name)); /* we don't use real object name, otherwise RNA screws with the real thing */
	
	/* if we're given a group to use, it's likely to be more efficient (though a bit more dangerous) */
	if (agrp) {
		/* specifically evaluate this group only */
		PointerRNA id_ptr;
		
		/* get RNA-pointer for the workob's ID */
		RNA_id_pointer_create(&workob->id, &id_ptr);
		
		/* execute action for this group only */
		animsys_evaluate_action_group(&id_ptr, act, agrp, NULL, cframe);
	}
	else {
		AnimData adt= {NULL};
		
		/* init animdata, and attach to workob */
		workob->adt= &adt;
		
		adt.recalc= ADT_RECALC_ANIM;
		adt.action= act;
		
		/* execute effects of Action on to workob (or it's PoseChannels) */
		BKE_animsys_evaluate_animdata(NULL, &workob->id, &adt, cframe, ADT_RECALC_ANIM);
	}
}
Beispiel #3
0
/* For the calculation of the effects of an Action at the given frame on an object 
 * This is currently only used for the Action Constraint 
 */
void what_does_obaction(Object *ob, Object *workob, bPose *pose, bAction *act, char groupname[], float cframe)
{
	bActionGroup *agrp = BKE_action_group_find_name(act, groupname);
	
	/* clear workob */
	BKE_object_workob_clear(workob);
	
	/* init workob */
	copy_m4_m4(workob->obmat, ob->obmat);
	copy_m4_m4(workob->parentinv, ob->parentinv);
	copy_m4_m4(workob->constinv, ob->constinv);
	workob->parent = ob->parent;
	
	workob->rotmode = ob->rotmode;
	
	workob->trackflag = ob->trackflag;
	workob->upflag = ob->upflag;
	
	workob->partype = ob->partype;
	workob->par1 = ob->par1;
	workob->par2 = ob->par2;
	workob->par3 = ob->par3;

	workob->constraints.first = ob->constraints.first;
	workob->constraints.last = ob->constraints.last;
	
	workob->pose = pose; /* need to set pose too, since this is used for both types of Action Constraint */
	if (pose) {
		/* This function is most likely to be used with a temporary pose with a single bone in there.
		 * For such cases it makes no sense to create hash since it'll only waste CPU ticks on memory
		 * allocation and also will make lookup slower.
		 */
		if (pose->chanbase.first != pose->chanbase.last) {
			BKE_pose_channels_hash_make(pose);
		}
		if (pose->flag & POSE_CONSTRAINTS_NEED_UPDATE_FLAGS) {
			BKE_pose_update_constraint_flags(pose);
		}
	}

	BLI_strncpy(workob->parsubstr, ob->parsubstr, sizeof(workob->parsubstr));
	BLI_strncpy(workob->id.name, "OB<ConstrWorkOb>", sizeof(workob->id.name)); /* we don't use real object name, otherwise RNA screws with the real thing */
	
	/* if we're given a group to use, it's likely to be more efficient (though a bit more dangerous) */
	if (agrp) {
		/* specifically evaluate this group only */
		PointerRNA id_ptr;
		
		/* get RNA-pointer for the workob's ID */
		RNA_id_pointer_create(&workob->id, &id_ptr);
		
		/* execute action for this group only */
		animsys_evaluate_action_group(&id_ptr, act, agrp, NULL, cframe);
	}
	else {
		AnimData adt = {NULL};
		
		/* init animdata, and attach to workob */
		workob->adt = &adt;
		
		adt.recalc = ADT_RECALC_ANIM;
		adt.action = act;
		
		/* execute effects of Action on to workob (or it's PoseChannels) */
		BKE_animsys_evaluate_animdata(NULL, &workob->id, &adt, cframe, ADT_RECALC_ANIM);
	}
}