Vertex position in ARKit's reconstructed mesh

I've got a quick question regarding ARKits scene reconstruction. Is it possible to get the world coordinates for the faces/vertices that are part of the generated mesh or to select them individually?

After looking through the documentation at apple and tinkering with the example apps it does not seem possible working with the faces property of ARMeshGeometry, but the vertices property does return coordinates. Here's apples code-snippet on how to select specific vertices:

    func vertex(at index: UInt32) -> SIMD3<Float> {
        assert(vertices.format == MTLVertexFormat.float3, "Expected three floats (twelve bytes) per vertex.")
        let vertexPointer = vertices.buffer.contents().advanced(by: vertices.offset + (vertices.stride * Int(index)))
        let vertex = vertexPointer.assumingMemoryBound(to: SIMD3<Float>.self).pointee
        return vertex
    }
}

I've tried to place objects at those coordinates to see what they refer to, but they somehow end up in the middle of the room, far away from the mesh.. leaving me a bit confused as to what the vertices coordinates actually refer to.

I'd appreciate any answers on how to approach this!

Replies

The ARMeshGeometry is in the ARMeshAnchor's coordinate system, so to go from this local anchor space to world space, you should transform these vertex positions using the transform of the ARMeshAnchor that owns the geometry.

Here's an answer I posted on Stack Overflow for the same question:

https://stackoverflow.com/questions/64590893/how-to-get-a-vertex-position-in-arkits-reconstructed-mesh/68884453#68884453