gpt4 book ai didi

swift - ARKit Stereo – 是否可以同时运行两个 ARSCNView?

转载 作者:行者123 更新时间:2023-12-02 14:54:30 24 4
gpt4 key购买 nike

我想对我现有的 AR 应用做一些修改,我想 Split View并在里面添加 2 个 ARSCNView 这样用户就可以使用 VR Card Box 并获得不同的体验但是 Xcode 总是返回给我:

Session (0x102617d10): did fail with error: Error Domain=com.apple.arkit.error Code=102 "Required sensor failed."

所以,我假设我不能同时运行 2 个 ARSCNView session ,或者我错了吗?

最佳答案

答案是:是的,这是可能的

使用下面的代码来完成:

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

// Setup for sceneView2
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()
}
func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) {
DispatchQueue.main.async {
self.updateFrame()
}
}
func updateFrame() {
// Clone pointOfView for Second View
let pointOfView: SCNNode = (sceneView.pointOfView?.clone())!

// Determine Adjusted Position for Right Eye
let orientation: SCNQuaternion = pointOfView.orientation
let orientationQuaternion: GLKQuaternion = GLKQuaternionMake(orientation.x,
orientation.y,
orientation.z,
orientation.w)
let eyePos: GLKVector3 = GLKVector3Make(1.0, 0.0, 0.0)
let rotatedEyePos: GLKVector3 = GLKQuaternionRotateVector3(orientationQuaternion,
eyePos)
let rotatedEyePosSCNV: SCNVector3 = SCNVector3Make(rotatedEyePos.x,
rotatedEyePos.y,
rotatedEyePos.z)
let mag: Float = 0.064 // Interocular distance (in metres)
pointOfView.position.x += rotatedEyePosSCNV.x * mag
pointOfView.position.y += rotatedEyePosSCNV.y * mag
pointOfView.position.z += rotatedEyePosSCNV.z * mag

// Set PointOfView for SecondView
sceneView2.pointOfView = pointOfView
}
}

For more details look at this project on a GitHub.

enter image description here

关于swift - ARKit Stereo – 是否可以同时运行两个 ARSCNView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53691179/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com