TA159

Notas, resueltos y trabajos practicos de la materia Sistemas Gráficos
Index Commits Files Refs Submodules README LICENSE
commit 6e95f52f42a0680cb6cdb5ca47953262ff49ab53
parent 0a1f7d86c87e7351c8af4bb4b224666a0ee11413
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date:   Sat,  6 Jul 2024 18:54:03 -0300

turn off train light if day mode

Diffstat:
Mtp/src/scene.js | 17++++++++++++-----
1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/tp/src/scene.js b/tp/src/scene.js
@@ -17,12 +17,13 @@ import { buildTrain } from '/src/train.js';
 import { generateBridge } from '/src/bridge.js';
 import { updateTrainCrankPosition } from '/src/train.js';
 
-let scene, camera, renderer, terrainMaterial, terrainGeometry, terrain, time;
+let scene, camera, renderer, terrainMaterial, terrainGeometry, terrain, time, gui;
 let treesForbiddenMapData, treesForbiddenMap, elevationMap, elevationMapData;
 
 let firstPersonControls, orbitControls;
 
-let train, gui;
+let train, trainLight, trainLight2, trainLight3;
+
 let cameras = [];
 let objects = [];
 let lights = {
@@ -439,21 +440,21 @@ function buildLoco() {
     cameras.push(trainBackCamera);
 
     // SpotLight(color: Int, intensity: Float, distance: Float, angle: Radians, penumbra: Float, decay: Float)
-    const trainLight = new THREE.SpotLight(0xffffff, 100.0, 2000.0, Math.PI/3, 0.5, 0.5);
+    trainLight = new THREE.SpotLight(0xffffff, 100.0, 2000.0, Math.PI/3, 0.5, 0.5);
     train.add(trainLight.target);
     train.add(trainLight);
     trainLight.position.set(0, 2, 15);
     trainLight.target.position.set(0, -100, 100);
     trainLight.target.updateMatrixWorld();
 
-    const trainLight2 = new THREE.SpotLight(0xffffff, 10.0, 4.0, Math.PI/2, 0.5, 0.5);
+    trainLight2 = new THREE.SpotLight(0xffffff, 10.0, 4.0, Math.PI/2, 0.5, 0.5);
     train.add(trainLight2.target);
     train.add(trainLight2);
     trainLight2.position.set(0, 5, 20);
     trainLight2.target.position.set(0, 0, -100);
     trainLight2.target.updateMatrixWorld();
 
-    const trainLight3 = new THREE.SpotLight(0xffffff, 10.0, 10.0, Math.PI/2, 0.5, 0.5);
+    trainLight3 = new THREE.SpotLight(0xffffff, 10.0, 10.0, Math.PI/2, 0.5, 0.5);
     train.add(trainLight3.target);
     train.add(trainLight3);
     trainLight3.position.set(0, 5, 10);
@@ -773,6 +774,9 @@ function toggleNightMode() {
         lights.directional.object.color.setHex(0xcdddfe); // 0x090254; 0xa8a1fd
         scene.background = textures.sky_night.object;
         lights.directional.object.position.set(100, 100, 100); // math the skybox texture moon light
+        trainLight.visible = true;
+        trainLight2.visible = true;
+        trainLight3.visible = true;
     } else {
         lights.ambient.object.visible = true;
         lights.hemisphere.object.intensity = 1;
@@ -780,6 +784,9 @@ function toggleNightMode() {
         lights.directional.object.color.setHex(0xFFFFFF);
         scene.background = textures.sky_day.object;
         lights.directional.object.position.set(-100, 100, 100);
+        trainLight.visible = false;
+        trainLight2.visible = false;
+        trainLight3.visible = false;
     }
 }