首页 > 解决方案 > RealityKit 让我的 iPhone 热状态无缘无故地发疯

问题描述

我有以下演示应用程序,其中我在 RealityKit 上设置了 ARWorldTrackingConfiguration。

我也使用平面检测。

当检测到飞机时,我会使用简单的方形碰撞框将矩形“发射”到飞机上。

大约 100 格后,应用程序thermalStatus更改为serious,我的帧速率下降到 30fps。

对于我的生活,我无法理解为什么 RealityKit 世界中没有特殊纹理甚至没有碰撞事件的 100 个简单形状会导致这种情况。

有人有什么主意吗?

PS1:在 iPhone XS 上运行,按照 HW 规格,它应该能够更好地执行。

PS2:添加以下代码


import UIKit
import RealityKit
import ARKit

let material = SimpleMaterial(color: .systemPink, isMetallic: false)
var sphere: MeshResource = MeshResource.generatePlane(width: 0.1, depth: 0.1)
var box = ShapeResource.generateBox(width: 0.1, height: 0.03, depth: 0.1)
var ballEntity = ModelEntity(mesh: sphere, materials: [material])
let collider = CollisionComponent(
  shapes: [box],
  mode: .trigger
)

class ViewController: UIViewController {

  @IBOutlet var arView: ARView!

  @IBOutlet weak var button: UIButton!

  override func viewDidLoad() {
    super.viewDidLoad()

    let configuration = ARWorldTrackingConfiguration()
    configuration.planeDetection = [.vertical]
    configuration.worldAlignment = .camera

    // Add the box anchor to the scene
    configuration.frameSemantics.remove(.bodyDetection)
    configuration.frameSemantics.remove(.personSegmentation)
    configuration.frameSemantics.remove(.personSegmentationWithDepth)

    arView.renderOptions.insert(.disableCameraGrain)
    arView.renderOptions.insert(.disableGroundingShadows)
    arView.renderOptions.insert(.disableHDR)
    arView.renderOptions.insert(.disableMotionBlur)
    arView.renderOptions.insert(.disableFaceOcclusions)
    arView.renderOptions.insert(.disableDepthOfField)
    arView.renderOptions.insert(.disablePersonOcclusion)

    configuration.planeDetection = [.vertical, .horizontal]

    arView.debugOptions = [.showAnchorGeometry, .showStatistics]

    let gesture = UITapGestureRecognizer(target: self,
                                         action: #selector(self.tap(_:)))
    arView.addGestureRecognizer(gesture)

    arView.session.run(configuration, options: [ .resetSceneReconstruction ])
  }

  @objc func tap(_ sender: UITapGestureRecognizer) {
    let point: CGPoint = sender.location(in: arView)

    guard let query = arView.makeRaycastQuery(from: point,
                                          allowing: .existingPlaneGeometry,
                                          alignment: .vertical) else {
      return
    }

    let result = arView.session.raycast(query)
    guard let raycastResult = result.first else { return }


    let anchor = AnchorEntity(raycastResult: raycastResult)
    var ballEntity = ModelEntity(mesh: sphere, materials: [material])
    ballEntity.collision = collider
    anchor.addChild(ballEntity)


    arView.scene.anchors.append(anchor)
  }


  @IBAction func removePlaneDebugging(_ sender: Any) {
    if arView.debugOptions.contains(.showAnchorGeometry) {
      arView.debugOptions.remove(.showAnchorGeometry)
      button.setTitle("Display planes", for: .normal)
      return
    }

    button.setTitle("Remove planes", for: .normal)
    arView.debugOptions.insert(.showAnchorGeometry)
  }
}

有人可以帮忙吗?

标签: iosswiftaugmented-realityarkitrealitykit

解决方案


当您使用 ARKit 或 RealityKit 时,iPhone 的热状况并不完全取决于 100 个图元的实时渲染。重点是以 60 fps 运行的 6 自由度世界跟踪。平面检测是hard core您设备的另一项功能。因此,世界跟踪和平面检测操作是 CPU/GPU 密集型操作(以及图像/对象检测或人员遮挡)。它们还会迅速耗尽您的电池电量。

CPU/GPU 的另一个沉重负担是阴影和反射金属着色器。实时 60 fps 软阴影是任何设备(即使使用 A12 处理器)的额外任务,并且使用环境反射的金属纹理是在神经引擎上计算的。


推荐阅读