作者热门文章
- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我正在使用 ARKit 图像跟踪配置,一旦检测到图像,图像上就会弹出 3D 场景。
但是当我设置两个不同的图像触发两个不同的场景文件时,一张图像总是在同一张图像上弹出两个不同的场景文件。我敢肯定图像不同,名称不同,场景文件不同,场景的内容也不同。
检测到图像后,控制台中也会弹出以下错误:
[SceneKit] Error: Scene <SCNScene: 0x284ebcfa0> is modified within a rendering callback of another scene (<SCNScene: 0x28099c820>). This is not allowed and may lead to crash
这个错误有什么原因和解决办法吗?
最佳答案
我在 ARKit 2 的图像跟踪中遇到了同样的错误。经过数小时的尝试,我找到了解决方案。显然你需要在后台线程中创建你的节点才能玩场景。这是我的代码:
DispatchQueue.main.async {
if let imageAnchor = anchor as? ARImageAnchor {
let plane = SCNPlane(width: imageAnchor.referenceImage.physicalSize.width, height: imageAnchor.referenceImage.physicalSize.height)
plane.firstMaterial?.diffuse.contents = UIColor(white: 1.0, alpha: 0.5)
let planeNode = SCNNode(geometry: plane)
planeNode.eulerAngles.x = -.pi
node.addChildNode(planeNode)
...
}
}
关于swift - "Scene is modified within a rendering callback of another scene."如何解决这个错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51624346/
我是一名优秀的程序员,十分优秀!