[Bf-blender-cvs] [d26b8c0e2a4] temp-trimesh-sculpt: moved trimesh into its own folder, source/blender/trimesh

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


Commit: d26b8c0e2a46adecdb4d1eed782307c0f0bd6ed0
Author: Joseph Eagar
Date:   Tue Sep 29 20:06:32 2020 -0700
Branches: temp-trimesh-sculpt
https://developer.blender.org/rBd26b8c0e2a46adecdb4d1eed782307c0f0bd6ed0

moved trimesh into its own folder, source/blender/trimesh

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

M	source/blender/CMakeLists.txt
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/paint.c
M	source/blender/blenkernel/intern/pbvh_trimesh.c
M	source/blender/blenlib/CMakeLists.txt
R073	source/blender/blenlib/intern/BLI_trimesh.c	source/blender/trimesh/intern/trimesh.c
R098	source/blender/blenlib/BLI_trimesh.h	source/blender/trimesh/trimesh.h

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

diff --git a/source/blender/CMakeLists.txt b/source/blender/CMakeLists.txt
index 203b6da272f..46f7b24f618 100644
--- a/source/blender/CMakeLists.txt
+++ b/source/blender/CMakeLists.txt
@@ -98,6 +98,7 @@ add_subdirectory(editors)
 add_subdirectory(windowmanager)
 add_subdirectory(blenkernel)
 add_subdirectory(blenlib)
