Fix T78994: Clear selected pose doesn't work without animation

It looks like the code left this as a todo, but the basic solution is to
add an extra parameter to BKE_bose_rest to check whether bones
are selected before reseting them.

I also corrected the operator description which said it acted on only
selected bones even when there is an option to turn that off. The
"act on selected" is generally implied for Blender's operators anyway.

Differential Revision: https://developer.blender.org/D8319
This commit is contained in:
Hans Goudey 2020-07-21 09:51:27 -04:00
parent 6b6e2e742f
commit d42530824e
Notes: blender-bot 2023-02-13 21:46:18 +01:00
Referenced by issue #78994, Armature, pose mode, Clear user transforms reset all despite «only selected» option
5 changed files with 14 additions and 11 deletions

View File

@ -209,8 +209,8 @@ void what_does_obaction(struct Object *ob,
void BKE_pose_copy_pchan_result(struct bPoseChannel *pchanto,
const struct bPoseChannel *pchanfrom);
bool BKE_pose_copy_result(struct bPose *to, struct bPose *from);
/* clear all transforms */
void BKE_pose_rest(struct bPose *pose);
/* Clear transforms. */
void BKE_pose_rest(struct bPose *pose, bool selected_bones_only);
/* Tag pose for recalc. Also tag all related data to be recalc. */
void BKE_pose_tag_recalc(struct Main *bmain, struct bPose *pose);

View File

@ -1512,8 +1512,10 @@ short action_get_item_transforms(bAction *act, Object *ob, bPoseChannel *pchan,
/* ************** Pose Management Tools ****************** */
/* for do_all_pose_actions, clears the pose. Now also exported for proxy and tools */
void BKE_pose_rest(bPose *pose)
/**
* Zero the pose transforms for the entire pose or only for selected bones.
*/
void BKE_pose_rest(bPose *pose, bool selected_bones_only)
{
bPoseChannel *pchan;
@ -1525,6 +1527,9 @@ void BKE_pose_rest(bPose *pose)
memset(pose->cyclic_offset, 0, sizeof(pose->cyclic_offset));
for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
if (selected_bones_only && pchan->bone != NULL && (pchan->bone->flag & BONE_SELECTED) == 0) {
continue;
}
zero_v3(pchan->loc);
zero_v3(pchan->eul);
unit_qt(pchan->quat);

View File

@ -2164,7 +2164,7 @@ static void pose_proxy_sync(Object *ob, Object *from, int layer_protected)
}
/* clear all transformation values from library */
BKE_pose_rest(frompose);
BKE_pose_rest(frompose, false);
/* copy over all of the proxy's bone groups */
/* TODO for later

View File

@ -2088,7 +2088,7 @@ void BKE_object_make_proxy(Main *bmain, Object *ob, Object *target, Object *cob)
/* type conversions */
if (target->type == OB_ARMATURE) {
copy_object_pose(ob, target, 0); /* data copy, object pointers in constraints */
BKE_pose_rest(ob->pose); /* clear all transforms in channels */
BKE_pose_rest(ob->pose, false); /* clear all transforms in channels */
BKE_pose_rebuild(bmain, ob, ob->data, true); /* set all internal links */
armature_set_id_extern(ob);

View File

@ -1262,10 +1262,8 @@ static int pose_clear_user_transforms_exec(bContext *C, wmOperator *op)
MEM_freeN(dummyPose);
}
else {
/* no animation, so just reset whole pose to rest pose
* (cannot just restore for selected though)
*/
BKE_pose_rest(ob->pose);
/* No animation, so just reset to the rest pose. */
BKE_pose_rest(ob->pose, only_select);
}
/* notifiers and updates */
@ -1282,7 +1280,7 @@ void POSE_OT_user_transforms_clear(wmOperatorType *ot)
/* identifiers */
ot->name = "Clear User Transforms";
ot->idname = "POSE_OT_user_transforms_clear";
ot->description = "Reset pose on selected bones to keyframed state";
ot->description = "Reset pose bone transforms to keyframed state";
/* callbacks */
ot->exec = pose_clear_user_transforms_exec;