Spaces:
Running
Running
Add 2 files
Browse files- index.html +69 -718
- prompts.txt +2 -1
index.html
CHANGED
@@ -3,14 +3,10 @@
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
-
<title>Simulateur de Camion -
|
7 |
<script src="https://cdn.tailwindcss.com"></script>
|
8 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
|
9 |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/examples/js/controls/OrbitControls.js"></script>
|
10 |
-
<script src="https://cdn.jsdelivr.net/npm/[email protected]/examples/js/loaders/GLTFLoader.js"></script>
|
11 |
-
<script src="https://cdn.jsdelivr.net/npm/[email protected]/examples/js/loaders/DRACOLoader.js"></script>
|
12 |
-
<script src="https://cdn.jsdelivr.net/npm/[email protected]/examples/js/objects/Water.js"></script>
|
13 |
-
<script src="https://cdn.jsdelivr.net/npm/[email protected]/examples/js/objects/Sky.js"></script>
|
14 |
<style>
|
15 |
body {
|
16 |
margin: 0;
|
@@ -108,30 +104,16 @@
|
|
108 |
.menu-button:hover {
|
109 |
background: rgba(255, 255, 255, 0.3);
|
110 |
}
|
111 |
-
.
|
112 |
position: absolute;
|
113 |
top: 20px;
|
114 |
right: 20px;
|
115 |
background: rgba(0, 0, 0, 0.7);
|
116 |
border-radius: 10px;
|
117 |
-
padding:
|
118 |
-
color: white;
|
119 |
-
max-width: 300px;
|
120 |
backdrop-filter: blur(5px);
|
121 |
border: 1px solid rgba(255, 255, 255, 0.2);
|
122 |
-
|
123 |
-
.instructions h3 {
|
124 |
-
margin-top: 0;
|
125 |
-
margin-bottom: 10px;
|
126 |
-
font-size: 1.2rem;
|
127 |
-
}
|
128 |
-
.instructions ul {
|
129 |
-
padding-left: 20px;
|
130 |
-
margin: 0;
|
131 |
-
}
|
132 |
-
.instructions li {
|
133 |
-
margin-bottom: 5px;
|
134 |
-
font-size: 0.9rem;
|
135 |
}
|
136 |
.loading-screen {
|
137 |
position: absolute;
|
@@ -161,81 +143,6 @@
|
|
161 |
width: 0%;
|
162 |
transition: width 0.3s;
|
163 |
}
|
164 |
-
.traffic-light {
|
165 |
-
position: absolute;
|
166 |
-
top: 50%;
|
167 |
-
right: 50px;
|
168 |
-
transform: translateY(-50%);
|
169 |
-
background: rgba(0, 0, 0, 0.7);
|
170 |
-
border-radius: 10px;
|
171 |
-
padding: 10px;
|
172 |
-
display: flex;
|
173 |
-
flex-direction: column;
|
174 |
-
gap: 5px;
|
175 |
-
backdrop-filter: blur(5px);
|
176 |
-
border: 1px solid rgba(255, 255, 255, 0.2);
|
177 |
-
}
|
178 |
-
.light {
|
179 |
-
width: 20px;
|
180 |
-
height: 20px;
|
181 |
-
border-radius: 50%;
|
182 |
-
background: #555;
|
183 |
-
}
|
184 |
-
.light.active {
|
185 |
-
box-shadow: 0 0 10px 5px rgba(255, 255, 255, 0.5);
|
186 |
-
}
|
187 |
-
.light.red.active {
|
188 |
-
background: #ff0000;
|
189 |
-
}
|
190 |
-
.light.yellow.active {
|
191 |
-
background: #ffff00;
|
192 |
-
}
|
193 |
-
.light.green.active {
|
194 |
-
background: #00ff00;
|
195 |
-
}
|
196 |
-
.gps {
|
197 |
-
position: absolute;
|
198 |
-
top: 80px;
|
199 |
-
left: 20px;
|
200 |
-
background: rgba(0, 0, 0, 0.7);
|
201 |
-
border-radius: 10px;
|
202 |
-
padding: 10px;
|
203 |
-
color: white;
|
204 |
-
width: 200px;
|
205 |
-
height: 120px;
|
206 |
-
backdrop-filter: blur(5px);
|
207 |
-
border: 1px solid rgba(255, 255, 255, 0.2);
|
208 |
-
}
|
209 |
-
.gps h3 {
|
210 |
-
margin: 0 0 5px 0;
|
211 |
-
font-size: 0.9rem;
|
212 |
-
}
|
213 |
-
.gps p {
|
214 |
-
margin: 0;
|
215 |
-
font-size: 0.8rem;
|
216 |
-
}
|
217 |
-
.mirror {
|
218 |
-
position: absolute;
|
219 |
-
top: 20px;
|
220 |
-
left: 240px;
|
221 |
-
width: 150px;
|
222 |
-
height: 80px;
|
223 |
-
background: rgba(0, 0, 0, 0.3);
|
224 |
-
border: 1px solid rgba(255, 255, 255, 0.2);
|
225 |
-
border-radius: 5px;
|
226 |
-
overflow: hidden;
|
227 |
-
}
|
228 |
-
.weather-controls {
|
229 |
-
position: absolute;
|
230 |
-
top: 20px;
|
231 |
-
right: 340px;
|
232 |
-
background: rgba(0, 0, 0, 0.7);
|
233 |
-
border-radius: 10px;
|
234 |
-
padding: 10px;
|
235 |
-
backdrop-filter: blur(5px);
|
236 |
-
border: 1px solid rgba(255, 255, 255, 0.2);
|
237 |
-
pointer-events: all;
|
238 |
-
}
|
239 |
</style>
|
240 |
</head>
|
241 |
<body>
|
@@ -266,41 +173,16 @@
|
|
266 |
<div class="steering-wheel" id="steering-wheel"></div>
|
267 |
<div class="gear-indicator" id="gear-indicator">N</div>
|
268 |
<div class="menu">
|
269 |
-
<button class="menu-button" id="toggle-camera">VUE
|
270 |
<button class="menu-button" id="toggle-lights">PHARES</button>
|
271 |
-
<button class="menu-button" id="toggle-traffic">TRAFIC</button>
|
272 |
<button class="menu-button" id="reset-truck">RÉINITIALISER</button>
|
273 |
</div>
|
274 |
-
<div class="
|
275 |
-
<button class="menu-button" id="
|
276 |
-
<button class="menu-button" id="
|
277 |
-
<button class="menu-button" id="
|
|
|
278 |
</div>
|
279 |
-
<div class="instructions">
|
280 |
-
<h3>CONTROLES</h3>
|
281 |
-
<ul>
|
282 |
-
<li>Z/Q/S/D : Conduire</li>
|
283 |
-
<li>Espace : Frein</li>
|
284 |
-
<li>R : Rétrogradez</li>
|
285 |
-
<li>F : Phares</li>
|
286 |
-
<li>H : Klaxon</li>
|
287 |
-
<li>C : Changer de caméra</li>
|
288 |
-
<li>Flèches : Regarder autour</li>
|
289 |
-
<li>1-6 : Vitesses</li>
|
290 |
-
</ul>
|
291 |
-
</div>
|
292 |
-
<div class="traffic-light" id="traffic-light">
|
293 |
-
<div class="light red"></div>
|
294 |
-
<div class="light yellow"></div>
|
295 |
-
<div class="light green"></div>
|
296 |
-
</div>
|
297 |
-
<div class="gps">
|
298 |
-
<h3>GPS</h3>
|
299 |
-
<p id="gps-location">Campagne - Route Départementale</p>
|
300 |
-
<p id="gps-next">Prochain virage: 500m</p>
|
301 |
-
<p id="gps-speed">Limite: 90 km/h</p>
|
302 |
-
</div>
|
303 |
-
<div class="mirror" id="left-mirror"></div>
|
304 |
</div>
|
305 |
<div class="loading-screen" id="loading-screen">
|
306 |
<h1 class="text-2xl font-bold mb-4">SIMULATEUR DE CAMION - PAYSAGES</h1>
|
@@ -317,28 +199,13 @@
|
|
317 |
let scene, camera, renderer, truck, controls;
|
318 |
let speed = 0, rpm = 1000, fuel = 100, time = 0, distance = 0;
|
319 |
let steeringAngle = 0, gear = 'N';
|
320 |
-
let lightsOn = false, hornPlaying = false
|
321 |
let cameraMode = 'interior';
|
|
|
322 |
let lastTime = 0;
|
323 |
let loadingProgress = 0;
|
324 |
let assetsLoaded = false;
|
325 |
-
let trafficCars = [];
|
326 |
-
let trafficLightState = 'red';
|
327 |
-
let trafficLightTimer = 0;
|
328 |
-
let sky, sun, water;
|
329 |
let clock = new THREE.Clock();
|
330 |
-
let leftMirrorCamera, leftMirrorTexture;
|
331 |
-
let rainParticles = [];
|
332 |
-
let fog = null;
|
333 |
-
let weather = 'sunny'; // sunny, rainy, foggy
|
334 |
-
|
335 |
-
// Environnement amélioré
|
336 |
-
const environment = {
|
337 |
-
city: false,
|
338 |
-
highway: false,
|
339 |
-
countryside: true,
|
340 |
-
weather: 'sunny'
|
341 |
-
};
|
342 |
|
343 |
// Initialisation
|
344 |
function init() {
|
@@ -382,14 +249,6 @@
|
|
382 |
// Configuration des événements
|
383 |
setupEventListeners();
|
384 |
|
385 |
-
// Création du trafic
|
386 |
-
if (trafficEnabled) {
|
387 |
-
createTraffic();
|
388 |
-
}
|
389 |
-
|
390 |
-
// Configuration du rétroviseur
|
391 |
-
setupMirrors();
|
392 |
-
|
393 |
// Animation
|
394 |
animate();
|
395 |
}
|
@@ -400,7 +259,6 @@
|
|
400 |
"Initialisation du système...",
|
401 |
"Chargement des textures...",
|
402 |
"Création de l'environnement...",
|
403 |
-
"Génération du trafic...",
|
404 |
"Finalisation..."
|
405 |
];
|
406 |
|
@@ -431,20 +289,6 @@
|
|
431 |
|
432 |
// Configuration des lumières
|
433 |
function setupLights() {
|
434 |
-
// Lumière du soleil
|
435 |
-
sun = new THREE.Vector3();
|
436 |
-
|
437 |
-
// Skybox
|
438 |
-
sky = new THREE.Sky();
|
439 |
-
sky.scale.setScalar(10000);
|
440 |
-
scene.add(sky);
|
441 |
-
|
442 |
-
const skyUniforms = sky.material.uniforms;
|
443 |
-
skyUniforms['turbidity'].value = 2;
|
444 |
-
skyUniforms['rayleigh'].value = 2;
|
445 |
-
skyUniforms['mieCoefficient'].value = 0.005;
|
446 |
-
skyUniforms['mieDirectionalG'].value = 0.8;
|
447 |
-
|
448 |
// Lumière directionnelle principale
|
449 |
const sunlight = new THREE.DirectionalLight(0xffffff, 1);
|
450 |
sunlight.position.set(100, 100, 50);
|
@@ -481,12 +325,8 @@
|
|
481 |
function createEnvironment() {
|
482 |
// Sol avec texture haute résolution
|
483 |
const groundGeometry = new THREE.PlaneGeometry(10000, 10000);
|
484 |
-
const groundTexture = new THREE.TextureLoader().load('https://threejs.org/examples/textures/terrain/grasslight-big.jpg');
|
485 |
-
groundTexture.wrapS = groundTexture.wrapT = THREE.RepeatWrapping;
|
486 |
-
groundTexture.repeat.set(100, 100);
|
487 |
-
groundTexture.anisotropy = 16;
|
488 |
const groundMaterial = new THREE.MeshStandardMaterial({
|
489 |
-
|
490 |
roughness: 0.8,
|
491 |
metalness: 0.2
|
492 |
});
|
@@ -525,34 +365,8 @@
|
|
525 |
scene.add(line);
|
526 |
}
|
527 |
|
528 |
-
// Eau avec réflexion réaliste
|
529 |
-
water = new THREE.Water(
|
530 |
-
new THREE.PlaneGeometry(10000, 1000),
|
531 |
-
{
|
532 |
-
textureWidth: 1024,
|
533 |
-
textureHeight: 1024,
|
534 |
-
waterNormals: new THREE.TextureLoader().load('https://threejs.org/examples/textures/waternormals.jpg', function(texture) {
|
535 |
-
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
|
536 |
-
}),
|
537 |
-
sunDirection: new THREE.Vector3(),
|
538 |
-
sunColor: 0xffffff,
|
539 |
-
waterColor: 0x0077be,
|
540 |
-
distortionScale: 3.7,
|
541 |
-
fog: scene.fog !== undefined
|
542 |
-
}
|
543 |
-
);
|
544 |
-
water.rotation.x = -Math.PI / 2;
|
545 |
-
water.position.set(50, 0.1, 0);
|
546 |
-
scene.add(water);
|
547 |
-
|
548 |
// Paysage naturel détaillé
|
549 |
createNaturalFeatures();
|
550 |
-
|
551 |
-
// Ponts et éléments architecturaux
|
552 |
-
createBridges();
|
553 |
-
|
554 |
-
// Feux de circulation
|
555 |
-
createTrafficLights();
|
556 |
}
|
557 |
|
558 |
// Création des éléments naturels améliorés
|
@@ -622,121 +436,6 @@
|
|
622 |
|
623 |
scene.add(mountain);
|
624 |
}
|
625 |
-
|
626 |
-
// Rivières et lacs
|
627 |
-
createWaterFeatures();
|
628 |
-
|
629 |
-
// Rochers
|
630 |
-
createRocks();
|
631 |
-
}
|
632 |
-
|
633 |
-
// Création des éléments aquatiques
|
634 |
-
function createWaterFeatures() {
|
635 |
-
// Rivière sinueuse
|
636 |
-
const riverGeometry = new THREE.PlaneGeometry(5000, 30);
|
637 |
-
const riverMaterial = new THREE.MeshStandardMaterial({
|
638 |
-
color: 0x0077be,
|
639 |
-
roughness: 0.1,
|
640 |
-
metalness: 0.9,
|
641 |
-
transparent: true,
|
642 |
-
opacity: 0.8
|
643 |
-
});
|
644 |
-
const river = new THREE.Mesh(riverGeometry, riverMaterial);
|
645 |
-
river.rotation.x = -Math.PI / 2;
|
646 |
-
river.position.set(0, 0.05, 0);
|
647 |
-
scene.add(river);
|
648 |
-
|
649 |
-
// Lac
|
650 |
-
const lakeGeometry = new THREE.CircleGeometry(200, 64);
|
651 |
-
const lakeMaterial = new THREE.MeshStandardMaterial({
|
652 |
-
color: 0x006994,
|
653 |
-
roughness: 0.1,
|
654 |
-
metalness: 0.9,
|
655 |
-
transparent: true,
|
656 |
-
opacity: 0.7
|
657 |
-
});
|
658 |
-
const lake = new THREE.Mesh(lakeGeometry, lakeMaterial);
|
659 |
-
lake.rotation.x = -Math.PI / 2;
|
660 |
-
lake.position.set(300, 0.05, 800);
|
661 |
-
scene.add(lake);
|
662 |
-
}
|
663 |
-
|
664 |
-
// Création des rochers
|
665 |
-
function createRocks() {
|
666 |
-
const rockGeometry = new THREE.DodecahedronGeometry(3, 1);
|
667 |
-
const rockMaterial = new THREE.MeshStandardMaterial({
|
668 |
-
color: 0x555555,
|
669 |
-
roughness: 0.8,
|
670 |
-
metalness: 0.2
|
671 |
-
});
|
672 |
-
|
673 |
-
for (let i = 0; i < 200; i++) {
|
674 |
-
const x = (Math.random() > 0.5 ? 1 : -1) * (50 + Math.random() * 300);
|
675 |
-
const z = -2000 + Math.random() * 4000;
|
676 |
-
const y = Math.random() * 2;
|
677 |
-
const scale = 0.5 + Math.random() * 3;
|
678 |
-
|
679 |
-
const rock = new THREE.Mesh(rockGeometry, rockMaterial);
|
680 |
-
rock.position.set(x, y, z);
|
681 |
-
rock.scale.set(scale, scale, scale);
|
682 |
-
rock.rotation.set(Math.random() * Math.PI, Math.random() * Math.PI, Math.random() * Math.PI);
|
683 |
-
rock.castShadow = true;
|
684 |
-
scene.add(rock);
|
685 |
-
}
|
686 |
-
}
|
687 |
-
|
688 |
-
// Création des ponts
|
689 |
-
function createBridges() {
|
690 |
-
// Pont principal
|
691 |
-
const bridgeGeometry = new THREE.BoxGeometry(30, 5, 100);
|
692 |
-
const bridgeMaterial = new THREE.MeshStandardMaterial({ color: 0x333333 });
|
693 |
-
const bridge = new THREE.Mesh(bridgeGeometry, bridgeMaterial);
|
694 |
-
bridge.position.set(0, 2.5, 0);
|
695 |
-
bridge.castShadow = true;
|
696 |
-
bridge.receiveShadow = true;
|
697 |
-
scene.add(bridge);
|
698 |
-
|
699 |
-
// Garde-fous
|
700 |
-
const railingGeometry = new THREE.BoxGeometry(1, 1, 100);
|
701 |
-
const railingMaterial = new THREE.MeshStandardMaterial({ color: 0x777777 });
|
702 |
-
|
703 |
-
const railingLeft = new THREE.Mesh(railingGeometry, railingMaterial);
|
704 |
-
railingLeft.position.set(15.5, 3, 0);
|
705 |
-
scene.add(railingLeft);
|
706 |
-
|
707 |
-
const railingRight = new THREE.Mesh(railingGeometry, railingMaterial);
|
708 |
-
railingRight.position.set(-15.5, 3, 0);
|
709 |
-
scene.add(railingRight);
|
710 |
-
|
711 |
-
// Piliers
|
712 |
-
const pillarGeometry = new THREE.CylinderGeometry(2, 2, 10, 8);
|
713 |
-
|
714 |
-
for (let i = -40; i <= 40; i += 20) {
|
715 |
-
const pillar = new THREE.Mesh(pillarGeometry, bridgeMaterial);
|
716 |
-
pillar.position.set(0, -5, i);
|
717 |
-
scene.add(pillar);
|
718 |
-
}
|
719 |
-
}
|
720 |
-
|
721 |
-
// Création des feux de circulation
|
722 |
-
function createTrafficLights() {
|
723 |
-
const poleGeometry = new THREE.CylinderGeometry(0.2, 0.2, 5);
|
724 |
-
const poleMaterial = new THREE.MeshStandardMaterial({ color: 0x333333 });
|
725 |
-
|
726 |
-
const lightGeometry = new THREE.BoxGeometry(1, 3, 0.5);
|
727 |
-
const lightMaterial = new THREE.MeshStandardMaterial({ color: 0x222222 });
|
728 |
-
|
729 |
-
for (let i = 0; i < 10; i++) {
|
730 |
-
const z = -500 + i * 500;
|
731 |
-
|
732 |
-
const pole = new THREE.Mesh(poleGeometry, poleMaterial);
|
733 |
-
pole.position.set(10, 2.5, z);
|
734 |
-
scene.add(pole);
|
735 |
-
|
736 |
-
const light = new THREE.Mesh(lightGeometry, lightMaterial);
|
737 |
-
light.position.set(10, 5, z);
|
738 |
-
scene.add(light);
|
739 |
-
}
|
740 |
}
|
741 |
|
742 |
// Création du camion
|
@@ -849,188 +548,6 @@
|
|
849 |
// Ajout du camion à la scène
|
850 |
scene.add(truck);
|
851 |
truck.position.set(0, 2, 0);
|
852 |
-
|
853 |
-
// Vue intérieure
|
854 |
-
const interiorGeometry = new THREE.BoxGeometry(2.5, 2, 2.5);
|
855 |
-
const interiorMaterial = new THREE.MeshStandardMaterial({
|
856 |
-
color: 0x555555,
|
857 |
-
side: THREE.BackSide
|
858 |
-
});
|
859 |
-
const interior = new THREE.Mesh(interiorGeometry, interiorMaterial);
|
860 |
-
interior.position.set(0, 2, 0);
|
861 |
-
truck.add(interior);
|
862 |
-
|
863 |
-
// Volant
|
864 |
-
const steeringWheelGeometry = new THREE.TorusGeometry(0.3, 0.05, 16, 32);
|
865 |
-
const steeringWheelMaterial = new THREE.MeshStandardMaterial({ color: 0x333333 });
|
866 |
-
const steeringWheel = new THREE.Mesh(steeringWheelGeometry, steeringWheelMaterial);
|
867 |
-
steeringWheel.position.set(0.5, 2.5, 0.5);
|
868 |
-
steeringWheel.rotation.z = Math.PI / 2;
|
869 |
-
truck.add(steeringWheel);
|
870 |
-
|
871 |
-
// Siège
|
872 |
-
const seatGeometry = new THREE.BoxGeometry(0.8, 0.2, 0.8);
|
873 |
-
const seatMaterial = new THREE.MeshStandardMaterial({ color: 0x222222 });
|
874 |
-
const seat = new THREE.Mesh(seatGeometry, seatMaterial);
|
875 |
-
seat.position.set(0, 1.5, 0);
|
876 |
-
truck.add(seat);
|
877 |
-
|
878 |
-
// Tableau de bord
|
879 |
-
const dashboardGeometry = new THREE.BoxGeometry(2.5, 0.5, 0.1);
|
880 |
-
const dashboardMaterial = new THREE.MeshStandardMaterial({ color: 0x111111 });
|
881 |
-
const dashboard = new THREE.Mesh(dashboardGeometry, dashboardMaterial);
|
882 |
-
dashboard.position.set(0, 2, 1.2);
|
883 |
-
truck.add(dashboard);
|
884 |
-
|
885 |
-
// Rétroviseurs
|
886 |
-
const mirrorGeometry = new THREE.BoxGeometry(0.5, 0.2, 0.1);
|
887 |
-
const mirrorMaterial = new THREE.MeshStandardMaterial({ color: 0x333333 });
|
888 |
-
|
889 |
-
const leftMirror = new THREE.Mesh(mirrorGeometry, mirrorMaterial);
|
890 |
-
leftMirror.position.set(1.8, 2.5, 0.5);
|
891 |
-
truck.add(leftMirror);
|
892 |
-
|
893 |
-
const rightMirror = new THREE.Mesh(mirrorGeometry, mirrorMaterial);
|
894 |
-
rightMirror.position.set(-1.8, 2.5, 0.5);
|
895 |
-
truck.add(rightMirror);
|
896 |
-
}
|
897 |
-
|
898 |
-
// Configuration des rétroviseurs
|
899 |
-
function setupMirrors() {
|
900 |
-
// Rétroviseur gauche
|
901 |
-
leftMirrorTexture = new THREE.WebGLRenderTarget(512, 256, {
|
902 |
-
minFilter: THREE.LinearFilter,
|
903 |
-
magFilter: THREE.LinearFilter,
|
904 |
-
format: THREE.RGBFormat
|
905 |
-
});
|
906 |
-
|
907 |
-
leftMirrorCamera = new THREE.PerspectiveCamera(60, 2, 0.1, 1000);
|
908 |
-
leftMirrorCamera.position.set(1.8, 2.5, 0.5);
|
909 |
-
leftMirrorCamera.rotation.y = Math.PI / 2;
|
910 |
-
|
911 |
-
const mirrorPlane = new THREE.PlaneGeometry(1.5, 0.8);
|
912 |
-
const mirrorMaterial = new THREE.MeshBasicMaterial({
|
913 |
-
map: leftMirrorTexture.texture,
|
914 |
-
side: THREE.DoubleSide
|
915 |
-
});
|
916 |
-
const mirrorMesh = new THREE.Mesh(mirrorPlane, mirrorMaterial);
|
917 |
-
mirrorMesh.position.set(2.5, 2.5, 0);
|
918 |
-
mirrorMesh.rotation.y = Math.PI / 2;
|
919 |
-
truck.add(mirrorMesh);
|
920 |
-
}
|
921 |
-
|
922 |
-
// Création du trafic
|
923 |
-
function createTraffic() {
|
924 |
-
const carColors = [
|
925 |
-
0xff0000, 0x00ff00, 0x0000ff, 0xffff00,
|
926 |
-
0xff00ff, 0x00ffff, 0xffffff, 0xaaaaaa
|
927 |
-
];
|
928 |
-
|
929 |
-
// Création de 20 voitures
|
930 |
-
for (let i = 0; i < 20; i++) {
|
931 |
-
const car = new THREE.Group();
|
932 |
-
|
933 |
-
// Corps de la voiture
|
934 |
-
const bodyGeometry = new THREE.BoxGeometry(2, 1, 4);
|
935 |
-
const bodyMaterial = new THREE.MeshStandardMaterial({
|
936 |
-
color: carColors[Math.floor(Math.random() * carColors.length)],
|
937 |
-
roughness: 0.5,
|
938 |
-
metalness: 0.5
|
939 |
-
});
|
940 |
-
const body = new THREE.Mesh(bodyGeometry, bodyMaterial);
|
941 |
-
body.position.y = 1;
|
942 |
-
body.castShadow = true;
|
943 |
-
body.receiveShadow = true;
|
944 |
-
car.add(body);
|
945 |
-
|
946 |
-
// Vitres
|
947 |
-
const windowGeometry = new THREE.BoxGeometry(1.8, 0.6, 3.8);
|
948 |
-
const windowMaterial = new THREE.MeshStandardMaterial({
|
949 |
-
color: 0x7ec0ee,
|
950 |
-
transparent: true,
|
951 |
-
opacity: 0.7,
|
952 |
-
roughness: 0.1,
|
953 |
-
metalness: 0.9
|
954 |
-
});
|
955 |
-
const windows = new THREE.Mesh(windowGeometry, windowMaterial);
|
956 |
-
windows.position.y = 1.3;
|
957 |
-
car.add(windows);
|
958 |
-
|
959 |
-
// Roues
|
960 |
-
const wheelGeometry = new THREE.CylinderGeometry(0.4, 0.4, 0.3, 16);
|
961 |
-
const wheelMaterial = new THREE.MeshStandardMaterial({ color: 0x333333 });
|
962 |
-
|
963 |
-
const wheelFL = new THREE.Mesh(wheelGeometry, wheelMaterial);
|
964 |
-
wheelFL.rotation.z = Math.PI / 2;
|
965 |
-
wheelFL.position.set(1, 0.4, 1.5);
|
966 |
-
car.add(wheelFL);
|
967 |
-
|
968 |
-
const wheelFR = new THREE.Mesh(wheelGeometry, wheelMaterial);
|
969 |
-
wheelFR.rotation.z = Math.PI / 2;
|
970 |
-
wheelFR.position.set(-1, 0.4, 1.5);
|
971 |
-
car.add(wheelFR);
|
972 |
-
|
973 |
-
const wheelRL = new THREE.Mesh(wheelGeometry, wheelMaterial);
|
974 |
-
wheelRL.rotation.z = Math.PI / 2;
|
975 |
-
wheelRL.position.set(1, 0.4, -1.5);
|
976 |
-
car.add(wheelRL);
|
977 |
-
|
978 |
-
const wheelRR = new THREE.Mesh(wheelGeometry, wheelMaterial);
|
979 |
-
wheelRR.rotation.z = Math.PI / 2;
|
980 |
-
wheelRR.position.set(-1, 0.4, -1.5);
|
981 |
-
car.add(wheelRR);
|
982 |
-
|
983 |
-
// Position aléatoire sur la route
|
984 |
-
const lane = Math.random() > 0.5 ? 1 : -1;
|
985 |
-
const z = -1000 + Math.random() * 2000;
|
986 |
-
const speed = 5 + Math.random() * 10;
|
987 |
-
|
988 |
-
car.position.set(lane * 8, 0.4, z);
|
989 |
-
car.userData.speed = speed;
|
990 |
-
car.userData.lane = lane;
|
991 |
-
|
992 |
-
scene.add(car);
|
993 |
-
trafficCars.push(car);
|
994 |
-
}
|
995 |
-
}
|
996 |
-
|
997 |
-
// Mise à jour du trafic
|
998 |
-
function updateTraffic(delta) {
|
999 |
-
trafficLightTimer += delta;
|
1000 |
-
|
1001 |
-
// Changement des feux de circulation
|
1002 |
-
if (trafficLightTimer > 10) {
|
1003 |
-
trafficLightTimer = 0;
|
1004 |
-
trafficLightState = trafficLightState === 'red' ? 'green' : 'red';
|
1005 |
-
|
1006 |
-
// Mise à jour de l'UI
|
1007 |
-
document.querySelector('.light.red').classList.toggle('active', trafficLightState === 'red');
|
1008 |
-
document.querySelector('.light.yellow').classList.toggle('active', false);
|
1009 |
-
document.querySelector('.light.green').classList.toggle('active', trafficLightState === 'green');
|
1010 |
-
} else if (trafficLightTimer > 8 && trafficLightState === 'green') {
|
1011 |
-
document.querySelector('.light.yellow').classList.toggle('active', true);
|
1012 |
-
document.querySelector('.light.green').classList.toggle('active', false);
|
1013 |
-
}
|
1014 |
-
|
1015 |
-
// Mise à jour des voitures
|
1016 |
-
trafficCars.forEach(car => {
|
1017 |
-
// Déplacement
|
1018 |
-
if (trafficLightState === 'green' || car.position.z < -100 || car.position.z > 100) {
|
1019 |
-
car.position.z += car.userData.speed * delta * (car.userData.lane === 1 ? 1 : -1);
|
1020 |
-
}
|
1021 |
-
|
1022 |
-
// Réinitialisation si hors de la vue
|
1023 |
-
if (car.position.z > 1500 || car.position.z < -1500) {
|
1024 |
-
car.position.z = car.userData.lane === 1 ? -1500 : 1500;
|
1025 |
-
}
|
1026 |
-
|
1027 |
-
// Rotation des roues
|
1028 |
-
car.children.forEach(child => {
|
1029 |
-
if (child.geometry?.type === 'CylinderGeometry') {
|
1030 |
-
child.rotation.x += car.userData.speed * delta * 2;
|
1031 |
-
}
|
1032 |
-
});
|
1033 |
-
});
|
1034 |
}
|
1035 |
|
1036 |
// Configuration des événements
|
@@ -1044,7 +561,6 @@
|
|
1044 |
// Klaxon
|
1045 |
if (event.key.toLowerCase() === 'h' && !hornPlaying) {
|
1046 |
hornPlaying = true;
|
1047 |
-
// Ici vous pourriez ajouter un son de klaxon
|
1048 |
setTimeout(() => { hornPlaying = false; }, 1000);
|
1049 |
}
|
1050 |
|
@@ -1072,13 +588,13 @@
|
|
1072 |
// Contrôles UI
|
1073 |
document.getElementById('toggle-camera').addEventListener('click', toggleCamera);
|
1074 |
document.getElementById('toggle-lights').addEventListener('click', toggleLights);
|
1075 |
-
document.getElementById('toggle-traffic').addEventListener('click', toggleTraffic);
|
1076 |
document.getElementById('reset-truck').addEventListener('click', resetTruck);
|
1077 |
|
1078 |
-
//
|
1079 |
-
document.getElementById('
|
1080 |
-
document.getElementById('
|
1081 |
-
document.getElementById('
|
|
|
1082 |
|
1083 |
// Animation des contrôles
|
1084 |
function updateControls(delta) {
|
@@ -1142,9 +658,6 @@
|
|
1142 |
document.getElementById('time').textContent =
|
1143 |
(minutes < 10 ? '0' + minutes : minutes) + ':' +
|
1144 |
(seconds < 10 ? '0' + seconds : seconds);
|
1145 |
-
|
1146 |
-
// Mise à jour du GPS
|
1147 |
-
updateGPS();
|
1148 |
}
|
1149 |
|
1150 |
// Vitesse maximale en fonction de la vitesse
|
@@ -1175,38 +688,6 @@
|
|
1175 |
}
|
1176 |
}
|
1177 |
|
1178 |
-
// Mise à jour des informations GPS
|
1179 |
-
function updateGPS() {
|
1180 |
-
let location = "Campagne - Route Départementale";
|
1181 |
-
let nextTurn = "Prochain virage: 2.5km";
|
1182 |
-
let speedLimit = "Limite: 90 km/h";
|
1183 |
-
|
1184 |
-
if (distance < 5) {
|
1185 |
-
location = "Centre de Formation";
|
1186 |
-
speedLimit = "Limite: 30 km/h";
|
1187 |
-
} else if (distance < 20) {
|
1188 |
-
location = "Route Départementale";
|
1189 |
-
nextTurn = "Prochain virage: 1.2km";
|
1190 |
-
speedLimit = "Limite: 70 km/h";
|
1191 |
-
} else if (distance < 50) {
|
1192 |
-
location = "Périphérique";
|
1193 |
-
nextTurn = "Sortie: 500m";
|
1194 |
-
speedLimit = "Limite: 110 km/h";
|
1195 |
-
} else if (distance < 80) {
|
1196 |
-
location = "Pont sur la rivière";
|
1197 |
-
nextTurn = "Virage serré: 300m";
|
1198 |
-
speedLimit = "Limite: 60 km/h";
|
1199 |
-
} else if (distance < 120) {
|
1200 |
-
location = "Zone Montagneuse";
|
1201 |
-
nextTurn = "Descente: 1km";
|
1202 |
-
speedLimit = "Limite: 80 km/h";
|
1203 |
-
}
|
1204 |
-
|
1205 |
-
document.getElementById('gps-location').textContent = location;
|
1206 |
-
document.getElementById('gps-next').textContent = nextTurn;
|
1207 |
-
document.getElementById('gps-speed').textContent = speedLimit;
|
1208 |
-
}
|
1209 |
-
|
1210 |
// Rafraîchissement des contrôles
|
1211 |
let lastUpdateTime = 0;
|
1212 |
function updateControlsLoop(timestamp) {
|
@@ -1225,7 +706,6 @@
|
|
1225 |
// Basculer les phares
|
1226 |
function toggleLights() {
|
1227 |
lightsOn = !lightsOn;
|
1228 |
-
// Ici vous pourriez activer/désactiver les lumières des phares
|
1229 |
scene.children.forEach(child => {
|
1230 |
if (child.type === 'SpotLight') {
|
1231 |
child.visible = lightsOn;
|
@@ -1234,18 +714,22 @@
|
|
1234 |
document.getElementById('toggle-lights').textContent = lightsOn ? 'ÉTEINDRE' : 'PHARES';
|
1235 |
}
|
1236 |
|
1237 |
-
// Basculer le trafic
|
1238 |
-
function toggleTraffic() {
|
1239 |
-
trafficEnabled = !trafficEnabled;
|
1240 |
-
document.getElementById('toggle-traffic').textContent =
|
1241 |
-
trafficEnabled ? 'DÉSACTIVER TRAFIC' : 'ACTIVER TRAFIC';
|
1242 |
-
}
|
1243 |
-
|
1244 |
// Basculer la caméra
|
1245 |
function toggleCamera() {
|
1246 |
cameraMode = cameraMode === 'interior' ? 'exterior' : 'interior';
|
1247 |
document.getElementById('toggle-camera').textContent =
|
1248 |
-
cameraMode === 'interior' ? 'VUE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1249 |
}
|
1250 |
|
1251 |
// Réinitialiser le camion
|
@@ -1260,105 +744,6 @@
|
|
1260 |
document.getElementById('gear-indicator').textContent = gear;
|
1261 |
}
|
1262 |
|
1263 |
-
// Changer la météo
|
1264 |
-
function setWeather(newWeather) {
|
1265 |
-
weather = newWeather;
|
1266 |
-
|
1267 |
-
// Mettre à jour le ciel et l'éclairage
|
1268 |
-
const skyUniforms = sky.material.uniforms;
|
1269 |
-
|
1270 |
-
switch(weather) {
|
1271 |
-
case 'sunny':
|
1272 |
-
skyUniforms['turbidity'].value = 2;
|
1273 |
-
skyUniforms['rayleigh'].value = 2;
|
1274 |
-
skyUniforms['mieCoefficient'].value = 0.005;
|
1275 |
-
scene.fog.density = 0.0005;
|
1276 |
-
scene.background = new THREE.Color(0x87CEEB);
|
1277 |
-
break;
|
1278 |
-
|
1279 |
-
case 'rainy':
|
1280 |
-
skyUniforms['turbidity'].value = 10;
|
1281 |
-
skyUniforms['rayleigh'].value = 3;
|
1282 |
-
skyUniforms['mieCoefficient'].value = 0.05;
|
1283 |
-
scene.fog.density = 0.003;
|
1284 |
-
scene.background = new THREE.Color(0x666666);
|
1285 |
-
createRain();
|
1286 |
-
break;
|
1287 |
-
|
1288 |
-
case 'foggy':
|
1289 |
-
skyUniforms['turbidity'].value = 20;
|
1290 |
-
skyUniforms['rayleigh'].value = 1;
|
1291 |
-
skyUniforms['mieCoefficient'].value = 0.1;
|
1292 |
-
scene.fog.density = 0.01;
|
1293 |
-
scene.background = new THREE.Color(0x999999);
|
1294 |
-
break;
|
1295 |
-
}
|
1296 |
-
}
|
1297 |
-
|
1298 |
-
// Créer l'effet de pluie
|
1299 |
-
function createRain() {
|
1300 |
-
// Supprimer les anciennes particules de pluie
|
1301 |
-
rainParticles.forEach(particle => scene.remove(particle));
|
1302 |
-
rainParticles = [];
|
1303 |
-
|
1304 |
-
// Créer 1000 particules de pluie
|
1305 |
-
const rainGeometry = new THREE.BufferGeometry();
|
1306 |
-
const positions = [];
|
1307 |
-
const velocities = [];
|
1308 |
-
|
1309 |
-
for (let i = 0; i < 1000; i++) {
|
1310 |
-
positions.push(
|
1311 |
-
Math.random() * 200 - 100, // x
|
1312 |
-
Math.random() * 100 + 50, // y
|
1313 |
-
Math.random() * 200 - 100 // z
|
1314 |
-
);
|
1315 |
-
|
1316 |
-
velocities.push(
|
1317 |
-
0, // vx
|
1318 |
-
-5 - Math.random() * 10, // vy
|
1319 |
-
0 // vz
|
1320 |
-
);
|
1321 |
-
}
|
1322 |
-
|
1323 |
-
rainGeometry.setAttribute('position', new THREE.Float32BufferAttribute(positions, 3));
|
1324 |
-
rainGeometry.setAttribute('velocity', new THREE.Float32BufferAttribute(velocities, 3));
|
1325 |
-
|
1326 |
-
const rainMaterial = new THREE.PointsMaterial({
|
1327 |
-
color: 0xAAAAAA,
|
1328 |
-
size: 0.1,
|
1329 |
-
transparent: true,
|
1330 |
-
opacity: 0.8
|
1331 |
-
});
|
1332 |
-
|
1333 |
-
const rain = new THREE.Points(rainGeometry, rainMaterial);
|
1334 |
-
scene.add(rain);
|
1335 |
-
rainParticles.push(rain);
|
1336 |
-
}
|
1337 |
-
|
1338 |
-
// Mettre à jour la pluie
|
1339 |
-
function updateRain(delta) {
|
1340 |
-
rainParticles.forEach(rain => {
|
1341 |
-
const positions = rain.geometry.attributes.position.array;
|
1342 |
-
const velocities = rain.geometry.attributes.velocity.array;
|
1343 |
-
|
1344 |
-
for (let i = 0; i < positions.length; i += 3) {
|
1345 |
-
// Mettre à jour la position
|
1346 |
-
positions[i] += velocities[i] * delta;
|
1347 |
-
positions[i+1] += velocities[i+1] * delta;
|
1348 |
-
positions[i+2] += velocities[i+2] * delta;
|
1349 |
-
|
1350 |
-
// Réinitialiser les particules qui sont tombées
|
1351 |
-
if (positions[i+1] < 0) {
|
1352 |
-
positions[i] = Math.random() * 200 - 100;
|
1353 |
-
positions[i+1] = Math.random() * 100 + 50;
|
1354 |
-
positions[i+2] = Math.random() * 200 - 100;
|
1355 |
-
}
|
1356 |
-
}
|
1357 |
-
|
1358 |
-
rain.geometry.attributes.position.needsUpdate = true;
|
1359 |
-
});
|
1360 |
-
}
|
1361 |
-
|
1362 |
// Animation
|
1363 |
function animate() {
|
1364 |
requestAnimationFrame(animate);
|
@@ -1367,21 +752,6 @@
|
|
1367 |
|
1368 |
if (!assetsLoaded) return;
|
1369 |
|
1370 |
-
// Mise à jour de l'eau
|
1371 |
-
if (water) {
|
1372 |
-
water.material.uniforms['time'].value += delta;
|
1373 |
-
}
|
1374 |
-
|
1375 |
-
// Mise à jour du trafic
|
1376 |
-
if (trafficEnabled) {
|
1377 |
-
updateTraffic(delta);
|
1378 |
-
}
|
1379 |
-
|
1380 |
-
// Mise à jour de la pluie
|
1381 |
-
if (weather === 'rainy') {
|
1382 |
-
updateRain(delta);
|
1383 |
-
}
|
1384 |
-
|
1385 |
// Déplacement du camion
|
1386 |
if (truck) {
|
1387 |
truck.position.z += speed * delta;
|
@@ -1403,8 +773,9 @@
|
|
1403 |
}
|
1404 |
});
|
1405 |
|
1406 |
-
// Positionnement de la caméra
|
1407 |
if (cameraMode === 'interior') {
|
|
|
1408 |
camera.position.set(
|
1409 |
truck.position.x + 0.5 * Math.sin(truck.rotation.y),
|
1410 |
truck.position.y + 2,
|
@@ -1416,38 +787,44 @@
|
|
1416 |
truck.position.z + 10
|
1417 |
);
|
1418 |
} else {
|
1419 |
-
|
1420 |
-
|
1421 |
-
|
1422 |
-
|
1423 |
-
|
1424 |
-
|
1425 |
-
|
1426 |
-
|
1427 |
-
|
1428 |
-
|
1429 |
-
|
1430 |
-
|
1431 |
-
|
1432 |
-
|
1433 |
-
|
1434 |
-
|
1435 |
-
|
1436 |
-
|
1437 |
-
|
1438 |
-
|
1439 |
-
|
1440 |
-
|
1441 |
-
|
1442 |
-
|
1443 |
-
|
1444 |
-
|
1445 |
-
|
1446 |
-
|
1447 |
-
|
1448 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
1449 |
}
|
1450 |
-
}
|
1451 |
}
|
1452 |
|
1453 |
// Mise à jour des contrôles
|
@@ -1457,37 +834,11 @@
|
|
1457 |
renderer.render(scene, camera);
|
1458 |
}
|
1459 |
|
1460 |
-
// Mise à jour du rétroviseur
|
1461 |
-
function updateMirror() {
|
1462 |
-
if (leftMirrorCamera && leftMirrorTexture) {
|
1463 |
-
// Position et orientation de la caméra du rétroviseur
|
1464 |
-
leftMirrorCamera.position.copy(truck.position).add(new THREE.Vector3(1.8, 2.5, 0.5));
|
1465 |
-
leftMirrorCamera.rotation.copy(truck.rotation);
|
1466 |
-
leftMirrorCamera.rotation.y += Math.PI / 2;
|
1467 |
-
|
1468 |
-
// Rendu de la vue du rétroviseur
|
1469 |
-
renderer.setRenderTarget(leftMirrorTexture);
|
1470 |
-
renderer.clear();
|
1471 |
-
renderer.render(scene, leftMirrorCamera);
|
1472 |
-
renderer.setRenderTarget(null);
|
1473 |
-
|
1474 |
-
// Mise à jour de la texture dans l'UI
|
1475 |
-
const mirrorUI = document.getElementById('left-mirror');
|
1476 |
-
mirrorUI.style.backgroundImage = `url(${leftMirrorTexture.texture.image.src})`;
|
1477 |
-
mirrorUI.style.backgroundSize = 'cover';
|
1478 |
-
}
|
1479 |
-
}
|
1480 |
-
|
1481 |
// Redimensionnement
|
1482 |
window.addEventListener('resize', () => {
|
1483 |
camera.aspect = window.innerWidth / window.innerHeight;
|
1484 |
camera.updateProjectionMatrix();
|
1485 |
renderer.setSize(window.innerWidth, window.innerHeight);
|
1486 |
-
|
1487 |
-
if (leftMirrorCamera) {
|
1488 |
-
leftMirrorCamera.aspect = 2;
|
1489 |
-
leftMirrorCamera.updateProjectionMatrix();
|
1490 |
-
}
|
1491 |
});
|
1492 |
|
1493 |
// Démarrer l'application
|
|
|
3 |
<head>
|
4 |
<meta charset="UTF-8">
|
5 |
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Simulateur de Camion - Vues Extérieures</title>
|
7 |
<script src="https://cdn.tailwindcss.com"></script>
|
8 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
|
9 |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/examples/js/controls/OrbitControls.js"></script>
|
|
|
|
|
|
|
|
|
10 |
<style>
|
11 |
body {
|
12 |
margin: 0;
|
|
|
104 |
.menu-button:hover {
|
105 |
background: rgba(255, 255, 255, 0.3);
|
106 |
}
|
107 |
+
.view-buttons {
|
108 |
position: absolute;
|
109 |
top: 20px;
|
110 |
right: 20px;
|
111 |
background: rgba(0, 0, 0, 0.7);
|
112 |
border-radius: 10px;
|
113 |
+
padding: 10px;
|
|
|
|
|
114 |
backdrop-filter: blur(5px);
|
115 |
border: 1px solid rgba(255, 255, 255, 0.2);
|
116 |
+
pointer-events: all;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
117 |
}
|
118 |
.loading-screen {
|
119 |
position: absolute;
|
|
|
143 |
width: 0%;
|
144 |
transition: width 0.3s;
|
145 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
</style>
|
147 |
</head>
|
148 |
<body>
|
|
|
173 |
<div class="steering-wheel" id="steering-wheel"></div>
|
174 |
<div class="gear-indicator" id="gear-indicator">N</div>
|
175 |
<div class="menu">
|
176 |
+
<button class="menu-button" id="toggle-camera">VUE INTÉRIEURE</button>
|
177 |
<button class="menu-button" id="toggle-lights">PHARES</button>
|
|
|
178 |
<button class="menu-button" id="reset-truck">RÉINITIALISER</button>
|
179 |
</div>
|
180 |
+
<div class="view-buttons">
|
181 |
+
<button class="menu-button" id="view-behind">VUE ARRIÈRE</button>
|
182 |
+
<button class="menu-button" id="view-side">VUE LATÉRALE</button>
|
183 |
+
<button class="menu-button" id="view-top">VUE AÉRIENNE</button>
|
184 |
+
<button class="menu-button" id="view-free">CAMÉRA LIBRE</button>
|
185 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
</div>
|
187 |
<div class="loading-screen" id="loading-screen">
|
188 |
<h1 class="text-2xl font-bold mb-4">SIMULATEUR DE CAMION - PAYSAGES</h1>
|
|
|
199 |
let scene, camera, renderer, truck, controls;
|
200 |
let speed = 0, rpm = 1000, fuel = 100, time = 0, distance = 0;
|
201 |
let steeringAngle = 0, gear = 'N';
|
202 |
+
let lightsOn = false, hornPlaying = false;
|
203 |
let cameraMode = 'interior';
|
204 |
+
let currentView = 'free'; // free, behind, side, top
|
205 |
let lastTime = 0;
|
206 |
let loadingProgress = 0;
|
207 |
let assetsLoaded = false;
|
|
|
|
|
|
|
|
|
208 |
let clock = new THREE.Clock();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
|
210 |
// Initialisation
|
211 |
function init() {
|
|
|
249 |
// Configuration des événements
|
250 |
setupEventListeners();
|
251 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
// Animation
|
253 |
animate();
|
254 |
}
|
|
|
259 |
"Initialisation du système...",
|
260 |
"Chargement des textures...",
|
261 |
"Création de l'environnement...",
|
|
|
262 |
"Finalisation..."
|
263 |
];
|
264 |
|
|
|
289 |
|
290 |
// Configuration des lumières
|
291 |
function setupLights() {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
292 |
// Lumière directionnelle principale
|
293 |
const sunlight = new THREE.DirectionalLight(0xffffff, 1);
|
294 |
sunlight.position.set(100, 100, 50);
|
|
|
325 |
function createEnvironment() {
|
326 |
// Sol avec texture haute résolution
|
327 |
const groundGeometry = new THREE.PlaneGeometry(10000, 10000);
|
|
|
|
|
|
|
|
|
328 |
const groundMaterial = new THREE.MeshStandardMaterial({
|
329 |
+
color: 0x3a5f0b,
|
330 |
roughness: 0.8,
|
331 |
metalness: 0.2
|
332 |
});
|
|
|
365 |
scene.add(line);
|
366 |
}
|
367 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
368 |
// Paysage naturel détaillé
|
369 |
createNaturalFeatures();
|
|
|
|
|
|
|
|
|
|
|
|
|
370 |
}
|
371 |
|
372 |
// Création des éléments naturels améliorés
|
|
|
436 |
|
437 |
scene.add(mountain);
|
438 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
439 |
}
|
440 |
|
441 |
// Création du camion
|
|
|
548 |
// Ajout du camion à la scène
|
549 |
scene.add(truck);
|
550 |
truck.position.set(0, 2, 0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
551 |
}
|
552 |
|
553 |
// Configuration des événements
|
|
|
561 |
// Klaxon
|
562 |
if (event.key.toLowerCase() === 'h' && !hornPlaying) {
|
563 |
hornPlaying = true;
|
|
|
564 |
setTimeout(() => { hornPlaying = false; }, 1000);
|
565 |
}
|
566 |
|
|
|
588 |
// Contrôles UI
|
589 |
document.getElementById('toggle-camera').addEventListener('click', toggleCamera);
|
590 |
document.getElementById('toggle-lights').addEventListener('click', toggleLights);
|
|
|
591 |
document.getElementById('reset-truck').addEventListener('click', resetTruck);
|
592 |
|
593 |
+
// Boutons de vue
|
594 |
+
document.getElementById('view-behind').addEventListener('click', () => setView('behind'));
|
595 |
+
document.getElementById('view-side').addEventListener('click', () => setView('side'));
|
596 |
+
document.getElementById('view-top').addEventListener('click', () => setView('top'));
|
597 |
+
document.getElementById('view-free').addEventListener('click', () => setView('free'));
|
598 |
|
599 |
// Animation des contrôles
|
600 |
function updateControls(delta) {
|
|
|
658 |
document.getElementById('time').textContent =
|
659 |
(minutes < 10 ? '0' + minutes : minutes) + ':' +
|
660 |
(seconds < 10 ? '0' + seconds : seconds);
|
|
|
|
|
|
|
661 |
}
|
662 |
|
663 |
// Vitesse maximale en fonction de la vitesse
|
|
|
688 |
}
|
689 |
}
|
690 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
691 |
// Rafraîchissement des contrôles
|
692 |
let lastUpdateTime = 0;
|
693 |
function updateControlsLoop(timestamp) {
|
|
|
706 |
// Basculer les phares
|
707 |
function toggleLights() {
|
708 |
lightsOn = !lightsOn;
|
|
|
709 |
scene.children.forEach(child => {
|
710 |
if (child.type === 'SpotLight') {
|
711 |
child.visible = lightsOn;
|
|
|
714 |
document.getElementById('toggle-lights').textContent = lightsOn ? 'ÉTEINDRE' : 'PHARES';
|
715 |
}
|
716 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
717 |
// Basculer la caméra
|
718 |
function toggleCamera() {
|
719 |
cameraMode = cameraMode === 'interior' ? 'exterior' : 'interior';
|
720 |
document.getElementById('toggle-camera').textContent =
|
721 |
+
cameraMode === 'interior' ? 'VUE EXTÉRIEURE' : 'VUE INTÉRIEURE';
|
722 |
+
}
|
723 |
+
|
724 |
+
// Changer la vue
|
725 |
+
function setView(view) {
|
726 |
+
currentView = view;
|
727 |
+
|
728 |
+
// Mettre à jour l'état des boutons
|
729 |
+
document.getElementById('view-behind').classList.toggle('bg-blue-500', view === 'behind');
|
730 |
+
document.getElementById('view-side').classList.toggle('bg-blue-500', view === 'side');
|
731 |
+
document.getElementById('view-top').classList.toggle('bg-blue-500', view === 'top');
|
732 |
+
document.getElementById('view-free').classList.toggle('bg-blue-500', view === 'free');
|
733 |
}
|
734 |
|
735 |
// Réinitialiser le camion
|
|
|
744 |
document.getElementById('gear-indicator').textContent = gear;
|
745 |
}
|
746 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
747 |
// Animation
|
748 |
function animate() {
|
749 |
requestAnimationFrame(animate);
|
|
|
752 |
|
753 |
if (!assetsLoaded) return;
|
754 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
755 |
// Déplacement du camion
|
756 |
if (truck) {
|
757 |
truck.position.z += speed * delta;
|
|
|
773 |
}
|
774 |
});
|
775 |
|
776 |
+
// Positionnement de la caméra en fonction de la vue
|
777 |
if (cameraMode === 'interior') {
|
778 |
+
// Vue intérieure
|
779 |
camera.position.set(
|
780 |
truck.position.x + 0.5 * Math.sin(truck.rotation.y),
|
781 |
truck.position.y + 2,
|
|
|
787 |
truck.position.z + 10
|
788 |
);
|
789 |
} else {
|
790 |
+
// Vue extérieure avec différentes perspectives
|
791 |
+
switch(currentView) {
|
792 |
+
case 'behind':
|
793 |
+
// Vue arrière
|
794 |
+
camera.position.set(
|
795 |
+
truck.position.x + 5 * Math.sin(truck.rotation.y),
|
796 |
+
truck.position.y + 5,
|
797 |
+
truck.position.z - 15 + 5 * Math.sin(truck.rotation.y)
|
798 |
+
);
|
799 |
+
camera.lookAt(truck.position);
|
800 |
+
break;
|
801 |
+
|
802 |
+
case 'side':
|
803 |
+
// Vue latérale
|
804 |
+
camera.position.set(
|
805 |
+
truck.position.x + 15,
|
806 |
+
truck.position.y + 5,
|
807 |
+
truck.position.z
|
808 |
+
);
|
809 |
+
camera.lookAt(truck.position);
|
810 |
+
break;
|
811 |
+
|
812 |
+
case 'top':
|
813 |
+
// Vue aérienne
|
814 |
+
camera.position.set(
|
815 |
+
truck.position.x,
|
816 |
+
truck.position.y + 25,
|
817 |
+
truck.position.z - 10
|
818 |
+
);
|
819 |
+
camera.lookAt(truck.position);
|
820 |
+
break;
|
821 |
+
|
822 |
+
case 'free':
|
823 |
+
default:
|
824 |
+
// Caméra libre (contrôlée par OrbitControls)
|
825 |
+
break;
|
826 |
}
|
827 |
+
}
|
828 |
}
|
829 |
|
830 |
// Mise à jour des contrôles
|
|
|
834 |
renderer.render(scene, camera);
|
835 |
}
|
836 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
837 |
// Redimensionnement
|
838 |
window.addEventListener('resize', () => {
|
839 |
camera.aspect = window.innerWidth / window.innerHeight;
|
840 |
camera.updateProjectionMatrix();
|
841 |
renderer.setSize(window.innerWidth, window.innerHeight);
|
|
|
|
|
|
|
|
|
|
|
842 |
});
|
843 |
|
844 |
// Démarrer l'application
|
prompts.txt
CHANGED
@@ -7,4 +7,5 @@ JE VEUX QUIL TOURNE PLUS VISTE
|
|
7 |
ecrire les mots : BAVOL JEAN ERIC EN GROS CARACTERE AVEC DES PARTICULE QUI FAIT LE TOUR DU GLOBE
|
8 |
CREER MOI UN VRAIS SIMULATEUR DE CONDUITE DES VRAIS CAMION DAND UN CENTRE DE FORMATION
|
9 |
JE VEUT DES VRAI PAYSAGE ET DES VRAIS CIRCULATION EN TEMP REEL
|
10 |
-
JJE VEUX CONDUIRE SUR LA ROUTE AVEC DE BEAUX PAYSAGE
|
|
|
|
7 |
ecrire les mots : BAVOL JEAN ERIC EN GROS CARACTERE AVEC DES PARTICULE QUI FAIT LE TOUR DU GLOBE
|
8 |
CREER MOI UN VRAIS SIMULATEUR DE CONDUITE DES VRAIS CAMION DAND UN CENTRE DE FORMATION
|
9 |
JE VEUT DES VRAI PAYSAGE ET DES VRAIS CIRCULATION EN TEMP REEL
|
10 |
+
JJE VEUX CONDUIRE SUR LA ROUTE AVEC DE BEAUX PAYSAGE
|
11 |
+
JE VEUX D AUTRE VUE EXTERRIEUR ACE
|