[Bf-blender-cvs] [db35853b19b] temp-trimesh-sculpt: more trimesh stuff

Joseph Eagar noreply at git.blender.org
Wed Oct 14 04:05:43 CEST 2020


Commit: db35853b19b60ad6111a8412eb400e89ec8ec301
Author: Joseph Eagar
Date:   Wed Sep 30 04:35:52 2020 -0700
Branches: temp-trimesh-sculpt
https://developer.blender.org/rBdb35853b19b60ad6111a8412eb400e89ec8ec301

more trimesh stuff

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

M	source/blender/blenkernel/BKE_customdata.h
M	source/blender/blenkernel/BKE_paint.h
M	source/blender/blenkernel/BKE_pbvh.h
M	source/blender/blenkernel/intern/DerivedMesh.c
M	source/blender/blenkernel/intern/customdata.c
M	source/blender/blenkernel/intern/paint.c
M	source/blender/blenkernel/intern/pbvh.c
M	source/blender/blenkernel/intern/pbvh_trimesh.c
M	source/blender/blenlib/BLI_threadsafe_mempool.h
M	source/blender/blenlib/intern/BLI_threadsafe_mempool.c
M	source/blender/bmesh/intern/bmesh_interp.c
M	source/blender/bmesh/intern/bmesh_mesh.c
M	source/blender/bmesh/intern/bmesh_mesh_conv.c
M	source/blender/editors/object/object_remesh.c
M	source/blender/editors/sculpt_paint/CMakeLists.txt
M	source/blender/editors/sculpt_paint/sculpt.c
M	source/blender/editors/sculpt_paint/sculpt_intern.h
M	source/blender/editors/space_info/CMakeLists.txt
M	source/blender/editors/space_info/info_stats.c
M	source/blender/makesdna/DNA_customdata_types.h
M	source/blender/trimesh/intern/trimesh.c
M	source/blender/trimesh/trimesh.h

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

diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h
index a4a36343ca3..f23b0ae07da 100644
--- a/source/blender/blenkernel/BKE_customdata.h
+++ b/source/blender/blenkernel/BKE_customdata.h
@@ -310,6 +310,15 @@ void CustomData_bmesh_interp(struct CustomData *data,
                              int count,
                              void *dst_block);
 
+struct TM_TriMesh;
+void CustomData_trimesh_init_pool(struct TM_TriMesh *tm, struct CustomData *data, int totelem, const char htype);
+bool CustomData_trimesh_merge(const struct CustomData *source,
+  struct CustomData *dest,
+  CustomDataMask mask,
+  eCDAllocType alloctype,
+  struct TM_TriMesh *bm,
+  const char htype);
+
 /* swaps the data in the element corners, to new corners with indices as
  * specified in corner_indices. for edges this is an array of length 2, for
  * faces an array of length 4 */
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index d840b6e5734..27363484673 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -394,7 +394,6 @@ typedef struct SculptSession {
    * Set #Main.is_memfile_undo_flush_needed when enabling.
    */
   char needs_flush_to_id;
-
 } SculptSession;
 
 void BKE_sculptsession_free(struct Object *ob);
@@ -403,6 +402,9 @@ void BKE_sculptsession_free_vwpaint_data(struct SculptSession *ss);
 void BKE_sculptsession_bm_to_me(struct Object *ob, bool reorder);
 void BKE_sculptsession_bm_to_me_for_render(struct Object *object);
 
