Ejemplo n.º 1
0
static int poselib_add_exec (bContext *C, wmOperator *op)
{
	Object *ob= get_poselib_object(C);
	bAction *act = poselib_validate(ob);
	bPose *pose= (ob) ? ob->pose : NULL;
	TimeMarker *marker;
	KeyingSet *ks= ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_WHOLE_CHARACTER_ID); /* this includes custom props :)*/
	int frame= RNA_int_get(op->ptr, "frame");
	char name[64];
	
	/* sanity check (invoke should have checked this anyway) */
	if (ELEM(NULL, ob, pose)) 
		return OPERATOR_CANCELLED;
	
	/* get name to give to pose */
	RNA_string_get(op->ptr, "name", name);
	
	/* add pose to poselib - replaces any existing pose there
	 *	- for the 'replace' option, this should end up finding the appropriate marker,
	 *	  so no new one will be added
	 */
	for (marker= act->markers.first; marker; marker= marker->next) {
		if (marker->frame == frame) {
			BLI_strncpy(marker->name, name, sizeof(marker->name));
			break;
		}
	}
	if (marker == NULL) {
		marker= MEM_callocN(sizeof(TimeMarker), "ActionMarker");
		
		BLI_strncpy(marker->name, name, sizeof(marker->name));
		marker->frame= frame;
		
		BLI_addtail(&act->markers, marker);
	}
	
	/* validate name */
	BLI_uniquename(&act->markers, marker, "Pose", '.', offsetof(TimeMarker, name), sizeof(marker->name));
	
	/* use Keying Set to determine what to store for the pose */
	// FIXME: in the past, the Keying Set respected selections (LocRotScale), but the current one doesn't (Whole Character)
	// so perhaps we need either a new Keying Set, or just to add overrides here...
	ANIM_apply_keyingset(C, NULL, act, ks, MODIFYKEY_MODE_INSERT, (float)frame);
	
	/* store new 'active' pose number */
	act->active_marker= BLI_countlist(&act->markers);
	
	/* done */
	return OPERATOR_FINISHED;
}
Ejemplo n.º 2
0
/* Auto-keys/tags bones affected by the pose used from the poselib */
static void poselib_keytag_pose (bContext *C, Scene *scene, tPoseLib_PreviewData *pld)
{
	bPose *pose= pld->pose;
	bPoseChannel *pchan;
	bAction *act= pld->act;
	bActionGroup *agrp;
	
	KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, ANIM_KS_WHOLE_CHARACTER_ID);
	ListBase dsources = {NULL, NULL};
	short autokey = autokeyframe_cfra_can_key(scene, &pld->ob->id);
	
	/* start tagging/keying */
	for (agrp= act->groups.first; agrp; agrp= agrp->next) {
		/* only for selected bones unless there aren't any selected, in which case all are included  */
		pchan= get_pose_channel(pose, agrp->name);
		
		if (pchan) {
			if ( (pld->selcount == 0) || ((pchan->bone) && (pchan->bone->flag & BONE_SELECTED)) ) {
				if (autokey) {
					/* add datasource override for the PoseChannel, to be used later */
					ANIM_relative_keyingset_add_source(&dsources, &pld->ob->id, &RNA_PoseBone, pchan); 
					
					/* clear any unkeyed tags */
					if (pchan->bone)
						pchan->bone->flag &= ~BONE_UNKEYED;
				}
				else {
					/* add unkeyed tags */
					if (pchan->bone)
						pchan->bone->flag |= BONE_UNKEYED;
				}
			}
		}
	}
	
	/* perform actual auto-keying now */
	if (autokey) {
		/* insert keyframes for all relevant bones in one go */
		ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
		BLI_freelistN(&dsources);
	}
	
	/* send notifiers for this */
	WM_event_add_notifier(C, NC_ANIMATION|ND_KEYFRAME|NA_EDITED, NULL);
}
Ejemplo n.º 3
0
	/* operate on selected objects only if they aren't in weight-paint mode 
	 * (so that object-transform clearing won't be applied at same time as bone-clearing)
	 */
	CTX_DATA_BEGIN(C, Object*, ob, selected_editable_objects) 
	{
		if (!(ob->mode & OB_MODE_WEIGHT_PAINT)) {
			/* run provided clearing function */
			clear_func(ob);
			
			/* auto keyframing */
			if (autokeyframe_cfra_can_key(scene, &ob->id)) {
				ListBase dsources = {NULL, NULL};
				
				/* now insert the keyframe(s) using the Keying Set
				 *	1) add datasource override for the Object
				 *	2) insert keyframes
				 *	3) free the extra info 
				 */
				ANIM_relative_keyingset_add_source(&dsources, &ob->id, NULL, NULL); 
				ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
				BLI_freelistN(&dsources);
			}
			
			/* tag for updates */
			ob->recalc |= OB_RECALC_OB;
		}
	}
Ejemplo n.º 4
0
/**
 * Updates cameras from the ``rv3d`` values, optionally auto-keyframing.
 */
void ED_view3d_cameracontrol_update(
    View3DCameraControl *vctrl,
    /* args for keyframing */
    const bool use_autokey,
    struct bContext *C, const bool do_rotate, const bool do_translate)
{
    /* we are in camera view so apply the view ofs and quat to the view matrix and set the camera to the view */

