This project uses Three.js to render an interactive 3D game environment inside the browser. It leverages various Three.js components to display models, animate objects, handle user interactions, and play sounds — all in real time.
The core logic is encapsulated in the ThreeJSManager
class (ThreeJSManager.js
), which is responsible for:
Three.Scene
A single global scene object holds all visual elements — background, paddles, ball (human), environment models.
Three.PerspectiveCamera
A perspective camera is configured with adjustable viewpoints. Users can switch between:
Three.WebGLRenderer
Handles rendering of the scene and integrates with the browser’s canvas.
OrbitControls
Allows users to rotate and zoom the camera when appropriate (with damping).
GLTFLoader
& FBXLoader
Used for importing .glb
and .fbx
3D models like:
AudioManager
A custom audio manager (audioManager.js
) wraps Three.js audio features to handle:
The playing field is a 3D plane with:
fahrscheinebitte2.jpg
)Instead of a basic sphere, a 3D animated human model represents the ball, moving and rotating based on ball direction.
paddleModels2
) with adjustable height for visual feedback.All paddle and ball positions update dynamically using updatePositions(gameState)
based on incoming real-time data.
Audio events are tied to gameplay:
Event | Sound |
---|---|
Game start | Mehringdamm.mp3 |
Ball bounce | boing-2-44164.mp3 |
Player scores | girl-scream-45657.mp3 |
Background Main Page | ToyCars_©PlasticPigs.mp3 (looped) |
Background Game | HeavyJam_©PlasticPigs.mp3 (looped) |
If the loaded 3D models contain animation clips (e.g., walking), the first animation is automatically played using THREE.AnimationMixer
.
Key | Effect |
---|---|
1 |
Switch to Player 1 |
2 |
Switch to Player 2 |
3 |
Bird’s-eye view |
Arrows | Prevent page scroll |
```js import { ThreeJSManager } from ‘./ThreeJSManager.js’;
const manager = new ThreeJSManager();
await manager.loadModels(); manager.setupRenderer(document.getElementById(‘game-container’));
function animate() { requestAnimationFrame(animate); manager.render(); } animate();