swift - ARKit – 光估计

标签 swift abstract-class augmented-reality scenekit arkit

我收到有关 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 中的环境光传感器来检测环境光。

最佳答案

Here's how you can use Light Estimation in ARKit – 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
     }
    

关于swift - ARKit – 光估计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59756284/

相关文章:

ios - 推送通知有关

ios - 在标签上打印 Instagram 帖子回复时出现问题

swift - 如何使用 Swift 选择 UITextField 中的所有文本

unity-game-engine - Vuforia(Unity 创建的 Xcode 项目)添加到现有 Xcode 应用程序后显示空白屏幕

iphone - 具有透明背景的增强现实视频播放

xcode - 在 Xcode 编辑器中看不到 3D 模型文件

swift - 便利初始化程序不断崩溃,但指定的初始化程序工作正常吗?

scala:抽象类实例化?

c# - 抽象类的继承使用不同于为属性定义的类型

swift - 如何使用 Swift 的类似 'abstract class' 的协议(protocol)扩展来访问方法中的静态变量