    Scene *scene       = vctrl->ctx_scene;
    View3D *v3d        = vctrl->ctx_v3d;
    RegionView3D *rv3d = vctrl->ctx_rv3d;

    ID *id_key;

    /* transform the parent or the camera? */
    if (vctrl->root_parent) {
        Object *ob_update;

        float view_mat[4][4];
        float prev_view_imat[4][4];
        float diff_mat[4][4];
        float parent_mat[4][4];

        invert_m4_m4(prev_view_imat, vctrl->view_mat_prev);
        ED_view3d_to_m4(view_mat, rv3d->ofs, rv3d->viewquat, rv3d->dist);
        mul_m4_m4m4(diff_mat, view_mat, prev_view_imat);
        mul_m4_m4m4(parent_mat, diff_mat, vctrl->root_parent->obmat);

        BKE_object_apply_mat4(vctrl->root_parent, parent_mat, true, false);

        ob_update = v3d->camera->parent;
        while (ob_update) {
            DAG_id_tag_update(&ob_update->id, OB_RECALC_OB);
            ob_update = ob_update->parent;
        }

        copy_m4_m4(vctrl->view_mat_prev, view_mat);

        id_key = &vctrl->root_parent->id;
    }
    else {
        float view_mat[4][4];
        float size_mat[4][4];
        float size_back[3];

        /* even though we handle the size matrix, this still changes over time */
        copy_v3_v3(size_back, v3d->camera->size);

        ED_view3d_to_m4(view_mat, rv3d->ofs, rv3d->viewquat, rv3d->dist);
        size_to_mat4(size_mat, v3d->camera->size);
        mul_m4_m4m4(view_mat, view_mat, size_mat);

        BKE_object_apply_mat4(v3d->camera, view_mat, true, true);

        copy_v3_v3(v3d->camera->size, size_back);

        id_key = &v3d->camera->id;
    }

    /* record the motion */
    if (use_autokey && autokeyframe_cfra_can_key(scene, id_key)) {
        ListBase dsources = {NULL, NULL};

        /* add data-source override for the camera object */
        ANIM_relative_keyingset_add_source(&dsources, id_key, NULL, NULL);

        /* insert keyframes
         * 1) on the first frame
         * 2) on each subsequent frame
         *    TODO: need to check in future that frame changed before doing this
         */
        if (do_rotate) {
            struct KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_ROTATION_ID);
            ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
        }
        if (do_translate) {
            struct KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_LOCATION_ID);
            ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
        }

        /* free temp data */
        BLI_freelistN(&dsources);
    }
}
Ejemplo n.º 5
0
static void flyMoveCamera(bContext *C, RegionView3D *rv3d, FlyInfo *fly,
                            const bool do_rotate, const bool do_translate)
{
	/* we are in camera view so apply the view ofs and quat to the view matrix and set the camera to the view */

	View3D *v3d = fly->v3d;
	Scene *scene = fly->scene;
	ID *id_key;

	/* transform the parent or the camera? */
	if (fly->root_parent) {
		Object *ob_update;

		float view_mat[4][4];
		float prev_view_mat[4][4];
		float prev_view_imat[4][4];
		float diff_mat[4][4];
		float parent_mat[4][4];
		float size_mat[4][4];

		ED_view3d_to_m4(prev_view_mat, fly->rv3d->ofs, fly->rv3d->viewquat, fly->rv3d->dist);
		invert_m4_m4(prev_view_imat, prev_view_mat);
		ED_view3d_to_m4(view_mat, rv3d->ofs, rv3d->viewquat, rv3d->dist);
		mult_m4_m4m4(diff_mat, view_mat, prev_view_imat);
		mult_m4_m4m4(parent_mat, diff_mat, fly->root_parent->obmat);

		size_to_mat4(size_mat, fly->root_parent->size);
		mult_m4_m4m4(parent_mat, parent_mat, size_mat);

		BKE_object_apply_mat4(fly->root_parent, parent_mat, true, false);

		// BKE_object_where_is_calc(scene, fly->root_parent);

		ob_update = v3d->camera->parent;
		while (ob_update) {
			DAG_id_tag_update(&ob_update->id, OB_RECALC_OB);
			ob_update = ob_update->parent;
		}

		id_key = &fly->root_parent->id;
	}
	else {
		float view_mat[4][4];
		float size_mat[4][4];

		ED_view3d_to_m4(view_mat, rv3d->ofs, rv3d->viewquat, rv3d->dist);
		size_to_mat4(size_mat, v3d->camera->size);
		mult_m4_m4m4(view_mat, view_mat, size_mat);

		BKE_object_apply_mat4(v3d->camera, view_mat, true, false);

		id_key = &v3d->camera->id;
	}

	/* record the motion */
	if (autokeyframe_cfra_can_key(scene, id_key)) {
		ListBase dsources = {NULL, NULL};

		/* add datasource override for the camera object */
		ANIM_relative_keyingset_add_source(&dsources, id_key, NULL, NULL);

		/* insert keyframes 
		 *	1) on the first frame
		 *	2) on each subsequent frame
		 *		TODO: need to check in future that frame changed before doing this 
		 */
		if (do_rotate) {
			KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_ROTATION_ID);
			ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
		}
		if (do_translate) {
			KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_LOCATION_ID);
			ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
		}

		/* free temp data */
		BLI_freelistN(&dsources);
	}
}