我正在尝试 ARKit,并设置了一个ARSCNView
using this tutorial。
然后使用本教程的第二部分设置跟踪水平 3D 平面。
我创建了一个单视图应用程序,然后ARSCNView
通过我的ViewController
.
这是 中的代码ViewController
:
import UIKit
import ARKit
class ViewController: UIViewController {
//MARK: Properties
@IBOutlet weak var arScene: ARSCNView!
//MARK: ARKit variables
var realityConfiguration: ARWorldTrackingSessionConfiguration?
//MARK: Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.prepare()
}
//MARK: Actions
//MARK: Overrides
}
extension ViewController {
func prepare() {
//Check to see if active reality is supported
guard ARSessionConfiguration.isSupported else {
//Custom alert function that just quickly displays a UIAlertController
AppDelegate.alert(title: "Not Supported", message: "Active Reality is not supported on this device")
return
}
//Set up the ARSessionConfiguration
self.realityConfiguration = ARWorldTrackingSessionConfiguration()
//Set up the ARSCNView
guard let config = self.realityConfiguration else {
return
}
//Run the ARSCNView and set its delegate
self.arScene.session.run(config)
self.arScene.delegate = self
}
}
extension ViewController: ARSCNViewDelegate {
func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
return nil
}
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
guard let planAnchor = anchor as? ARPlaneAnchor else {
return
}
let plane = SCNPlane(width: CGFloat(planAnchor.extent.x), height: CGFloat(planAnchor.extent.z))
let planeNode = SCNNode(geometry: plane)
planeNode.position = SCNVector3Make(planAnchor.center.x, 0, planAnchor.center.z)
planeNode.transform = SCNMatrix4MakeRotation(-Float.pi / 2, 1, 0, 0)
node.addChildNode(planeNode)
}
func renderer(_ renderer: SCNSceneRenderer, willUpdate node: SCNNode, for anchor: ARAnchor) {
print("Will updated Node on Anchor: \(anchor.identifier)")
}
func renderer(_ renderer: SCNSceneRenderer, didUpdate node: SCNNode, for anchor: ARAnchor) {
print("Did updated Node on Anchor: \(anchor.identifier)")
}
func renderer(_ renderer: SCNSceneRenderer, didRemove node: SCNNode, for anchor: ARAnchor) {
print("Removed Node on Anchor: \(anchor.identifier)")
}
}
我下载了 Xcode 9 测试版,按照 Apple 的教程进行操作,发现我的 iPhone 6 没有该ARWorldTrackingSessionConfiguration
对象所需的 A9 芯片。
在我链接的第一个教程中大约一半时,Apple 表示您仍然可以在没有 A9 芯片的情况下创建 AR 体验。但是,它们没有进一步详细说明。有没有其他人找到起点,并愿意提供使用 .dae 文件的代码示例和
- 选择一个锚点来显示它
- 跟踪该锚点
- 实际显示 .dae 文件