Removes vertex and all referencing triangles, reindexes remaining geometry. Takes mesh (surface-based mesh entity), surface (surface handle, 0-based), vertexIndex (vertex number, 0-based). Returns nothing. Validates mesh exists, type is ENTITY_MESH, surface-based, surface index valid, and mesh is locked. Three-step algorithm: (1) Iterate indices array backward, remove any triangle containing vertexIndex (erase 3 indices per triangle).
Removes vertex and all referencing triangles, reindexes remaining geometry. Takes mesh (surface-based mesh entity), surface (surface handle, 0-based), vertexIndex (vertex number, 0-based). Returns nothing. Validates mesh exists, type is ENTITY_MESH, surface-based, surface index valid, and mesh is locked. Three-step algorithm: (1) Iterate indices array backward, remove any triangle containing vertexIndex (erase 3 indices per triangle). (2) Iterate remaining indices, decrement any index > vertexIndex (shifts references down). (3) Erase vertex from vertices array at vertexIndex. Sets mesh->needsGPUUpload=true. Silently returns on validation errors. Subsequent vertices shift down - vertex N+1 becomes vertex N after deletion.
This function removes vertex and maintains topology consistency by reindexing. Vertex deletion complex: can't simply remove vertex without handling triangles that reference it (dangling references crash GPU). Algorithm ensures: (1) No triangles reference deleted vertex (removes referencing triangles first), (2) Remaining triangle indices remain valid (decrements indices pointing to shifted vertices). Step 1 (remove triangles): iterate indices backward (prevents index shift issues), check each triangle's 3 indices, if any matches vertexIndex, erase entire triangle (3 consecutive indices). Multiple triangles may reference vertex - all removed. Step 2 (reindex): remaining triangles reference vertices by index - deleting vertex shifts subsequent indices down by 1. All indices > vertexIndex must decrement to maintain correct references. Example: vertex array [v0,v1,v2,v3,v4], triangle uses indices [0,3,4]. Delete vertex 1: array becomes [v0,v2,v3,v4] (v1 removed, v2-v4 shift down), indices must change to [0,2,3] (decremented). Step 3 (remove vertex): after triangles updated, safe to erase vertex from array. Vertices > vertexIndex shift down - vertex N+1 becomes vertex N. Locked mesh required - validation enforces lock state. Use cases: (1) Mesh simplification (remove vertices for LOD reduction), (2) Topology editing (delete vertices to create holes/gaps), (3) Vertex cleanup (remove duplicate/unused vertices), (4) Mesh surgery (cut away vertex regions). Cascade effect: deleting vertex removes all connected triangles - can create large hole if vertex highly connected. Check vertex degree (triangle count) before deleting if hole size matters. Performance: O(T + V) where T = triangle count (step 1+2 iterate indices), V = vertex count (step 3 shifts vertices). Deleting multiple vertices: delete in reverse order (highest index first) to avoid reindex issues - deleting vertex N doesn't affect indices 0 to N-1. Common workflow: b3dLockMesh(mesh), For i = vertexCount-1 To 0 Step -1, If vertex_should_delete Then b3dDeleteVertex(mesh, surf, i), b3dUnlockMesh(mesh). Alternative: rebuild surface with wanted vertices only (b3dClearSurface, re-add), use vertex welding with threshold=0 to merge duplicates, manual index array manipulation. Empty surface possible - deleting all vertices leaves surface with no geometry. Vertex attributes lost - position, normal, UV, color all discarded when vertex removed.