[Bf-blender-cvs] [7562ad57776] temp_bmesh_multires: Sculpt dyntopo: BMLog now uses the new bmesh unique id system

Joseph Eagar noreply at git.blender.org
Sun Jun 27 06:35:00 CEST 2021


Commit: 7562ad5777618f331226de277c6a5f1f9846d463
Author: Joseph Eagar
Date:   Sat Jun 26 21:26:33 2021 -0700
Branches: temp_bmesh_multires
https://developer.blender.org/rB7562ad5777618f331226de277c6a5f1f9846d463

Sculpt dyntopo: BMLog now uses the new bmesh unique id system

A few notes:

* MESH_ID layers are not saved on conversion to Mesh unless
  you ask for it in BM_mesh_bm_to_me's params.
* Still need to test the box/lasso trim tools.
* Need to find some way to test loop/edge ids, which aren't
  used by dyntopo.

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

M	source/blender/blenkernel/intern/customdata.c
M	source/blender/bmesh/intern/bmesh_construct.c
M	source/blender/bmesh/intern/bmesh_interp.c
M	source/blender/bmesh/intern/bmesh_log.c
M	source/blender/bmesh/intern/bmesh_log.h
M	source/blender/bmesh/intern/bmesh_mesh.c
M	source/blender/bmesh/intern/bmesh_mesh_convert.c
M	source/blender/editors/sculpt_paint/sculpt_dyntopo.c
M	source/blender/editors/sculpt_paint/sculpt_undo.c

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

diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index 330ea94f0c0..172758cb405 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -4319,12 +4319,12 @@ void CustomData_bmesh_interp_n(CustomData *data,
   typeInfo->interp(src_blocks_ofs, weights, sub_weights, count, dst_block_ofs);
 }
 
-ATTR_NO_OPT void CustomData_bmesh_interp(CustomData *data,
-                                         const void **src_blocks,
-                                         const float *weights,
-                                         const float *sub_weights,
-                                         int count,
-                                         void *dst_block)
+void CustomData_bmesh_interp(CustomData *data,
+                             const void **src_blocks,
+                             const float *weights,
+                             const float *sub_weights,
+                             int count,
+                             void *dst_block)
 {
   if (count <= 0) {
     return;
diff --git a/source/blender/bmesh/intern/bmesh_construct.c b/source/blender/bmesh/intern/bmesh_construct.c
index 2ca87f34c2d..9fa73e541b1 100644
--- a/source/blender/bmesh/intern/bmesh_construct.c
+++ b/source/blender/bmesh/intern/bmesh_construct.c
@@ -40,7 +40,7 @@
 
 #define SELECT 1
 
-void bm_assign_id(BMesh *bm, BMElem *elem, uint id)
+static void bm_assign_id_intern(BMesh *bm, BMElem *elem, uint id)
 {
   BM_ELEM_CD_SET_INT(elem, bm->idmap.cd_id_off[elem->head.htype], id);
 
@@ -65,6 +65,12 @@ void bm_assign_id(BMesh *bm, BMElem *elem, uint id)
   }
 }
 
+void bm_assign_id(BMesh *bm, BMElem *elem, uint id)
+{
+  range_tree_uint_retake(bm->idmap.idtree, id);
+  bm_assign_id_intern(bm, elem, id);
+}
+
 void bm_alloc_id(BMesh *bm, BMElem *elem)
 {
   if ((bm->idmap.flag & (elem->head.htype | BM_HAS_IDS)) != (elem->head.htype | BM_HAS_IDS)) {
@@ -72,7 +78,7 @@ void bm_alloc_id(BMesh *bm, BMElem *elem)
   }
 
   uint id = range_tree_uint_take_any(bm->idmap.idtree);
-  bm_assign_id(bm, elem, id);
+  bm_assign_id_intern(bm, elem, id);
 }
 
 void bm_free_id(BMesh *bm, BMElem *elem)
diff --git a/source/blender/bmesh/intern/bmesh_interp.c b/source/blender/bmesh/intern/bmesh_interp.c
index f49ea5c6535..e4a81aa5a31 100644
--- a/source/blender/bmesh/intern/bmesh_interp.c
+++ b/source/blender/bmesh/intern/bmesh_interp.c
@@ -1336,10 +1336,7 @@ static void update_data_blocks(BMesh *bm, CustomData *olddata, CustomData *data)
   }
 }
 
