[Bf-blender-cvs] [9b8b4a5ab86] refactor-vertex-group-names: Move active index to geometry

Hans Goudey noreply at git.blender.org
Tue Jul 13 01:41:10 CEST 2021


Commit: 9b8b4a5ab86516b9948b97928d945cd7be76a2d7
Author: Hans Goudey
Date:   Tue Jun 29 12:43:03 2021 -0500
Branches: refactor-vertex-group-names
https://developer.blender.org/rB9b8b4a5ab86516b9948b97928d945cd7be76a2d7

Move active index to geometry

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

M	source/blender/blenkernel/BKE_deform.h
M	source/blender/blenkernel/intern/deform.c
M	source/blender/blenkernel/intern/object_deform.c
M	source/blender/draw/intern/draw_cache.c
M	source/blender/draw/intern/draw_cache_impl_gpencil.c
M	source/blender/draw/intern/draw_cache_impl_mesh.c
M	source/blender/editors/gpencil/gpencil_data.c
M	source/blender/editors/gpencil/gpencil_fill.c
M	source/blender/editors/gpencil/gpencil_paint.c
M	source/blender/editors/gpencil/gpencil_primitive.c
M	source/blender/editors/gpencil/gpencil_sculpt_paint.c
M	source/blender/editors/gpencil/gpencil_utils.c
M	source/blender/editors/gpencil/gpencil_weight_paint.c
M	source/blender/editors/mesh/editmesh_tools.c
M	source/blender/editors/mesh/meshtools.c
M	source/blender/editors/object/object_hook.c
M	source/blender/editors/object/object_vgroup.c
M	source/blender/editors/sculpt_paint/paint_vertex.c
M	source/blender/editors/sculpt_paint/paint_vertex_color_ops.c
M	source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c
M	source/blender/editors/sculpt_paint/paint_vertex_weight_utils.c
M	source/blender/editors/space_outliner/outliner_select.c
M	source/blender/editors/space_view3d/view3d_buttons.c
M	source/blender/makesdna/DNA_gpencil_types.h
M	source/blender/makesdna/DNA_lattice_types.h
M	source/blender/makesdna/DNA_mesh_types.h
M	source/blender/makesdna/DNA_object_types.h
M	source/blender/makesrna/intern/rna_object.c
M	source/blender/render/intern/texture_pointdensity.c

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

diff --git a/source/blender/blenkernel/BKE_deform.h b/source/blender/blenkernel/BKE_deform.h
index c9f01f3d2eb..3a9475e2f6c 100644
--- a/source/blender/blenkernel/BKE_deform.h
+++ b/source/blender/blenkernel/BKE_deform.h
@@ -41,6 +41,10 @@ struct bDeformGroup;
 const struct ListBase *BKE_object_defgroup_list_for_read(const struct Object *ob);
 struct ListBase *BKE_object_defgroup_list_for_write(struct Object *ob);
 
+int BKE_object_defgroup_count(const struct Object *ob);
+int BKE_object_defgroup_active_index_get(const struct Object *ob);
+void BKE_object_defgroup_active_index_set(struct Object *ob, const int new_index);
+
 struct bDeformGroup *BKE_object_defgroup_new(struct Object *ob, const char *name);
 void BKE_defgroup_copy_list(struct ListBase *outbase, const struct ListBase *inbase);
 struct bDeformGroup *BKE_defgroup_duplicate(const struct bDeformGroup *ingroup);
diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c
index a448cf4236b..1a375c4b452 100644
--- a/source/blender/blenkernel/intern/deform.c
+++ b/source/blender/blenkernel/intern/deform.c
@@ -546,6 +546,61 @@ ListBase *BKE_object_defgroup_list_for_write(Object *ob)
   return NULL;
 }
 
+int BKE_object_defgroup_count(const Object *ob)
+{
+  return BLI_listbase_count(BKE_object_defgroup_list_for_read(ob));
+}
+
+/**
+ * \note For historical reasons, the index starts at 1 rather than 0.
+ */
+int BKE_object_defgroup_active_index_get(const Object *ob)
+{
+  switch (ob->type) {
+    case OB_MESH: {
+      const Mesh *mesh = (const Mesh *)ob->data;
+      return mesh->vertex_group_active_index;
+    }
+    case OB_LATTICE: {
+      const Lattice *lattice = (const Lattice *)ob->data;
+      return lattice->vertex_group_active_index;
+    }
+    case OB_GPENCIL: {
+      const bGPdata *gpd = (const bGPdata *)ob->data;
+      return gpd->vertex_group_active_index;
+    }
+  }
+  BLI_assert_unreachable();
+  return -1;
+}
+
+/**
+ * \note For historical reasons, the index starts at 1 rather than 0.
+ */
+void BKE_object_defgroup_active_index_set(Object *ob, const int new_index)
+{
+  switch (ob->type) {
+    case OB_MESH: {
+      Mesh *mesh = (Mesh *)ob->data;
+      mesh->vertex_group_active_index = new_index;
+      break;
+    }
+    case OB_LATTICE: {
+      Lattice *lattice = (Lattice *)ob->data;
+      lattice->vertex_group_active_index = new_index;
+      break;
+    }
+    case OB_GPENCIL: {
+      bGPdata *gpd = (bGPdata *)ob->data;
+      gpd->vertex_group_active_index = new_index;
+      break;
+    }
+    default: {
+      BLI_assert_unreachable();
+    }
+  }
+}
+
 /**
  * \note caller must free.
  */
