ARMeshAnchor – SceneKit SCNView 渲染器 EXC_BAD_ACCESS

ARMeshAnchor – SceneKit SCNView Renderer EXC_BAD_ACCESS

我正在使用 SCNGeometrySource 将 ARMeshAnchor 数据转换为网格,它工作正常但有时 3/10 我会从 SceneKit 渲染器获得 bad_access。

[![在此处输入图片描述][1]][1]

It occurs because ARMeshAnchors constantly update their data as ARKit refines its understanding of the real world. All ARMeshAnchors are dynamic anchors. However their mesh's subsequent changes are not intended to reflect in real time.

如果您想复制 ARMeshAnchors 集合,请使用以下代码:

var anchorsArray = [ARMeshAnchor]()
    
let frame = arView.session.currentFrame
    
let meshAnchors = frame?.anchors.compactMap { [=10=] as? ARMeshAnchor }
    
anchorsArray += meshAnchors!

每个 ARMeshAnchor 都与存储在 MTLBuffer 中的原始几何数据相关联:

anchorsArray[0].geometry.faces.buffer
anchorsArray[0].geometry.vertices.buffer
anchorsArray[0].geometry.normals.buffer
anchorsArray[0].geometry.classification?.buffer