From 2177f645855c242399f3d3324f4d8e0357c3601c Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 3 Mar 2016 11:45:43 +1100 Subject: Armature edit-mode: Add clear-roll operator, Alt-R --- source/blender/editors/armature/armature_edit.c | 52 +++++++++++++++++++++++ source/blender/editors/armature/armature_intern.h | 1 + source/blender/editors/armature/armature_ops.c | 2 + 3 files changed, 55 insertions(+) (limited to 'source/blender/editors/armature') diff --git a/source/blender/editors/armature/armature_edit.c b/source/blender/editors/armature/armature_edit.c index 94b7277ce8f..7802a990071 100644 --- a/source/blender/editors/armature/armature_edit.c +++ b/source/blender/editors/armature/armature_edit.c @@ -459,6 +459,58 @@ void ARMATURE_OT_calculate_roll(wmOperatorType *ot) RNA_def_boolean(ot->srna, "axis_only", 0, "Shortest Rotation", "Ignore the axis direction, use the shortest rotation to align"); } +static int armature_roll_clear_exec(bContext *C, wmOperator *op) +{ + Object *ob = CTX_data_edit_object(C); + + bArmature *arm = ob->data; + EditBone *ebone; + + const float roll = RNA_float_get(op->ptr, "roll"); + + for (ebone = arm->edbo->first; ebone; ebone = ebone->next) { + if (EBONE_VISIBLE(arm, ebone) && EBONE_EDITABLE(ebone)) { + /* roll func is a callback which assumes that all is well */ + ebone->roll = roll; + } + } + + if (arm->flag & ARM_MIRROR_EDIT) { + for (ebone = arm->edbo->first; ebone; ebone = ebone->next) { + if ((EBONE_VISIBLE(arm, ebone) && EBONE_EDITABLE(ebone)) == 0) { + EditBone *ebone_mirr = ED_armature_bone_get_mirrored(arm->edbo, ebone); + if (ebone_mirr && (EBONE_VISIBLE(arm, ebone_mirr) && EBONE_EDITABLE(ebone_mirr))) { + ebone->roll = -ebone_mirr->roll; + } + } + } + } + + /* note, notifier might evolve */ + WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob); + + return OPERATOR_FINISHED; +} + +void ARMATURE_OT_roll_clear(wmOperatorType *ot) +{ + /* identifiers */ + ot->name = "Clear Roll"; + ot->idname = "ARMATURE_OT_roll_clear"; + ot->description = "Clear roll for select bones"; + + /* api callbacks */ + ot->exec = armature_roll_clear_exec; + ot->poll = ED_operator_editarmature; + + /* flags */ + ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO; + + RNA_def_float_rotation( + ot->srna, "roll", 0, NULL, DEG2RADF(-360.0f), DEG2RADF(360.0f), + "Roll", "", DEG2RADF(-360.0f), DEG2RADF(360.0f)); +} + /* ******************************** Chain-Based Tools ********************************* */ /* temporary data-structure for merge/fill bones */ diff --git a/source/blender/editors/armature/armature_intern.h b/source/blender/editors/armature/armature_intern.h index 2968851f2eb..08db32fa357 100644 --- a/source/blender/editors/armature/armature_intern.h +++ b/source/blender/editors/armature/armature_intern.h @@ -54,6 +54,7 @@ void ARMATURE_OT_bone_primitive_add(struct wmOperatorType *ot); void ARMATURE_OT_align(struct wmOperatorType *ot); void ARMATURE_OT_calculate_roll(struct wmOperatorType *ot); +void ARMATURE_OT_roll_clear(struct wmOperatorType *ot); void ARMATURE_OT_switch_direction(struct wmOperatorType *ot); void ARMATURE_OT_subdivide(struct wmOperatorType *ot); diff --git a/source/blender/editors/armature/armature_ops.c b/source/blender/editors/armature/armature_ops.c index e7f036f6911..ed5f96a5829 100644 --- a/source/blender/editors/armature/armature_ops.c +++ b/source/blender/editors/armature/armature_ops.c @@ -49,6 +49,7 @@ void ED_operatortypes_armature(void) WM_operatortype_append(ARMATURE_OT_align); WM_operatortype_append(ARMATURE_OT_calculate_roll); + WM_operatortype_append(ARMATURE_OT_roll_clear); WM_operatortype_append(ARMATURE_OT_switch_direction); WM_operatortype_append(ARMATURE_OT_subdivide); @@ -228,6 +229,7 @@ void ED_keymap_armature(wmKeyConfig *keyconf) WM_keymap_add_item(keymap, "ARMATURE_OT_reveal", HKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "ARMATURE_OT_align", AKEY, KM_PRESS, KM_CTRL | KM_ALT, 0); WM_keymap_add_item(keymap, "ARMATURE_OT_calculate_roll", NKEY, KM_PRESS, KM_CTRL, 0); + WM_keymap_add_item(keymap, "ARMATURE_OT_roll_clear", RKEY, KM_PRESS, KM_ALT, 0); WM_keymap_add_item(keymap, "ARMATURE_OT_switch_direction", FKEY, KM_PRESS, KM_ALT, 0); -- cgit v1.2.3