diff options
Diffstat (limited to 'source/blender/editors/armature/armature_edit.c')
-rw-r--r-- | source/blender/editors/armature/armature_edit.c | 86 |
1 files changed, 65 insertions, 21 deletions
diff --git a/source/blender/editors/armature/armature_edit.c b/source/blender/editors/armature/armature_edit.c index 75b80627dff..2335e29aca8 100644 --- a/source/blender/editors/armature/armature_edit.c +++ b/source/blender/editors/armature/armature_edit.c @@ -48,6 +48,7 @@ #include "BKE_armature.h" #include "BKE_constraint.h" #include "BKE_context.h" +#include "BKE_layer.h" #include "BKE_global.h" #include "BKE_report.h" #include "BKE_object.h" @@ -630,25 +631,39 @@ static void fill_add_joint(EditBone *ebo, short eb_tail, ListBase *points) /* bone adding between selected joints */ static int armature_fill_bones_exec(bContext *C, wmOperator *op) { - Object *obedit = CTX_data_edit_object(C); - bArmature *arm = (obedit) ? obedit->data : NULL; + Object *obedit_active = CTX_data_edit_object(C); Scene *scene = CTX_data_scene(C); View3D *v3d = CTX_wm_view3d(C); ListBase points = {NULL, NULL}; EditBone *newbone = NULL; int count; + bool mixed_object_error = false; /* sanity checks */ - if (ELEM(NULL, obedit, arm)) + if (ELEM(NULL, obedit_active, obedit_active->data)) { return OPERATOR_CANCELLED; + } /* loop over all bones, and only consider if visible */ - CTX_DATA_BEGIN(C, EditBone *, ebone, visible_bones) + bArmature *arm = NULL; + CTX_DATA_BEGIN_WITH_ID(C, EditBone *, ebone, visible_bones, bArmature *, arm_iter) { - if (!(ebone->flag & BONE_CONNECTED) && (ebone->flag & BONE_ROOTSEL)) + bool check = false; + if (!(ebone->flag & BONE_CONNECTED) && (ebone->flag & BONE_ROOTSEL)) { fill_add_joint(ebone, 0, &points); - if (ebone->flag & BONE_TIPSEL) + check = true; + } + if (ebone->flag & BONE_TIPSEL) { fill_add_joint(ebone, 1, &points); + check = true; + } + + if (check) { + if (arm && (arm != arm_iter)) { + mixed_object_error = true; + } + arm = arm_iter; + } } CTX_DATA_END; @@ -658,12 +673,30 @@ static int armature_fill_bones_exec(bContext *C, wmOperator *op) * 3+) error (a smarter method involving finding chains needs to be worked out */ count = BLI_listbase_count(&points); - + if (count == 0) { BKE_report(op->reports, RPT_ERROR, "No joints selected"); return OPERATOR_CANCELLED; } - else if (count == 1) { + else if (mixed_object_error) { + BKE_report(op->reports, RPT_ERROR, "Bones for different objects selected"); + BLI_freelistN(&points); + return OPERATOR_CANCELLED; + } + + Object *obedit = NULL; + { + ViewLayer *view_layer = CTX_data_view_layer(C); + FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, OB_MODE_EDIT, ob_iter) { + if (ob_iter->data == arm) { + obedit = ob_iter; + } + } + FOREACH_OBJECT_IN_MODE_END; + } + BLI_assert(obedit != NULL); + + if (count == 1) { EditBonePoint *ebp; float curs[3]; @@ -1301,18 +1334,23 @@ static bool armature_delete_ebone_cb(const char *bone_name, void *arm_p) /* only editmode! */ static int armature_delete_selected_exec(bContext *C, wmOperator *UNUSED(op)) { - bArmature *arm; EditBone *curBone, *ebone_next; - Object *obedit = CTX_data_edit_object(C); - bool changed = false; - arm = obedit->data; + bool changed_multi = false; /* cancel if nothing selected */ if (CTX_DATA_COUNT(C, selected_bones) == 0) return OPERATOR_CANCELLED; - + + ViewLayer *view_layer = CTX_data_view_layer(C); + uint objects_len = 0; + Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len); + for (uint ob_index = 0; ob_index < objects_len; ob_index++) { + Object *obedit = objects[ob_index]; + bArmature *arm = obedit->data; + bool changed = false; + armature_select_mirrored(arm); - + BKE_pose_channels_remove(obedit, armature_delete_ebone_cb, arm); for (curBone = arm->edbo->first; curBone; curBone = ebone_next) { @@ -1325,14 +1363,20 @@ static int armature_delete_selected_exec(bContext *C, wmOperator *UNUSED(op)) } } } - - if (!changed) - return OPERATOR_CANCELLED; - - ED_armature_edit_sync_selection(arm->edbo); - BKE_pose_tag_recalc(CTX_data_main(C), obedit->pose); - WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, obedit); + if (changed) { + changed_multi = true; + + ED_armature_edit_sync_selection(arm->edbo); + BKE_pose_tag_recalc(CTX_data_main(C), obedit->pose); + + WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, obedit); + } + } + + if (!changed_multi) { + return OPERATOR_CANCELLED; + } return OPERATOR_FINISHED; } |