【发布时间】:2019-02-17 23:11:13
【问题描述】:
我目前正在努力限制我的 ARKit iOS 应用程序的 CPU 负载。为了做到这一点,我需要限制每秒 session(_ didUpdate: 函数被调用的时间。我尝试更改我的 ARSCNView 的 preferredFramesPerSecond 属性。这确实减慢了传入视频源的 fps,但更新函数仍然被每秒调用疯狂的次数。我的另一个解决方案是使用传入 ARFrame 的 timeStamp 属性并计算上次保存的渲染时间之间的差异。我正在尝试在 Swift Playgrounds 上运行该程序并且无论出于何种原因,在渲染循环中设置 TimeInterval 类型的变量失败。此解决方案适用于普通的 iOS 应用程序。是否有任何适当的方法可以直接设置 ARKit 更新功能的频率?
当前代码:
我的 AR 属性:
private lazy var lastRenderTime = Date().timeIntervalSince1970
private lazy var sceneView: ARSCNView = {
let sceneView = ARSCNView()
sceneView.session.delegate = self
sceneView.preferredFramesPerSecond = 30
sceneView.debugOptions = [.showFeaturePoints]
sceneView.translatesAutoresizingMaskIntoConstraints = false
return sceneView
}()
以及委托实现:
extension MainViewController: ARSessionDelegate {
func session(_ session: ARSession, didUpdate frame: ARFrame) {
let timeSinceLastUpdate = lastRenderTime - frame.timestamp
if timeSinceLastUpdate >= 0.1 || timeSinceLastUpdate < 0 {
lastRenderTime = frame.timestamp
// Do Updating Stuff
}
}
}
【问题讨论】: