【问题标题】:ARKit – Light EstimationARKit – 光照估计
【发布时间】:2020-01-15 17:00:16
【问题描述】:

我收到关于 init() 不可用于 ARLightEstimate 的错误消息。

代码:

class LightSensorManager {

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

    init() {
        ambientLightIntensity = lightEstimate.ambientIntensity
    }
}

错误:

/*   'init()' is unavailable    */

API to ARLightEstimation - ARKit

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

【问题讨论】:

    标签: swift abstract-class augmented-reality scenekit arkit


    【解决方案1】:

    这是在 ARKit 中使用 Light Estimation 的方法 – Full code version is HERE

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

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

       func renderer(_ renderer: SCNSceneRenderer, 
              updateAtTime time: TimeInterval) {
      
           guard let lightEstimate = sceneView.session.currentFrame?.lightEstimate 
           else { return } 
           spotLightNode.light?.intensity = lightEstimate.ambientIntensity
       }
      

    【讨论】:

      猜你喜欢
      • 2018-04-03
      • 2019-04-25
      • 2019-03-17
      • 1970-01-01
      • 2021-06-22
      • 2021-07-15
      • 2018-12-25
      • 2023-03-17
      • 2012-05-12
      相关资源
      最近更新 更多