42-transcendence

3D Game Visualization with Three.js

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.


Architecture Overview

The core logic is encapsulated in the ThreeJSManager class (ThreeJSManager.js), which is responsible for:


Main Components

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:


Game Field Design

The playing field is a 3D plane with:


Paddle & Ball System

Ball → Human Model

Instead of a basic sphere, a 3D animated human model represents the ball, moving and rotating based on ball direction.

Paddle Types

All paddle and ball positions update dynamically using updatePositions(gameState) based on incoming real-time data.


Sound Integration

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)

Animation

If the loaded 3D models contain animation clips (e.g., walking), the first animation is automatically played using THREE.AnimationMixer.


Controls

Key Effect
1 Switch to Player 1
2 Switch to Player 2
3 Bird’s-eye view
Arrows Prevent page scroll

Resource Management


Usage Example

```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();