Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
webgl25
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Villard PierreFrederic
webgl25
Commits
808f80fd
Commit
808f80fd
authored
3 months ago
by
HERRY Matteo
Browse files
Options
Downloads
Patches
Plain Diff
Fumée GUI masterclass /10 ?
parent
341ef6e3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
HERRY-M--HERRY-E/TABLO.js
+51
-19
51 additions, 19 deletions
HERRY-M--HERRY-E/TABLO.js
with
51 additions
and
19 deletions
HERRY-M--HERRY-E/TABLO.js
+
51
−
19
View file @
808f80fd
...
@@ -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.siz
e
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
);
// Cr
e
ation 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
(
'
d
ensité
'
);
folderFog
.
add
(
scene
.
fog
,
'
density
'
,
0
,
0.2
,
0.00025
).
name
(
'
D
ensité
'
);
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
));
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment