Skip to content

Commit

Permalink
SpotLight --> DirectionalLight
Browse files Browse the repository at this point in the history
A SpotLight must have its distance set in real world coordinates.
This was resulting in very dark scenes, where the position of the light or its intensity must take into account the bounding box.
Directional Lights do not require this settings. They light the scene in a uniform manner from afar.
  • Loading branch information
ppillot committed Mar 17, 2024
1 parent e173521 commit f9802b2
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/viewer/viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
ShaderMaterial,
PlaneGeometry,
Scene, Mesh, Group, Object3D, Uniform,
Fog, SpotLight, AmbientLight,
Fog, DirectionalLight, AmbientLight,
BufferGeometry, BufferAttribute,
LineSegments, ColorSpace
} from 'three'
Expand Down Expand Up @@ -203,7 +203,7 @@ export default class Viewer {
height: number

scene: Scene
private spotLight: SpotLight
private directionalLight: DirectionalLight
private ambientLight: AmbientLight
rotationGroup: Group
translationGroup: Group
Expand Down Expand Up @@ -402,10 +402,10 @@ export default class Viewer {

// light

this.spotLight = new SpotLight(
this.directionalLight = new DirectionalLight(
this.parameters.lightColor.getHex(), this.parameters.lightIntensity
)
this.scene.add(this.spotLight)
this.scene.add(this.directionalLight)

this.ambientLight = new AmbientLight(
this.parameters.ambientColor.getHex(), this.parameters.ambientIntensity
Expand Down Expand Up @@ -1226,11 +1226,11 @@ export default class Viewer {
}

private __updateLights () {
this.spotLight.color.set(this.parameters.lightColor)
this.spotLight.intensity = this.parameters.lightIntensity
this.directionalLight.color.set(this.parameters.lightColor)
this.directionalLight.intensity = this.parameters.lightIntensity

this.distVector.copy(this.camera.position).setLength(this.boundingBoxLength * 100)
this.spotLight.position.copy(this.camera.position).add(this.distVector)
this.directionalLight.position.copy(this.camera.position).add(this.distVector)

this.ambientLight.color.set(this.parameters.ambientColor)
this.ambientLight.intensity = this.parameters.ambientIntensity
Expand Down

0 comments on commit f9802b2

Please sign in to comment.