From 6f88dca9c34b70905930067055935dea18757fec Mon Sep 17 00:00:00 2001 From: Antony Riakiotakis Date: Mon, 19 Aug 2013 14:08:59 +0000 Subject: Dyntopo: Turn off pbvh normal update flag after recalculation, saves recalculating normals every frame when not stroking the mesh. For this to work reliably with undo we need to support original normals in the bm_log (was marked as a TODO already in the code), so that undoing avoids having invalid normals in the mesh (since we don't update every frame anymore). This was added in this commit as well. Also added some (disabled) quite paranoid checks in the bmesh valication code for dyntopo hoping to catch the real normal update issue. No luck there yet. --- source/blender/blenkernel/intern/pbvh_bmesh.c | 35 ++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) (limited to 'source/blender/blenkernel/intern/pbvh_bmesh.c') diff --git a/source/blender/blenkernel/intern/pbvh_bmesh.c b/source/blender/blenkernel/intern/pbvh_bmesh.c index c70b1fd11bf..e5cbe64abc0 100644 --- a/source/blender/blenkernel/intern/pbvh_bmesh.c +++ b/source/blender/blenkernel/intern/pbvh_bmesh.c @@ -1026,9 +1026,11 @@ void pbvh_bmesh_normals_update(PBVHNode **nodes, int totnode) 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; } } @@ -1365,7 +1367,9 @@ void print_flag_factors(int flag) void pbvh_bmesh_verify(PBVH *bvh) { GHashIterator gh_iter; - int i; + int i, vert_count = 0; + BMIter iter; + BMVert *vi; /* Check faces */ BLI_assert(bvh->bm->totface == BLI_ghash_size(bvh->bm_face_to_node)); @@ -1431,8 +1435,37 @@ void pbvh_bmesh_verify(PBVH *bvh) } } BLI_assert(found); + + #if 0 + /* total freak stuff, check if node exists somewhere else */ + /* Slow */ + for (i = 0; i < bvh->totnode; i++) { + PBVHNode *n = &bvh->nodes[i]; + if (i != ni && n->bm_unique_verts) + BLI_assert(!BLI_ghash_haskey(n->bm_unique_verts, v)); + } + + #endif } + #if 0 + /* check that every vert belongs somewhere */ + /* Slow */ + BM_ITER_MESH (vi, &iter, bvh->bm, BM_VERTS_OF_MESH) { + bool has_unique = false; + for (i = 0; i < bvh->totnode; i++) { + PBVHNode *n = &bvh->nodes[i]; + if ((n->bm_unique_verts != NULL) && BLI_ghash_haskey(n->bm_unique_verts, vi)) + has_unique = true; + } + BLI_assert(has_unique); + vert_count++; + } + + /* if totvert differs from number of verts inside the hash. hash-totvert is checked above */ + BLI_assert(vert_count == bvh->bm->totvert); + #endif + /* Check that node elements are recorded in the top level */ for (i = 0; i < bvh->totnode; i++) { PBVHNode *n = &bvh->nodes[i]; -- cgit v1.2.3