我收到有关 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/