ARLightEstimate-init()不可用

问题描述 投票:1回答:1

我收到关于init()无法用于ARLightEstimate的错误。

  • Xcode版本:11.3.1
  • 快速版本:5

代码:

class LightSensorManager{

    let lightEstimate = ARLightEstimate()  // <-- error is here
    var ambientLightIntensity: CGFloat

    init() {
        ambientLightIntensity = lightEstimate.ambientIntensity
    }
}

错误:

'init()'不可用

API to ARLightEstimation - ARKit

我认为这是一个抽象类?但是我找不到它的具体子类。我只想使用此API中的环境光传感器来检测环境光。

ios swift abstract-class augmented-reality arkit
1个回答
1
投票

这里是您如何在ARKit中使用Light Estimation

  • 在viewWillAppear(_ :)实例方法中启用光照估计:

    let configuration = ARWorldTrackingConfiguration()
    configuration.lightEstimationEnabled = true
    
  • 更新渲染器中的光照(_:updateAtTime :)实例方法:

    func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval) {
    
        guard let lightEstimate = sceneView.session.currentFrame?.lightEstimate 
        else { return } 
        spotLight.intensity = lightEstimate.ambientIntensity / 1000.0
    }
    
  • 如果需要,请分配环境图:

    let environment = UIImage(named: "environmentMap.png")
    sceneView.scene.lightingEnvironment.contents = environment
    
  • 设置照明环境的强度:

    let intensity = lightEstimate.ambientIntensity / 1000.0 
    sceneView.scene.lightingEnvironment.intensity = intensity
    
© www.soinside.com 2019 - 2024. All rights reserved.