Tried to make pbvh bmesh normals calc a bit more efficient.
This commit is contained in:
parent
17fafe2f63
commit
27f4f761e7
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -138,6 +138,7 @@ struct PBVH {
|
|||
int totvert;
|
||||
|
||||
int leaf_limit;
|
||||
int depth_limit;
|
||||
|
||||
/* Mesh data */
|
||||
const struct Mesh *mesh;
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue