Skip to content

Commit

Permalink
Refactored Light Estimator
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasGorisse committed Oct 27, 2023
1 parent 815f6a3 commit d2bfbfc
Show file tree
Hide file tree
Showing 11 changed files with 237 additions and 317 deletions.
82 changes: 48 additions & 34 deletions arsceneview/src/main/java/io/github/sceneview/ar/ARSceneView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@ import io.github.sceneview.ar.camera.ARCameraStream
import io.github.sceneview.ar.node.ARCameraNode
import io.github.sceneview.ar.node.PoseNode
import io.github.sceneview.ar.scene.PlaneRenderer
import io.github.sceneview.environment.Environment
import io.github.sceneview.loaders.MaterialLoader
import io.github.sceneview.loaders.ModelLoader
import io.github.sceneview.node.LightNode
import io.github.sceneview.node.Node
import io.github.sceneview.utils.setKeepScreenOn

/**
* ### A SurfaceView that integrates with ARCore and renders a scene
* A SurfaceView that integrates with ARCore and renders a scene
*
* @param sessionFeatures Fundamental session features
*/
Expand Down Expand Up @@ -206,6 +205,30 @@ open class ARSceneView @JvmOverloads constructor(
*/
val planeRenderer = PlaneRenderer(engine, modelLoader, materialLoader, scene)

final override var indirectLight: IndirectLight? = super.indirectLight
set(value) {
super.indirectLight = value
field = value
}

var indirectLightEstimated: IndirectLight?
get() = super.indirectLight
private set(value) {
super.indirectLight = value
}

final override var mainLightNode: LightNode? = super.mainLightNode
set(value) {
super.mainLightNode = value
field = value
}

var mainLightEstimatedNode: LightNode?
get() = super.mainLightNode
set(value) {
super.mainLightNode = value
}

/**
* The environment and main light that are estimated by AR Core to render the scene.
*
Expand All @@ -216,41 +239,32 @@ open class ARSceneView @JvmOverloads constructor(

var lightEstimation: LightEstimator.Estimation? = null
private set(value) {
value?.mainLightColorFactor?.let {
mainLightNode?.color = DEFAULT_MAIN_LIGHT_COLOR * it
}
value?.mainLightIntensityFactor?.let {
mainLightNode?.intensity = DEFAULT_MAIN_LIGHT_INTENSITY * it
}
value?.mainLightDirection?.let {
mainLightNode?.lightDirection = it
}
value?.environment?.let {
environment = it
// Delete previous environment only in case of new one
if (field?.environment != it) {
field?.environment?.destroy()
}
}
field = value
if (value != null) {
mainLightNode?.let { mainLightNode ->
value.mainLightColor?.let {
mainLightEstimatedNode?.color = mainLightNode.color * it
}
value.mainLightIntensity?.let {
mainLightEstimatedNode?.intensity = mainLightNode.intensity * it
}
value.mainLightDirection?.let {
mainLightEstimatedNode?.lightDirection = it
}
}

onLightEstimationUpdated?.invoke(value)
}

override var environment: Environment?
get() = super.environment
set(value) {
super.environment = value
lightEstimator?.baseSphericalHarmonics = value?.sphericalHarmonics
}

override var indirectLight: IndirectLight?
get() = super.indirectLight
set(value) {
if (super.indirectLight != value) {
super.indirectLight = value
lightEstimator?.setBaseIndirectLight(value)
indirectLightEstimated = IndirectLight.Builder().apply {
value.irradiance?.let {
irradiance(3, it)
} ?: indirectLight?.irradianceTexture?.let { irradiance(it) }
value.reflections?.let {
reflections(it)
} ?: indirectLight?.reflectionsTexture?.let { reflections(it) }
indirectLight?.intensity?.let { intensity(it) }
indirectLight?.getRotation(null)?.let { rotation(it) }
}.build(engine)
}
onLightEstimationUpdated?.invoke(value)
}

var trackingFailureReason: TrackingFailureReason? = null
Expand Down
Loading

0 comments on commit d2bfbfc

Please sign in to comment.