我的视图控制器出现问题。我正在尝试创建一个使用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)
}
}
答案 0 :(得分:1)
您需要做的就是在两个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
。