[Bf-blender-cvs] [15cb567c8e2] master: Armature: remove merge function, use dissolve instead

Campbell Barton noreply at git.blender.org
Mon Mar 30 10:21:13 CEST 2020


Commit: 15cb567c8e2f35eca15165d376a53802921a9a22
Author: Campbell Barton
Date:   Mon Mar 30 18:02:09 2020 +1100
Branches: master
https://developer.blender.org/rB15cb567c8e2f35eca15165d376a53802921a9a22

Armature: remove merge function, use dissolve instead

This was crashing, when looking into a fix I noticed that it gave
hap-hazard results dissolving past forks in the parent/child hierarchy
arbitrarily following one chain.

This functionality is almost identical to "dissolve" which delimits
forks in the chain predictably.

So remove this in favor of dissolve (available from the delete menu).

===================================================================

M	release/scripts/presets/keyconfig/keymap_data/blender_default.py
M	release/scripts/startup/bl_ui/space_view3d.py
M	source/blender/editors/armature/armature_edit.c
M	source/blender/editors/armature/armature_intern.h
M	source/blender/editors/armature/armature_ops.c

===================================================================

diff --git a/release/scripts/presets/keyconfig/keymap_data/blender_default.py b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
index f1c7e1a0976..bef054a1f1d 100644
--- a/release/scripts/presets/keyconfig/keymap_data/blender_default.py
+++ b/release/scripts/presets/keyconfig/keymap_data/blender_default.py
@@ -4575,7 +4575,6 @@ def km_armature(params):
         ("armature.extrude_forked", {"type": 'E', "value": 'PRESS', "shift": True}, None),
         ("armature.click_extrude", {"type": params.action_mouse, "value": 'CLICK', "ctrl": True}, None),
         ("armature.fill", {"type": 'F', "value": 'PRESS'}, None),
-        ("armature.merge", {"type": 'M', "value": 'PRESS', "alt": True}, None),
         ("armature.split", {"type": 'Y', "value": 'PRESS'}, None),
         ("armature.separate", {"type": 'P', "value": 'PRESS'}, None),
         # Set flags.
diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 2349d9cc1f3..2d3b4af4ae5 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -4636,7 +4636,6 @@ class VIEW3D_MT_edit_armature(Menu):
             layout.operator("armature.extrude_forked")
 
         layout.operator("armature.duplicate_move")
-        layout.operator("armature.merge")
         layout.operator("armature.fill")
         layout.operator("armature.split")
         layout.operator("armature.separate")
@@ -4710,7 +4709,6 @@ class VIEW3D_MT_armature_context_menu(Menu):
         # Remove
         layout.operator("armature.split")
         layout.operator("armature.separate")
-        layout.operator("armature.merge")
         layout.operator("armature.dissolve")
         layout.operator("armature.delete")
 
diff --git a/source/blender/editors/armature/armature_edit.c b/source/blender/editors/armature/armature_edit.c
index b8378c95a60..9a640952253 100644
--- a/source/blender/editors/armature/armature_edit.c
+++ b/source/blender/editors/armature/armature_edit.c
@@ -888,213 +888,6 @@ void ARMATURE_OT_fill(wmOperatorType *ot)
 
 /** \} */
 
