diff options
Diffstat (limited to 'source/blender/bmesh')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_log.c | 15 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_log.h | 5 | ||||
-rw-r--r-- | source/blender/bmesh/intern/bmesh_mesh_convert.c | 21 |
3 files changed, 25 insertions, 16 deletions
diff --git a/source/blender/bmesh/intern/bmesh_log.c b/source/blender/bmesh/intern/bmesh_log.c index e667505caca..edcd9159520 100644 --- a/source/blender/bmesh/intern/bmesh_log.c +++ b/source/blender/bmesh/intern/bmesh_log.c @@ -109,7 +109,7 @@ struct BMLog { typedef struct { float co[3]; - short no[3]; + float no[3]; char hflag; float mask; } BMLogVert; @@ -200,7 +200,7 @@ static void vert_mask_set(BMVert *v, const float new_mask, const int cd_vert_mas static void bm_log_vert_bmvert_copy(BMLogVert *lv, BMVert *v, const int cd_vert_mask_offset) { copy_v3_v3(lv->co, v->co); - normal_float_to_short_v3(lv->no, v->no); + copy_v3_v3(lv->no, v->no); lv->mask = vert_mask_get(v, cd_vert_mask_offset); lv->hflag = v->head.hflag; } @@ -294,7 +294,7 @@ static void bm_log_verts_restore(BMesh *bm, BMLog *log, GHash *verts) BMVert *v = BM_vert_create(bm, lv->co, NULL, BM_CREATE_NOP); vert_mask_set(v, lv->mask, cd_vert_mask_offset); v->head.hflag = lv->hflag; - normal_short_to_float_v3(v->no, lv->no); + copy_v3_v3(v->no, lv->no); bm_log_vert_id_set(log, v, POINTER_AS_UINT(key)); } } @@ -329,12 +329,9 @@ static void bm_log_vert_values_swap(BMesh *bm, BMLog *log, GHash *verts) uint id = POINTER_AS_UINT(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_v3_v3(v->no, lv->no); SWAP(char, v->head.hflag, lv->hflag); mask = lv->mask; lv->mask = vert_mask_get(v, cd_vert_mask_offset); @@ -937,7 +934,7 @@ const float *BM_log_original_vert_co(BMLog *log, BMVert *v) return lv->co; } -const short *BM_log_original_vert_no(BMLog *log, BMVert *v) +const float *BM_log_original_vert_no(BMLog *log, BMVert *v) { BMLogEntry *entry = log->current_entry; const BMLogVert *lv; @@ -967,7 +964,7 @@ float BM_log_original_mask(BMLog *log, BMVert *v) return lv->mask; } -void BM_log_original_vert_data(BMLog *log, BMVert *v, const float **r_co, const short **r_no) +void BM_log_original_vert_data(BMLog *log, BMVert *v, const float **r_co, const float **r_no) { BMLogEntry *entry = log->current_entry; const BMLogVert *lv; diff --git a/source/blender/bmesh/intern/bmesh_log.h b/source/blender/bmesh/intern/bmesh_log.h index 1cc860beed1..935cb5aba28 100644 --- a/source/blender/bmesh/intern/bmesh_log.h +++ b/source/blender/bmesh/intern/bmesh_log.h @@ -196,11 +196,10 @@ void BM_log_before_all_removed(BMesh *bm, BMLog *log); * Does not modify the log or the vertex */ const float *BM_log_original_vert_co(BMLog *log, BMVert *v); -/* Get the logged normal of a vertex */ /* 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); +const float *BM_log_original_vert_no(BMLog *log, BMVert *v); /* Get the logged mask of a vertex */ /* Get the logged mask of a vertex @@ -209,7 +208,7 @@ const short *BM_log_original_vert_no(BMLog *log, BMVert *v); float BM_log_original_mask(BMLog *log, BMVert *v); /* Get the logged data of a vertex (avoid multiple lookups) */ -void BM_log_original_vert_data(BMLog *log, BMVert *v, const float **r_co, const short **r_no); +void BM_log_original_vert_data(BMLog *log, BMVert *v, const float **r_co, const float **r_no); /* For internal use only (unit testing) */ /* For internal use only (unit testing) */ diff --git a/source/blender/bmesh/intern/bmesh_mesh_convert.c b/source/blender/bmesh/intern/bmesh_mesh_convert.c index 544a81f7020..d99fefbcd02 100644 --- a/source/blender/bmesh/intern/bmesh_mesh_convert.c +++ b/source/blender/bmesh/intern/bmesh_mesh_convert.c @@ -208,6 +208,14 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar return; /* Sanity check. */ } + /* Only copy normals to the new BMesh if they are not already dirty. This avoids unnecessary + * work, but also accessing normals on an incomplete mesh, for example when restoring undo steps + * in edit mode. */ + const float(*vert_normals)[3] = NULL; + if (!BKE_mesh_vertex_normals_are_dirty(me)) { + vert_normals = BKE_mesh_vertex_normals_ensure(me); + } + if (is_new) { CustomData_copy(&me->vdata, &bm->vdata, mask.vmask, CD_CALLOC, 0); CustomData_copy(&me->edata, &bm->edata, mask.emask, CD_CALLOC, 0); @@ -334,7 +342,9 @@ void BM_mesh_bm_from_me(BMesh *bm, const Mesh *me, const struct BMeshFromMeshPar BM_vert_select_set(bm, v, true); } - normal_short_to_float_v3(v->no, mvert->no); + if (vert_normals) { + copy_v3_v3(v->no, vert_normals[i]); + } /* Copy Custom Data */ CustomData_to_bmesh_block(&me->vdata, &bm->vdata, i, &v->head.data, true); @@ -639,6 +649,10 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh CustomData_add_layer(&me->ldata, CD_MLOOP, CD_ASSIGN, mloop, me->totloop); CustomData_add_layer(&me->pdata, CD_MPOLY, CD_ASSIGN, mpoly, me->totpoly); + /* There is no way to tell if BMesh normals are dirty or not. Instead of calculating the normals + * on the BMesh possibly unnecessarily, just tag them dirty on the resulting mesh. */ + BKE_mesh_normals_tag_dirty(me); + me->cd_flag = BM_mesh_cd_flag_from_bmesh(bm); /* This is called again, 'dotess' arg is used there. */ @@ -647,7 +661,6 @@ void BM_mesh_bm_to_me(Main *bmain, BMesh *bm, Mesh *me, const struct BMeshToMesh i = 0; BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) { copy_v3_v3(mvert->co, v->co); - normal_float_to_short_v3(mvert->no, v->no); mvert->flag = BM_vert_flag_to_mflag(v); @@ -1041,6 +1054,8 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks * const int cd_edge_bweight_offset = CustomData_get_offset(&bm->edata, CD_BWEIGHT); const int cd_edge_crease_offset = CustomData_get_offset(&bm->edata, CD_CREASE); + BKE_mesh_normals_tag_dirty(me); + me->runtime.deformed_only = true; /* Don't add origindex layer if one already exists. */ @@ -1055,8 +1070,6 @@ void BM_mesh_bm_to_me_for_eval(BMesh *bm, Mesh *me, const CustomData_MeshMasks * BM_elem_index_set(eve, i); /* set_inline */ - normal_float_to_short_v3(mv->no, eve->no); - mv->flag = BM_vert_flag_to_mflag(eve); if (cd_vert_bweight_offset != -1) { |