+void BKE_sculptsession_tm_to_me(struct Object *ob, bool reorder);
+void BKE_sculptsession_tm_to_me_for_render(struct Object *object);
+
 void BKE_sculpt_update_object_for_edit(struct Depsgraph *depsgraph,
                                        struct Object *ob_orig,
                                        bool need_pmap,
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index cabacabf0ad..8d26704446d 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -352,6 +352,8 @@ bool BKE_pbvh_is_deformed(struct PBVH *pbvh);
 #define PBVH_ITER_ALL 0
 #define PBVH_ITER_UNIQUE 1
 
+struct TMVert;
+
 typedef struct PBVHVertexIter {
   /* iteration */
   int g;
@@ -381,12 +383,18 @@ typedef struct PBVHVertexIter {
   struct GSetIterator bm_unique_verts;
   struct GSetIterator bm_other_verts;
   struct CustomData *bm_vdata;
+
+  struct GSetIterator tm_unique_verts;
+  struct GSetIterator tm_other_verts;
+  struct CustomData *tm_vdata;
+
   int cd_vert_mask_offset;
 
   /* result: these are all computed in the macro, but we assume
    * that compiler optimization's will skip the ones we don't use */
   struct MVert *mvert;
   struct BMVert *bm_vert;
+  struct TMVert *tm_vert;
   float *co;
   short *no;
   float *fno;
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index baef2b2290e..20673938bfa 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -904,7 +904,7 @@ static void mesh_calc_modifiers(struct Depsgraph *depsgraph,
   const bool has_multires = (mmd && BKE_multires_sculpt_level_get(mmd) != 0);
   bool multires_applied = false;
   const bool sculpt_mode = ob->mode & OB_MODE_SCULPT && ob->sculpt && !use_render;
-  const bool sculpt_dyntopo = (sculpt_mode && ob->sculpt->bm) && !use_render;
+  const bool sculpt_dyntopo = (sculpt_mode && (ob->sculpt->bm || ob->sculpt->tm)) && !use_render;
 
   /* Modifier evaluation contexts for different types of modifiers. */
   ModifierApplyFlag app_render = use_render ? MOD_APPLY_RENDER : 0;
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index 87a5ac80bc7..744e7644c90 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -38,6 +38,7 @@
 #include "BLI_math.h"
 #include "BLI_math_color_blend.h"
 #include "BLI_mempool.h"
+#include "BLI_threadsafe_mempool.h"
 #include "BLI_path_util.h"
 #include "BLI_string.h"
 #include "BLI_string_utils.h"
@@ -53,6 +54,7 @@
 #include "BKE_multires.h"
 
 #include "bmesh.h"
+#include "trimesh.h"
 
 #include "CLG_log.h"
 
@@ -3277,25 +3279,25 @@ void CustomData_bmesh_do_versions_update_active_layers(CustomData *fdata, Custom
   }
 }
 
-void CustomData_bmesh_init_pool(CustomData *data, int totelem, const char htype)
+void CustomData_trimesh_init_pool(TM_TriMesh *tm, CustomData *data, int totelem, const char htype)
 {
   int chunksize;
 
   /* Dispose old pools before calling here to avoid leaks */
-  BLI_assert(data->pool == NULL);
+  BLI_assert(data->tpool == NULL);
 
   switch (htype) {
-    case BM_VERT:
-      chunksize = bm_mesh_chunksize_default.totvert;
+    case TM_VERTEX:
+      chunksize = 512;
       break;
-    case BM_EDGE:
-      chunksize = bm_mesh_chunksize_default.totedge;
+    case TM_EDGE:
+      chunksize = 1024;
       break;
-    case BM_LOOP:
-      chunksize = bm_mesh_chunksize_default.totloop;
+    case TM_LOOP:
+      chunksize = 2048;
       break;
-    case BM_FACE:
-      chunksize = bm_mesh_chunksize_default.totface;
+    case TM_TRI:
+      chunksize = 512;
       break;
     default:
       BLI_assert(0);
@@ -3305,8 +3307,135 @@ void CustomData_bmesh_init_pool(CustomData *data, int totelem, const char htype)
 
   /* If there are no layers, no pool is needed just yet */
   if (data->totlayer) {
-    data->pool = BLI_mempool_create(data->totsize, totelem, chunksize, BLI_MEMPOOL_NOP);
+    data->tpool = BLI_safepool_create(data->totsize, chunksize, tm->maxthread);
+  }
+}
+
+//XXX original code got axed in. . .copy/paste error? anyway, restore it from GIT later
+void CustomData_bmesh_init_pool(CustomData *data, int totelem, const char htype)
+{
+  int chunksize;
+
+  /* Dispose old pools before calling here to avoid leaks */
+  BLI_assert(data->tpool == NULL);
+
+  switch (htype) {
+  case BM_VERT:
+    chunksize = 512;
+    break;
+  case BM_EDGE:
+    chunksize = 1024;
+    break;
+  case BM_LOOP:
+    chunksize = 2048;
+    break;
+  case BM_FACE:
+    chunksize = 512;
+    break;
+  default:
+    BLI_assert(0);
+    chunksize = 512;
+    break;
   }
+
+  /* If there are no layers, no pool is needed just yet */
+  if (data->totlayer) {
+    data->tpool = BLI_safepool_create(data->totsize, chunksize, 1);
+  }
+}
+
+bool CustomData_trimesh_merge(const CustomData *source,
+  CustomData *dest,
+  CustomDataMask mask,
+  eCDAllocType alloctype,
+  TM_TriMesh *bm,
+  const char htype)
+{
+  TMElement *h;
+  TM_TriMeshIter iter;
+  CustomData destold;
+  void *tmp;
+  int iter_type;
+  int totelem;
+
+  if (CustomData_number_of_layers_typemask(source, mask) == 0) {
+    return false;
+  }
+
+  /* copy old layer description so that old data can be copied into
+  * the new allocation */
+  destold = *dest;
+  if (destold.layers) {
+    destold.layers = MEM_dupallocN(destold.layers);
+  }
+
+  if (CustomData_merge(source, dest, mask, alloctype, 0) == false) {
+    if (destold.layers) {
+      MEM_freeN(destold.layers);
+    }
+    return false;
+  }
+
+  switch (htype) {
+  case TM_VERTEX:
+    iter_type = TM_VERTS_OF_MESH;
+    totelem = bm->totvert;
+    break;
+  case TM_EDGE:
+    iter_type = TM_EDGES_OF_MESH;
+    totelem = bm->totedge;
+    break;
+  case BM_LOOP:
+    iter_type = -1;
+    totelem = bm->tottri*3;
+    break;
+  case BM_FACE:
+    iter_type = TM_TRIS_OF_MESH;
+    totelem = bm->tottri;
+    break;
+  default: /* should never happen */
+    BLI_assert(!"invalid type given");
+    iter_type = TM_VERTS_OF_MESH;
+    totelem = bm->totvert;
+    break;
+  }
+
+  dest->tpool = NULL;
+  CustomData_trimesh_init_pool(bm, dest, totelem, htype);
+
+  if (iter_type != -1) {
+    /*ensure all current elements follow new customdata layout*/
+
+    TM_ITER_MESH (h, &iter, bm, iter_type) {
+      tmp = NULL;
+      CustomData_bmesh_copy_data(&destold, dest, h->customdata, &tmp);
+      CustomData_bmesh_free_block(&destold, &h->customdata);
+      h->customdata = tmp;
+    }
+  }
+  else {
+    TMFace *f;
+    
+    /*ensure all current elements follow new customdata layout*/
+    TM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
+      for (int i=0; i<3; i++) {
+        TMLoopData *l = TM_GET_TRI_LOOP(f, i);
+
+        tmp = NULL;
+        CustomData_bmesh_copy_data(&destold, dest, l->customdata, &tmp);
+        CustomData_bmesh_free_block(&destold, &l->customdata);
+        l->customdata = tmp;
+      }
+    }
+  }
+
+  if (destold.tpool) {
+    BLI_safepool_destroy(destold.tpool);
+  }
+  if (destold.layers) {
+    MEM_freeN(destold.layers);
+  }
+  return true;
 }
 
 bool CustomData_bmesh_merge(const CustomData *source,
@@ -3365,7 +3494,7 @@ bool CustomData_bmesh_merge(const CustomData *source,
       break;
   }
 
-  dest->pool = NULL;
+  dest->tpool = NULL;
   CustomData_bmesh_init_pool(dest, totelem, htype);
 
   if (iter_type != BM_LOOPS_OF_FACE) {
@@ -3393,8 +3522,8 @@ bool CustomData_bmesh_merge(const CustomData *source,
     }
   }
 
-  if (destold.pool) {
-    BLI_mempool_destroy(destold.pool);
+  if (destold.tpool) {
+    BLI_safepool_destroy(destold.tpool);
   }
   if (destold.layers) {
     MEM_freeN(destold.layers);
@@ -3423,7 +3552,7 @@ void CustomData_bmesh_free_block(CustomData *data, void **block)
   }
 
   if (data->totsize) {
-    BLI_mempool_free(data->pool, *block);
+    BLI_safepool_free(data->tpool, *block);
   }
 
   *block = NULL;
@@ -3459,7 +3588,7 @@ static void CustomData_bmesh_alloc_block(CustomData *data, void **block)
   }
 
   if (data->totsize > 0) {
-    *block = BLI_mempool_alloc(data->pool);
+    *block = BLI_safepool_alloc(data->tpool);
   }
   else {
     *block = NULL;
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index dbdaea5f5aa..b91d058d0c5 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -1274,7 +1274,7 @@ static void sculptsession_tm_to_me_update_data_only(Object *ob, bool reorder)
 {
   SculptSession *ss = ob->sculpt;
 
-  if (ss->bm) {
+  if (ss->tm) 

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list