Skip to main content

Continuous Allocation and Remapping of Vertex/Edge/Face Ids

Mesh elements (vertices VertId, edges EdgeId, faces FaceId) are allocated using contiguous integer indices. During mesh construction (for example, using MeshTopology::fromTriangles, the system preemptively allocates storage space for vertices and faces based on the number of triangles or points, assigning new elements with continuous numbering from 0 to N-1. When merging meshes (such as with Mesh::addPart, which incorporates another mesh into the current one), the vertices and faces of the second mesh continue numbering based on the existing counts, avoiding any conflicts.

If it is necessary to merge closely positioned vertices, one can invoke the MeshBuilder::uniteCloseVertices function, passing the optionalVertOldToNew parameter to obtain a mapping of vertex IDs before and after merging. When deleting faces (via MeshTopology::deleteFaces(faceSet)), the corresponding faces are removed from the topology, and the system automatically updates the collection of valid faces. Should there be direct modifications to the topology (such as face deletions or edge splits), it is essential to call mesh.invalidateCaches() to rebuild cached normals, adjacency, and other related information.

Through these mechanisms, it is ensured that all IDs consistently point to valid elements, with compression or reconstruction performed as necessary to maintain alignment between indices and their underlying structures.