我正在尝试将SKScene设置为ARSCNView内部SCNPlane中的内容。现在,SKScene是一个非常简单的,在.sks文件中定义,它只包含红色背景和中心的绿色矩形。就在这里是代码:第一个函数在用户点击屏幕时在摄像机前面创建一个ARAnchor,另一个函数为锚点创建SCNNode。
当我将飞机的第一个材料内容设置为skScene时,我遇到了崩溃: validateDepthStencilState:3671:断言失败`MTLDepthStencilDescriptor使用frontFaceStencil但MTLRenderPassDescriptor有一个nil stencilAttachment纹理
这只发生在附加设备的XCode上运行应用程序。如果我拔掉它并直接从设备运行应用程序,我会正确看到内容,我可以添加大量那些丑陋的飞机(截图在底部)
@objc func addAnchor() {
if let currentFrame = sceneView.session.currentFrame {
var translation = matrix_identity_float4x4
translation.columns.3.z = -1.0
let transform = simd_mul(currentFrame.camera.transform, translation)
// Add a new anchor to the session
let anchor = ARAnchor(transform: transform)
sceneView.session.add(anchor: anchor)
}
}
// Override to create and configure nodes for anchors added to the view's session.
func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
guard let skScene = SKScene(fileNamed: "MyScene") else {
print("Could not load skscene!")
return nil
}
let sceneSize = skScene.size
print("Scene size in points: \(sceneSize)")
skScene.scaleMode = .aspectFit
//skScene.backgroundColor = UIColor.red
let plane = SCNPlane(width: sceneSize.width * 0.001, height: sceneSize.height * 0.001)
plane.firstMaterial?.isDoubleSided = true
plane.firstMaterial?.diffuse.contents = skScene //Crash here
let planeNode = SCNNode(geometry: plane)
return planeNode
}