Skip to content

Add @vcad/sheet-metal package with unfold/refold and flat-pattern projection#181

Closed
ecto wants to merge 2 commits intomainfrom
claude/sheet-metal-app-tier-1
Closed

Add @vcad/sheet-metal package with unfold/refold and flat-pattern projection#181
ecto wants to merge 2 commits intomainfrom
claude/sheet-metal-app-tier-1

Conversation

@ecto
Copy link
Copy Markdown
Owner

@ecto ecto commented May 10, 2026

Summary

Introduces a complete sheet-metal modeling kernel as a new @vcad/sheet-metal package, porting the Rust vcad-kernel-sheet crate to TypeScript. The implementation provides lossless bidirectional unfold/refold operations, flat-pattern projection for manufacturing, and 3D tessellation for rendering.

Key Changes

  • New @vcad/sheet-metal package with core data structures and operations:

    • SheetMetalModel: A panel/bend graph tree structure representing bent sheet-metal parts
    • Frame: 3D pose representation (origin + orthonormal basis) for both bent and flat configurations
    • Panel: Flat planar regions with outlines, holes, and dual-frame poses
    • Bend: Cylindrical connections between panels with angle, radius, and K-factor metadata
  • Unfold/refold operations (unfold.ts):

    • unfold(): Computes flat-pattern frameFlat for all panels via tree walk
    • refold(): Reconstructs bent frameBent from flat configuration
    • Proven lossless inverses by construction: refold(unfold(m)) == m within tolerance
    • flatPatternFromModel(): Projects model into global 2D manufacturing coordinates with crease lines
    • tessellate(): Converts model to triangle mesh with bend-region geometry for 3D rendering
  • Base flange operations (base-flange.ts):

    • baseFlangeRect(): Creates initial sheet-metal model from axis-aligned rectangle
    • baseFlangePolygon(): Creates model from arbitrary polygon outline
  • Edge flange operations (edge-flange.ts):

    • addEdgeFlange(): Extends model by adding flanges off existing panel edges
    • Validates geometry, resolves K-factors from bend tables, computes bend allowances
  • Bend table system (bend-table.ts):

    • BendTable: Queryable (material, thickness, radius) → (K-factor, provenance) lookup
    • builtinBendTable(): Curated defaults (Al-soft, Al-hard, Steel-mild, SS-304)
    • lookupKFactor(): Intelligent fallback to closest R/t ratio when exact match unavailable
    • KFactorSource: Tracks provenance (builtin, shop, measured, manual) for UI visualization
  • Engine integration (packages/engine/src/sheet-metal.ts):

    • buildSheetMetalModel(): Walks node chain to construct model from IR ops
    • sheetMetalToMesh(): Converts model to TriangleMesh for scene rendering
    • Attaches model to EvaluatedPart for flat-pattern view and property panel access
  • UI components (packages/app/src/components/SheetMetalView.tsx):

    • Property panel showing thickness, panel/bend counts, flat-pattern area
    • Per-bend list with K-factor, radius, bend allowance, and colored provenance dots
    • Live SVG flat-pattern visualization with red (bend-up) and blue (bend-down) creases
  • IR extensions (packages/ir/src/index.ts):

    • SheetMetalBaseFlangeRectOp: Creates rectangular base flange
    • SheetMetalEdgeFlangeOp: Adds edge flange to existing panel
  • Example (packages/app/src/data/examples/sheet-metal-bracket.vcad.ts):

    • U-channel bracket (100×50×1mm aluminum) with two 25mm edge flanges demonstrating foundation tier

Notable Implementation Details

  • Lossless by construction: Both bent and flat poses are derived from panel-local outline + bend metadata; no information is lost during unfold/refold
  • Tree-based graph: Uses BFS traversal to walk panel/bend tree from root; cycle detection prevents invalid models
  • Bend allowance calculation: Implements classic formula

https://claude.ai/code/session_019XYMEQuLaAX45cqDtpyen7

Wires the foundation kernel into the app so users can see, select, and
inspect a sheet-metal part. Lands the @vcad/sheet-metal TS package
mirroring the Rust crate, IR variants for the two foundation ops,
engine evaluation that bypasses the Solid pipeline (the WASM kernel
doesn't yet need to know about sheet metal), a contextual side view
showing panel/bend/area stats with K-factor provenance dots, and a
live SVG flat-pattern view (red dashed = bend up, blue dashed = bend
down). Includes a "Sheet metal U-channel" example doc that demos a
100×50×1mm aluminum base flange with two 25mm Up flanges.

This is tier 1 of the UI plan in docs/design/sheet-metal.md: read-only
flat-pattern peer view + property panel surface. Direct-manipulation
flange gestures, the contextual Bend Strip, the bend-table editor
tab, and bidirectional flat editing land in follow-up tiers.

@vcad/sheet-metal mirrors the Rust crate exactly (Panel/Bend/
SheetMetalModel graph, base + edge flange ops, lossless
unfold/refold, FlatPattern projection, tessellation). 24 tests pass
including the round-trip-is-identity involution proof and the
no-drift-under-10-cycles property test — the legendary architecture
holds in the browser too.

https://claude.ai/code/session_019XYMEQuLaAX45cqDtpyen7
@vercel
Copy link
Copy Markdown

vercel Bot commented May 10, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
mecheval Ready Ready Preview, Comment May 10, 2026 1:57am
vcad Error Error May 10, 2026 1:57am
vcad-docs Ready Ready Preview, Comment May 10, 2026 1:57am
vcad-mcp Ready Ready Preview, Comment May 10, 2026 1:57am

Request Review

Vercel deployment failed because the explicit build chains in
packages/app/vercel.json, vercel.json, packages/docs/vercel.json, and
services/mcp/build.sh built @vcad/engine before @vcad/sheet-metal had
been built. In production mode the package's exports map points to
./dist/index.d.ts (only "development" resolves to source), so tsc
inside @vcad/engine couldn't find the type declarations:

  src/sheet-metal.ts(19,8): error TS2307: Cannot find module
  '@vcad/sheet-metal' or its corresponding type declarations.

Insert @vcad/sheet-metal between @vcad/ir and @vcad/engine in all
four build chains. Local repro of the Vercel order builds clean.

https://claude.ai/code/session_019XYMEQuLaAX45cqDtpyen7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants