From 3bf2715039eecee409d3b6c3639e853b6750e77c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 19 Feb 2010 15:34:26 +0000 Subject: apply visual transform to pose So constrainted bones can have their transform applied to their loc/scale/rot, then remove the constraints --- source/blender/editors/armature/armature_intern.h | 3 +- source/blender/editors/armature/armature_ops.c | 9 ++-- source/blender/editors/armature/editarmature.c | 62 ++++++++++++++++++++++- 3 files changed, 67 insertions(+), 7 deletions(-) (limited to 'source/blender/editors') diff --git a/source/blender/editors/armature/armature_intern.h b/source/blender/editors/armature/armature_intern.h index 04c113db3be..9d0db52d007 100644 --- a/source/blender/editors/armature/armature_intern.h +++ b/source/blender/editors/armature/armature_intern.h @@ -84,7 +84,8 @@ void ARMATURE_OT_bone_layers(struct wmOperatorType *ot); void POSE_OT_hide(struct wmOperatorType *ot); void POSE_OT_reveal(struct wmOperatorType *ot); -void POSE_OT_apply(struct wmOperatorType *ot); +void POSE_OT_armature_apply(struct wmOperatorType *ot); +void POSE_OT_visual_transform_apply(struct wmOperatorType *ot); void POSE_OT_rot_clear(struct wmOperatorType *ot); void POSE_OT_loc_clear(struct wmOperatorType *ot); diff --git a/source/blender/editors/armature/armature_ops.c b/source/blender/editors/armature/armature_ops.c index 9c1812fb61b..ba2c6597e43 100644 --- a/source/blender/editors/armature/armature_ops.c +++ b/source/blender/editors/armature/armature_ops.c @@ -111,7 +111,8 @@ void ED_operatortypes_armature(void) WM_operatortype_append(POSE_OT_hide); WM_operatortype_append(POSE_OT_reveal); - WM_operatortype_append(POSE_OT_apply); + WM_operatortype_append(POSE_OT_armature_apply); + WM_operatortype_append(POSE_OT_visual_transform_apply); WM_operatortype_append(POSE_OT_rot_clear); WM_operatortype_append(POSE_OT_loc_clear); @@ -285,9 +286,9 @@ void ED_keymap_armature(wmKeyConfig *keyconf) kmi= WM_keymap_add_item(keymap, "POSE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0); RNA_boolean_set(kmi->ptr, "unselected", 1); WM_keymap_add_item(keymap, "POSE_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0); - - WM_keymap_add_item(keymap, "POSE_OT_apply", AKEY, KM_PRESS, KM_CTRL, 0); - + + WM_keymap_add_menu(keymap, "VIEW3D_MT_pose_apply", AKEY, KM_PRESS, KM_CTRL, 0); + // TODO: clear pose WM_keymap_add_item(keymap, "POSE_OT_rot_clear", RKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "POSE_OT_loc_clear", GKEY, KM_PRESS, KM_ALT, 0); diff --git a/source/blender/editors/armature/editarmature.c b/source/blender/editors/armature/editarmature.c index 1db6a4b4112..4a3ef38daa6 100644 --- a/source/blender/editors/armature/editarmature.c +++ b/source/blender/editors/armature/editarmature.c @@ -637,11 +637,11 @@ static int apply_armature_pose2bones_exec (bContext *C, wmOperator *op) return OPERATOR_FINISHED; } -void POSE_OT_apply (wmOperatorType *ot) +void POSE_OT_armature_apply (wmOperatorType *ot) { /* identifiers */ ot->name= "Apply Pose as Rest Pose"; - ot->idname= "POSE_OT_apply"; + ot->idname= "POSE_OT_armature_apply"; ot->description= "Apply the current pose as the new rest pose"; /* callbacks */ @@ -652,6 +652,64 @@ void POSE_OT_apply (wmOperatorType *ot) ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; } + +/* set the current pose as the restpose */ +static int pose_visual_transform_apply_exec (bContext *C, wmOperator *op) +{ + Scene *scene= CTX_data_scene(C); + Object *ob= CTX_data_active_object(C); // must be active object, not edit-object + + /* don't check if editmode (should be done by caller) */ + if (ob->type!=OB_ARMATURE) + return OPERATOR_CANCELLED; + + /* loop over all selected pchans + * + * TODO, loop over children before parents if multiple bones + * at once are to be predictable*/ + CTX_DATA_BEGIN(C, bPoseChannel *, pchan, selected_pose_bones) + { + float delta_mat[4][4], imat[4][4], mat[4][4]; + + where_is_pose_bone(scene, ob, pchan, CFRA, 1); + + copy_m4_m4(mat, pchan->pose_mat); + + /* calculate pchan->pose_mat without loc/size/rot & constraints applied */ + where_is_pose_bone(scene, ob, pchan, CFRA, 0); + invert_m4_m4(imat, pchan->pose_mat); + mul_m4_m4m4(delta_mat, mat, imat); + + pchan_apply_mat4(pchan, delta_mat); + + where_is_pose_bone(scene, ob, pchan, CFRA, 1); + } + CTX_DATA_END; + + // ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK); + DAG_id_flush_update(&ob->id, OB_RECALC_DATA); + + /* note, notifier might evolve */ + WM_event_add_notifier(C, NC_OBJECT|ND_POSE, ob); + + return OPERATOR_FINISHED; +} + +void POSE_OT_visual_transform_apply (wmOperatorType *ot) +{ + /* identifiers */ + ot->name= "Apply Visual Transform to Pose"; + ot->idname= "POSE_OT_visual_transform_apply"; + ot->description= "Apply final constrained position of pose bones to their transform."; + + /* callbacks */ + ot->exec= pose_visual_transform_apply_exec; + ot->poll= ED_operator_posemode; + + /* flags */ + ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO; +} + /* ---------------------- */ /* Helper function for armature joining - link fixing */ -- cgit v1.2.3