How amandaghassaei/origamisimulator works
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: dynamicSolver.js Dynamic GPU Solver · model.js Simulation Model · main.js App Bootstrap · pattern.js Crease Pattern
Components 18
Browser Application
- Application Page · Loads browser-global modules and static UI.
index.html - App Bootstrap · Connects UI, import, model, solver, and rendering workflows.
js/main.js - Shared State · Application settings and shared runtime state.
js/globals.js - Fold Controls · Binds folding and advanced options.
js/controls.js
Pattern & Geometry
- Pattern Importer · Accepts SVG, FOLD, and bundled examples.
js/importer.js - Crease Pattern · Represents imported crease topology.
js/pattern.js - Curved-Fold Prep · Applies ruling-aware triangulation for curved folds.
js/curvedFolding.js - Simulation Model · Builds triangulated simulation geometry from topology.
js/model.js - Nodes, Creases & Beams
js/node.js - Triangulation Libraries · Earcut and CDT2D support mesh construction.
dependencies/earcut.js
Folding Solver
- Dynamic GPU Solver · Iteratively updates displacement as fold percentage changes.
js/dynamic/dynamicSolver.js - GPU Math Runtime · Fragment-shader parallel calculation infrastructure.
js/dynamic/GPUMath.js - Static & Rigid Solvers · CPU/static and rigid solving modes.
js/staticSolver.js
View & Outputs
- Three.js View · Visualizes and updates the interactive folded mesh.
js/threeView.js - 3D & VR Interaction · Provides orbit controls and optional VR interaction.
js/3dUI.js - FOLD & Mesh Export · Exports FOLD and printable mesh formats.
js/saveFOLD.js - Video Animator · Produces video animation separately from interactive solving.
js/videoAnimator.js - Vendored Runtime Libraries · Three.js, FOLD, SVG parsing, and numeric libraries run entirely in the browser.
dependencies/three.js
Connections 20
- 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