Esempio n. 1
0
/* Get Keying Set to use for Auto-Keyframing some transforms */
KeyingSet *ANIM_get_keyingset_for_autokeying(Scene *scene, const char *tranformKSName)
{
	/* get KeyingSet to use 
	 *	- use the active KeyingSet if defined (and user wants to use it for all autokeying), 
	 *    or otherwise key transforms only
	 */
	if (IS_AUTOKEY_FLAG(scene, ONLYKEYINGSET) && (scene->active_keyingset))
		return ANIM_scene_get_active_keyingset(scene);
	else if (IS_AUTOKEY_FLAG(scene, INSERTAVAIL))
		return ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_AVAILABLE_ID);
	else 
		return ANIM_builtin_keyingset_get_named(NULL, tranformKSName);
}
Esempio n. 2
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;
}
Esempio n. 3
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);
    }
}
Esempio n. 4
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);
	}
}