diff options
-rw-r--r-- | source/blender/blenkernel/intern/pbvh_bmesh.c | 35 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_log.c | 25 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_log.h | 3 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt.c | 7 |
4 files changed, 65 insertions, 5 deletions
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]; diff --git a/source/blender/bmesh/intern/bmesh_log.c b/source/blender/bmesh/intern/bmesh_log.c index b50f35be4f3..f612f33e8fc 100644 --- a/source/blender/bmesh/intern/bmesh_log.c +++ b/source/blender/bmesh/intern/bmesh_log.c @@ -95,6 +95,7 @@ struct BMLog { typedef struct { float co[3]; + short no[3]; float mask; char hflag; } BMLogVert; @@ -187,6 +188,7 @@ static void vert_mask_set(BMesh *bm, BMVert *v, float new_mask) static void bm_log_vert_bmvert_copy(BMesh *bm, BMLogVert *lv, BMVert *v) { copy_v3_v3(lv->co, v->co); + normal_float_to_short_v3(lv->no, v->no); lv->mask = vert_mask_get(bm, v); lv->hflag = v->head.hflag; } @@ -276,6 +278,7 @@ static void bm_log_verts_restore(BMesh *bm, BMLog *log, GHash *verts) BMVert *v = BM_vert_create(bm, lv->co, NULL, 0); v->head.hflag = lv->hflag; vert_mask_set(bm, v, lv->mask); + normal_short_to_float_v3(v->no, lv->no); bm_log_vert_id_set(log, v, GET_INT_FROM_POINTER(key)); } } @@ -305,8 +308,12 @@ static void bm_log_vert_values_swap(BMesh *bm, BMLog *log, GHash *verts) unsigned int id = GET_INT_FROM_POINTER(key); BMVert *v = bm_log_vert_from_id(log, id); float mask; + short normal[3]; swap_v3_v3(v->co, lv->co); + copy_v3_v3_short(normal, lv->no); + normal_float_to_short_v3(lv->no, v->no); + normal_short_to_float_v3(v->no, normal); SWAP(char, v->head.hflag, lv->hflag); mask = lv->mask; lv->mask = vert_mask_get(bm, v); @@ -927,6 +934,24 @@ const float *BM_log_original_vert_co(BMLog *log, BMVert *v) return lv->co; } +/* Get the logged normal of a vertex + * + * Does not modify the log or the vertex */ +const short *BM_log_original_vert_no(BMLog *log, BMVert *v) +{ + BMLogEntry *entry = log->current_entry; + const BMLogVert *lv; + unsigned v_id = bm_log_vert_id_get(log, v); + void *key = SET_INT_IN_POINTER(v_id); + + BLI_assert(entry); + + BLI_assert(BLI_ghash_haskey(entry->modified_verts, key)); + + lv = BLI_ghash_lookup(entry->modified_verts, key); + return lv->no; +} + /* Get the logged mask of a vertex * * Does not modify the log or the vertex */ diff --git a/source/blender/bmesh/intern/bmesh_log.h b/source/blender/bmesh/intern/bmesh_log.h index 958ff340b43..4767c82ff2f 100644 --- a/source/blender/bmesh/intern/bmesh_log.h +++ b/source/blender/bmesh/intern/bmesh_log.h @@ -92,6 +92,9 @@ void BM_log_before_all_removed(BMesh *bm, BMLog *log); /* Get the logged coordinates of a vertex */ const float *BM_log_original_vert_co(BMLog *log, BMVert *v); +/* Get the logged normal of a vertex */ +const short *BM_log_original_vert_no(BMLog *log, BMVert *v); + /* Get the logged mask of a vertex */ float BM_log_original_mask(BMLog *log, BMVert *v); diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index b16d5f6b4cd..545c0f6f0e8 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -330,7 +330,7 @@ typedef struct { /* Original coordinate, normal, and mask */ const float *co; float mask; - short no[3]; + const short *no; } SculptOrigVertData; @@ -381,11 +381,10 @@ static void sculpt_orig_vert_data_update(SculptOrigVertData *orig_data, } if (orig_data->normals) { - copy_v3_v3_short(orig_data->no, orig_data->normals[iter->i]); + orig_data->no = orig_data->normals[iter->i]; } else { - /* TODO: log doesn't store normals yet */ - normal_float_to_short_v3(orig_data->no, iter->bm_vert->no); + orig_data->no = BM_log_original_vert_no(orig_data->bm_log, iter->bm_vert); } } else if (orig_data->unode->type == SCULPT_UNDO_MASK) { |