@@ -1329,7 +1384,7 @@ static bool data_transfer_layersmapping_vgroups_multisrc_to_dst(ListBase *r_map,
         if ((idx_dst = BKE_object_defgroup_name_index(ob_dst, dg_src->name)) == -1) {
           if (use_create) {
             BKE_object_defgroup_add_name(ob_dst, dg_src->name);
-            idx_dst = ob_dst->actdef - 1;
+            idx_dst = BKE_object_defgroup_active_index_get(ob_dst) - 1;
           }
           else {
             /* If we are not allowed to create missing dst vgroups, just skip matching src one. */
@@ -1427,7 +1482,7 @@ bool data_transfer_layersmapping_vgroups(ListBase *r_map,
         return false;
       }
     }
-    else if ((idx_src = ob_src->actdef - 1) == -1) {
+    else if ((idx_src = BKE_object_defgroup_active_index_get(ob_src) - 1) == -1) {
       return false;
     }
 
@@ -1439,14 +1494,14 @@ bool data_transfer_layersmapping_vgroups(ListBase *r_map,
       UNUSED_VARS_NDEBUG(dst_defbase);
     }
     else if (tolayers == DT_LAYERS_ACTIVE_DST) {
-      if ((idx_dst = ob_dst->actdef - 1) == -1) {
+      if ((idx_dst = BKE_object_defgroup_active_index_get(ob_dst) - 1) == -1) {
         bDeformGroup *dg_src;
         if (!use_create) {
           return true;
         }
         dg_src = BLI_findlink(src_defbase, idx_src);
         BKE_object_defgroup_add_name(ob_dst, dg_src->name);
-        idx_dst = ob_dst->actdef - 1;
+        idx_dst = BKE_object_defgroup_active_index_get(ob_dst) - 1;
       }
     }
     else if (tolayers == DT_LAYERS_INDEX_DST) {
@@ -1469,7 +1524,7 @@ bool data_transfer_layersmapping_vgroups(ListBase *r_map,
           return true;
         }
         BKE_object_defgroup_add_name(ob_dst, dg_src->name);
-        idx_dst = ob_dst->actdef - 1;
+        idx_dst = BKE_object_defgroup_active_index_get(ob_dst) - 1;
       }
     }
     else {
diff --git a/source/blender/blenkernel/intern/object_deform.c b/source/blender/blenkernel/intern/object_deform.c
index 07d801f45c2..6659dd058db 100644
--- a/source/blender/blenkernel/intern/object_deform.c
+++ b/source/blender/blenkernel/intern/object_deform.c
@@ -123,8 +123,7 @@ bDeformGroup *BKE_object_defgroup_add_name(Object *ob, const char *name)
   }
 
   defgroup = BKE_object_defgroup_new(ob, name);
-
-  ob->actdef = BLI_listbase_count(BKE_object_defgroup_list_for_read(ob));
+  BKE_object_defgroup_active_index_set(ob, BKE_object_defgroup_count(ob));
 
   return defgroup;
 }
@@ -294,8 +293,9 @@ static void object_defgroup_remove_common(Object *ob, bDeformGroup *dg, const in
   BLI_freelinkN(defbase, dg);
 
   /* Update the active deform index if necessary */
-  if (ob->actdef > def_nr) {
-    ob->actdef--;
+  const int active_index = BKE_object_defgroup_active_index_get(ob);
+  if (active_index > def_nr) {
+    BKE_object_defgroup_active_index_set(ob, active_index - 1);
   }
 
   /* remove all dverts */
@@ -313,8 +313,9 @@ static void object_defgroup_remove_common(Object *ob, bDeformGroup *dg, const in
       }
     }
   }
-  else if (ob->actdef < 1) { /* Keep a valid active index if we still have some vgroups. */
-    ob->actdef = 1;
+  else if (BKE_object_defgroup_active_index_get(ob) < 1) {
+    /* Keep a valid active index if we still have some vgroups. */
+    BKE_object_defgroup_active_index_set(ob, 1);
   }
 }
 
@@ -470,7 +471,7 @@ void BKE_object_defgroup_remove_all_ex(struct Object *ob, bool only_unlocked)
       }
     }
     /* Fix counters/indices */
-    ob->actdef = 0;
+    BKE_object_defgroup_active_index_set(ob, 0);
   }
 }
 
