# amandaghassaei/origamisimulator architecture

> Architecture diagram of the GitHub repository amandaghassaei/origamisimulator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amandaghassaei/origamisimulator
- Repository: https://github.com/amandaghassaei/origamisimulator

## Overview

#### Purpose and Delivery
OrigamiSimulator is a static browser application that interactively folds origami crease patterns by solving the sheet geometry from crease forces. It is hosted as client-side files; `index.html` is the application entry point, with presentation styles in `css/main.css` and `css/nav.css`.

#### Bootstrap and Global Coordination
The JavaScript application is organized as browser-global modules loaded by the HTML page. `js/main.js` initializes the app and connects UI, import, model, solver, and rendering workflows. `js/globals.js` holds shared application state and settings; `js/controls.js` binds folding and advanced-option controls.

Paths: `index.html`, `js/main.js`, `js/globals.js`, `js/controls.js`.

#### Pattern Import and Geometry Preparation
Imported SVG and FOLD patterns, plus bundled examples, enter through the importer. The pattern/model layer converts crease topology into triangulated simulation geometry and distinguishes creases, nodes, and beams. Curved-fold preprocessing is a separate path that applies ruling-aware triangulation before simulation.

Paths: `js/importer.js`, `js/pattern.js`, `js/model.js`, `js/curvedFolding.js`, `js/node.js`, `js/crease.js`, `js/beam.js`.

#### Folding Solver Pipeline
The primary control flow is: flat crease pattern → mesh/topology construction → solver initialization → iterative displacement updates as fold percentage changes → render/export state. The main high-performance solver runs parallel calculations through GPU fragment-shader infrastructure, with CPU/static and rigid-solver alternatives or supporting modes.

Paths: `js/dynamic/dynamicSolver.js`, `js/dynamic/GPUMath.js`, `js/dynamic/GLBoilerplate.js`, `js/staticSolver.js`, `js/rigidSolver.js`.

#### Rendering and Interaction Boundary
Three.js is the rendering and 3D interaction boundary. The view module owns scene visualization and likely updates mesh state from the solver; UI modules provide 3D controls and optional VR interaction. Users can rotate, zoom, inspect strain, and adjust fold amount without a server round trip.

Paths: `js/threeView.js`, `js/3dUI.js`, `js/VRInterface.js`, `dependencies/three.js`, `dependencies/OrbitControls.js`.

#### Import/Export and Animation Outputs
The application accepts SVG and FOLD as its input boundary. FOLD is the internal interchange representation; output includes FOLD and printable/mesh formats such as STL and OBJ. Video animation/export is handled separately from interactive solving.

Paths: `js/saveFOLD.js`, `js/saveSTL.js`, `js/videoAnimator.js`, `dependencies/fold.js`, `dependencies/OBJExporter.js`, `dependencies/binary_stl_writer.js`.

#### Runtime Assets and External Dependencies
All runtime dependencies are vendored under `dependencies/`; no backend, database, or build/deployment service is evident. Key libraries are Three.js for rendering, FOLD plus SVG parsing libraries for pattern ingestion, Earcut/CDT2D for triangulation, and numeric.js for linear algebra. Example crease patterns and documentation media are static assets.

Paths: `dependencies/SVGLoader.js`, `dependencies/earcut.js`, `dependencies/cdt2d.js`, `dependencies/numeric-1.2.6.js`, `assets/Pleating/BoxPleatTessellation.fold`, `assets/doc/crane.gif`.

