vertexIndex(at:)
Returns the vertex index at the given position in the mesh’s flattened primitive index array.
Declaration
final func vertexIndex(at index: UInt32) -> UInt32Return Value
The vertex index at the specified position.
Discussion
The mesh is formed by triangles with three vertices each. Different triangles can share the same vertex (for example, two adjacent triangles share the two vertices joined by their common edge).
For example, if you want to retrieve the index of the second vertex in the eleventh triangle, you would use myMesh.vertexIndex(at: 3 * 10 + 1). This is because each triangle is formed by three vertices, and indices start at zero, so the eleventh triangle starts at index 3 ⨉ 10. You then add one to get the second vertex within that triangle.
You can use the returned vertex index to inspect vertex properties. You can retrieve the position, for example, by using position(at:):
let vertexIndex = myMesh.vertexIndex(at: 3 * 10 + 1)
let vertexPosition = myMesh.position(at: vertexIndex)
print("The second vertex of the eleventh triangle is at X=\(vertexPosition.x)")index: Index of the vertex to be retrieved within the list of vertex indices for all the mesh primitives.