TA159

Notas, resueltos y trabajos practicos de la materia Sistemas Gráficos
Index Commits Files Refs Submodules README LICENSE
commit 82bd52054cc8543db98cb5d257f45150608c9e08
parent 15ad889897c616b8fbf9ee604e53b63bc8416ab8
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date:   Sun,  7 Jul 2024 22:32:40 -0300

code cleanup

Diffstat:
Dtp/public/durmientes.jpg | 0
Dtp/public/elevation_map.png | 0
Dtp/public/elevation_map2.png | 0
Dtp/public/elevation_map3.png | 0
Dtp/public/elevation_map_wider_river.png | 0
Dtp/public/madera.jpg | 0
Dtp/public/pared-de-ladrillos.jpg | 0
Dtp/public/pasto.jpg | 0
Dtp/public/roca.jpg | 0
Dtp/public/sky_day_void.jpg | 0
Dtp/public/sky_night.jpg | 0
Dtp/public/tierra.jpg | 0
Dtp/public/tierraSeca.jpg | 0
Dtp/public/tree_forbidden_zone_map.png | 0
Dtp/public/tree_forbidden_zone_map_wider_path.png | 0
Mtp/src/bridge.js | 2+-
Mtp/src/rails.js | 45+--------------------------------------------
Mtp/src/scene.js | 38++------------------------------------
18 files changed, 4 insertions(+), 81 deletions(-)
diff --git a/tp/public/durmientes.jpg b/tp/public/durmientes.jpg
Binary files differ.
diff --git a/tp/public/elevation_map.png b/tp/public/elevation_map.png
Binary files differ.
diff --git a/tp/public/elevation_map2.png b/tp/public/elevation_map2.png
Binary files differ.
diff --git a/tp/public/elevation_map3.png b/tp/public/elevation_map3.png
Binary files differ.
diff --git a/tp/public/elevation_map_wider_river.png b/tp/public/elevation_map_wider_river.png
Binary files differ.
diff --git a/tp/public/madera.jpg b/tp/public/madera.jpg
Binary files differ.
diff --git a/tp/public/pared-de-ladrillos.jpg b/tp/public/pared-de-ladrillos.jpg
Binary files differ.
diff --git a/tp/public/pasto.jpg b/tp/public/pasto.jpg
Binary files differ.
diff --git a/tp/public/roca.jpg b/tp/public/roca.jpg
Binary files differ.
diff --git a/tp/public/sky_day_void.jpg b/tp/public/sky_day_void.jpg
Binary files differ.
diff --git a/tp/public/sky_night.jpg b/tp/public/sky_night.jpg
Binary files differ.
diff --git a/tp/public/tierra.jpg b/tp/public/tierra.jpg
Binary files differ.
diff --git a/tp/public/tierraSeca.jpg b/tp/public/tierraSeca.jpg
Binary files differ.
diff --git a/tp/public/tree_forbidden_zone_map.png b/tp/public/tree_forbidden_zone_map.png
Binary files differ.
diff --git a/tp/public/tree_forbidden_zone_map_wider_path.png b/tp/public/tree_forbidden_zone_map_wider_path.png
Binary files differ.
diff --git a/tp/src/bridge.js b/tp/src/bridge.js
@@ -203,7 +203,7 @@ export function generateBridge(arcCount=1, arcRadius=3,
     const bridgeLen    = arcCount*(columnWidth+arcWidth)+columnWidth+startPadding+endPadding;
     const squareTubeRadius = 0.30;
 
-    const bridge       = new THREE.Object3D();
+    const bridge = new THREE.Object3D();
 
     const leftWallGeometry = generateBridgeWallGeometry(
         arcCount, arcRadius, columnWidth, columnHeight, padding);
diff --git a/tp/src/rails.js b/tp/src/rails.js
@@ -1,7 +1,6 @@
 import * as THREE from 'three';
 
 import { ParametricGeometry } from 'three/addons/geometries/ParametricGeometry.js';
-import { ParametricGeometries } from 'three/examples/jsm/geometries/ParametricGeometries.js';
 import { mergeGeometries } from 'three/addons/utils/BufferGeometryUtils.js';
 
 let railsPath;
@@ -14,19 +13,6 @@ export const railsFoundationShape = new THREE.CatmullRomCurve3([
     new THREE.Vector3(  2.00, 0.00, 0.00),
 ], false);
 
-
-import tierraUrl     from './assets/tierra.jpg'
-import rocaUrl       from './assets/roca.jpg'
-import pastoUrl      from './assets/pasto.jpg'
-import durmientesUrl from './assets/durmientes.jpg'
-
-const textures = {
-    tierra:     { url: tierraUrl,     object: null },
-    roca:       { url: rocaUrl,       object: null },
-    pasto:      { url: pastoUrl,      object: null },
-    durmientes: { url: durmientesUrl, object: null },
-};
-
 export function getRailsPathPosAt(t) {
     if(railsPath == undefined) {
         console.log("railsPath is undefined");
@@ -152,35 +138,6 @@ export function buildRailsGeometry(railsRadius = 0.35) {
     return railsGeometry;
 }
 
-function onTextureLoaded(key, texture) {
-    texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
-    textures[key].object = texture;
-    console.log('Texture `' + key + '` loaded');
-}
-
-function loadTextures(callback) {
-    const loadingManager = new THREE.LoadingManager();
-
-    loadingManager.onLoad = () => {
-        console.log('All textures loaded');
-        callback();
-    };
-
-    for (const key in textures) {
-        console.log("Loading textures");
-        const loader = new THREE.TextureLoader(loadingManager);
-        const texture = textures[key];
-        texture.object = loader.load(
-            texture.url,
-            onTextureLoaded.bind(this, key),
-            null,
-            (error) => {
-                console.error(error);
-            }
-        );
-    }
-}
-
 function main() {
     railsPath = new THREE.CatmullRomCurve3([
         // bridge1 side
@@ -211,4 +168,4 @@ function main() {
 }
 
 // setupThreeJs();
-loadTextures(main);
+main();
diff --git a/tp/src/scene.js b/tp/src/scene.js
@@ -17,7 +17,7 @@ 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, gui;
+let scene, camera, renderer, terrainGeometry, terrain, time, gui;
 let treesForbiddenMapData, treesForbiddenMap, elevationMap, elevationMapData;
 
 let firstPersonControls, orbitControls;
@@ -68,18 +68,6 @@ import durmientesUrl       from './assets/durmientes.jpg'
 import elevationMapUrl     from './assets/elevation_map_wider_river.png'
 import treeForbiddenMapUrl from './assets/tree_forbidden_zone_map_wider_path.png'
 
-// const textures = {
-//     sky_day:          { url: '/sky_day_void.jpg', object: null },
-//     sky_night:        { url: '/sky_night.jpg', object: null },
-//     roca:             { url: '/roca.jpg', object: null },
-//     pasto:            { url: '/pasto.jpg', object: null },
-//     tierra:           { url: '/tierra.jpg', object: null },
-//     madera:           { url: '/madera.jpg', object: null },
-//     durmientes:       { url: '/durmientes.jpg', object: null },
-//     elevationMap:     { url: '/elevation_map_wider_river.png', object: null },
-//     treeForbiddenMap: { url: '/tree_forbidden_zone_map_wider_path.png', object: null }
-// };
-
 const textures = {
     skyDay:           { url: skyDayUrl, object: null },
     skyNight:         { url: skyNightUrl, object: null },
@@ -706,31 +694,9 @@ function buildTerrain() {
 
     console.log('Applying textures');
 
-    terrainMaterial = new THREE.RawShaderMaterial({
-        uniforms: {
-            dirtSampler: { type: 't', value: textures.tierra.object },
-            rockSampler: { type: 't', value: textures.roca.object },
-            grassSampler: { type: 't', value: textures.pasto.object },
-            scale: { type: 'f', value: 2.5 },
-            terrainAmplitude: { type: 'f', value: amplitude },
-            terrainAmplitudeBottom: { type: 'f', value: amplitudeBottom },
-            worldNormalMatrix: { type: 'm4', value: null },
-            dirtStepWidth: { type: 'f', value: 0.20 },
-            rockStepWidth: { type: 'f', value: 0.15 },
-        },
-        vertexShader: vertexShader,
-        fragmentShader: fragmentShader,
-        side: THREE.DoubleSide,
-    });
     const customMaterial = buildTerrainCustomMaterial();
-    terrain = new THREE.Mesh(terrainGeometry, customMaterial );
+    terrain = new THREE.Mesh(terrainGeometry, customMaterial);
 
-    terrainMaterial.onBeforeRender = (renderer, scene, camera, geometry, terrain) => {
-        let m = terrain.matrixWorld.clone();
-        m = m.transpose().invert();
-        terrain.material.uniforms.worldNormalMatrix.value = m;
-    };
-    terrainMaterial.needsUpdate = true;
     scene.add(terrain);
 
     terrain.position.set(0, amplitudeBottom, 0);