TA159

Notas, resueltos y trabajos practicos de la materia Sistemas Gráficos
Index Commits Files Refs Submodules README LICENSE
commit 12433a1a0ca13a39486394c59136db30ad385ce4
parent 167f6d8a8d7e55cc467a15018f2266f135637120
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date:   Sat,  6 Jul 2024 17:57:16 -0300

make `train` dimensinos smaller

Diffstat:
Mtp/src/scene.js | 13+++++++------
Mtp/src/standalone/train.js | 145++++++++++++++++++++++++++++++++++++++++++++++++++++---------------------------
Mtp/src/train.js | 76+++++++++++++++++++++++++++++++++++++---------------------------------------
3 files changed, 140 insertions(+), 94 deletions(-)
diff --git a/tp/src/scene.js b/tp/src/scene.js
@@ -404,8 +404,8 @@ function buildLoco() {
     const trainCamera = new THREE.PerspectiveCamera(
         55, window.innerWidth / window.innerHeight, 0.1, 10000);
 
-    trainCamera.position.set(-22, 12, -26);
-    trainCamera.lookAt(0, 10, 20);
+    trainCamera.position.set(-12, 6, -20);
+    trainCamera.lookAt(0, 10, 15);
     train.add(trainCamera);
     trainCamera.name = `trainCamera`;
     cameras.push(trainCamera);
@@ -419,7 +419,8 @@ function buildLoco() {
     trainBackCamera.name = "trainBackCamera";
     cameras.push(trainBackCamera);
 
-    train.scale.set(0.075, 0.10, 0.09);
+
+    train.scale.set(0.145, 0.145, 0.145);
     train.visible = settings.showTrain;
     scene.add(train);
 }
@@ -787,19 +788,19 @@ function mainLoop() {
     }
 
     if(train.visible) {
-        updateTrainCrankPosition(time*100);
+        updateTrainCrankPosition(time*200);
         const trainPos = getRailsPathPosAt(time);
         const railsData = getRailsPathPosAt(time);
 
         let x = railsData[0].x;
         let z = railsData[0].z;
 
-        train.position.set(-1+x, 2.25, -1+z);
+        train.position.set(-1+x, 2.30, -1+z);
         train.lookAt(railsData[1].x*1000, 1.9, railsData[1].z*1000);
     }
 
     let time2 = performance.now();
-    const firstPersonCameraHeight = 1.90;
+    const firstPersonCameraHeight = 1.60;
     if (firstPersonControls.isLocked === true) {
         raycaster = new THREE.Raycaster();
         var raycasterPos = new THREE.Vector3();
diff --git a/tp/src/standalone/train.js b/tp/src/standalone/train.js
@@ -51,29 +51,29 @@ function setupThreeJs() {
     onResize();
 }
 
-const steamChamberLen = 20;
-const steamChamberRad = 5;
-const steamChamberEndRad = steamChamberRad+0.75;
-const steamChamberEndLen = 5;
-const cabinLen = 10;
-const cabinHeight = 11;
-const cabinRoofHeight = 8;
-const cabinWallThickness = 0.75;
-const wheelRad = 2.75;
-const chassisHeight = 5;
-const wheelThickness = 0.85;
-const chassisOffset = 2.49;
-const wheelOffset = -0.70;
-const steamCylindersLen = 8;
-const crankLen = 22;
-const crankOffset = 3.750;
-const crankWidth = 0.5;
+const steamChamberLen = 10;
+const steamChamberRad = 2.50;
+const steamChamberEndRad = steamChamberRad+0.375;
+const steamChamberEndLen = 2.50;
+const cabinLen = 5;
+const cabinHeight = 6;
+const cabinRoofHeight = 3;
+const cabinWallThickness = 0.375;
+const wheelRad = 1.475;
+const chassisHeight = 2.5;
+const wheelThickness = 0.425;
+const chassisOffset = 1.245;
+const wheelOffset = -0.45;
+const steamCylindersLen = 4;
+const crankLen = 10;
+const crankOffset = 0.60;
+const crankWidth = 0.25;
 
 let crankLeft, crankRight;
 
 function buildCabinRoof() {
     console.log('Building train cabin roof');
-    const geometry = new THREE.BoxGeometry(12, cabinWallThickness, 12);
+    const geometry = new THREE.BoxGeometry(6, cabinWallThickness, 6);
     return geometry;
 }
 
@@ -82,38 +82,82 @@ function buildCabin() {
 
     let cabin = [];
 
-    const cabinFront = new THREE.BoxGeometry(steamChamberRad*2, cabinWallThickness, cabinHeight);
+    const cabinFront = new THREE.BoxGeometry(
+        steamChamberRad*2,
+        cabinWallThickness,
+        cabinHeight);
+
     cabinFront.translate(0, cabinLen/2, -cabinHeight/2);
     cabin.push(cabinFront);
 
-    const cabinLeft = new THREE.BoxGeometry(steamChamberRad*2, cabinWallThickness, cabinHeight);
+    const cabinLeft = new THREE.BoxGeometry(
+        steamChamberRad*2,
+        cabinWallThickness,
+        cabinHeight);
+
     cabinLeft.rotateZ(Math.PI/2);
-    cabinLeft.translate(steamChamberRad-cabinWallThickness/2, cabinWallThickness/2, -cabinHeight/2);
+    cabinLeft.translate(
+        steamChamberRad-cabinWallThickness/2,
+        cabinWallThickness/2,
+        -cabinHeight/2);
+
     cabin.push(cabinLeft);
 
-    const cabinRight = new THREE.BoxGeometry(steamChamberRad*2, cabinWallThickness, cabinHeight);
+    const cabinRight = new THREE.BoxGeometry(
+        steamChamberRad*2,
+        cabinWallThickness,
+        cabinHeight);
+
     cabinRight.rotateZ(Math.PI/2);
-    cabinRight.translate(-steamChamberRad+cabinWallThickness/2, cabinWallThickness/2, -cabinHeight/2);
+    cabinRight.translate(
+        -steamChamberRad+cabinWallThickness/2,
+        cabinWallThickness/2,
+        -cabinHeight/2);
+
     cabin.push(cabinRight);
 
-    const g1 = new THREE.BoxGeometry(cabinWallThickness, cabinWallThickness, cabinRoofHeight);
+    const g1 = new THREE.BoxGeometry(
+        cabinWallThickness, cabinWallThickness, cabinRoofHeight);
+
     g1.rotateZ(Math.PI/2);
-    g1.translate(-steamChamberRad+(cabinWallThickness/2), -steamChamberRad+cabinWallThickness, -cabinHeight-cabinRoofHeight/2);
+    g1.translate(
+        -steamChamberRad+(cabinWallThickness/2),
+        -steamChamberRad+cabinWallThickness,
+        -cabinHeight-cabinRoofHeight/2);
+
     cabin.push(g1);
 
-    const g2 = new THREE.BoxGeometry(cabinWallThickness, cabinWallThickness, cabinRoofHeight);
+    const g2 = new THREE.BoxGeometry(
+        cabinWallThickness, cabinWallThickness, cabinRoofHeight);
+
     g2.rotateZ(Math.PI/2);
-    g2.translate(steamChamberRad-cabinWallThickness/2, steamChamberRad, -cabinHeight-cabinRoofHeight/2);
+    g2.translate(
+        steamChamberRad-cabinWallThickness/2,
+        steamChamberRad,
+        -cabinHeight-cabinRoofHeight/2);
+
     cabin.push(g2);
 
-    const g3 = new THREE.BoxGeometry(cabinWallThickness, cabinWallThickness, cabinRoofHeight);
+    const g3 = new THREE.BoxGeometry(
+        cabinWallThickness, cabinWallThickness, cabinRoofHeight);
+
     g3.rotateZ(Math.PI/2);
-    g3.translate(steamChamberRad-cabinWallThickness/2, -steamChamberRad+cabinWallThickness, -cabinHeight-cabinRoofHeight/2);
+    g3.translate(
+        steamChamberRad-cabinWallThickness/2,
+        -steamChamberRad+cabinWallThickness,
+        -cabinHeight-cabinRoofHeight/2);
+
     cabin.push(g3);
 
-    const g4 = new THREE.BoxGeometry(cabinWallThickness, cabinWallThickness, cabinRoofHeight);
+    const g4 = new THREE.BoxGeometry(
+        cabinWallThickness, cabinWallThickness, cabinRoofHeight);
+
     g4.rotateZ(Math.PI/2);
-    g4.translate(-steamChamberRad+cabinWallThickness/2, steamChamberRad, -cabinHeight-cabinRoofHeight/2);
+    g4.translate(
+        -steamChamberRad+cabinWallThickness/2,
+        steamChamberRad,
+        -cabinHeight-cabinRoofHeight/2);
+
     cabin.push(g4);
 
     const geometry = BufferGeometryUtils.mergeGeometries(cabin);
@@ -135,20 +179,22 @@ function buildChamber() {
     steamChamberEnd.translate(0,steamChamberLen/2 + steamChamberEndLen/2,0);
     geometries.push(steamChamberEnd);
 
-    const floor = new THREE.BoxGeometry(steamChamberRad*2, steamChamberLen + steamChamberEndLen + cabinLen, 1.0);
+    const floor = new THREE.BoxGeometry(
+        steamChamberRad*2, steamChamberLen + steamChamberEndLen + cabinLen, 1.0);
     floor.translate(0, -steamChamberEndLen/2, steamChamberRad);
     geometries.push(floor);
 
-    const chamberPipeLen = 8;
-    const chamberPipe = new THREE.CylinderGeometry(0.75, 0.75, chamberPipeLen, 32);
+    const chamberPipeLen = 4;
+    const chamberPipe = new THREE.CylinderGeometry(0.55, 0.55, chamberPipeLen, 32);
     chamberPipe.translate(0, -(steamChamberRad + chamberPipeLen/2)+1.0,
         -(steamChamberLen+steamChamberEndLen)/2);
+
     chamberPipe.rotateX(Math.PI/2);
     geometries.push(chamberPipe);
 
     const geometry = BufferGeometryUtils.mergeGeometries(geometries);
     geometry.rotateX(Math.PI/2);
-    geometry.translate(0, steamChamberRad, 0);
+    geometry.translate(0, steamChamberRad+0.25, 0);
     return geometry;
 }
 
@@ -169,7 +215,7 @@ function buildTrainWheel() {
 }
 
 function buildTrainAxe(material) {
-    const axeGeometry = new THREE.CylinderGeometry(0.65, 0.65, 10);
+    const axeGeometry = new THREE.CylinderGeometry(0.325, 0.325, 5);
     axeGeometry.rotateZ(Math.PI/2);
 
     const axeMaterial = new THREE.MeshPhongMaterial({
@@ -182,7 +228,7 @@ function buildTrainAxe(material) {
 }
 
 function buildTrainChassis() {
-    const chassis = new THREE.BoxGeometry(7, 5, steamChamberLen+steamChamberEndLen+cabinLen);
+    const chassis = new THREE.BoxGeometry(3.5, 2.5, steamChamberLen+steamChamberEndLen+cabinLen);
     return chassis;
 }
 
@@ -214,7 +260,9 @@ function buildTrain() {
     const cabinGeometry = buildCabin();
     const cabin = new THREE.Mesh(cabinGeometry, chamberMaterial);
     chassis.add(cabin);
-    cabin.position.set(0, (chassisHeight + cabinWallThickness)/2, -steamChamberLen+(cabinLen/2)+chassisOffset);
+    cabin.position.set(0,
+        (chassisHeight + cabinWallThickness)/2,
+        -steamChamberLen+(cabinLen/2)+chassisOffset);
 
     const cabinRoofGeometry = buildCabinRoof();
     const roofMaterial = new THREE.MeshPhongMaterial({
@@ -236,18 +284,17 @@ function buildTrain() {
     const a3 = buildTrainAxe(chassisMaterial);
     chassis.add(a3);
 
-    a1.position.set(0, wheelOffset, 0);
-    a2.position.set(0, wheelOffset, wheelRad*2.5);
-    a3.position.set(0, wheelOffset, -wheelRad*2.5);
-
+    a1.position.set(0, wheelOffset, -0.60);
+    a2.position.set(0, wheelOffset, -0.60+wheelRad*2.5);
+    a3.position.set(0, wheelOffset, -0.60-wheelRad*2.5);
 
-    const cylinderLeft = new THREE.CylinderGeometry(2.25, 2.5, steamCylindersLen);
+    const cylinderLeft = new THREE.CylinderGeometry(1.25, 1.5, steamCylindersLen);
     cylinderLeft.rotateX(Math.PI/2);
-    cylinderLeft.translate(steamChamberRad-0.25, 0, steamChamberLen-steamCylindersLen/1.5);
+    cylinderLeft.translate(steamChamberRad-0.25, -.25, steamChamberLen-steamCylindersLen/1.5);
 
-    const cylinderRight = new THREE.CylinderGeometry(2.25, 2.5, steamCylindersLen);
+    const cylinderRight = new THREE.CylinderGeometry(1.25, 1.5, steamCylindersLen);
     cylinderRight.rotateX(Math.PI/2);
-    cylinderRight.translate(-steamChamberRad+0.25, 0, steamChamberLen-steamCylindersLen/1.5);
+    cylinderRight.translate(-steamChamberRad+0.25, -.25, steamChamberLen-steamCylindersLen/1.5);
 
     const cylindersGeometry = BufferGeometryUtils.mergeGeometries([cylinderRight, cylinderLeft]);
     const cylindersMaterial = new THREE.MeshPhongMaterial({
@@ -283,7 +330,7 @@ function buildTrain() {
     w6.position.set(-steamChamberRad+wheelThickness/2.1,0,0);
     a3.add(w6);
 
-    const crankGeometry = new THREE.BoxGeometry(crankWidth, 1.0, crankLen);
+    const crankGeometry = new THREE.BoxGeometry(crankWidth, 0.5, crankLen);
 
     crankRight = new THREE.Mesh(crankGeometry, chassisMaterial);
     //crankRight.position.set(steamChamberRad, wheelOffset, crankOffset);
@@ -319,11 +366,11 @@ function mainLoop() {
     requestAnimationFrame(mainLoop);
 
     crankLeft.position.set(-steamChamberRad-crankWidth/2,
-        wheelOffset+1.00*(Math.sin(time*Math.PI/2)),
+        wheelOffset + 1.00*(Math.sin(time*Math.PI/2)),
         crankOffset - 1.00*(Math.cos(time*Math.PI/2)));
 
     crankRight.position.set(steamChamberRad+crankWidth/2,
-        wheelOffset+1.00*(Math.sin(time*Math.PI/2)),
+        wheelOffset + 1.00*(Math.sin(time*Math.PI/2)),
         crankOffset - 1.00*(Math.cos(time*Math.PI/2)));
 
     renderer.render(scene, camera);
diff --git a/tp/src/train.js b/tp/src/train.js
@@ -1,29 +1,29 @@
 import * as THREE from 'three';
 import * as BufferGeometryUtils from 'three/addons/utils/BufferGeometryUtils.js';
 
-const steamChamberLen = 20;
-const steamChamberRad = 5;
-const steamChamberEndRad = steamChamberRad+0.75;
-const steamChamberEndLen = 5;
-const cabinLen = 10;
-const cabinHeight = 11;
-const cabinRoofHeight = 8;
-const cabinWallThickness = 0.75;
-const wheelRad = 2.75;
-const chassisHeight = 5;
-const wheelThickness = 0.85;
-const chassisOffset = 2.49;
-const wheelOffset = -0.70;
-const steamCylindersLen = 8;
-const crankLen = 22;
-const crankOffset = 3.750;
-const crankWidth = 0.5;
+const steamChamberLen = 10;
+const steamChamberRad = 2.50;
+const steamChamberEndRad = steamChamberRad+0.375;
+const steamChamberEndLen = 2.50;
+const cabinLen = 5;
+const cabinHeight = 6;
+const cabinRoofHeight = 3;
+const cabinWallThickness = 0.375;
+const wheelRad = 1.475;
+const chassisHeight = 2.5;
+const wheelThickness = 0.425;
+const chassisOffset = 1.245;
+const wheelOffset = -0.45;
+const steamCylindersLen = 4;
+const crankLen = 10;
+const crankOffset = 0.60;
+const crankWidth = 0.25;
 
 let crankLeft, crankRight;
 
 function buildCabinRoof() {
     console.log('Building train cabin roof');
-    const geometry = new THREE.BoxGeometry(12, cabinWallThickness, 12);
+    const geometry = new THREE.BoxGeometry(6, cabinWallThickness, 6);
     return geometry;
 }
 
@@ -134,11 +134,9 @@ function buildChamber() {
     floor.translate(0, -steamChamberEndLen/2, steamChamberRad);
     geometries.push(floor);
 
-    const chamberPipeLen = 8;
-    const chamberPipe = new THREE.CylinderGeometry(0.75, 0.75, chamberPipeLen, 32);
-
-    chamberPipe.translate(0,
-        -(steamChamberRad + chamberPipeLen/2)+1.0,
+    const chamberPipeLen = 4;
+    const chamberPipe = new THREE.CylinderGeometry(0.55, 0.55, chamberPipeLen, 32);
+    chamberPipe.translate(0, -(steamChamberRad + chamberPipeLen/2)+1.0,
         -(steamChamberLen+steamChamberEndLen)/2);
 
     chamberPipe.rotateX(Math.PI/2);
@@ -146,7 +144,7 @@ function buildChamber() {
 
     const geometry = BufferGeometryUtils.mergeGeometries(geometries);
     geometry.rotateX(Math.PI/2);
-    geometry.translate(0, steamChamberRad, 0);
+    geometry.translate(0, steamChamberRad+0.25, 0);
     return geometry;
 }
 
@@ -167,7 +165,7 @@ function buildTrainWheel() {
 }
 
 function buildTrainAxe(material) {
-    const axeGeometry = new THREE.CylinderGeometry(0.65, 0.65, 10);
+    const axeGeometry = new THREE.CylinderGeometry(0.325, 0.325, 5);
     axeGeometry.rotateZ(Math.PI/2);
 
     const axeMaterial = new THREE.MeshPhongMaterial({
@@ -180,7 +178,7 @@ function buildTrainAxe(material) {
 }
 
 function buildTrainChassis() {
-    const chassis = new THREE.BoxGeometry(7, 5, steamChamberLen+steamChamberEndLen+cabinLen);
+    const chassis = new THREE.BoxGeometry(3.5, 2.5, steamChamberLen+steamChamberEndLen+cabinLen);
     return chassis;
 }
 
@@ -236,17 +234,17 @@ export function buildTrain() {
     const a3 = buildTrainAxe(chassisMaterial);
     chassis.add(a3);
 
-    a1.position.set(0, wheelOffset, 0);
-    a2.position.set(0, wheelOffset, wheelRad*2.5);
-    a3.position.set(0, wheelOffset, -wheelRad*2.5);
+    a1.position.set(0, wheelOffset, -0.60);
+    a2.position.set(0, wheelOffset, -0.60+wheelRad*2.5);
+    a3.position.set(0, wheelOffset, -0.60-wheelRad*2.5);
 
-    const cylinderLeft = new THREE.CylinderGeometry(2.25, 2.5, steamCylindersLen);
+    const cylinderLeft = new THREE.CylinderGeometry(1.25, 1.5, steamCylindersLen);
     cylinderLeft.rotateX(Math.PI/2);
-    cylinderLeft.translate(steamChamberRad-0.25, 0, steamChamberLen-steamCylindersLen/1.5);
+    cylinderLeft.translate(steamChamberRad-0.25, -.25, steamChamberLen-steamCylindersLen/1.5);
 
-    const cylinderRight = new THREE.CylinderGeometry(2.25, 2.5, steamCylindersLen);
+    const cylinderRight = new THREE.CylinderGeometry(1.25, 1.5, steamCylindersLen);
     cylinderRight.rotateX(Math.PI/2);
-    cylinderRight.translate(-steamChamberRad+0.25, 0, steamChamberLen-steamCylindersLen/1.5);
+    cylinderRight.translate(-steamChamberRad+0.25, -.25, steamChamberLen-steamCylindersLen/1.5);
 
     const cylindersGeometry = BufferGeometryUtils.mergeGeometries([cylinderRight, cylinderLeft]);
     const cylindersMaterial = new THREE.MeshPhongMaterial({
@@ -282,7 +280,7 @@ export function buildTrain() {
     w6.position.set(-steamChamberRad+wheelThickness/2.1,0,0);
     a3.add(w6);
 
-    const crankGeometry = new THREE.BoxGeometry(crankWidth, 1.0, crankLen);
+    const crankGeometry = new THREE.BoxGeometry(crankWidth, 0.5, crankLen);
 
     crankRight = new THREE.Mesh(crankGeometry, chassisMaterial);
     //crankRight.position.set(steamChamberRad, wheelOffset, crankOffset);
@@ -296,16 +294,16 @@ export function buildTrain() {
     // chassis.translateY(-wheelOffset);
     updateTrainCrankPosition();
 
-    train.position.set(0, 1.9, 0);
+    train.position.set(0, 2, 0);
     return train;
 }
 
 export function updateTrainCrankPosition(time = 0.0) {
     crankLeft.position.set(-steamChamberRad-crankWidth/2,
-        wheelOffset+1.00*(Math.sin(time*Math.PI*2)),
-        crankOffset - 1.00*(Math.cos(time*Math.PI*2)));
+        wheelOffset + 1.00*(Math.sin(time*Math.PI/2)),
+        crankOffset - 1.00*(Math.cos(time*Math.PI/2)));
 
     crankRight.position.set(steamChamberRad+crankWidth/2,
-        wheelOffset+1.00*(Math.sin(time*Math.PI*2)),
-        crankOffset - 1.00*(Math.cos(time*Math.PI*2)));
+        wheelOffset + 1.00*(Math.sin(time*Math.PI/2)),
+        crankOffset - 1.00*(Math.cos(time*Math.PI/2)));
 }