How ahzs645/seamer works
1. Overall shape
- This is a SvelteKit application with a split architecture: a browser-based studio UI and a small server/API layer for pattern persistence.
- The distinctive path is 2D sewing pattern → reconstructed avatar → arranged garment → WebGPU cloth simulation → 3D drape render.
2. Primary user surface
- The main workspace is /studio, which combines a 2D pattern editor, property/panel UI, and a 3D simulation pane.
- Supporting informational routes (/about, /docs, /software, /support-seamer) are separate from the studio workflow and do not drive the simulation pipeline.
3. Pattern domain model and persistence
- src/lib/types/pattern.ts defines the core data shape: points, Bézier paths, pieces, seams, materials, body settings, and 3D arrangement metadata.
- Pattern state is managed on the client through Svelte stores, with local persistence via src/lib/stores/localDB.ts.
- Server-side persistence/CRUD is exposed under src/routes/api/patterns/*, with public and per-id endpoints suggesting a lightweight pattern library backend.
4. 2D pattern editing layer
- The 2D editor is assembled from Svelte components such as PatternCanvas2D, BodyPanel, LayerPanel, PropertyPanel, SeamPanel, MaterialPanel, and DrawingTools.
- src/lib/utils/patternGeometry.ts, patternMutations.ts, patternValidation.ts, and patternImport.ts handle the transformation from editable pattern data to renderable/validated geometry.
- This layer is the authoring boundary: it manages user edits, but the 3D simulation consumes the resolved pattern state.
5. Avatar reconstruction pipeline
- The avatar subsystem in src/lib/model/* rebuilds a body mesh from measurements using bundled statistical model assets in static/models/.
- measurements.ts and measurementDefs.ts define body inputs; avatar.ts, skinnedAvatar.ts, and avatarController.ts turn those inputs into a posed mesh.
- The readme’s flow is important here: measurements → regression coefficients → 12,302-vertex mesh → skeleton + skinning → posed avatar.
6. Garment arrangement and geometry prep
- Before simulation, garment pieces are converted into physical geometry by src/lib/geometry/* and src/lib/sim/*.
- boundary.ts, triangulate.ts, and arrangement.ts prepare piece boundaries and triangulated cloth panels; cylinders.ts and bodyGrid.ts fit the garment around tapered body cylinders for initial placement.
- This is the bridge between 2D drafting and 3D physics: it turns sewing patterns into a mesh that can be simulated around the body.
7. Cloth simulation core
- The simulation stack in src/lib/sim/ implements a WebGPU XPBD cloth solver.
- build.ts assembles particles, stretch/bend constraints, seam constraints, and collision structures; simulator.ts coordinates stepping; webgpu/device.ts, engine.ts, and shaders.ts contain the GPU execution path.
- The solver is intentionally hard-bound to WebGPU for live draping; the repo does not provide a WebGL fallback for cloth physics.
8. Collision, seams, and physical constraints
- The sim includes body collision, seam attraction, anisotropic stretch compliance, and bend constraints.
- The body collision path uses a grid-based broad phase and closest-point push-out/friction handling, while seam constraints keep mirrored or paired pattern edges together.
- This makes the garment physics dependent on the reconstructed avatar shape, so measurement changes propagate all the way into the drape result.
9. 3D scene and rendering
- src/lib/scene/scene3d.ts and materials.ts define the 3D viewport using three.js / WebGL for rendering.
- The scene renders the avatar, the arranged or simulated garment, lighting, and controls; WebGPU is only used for the physics solve, not for the main scene renderer.
- The repo explicitly separates “display” rendering from “physics” execution.
10. Client state, UX overlays, and interaction
- Shared UI concerns are encapsulated in components like Toaster, ConfirmDialog, ContextMenu, FormulaDialog, KeyboardShortcuts, and WelcomeModal.
- This layer coordinates editing, feedback, and workflow state, but it does not own the geometry or physics; it wraps the domain subsystems above.
11. Static assets and bundled content
- Most heavy assets live in static/: avatar model binaries/json, HDR environment maps, sample DXFs, templates, textures, and the PWA/service-worker files.
- The presence of many prebuilt garment templates suggests the app supports both import/open flows and curated starter patterns.
12. Operational and test boundary
- src/routes/sw.js and static/service-worker.js indicate offline/cache-aware behavior typical of a studio app with large static assets.
- End-to-end coverage is done with Playwright in e2e/, including scenarios for importing samples and edge editing, which reflects the two critical workflows: pattern ingestion and interactive garment manipulation.
Main entry points: +page.svelte Studio · pattern.ts Pattern store · patternGeometry.ts Pattern ops · scene3d.ts 3D scene
Components 21
Studio UI
Browser workspace for drafting, panels, and 3D preview.
- Studio · Main workspace route combining editor, panels, and simulation viewport.
src/routes/studio/+page.svelte - UI chrome · Header, toolbar, overlays, dialogs, and workflow helpers.
src/lib/components - 2D editor · Pattern canvas and editing tools for drafting and annotation.
src/lib/components/PatternCanvas2D.svelte - Panels · Body, layer, property, seam, material, and object panels.
src/lib/components - Docs routes · Informational routes for about, docs, software, and support pages.
src/routes/docs/+page.svelte
Pattern Domain
Pattern data model, editing, validation, and persistence on the client.
- Pattern store · Svelte store state and local database persistence for patterns.
src/lib/stores/pattern.ts - Local DB · Browser-side persistence layer for saved pattern state.
src/lib/stores/localDB.ts - Pattern model · Core data shapes for points, seams, materials, bodies, and arrangement metadata.
src/lib/types/pattern.ts - Pattern ops · Mutation, validation, import, export, and geometry conversion helpers.
src/lib/utils/patternGeometry.ts
Avatar Pipeline
Measurement-driven body reconstruction and posed avatar generation.
- Avatar model · Measurement-driven body reconstruction and posed mesh pipeline.
src/lib/model/avatar.ts - Measurements · Measurement definitions and measurement data used to drive body fitting.
src/lib/model/measurements.ts
Garment Prep
Converts 2D patterns into simulation-ready cloth geometry.
- Garment prep · Boundary extraction, triangulation, and initial garment arrangement around the body.
src/lib/geometry/arrangement.ts - Body grid · Cylindrical fitting and grid-based garment placement helpers.
src/lib/sim/bodyGrid.ts
Cloth Sim
WebGPU XPBD cloth solver and its orchestration layers.
- Simulator · Coordinates cloth stepping, constraints, and collision-aware simulation updates.
src/lib/sim/simulator.ts - Solver build · Builds particles, stretch/bend constraints, seams, and collision structures.
src/lib/sim/build.ts - WebGPU engine · Device, execution engine, and shaders for cloth physics on the GPU.
src/lib/sim/webgpu/engine.ts
3D Scene
Display renderer and materials for the studio viewport.
- 3D scene · Three.js/WebGL scene for avatar, cloth, lighting, and interaction.
src/lib/scene/scene3d.ts - Scene mats · Viewport material definitions and rendering configuration.
src/lib/scene/materials.ts
API
Server endpoints for pattern library CRUD and public access.
- Pattern API · Pattern library endpoints for list, create, update, delete, and public access.
src/routes/api/patterns/+server.ts
Static Assets
Bundled models, templates, samples, and environment maps.
- Model assets · Bundled coefficient, index, and skinning assets for avatar reconstruction.
static/models/base_model.json - Templates · Curated pattern templates and sample DXF imports for onboarding and reuse.
static/templates/black-dress.json
Connections 24
- Studio → 2D editor: hosts · The studio page embeds the drafting canvas.
- Studio → Panels: hosts · The studio page lays out the editing panels.
- Studio → 3D scene: hosts · The studio page includes the 3D viewport.
- UI chrome → Studio: wraps · Shared chrome and dialogs support the studio flow.
- 2D editor → Pattern store: reads/writes · Editor actions mutate the client-side pattern state.
- Panels → Pattern store: reads/writes · Panels edit the same pattern state as the canvas.
- Pattern store → Local DB: persists · Pattern state is saved locally for reload and continuity.
- Pattern store → Pattern model: uses · Store state follows the shared pattern domain model.
- Pattern ops → Pattern model: transforms · Utilities mutate, validate, and derive geometry from pattern data.
- Pattern ops → Templates: imports · Pattern utilities consume template and sample content.
- 2D editor → Pattern ops: uses · Interactive editing relies on geometry and validation helpers.
- Measurements → Avatar model: feeds · Measurement inputs drive body reconstruction.
- Model assets → Avatar model: backs · Bundled statistical assets support avatar generation.
- Avatar model → 3D scene: renders · The reconstructed avatar is shown in the viewport.
- Pattern ops → Garment prep: prepares · Resolved pattern data becomes garment geometry.
- Garment prep → Body grid: initializes · Geometry preparation uses body-fit placement helpers.
- Garment prep → Simulator: feeds · Prepared cloth geometry enters the simulation pipeline.
- Solver build → WebGPU engine: executes on · Solver assembly is run through the WebGPU path.
- Simulator → Solver build: drives · The simulator coordinates constraint and collision setup.
- Simulator → 3D scene: updates · Simulation results are visualized in the 3D scene.
- 3D scene → Scene mats: uses · Viewport rendering depends on material definitions.
- Pattern API → Pattern store: syncs · Server-side pattern CRUD complements client persistence.
- Pattern API → Pattern model: serializes · API payloads follow the shared pattern schema.
- Docs routes → Studio: separate · Informational pages are distinct from the studio workflow.