@@ -828,7 +829,7 @@ bool *BKE_object_defgroup_subset_from_select_type(Object *ob,
 
   switch (subset_type) {
     case WT_VGROUP_ACTIVE: {
-      const int def_nr_active = ob->actdef - 1;
+      const int def_nr_active = BKE_object_defgroup_active_index_get(ob) - 1;
       defgroup_validmap = MEM_mallocN(*r_defgroup_tot * sizeof(*defgroup_validmap), __func__);
       memset(defgroup_validmap, false, *r_defgroup_tot * sizeof(*defgroup_validmap));
       if ((def_nr_active >= 0) && (def_nr_active < *r_defgroup_tot)) {
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
index 51bb9253e62..654494a9fe0 100644
--- a/source/blender/draw/intern/draw_cache.c
+++ b/source/blender/draw/intern/draw_cache.c
@@ -3275,7 +3275,7 @@ GPUBatch *DRW_cache_lattice_wire_get(Object *ob, bool use_weight)
   int actdef = -1;
 
   if (use_weight && !BLI_listbase_is_empty(&lt->vertex_group_names) && lt->editlatt->latt->dvert) {
-    actdef = ob->actdef - 1;
+    actdef = lt->vertex_group_active_index - 1;
   }
 
   return DRW_lattice_batch_cache_get_all_edges(lt, use_weight, actdef);
diff --git a/source/blender/draw/intern/draw_cache_impl_gpencil.c b/source/blender/draw/intern/draw_cache_impl_gpencil.c
index cca3e8a8b3c..3c82b4d4b6f 100644
--- a/source/blender/draw/intern/draw_cache_impl_gpencil.c
+++ b/source/blender/draw/intern/draw_cache_impl_gpencil.c
@@ -843,7 +843,7 @@ static void gpencil_edit_batches_ensure(Object *ob, GpencilBatchCache *cache, in
     int vert_len = GPU_vertbuf_get_vertex_len(cache->vbo);
 
     gpEditIterData iter;
-    iter.vgindex = ob->actdef - 1;
+    iter.vgindex = BKE_object_defgroup_active_index_get(ob) - 1;
     if (!BLI_findlink(&gpd->vertex_group_names, iter.vgindex)) {
       iter.vgindex = -1;
     }
diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c
index 6938a12c474..673a662a512 100644
--- a/source/blender/draw/intern/draw_cache_impl_mesh.c
+++ b/source/blender/draw/intern/draw_cache_impl_mesh.c
@@ -544,7 +544,7 @@ static void drw_mesh_weight_state_extract(Object *ob,
   /* Extract complete vertex weight group selection state and mode flags. */
   memset(wstate, 0, sizeof(*wstate));
 
-  wstate->defgroup_active = ob->actdef - 1;
+  wstate->defgroup_active = me->vertex_group_active_index - 1;
   wstate->defgroup_len = BLI_listbase_count(&me->vertex_group_names);
 
   wstate->alert_mode = ts->weightuser;
diff --git a/source/blender/editors/gpencil/gpencil_data.c b/source/blender/editors/gpencil/gpencil_data.c
index 4df9c37ff89..59a3acfeeaf 100644
--- a/source/blender/editors/gpencil/gpencil_data.c
+++ b/source/blender/editors/gpencil/gpencil_data.c
@@ -2345,7 +2345,7 @@ static int gpencil_vertex_group_invert_exec(bContext *C, wmOperator *op)
   }
 
   MDeformVert *dvert;
-  const int def_nr = ob->actdef - 1;
+  const int def_nr = gpd->vertex_group_active_index - 1;
 
   bDeformGroup *defgroup = BLI_findlink(&gpd->vertex_group_names, def_nr);
   if (defgroup == NULL) {
@@ -2415,7 +2415,7 @@ static int gpencil_vertex_group_smooth_exec(bContext *C, wmOperator *op)
     return OPERATOR_CANCELLED;
   }
 
-  const int def_nr = ob->actdef - 1;
+  const int def_nr = gpd->vertex_group_active_index - 1;
   bDeformGroup *defgroup = BLI_findlink(&gpd->vertex_group_names, def_nr);
   if (defgroup == NULL) {
     return OPERATOR_CANCELLED;
@@ -2514,7 +2514,7 @@ static int gpencil_vertex_group_normalize_exec(bContext *C, wmOperator *op)
 
   MDeformVert *dvert = NULL;
   MDeformWeight *dw = NULL;
-  const int def_nr = ob->actdef - 1;
+  const int def_nr = gpd->vertex_group_active_index - 1;
   bDeformGroup *defgroup = BLI_findlink(&gpd->vertex_group_names, def_nr);
   if (defgroup == NULL) {
     return OPERATOR_CANCELLED;
@@ -2591,7 +2591,7 @@ static int gpencil_vertex_group_normalize_all_exec(bContext *C, wmOperator *op)
   bDeformGroup *defgroup = NULL;
   MDeformVert *dvert = NULL;
   MDeformWeight *dw = NULL;
-  const int def_nr = ob->actdef - 1;
+  const int def_nr = gpd->vertex_group_active_in

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list