我的视图控制器遇到问题。我正在尝试创建一个使用ARKit在两个AR场景上显示的应用程序。我尝试使用插座集合,但是出现类型“[ARSCNView]”值的错误。没有成员。我从Swift开始,所以我不知道一些事情。

这是我的代码:

import UIKit
import SceneKit
import ARKit

class ViewController: UIViewController {
    @IBOutlet var bothEyes: [ARSCNView]!

    override func viewDidLoad() {
        super.viewDidLoad()

        let configuration = ARWorldTrackingConfiguration()
        configuration.planeDetection = .horizontal

        let cubeNode = SCNNode(geometry: SCNBox(width: 0.2, height: 0.2, length: 0.2, chamferRadius: 0.0))
        cubeNode.position = SCNVector3(0, 0, -0.2)// in meters

        bothEyes.session.run(configuration)
        bothEyes.scene.rootNode.addChildNode(cubeNode)
    }
}

最佳答案

您需要做的就是在两个ARSession之间共享一个ARSCNViews(并且,正如我之前所说的,您需要一个委托):

import UIKit
import SceneKit
import ARKit

class ViewController: UIViewController, ARSCNViewDelegate {

    @IBOutlet weak var sceneView: ARSCNView!
    @IBOutlet weak var sceneView2: ARSCNView!

    override func viewDidLoad() {
        super.viewDidLoad()

        sceneView.delegate = self
        sceneView.showsStatistics = true
        let scene = SCNScene(named: "art.scnassets/ship.scn")!
        sceneView.scene = scene
        sceneView.isPlaying = true

        // SceneView2 Setup
        sceneView2.scene = scene
        sceneView2.showsStatistics = sceneView.showsStatistics

        // Now sceneView2 starts receiving updates
        sceneView2.isPlaying = true
    }

    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        let configuration = ARWorldTrackingConfiguration()
        sceneView.session.run(configuration)
    }
    override func viewWillDisappear(_ animated: Bool) {
        super.viewWillDisappear(animated)
        sceneView.session.pause()
    }
}

但要记住!现在,帧速率60 fps在两个ARSCNViews(30 fps + 30 fps)之间共享。

我使用Horizontal Stack View线性排列ARSCNViews

ios - 如何使用ARKit在两个ARSCNView中显示相同的场景?-LMLPHP

07-27 19:10