Skip to content
Snippets Groups Projects
Commit 7b50c55a authored by VoidOma's avatar VoidOma
Browse files

Ajout des Map

parent d83feb9c
No related branches found
No related tags found
Loading
......@@ -9,12 +9,12 @@
- [X] Ombres portées
- [X] Position de la caméra
- [X] Brouillard
- [ ] Effet miroir
- [X] Effet miroir
- [X] Texture classique
- [X] Texture avec transparence
- [X] Sprites
- [ ] Environment map
- [X] Environment map
- [X] Skybox
- [X] Animations
- [ ] normal maps
- [X] normal maps
- [X] Interaction par GUI
\ No newline at end of file
......@@ -40,24 +40,38 @@ function init() {
'textures/6.jpg'
]);
scene.background = texture;
//Chargement de la texture du sol
scene.environment = texture;
//Map
// Chargement de la texture du sol avec displacement map
var textureLoader = new THREE.TextureLoader();
var grassTexture = textureLoader.load('textures/grass.jpg');
var displacementMap = textureLoader.load('textures/displacement.png'); // Image en niveaux de gris
grassTexture.wrapS = THREE.RepeatWrapping;
grassTexture.wrapT = THREE.RepeatWrapping;
grassTexture.repeat.set(2000, 2000);
grassTexture.repeat.set(50, 50);
displacementMap.wrapS = THREE.RepeatWrapping;
displacementMap.wrapT = THREE.RepeatWrapping;
displacementMap.repeat.set(50, 50);
//Création du sol
// Création du sol avec displacement map
solidGround = new THREE.Mesh(
new THREE.PlaneGeometry(50, 50, 1, 1),
new THREE.MeshLambertMaterial({ map: grassTexture })
new THREE.PlaneGeometry(50, 50, 256, 256),
new THREE.MeshStandardMaterial({
map: grassTexture,
displacementMap: displacementMap,
displacementScale: 0.3, // Ajuste la hauteur du relief
displacementBias: 0.4, // Ajuste le niveau de base
roughness: 0.8
})
);
solidGround.position.x = 12.5;
solidGround.position.z = -20.4;
solidGround.position.set(12.5, -0.5, -20.4); // Ajustement pour éviter des creux trop bas
solidGround.rotation.x = -Math.PI / 2;
solidGround.receiveShadow = true;
scene.add(solidGround);
//Map fin
// Chargement du modèle de l'homme
const loader = new OBJLoader();
......@@ -66,7 +80,7 @@ function init() {
(object) => {
object.traverse((child) => {
if (child.isMesh) {
child.material = new THREE.MeshStandardMaterial({ color: 0x0000FF, metalness: 0.5, roughness: 0.5 });
child.material = new THREE.MeshStandardMaterial({ color: 0x0000FF, metalness: 0.5, roughness: 0.5, envMap: texture });
child.castShadow = true;
child.receiveShadow = true;
}
......@@ -105,13 +119,13 @@ function init() {
}
);
// --- Chargement et génération de la forêt ---
// --- Chargement et génération de la forêt ---
console.log('Début du chargement de la forêt');
const mtlLoader = new MTLLoader();
mtlLoader.load('textures/Tree.mtl', (materials) => {
console.log('Matériaux chargés');
materials.preload();
materials.preload();
const objLoader = new OBJLoader();
objLoader.setMaterials(materials);
objLoader.load('textures/Tree.obj', (object) => {
......@@ -122,9 +136,11 @@ function init() {
//Fonction pour générer une forêt
function generateForest(objModel, numTrees) {
console.log('Début de la génération de la forêt');
const minDistance = 0.25;
const minX = -8.5, maxX = -12;
const minZ = -4, maxZ = -15;
const minDistance = 0.25;
const minX = -8.5,
maxX = -12;
const minZ = -4,
maxZ = -15;
let treePositions = [];
......@@ -133,7 +149,7 @@ function init() {
let attempts = 0;
let placed = false;
while (!placed && attempts < 10) {
while (!placed && attempts < 10) {
const x = Math.random() * (maxX - minX) + minX;
const z = Math.random() * (maxZ - minZ) + minZ;
const y = -0.25;
......@@ -153,10 +169,11 @@ function init() {
}
console.log("foret ok");
}
function addGrass() {
const numGrassBlades = 100000;
const areaSize = 50;
const numGrassBlades = 100000;
const areaSize = 50;
const grassGeometry = new THREE.CylinderGeometry(0.0, 0.05, 0.5, 3, 1);
const grassMaterial = new THREE.MeshStandardMaterial({
map: new THREE.TextureLoader().load('textures/grassblade.png'),
......@@ -165,25 +182,25 @@ function init() {
emissive: 0x000000,
roughness: 0.6,
});
const grassMesh = new THREE.InstancedMesh(grassGeometry, grassMaterial, numGrassBlades);
const dummy = new THREE.Object3D();
for (let i = 0; i < numGrassBlades; i++) {
const x = Math.random() * areaSize - areaSize / 4;
const z = Math.random() * areaSize - areaSize / 1.1 ;
const z = Math.random() * areaSize - areaSize / 1.1;
const y = 0.1;
dummy.position.set(x, y, z);
dummy.rotation.y = Math.random() * Math.PI * 2;
dummy.rotation.x = Math.random() * Math.PI * 0.1;
dummy.scale.set(0.5 + Math.random() * 0.5, 1, 0.5 + Math.random() * 0.5);
dummy.updateMatrix();
grassMesh.setMatrixAt(i, dummy.matrix);
}
scene.add(grassMesh);
}
......@@ -192,18 +209,18 @@ function init() {
function addVillageImage() {
const textureLoader = new THREE.TextureLoader();
textureLoader.load('textures/village.jpg', (texture) => {
const geometry = new THREE.PlaneGeometry(75, 50);
const material = new THREE.MeshBasicMaterial({
const geometry = new THREE.PlaneGeometry(75, 50);
const material = new THREE.MeshBasicMaterial({
map: texture,
color: 0x777777
color: 0x777777
});
const plane = new THREE.Mesh(geometry, material);
plane.position.set(0, 18, -150);
plane.position.set(0, 18, -150);
scene.add(plane);
console.log('Image du village ajouté');
});
}
addVillageImage();
......@@ -214,7 +231,7 @@ function init() {
object.traverse((child) => {
if (child.isMesh) {
child.material = new THREE.MeshStandardMaterial({ color: 0xfff5c3, metalness: 0.2, roughness: 0.7 });
child.castShadow = true;
child.castShadow = true;
child.receiveShadow = true;
}
});
......@@ -236,6 +253,23 @@ function init() {
candleLight.position.y = object.position.y + 0.35 + Math.random() * 0.02; //Léger mouvement
}
animateCandleLight();
const sphereGeometry = new THREE.SphereGeometry(0.3, 32, 32);
const sphereMaterial = new THREE.MeshStandardMaterial({
color: 0xffffff,
metalness: 1.0,
roughness: 0.0,
envMap: scene.background
});
const mirrorSphere = new THREE.Mesh(sphereGeometry, sphereMaterial);
mirrorSphere.position.set(
object.position.x + 3,
object.position.y + 0.8, // 0.8 unités au-dessus de la bougie
object.position.z
);
mirrorSphere.castShadow = true;
mirrorSphere.receiveShadow = true;
scene.add(mirrorSphere);
}
);
......@@ -244,7 +278,7 @@ function init() {
scene.add(ambientLight);
window.addEventListener('resize', onWindowResize);
setupGUI();
animate();
}
......@@ -255,6 +289,7 @@ const guiParams = {
function setupGUI() {
gui.add(guiParams, 'intensity', 0.01, 5, 0.1).name('Intensité Bougie');
}
function onWindowResize() {
......
MATEJKA_MAURICE_COLIN/textures/1.png

249 KiB

MATEJKA_MAURICE_COLIN/textures/2.png

238 KiB

MATEJKA_MAURICE_COLIN/textures/3.png

267 KiB

MATEJKA_MAURICE_COLIN/textures/4.png

271 KiB

MATEJKA_MAURICE_COLIN/textures/5.png

291 KiB

MATEJKA_MAURICE_COLIN/textures/6.png

224 KiB

MATEJKA_MAURICE_COLIN/textures/displacement.png

67.8 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment