@@ -18,13 +18,12 @@ class Scene {
1818 constructor ( ) {
1919 this . scene = new THREE . Scene ( ) ;
2020
21- // light
22- const ambientLight = new THREE . AmbientLight ( 0xffffff , 1 ) ;
21+ // lighting
22+ const ambientLight = new THREE . AmbientLight ( 0xffffff , 0.5 ) ;
2323 this . scene . add ( ambientLight ) ;
2424
25- const directionalLight = new THREE . DirectionalLight ( 0xffffff , 0.3 ) ;
26- directionalLight . position . set ( 0. , 0. , 1 ) ;
27- this . scene . add ( directionalLight ) ;
25+ this . directionalLight = new THREE . DirectionalLight ( 0xffffff , 0.5 ) ;
26+ this . scene . add ( this . directionalLight ) ;
2827 }
2928
3029 /**
@@ -35,6 +34,10 @@ class Scene {
3534 block . addToScene ( this . scene ) ;
3635 }
3736
37+ handleCameraMove ( cameraPosition : THREE . Vector3 ) {
38+ this . directionalLight . position . set ( cameraPosition . x , cameraPosition . y , cameraPosition . z ) ;
39+ }
40+
3841 handleCameraMoveEnd ( cameraPosition : THREE . Vector3 ) {
3942 for ( const block of this . blocks ) {
4043 block . handleCameraMoveEnd ( cameraPosition ) ;
@@ -52,6 +55,8 @@ class Scene {
5255 scene : THREE . Scene ;
5356 blocks : Block [ ] = [ ] ;
5457
58+ private directionalLight : THREE . DirectionalLight ;
59+
5560}
5661
5762
@@ -106,8 +111,11 @@ class Renderer {
106111 this . controls . panSpeed = 0.9 ;
107112 this . controls . dynamicDampingFactor = 0.9 ;
108113
114+ this . controls . addEventListener ( 'change' , this . handleCameraMove . bind ( this ) ) ;
109115 this . controls . addEventListener ( 'end' , this . handleCameraMoveEnd . bind ( this ) ) ;
110116
117+ this . handleCameraMove ( ) ;
118+
111119 this . animate ( ) ;
112120 }
113121
@@ -189,6 +197,10 @@ class Renderer {
189197 this . controls . update ( ) ;
190198 }
191199
200+ handleCameraMove ( ) {
201+ this . scene . handleCameraMove ( this . camera . position ) ;
202+ }
203+
192204 handleCameraMoveEnd ( ) {
193205 this . scene . handleCameraMoveEnd ( this . camera . position ) ;
194206 }
0 commit comments