diff options
author | Antony Riakiotakis <kalast@gmail.com> | 2013-08-19 21:37:21 +0400 |
---|---|---|
committer | Antony Riakiotakis <kalast@gmail.com> | 2013-08-19 21:37:21 +0400 |
commit | 789ee1bfccbdf5be842c91b7c60334a06f3dc4c9 (patch) | |
tree | 8aee99417d21883c141684547b1357bcc6c0b41f /source/blender/blenkernel/intern | |
parent | 16ed997d21595c5af413da84df933bd5bb599163 (diff) |
Dyntopo:
* Actually check if normal recalculation flags exists and set it when
splitting nodes in dyntopo. Right now, nodes that need GPU buffer update
will always get in the list to get their normals generated, but to avoid
a possible future breakage better do it right now.
* Avoid keeping deleted/removed vertices in vertex-to-node and unique
vertex hashes, since some checks rely on those and may go awry if these
still exist. Also they pollute the hashes, and may hurt performance
somewhat.
Diffstat (limited to 'source/blender/blenkernel/intern')
-rw-r--r-- | source/blender/blenkernel/intern/pbvh_bmesh.c | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c index e5cbe64abc0..4d68336e66f 100644 --- a/source/blender/blenkernel/intern/pbvh_bmesh.c +++ b/source/blender/blenkernel/intern/pbvh_bmesh.c @@ -92,7 +92,7 @@ static void pbvh_bmesh_node_finalize(PBVH *bvh, int node_index) if (!G.background) { int smooth = bvh->flags & PBVH_DYNTOPO_SMOOTH_SHADING; n->draw_buffers = GPU_build_bmesh_buffers(smooth); - n->flag |= PBVH_UpdateDrawBuffers; + n->flag |= PBVH_UpdateDrawBuffers | PBVH_UpdateNormals; } } @@ -386,6 +386,7 @@ static void pbvh_bmesh_vert_remove(PBVH *bvh, BMVert *v) BLI_assert(BLI_ghash_haskey(bvh->bm_vert_to_node, v)); v_node = pbvh_bmesh_node_lookup(bvh, bvh->bm_vert_to_node, v); + BLI_ghash_remove(bvh->bm_vert_to_node, v, NULL, NULL); BLI_ghash_remove(v_node->bm_unique_verts, v, NULL, NULL); BLI_ghash_remove(bvh->bm_vert_to_node, v, NULL, NULL); @@ -393,7 +394,9 @@ static void pbvh_bmesh_vert_remove(PBVH *bvh, BMVert *v) BM_ITER_ELEM (f, &bm_iter, v, BM_FACES_OF_VERT) { PBVHNode *f_node = pbvh_bmesh_node_lookup(bvh, bvh->bm_face_to_node, f); - BLI_ghash_remove(f_node->bm_unique_verts, v, NULL, NULL); + /* Remove current ownership */ + /* Should be handled above by vert_to_node removal, leaving just in case - psy-fi */ + //BLI_ghash_remove(f_node->bm_unique_verts, v, NULL, NULL); BLI_ghash_remove(f_node->bm_other_verts, v, NULL, NULL); BLI_assert(!BLI_ghash_haskey(f_node->bm_unique_verts, v)); @@ -426,6 +429,9 @@ static void pbvh_bmesh_face_remove(PBVH *bvh, BMFace *f) if (new_node) { pbvh_bmesh_vert_ownership_transfer(bvh, new_node, v); + } else { + BLI_ghash_remove(f_node->bm_unique_verts, v, NULL, NULL); + BLI_ghash_remove(bvh->bm_vert_to_node, v, NULL, NULL); } } else { @@ -686,7 +692,7 @@ static void pbvh_bmesh_split_edge(PBVH *bvh, EdgeQueue *q, BLI_mempool *pool, ni = GET_INT_FROM_POINTER(nip); /* Ensure node gets redrawn */ - bvh->nodes[ni].flag |= PBVH_UpdateDrawBuffers; + bvh->nodes[ni].flag |= PBVH_UpdateDrawBuffers | PBVH_UpdateNormals; /* Find the vertex not in the edge */ v_opp = l_adj->prev->v; @@ -1012,25 +1018,29 @@ int pbvh_bmesh_node_raycast(PBVHNode *node, const float ray_start[3], return hit; } + void pbvh_bmesh_normals_update(PBVHNode **nodes, int totnode) { int n; for (n = 0; n < totnode; n++) { PBVHNode *node = nodes[n]; - GHashIterator gh_iter; - GHASH_ITER (gh_iter, node->bm_faces) { - BM_face_normal_update(BLI_ghashIterator_getKey(&gh_iter)); - } - GHASH_ITER (gh_iter, node->bm_unique_verts) { - BM_vert_normal_update(BLI_ghashIterator_getKey(&gh_iter)); - } - /* This should be unneeded normally */ - GHASH_ITER (gh_iter, node->bm_other_verts) { + if (node->flag & PBVH_UpdateNormals) { + GHashIterator gh_iter; + + GHASH_ITER (gh_iter, node->bm_faces) { + BM_face_normal_update(BLI_ghashIterator_getKey(&gh_iter)); + } + GHASH_ITER (gh_iter, node->bm_unique_verts) { + BM_vert_normal_update(BLI_ghashIterator_getKey(&gh_iter)); + } + /* This should be unneeded normally */ + GHASH_ITER (gh_iter, node->bm_other_verts) { BM_vert_normal_update(BLI_ghashIterator_getKey(&gh_iter)); + } + node->flag &= ~PBVH_UpdateNormals; } - node->flag &= ~PBVH_UpdateNormals; } } |