commit ef2dacdd2d49be1e1bbd2f066bc5b3dd7acfa548
parent 0193c78dc8a4fc246df59783f89bde124eb9356a
Author: Martin Klöckner <mjkloeckner@gmail.com>
Date: Fri, 28 Jun 2024 11:47:05 -0300
add function `getRailsPathPosAt` to module `rails.js`
Diffstat:
2 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/tp/src/rails.js b/tp/src/rails.js
@@ -22,6 +22,13 @@ const textures = {
durmientes: { url: '/assets/durmientes.jpg', object: null },
};
+export function getRailsPathPosAt(t) {
+ if(railsPath == undefined) {
+ console.log("railsPath is undefined");
+ }
+ return railsPath.getPointAt(t);
+}
+
function parametricRailsFoundationFunction(u, v, target) {
const rotMatrix = new THREE.Matrix4();
const translationMatrix = new THREE.Matrix4();
diff --git a/tp/src/scene.js b/tp/src/scene.js
@@ -7,6 +7,7 @@ import { generateTunnelGeometry } from '/src/tunnel.js';
import { createInstancedTrees } from '/src/track-map.js';
import { elevationGeometry } from '/src/terrain.js';
import {
+ getRailsPathPosAt,
buildRailsGeometry,
buildRailsFoundationGeometry
} from '/src/rails.js';
@@ -17,7 +18,6 @@ import { updateTrainCrankPosition } from '/src/train.js';
let scene, camera, renderer, container, terrainMaterial, terrainGeometry, terrain, time;
let treesForbiddenMapData, treesForbiddenMap, elevationMap, elevationMapData;
-
// actualizar la variable global `amplitude` de '/src/track-map/'
const widthSegments = 150;
const heightSegments = 150;
@@ -36,6 +36,7 @@ const textures = {
let settings = {
animationEnable: false,
+ showTrain: false
};
function onResize() {
@@ -127,10 +128,13 @@ function buildBridge() {
scene.add(bridge2);
}
+let train;
+
// loco -> locomotora/locomotive
function buildLoco() {
- const train = buildTrain();
- train.scale.set(0.35, 0.35, 0.35)
+ train = buildTrain();
+ train.scale.set(0.10, 0.10, 0.10);
+ train.rotateY(Math.PI/8);
scene.add(train);
}
@@ -263,17 +267,24 @@ function buildScene() {
buildTerrain();
buildRailsFoundation();
buildRails();
- // buildLoco();
+ buildLoco();
buildBridge();
}
function mainLoop() {
requestAnimationFrame(mainLoop);
renderer.render(scene, camera);
+ const translationMatrix = new THREE.Matrix4();
+
+ train.position.set(-10, 2.25, 0);
- time += 0.05;
- if(settings.animationEnable) {
+ time += 0.10;
+ if(settings.animationEnable && ((time % 1) != 0)) {
updateTrainCrankPosition(time);
+ // const railsPos = getRailsPathPosAt(time % 1.0);
+ // console.log(railsPos);
+ // translationMatrix.makeTranslation(railsPos);
+ // train.applyMatrix(translationMatrix);
}
renderer.render(scene, camera);
}