How steve245270533/react-three-egg works
Project Type and Purpose
• This is a single-page, client-side 3D game built with React and Three.js (via @react-three/fiber) plus a physics engine (@react-three/rapier).
• The README calls it “react-three-egg,” a third-person Q-style adventure game clone, stripped of multiplayer logic and migrated to Vite.
File Structure
• Top-level config & env files (.env.*, tsconfig, vite.config.ts, .eslintrc.cjs, GitHub Actions).
• public/ holds static 3D models (GLB) and index.html.
• src/ contains:
• App.tsx & index.tsx – React entry point and root component.
• components/Character (Character.tsx + model & hooks)
• components/Map (Map.tsx + useMap hook)
• components/Spinner (loading UI)
• hooks/ (useMap, useCharacter)
• Constants.ts, styles.scss, vite-env.d.ts
Key Insights from the README
• Tech stack: react, three, @react-three/fiber, @react-three/rapier
• Game controls via keyboard (input → useCharacter hook → physics)
• Assets loaded at runtime from public/
Main Components
a. Browser / Client
• index.html → Vite-bundled JS/CSS → React app
b. React App Layer
• <App>
• <Canvas> (react-three-fiber)
• <Spinner> (loading indicator)
• Scene Graph:
– Character component (uses useCharacter hook + CharacterModel)
– Map component (uses useMap hook)
c. 3D Engine & Physics
• Three.js core (renderer, scene, camera)
• Rapier physics engine (rigid bodies, collision)
d. Assets & Configuration
• GLB model files (public/)
• Constants.ts for magic values
• SCSS styles
e. Build & Deployment
• Vite (dev server, bundler)
• GitHub Actions (deploy.yml)
Relationships and Data Flows
• User Input (keyboard events) → useCharacter hook → Rapier physics update → Three.js scene graph
• useMap hook → sets up static physics colliders + Map mesh in scene
• Three.js + Canvas → painted to browser viewport
• Public assets loaded via HTTP requests
Architectural Patterns & Design Principles
• Component-based decomposition (React functional components + hooks)
• Separation of concerns: rendering (react-three-fiber), physics (rapier), game logic (hooks), assets (public)
• Single responsibility: each hook & component has a distinct role