-/* -------------------------------------------------------------------- */
-/** \name Merge Operator
- * \{ */
-
-/* this function merges between two bones, removes them and those in-between,
- * and adjusts the parent relationships for those in-between
- */
-static void bones_merge(
-    Object *obedit, EditBone *start, EditBone *end, EditBone *endchild, ListBase *chains)
-{
-  bArmature *arm = obedit->data;
-  EditBone *ebo, *ebone, *newbone;
-  LinkData *chain;
-  float head[3], tail[3];
-
-  /* check if same bone */
-  if (start == end) {
-    if (G.debug & G_DEBUG) {
-      printf("Error: same bone!\n");
-      printf("\tstart = %s, end = %s\n", start->name, end->name);
-    }
-  }
-
-  /* step 1: add a new bone
-   * - head = head/tail of start (default head)
-   * - tail = head/tail of end (default tail)
-   * - parent = parent of start
-   */
-  if ((start->flag & BONE_TIPSEL) && (start->flag & BONE_SELECTED) == 0) {
-    copy_v3_v3(head, start->tail);
-  }
-  else {
-    copy_v3_v3(head, start->head);
-  }
-  if ((end->flag & BONE_ROOTSEL) && (end->flag & BONE_SELECTED) == 0) {
-    copy_v3_v3(tail, end->head);
-  }
-  else {
-    copy_v3_v3(tail, end->tail);
-  }
-  newbone = add_points_bone(obedit, head, tail);
-  newbone->parent = start->parent;
-
-  /* TODO, copy more things to the new bone */
-  newbone->flag = start->flag & (BONE_HINGE | BONE_NO_DEFORM | BONE_NO_CYCLICOFFSET |
-                                 BONE_NO_LOCAL_LOCATION | BONE_DONE);
-
-  newbone->inherit_scale_mode = start->inherit_scale_mode;
-
-  /* Step 2a: reparent any side chains which may be parented to any bone in the chain
-   * of bones to merge - potentially several tips for side chains leading to some tree exist.
-   */
-  for (chain = chains->first; chain; chain = chain->next) {
-    /* Traverse down chain until we hit the bottom or if we run into the tip of the chain of bones
-     * we're merging (need to stop in this case to avoid corrupting this chain too!).
-     */
-    for (ebone = chain->data; (ebone) && (ebone != end); ebone = ebone->parent) {
-      short found = 0;
-
-      /* Check if this bone is parented to one in the merging chain
-       * ! WATCHIT: must only go check until end of checking chain
-       */
-      for (ebo = end; (ebo) && (ebo != start->parent); ebo = ebo->parent) {
-        /* side-chain found? --> remap parent to new bone, then we're done with this chain :) */
-        if (ebone->parent == ebo) {
-          ebone->parent = newbone;
-          found = 1;
-          break;
-        }
-      }
-
-      /* carry on to the next tip now  */
-      if (found) {
-        break;
-      }
-    }
-  }
-
-  /* step 2b: parent child of end to newbone (child from this chain) */
-  if (endchild) {
-    endchild->parent = newbone;
-  }
-
-  /* step 3: delete all bones between and including start and end */
-  for (ebo = end; ebo; ebo = ebone) {
-    ebone = (ebo == start) ? (NULL) : (ebo->parent);
-    bone_free(arm, ebo);
-  }
-
-  newbone->flag |= (BONE_ROOTSEL | BONE_TIPSEL | BONE_SELECTED);
-  ED_armature_edit_sync_selection(arm->edbo);
-}
-
-static int armature_merge_exec(bContext *C, wmOperator *op)
-{
-  ViewLayer *view_layer = CTX_data_view_layer(C);
-  const short type = RNA_enum_get(op->ptr, "type");
-
-  uint objects_len = 0;
-  Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
-      view_layer, CTX_wm_view3d(C), &objects_len);
-
-  for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
-    Object *obedit = objects[ob_index];
-    bArmature *arm = obedit->data;
-
-    /* for now, there's only really one type of merging that's performed... */
-    if (type == 1) {
-      /* go down chains, merging bones */
-      ListBase chains = {NULL, NULL};
-      LinkData *chain, *nchain;
-      EditBone *ebo;
-
-      armature_tag_select_mirrored(arm);
-
-      /* get chains (ends on chains) */
-      chains_find_tips(arm->edbo, &chains);
-      if (BLI_listbase_is_empty(&chains)) {
-        continue;
-      }
-
-      /* each 'chain' is the last bone in the chain (with no children) */
-      for (chain = chains.first; chain; chain = nchain) {
-        EditBone *bstart = NULL, *bend = NULL;
-        EditBone *bchild = NULL, *child = NULL;
-
-        /* temporarily remove chain from list of chains */
-        nchain = chain->next;
-        BLI_remlink(&chains, chain);
-
-        /* only consider bones that are visible and selected */
-        for (ebo = chain->data; ebo; child = ebo, ebo = ebo->parent) {
-          /* check if visible + selected */
-          if (EBONE_VISIBLE(arm, ebo) && ((ebo->flag & BONE_CONNECTED) || (ebo->parent == NULL)) &&
-              (ebo->flag & BONE_SELECTED)) {
-            /* set either end or start (end gets priority, unless it is already set) */
-            if (bend == NULL) {
-              bend = ebo;
-              bchild = child;
-            }
-            else {
-              bstart = ebo;
-            }
-          }
-          else {
-            /* chain is broken... merge any continuous segments then clear */
-            if (bstart && bend) {
-              bones_merge(obedit, bstart, bend, bchild, &chains);
-            }
-
-            bstart = NULL;
-            bend = NULL;
-            bchild = NULL;
-          }
-        }
-
-        /* merge from bstart to bend if something not merged */
-        if (bstart && bend) {
-          bones_merge(obedit, bstart, bend, bchild, &chains);
-        }
-
-        /* put back link */
-        BLI_insertlinkbefore(&chains, nchain, chain);
-      }
-
-      armature_tag_unselect(arm);
-
-      BLI_freelistN(&chains);
-    }
-
-    /* updates */
-    ED_armature_edit_sync_selection(arm->edbo);
-    ED_armature_edit_refresh_layer_used(arm);
-    WM_event_add_notifier(C, NC_OBJECT | ND_POSE, obedit);
-    DEG_id_tag_update(&arm->id, ID_RECALC_COPY_ON_WRITE);
-  }
-  MEM_freeN(objects);
-
-  return OPERATOR_FINISHED;
-}
-
-void ARMATURE_OT_merge(wmOperatorType *ot)
-{
-  static const EnumPropertyItem merge_types[] = {
-      {1, "WITHIN_CHAIN", 0, "Within Chains", ""},
-      {0, NULL, 0, NULL, NULL},
-  };
-
-  /* identifiers */
-  ot->name = "Merge Bones";
-  ot->idname = "ARMATURE_OT_merge";
-  ot->description = "Merge continuous chains of selected bones";
-
-  /* callbacks */
-  ot->invoke = WM_menu_invoke;
-  ot->exec = armature_merge_exec;
-  ot->poll = ED_operator_editarmature;
-
-  /* flags */
-  ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
-  /* properties */
-  ot->prop = RNA_def_enum(ot->srna, "type", merge_types, 0, "Type", "");
-}
-
-/** \} */
-
 /* -------------------------------------------------------------------- */
 /** \name Switch Direction Operator
  *
diff --git a/source/blender/editors/armature/armature_intern.h b/source/blender/editors/armature/armature_intern.h
index fa562ab0f44..ba914080d98 100644
--- a/source/blender/editors/armature/armature_intern.h
+++ b/source/blender/editors/armature/armature_intern.h
@@ -72,7 +72,6 @@ void ARMATURE_OT_hide(struct wmOperatorType *ot);
 void ARMATURE_OT_reveal(struct wmOperatorType *ot);
 void ARMATURE_OT_click_extrude(struct wmOperatorType *ot);
 void ARMATURE_OT_fill(struct wmOperatorType *ot);
-void ARMATURE_OT_merge(struct wmOperatorType *ot);
 void ARMATURE_OT_separate(struct wmOperatorType *ot);
 void ARMATURE_OT_split(struct wmOperatorType *ot);
 
diff --git a/source/blender/editors/armature/armature_ops.c b/source/blender/editors/armature/armature_ops.c
index a29d0f5f158..097d384a609 100644
--- a/source/blender/editors/armature/armature_ops.c
+++ b/source/blender/editors/armature/armature_ops.c
@@ -68,7 +68,6 @@ void ED_operatortypes_armature(void)
   WM_operatortype_append(ARMATURE_OT_reveal);
   WM_operatortype_append(ARMATURE_OT_click_extrude);
   WM_operatortype_append(ARMATURE_OT_fill);
-  WM_operatortype_append(ARMATURE_OT_merge);
   WM_operatortype_append(ARMATURE_OT_separate);
   WM_operatortype_append(ARMATURE_OT_split);



More information about the Bf-blender-cvs mailing list