# amberjen/learn-threejs architecture

> Architecture diagram of the GitHub repository amberjen/learn-threejs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amberjen/learn-threejs
- Repository: https://github.com/amberjen/learn-threejs

## Overview

##### Project Type Analysis
This is a collection of interactive 3D graphics demonstrations built with Three.js, each showcasing different capabilities and techniques. The project is structured as multiple independent sub-projects, each with its own specific focus.

##### Main Components

A. Core Infrastructure Layer:
- Three.js Runtime Environment
- WebGL Renderer
- Browser DOM Interface

B. Project Structure Layer:
- Individual Project Modules (01-06)
- Asset Management System
- Rendering Pipeline

C. Resource Management Layer:
- Texture Loading System
- 3D Model Loading System
- Font Loading System

**[Browser Environment]**
- ↓
**[Three.js Core Engine]**
- ↓
**[Project Components]**

**[Asset Management]**
- ↓
**[Scene Management] → [Render Pipeline] → [Display Output]**
- ↑
**[User Interaction]**

##### Specific Implementation Details

For each project module, include:

a) Solar System (01):
- Texture loading system
- Orbital mechanics
- Cubemap implementation

b) 3D Text (02):
- Font loading system
- Material management
- Matcap texture handling

c) Haunted House (03):
- Geometry generation
- Texture management
- Scene composition

d) Galaxy Generator (04):
- Particle systems
- Dynamic geometry

e) Scroll Animation (05):
- DOM interaction
- Animation system
- Scroll event handling

f) Low Poly Planet (06):
- GLTF model loading
- Draco compression
- Interactive controls

##### Connection Flow

→ Synchronous operations
⇢ Asynchronous operations
⇄ Two-way data binding

##### Important Notes

- Shared infrastructure between projects
- How assets are loaded and managed
- Rendering pipeline flow
- Demonstrate user interaction paths
- Performance optimization points

##### Technical Stack Highlights

- Vite.js for build system
- Three.js for 3D rendering
- WebGL as the graphics API
- Static asset handling
- GLTF/Draco for 3D models

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph Browser["Browser Environment"]
        DOM["DOM Interface"]
        WebGL["WebGL Context"]
    end

    subgraph Core["Three.js Core Engine"]
        ThreeJS["Three.js Runtime"]
        Renderer["WebGL Renderer"]
        AssetMgr["Asset Management System"]
    end

    subgraph Projects["Project Implementations"]
        direction TB
        
        subgraph Solar["Solar System Demo"]
            SolarImpl["Main Implementation"]:::impl
            SolarTex["Texture System"]:::resource
            SolarOrbit["Orbital Mechanics"]
            SolarCube["Cubemap System"]:::resource
        end

        subgraph Text["3D Text Demo"]
            TextImpl["Main Implementation"]:::impl
            FontSys["Font System"]:::resource
            MatcapSys["Matcap System"]:::resource
            MaterialMgr["Material Management"]
        end

        subgraph House["Haunted House Demo"]
            HouseImpl["Main Implementation"]:::impl
            HouseAssets["Asset System"]:::resource
            Geometry["Geometry Generation"]
            SceneComp["Scene Composition"]
        end

        subgraph Galaxy["Galaxy Generator Demo"]
            GalaxyImpl["Main Implementation"]:::impl
            ParticleSys["Particle System"]
            DynamicGeo["Dynamic Geometry"]
            ColorMgr["Color Management"]
        end

        subgraph Scroll["Scroll Animation Demo"]
            ScrollImpl["Main Implementation"]:::impl
            ScrollTex["Texture System"]:::resource
            AnimSys["Animation System"]
            EventHandler["Event Handling"]
        end

        subgraph Planet["Low Poly Planet Demo"]
            PlanetImpl["Main Implementation"]:::impl
            ModelSys["Model Loading"]:::resource
            DracoSys["Draco Compression"]:::resource
            Controls["Interactive Controls"]
            GLTF["GLTF Model"]:::resource
        end
    end

    subgraph Build["Build System"]
        Vite["Vite Configuration"]:::config
    end

    %% Connections
    DOM --> ThreeJS
    WebGL --> Renderer
    ThreeJS --> Renderer
    Renderer --> Projects
    AssetMgr --> Projects

    %% Click events
    click SolarImpl "https://github.com/amberjen/learn-threejs/blob/master/01-solar-system/main.js"
    click SolarCube "https://github.com/amberjen/learn-threejs/tree/master/01-solar-system/public/textures/cubeMaps"
    click TextImpl "https://github.com/amberjen/learn-threejs/blob/master/02-3d-text/src/main.js"
    click FontSys "https://github.com/amberjen/learn-threejs/tree/master/02-3d-text/static/fonts"
    click MatcapSys "https://github.com/amberjen/learn-threejs/tree/master/02-3d-text/static/textures/matcaps"
    click HouseImpl "https://github.com/amberjen/learn-threejs/blob/master/03-haunted-house/src/main.js"
    click HouseAssets "https://github.com/amberjen/learn-threejs/tree/master/03-haunted-house/static"
    click GalaxyImpl "https://github.com/amberjen/learn-threejs/blob/master/04-galaxy-generator/src/main.js"
    click ScrollImpl "https://github.com/amberjen/learn-threejs/blob/master/05-scroll-animation/src/main.js"
    click ScrollTex "https://github.com/amberjen/learn-threejs/tree/master/05-scroll-animation/static/textures/gradients"
    click PlanetImpl "https://github.com/amberjen/learn-threejs/blob/master/06-lowpoly-planet/src/main.js"
    click ModelSys "https://github.com/amberjen/learn-threejs/tree/master/06-lowpoly-planet/static/models"
    click DracoSys "https://github.com/amberjen/learn-threejs/tree/master/06-lowpoly-planet/static/draco"
    click GLTF "https://github.com/amberjen/learn-threejs/blob/master/06-lowpoly-planet/static/models/lowpoly-planet.glb"
    click Vite "https://github.com/amberjen/learn-threejs/blob/master/06-lowpoly-planet/vite.config.js"

    %% Styles
    classDef impl fill:#4a9eff,stroke:#666
    classDef resource fill:#ffa500,stroke:#666
    classDef config fill:#98ff98,stroke:#666

    %% Legend
    subgraph Legend
        L1["Implementation"]:::impl
        L2["Resource/Asset"]:::resource
        L3["Configuration"]:::config
    end
```