-ATTR_NO_OPT void BM_data_layers_ensure(BMesh *bm,
-                                       CustomData *data,
-                                       BMCustomLayerReq *layers,
-                                       int totlayer)
+void BM_data_layers_ensure(BMesh *bm, CustomData *data, BMCustomLayerReq *layers, int totlayer)
 {
   bool modified = false;
   CustomData old = *data;
diff --git a/source/blender/bmesh/intern/bmesh_log.c b/source/blender/bmesh/intern/bmesh_log.c
index ebf826de70e..4f1405ddccd 100644
--- a/source/blender/bmesh/intern/bmesh_log.c
+++ b/source/blender/bmesh/intern/bmesh_log.c
@@ -47,12 +47,12 @@
 #include "BKE_customdata.h"
 #include "BKE_mesh.h"
 
+#include "BLI_strict_flags.h"
 #include "bmesh.h"
 #include "bmesh_log.h"
+#include "bmesh_private.h"
 #include "range_tree.h"
 
-#include "BLI_strict_flags.h"
-
 #define CUSTOMDATA
 
 struct Mesh;
@@ -95,13 +95,9 @@ struct BMLogEntry {
   bool fully_copy;  // has full copy
   struct Mesh
       *full_copy_mesh;  // avoid excessive memory use by saving a Mesh instead of copying the bmesh
-  GHash *full_copy_idmap;  // maps ids to indices (with the elem-type in the high order bits)
 };
 
 struct BMLog {
-  /* Tree of free IDs */
-  struct RangeTreeUInt *unused_ids;
-
   BMLogEntry *frozen_full_mesh;
 
   int refcount;
@@ -115,8 +111,6 @@ struct BMLog {
    * The ID is needed because element pointers will change as they
    * are created and deleted.
    */
-  GHash *id_to_elem;
-  GHash *elem_to_id;
 
   ThreadRWMutex lock;
 
@@ -149,6 +143,7 @@ typedef struct {
 
 typedef struct {
   uint v_ids[3];
+  uint l_ids[3];
   float no[3];
   void *customdata[3];
   void *customdata_f;
@@ -233,32 +228,19 @@ static bool log_ghash_ensure_p(BMLog *log, GHash *gh, void *key, void ***val)
 /* Get the vertex's unique ID from the log */
 static uint bm_log_vert_id_get(BMLog *log, BMVert *v)
 {
-  BLI_assert(log_ghash_haskey(log, log->elem_to_id, v));
-  return POINTER_AS_UINT(log_ghash_lookup(log, log->elem_to_id, v));
-}
-
-/* Set the vertex's unique ID in the log */
-static void bm_log_vert_id_set(BMLog *log, BMVert *v, uint id)
-{
-  void *vid = POINTER_FROM_UINT(id);
-
-  log_ghash_reinsert(log, log->id_to_elem, vid, v, NULL, NULL);
-  log_ghash_reinsert(log, log->elem_to_id, v, vid, NULL, NULL);
+  return (uint)BM_ELEM_GET_ID(log->bm, v);
 }
 
 /* Get a vertex from its unique ID */
 static BMVert *bm_log_vert_from_id(BMLog *log, uint id)
 {
-  void *key = POINTER_FROM_UINT(id);
-  BLI_assert(log_ghash_haskey(log, log->id_to_elem, key));
-  return log_ghash_lookup(log, log->id_to_elem, key);
+  return (BMVert *)log->bm->idmap.map[id];
 }
 
 /* Get the face's unique ID from the log */
 static uint bm_log_face_id_get(BMLog *log, BMFace *f)
 {
-  BLI_assert(log_ghash_haskey(log, log->elem_to_id, f));
-  return POINTER_AS_UINT(log_ghash_lookup(log, log->elem_to_id, f));
+  return (uint)BM_ELEM_GET_ID(log->bm, f);
 }
 
 uint BM_log_vert_id_get(BMLog *log, BMVert *v)
@@ -268,7 +250,7 @@ uint BM_log_vert_id_get(BMLog *log, BMVert *v)
 
 BMVert *BM_log_id_vert_get(BMLog *log, uint id)
 {
-  return log_ghash_lookup(log, log->id_to_elem, POINTER_FROM_UINT(id));
+  return (BMVert *)log->bm->idmap.map[id];
 }
 
 uint BM_log_face_id_get(BMLog *log, BMFace *f)
@@ -278,24 +260,13 @@ uint BM_log_face_id_get(BMLog *log, BMFace *f)
 
 BMFace *BM_log_id_face_get(BMLog *log, uint id)
 {
-  return log_ghash_lookup(log, log->id_to_elem, POINTER_FROM_UINT(id));
-}
-
-/* Set the face's unique ID in the log */
-static void bm_log_face_id_set(BMLog *log, BMFace *f, uint id)
-{
-  void *fid = POINTER_FROM_UINT(id);
-
-  log_ghash_reinsert(log, log->id_to_elem, fid, f, NULL, NULL);
-  log_ghash_reinsert(log, log->elem_to_id, f, fid, NULL, NULL);
+  return (BMFace *)log->bm->idmap.map[id];
 }
 
 /* Get a face from its unique ID */
 static BMFace *bm_log_face_from_id(BMLog *log, uint id)
 {
-  void *key = POINTER_FROM_UINT(id);
-  BLI_assert(log_ghash_haskey(log, log->id_to_elem, key));
-  return log_ghash_lookup(log, log->id_to_elem, key);
+  return (BMFace *)log->bm->idmap.map[id];
 }
 
 /************************ BMLogVert / BMLogFace ***********************/
@@ -419,6 +390,15 @@ static BMLogFace *bm_log_face_alloc(BMLog *log, BMFace *f)
 
   copy_v3_v3(lf->no, f->no);
 
+  if (log->bm->idmap.flag & BM_LOOP) {
+    lf->l_ids[0] = (uint)BM_ELEM_GET_ID(log->bm, f->l_first);
+    lf->l_ids[1] = (uint)BM_ELEM_GET_ID(log->bm, f->l_first->next);
+    lf->l_ids[2] = (uint)BM_ELEM_GET_ID(log->bm, f->l_first->prev);
+  }
+  else {
+    lf->l_ids[0] = lf->l_ids[1] = lf->l_ids[2] = (uint)-1;
+  }
+
   lf->v_ids[0] = bm_log_vert_id_get(log, v[0]);
   lf->v_ids[1] = bm_log_vert_id_get(log, v[1]);
   lf->v_ids[2] = bm_log_vert_id_get(log, v[2]);
@@ -517,11 +497,10 @@ static void bm_log_verts_restore(
   GHASH_ITER (gh_iter, verts) {
     void *key = BLI_ghashIterator_getKey(&gh_iter);
     BMLogVert *lv = BLI_ghashIterator_getValue(&gh_iter);
-    BMVert *v = BM_vert_create(bm, lv->co, NULL, BM_CREATE_NOP);
+    BMVert *v = BM_vert_create(bm, lv->co, NULL, BM_CREATE_SKIP_ID);
     vert_mask_set(v, lv->mask, cd_vert_mask_offset);
     v->head.hflag = lv->hflag;
     normal_short_to_float_v3(v->no, lv->no);
-    bm_log_vert_id_set(log, v, POINTER_AS_UINT(key));
 
 #ifdef CUSTOMDATA
     if (lv->customdata) {
@@ -529,6 +508,8 @@ static void bm_log_verts_restore(
     }
 #endif
 
+    bm_assign_id(bm, (BMElem *)v, POINTER_AS_UINT(key));
+
     if (callbacks) {
       callbacks->on_vert_add(v, callbacks->userdata);
     }
@@ -549,11 +530,11 @@ static void bm_log_faces_restore(
     };
     BMFace *f;
 
-    f = BM_face_create_verts(bm, v, 3, NULL, BM_CREATE_NOP, true);
+    f = BM_face_create_verts(bm, v, 3, NULL, BM_CREATE_SKIP_ID, true);
     f->head.hflag = lf->hflag;
 
     copy_v3_v3(f->no, lf->no);
-    bm_log_face_id_set(log, f, POINTER_AS_UINT(key));
+    bm_assign_id(bm, (BMElem *)f, POINTER_AS_UINT(key));
 
 #ifdef CUSTOMDATA
     if (lf->customdata_f) {
@@ -563,6 +544,10 @@ static void bm_log_faces_restore(
     BMLoop *ls[3] = {f->l_first, f->l_first->next, f->l_first->prev};
 
     for (int i = 0; i < 3; i++) {
+      if (lf->l_ids[i] != (uint)-1) {
+        bm_assign_id(bm, (BMElem *)ls[i], lf->l_ids[i]);
+      }
+
       if (lf->customdata[i]) {
         CustomData_bmesh_copy_data(
             &entry->ldata, &bm->ldata, lf->customdata[i], &ls[i]->head.data);
@@ -674,53 +659,12 @@ static void bm_log_face_values_swap(BMLog *log,
 
 /**********************************************************************/
 
-/* Assign unique IDs to all vertices and faces already in the BMesh */
-static void bm_log_assign_ids(BMesh *bm, BMLog *log)
-{
-  BMIter iter;
-  BMVert *v;
-  BMFace *f;
-
-  /* Generate vertex IDs */
-  BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
-    uint id = range_tree_uint_take_any(log->unused_ids);
-    bm_log_vert_id_set(log, v, id);
-  }
-
-  /* Generate face IDs */
-  BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
-    uint id = range_tree_uint_take_any(log->unused_ids);
-    bm_log_face_id_set(log, f, id);
-  }
-}
-
 static void bm_log_full_mesh_intern(BMesh *bm, BMLog *log, BMLogEntry *entry)
 {
   CustomData_MeshMasks cd_mask_extra = {CD_MASK_DYNTOPO_VERT, 0, 0, 0, 0};
 
-  entry->full_copy_idmap = BLI_ghash_ptr_new_ex("bmlog",
-                                                (unsigned int)(bm->totvert + bm->totface));
-
   BM_mesh_elem_index_ensure(bm, BM_VERT | BM_EDGE | BM_FACE);
 
-  for (int step = 0; step < 2; step++) {
-    BMIter iter;
-    BMHeader *elem;
-
-    BM_ITER_MESH (elem, &iter, bm, step ? BM_FACES_OF_MESH : BM_VERTS_OF_MESH) {
-      void **val = log_ghash_lookup_p

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list