我收到关于init()
无法用于ARLightEstimate
的错误。
代码:
class LightSensorManager{
let lightEstimate = ARLightEstimate() // <-- error is here
var ambientLightIntensity: CGFloat
init() {
ambientLightIntensity = lightEstimate.ambientIntensity
}
}
错误:
'init()'不可用
API to ARLightEstimation - ARKit
我认为这是一个抽象类?但是我找不到它的具体子类。我只想使用此API中的环境光传感器来检测环境光。
这里是您如何在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