diff options
author | Antony Riakiotakis <kalast@gmail.com> | 2013-08-19 18:08:59 +0400 |
---|---|---|
committer | Antony Riakiotakis <kalast@gmail.com> | 2013-08-19 18:08:59 +0400 |
commit | 6f88dca9c34b70905930067055935dea18757fec (patch) | |
tree | 1d6fa82b3b13c8942128cdf0e7a3c98615c1b672 /source/blender/bmesh/intern | |
parent | cbfd2a8e62835544db750d8be834096e4e4f3a9d (diff) |
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.
Diffstat (limited to 'source/blender/bmesh/intern')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_log.c | 25 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_log.h | 3 |
2 files changed, 28 insertions, 0 deletions
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); |