How mnmxmx/three-dom-alignment works
Project type and purpose
• This is a frontend JavaScript “demo library” project (“three‑dom‑alignment”) that uses WebGL (Three.js), custom shaders (GLSL), SCSS, and Webpack to build two standalone demos (demo1 & demo2).
• It produces static HTML/CSS/JS bundles (in dist/) that illustrate how 3D objects stay aligned with the DOM.
File structure
• Top‐level:
• package.json, webpack.config.js → build & dependency config
• dist/ → compiled demo artifacts (HTML+CSS for demo1 and demo2, plus main.css)
• js/ → source code subdivided by demo
• js/demo1 & js/demo2 each contain:
• A “root” entry (demo1.js / demo2.js)
• modules/Artwork.js, Controls.js, Object.js → core logic for 3D+DOM alignment
• scss/styles.scss → demo‑specific styles
• js/glsl/ → shared shader code (plane.vert, plane.frag, utils/snoise3D.glsl)
• webpack.config.js → orchestrates module bundling (JS + SCSS + GLSL) into dist/
README for additional insights
• Minimal README: indicates Node.js v16, Yarn install & dev scripts. No further architectural notes; everything must be inferred from file layout and webpack config.
a. Main components
1. Development Environment (Node.js + Yarn)
2. Source Artifacts
– JS Entry Points (js/demo1.js, js/demo2.js)
– JS Modules (Artwork, Controls, Object)
– SCSS (styles.scss for each demo)
– GLSL Shaders (plane.vert, plane.frag, utils/snoise3D.glsl)
3. Build Pipeline (Webpack)
4. Output Bundles (dist/demo1.html, .css; dist/demo2.html, .css; main.css)
5. Runtime Environment (Browser)
– DOM
– Canvas & WebGL Context (Three.js)
– CSS styling
b. Relationships & interactions
– Source Artifacts flow into Webpack
– Webpack processes:
• JS modules → bundle.js
• SCSS → CSS files
• GLSL → inlined shader strings or separate assets
– Bundled outputs deployed to dist/
– Browser loads demoN.html → pulls in CSS & JS bundles
– JS bundle initializes Three.js scene, loads shaders, instantiates Artwork/Controls/Object, and manipulates DOM for alignment
c. Architectural patterns & design principles
– Module‑based design (ES modules per logical unit)
– Build‑time asset transformation (SCSS → CSS; GLSL → JS imports)
– Separation of concerns: rendering logic (Artwork/Object), input & UI controls, style definitions
d. Key technologies & libraries
– Node.js, Yarn (package management)
– Webpack (bundler + loaders for SCSS & GLSL)
– Three.js (WebGL abstraction)
– SCSS (preprocessed CSS)
– GLSL (shader language)