+add_subdirectory(trimesh)
 add_subdirectory(bmesh)
 add_subdirectory(draw)
 add_subdirectory(render)
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 6233de63d22..2aed99caa37 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -25,6 +25,7 @@ set(INC
   ../blenloader
   ../blentranslation
   ../bmesh
+  ../trimesh
   ../depsgraph
   ../draw
   ../gpencil_modifiers
@@ -403,6 +404,7 @@ set(LIB
   bf_blenloader
   bf_blentranslation
   bf_bmesh
+  bf_trimesh
   bf_depsgraph
   bf_draw
   bf_gpencil_modifiers
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index cfd7d758d91..dbdaea5f5aa 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -74,7 +74,7 @@
 #include "RNA_enum_types.h"
 
 #include "bmesh.h"
-#include "BLI_trimesh.h"
+#include "trimesh.h"
 
 static void palette_init_data(ID *id)
 {
diff --git a/source/blender/blenkernel/intern/pbvh_trimesh.c b/source/blender/blenkernel/intern/pbvh_trimesh.c
index c0869088d87..dfd670faaab 100644
--- a/source/blender/blenkernel/intern/pbvh_trimesh.c
+++ b/source/blender/blenkernel/intern/pbvh_trimesh.c
@@ -28,7 +28,7 @@
 #include "BLI_utildefines.h"
 
 #include "BLI_threadsafe_mempool.h"
-#include "BLI_trimesh.h"
+#include "trimesh.h"
 
 #include "BKE_DerivedMesh.h"
 #include "BKE_ccg.h"
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index 61cfd78f966..db1bee1a4fa 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -40,7 +40,6 @@ set(SRC
   intern/BLI_dial_2d.c
   intern/BLI_dynstr.c
   intern/BLI_filelist.c
-  intern/BLI_trimesh.c
   intern/BLI_ghash.c
   intern/BLI_ghash_utils.c
   intern/BLI_heap.c
diff --git a/source/blender/blenlib/intern/BLI_trimesh.c b/source/blender/trimesh/intern/trimesh.c
similarity index 73%
rename from source/blender/blenlib/intern/BLI_trimesh.c
rename to source/blender/trimesh/intern/trimesh.c
index 0e88272ae68..d201dfaea92 100644
--- a/source/blender/blenlib/intern/BLI_trimesh.c
+++ b/source/blender/trimesh/intern/trimesh.c
@@ -18,7 +18,7 @@
  */
 
  /** \file
-  * \ingroup bli
+  * \ingroup trimesh
   *
   * optimized thread-safe triangle mesh library with topological info
   *
@@ -30,7 +30,7 @@
 #include "BLI_listbase.h"
 
 #include "BLI_math.h"
-#include "BLI_trimesh.h"
+#include "trimesh.h"
 #include "BLI_threadsafe_mempool.h"
 #include "BLI_array.h"
 
@@ -57,33 +57,8 @@
 #  include "valgrind/memcheck.h"
 #endif
 
+#include "trimesh_private.h"
 
-#define TRIVERT(tri, n) ((&(tri)->v1)[n])
-#define TRIEDGE(tri, n) ((&(tri)->e1)[n])
-
-#define TRILOOP(tri, n) ((&(tri)->l1)[n])
-
-enum {
-  TM_VERTEX = 1,
-  TM_EDGE = 2,
-  TM_LOOP = 4,
-  TM_TRI = 8
-};
-
-enum {
-POOL_VERTEX = 0,
-POOL_EDGE = 1,
-//POOL_LOOP = 2,
-POOL_TRI = 2,
-POOL_ELIST = 3, //pool for lists of edges around vertices
-POOL_TLIST = 4, //pool for lists of triangles around edges
-#ifdef WITH_TRIMESH_CUSTOMDATA
-POOL_LOOP = 5
-#endif
-};
-
-#define V_ELIST_ESIZE 5
-#define E_TLIST_ESIZE 2
 
 //keep up to sync with MAX_TRIMESH_POOLS in BLI_trimesh.h
 static int poolsizes[] = {
@@ -92,39 +67,23 @@ static int poolsizes[] = {
   sizeof(TMFace),
   sizeof(void*)*V_ELIST_ESIZE,
   sizeof(void*)*E_TLIST_ESIZE,
-#ifdef WITH_TRIMESH_CUSTOMDATA
   sizeof(TMLoopData)
-#endif
 };
 
-#ifdef WITH_TRIMESH_CUSTOMDATA
 void trimesh_element_init(void *elem, CustomData *customdata) {
-#else
-void trimesh_element_init(void *elem) {
-#endif
 
-#ifdef WITH_TRIMESH_CUSTOMDATA
   TMElement *e = elem;
 
   CustomData_bmesh_set_default(customdata, &e->customdata);
-#endif
 }
 
-#ifdef WITH_TRIMESH_CUSTOMDATA
 void trimesh_element_destroy(void *elem, int threadnr, CustomData *customdata) {
-#else
-void trimesh_element_destroy(void *elem, int threadnr) {
-#endif
-
-#ifdef WITH_TRIMESH_CUSTOMDATA
   TMElement *e = elem;
 
   CustomData_bmesh_free_block(customdata, &e->customdata);
-#endif
 }
 
-#ifdef WITH_TRIMESH_CUSTOMDATA
-static TMLoopData *trimesh_make_loop(TM_TriMesh *tm, int threadnr) {
+static TMLoopData *trimesh_make_loop(TM_TriMesh *tm, int threadnr, bool skipcd) {
   TMLoopData *loop = BLI_safepool_alloc(tm->pools[POOL_LOOP], threadnr);
   trimesh_element_init(loop, &tm->ldata);
 
@@ -134,7 +93,6 @@ static TMLoopData *trimesh_make_loop(TM_TriMesh *tm, int threadnr) {
 static void trimesh_kill_loop(TM_TriMesh *tm, TMLoopData *l, int threadnr) {
   trimesh_element_destroy(l, threadnr, &tm->ldata);
 }
-#endif
 
 TM_TriMesh* TMesh_new(int maxthread) {
   TM_TriMesh* tm = MEM_callocN(sizeof(*tm), "OptTriMesh");
@@ -147,56 +105,6 @@ TM_TriMesh* TMesh_new(int maxthread) {
   return tm;
 }
 
-
-static void simplelist_remove(TM_TriMesh *tm, optmesh_simplelist *list, void *item, int pool, int threadnr) {
-  if (list->length == 0) {
-    return;
-  }
-
-  for (int i=0; i<list->length; i++) {
-    if (list->items[i] == item) {
-      while (i < list->length-1) {
-        list->items[i] = list->items[i+1];
-      }
-
-      list->items[list->length-1] = NULL;
-      list->length--;
-
-      return;
-    }
-  }
-}
-
-static void simplelist_free(TM_TriMesh *tm, optmesh_simplelist *list, int pool, int threadnr) {
-  if (list->is_pool_allocd) {
-    BLI_safepool_free(tm->pools[pool], list->items);
-  } else {
-    MEM_freeN(list->items);
-  }
-}
-
-static void simplelist_append(TM_TriMesh* tm, optmesh_simplelist* list, void *item, int pool, int threadnr) {
-  list->length++;
-
-  if (list->length > list->_size) {
-    if (list->is_pool_allocd) {
-      list->is_pool_allocd = false;
-
-      void **items = MEM_mallocN(sizeof(void*)*list->_size*2, "simplelist_append");
-      memcpy(items, list->items, sizeof(void*)*list->_size);
-
-      BLI_safepool_threaded_free(tm->pools[pool], list->items, threadnr);
-      list->items = items;
-    } else {
-      list->items = MEM_reallocN(list->items, sizeof(void*)*list->_size*2);
-    }
-
-    list->_size *= 2;
-  }
-
-  list->items[list->length-1] = item;
-}
-
 #define OTHER_VERT(e, v) ((v) == (e)->v1 ? (e)->v2 : (e)->v1)
 
 static TMEdge *ensure_edge(TM_TriMesh* tm, TMVert* v1, TMVert* v2, int threadnr, bool skipcd) {
@@ -214,14 +122,10 @@ static TMEdge *ensure_edge(TM_TriMesh* tm, TMVert* v1, TMVert* v2, int threadnr,
   e->v1 = v1;
   e->v2 = v2;
 
-  simplelist_append(tm, &e->v1->edges, e, POOL_ELIST, threadnr);
-  simplelist_append(tm, &e->v2->edges, e, POOL_ELIST, threadnr);
+  trilist_simplelist_append(tm, &e->v1->edges, e, POOL_ELIST, threadnr);
+  trilist_simplelist_append(tm, &e->v2->edges, e, POOL_ELIST, threadnr);
 
-#ifdef WITH_TRIMESH_CUSTOMDATA
   trimesh_element_init(e, &tm->edata);
-#else
-  trimesh_element_init(e);
-#endif
 
   return e;
 }
@@ -253,7 +157,7 @@ void *TM_iterstep(TM_TriMeshIter* iter) {
 
 static TMEdge *edge_add_tri(TM_TriMesh* tm, TMVert* v1, TMVert* v2, TMFace* tri, int threadnr, bool skipcd) {
   TMEdge *e = ensure_edge(tm, v1, v2, threadnr, skipcd);
-  simplelist_append(tm, &e->tris, tri, POOL_TLIST, threadnr);
+  trilist_simplelist_append(tm, &e->tris, tri, POOL_TLIST, threadnr);
 
   return e;
 }
@@ -261,11 +165,7 @@ static TMEdge *edge_add_tri(TM_TriMesh* tm, TMVert* v1, TMVert* v2, TMFace* tri,
 TMVert *TM_make_vert(TM_TriMesh *tm, float co[3], float no[3], int threadnr, bool skipcd) {
   TMVert *v = BLI_safepool_alloc(tm->pools[POOL_VERTEX], threadnr);
 
-#ifdef WITH_TRIMESH_CUSTOMDATA
   trimesh_element_init(v, &tm->vdata);
-#else
-  trimesh_element_init(v);
-#endif
 
   memset(v, 0, sizeof(*v));
 
@@ -282,17 +182,11 @@ TMFace *TM_make_tri(TM_TriMesh *tm, TMVert *v1, TMVert *v2, TMVert *v3, int thre
 
   memset(tri, 0, sizeof(*tri));
 
-#ifdef WITH_TRIMESH_CUSTOMDATA
   trimesh_element_init(tri, &tm->tdata);
-#else
-  trimesh_element_init(tri);
-#endif
 
-#ifdef WITH_TRIMESH_CUSTOMDATA
   tri->l1 = trimesh_make_loop(tm, threadnr, skipcd);
   tri->l2 = trimesh_make_loop(tm, threadnr, skipcd);
   tri->l3 = trimesh_make_loop(tm, threadnr, skipcd);
-#endif
 
   tri->v1 = v1;
   tri->v2 = v2;
@@ -339,233 +233,6 @@ void TM_add(TM_TriMesh *tm, float* vertCos, float* vertNos, int totvert, int* tr
 }
 
 
-//we do somewhat weird things with stack, it's returned by this function
-static void **trimesh_tag_step(TM_TriMesh* tm, TMVert* v, void** stack, int tag, int maxelem) {
-  BLI_array_declare(stack);
-
-  v->threadtag = tag;
-  int totelem = 0;
-
-  for (int i = 0; i < v->edges.length; i++) {
-    TMEdge *e = v->edges.items[i];
-
-    for (int j = 0; j < e->tris.length; j++) {
-      TMFace *tri = e->tris.items[j];
-
-      if (tri->threadtag == TRIMESH_NEED_TAG) {
-        tri->threadtag = tag;
-        BLI_array_append(stack, tri);
-        totelem++;
-      }
-    }
-  }
-
-  int len = BLI_array_len(stack);
-  for (; len && totelem < maxelem; len = BLI_array_len(stack)) {
-    TMFace *tri = BLI_array_pop(stack);
-
-    for (int i = 0; i < 3; i++) {
-      TMEdge *e = i == 0 ? tri->e1 : (i == 1 ? tri->e2 : tri->e3);
-
-      for (int j = 0; j < e->tris.length; j++) {
-        TMFace *tri2 = e->tris.items[j];
-
-        if (tri2->threadtag == TRIMESH_NEED_TAG) {
-          tri2->threadtag = tag;
-          totelem++;
-          BLI_array_append(stack, tri2);
-        }
-      }
-    }
-  }
-
-  return stack;
-}
-
-//if tottris is -1 then all triangles will be tagged
-void TM_thread_tag(TM_TriMesh *tm, TMFace** tris, int tottri) {
-  void **stack = NULL;
-  BLI_array_declare(stack);
-
-  if (tottri == -1) {
-    int maxtag = MAX2(tm->tottri / tm->maxthread, 1);
-
-    ThreadSafePoolIter iter;
-
-    BLI_safepool_iternew(tm->pools[POOL_TRI], &iter);
-    TMFace *t = BLI_safepool_iterstep(&iter);
-    for (; t; t = BLI_safepool_iterstep(&iter)) {
-      t->threadtag = TRIMESH_NEED_TAG;
-    }
-    BLI_safepool_iterfree(&iter);
-
-    bool stop = false;
-
-    int ta

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list