Contents

faces

An object that contains a buffer of vertex indices of the geometry’s faces.

Declaration

var faces: ARGeometryElement { get }

Discussion

Each element of the buffer-based array is a three-index combination that forms a unique triangle, or face. The index refers to that vertex’s position in the vertices array. The count of this property represents the number of faces.

The following code demonstrates getting the vertices of a particular face:

extension ARMeshGeometry {
    func vertexIndicesOf(faceWithIndex index: Int) -> [Int] {
        let indicesPerFace = faces.indexCountPerPrimitive
        let facesPointer = faces.buffer.contents()
        var vertexIndices = [Int]()
        for offset in 0..<indicesPerFace {
            let vertexIndexAddress = facesPointer.advanced(by: (index * indicesPerFace + offset) * MemoryLayout<UInt32>.size)
            vertexIndices.append(Int(vertexIndexAddress.assumingMemoryBound(to: UInt32.self).pointee))
        }
        return vertexIndices
    }
}

See Also

Getting Geometry Information