TA159

Notas, resueltos y trabajos practicos de la materia Sistemas Gráficos
Index Commits Files Refs Submodules README LICENSE
commit bd41dbf3284389dabeb9c42c0cd73038904b7ae1
parent 28db1eb277ddbe87dc39929ccbfbc5d7b654d5b6
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date:   Wed,  3 Jul 2024 23:52:33 -0300

show tunnel and set the position on the scene

Diffstat:
Mtp/src/scene.js | 11+++++++++--
Mtp/src/tunnel.js | 5++++-
2 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/tp/src/scene.js b/tp/src/scene.js
@@ -311,7 +311,8 @@ function buildTerrain() {
 }
 
 function buildTunnel() {
-    const tunnelGeometry = generateTunnelGeometry();
+    // tunnelHeight = 20, tunnelWidth = 14, tunnelWallThickness = 0.5, tunnelLen = 26
+    const tunnelGeometry = generateTunnelGeometry(24, 12, 0.5, 46);
 
     textures.madera.object.wrapS = THREE.RepeatWrapping;
     textures.madera.object.wrapT = THREE.RepeatWrapping;
@@ -328,6 +329,12 @@ function buildTunnel() {
 
     const tunnel = new THREE.Mesh(tunnelGeometry, tunnelMaterial) ;
     tunnel.scale.set(0.5, 0.5, 0.5);
+
+    const trainPathPos = getRailsPathPosAt(0.32);
+    tunnel.position.set(trainPathPos[0].x, 0, trainPathPos[0].z);
+    tunnel.lookAt(trainPathPos[1].x*1000, 0, trainPathPos[1].z*1000);
+    console.log(trainPathPos);
+
     scene.add(tunnel);
 }
 
@@ -348,8 +355,8 @@ function createMenu() {
 
 function buildScene() {
     console.log('Building scene');
-    // buildTunnel();
     buildTrees(200);
+    buildTunnel();
     buildTerrain();
     buildRailsFoundation();
     buildRails();
diff --git a/tp/src/tunnel.js b/tp/src/tunnel.js
@@ -41,6 +41,9 @@ export function generateTunnelGeometry(
     };
 
     const geometry = new THREE.ExtrudeGeometry(shape, extrudeSettings);
-    geometry.translate(0, 0, -tunnelLen/2);
+
+    // el `1` en `x` es porque por algun motivo queda descentrado con respecto
+    // a la vía del tren
+    geometry.translate(1, 0, -tunnelLen/2);
     return geometry;
 }