I am trying to implement serializing the selections of the surface of a mesh as seen in this example implementation using three-mesh-bvh, three-mesh-bvh - Geometry Collect Triangles. (It is Open Source, the source code is here : https://github.com/gkjohnson/three-mesh-bvh/blob/39b479b41b9ecfc473a9abc1ac300b3ce5c82f86/example/selection.js). Now the example stores a list of indices of the mesh geometry that I can save.
const indexAttr = mesh.geometry.index;
const newIndexAttr = highlightMesh.geometry.index;
if ( indices.length && params.selectModel ) {
// if we found indices and we want to select the whole model
for ( let i = 0, l = indexAttr.count; i < l; i ++ ) {
const i2 = indexAttr.getX( i );
newIndexAttr.setX( i, i2 );
}
highlightMesh.geometry.drawRange.count = Infinity;
newIndexAttr.needsUpdate = true;
} else {
// update the highlight mesh
for ( let i = 0, l = indices.length; i < l; i ++ ) {
const i2 = indexAttr.getX( indices[ i ] );
newIndexAttr.setX( i, i2 );
}
highlightMesh.geometry.drawRange.count = indices.length;
newIndexAttr.needsUpdate = true;
}
The index array is small enough for storage, but If I even load 5 selected regions of a model, performance is impacted significantly (Orbit controls run slow too). Is it possible to somehow reduce the geometry and not just the draw range?
My current solution to the approach is to just show one region at a time.