Im converting the ARMeshAnchor data to mesh using SCNGeometrySource which it works fine but sometimes 3/10 I will get a bad_access from SceneKit renderer.
[![enter image description here][1]][1]
It occurs because
ARMeshAnchors
constantly update their data as ARKit refines its understanding of the real world. AllARMeshAnchors
are dynamic anchors. However their mesh's subsequent changes are not intended to reflect in real time.
If you want to duplicate your ARMeshAnchors collection use the following code:
var anchorsArray = [ARMeshAnchor]()
let frame = arView.session.currentFrame
let meshAnchors = frame?.anchors.compactMap { $0 as? ARMeshAnchor }
anchorsArray += meshAnchors!
Every ARMeshAnchor
is connected with primitive geometry data that's stored in MTLBuffer
:
anchorsArray[0].geometry.faces.buffer
anchorsArray[0].geometry.vertices.buffer
anchorsArray[0].geometry.normals.buffer
anchorsArray[0].geometry.classification?.buffer