Skip to content

Move transformMesh + embroideryPatternToMesh into the Rust kernel #194

@ecto

Description

@ecto

Context

Audit during #181 turned up two pieces of geometric computation living in packages/engine/src/evaluate.ts that should be in the Rust kernel:

  • transformMesh (~50 LOC) — Euler-XYZ → 3×3 matrix applied to a mesh's positions and normals. Used to bake transforms onto imported meshes and embroidery ribbons before they hit the scene. Reimplements rotation math that already exists in vcad-kernel-math.
  • embroideryPatternToMesh (~55 LOC) — Builds a ribbon mesh (positions/colors/indices) from EmbroideryPatternOp stitches. Pure tessellation logic; belongs alongside the embroidery design support in the kernel.

Same one-source-of-truth rule that motivated #181's rejection: anything that does geometry math or tessellation belongs in crates/vcad-kernel-*, with TS as a thin client.

Proposed work

  1. Add a tessellate_embroidery_pattern (or similar) entry in the kernel that takes the IR EmbroideryPatternOp JSON and returns triangle data + per-vertex colors.
  2. Add a transform_mesh entry in the kernel (or expose a Mesh::apply_transform on whatever mesh handle we already have).
  3. Expose both via wasm-bindgen in vcad-kernel-wasm.
  4. Delete the TS implementations and route evaluate.ts through the new bindings.

Files touched

  • packages/engine/src/evaluate.ts — delete embroideryPatternToMesh (~line 326) and transformMesh (~line 382)
  • packages/engine/src/eval-worker.ts — re-export wiring
  • crates/vcad-kernel-wasm/src/ — add bindings
  • New (or extended) kernel crate for the actual logic

Out of scope

Replacing the JS sketch-math.ts fallback path or the expressions.ts dual implementation — those are tracked separately.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions