【问题标题】:Why is ARSession restarted session slowly?为什么 ARSession 重新启动会话很慢?
【发布时间】:2022-10-22 03:07:07
【问题描述】:

我正在为我的 AR 应用程序使用 ARKit。我需要经常启动和停止 ARSession。 但是当我停止后重新启动 ARSession 时,它会慢慢进入正常状态,然后是初始启动。这意味着重新启动 ARSession 比初始启动有更多时间。 我试图重新创建 ARSession 而不是重新启动,但它总是失败。

这是我的代码:

private let session = ARSession()

override func viewDidLoad() {
  super.viewDidLoad()
  setupVM()
  setupARSession()
}

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

override func viewWillDisappear(_ animated: Bool) {
  super.viewWillDisappear(animated)
  session.pause()
}

private func startARSession() {
  let configuration = ARWorldTrackingConfiguration()
  configuration.frameSemantics = .sceneDepth

  session.run(configuration)
}

private func restartARSession() {
  if let configuration = session.configuration {
    session.run(configuration, options: .resetSceneReconstruction)
  }
}

如何更快地重启 ARSession?

【问题讨论】:

    标签: ios swift augmented-reality arkit


    【解决方案1】:

    尝试在您的 ARSession 委托上实现 sessionShouldAttemptRelocalization。如果您返回 false 如下所示,则假设用户位于同一位置。 More options can be found in the documentation for sessionShouldAttemptRelocalization

    func sessionShouldAttemptRelocalization(_ session: ARSession) -> Bool {
      return false
    }
    

    (来源:Ask Apple 活动 10 月 17 日至 21 日)

    【讨论】:

      猜你喜欢
      • 2013-05-03
      • 2021-05-03
      • 1970-01-01
      • 2015-02-17
      • 1970-01-01
      • 2011-01-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多