2017-07-06 43 views
1

當我運行我的ARSessionARWorldTrackingSessionConfigurationsceneView.session屬性似乎不保持配置。這是我的代碼ARSession運行,但沒有配置

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

    // Create a session configuration 
    let configuration = ARWorldTrackingSessionConfiguration() 

    configuration.planeDetection = .horizontal 

    // Run the view's session 
    sceneView.session.run(configuration) 
} 

我把一個斷點sceneView.session.run(configuration),它給了我下面的

po sceneView.session 
<ARSession: 0x1c83c8520 currentFrame=0x0 timestamp=0.000000 configuration=(null)> 

注:configuration=(null)

我後來試圖訪問sceneView.session.currentFrame,但它給了我零,所以我認爲以上是問題。

我在iPad Pro 2017上運行它,它確實支持ARWorldTrackingSessionConfiguration,並且我也嘗試過只使用ARSessionConfiguration,但這給了我相同的東西。

有其他人遇到此?它現在看起來像一個ARKit bug,因爲我的代碼是直接從文檔中獲取的。有任何想法嗎?

回答

0

我有同樣的問題。看起來像ARSession不會立即運行。我通過使用短延遲來解決它:

sceneView.session.run(configuration) 
    DispatchQueue.main.asyncAfter(deadline: .now() + 0.5) { [weak sceneView] in 
     guard let cameraTransform = sceneView?.session.currentFrame?.camera.transform else { return } 
     /* now you can use cameraTransform */ 
    } 

在0.2-0.5秒之後,會話開始正確地確定當前幀。但在第一次使用框架之前,您應該等待這麼短的時間。我用「打開相機」的動畫隱藏了0.5秒,所以用戶不會看到這個延遲。

相關問題