ARKit——光照估计
ARKit – Light Estimation
我收到有关 init()
不适用于 ARLightEstimate
的错误消息。
代码:
class LightSensorManager {
let lightEstimate = ARLightEstimate() // <-- error is here
var ambientLightIntensity: CGFloat
init() {
ambientLightIntensity = lightEstimate.ambientIntensity
}
}
错误:
/* 'init()' is unavailable */
API to ARLightEstimation - ARKit
我认为它是抽象的 class?但是我找不到它的具体子class。我只想使用此 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
}
我收到有关 init()
不适用于 ARLightEstimate
的错误消息。
代码:
class LightSensorManager {
let lightEstimate = ARLightEstimate() // <-- error is here
var ambientLightIntensity: CGFloat
init() {
ambientLightIntensity = lightEstimate.ambientIntensity
}
}
错误:
/* 'init()' is unavailable */
API to ARLightEstimation - ARKit
我认为它是抽象的 class?但是我找不到它的具体子class。我只想使用此 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 }