From 8a1860bd9aecddf611b64e3e842bdc8c76f15cc6 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Mon, 14 Jun 2021 22:56:03 +1000 Subject: BMesh: support face-normal calculation in normal & looptri functions Support calculating face normals when tessellating. When this is done before updating vertex normals it gives ~20% performance improvement. Now vertex normal calculation only needs to perform a single pass on the mesh vertices when called after tessellation. Extended versions of normal & looptri update functions have been added: - BM_mesh_calc_tessellation_ex - BM_mesh_normals_update_ex Most callers don't need to be aware of this detail by using: - BKE_editmesh_looptri_and_normals_calc - BKE_editmesh_looptri_and_normals_calc_with_partial - EDBM_update also takes advantage of this, where calling EDBM_update with calc_looptri & calc_normals enabled uses the faster normal updating logic. --- source/blender/editors/mesh/editmesh_utils.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'source/blender/editors/mesh/editmesh_utils.c') diff --git a/source/blender/editors/mesh/editmesh_utils.c b/source/blender/editors/mesh/editmesh_utils.c index c8f8f12ba90..071ca818120 100644 --- a/source/blender/editors/mesh/editmesh_utils.c +++ b/source/blender/editors/mesh/editmesh_utils.c @@ -1405,9 +1405,17 @@ bool EDBM_mesh_reveal(BMEditMesh *em, bool select) /** \name Update API * \{ */ +void EDBM_mesh_normals_update_ex(BMEditMesh *em, const struct BMeshNormalsUpdate_Params *params) +{ + BM_mesh_normals_update_ex(em->bm, params); +} + void EDBM_mesh_normals_update(BMEditMesh *em) { - BM_mesh_normals_update(em->bm); + EDBM_mesh_normals_update_ex(em, + &(const struct BMeshNormalsUpdate_Params){ + .face_normals = true, + }); } void EDBM_stats_update(BMEditMesh *em) @@ -1449,12 +1457,18 @@ void EDBM_update(Mesh *mesh, const struct EDBMUpdate_Params *params) DEG_id_tag_update(&mesh->id, ID_RECALC_GEOMETRY); WM_main_add_notifier(NC_GEOM | ND_DATA, &mesh->id); - if (params->calc_normals) { - EDBM_mesh_normals_update(em); + if (params->calc_normals && params->calc_looptri) { + /* Calculating both has some performance gains. */ + BKE_editmesh_looptri_and_normals_calc(em); } + else { + if (params->calc_normals) { + EDBM_mesh_normals_update(em); + } - if (params->calc_looptri) { - BKE_editmesh_looptri_calc(em); + if (params->calc_looptri) { + BKE_editmesh_looptri_calc(em); + } } if (params->is_destructive) { -- cgit v1.2.3