diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-06-14 15:56:03 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-06-14 16:01:19 +0300 |
commit | 8a1860bd9aecddf611b64e3e842bdc8c76f15cc6 (patch) | |
tree | 52afad79ca08551fa22bb35d082719299f0476ef /source/blender/bmesh/intern/bmesh_mesh_normals.c | |
parent | 6bef2559047461794eb3ff27de15f4caf5ddcf1e (diff) |
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.
Diffstat (limited to 'source/blender/bmesh/intern/bmesh_mesh_normals.c')
-rw-r--r-- | source/blender/bmesh/intern/bmesh_mesh_normals.c | 41 |
1 files changed, 32 insertions, 9 deletions
diff --git a/source/blender/bmesh/intern/bmesh_mesh_normals.c b/source/blender/bmesh/intern/bmesh_mesh_normals.c index bf30f3a52e1..bddd3da98b7 100644 --- a/source/blender/bmesh/intern/bmesh_mesh_normals.c +++ b/source/blender/bmesh/intern/bmesh_mesh_normals.c @@ -240,19 +240,29 @@ static void bm_face_calc_normals_cb(void *UNUSED(userdata), * * Updates the normals of a mesh. */ -void BM_mesh_normals_update(BMesh *bm) +void BM_mesh_normals_update_ex(BMesh *bm, const struct BMeshNormalsUpdate_Params *params) { - /* Calculate all face normals. */ - TaskParallelSettings settings; - BLI_parallel_mempool_settings_defaults(&settings); - settings.use_threading = bm->totedge >= BM_OMP_LIMIT; + if (params->face_normals) { + /* Calculate all face normals. */ + TaskParallelSettings settings; + BLI_parallel_mempool_settings_defaults(&settings); + settings.use_threading = bm->totedge >= BM_OMP_LIMIT; - BM_iter_parallel(bm, BM_FACES_OF_MESH, bm_face_calc_normals_cb, NULL, &settings); + BM_iter_parallel(bm, BM_FACES_OF_MESH, bm_face_calc_normals_cb, NULL, &settings); + } /* Add weighted face normals to vertices, and normalize vert normals. */ bm_mesh_verts_calc_normals(bm, NULL, NULL, NULL); } +void BM_mesh_normals_update(BMesh *bm) +{ + BM_mesh_normals_update_ex(bm, + &(const struct BMeshNormalsUpdate_Params){ + .face_normals = true, + }); +} + /** \} */ /* -------------------------------------------------------------------- */ @@ -277,7 +287,9 @@ static void bm_partial_verts_parallel_range_calc_normal_cb( * A version of #BM_mesh_normals_update that updates a subset of geometry, * used to avoid the overhead of updating everything. */ -void BM_mesh_normals_update_with_partial(BMesh *UNUSED(bm), const BMPartialUpdate *bmpinfo) +void BM_mesh_normals_update_with_partial_ex(BMesh *UNUSED(bm), + const BMPartialUpdate *bmpinfo, + const struct BMeshNormalsUpdate_Params *params) { BLI_assert(bmpinfo->params.do_normals); @@ -290,14 +302,25 @@ void BM_mesh_normals_update_with_partial(BMesh *UNUSED(bm), const BMPartialUpdat BLI_parallel_range_settings_defaults(&settings); /* Faces. */ - BLI_task_parallel_range( - 0, faces_len, faces, bm_partial_faces_parallel_range_calc_normals_cb, &settings); + if (params->face_normals) { + BLI_task_parallel_range( + 0, faces_len, faces, bm_partial_faces_parallel_range_calc_normals_cb, &settings); + } /* Verts. */ BLI_task_parallel_range( 0, verts_len, verts, bm_partial_verts_parallel_range_calc_normal_cb, &settings); } +void BM_mesh_normals_update_with_partial(BMesh *bm, const BMPartialUpdate *bmpinfo) +{ + BM_mesh_normals_update_with_partial_ex(bm, + bmpinfo, + &(const struct BMeshNormalsUpdate_Params){ + .face_normals = true, + }); +} + /** \} */ /* -------------------------------------------------------------------- */ |