Option to not recreate subMesh when updating indices of Geometry

It would be nice to have an option when calling Geometry.setIndices(...) that would prevent the calls to _createGlobalSubMesh, that will create a single subMesh for each of the mesh linked to the Geometry.

My use case is that I modify the indices to remove / add some new faces for a mesh that have several sub meshes. I also update the indexStart / indexCount properties of each sub mesh to account for those changes.

However, when calling setIndices(), my sub meshes are replaced by a single new sub mesh.

What I’m currently doing is copying the mesh.subMeshes array before calling setIndices() and set it again to mesh.subMeshes after the call, but maybe an option like dontRecreateSubMesh would be nice?

There’s the same “problem” in the setVerticesData / setVerticesBuffer methods of Geometry when kind is position: a number of specific operations are done (among them, a _createGlobalSubMesh call) that makes more difficult to handle manual low level operations on geometries.

Well, after looking at the mesh source code, it seems that the way to go is to copy the sub meshes, do your work with indices / vertex data buffers, then call releaseSubMeshes() and reset the sub meshes with your previous copy (or create new ones).

That’s what is done in bakeTransformIntoVertices, convertToFlatShadedMesh, convertToUnIndexedMesh, etc.

So I will do the same thing, I thin you can forget this request.

1 Like