Main entry points: [`js/dynamic/dynamicSolver.js`](https://github.com/amandaghassaei/origamisimulator/blob/main/js/dynamic/dynamicSolver.js) (Dynamic GPU Solver), [`js/model.js`](https://github.com/amandaghassaei/origamisimulator/blob/main/js/model.js) (Simulation Model), [`js/main.js`](https://github.com/amandaghassaei/origamisimulator/blob/main/js/main.js) (App Bootstrap), [`js/pattern.js`](https://github.com/amandaghassaei/origamisimulator/blob/main/js/pattern.js) (Crease Pattern)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Browser Application"]
  node_entry["Application Page<br/>HTML entry<br/>[index.html]"]
  node_main["App Bootstrap<br/>coordinator<br/>[main.js]"]
  node_state["Shared State<br/>global state<br/>[globals.js]"]
  node_controls["Fold Controls<br/>UI controls<br/>[controls.js]"]
end

subgraph group_geometry["Pattern &amp; Geometry"]
  node_importer["Pattern Importer<br/>input boundary<br/>[importer.js]"]
  node_pattern["Crease Pattern<br/>topology<br/>[pattern.js]"]
  node_curved["Curved-Fold Prep<br/>preprocessor<br/>[curvedFolding.js]"]
  node_model["Simulation Model<br/>mesh builder<br/>[model.js]"]
  node_primitives["Nodes, Creases &amp; Beams<br/>simulation primitives<br/>[node.js]"]
  node_triangulation["Triangulation Libraries<br/>vendored geometry<br/>[earcut.js]"]
end

subgraph group_solver["Folding Solver"]
  node_dynamic["Dynamic GPU Solver<br/>primary solver<br/>[dynamicSolver.js]"]
  node_gpu["GPU Math Runtime<br/>GPU compute<br/>[GPUMath.js]"]
  node_alternative["Static &amp; Rigid Solvers<br/>alternative solvers<br/>[staticSolver.js]"]
end

subgraph group_presentation["View &amp; Outputs"]
  node_view["Three.js View<br/>renderer<br/>[threeView.js]"]
  node_interaction["3D &amp; VR Interaction<br/>view controls<br/>[3dUI.js]"]
  node_exports["FOLD &amp; Mesh Export<br/>output boundary<br/>[saveFOLD.js]"]
  node_animation["Video Animator<br/>animation output<br/>[videoAnimator.js]"]
  node_runtime["Vendored Runtime Libraries<br/>client dependencies<br/>[three.js]"]
end

node_entry -->|"loads"| node_main
node_main -->|"initializes"| node_state
node_main -->|"binds"| node_controls
node_controls -->|"fold settings"| node_dynamic
node_main -->|"imports"| node_importer
node_importer -->|"parses"| node_pattern
node_pattern -.->|"curved-fold path"| node_curved
node_pattern -->|"builds"| node_model
node_curved -->|"triangulates"| node_model
node_model -->|"constructs"| node_primitives
node_triangulation -->|"triangulation"| node_model
node_model -->|"simulation mesh"| node_dynamic
node_gpu -->|"parallel compute"| node_dynamic
node_alternative -.->|"alternative mode"| node_dynamic
node_dynamic -->|"mesh state"| node_view
node_interaction -->|"camera and VR input"| node_view
node_dynamic -->|"folded state"| node_exports
node_dynamic -->|"animation state"| node_animation
node_runtime -->|"SVG and FOLD support"| node_importer
node_runtime -->|"Three.js rendering"| node_view

click node_entry "https://github.com/amandaghassaei/origamisimulator/blob/main/index.html"
click node_main "https://github.com/amandaghassaei/origamisimulator/blob/main/js/main.js"
click node_state "https://github.com/amandaghassaei/origamisimulator/blob/main/js/globals.js"
click node_controls "https://github.com/amandaghassaei/origamisimulator/blob/main/js/controls.js"
click node_importer "https://github.com/amandaghassaei/origamisimulator/blob/main/js/importer.js"
click node_pattern "https://github.com/amandaghassaei/origamisimulator/blob/main/js/pattern.js"
click node_curved "https://github.com/amandaghassaei/origamisimulator/blob/main/js/curvedFolding.js"
click node_model "https://github.com/amandaghassaei/origamisimulator/blob/main/js/model.js"
click node_primitives "https://github.com/amandaghassaei/origamisimulator/blob/main/js/node.js"
click node_triangulation "https://github.com/amandaghassaei/origamisimulator/blob/main/dependencies/earcut.js"
click node_dynamic "https://github.com/amandaghassaei/origamisimulator/blob/main/js/dynamic/dynamicSolver.js"
click node_gpu "https://github.com/amandaghassaei/origamisimulator/blob/main/js/dynamic/GPUMath.js"
click node_alternative "https://github.com/amandaghassaei/origamisimulator/blob/main/js/staticSolver.js"
click node_view "https://github.com/amandaghassaei/origamisimulator/blob/main/js/threeView.js"
click node_interaction "https://github.com/amandaghassaei/origamisimulator/blob/main/js/3dUI.js"
click node_exports "https://github.com/amandaghassaei/origamisimulator/blob/main/js/saveFOLD.js"
click node_animation "https://github.com/amandaghassaei/origamisimulator/blob/main/js/videoAnimator.js"
click node_runtime "https://github.com/amandaghassaei/origamisimulator/blob/main/dependencies/three.js"

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_main,node_state,node_controls toneBlue
class node_importer,node_pattern,node_curved,node_model,node_primitives,node_triangulation toneAmber
class node_dynamic,node_gpu,node_alternative toneMint
class node_view,node_interaction,node_exports,node_animation,node_runtime toneRose
```

## Components

### Browser Application

- [Application Page](https://github.com/amandaghassaei/origamisimulator/blob/main/index.html): HTML entry · Loads browser-global modules and static UI. · `index.html`
- [App Bootstrap](https://github.com/amandaghassaei/origamisimulator/blob/main/js/main.js): coordinator · Connects UI, import, model, solver, and rendering workflows. · `js/main.js`
- [Shared State](https://github.com/amandaghassaei/origamisimulator/blob/main/js/globals.js): global state · Application settings and shared runtime state. · `js/globals.js`
- [Fold Controls](https://github.com/amandaghassaei/origamisimulator/blob/main/js/controls.js): UI controls · Binds folding and advanced options. · `js/controls.js`

### Pattern & Geometry

- [Pattern Importer](https://github.com/amandaghassaei/origamisimulator/blob/main/js/importer.js): input boundary · Accepts SVG, FOLD, and bundled examples. · `js/importer.js`
- [Crease Pattern](https://github.com/amandaghassaei/origamisimulator/blob/main/js/pattern.js): topology · Represents imported crease topology. · `js/pattern.js`
- [Curved-Fold Prep](https://github.com/amandaghassaei/origamisimulator/blob/main/js/curvedFolding.js): preprocessor · Applies ruling-aware triangulation for curved folds. · `js/curvedFolding.js`
- [Simulation Model](https://github.com/amandaghassaei/origamisimulator/blob/main/js/model.js): mesh builder · Builds triangulated simulation geometry from topology. · `js/model.js`
- [Nodes, Creases & Beams](https://github.com/amandaghassaei/origamisimulator/blob/main/js/node.js): simulation primitives · `js/node.js`
- [Triangulation Libraries](https://github.com/amandaghassaei/origamisimulator/blob/main/dependencies/earcut.js): vendored geometry · Earcut and CDT2D support mesh construction. · `dependencies/earcut.js`

### Folding Solver

- [Dynamic GPU Solver](https://github.com/amandaghassaei/origamisimulator/blob/main/js/dynamic/dynamicSolver.js): primary solver · Iteratively updates displacement as fold percentage changes. · `js/dynamic/dynamicSolver.js`
- [GPU Math Runtime](https://github.com/amandaghassaei/origamisimulator/blob/main/js/dynamic/GPUMath.js): GPU compute · Fragment-shader parallel calculation infrastructure. · `js/dynamic/GPUMath.js`
- [Static & Rigid Solvers](https://github.com/amandaghassaei/origamisimulator/blob/main/js/staticSolver.js): alternative solvers · CPU/static and rigid solving modes. · `js/staticSolver.js`

### View & Outputs

- [Three.js View](https://github.com/amandaghassaei/origamisimulator/blob/main/js/threeView.js): renderer · Visualizes and updates the interactive folded mesh. · `js/threeView.js`
- [3D & VR Interaction](https://github.com/amandaghassaei/origamisimulator/blob/main/js/3dUI.js): view controls · Provides orbit controls and optional VR interaction. · `js/3dUI.js`
- [FOLD & Mesh Export](https://github.com/amandaghassaei/origamisimulator/blob/main/js/saveFOLD.js): output boundary · Exports FOLD and printable mesh formats. · `js/saveFOLD.js`
- [Video Animator](https://github.com/amandaghassaei/origamisimulator/blob/main/js/videoAnimator.js): animation output · Produces video animation separately from interactive solving. · `js/videoAnimator.js`
- [Vendored Runtime Libraries](https://github.com/amandaghassaei/origamisimulator/blob/main/dependencies/three.js): client dependencies · Three.js, FOLD, SVG parsing, and numeric libraries run entirely in the browser. · `dependencies/three.js`

## Connections

- Application Page → App Bootstrap: loads
- App Bootstrap → Shared State: initializes
- App Bootstrap → Fold Controls: binds
- Fold Controls → Dynamic GPU Solver: fold settings
- App Bootstrap → Pattern Importer: imports
- Pattern Importer → Crease Pattern: parses
- Crease Pattern → Curved-Fold Prep: curved-fold path
- Crease Pattern → Simulation Model: builds
- Curved-Fold Prep → Simulation Model: triangulates
- Simulation Model → Nodes, Creases & Beams: constructs
- Triangulation Libraries → Simulation Model: triangulation
- Simulation Model → Dynamic GPU Solver: simulation mesh
- GPU Math Runtime → Dynamic GPU Solver: parallel compute
- Static & Rigid Solvers → Dynamic GPU Solver: alternative mode
- Dynamic GPU Solver → Three.js View: mesh state
- 3D & VR Interaction → Three.js View: camera and VR input
- Dynamic GPU Solver → FOLD & Mesh Export: folded state
- Dynamic GPU Solver → Video Animator: animation state
- Vendored Runtime Libraries → Pattern Importer: SVG and FOLD support
- Vendored Runtime Libraries → Three.js View: Three.js rendering
