Mesh: Split MLoopTri poly indices into a separate array

For derived mesh triangulation information, currently the three face
corner indices are stored in the same struct as index of the mesh
polygon the triangle is part of. While those pieces of information are
often used together, they often aren't, and combining them prevents
the indices from being used with generic utilities. It also means that
1/3 more memory has to be written when recalculating the triangulation
after deforming the mesh, and that the entire triangle data has to be
read when only the polygon indices are needed.

This commit splits the polygon index into a separate cache on `Mesh`.
The triangulation data isn't saved to files, so this doesn't affect
.blend files at all.

In a simple test deforming a mesh with geometry nodes, the time used
to recalculate the triangulation reduced from 2.0 ms to 1.6 ms,
increasing overall FPS from 14.6 to 15.

Pull Request: blender/blender#106774
This commit is contained in:
2023-05-04 15:39:10 +02:00
committed by Hans Goudey
parent bf77d3436d
commit d0705bd697
51 changed files with 416 additions and 225 deletions

View File

@@ -1142,6 +1142,7 @@ static PyObject *C_BVHTree_FromObject(PyObject * /*cls*/, PyObject *args, PyObje
const blender::Span<int> corner_verts = mesh->corner_verts();
const blender::Span<MLoopTri> looptris = mesh->looptris();
const blender::Span<int> looptri_polys = mesh->looptri_polys();
/* Get data for tessellation */
@@ -1182,7 +1183,7 @@ static PyObject *C_BVHTree_FromObject(PyObject * /*cls*/, PyObject *args, PyObje
copy_v3_v3(co[2], coords[tris[i][2]]);
BLI_bvhtree_insert(tree, int(i), co[0], 3);
orig_index[i] = int(looptris[i].poly);
orig_index[i] = int(looptri_polys[i]);
}
BLI_bvhtree_balance(tree);