[Bf-blender-cvs] [27f4f761e79] temp_bmesh_multires: Tried to make pbvh bmesh normals calc a bit more efficient.
Joseph Eagar
noreply at git.blender.org
Sat May 15 20:51:31 CEST 2021
Commit: 27f4f761e79aa804e93ec175b75647a3cb379a4c
Author: Joseph Eagar
Date: Sat May 15 11:51:14 2021 -0700
Branches: temp_bmesh_multires
https://developer.blender.org/rB27f4f761e79aa804e93ec175b75647a3cb379a4c
Tried to make pbvh bmesh normals calc a bit more efficient.
===================================================================
M source/blender/blenkernel/intern/pbvh.c
M source/blender/blenkernel/intern/pbvh_bmesh.c
M source/blender/blenkernel/intern/pbvh_intern.h
M source/blender/editors/sculpt_paint/sculpt_dyntopo.c
===================================================================
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index c3e16f4a050..94ecfcc9796 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -52,6 +52,7 @@
#include <limits.h>
#define LEAF_LIMIT 4000
+#define LEAF_DEPTH_LIMIT 18
//#define PERFCNTRS
@@ -485,13 +486,15 @@ static bool leaf_needs_material_split(PBVH *pbvh, int offset, int count)
* offset and start indicate a range in the array of primitive indices
*/
-static void build_sub(PBVH *pbvh, int node_index, BB *cb, BBC *prim_bbc, int offset, int count)
+static void build_sub(
+ PBVH *pbvh, int node_index, BB *cb, BBC *prim_bbc, int offset, int count, int depth)
{
int end;
BB cb_backing;
/* Decide whether this is a leaf or not */
- const bool below_leaf_limit = count <= pbvh->leaf_limit;
+ const bool below_leaf_limit = count <= pbvh->leaf_limit || depth >= pbvh->depth_limit;
+
if (below_leaf_limit) {
if (!leaf_needs_material_split(pbvh, offset, count)) {
build_leaf(pbvh, node_index, prim_bbc, offset, count);
@@ -531,13 +534,20 @@ static void build_sub(PBVH *pbvh, int node_index, BB *cb, BBC *prim_bbc, int off
}
/* Build children */
- build_sub(pbvh, pbvh->nodes[node_index].children_offset, NULL, prim_bbc, offset, end - offset);
+ build_sub(pbvh,
+ pbvh->nodes[node_index].children_offset,
+ NULL,
+ prim_bbc,
+ offset,
+ end - offset,
+ depth + 1);
build_sub(pbvh,
pbvh->nodes[node_index].children_offset + 1,
NULL,
prim_bbc,
end,
- offset + count - end);
+ offset + count - end,
+ depth + 1);
}
static void pbvh_build(PBVH *pbvh, BB *cb, BBC *prim_bbc, int totprim)
@@ -562,7 +572,7 @@ static void pbvh_build(PBVH *pbvh, BB *cb, BBC *prim_bbc, int totprim)
}
pbvh->totnode = 1;
- build_sub(pbvh, 0, cb, prim_bbc, 0, totprim);
+ build_sub(pbvh, 0, cb, prim_bbc, 0, totprim, 0);
}
/**
@@ -595,6 +605,8 @@ void BKE_pbvh_build_mesh(PBVH *pbvh,
pbvh->vert_bitmap = BLI_BITMAP_NEW(totvert, "bvh->vert_bitmap");
pbvh->totvert = totvert;
pbvh->leaf_limit = LEAF_LIMIT;
+ pbvh->depth_limit = LEAF_DEPTH_LIMIT;
+
pbvh->vdata = vdata;
pbvh->ldata = ldata;
pbvh->pdata = pdata;
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c
index 6987d760384..0b812bdaa99 100644
--- a/source/blender/blenkernel/intern/pbvh_bmesh.c
+++ b/source/blender/blenkernel/intern/pbvh_bmesh.c
@@ -3263,7 +3263,36 @@ static void pbvh_update_normals_task_cb(void *__restrict userdata,
TGSET_ITER_END
TGSET_ITER (v, node->bm_unique_verts) {
- BM_vert_normal_update(v);
+ // BM_vert_normal_update(v);
+ // optimized loop
+ BMEdge *e = v->e;
+
+ zero_v3(v->no);
+
+ if (!e) {
+ continue;
+ }
+
+ do {
+ BMLoop *l = e->l;
+
+ if (!l) {
+ e = v == e->v1 ? e->v1_disk_link.next : e->v2_disk_link.next;
+ continue;
+ }
+
+ do {
+ v->no[0] += l->f->no[0];
+ v->no[1] += l->f->no[1];
+ v->no[2] += l->f->no[2];
+
+ l = l->radial_next;
+ } while (l != e->l);
+
+ e = v == e->v1 ? e->v1_disk_link.next : e->v2_disk_link.next;
+ } while (e != v->e);
+
+ normalize_v3(v->no);
}
TGSET_ITER_END
@@ -3557,6 +3586,8 @@ void BKE_pbvh_build_bmesh(PBVH *pbvh,
pbvh->cd_vcol_offset = CustomData_get_offset(&bm->vdata, CD_PROP_COLOR);
pbvh->cd_faceset_offset = CustomData_get_offset(&bm->pdata, CD_SCULPT_FACE_SETS);
+ pbvh->depth_limit = 18;
+
/* TODO: choose leaf limit better */
pbvh->leaf_limit = 1000;
diff --git a/source/blender/blenkernel/intern/pbvh_intern.h b/source/blender/blenkernel/intern/pbvh_intern.h
index 5ab446c6f13..d3b45d8e8d3 100644
--- a/source/blender/blenkernel/intern/pbvh_intern.h
+++ b/source/blender/blenkernel/intern/pbvh_intern.h
@@ -138,6 +138,7 @@ struct PBVH {
int totvert;
int leaf_limit;
+ int depth_limit;
/* Mesh data */
const struct Mesh *mesh;
diff --git a/source/blender/editors/sculpt_paint/sculpt_dyntopo.c b/source/blender/editors/sculpt_paint/sculpt_dyntopo.c
index 4bc8e7ff955..f11cb0d884e 100644
--- a/source/blender/editors/sculpt_paint/sculpt_dyntopo.c
+++ b/source/blender/editors/sculpt_paint/sculpt_dyntopo.c
@@ -92,8 +92,12 @@ void SCULPT_reorder_bmesh(SculptSession *ss)
SCULPT_face_random_access_ensure(ss);
SCULPT_vertex_random_access_ensure(ss);
- int actv = ss->active_vertex_index.i ? BKE_pbvh_vertex_index_to_table(ss->pbvh, ss->active_vertex_index) : -1;
- int actf =ss->active_face_index.i ? BKE_pbvh_face_index_to_table(ss->pbvh, ss->active_face_index) : -1;
+ int actv = ss->active_vertex_index.i ?
+ BKE_pbvh_vertex_index_to_table(ss->pbvh, ss->active_vertex_index) :
+ -1;
+ int actf = ss->active_face_index.i ?
+ BKE_pbvh_face_index_to_table(ss->pbvh, ss->active_face_index) :
+ -1;
if (ss->bm_log) {
BM_log_full_mesh(ss->bm, ss->bm_log);
@@ -110,7 +114,7 @@ void SCULPT_reorder_bmesh(SculptSession *ss)
if (actf >= 0) {
ss->active_face_index = BKE_pbvh_table_index_to_face(ss->pbvh, actf);
}
-
+
SCULPT_dyntopo_node_layers_update_offsets(ss);
if (ss->bm_log) {
More information about the Bf-blender-cvs
mailing list