Dream Car lets you switch two independent visual effects on and off at any time: a pair of amber headlights cast by aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/JustADev1024/threejs-car/llms.txt
Use this file to discover all available pages before exploring further.
SpotLight and a PointLight attached to the car’s front, and a drifting exhaust cloud simulated by a THREE.Points particle system mounted at the car’s rear. Both are toggled with dedicated buttons in the control panel and are fully independent — you can run exhaust without lights, lights without exhaust, or both together.
Headlights
Light objects
Two Three.js lights are created at the top of the script and attached directly to the carGroup, so they move in lockstep with the vehicle:
intensity = 0; they are activated at startup by the initial state logic (see below).
Lamp housing mesh
A small glowing sphere is placed at the car’s front to represent the physical headlight lens:emissive channel makes the sphere appear self-lit when the headlights are on, without requiring an additional light source aimed at it.
Positioning on the car
Group, their world-space positions update automatically whenever the car moves.
Toggle logic
| State | headlightSpot.intensity | headlightPoint.intensity | emissiveIntensity |
|---|---|---|---|
| ON (default) | 1.5 | 0.8 | 1.2 |
| OFF | 0 | 0 | 0 |
Exhaust Particles
Particle system setup
The exhaust effect is aTHREE.Points object — a cloud of small dots rendered with a single draw call. It is added as a child of the car Group so it inherits the car’s position automatically:
updateExhaust() — the per-frame simulation loop
updateExhaust runs every animation frame via requestAnimationFrame. When exhaust is disabled it hides the mesh and returns early, keeping overhead near zero:
- 30% — reset to origin: The particle jumps back to the exhaust pipe area (
z ≈ -1.2, scattered slightly in X and Y). This constantly replenishes fresh “smoke” near the car. - 70% — drift backward: The particle’s Z coordinate decreases by
0.07units, simulating the cloud blowing behind the moving car. When a particle drifts pastz = -2.5it is recycled back to the origin.
needsUpdate = true on the position attribute tells Three.js to re-upload the buffer to the GPU on the next render call.
Toggle logic
exhaustOnState variable is the flag read inside updateExhaust. Because the loop always keeps running (it calls requestAnimationFrame even when off), toggling the effect on is immediate — there is no loop to restart.
The button labels for both headlights and exhaust change automatically when you switch between English and Russian using the language buttons. In English the labels read ”💡 Headlights On / Off” and ”💨 Exhaust On / Off”; in Russian they switch to ”💡 Фары Вкл / Выкл” and ”💨 Выхлоп Вкл / Выкл”. This is handled by the
updateLightsButton() and updateExhaustButton() helpers, which read the current language from the translations object via t('lightsOn'), t('lightsOff'), etc.