Skip to content
Snippets Groups Projects
Commit 808f80fd authored by HERRY Matteo's avatar HERRY Matteo
Browse files

Fumée GUI masterclass /10 ?

parent 341ef6e3
No related branches found
No related tags found
No related merge requests found
...@@ -109,6 +109,16 @@ function CreationBatonEncent(position) { ...@@ -109,6 +109,16 @@ function CreationBatonEncent(position) {
return stick; return stick;
} }
// Créer une liste pour les particules
var smokeParticles = [];
// Paramètres de la fumée
var smokeParams = {
spawnRate: 0.1, // Taux de génération des particules à 0 initialement
size: 0.1, // Taille de base des particules
speed: 0.002, // Vitesse de montée des particules
};
// Fonction pour créer la fumée
function CreationFumee(position) { function CreationFumee(position) {
var smokeTexture = new THREE.TextureLoader().load('textures/smoke.png'); var smokeTexture = new THREE.TextureLoader().load('textures/smoke.png');
var smokeMaterial = new THREE.SpriteMaterial({ var smokeMaterial = new THREE.SpriteMaterial({
...@@ -117,19 +127,12 @@ function CreationFumee(position) { ...@@ -117,19 +127,12 @@ function CreationFumee(position) {
blending: THREE.AdditiveBlending blending: THREE.AdditiveBlending
}); });
// Créer une liste pour les particules
var smokeParticles = [];
// Paramètres de la fumée
var smokeCount = 500; // Nombre de particules
var spawnRate = 0.15; // Taux de génération des particules
// Fonction pour créer une particule de fumée (sprite) // Fonction pour créer une particule de fumée (sprite)
function createSmokeParticle() { function createSmokeParticle() {
var smokeParticle = new THREE.Sprite(smokeMaterial); var smokeParticle = new THREE.Sprite(smokeMaterial);
smokeParticle.position.set(position.x, position.y, position.z); smokeParticle.position.set(position.x, position.y, position.z);
smokeParticle.scale.set(0.1 + Math.random() * 0.05, 0.1 + Math.random() * 0.05, 1); // Taille initiale variée smokeParticle.scale.set(smokeParams.size, smokeParams.size, 1); // Taille initiale en fonction de smokeParams.size
smokeParticle.velocity = Math.random() * 0.01 + 0.002; // Vitesse de montée aléatoire smokeParticle.velocity = smokeParams.speed; // Vitesse initiale basée sur smokeParams.speed
smokeParticle.rotationSpeed = Math.random() * 0.02 - 0.01; // Rotation aléatoire smokeParticle.rotationSpeed = Math.random() * 0.02 - 0.01; // Rotation aléatoire
scene.add(smokeParticle); scene.add(smokeParticle);
return smokeParticle; return smokeParticle;
...@@ -142,7 +145,7 @@ function CreationFumee(position) { ...@@ -142,7 +145,7 @@ function CreationFumee(position) {
particle.position.y += particle.velocity + Math.random() * 0.002; // Vitesse de montée plus naturelle particle.position.y += particle.velocity + Math.random() * 0.002; // Vitesse de montée plus naturelle
particle.position.x += (Math.random() - 0.5) * 0.001; // Légère dispersion horizontale particle.position.x += (Math.random() - 0.5) * 0.001; // Légère dispersion horizontale
particle.position.z += (Math.random() - 0.5) * 0.001; // Légère dispersion dans l'espace particle.position.z += (Math.random() - 0.5) * 0.001; // Légère dispersion dans l'espace
// Rotation lente des particules // Rotation lente des particules
particle.rotation.z += particle.rotationSpeed; particle.rotation.z += particle.rotationSpeed;
...@@ -150,16 +153,24 @@ function CreationFumee(position) { ...@@ -150,16 +153,24 @@ function CreationFumee(position) {
particle.scale.x += 0.001 + Math.random() * 0.0005; particle.scale.x += 0.001 + Math.random() * 0.0005;
particle.scale.y += 0.001 + Math.random() * 0.0005; particle.scale.y += 0.001 + Math.random() * 0.0005;
// Réinitialiser la particule si elle dépasse une certaine hauteur // Réinitialiser la particule si elle dépasse une certaine hauteur, ou la faire disparaître si spawnRate = 0
if (particle.position.y > 5) { if (particle.position.y > 5 || (smokeParams.spawnRate === 0 && particle.position.y > 5)) {
particle.position.set(position.x, position.y, position.z); // Réinitialiser la position // Supprimer la particule si spawnRate est 0
particle.scale.set(0.1 + Math.random() * 0.05, 0.1 + Math.random() * 0.05, 1); // Réinitialiser la taille if (smokeParams.spawnRate === 0) {
particle.velocity = Math.random() * 0.01 + 0.002; // Réinitialiser la vitesse scene.remove(particle); // Retirer la particule de la scène
}
// Réinitialiser la particule si spawnRate > 0
if (smokeParams.spawnRate > 0) {
particle.position.set(position.x, position.y, position.z); // Réinitialiser la position
particle.scale.set(smokeParams.size, smokeParams.size, 1); // Réinitialiser la taille
particle.velocity = smokeParams.speed; // Réinitialiser la vitesse
}
} }
}); });
// Créer de nouvelles particules // Créer de nouvelles particules si spawnRate > 0
if (Math.random() < spawnRate) { if (smokeParams.spawnRate > 0 && Math.random() < smokeParams.spawnRate) {
smokeParticles.push(createSmokeParticle()); smokeParticles.push(createSmokeParticle());
} }
...@@ -202,12 +213,33 @@ function fillScene() { ...@@ -202,12 +213,33 @@ function fillScene() {
//Brouillard //Brouillard
scene.fog = new THREE.FogExp2(0xAAAAAA, 0.0025); scene.fog = new THREE.FogExp2(0xAAAAAA, 0.0025);
// Creation du GUI // Création du GUI global
const gui = new dat.GUI(); const gui = new dat.GUI();
// Brouillard
const folderFog = gui.addFolder('Brouillard'); const folderFog = gui.addFolder('Brouillard');
folderFog.add(scene.fog, 'density', 0, 0.2 , 0.00025).name('densité'); folderFog.add(scene.fog, 'density', 0, 0.2, 0.00025).name('Densité');
folderFog.open(); folderFog.open();
// Fumée
const folderSmoke = gui.addFolder('Fumée');
folderSmoke.add(smokeParams, 'spawnRate', 0, 1, 0.01).name('Taux de génération').onChange(function(value) {
smokeParams.spawnRate = value; // Directement affecter le taux de génération
});
folderSmoke.add(smokeParams, 'size', 0.05, 0.4).name('Taille particules').onChange(function(value) {
smokeParams.size = value; // Directement affecter la taille des particules
smokeParticles.forEach(function(particle) {
particle.scale.set(smokeParams.size, smokeParams.size, 1); // Appliquer la nouvelle taille
});
});
folderSmoke.add(smokeParams, 'speed', 0.001, 0.02).name('Vitesse de montée').onChange(function(value) {
smokeParams.speed = value; // Directement affecter la vitesse de montée
smokeParticles.forEach(function(particle) {
particle.velocity = smokeParams.speed; // Appliquer la nouvelle vitesse
});
});
folderSmoke.open();
// LIGHT // LIGHT
var light = new THREE.SpotLight(0xFFFFFF, 500); var light = new THREE.SpotLight(0xFFFFFF, 500);
scene.add(new THREE.CameraHelper(light.shadow.camera)); scene.add(new THREE.CameraHelper(light.shadow.camera));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment