# lindblum/4d-viewer-threejs architecture

> Architecture diagram of the GitHub repository lindblum/4d-viewer-threejs, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/lindblum/4d-viewer-threejs
- Repository: https://github.com/lindblum/4d-viewer-threejs
- Video tour (about a minute): https://gitdiagram.com/lindblum/4d-viewer-threejs/video

## Overview

The 4D Polytope Viewer turns user controls into a selected, animated polytope shown on desktop, in WebXR, or through phone stereo modes. Its main stages are shape data and projection, scene rendering and appearance, shared options and XR interaction, and alternate display paths. The README documents capabilities beyond the sampled excerpts; edges below are limited to relationships visible in excerpts, the SOURCE INDEX, or README. Some rendering internals are grouped at their documented source paths.

Main entry points: [`src/Scene.jsx`](https://github.com/lindblum/4d-viewer-threejs/blob/master/src/Scene.jsx) (Scene Renderer), [`src/App.jsx`](https://github.com/lindblum/4d-viewer-threejs/blob/master/src/App.jsx) (App State and HUD), [`src/menu.js`](https://github.com/lindblum/4d-viewer-threejs/blob/master/src/menu.js) (Options Model), [`src/XRMenuPanel.jsx`](https://github.com/lindblum/4d-viewer-threejs/blob/master/src/XRMenuPanel.jsx) (XR Menu Panel)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application"]
  node_entry["App Bootstrap<br/>[main.jsx]"]
  node_appstate["App State and HUD<br/>[App.jsx]"]
end

subgraph group_model["Polytope Rendering"]
  node_scene["Scene Renderer<br/>[Scene.jsx]"]
  node_polydata["Polytope Data<br/>[polytope.js]"]
  node_geometry["4D Projection"]
  node_faces["Face Looks<br/>[faceLooks.js]"]
  node_edges["Edge Frames<br/>[Edges.jsx]"]
  node_pacing["Frame Pacing<br/>[FramePacing.jsx]"]
end

subgraph group_controls["Controls and XR"]
  node_menu["Options Model<br/>[menu.js]"]
  node_xrpanel["XR Menu Panel<br/>[XRMenuPanel.jsx]"]
  node_gaze["Gaze Input<br/>[Gaze.jsx]"]
  node_grab["Grip Controls<br/>[Grab.jsx]"]
  node_gripmath["Grip Helpers<br/>[grip.js]"]
  node_icons["Menu Icons<br/>[Icon.jsx]"]
end

subgraph group_views["Display Modes"]
  node_cardboard["Cardboard View<br/>[Cardboard.jsx]"]
  node_phone["Phone XR Stereo<br/>[PhoneStereo.jsx]"]
  node_lens["Lens Model<br/>[CardboardLens.js]"]
  node_sbs["Side-by-Side View<br/>[SideBySide.jsx]"]
end

node_user(("Viewer"))

node_user -->|"controls"| node_appstate
node_entry -->|"mounts"| node_appstate
node_appstate -->|"renders"| node_scene
node_appstate -->|"uses options"| node_menu
node_appstate -->|"imports"| node_xrpanel
node_appstate -->|"selects mode"| node_cardboard
node_appstate -->|"initializes session"| node_phone
node_appstate -->|"uses shape projection"| node_geometry
node_scene -->|"renders"| node_cardboard
node_scene -->|"uses reticle"| node_gaze
node_scene -->|"renders"| node_xrpanel
node_scene -->|"uses grip controls"| node_grab
node_scene -->|"checks face look"| node_faces
node_scene -->|"applies pacing"| node_pacing
node_scene -->|"renders"| node_edges
node_scene -->|"renders"| node_phone
node_scene -->|"renders"| node_sbs
node_polydata -->|"supplies vertices"| node_geometry
node_menu -->|"lists shapes"| node_geometry
node_menu -->|"lists face looks"| node_faces
node_menu -->|"lists edge looks"| node_edges
node_xrpanel -->|"registers gaze"| node_gaze
node_xrpanel -->|"formats labels"| node_menu
node_xrpanel -->|"draws icons"| node_icons
node_grab -->|"uses helpers"| node_gripmath
node_cardboard -->|"uses lens model"| node_lens
node_phone -->|"uses lens model"| node_lens

click node_entry "https://github.com/lindblum/4d-viewer-threejs/blob/master/src/main.jsx"
click node_appstate "https://github.com/lindblum/4d-viewer-threejs/blob/master/src/App.jsx"
click node_menu "https://github.com/lindblum/4d-viewer-threejs/blob/master/src/menu.js"
click node_scene "https://github.com/lindblum/4d-viewer-threejs/blob/master/src/Scene.jsx"
click node_polydata "https://github.com/lindblum/4d-viewer-threejs/blob/master/src/polytope.js"
click node_geometry "https://github.com/lindblum/4d-viewer-threejs/blob/master/src/polytopeGeometry.js"
click node_faces "https://github.com/lindblum/4d-viewer-threejs/blob/master/src/faceLooks.js"
click node_edges "https://github.com/lindblum/4d-viewer-threejs/blob/master/src/Edges.jsx"
click node_pacing "https://github.com/lindblum/4d-viewer-threejs/blob/master/src/FramePacing.jsx"
click node_xrpanel "https://github.com/lindblum/4d-viewer-threejs/blob/master/src/XRMenuPanel.jsx"
click node_gaze "https://github.com/lindblum/4d-viewer-threejs/blob/master/src/Gaze.jsx"
click node_grab "https://github.com/lindblum/4d-viewer-threejs/blob/master/src/Grab.jsx"
click node_gripmath "https://github.com/lindblum/4d-viewer-threejs/blob/master/src/grip.js"
click node_icons "https://github.com/lindblum/4d-viewer-threejs/blob/master/src/Icon.jsx"
click node_cardboard "https://github.com/lindblum/4d-viewer-threejs/blob/master/src/Cardboard.jsx"
click node_phone "https://github.com/lindblum/4d-viewer-threejs/blob/master/src/PhoneStereo.jsx"
click node_lens "https://github.com/lindblum/4d-viewer-threejs/blob/master/src/CardboardLens.js"
click node_sbs "https://github.com/lindblum/4d-viewer-threejs/blob/master/src/SideBySide.jsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entry,node_appstate,node_user toneBlue
class node_scene,node_polydata,node_geometry,node_faces,node_edges,node_pacing toneAmber
class node_menu,node_xrpanel,node_gaze,node_grab,node_gripmath,node_icons toneMint
class node_cardboard,node_phone,node_lens,node_sbs toneRose
```

## Components

### Application

- [App Bootstrap](https://github.com/lindblum/4d-viewer-threejs/blob/master/src/main.jsx): `src/main.jsx`
- [App State and HUD](https://github.com/lindblum/4d-viewer-threejs/blob/master/src/App.jsx): `src/App.jsx`

### Polytope Rendering

- [Scene Renderer](https://github.com/lindblum/4d-viewer-threejs/blob/master/src/Scene.jsx): `src/Scene.jsx`
- [Polytope Data](https://github.com/lindblum/4d-viewer-threejs/blob/master/src/polytope.js): `src/polytope.js`
- [4D Projection](https://github.com/lindblum/4d-viewer-threejs/blob/master/src/polytopeGeometry.js): `src/polytopeGeometry.js`
- [Face Looks](https://github.com/lindblum/4d-viewer-threejs/blob/master/src/faceLooks.js): `src/faceLooks.js`
- [Edge Frames](https://github.com/lindblum/4d-viewer-threejs/blob/master/src/Edges.jsx): `src/Edges.jsx`
- [Frame Pacing](https://github.com/lindblum/4d-viewer-threejs/blob/master/src/FramePacing.jsx): `src/FramePacing.jsx`

### Controls and XR

- [Options Model](https://github.com/lindblum/4d-viewer-threejs/blob/master/src/menu.js): `src/menu.js`
- [XR Menu Panel](https://github.com/lindblum/4d-viewer-threejs/blob/master/src/XRMenuPanel.jsx): `src/XRMenuPanel.jsx`
- [Gaze Input](https://github.com/lindblum/4d-viewer-threejs/blob/master/src/Gaze.jsx): `src/Gaze.jsx`
- [Grip Controls](https://github.com/lindblum/4d-viewer-threejs/blob/master/src/Grab.jsx): `src/Grab.jsx`
- [Grip Helpers](https://github.com/lindblum/4d-viewer-threejs/blob/master/src/grip.js): `src/grip.js`
- [Menu Icons](https://github.com/lindblum/4d-viewer-threejs/blob/master/src/Icon.jsx): `src/Icon.jsx`

### Display Modes

- [Cardboard View](https://github.com/lindblum/4d-viewer-threejs/blob/master/src/Cardboard.jsx): `src/Cardboard.jsx`
- [Phone XR Stereo](https://github.com/lindblum/4d-viewer-threejs/blob/master/src/PhoneStereo.jsx): `src/PhoneStereo.jsx`
- [Lens Model](https://github.com/lindblum/4d-viewer-threejs/blob/master/src/CardboardLens.js): `src/CardboardLens.js`
- [Side-by-Side View](https://github.com/lindblum/4d-viewer-threejs/blob/master/src/SideBySide.jsx): `src/SideBySide.jsx`

### Other components

- **Viewer**

## Connections

- Viewer → App State and HUD: controls (evidence: `README.md`)
- App Bootstrap → App State and HUD: mounts (evidence: `src/main.jsx`)
- App State and HUD → Scene Renderer: renders (evidence: `src/App.jsx`)
- App State and HUD → Options Model: uses options (evidence: `src/App.jsx`)
- App State and HUD → XR Menu Panel: imports (evidence: `src/App.jsx`)
- App State and HUD → Cardboard View: selects mode (evidence: `src/App.jsx`)
- App State and HUD → Phone XR Stereo: initializes session (evidence: `src/App.jsx`)
- App State and HUD → 4D Projection: uses shape projection (evidence: `src/App.jsx`)
- Scene Renderer → Cardboard View: renders (evidence: `src/Scene.jsx`)
- Scene Renderer → Gaze Input: uses reticle (evidence: `src/Scene.jsx`)
- Scene Renderer → XR Menu Panel: renders (evidence: `src/Scene.jsx`)
- Scene Renderer → Grip Controls: uses grip controls (evidence: `src/Scene.jsx`)
- Scene Renderer → Face Looks: checks face look (evidence: `src/Scene.jsx`)
- Scene Renderer → Frame Pacing: applies pacing (evidence: `src/Scene.jsx`)
- Scene Renderer → Edge Frames: renders (evidence: `src/Scene.jsx`)
- Scene Renderer → Phone XR Stereo: renders (evidence: `src/Scene.jsx`)
- Scene Renderer → Side-by-Side View: renders (evidence: `src/Scene.jsx`)
- Polytope Data → 4D Projection: supplies vertices (evidence: `src/polytopeGeometry.js`)
- Options Model → 4D Projection: lists shapes (evidence: `src/menu.js`)
- Options Model → Face Looks: lists face looks (evidence: `src/menu.js`)
- Options Model → Edge Frames: lists edge looks (evidence: `src/menu.js`)
- XR Menu Panel → Gaze Input: registers gaze (evidence: `src/XRMenuPanel.jsx`)
- XR Menu Panel → Options Model: formats labels (evidence: `src/XRMenuPanel.jsx`)
- XR Menu Panel → Menu Icons: draws icons (evidence: `src/XRMenuPanel.jsx`)
- Grip Controls → Grip Helpers: uses helpers (evidence: `src/Grab.jsx`)
- Cardboard View → Lens Model: uses lens model (evidence: `src/Cardboard.jsx`)
- Phone XR Stereo → Lens Model: uses lens model (evidence: `src/PhoneStereo.jsx`)
