[Bf-blender-cvs] [9d09011f916] sculpt-dev: Sculpt-dev: part 2 of dyntopo cleanup

Joseph Eagar noreply at git.blender.org
Tue Feb 1 04:04:54 CET 2022


Commit: 9d09011f9167d44061dd4f21a3a078404da7a8e6
Author: Joseph Eagar
Date:   Mon Jan 31 19:03:47 2022 -0800
Branches: sculpt-dev
https://developer.blender.org/rB9d09011f9167d44061dd4f21a3a078404da7a8e6

Sculpt-dev: part 2 of dyntopo cleanup

Code is now much cleaner, at least
relative to before.  Still need to test
local mode.

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

M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/blenkernel/intern/dyntopo.c
M	source/blender/blenkernel/intern/pbvh_bmesh.c
M	source/blender/bmesh/intern/bmesh_log.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index f62293deebf..e00114c0f22 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -487,7 +487,7 @@ class VIEW3D_PT_tools_brush_settings_advanced_sculpt(Panel, View3DPaintBrushPane
         if context.mode != 'SCULPT':
           return False
 
-        return View3DPaintBrushPanel.poll(cls, context)
+        return View3DPaintBrushPanel.poll(context)
 
     def draw(self, context):
         layout = self.layout
diff --git a/source/blender/blenkernel/intern/dyntopo.c b/source/blender/blenkernel/intern/dyntopo.c
index eff61fc2878..ce808fb593e 100644
--- a/source/blender/blenkernel/intern/dyntopo.c
+++ b/source/blender/blenkernel/intern/dyntopo.c
@@ -35,7 +35,7 @@
 
 #include <stdio.h>
 
-#define DYNTOPO_REPORT
+//#define DYNTOPO_REPORT
 //#define WITH_ADAPTIVE_CURVATURE
 //#define DYNTOPO_NO_THREADING
 
@@ -1376,36 +1376,7 @@ static void pbvh_bmesh_edge_loops(BLI_Buffer *buf, BMEdge *e)
 
 struct EdgeQueue;
 
-typedef struct EdgePair {
-  BMVert *v1, *v2;
-  float limit_len_squared;
-} EdgePair;
-
-typedef struct EdgeQueue {
-  HeapSimple *heap;
-
-  void **elems;
-  int totelems;
-
-  const float *center;
-  float center_proj[3]; /* for when we use projected coords. */
-  float radius_squared;
-  float limit_len_squared;
-#ifdef USE_EDGEQUEUE_EVEN_SUBDIV
-  float limit_len;
-#endif
-
-  bool (*edge_queue_tri_in_range)(const struct EdgeQueue *q, BMVert *vs[3], float no[3]);
-  bool (*edge_queue_vert_in_range)(const struct EdgeQueue *q, BMVert *v);
-
-  const float *view_normal;
-#ifdef USE_EDGEQUEUE_FRONTFACE
-  unsigned int use_view_normal : 1;
-#endif
-} EdgeQueue;
-
 typedef struct EdgeQueueContext {
-  EdgeQueue *q;
   BLI_mempool *pool;
   BMesh *bm;
   DyntopoMaskCB mask_cb;
@@ -1418,9 +1389,6 @@ typedef struct EdgeQueueContext {
   float max_elen;
   float min_elen;
   float totedge;
-  BMVert **val34_verts;
-  int val34_verts_tot;
-  int val34_verts_size;
   bool local_mode;
   float surface_smooth_fac;
 
@@ -1430,15 +1398,61 @@ typedef struct EdgeQueueContext {
   float view_normal[3];
   bool use_view_normal;
   float limit_min, limit_max, limit_mid;
+
+  const float *center;
+  float center_proj[3]; /* for when we use projected coords. */
+  float radius_squared;
+  float limit_len;
+  float limit_len_squared;
+
+  bool (*edge_queue_tri_in_range)(const struct EdgeQueueContext *q, BMVert *vs[3], float no[3]);
+  bool (*edge_queue_vert_in_range)(const struct EdgeQueueContext *q, BMVert *v);
+
+  PBVHTopologyUpdateMode mode;
 } EdgeQueueContext;
 
+static float maskcb_get(EdgeQueueContext *eq_ctx, BMVert *v1, BMVert *v2)
+{
+  if (eq_ctx->mask_cb) {
+    SculptVertRef sv1 = {(intptr_t)v1};
+    SculptVertRef sv2 = {(intptr_t)v2};
+
+    float w1 = eq_ctx->mask_cb(sv1, eq_ctx->mask_cb_data);
+    float w2 = eq_ctx->mask_cb(sv2, eq_ctx->mask_cb_data);
+
+    //float limit = 0.5;
+    //if (w1 > limit || w2 > limit) {
+      return min_ff(w1, w2);
+    //}
+
+    return (w1 + w2) * 0.5f;
+  }
+
+  return 1.0f;
+}
+
+BLI_INLINE float calc_edge_length(EdgeQueueContext *eq_ctx, BMVert *v1, BMVert *v2)
+{
+  return len_squared_v3v3(v1->co, v2->co);
+}
+
+BLI_INLINE float calc_weighted_length(EdgeQueueContext *eq_ctx, BMVert *v1, BMVert *v2, float sign)
+{
+  float w = 1.0 - maskcb_get(eq_ctx, v1, v2);
+  float len = len_squared_v3v3(v1->co, v2->co);
+
+  w = 1.0 + w*sign;
+
+  return len * w;
+}
+
 static void edge_queue_insert_unified(EdgeQueueContext *eq_ctx, BMEdge *e)
 {
   if (/*BLI_mm_heap_len(eq_ctx->heap_mm) < eq_ctx->max_heap_mm &&*/ !(e->head.hflag &
                                                                       BM_ELEM_TAG)) {
     float len = len_squared_v3v3(e->v1->co, e->v2->co);
 
-    len += (BLI_thread_frand(0)-0.5f)*0.1*eq_ctx->limit_mid;
+    len += (BLI_thread_frand(0) - 0.5f) * 0.1 * eq_ctx->limit_mid;
 
     BLI_mm_heap_insert(eq_ctx->heap_mm, len, e);
     e->head.hflag |= BM_ELEM_TAG;
@@ -1455,46 +1469,10 @@ static void edge_queue_insert_val34_vert(EdgeQueueContext *eq_ctx, BMVert *v)
   }
 
   mv->flag |= SCULPTVERT_VALENCE_TEMP;
-
-  eq_ctx->val34_verts_tot++;
-
-  if (eq_ctx->val34_verts_tot > eq_ctx->val34_verts_size) {
-    int size2 = 4 + eq_ctx->val34_verts_tot + (eq_ctx->val34_verts_tot >> 1);
-
-    if (eq_ctx->val34_verts) {
-      eq_ctx->val34_verts = MEM_reallocN(eq_ctx->val34_verts, sizeof(void *) * size2);
-    }
-    else {
-      eq_ctx->val34_verts = MEM_mallocN(sizeof(void *) * size2, "val34_verts");
-    }
-
-    eq_ctx->val34_verts_size = size2;
-  }
-
-  eq_ctx->val34_verts[eq_ctx->val34_verts_tot - 1] = v;
-}
-
-static float maskcb_get(EdgeQueueContext *eq_ctx, BMEdge *e)
-{
-  float ret = 0.0f;
-
-  if (eq_ctx->mask_cb) {
-    SculptVertRef sv1 = {(intptr_t)e->v1};
-    SculptVertRef sv2 = {(intptr_t)e->v2};
-
-    float w1 = eq_ctx->mask_cb(sv1, eq_ctx->mask_cb_data);
-    float w2 = eq_ctx->mask_cb(sv2, eq_ctx->mask_cb_data);
-
-    ret = (w1 + w2) * 0.5f;
-  }
-  else {
-    ret = 1.0f;
-  }
-
-  return ret;
+  BLI_table_gset_add(eq_ctx->used_verts, v);
 }
 
-static float calc_weighted_edge_split(EdgeQueueContext *eq_ctx, BMVert *v1, BMVert *v2)
+BLI_INLINE float calc_curvature_weight(EdgeQueueContext *eq_ctx, BMVert *v1, BMVert *v2)
 {
 #ifdef WITH_ADAPTIVE_CURVATURE
   MSculptVert *mv1 = BKE_PBVH_SCULPTVERT(eq_ctx->cd_sculpt_vert, v1);
@@ -1505,71 +1483,16 @@ static float calc_weighted_edge_split(EdgeQueueContext *eq_ctx, BMVert *v1, BMVe
   float fac = 1.0f + powf((c1 + c2) * 100.0, 4.0f);
   fac = min_ff(fac, 4.0f);
 
-  return fac * len_squared_v3v3(v1->co, v2->co);
+  return fac;
 #else
-  return len_squared_v3v3(v1->co, v2->co);
+  return 1.0;
 #endif
 }
 
-BLI_INLINE float calc_weighted_edge_collapse(EdgeQueueContext *eq_ctx, BMVert *v1, BMVert *v2)
-{
-  float len_sq = len_squared_v3v3(v1->co, v2->co);
-
-#if 1  // this rule here seems to improve topology, but need to study it more
-  MSculptVert *mv1 = BKE_PBVH_SCULPTVERT(eq_ctx->cd_sculpt_vert, v1);
-  MSculptVert *mv2 = BKE_PBVH_SCULPTVERT(eq_ctx->cd_sculpt_vert, v2);
-
-  if (mv1->valence == 5 && mv2->valence == 5) {
-    len_sq *= 0.25;
-  }
-#endif
-
-  return len_sq;
-}
-
-/* only tag'd edges are in the queue */
-#ifdef USE_EDGEQUEUE_TAG
-#  define EDGE_QUEUE_TEST(e) (BM_elem_flag_test((CHECK_TYPE_INLINE(e, BMEdge *), e), BM_ELEM_TAG))
-#  define EDGE_QUEUE_ENABLE(e) \
-    BM_elem_flag_enable((CHECK_TYPE_INLINE(e, BMEdge *), e), BM_ELEM_TAG)
-#  define EDGE_QUEUE_DISABLE(e) \
-    BM_elem_flag_disable((CHECK_TYPE_INLINE(e, BMEdge *), e), BM_ELEM_TAG)
-#endif
-
-#ifdef USE_EDGEQUEUE_TAG_VERIFY
-/* simply check no edges are tagged
- * (it's a requirement that edges enter and leave a clean tag state) */
-static void pbvh_bmesh_edge_tag_verify(PBVH *pbvh)
-{
-  for (int n = 0; n < pbvh->totnode; n++) {
-    PBVHNode *node = &pbvh->nodes[n];
-    if (node->bm_faces) {
-      GSetIterator gs_iter;
-      GSET_ITER (gs_iter, node->bm_faces) {
-        BMFace *f = BLI_gsetIterator_getKey(&gs_iter);
-        BMEdge *e_tri[3];
-        BMLoop *l_iter;
-
-        BLI_assert(f->len == 3);
-        l_iter = BM_FACE_FIRST_LOOP(f);
-        e_tri[0] = l_iter->e;
-        l_iter = l_iter->next;
-        e_tri[1] = l_iter->e;
-        l_iter = l_iter->next;
-        e_tri[2] = l_iter->e;
-
-        BLI_assert((EDGE_QUEUE_TEST(e_tri[0]) == false) && (EDGE_QUEUE_TEST(e_tri[1]) == false) &&
-                   (EDGE_QUEUE_TEST(e_tri[2]) == false));
-      }
-    }
-  }
-}
-#endif
-
-static bool edge_queue_vert_in_sphere(const EdgeQueue *q, BMVert *v)
+static bool edge_queue_vert_in_sphere(const EdgeQueueContext *eq_ctx, BMVert *v)
 {
   /* Check if triangle intersects the sphere */
-  return len_squared_v3v3(q->center, v->co) <= q->radius_squared;
+  return len_squared_v3v3(eq_ctx->center, v->co) <= eq_ctx->radius_squared;
 }
 
 /*
@@ -1724,7 +1647,7 @@ static bool bm_elem_is_free(BMElem *elem, int htype)
   return ret;
 }
 
-static bool edge_queue_tri_in_sphere(const EdgeQueue *q, BMVert *vs[3], float no[3])
+static bool edge_queue_tri_in_sphere(const EdgeQueueContext *q, BMVert *vs[3], float no[3])
 {
 #if 0
   float cent[3];
@@ -1749,7 +1672,7 @@ static bool edge_queue_tri_in_sphere(const EdgeQueue *q, BMVert *vs[3], float no
   return dis <= q->radius_squared;
 }
 
-static bool edge_queue_tri_in_circle(const EdgeQueue *q, BMVert *v_tri[3], float no[3])
+static bool edge_queue_tri_in_circle(const EdgeQueueContext *q, BMVert *v_tri[3], float no[3])
 {
   float c[3];
   float tri_proj[3][3];
@@ -1768,8 +1691,6 @@ typedef struct EdgeQueueThreadData {
   PBVH *pbvh;
   PBVHNode *node;
   BMEdge **edges;
-  BMVert **val34_verts;
-  int val34_verts_tot;
   EdgeQueueContext *eq_ctx;
   int totedge;
   int size;
@@ -1802,75 +1723,15 @@ static void edge_thread_data_insert(EdgeQueueThreadData *tdata, BMEdge *e)
   tdata->totedge++;
 }
 
-static bool edge_queue_vert_in_circle(const EdgeQueue *q, BMVert *v)
+static bool edge_queue_vert_in_circle(const EdgeQueueContext *eq_ctx, BMVert *v)
 {
   float c[3];
 
-  project_plane_normalized_v3_v3v3(c, v->co, q->view_normal);
-
-  return len_squared_v3v3(q->center_proj, c) <= q->radius_squared;
-}
-
-static void edge_queue_insert(EdgeQueueContext *eq_ctx, BMEdge *e, float priority, float limit)
-{
-  void **elems = eq_ctx->q->elems;
-  BLI_array_declare(elems);
-  BLI_array_len_set(elems, eq_ctx->q->totelems);
-
-  if (eq_ctx->cd_vert_mask_offset == -1 ||
-      !((e->v1->head.hflag | e->v2->head.hflag) & BM_ELEM_HIDDEN)) {
-    float dis = len_v3v3(e->v1->co, e->v2->co);
-    eq_ctx->avg_elen += dis;
-    eq_ctx->max_elen = MAX2(eq_ctx->max_elen, dis);
-    eq_ctx->min_elen = MIN2(eq_ctx->min_elen, dis);
-    eq_ctx->totedge += 1.0f;
-
-    EdgePair *pair = BLI_mempool_alloc(eq_ctx->pool);
-
-    pair->v1 = e->v1;
-    pair->v2 = e->v2;
-    pair->limit_len_squared = limit * limit;
-
-#ifdef DYNTOPO_USE_MINMAX_HEAP
-
-#endif
-
-#ifdef DYNTOPO_USE_HEAP
-    BLI_heapsimple_insert(eq_ctx->q->heap, priority, pair);
-#endif
-#ifdef DYNTOPO_USE_MINMAX_HEAP
-    edge_queue_insert_unified(eq_ctx, e);
-    BLI_table

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list