commit 528f85d2b1f00eab9b8e90db538d3e4e71abec44
parent 4179de4d4eb68701922d0ce68065e2afdf55fd18
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date: Fri, 28 Jun 2024 00:47:09 -0300
add `rails` and `railsFoundation` to scene
Diffstat:
3 files changed, 45 insertions(+), 22 deletions(-)
diff --git a/tp/src/rails.js b/tp/src/rails.js
@@ -70,7 +70,7 @@ export function buildRailsFoundationGeometry() {
*/
const pGeometry = new ParametricGeometry(
- parametricRailsFoundationFunction, 100, 100);
+ parametricRailsFoundationFunction, 250, 250);
return pGeometry;
}
@@ -170,11 +170,19 @@ function loadTextures(callback) {
function main() {
railsPath = new THREE.CatmullRomCurve3([
- new THREE.Vector3(-10, 0, 10),
- new THREE.Vector3( 10, 0, 10),
- new THREE.Vector3( 10, 0, -10),
- new THREE.Vector3(-10, 0, -10),
- ], true);
+ // bridge1 side
+ new THREE.Vector3( 0, 0, 32),
+ new THREE.Vector3( 28, 0, 32),
+
+ new THREE.Vector3( 28, 0, 0),
+
+ // bridge2 side
+ new THREE.Vector3( 5, 0, -37),
+ new THREE.Vector3(-35, 0, -30),
+ // new THREE.Vector3(-20, 0, -10),
+
+ new THREE.Vector3(-10, 0, 0),
+ ], true, 'catmullrom', 0.75);
/*
// muestra la curva utilizada para el camino de `rails`
diff --git a/tp/src/scene.js b/tp/src/scene.js
@@ -6,7 +6,7 @@ import { vertexShader, fragmentShader } from '/assets/shaders.js';
import { generateTunnelGeometry } from '/src/tunnel.js';
import { createInstancedTrees } from '/src/track-map.js';
import { elevationGeometry } from '/src/terrain.js';
-import {
+import {
buildRailsGeometry,
buildRailsFoundationGeometry
} from '/src/rails.js';
@@ -17,6 +17,8 @@ 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;
const amplitude = 10;
@@ -33,7 +35,7 @@ const textures = {
};
let settings = {
- animationEnable: true,
+ animationEnable: false,
};
function onResize() {
@@ -114,11 +116,11 @@ function buildBridge() {
const bridge2 = generateBridge(2, 2, 1, 0, 15, 3, 2);
bridge1.scale.set(0.5, 0.5, 0.5);
- bridge1.position.set(16, -0.75, 33);
+ bridge1.position.set(16, -0.75, 36);
// bridge1.rotateY(-Math.PI*0.118);
bridge2.scale.set(0.5, 0.5, 0.5);
- bridge2.position.set(-14, 0, -40);
+ bridge2.position.set(-14, 0, -41);
// bridge2.rotateY(-Math.PI*0.118);
scene.add(bridge1);
@@ -137,19 +139,28 @@ function buildRailsFoundation() {
textures.durmientes.object.wrapS = THREE.RepeatWrapping;
textures.durmientes.object.wrapT = THREE.RepeatWrapping;
- textures.durmientes.object.repeat.set(1, 60);
+ textures.durmientes.object.repeat.set(1, 150);
textures.durmientes.object.anisotropy = 16;
+ // load into `map` the example texture
+ const map = new THREE.TextureLoader().load('https://threejs.org/examples/textures/uv_grid_opengl.jpg');
+ map.wrapS = map.wrapT = THREE.RepeatWrapping;
+ map.repeat.set(1, 80);
+ map.anisotropy = 16;
+ // map.rotation = Math.PI/2;
+
const railsFoundationMaterial = new THREE.MeshPhongMaterial({
side: THREE.DoubleSide,
transparent: false,
opacity: 1.0,
shininess: 10,
map: textures.durmientes.object
+ // map: map
});
const railsFoundation = new THREE.Mesh(railsFoundationGeometry, railsFoundationMaterial);
- railsFoundation.scale.set(2, 2, 2);
+ railsFoundation.position.set(-1, 1.25, -1);
+ railsFoundation.scale.set(1.00, 1.50, 1.00);
scene.add(railsFoundation);
}
@@ -164,7 +175,8 @@ function buildRails() {
});
const rails = new THREE.Mesh(railsGeometry, railsMaterial);
- rails.scale.set(2, 2, 2);
+ rails.position.set(-1, 1.25, -1);
+ rails.scale.set(1.00, 1.50, 1.00);
scene.add(rails);
}
@@ -246,13 +258,13 @@ function createMenu() {
function buildScene() {
console.log('Building scene');
- buildTunnel();
- // buildTrees(100);
- // buildTerrain();
+ // buildTunnel();
+ buildTrees(200);
+ buildTerrain();
buildRailsFoundation();
buildRails();
- buildLoco();
- // buildBridge();
+ // buildLoco();
+ buildBridge();
}
function mainLoop() {
diff --git a/tp/src/track-map.js b/tp/src/track-map.js
@@ -9,7 +9,7 @@ const textures = {
const widthSegments = 100;
const heightSegments = 100;
-const amplitude = 8;
+const amplitude = 10;
const amplitudeBottom = -1.00;
const imgWidth = 512;
const imgHeight = 512;
@@ -29,7 +29,8 @@ function isForbbidenPosition(position) {
const y = position.y;
const z = Math.floor(position.z);
- if((y > 5.8) || (y < 2.65)){
+ // TODO: estos valores deberian depender de la posicion del terreno
+ if((y > 5.8) || (y < 3.25)) {
// console.log("(" + position.x + ", " + position.y + ", " + position.z + ") is not valid ");
return true;
}
@@ -213,11 +214,12 @@ export function createInstancedTrees(count) {
continue;
}
- const treeOffset = 0.25;
+ const treeOffset = -1.50;
+
// 1.50 numbero magico para posicionar correctamente los arboles con
// respecto al terreno
position.x -= (widthSegments+treesBorderPadding+1.50)/2;
- position.y += amplitudeBottom - treeOffset;
+ position.y += (amplitudeBottom + treeOffset);
position.z -= (heightSegments+treesBorderPadding)/2;
translationMatrix.makeTranslation(position);
treeLogMatrix.identity();
@@ -228,6 +230,7 @@ export function createInstancedTrees(count) {
treeLogMatrix.premultiply(translationMatrix);
position.y += scale*logHeight;
+
translationMatrix.makeTranslation(position);
treeLeavesMatrix.premultiply(translationMatrix);