我正在尝试将 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

}

应用程序未连接到 xcode