How ghost0t/billiardo_project works
This is a client-side 3D billiards/pool simulation with no visible backend or server-side subsystem. The application boots from index.html, which loads the JS entrypoint and the global style.css viewport layout.
The central coordinator is src/main.js. It is responsible for creating the scene objects, wiring together the simulation objects, and driving the render/update loop. The README indicates it owns the animation frame loop and a fixed sub-stepping scheme (dt = 1/180s, run three times per frame) to keep motion and collision handling stable.
The simulation is split into four main runtime objects:
• Table.js for the static arena and room setup
• Ball.js for each moving ball
• Cue.js for the player’s cue/aiming construct
• Physics.js for collision and motion resolution
Table.js is not just a surface; it also builds the surrounding room/environment. The file tree under public/models/ contains the imported 3D assets used for this environment and props, including the billiard table, chandelier, couch, desk, chairs, punching bag, dartboard, and other scene items. This makes the scene more than a pure physics demo: it is a decorated 3D room with the pool table as the focal point.
Ball.js models each ball as a dynamic object with position, velocity, spin, and rotation state. The README calls out quaternion-based rotation and automatic texture updates, which implies each ball’s visual orientation is kept in sync with its physics state during the loop.
Physics.js is the core rules engine. It handles overlap correction, mass-based collision response, elastic impulse exchange, and motion decay from friction. It also appears to account for cushion contacts and pocket drops, which are reinforced by the bundled sound effects.
Cue.js is isolated as its own transform/group so aiming and striking can be manipulated independently of ball physics. The README’s “pivot isolation group” and “moveTo” note suggest the cue is positioned relative to the table/ball state rather than being a free-floating scene element.
The runtime data flow is:
main.js creates the table, physics engine, balls, and cue -> the animation loop advances time in substeps -> Physics.js updates ball interactions -> Ball.js objects receive new coordinates/rotation/spin -> the scene render reflects the updated state. This separation keeps scene construction, simulation, and visual representation distinct.
Audio is a separate presentation layer, not part of the physics core. The src/assets/ WAV files (ball_hit.wav, break_hit.wav, cushion_hit.wav, pocket_drop.wav) are triggered by simulation events such as ball-ball contact, break impacts, rail hits, and pocketing.
The public/models/ directory is the main asset boundary for imported geometry. The app depends on prebuilt .glb and .fbx models rather than generating geometry procedurally, except for the room/environment setup mentioned in the README.
In architecture terms, the key boundary is between:
• asset/scene setup (Table.js + public/models/)
• game-state simulation (Physics.js, Ball.js)
• player interaction (Cue.js)
• orchestration/render timing (main.js)
Overall, this is a single-page browser simulation organized around a deterministic physics loop and a 3D scene graph, with the table and room as static environment, balls as dynamic entities, and cue/audio as interaction layers.
Main entry points: main.js Main loop · Physics.js Physics · Ball.js Ball · Cue.js Cue
Components 9
App Shell
Browser entrypoint and viewport styling.
- index.html · Boots the client-side app and loads the runtime bundle.
index.html - Style · Global layout and presentation for the 3D viewport.
src/style.css
Runtime
Scene construction, simulation loop, and interactive game objects.
- Main loop · Creates the scene objects and drives the fixed-step animation loop.
src/main.js - Table · Builds the billiard table and surrounding room/environment.
src/Table.js - Ball · Represents each ball's position, velocity, spin, and rotation.
src/Ball.js - Cue · Handles aiming and striking as a separate transform from the balls.
src/Cue.js - Physics · Resolves collisions, cushion contacts, pocket drops, and friction.
src/Physics.js
Assets
Prebuilt 3D models and audio cues used by the scene.
- 3D models · Imported glb/fbx geometry for the table, room props, and decor.
- Sound effects · Collision, cushion, break, and pocket audio triggered by simulation events.
src/assets
Connections 14
- index.html → Main loop: loads · Bootstraps the JavaScript entrypoint.
- index.html → Style: applies · Loads the global viewport styling.
- Main loop → Table: creates · Builds the static arena and room.
- Main loop → Ball: creates · Instantiates the moving balls.
- Main loop → Cue: creates · Sets up the aiming and striking rig.
- Main loop → Physics: drives · Runs the deterministic fixed-step simulation loop.
- Main loop → 3D models: uses · Loads the imported scene geometry.
- Main loop → Sound effects: triggers · Plays impact and pocket audio from simulation events.
- Table → 3D models: assembles · Uses table and room props to build the scene.
- Physics → Ball: updates · Computes new ball motion and state.
- Physics → Cue: reads · Uses cue state when resolving strikes.
- Cue → Ball: strikes · Transfers aiming input into ball motion.
- Ball → Sound effects: emits · Ball collisions and pocketing generate audio events.
- Physics → Sound effects: emits · Collision and rail contacts trigger sound effects.