ios - ARKit session 的 currentFrame 始终为 nil

标签 ios augmented-reality arkit

我尝试从 ARSessioncurrentFrame.camera 属性获取相机变换。

为什么我总是将 sceneView.session.currentFrame? 获取为 nil

最佳答案

我刚刚进行了快速测试,发现 session.currentFrame 在前几次通过渲染循环时为 nil。延迟各不相同,可能是两个或十几个。但最终 currentFrame 出现了。

class ViewController: UIViewController, ARSCNViewDelegate, ARSessionDelegate, SCNSceneRendererDelegate {

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    // Create a session configuration
    let configuration = ARWorldTrackingSessionConfiguration()
    configuration.worldAlignment = .gravityAndHeading
    configuration.planeDetection = .horizontal

    sceneView.session.delegate = self

    // Run the view's session
    sceneView.session.run(configuration)
    print(#function, sceneView.session.currentFrame)

}

// MARK: - SCNSceneRendererDelegate
func renderer(_ renderer: SCNSceneRenderer, didRenderScene scene: SCNScene, atTime time: TimeInterval) {
    print(#function, sceneView.session.currentFrame)
}

// MARK: - ARSessionDelegate
func session(_ session: ARSession, didUpdate frame: ARFrame) {
    print(#function, sceneView.session.currentFrame)
}

给我们

renderer(_:didRenderScene:atTime:) nil
...
session(_:didUpdate:) Optional(<ARFrame: 0x1c42cff10 timestamp=6334.963644 capturedImage=0x1c0124d80 camera=0x1c41262c0 lightEstimate=0x1c4238640 | no anchors, 0 features>)
...
renderer(_:didRenderScene:atTime:) Optional(<ARFrame: 0x1c02c9c30 timestamp=6334.996948 capturedImage=0x1c0124b00 camera=0x1c0124920 lightEstimate=0x1c02251a0 | no anchors, 0 features>)

关于ios - ARKit session 的 currentFrame 始终为 nil,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44902754/

相关文章:

objective-c - 已发布的 UIViewController 已正确销毁,但未调用其 -(void)dealloc 方法

Android:Windows 中的 NDK 设置

ios - Swift:实例成员不能用于 ARKitVision 示例中的类型

swift - ARKIT - 如何粘贴两个物体

iphone - 如何在图像上写入文字并通过邮件发送?

iOS Crashlytics - 阻止崩溃报告发送到服务器

iphone - 多个 ViewController、xib 文件位于一个 Storyboard 中

swift - 在 RealityKit 中从场景中删除实体

opengl - 怎么做对应2D-3D点

swift - 如何使用 ARKit Swift 将对象附加到相机位置?