Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2022-09-23 16:23:35 +0300
committerHans Goudey <h.goudey@me.com>2022-09-23 16:23:35 +0300
commit0d7d8c73cf5c5c5f05c6a56951e4e5cd24871c12 (patch)
treeeb4462fdebcef4afca161d1257ecb7a78d298cec /source/blender/blenkernel
parent060a5341419412fd7996cf99a56db1f581a4c30c (diff)
Mesh: Use cached looptris in draw cache extraction
The mesh's triangulation cache is often created for other operations besides the drawing code, but during the mesh draw cache extraction it is recalculated on every single time. It is simpler and faster to use the existing MLoopTri array. It can also save memory if the cache already exists by avoiding allocating a duplicate array. For a 4 million face quad mesh, that is already 128 MB. Also use face normals for mesh triangulation if they aren't dirty, which should provide a general speedup when they're both necessary. Recently 54182e4925de made this more reliable, since the triangulation cache is invalidated properly when the mesh is deformed. Fixes T98073 Differential Revision: https://developer.blender.org/D15550
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r--source/blender/blenkernel/intern/mesh_runtime.cc23
1 files changed, 17 insertions, 6 deletions
diff --git a/source/blender/blenkernel/intern/mesh_runtime.cc b/source/blender/blenkernel/intern/mesh_runtime.cc
index 4b6433edd5a..d7a0b73298e 100644
--- a/source/blender/blenkernel/intern/mesh_runtime.cc
+++ b/source/blender/blenkernel/intern/mesh_runtime.cc
@@ -154,12 +154,23 @@ void BKE_mesh_runtime_looptri_recalc(Mesh *mesh)
const Span<MPoly> polys = mesh->polys();
const Span<MLoop> loops = mesh->loops();
- BKE_mesh_recalc_looptri(loops.data(),
- polys.data(),
- verts.data(),
- mesh->totloop,
- mesh->totpoly,
- mesh->runtime.looptris.array_wip);
+ if (BKE_mesh_poly_normals_are_dirty(mesh)) {
+ BKE_mesh_recalc_looptri_with_normals(loops.data(),
+ polys.data(),
+ verts.data(),
+ mesh->totloop,
+ mesh->totpoly,
+ mesh->runtime.looptris.array_wip,
+ BKE_mesh_poly_normals_ensure(mesh));
+ }
+ else {
+ BKE_mesh_recalc_looptri(loops.data(),
+ polys.data(),
+ verts.data(),
+ mesh->totloop,
+ mesh->totpoly,
+ mesh->runtime.looptris.array_wip);
+ }
BLI_assert(mesh->runtime.looptris.array == nullptr);
atomic_cas_ptr((void **)&mesh->runtime.looptris.array,