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
- Add a
tessellate_embroidery_pattern (or similar) entry in the kernel that takes the IR EmbroideryPatternOp JSON and returns triangle data + per-vertex colors.
- Add a
transform_mesh entry in the kernel (or expose a Mesh::apply_transform on whatever mesh handle we already have).
- Expose both via wasm-bindgen in
vcad-kernel-wasm.
- 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.
Context
Audit during #181 turned up two pieces of geometric computation living in
packages/engine/src/evaluate.tsthat 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 invcad-kernel-math.embroideryPatternToMesh(~55 LOC) — Builds a ribbon mesh (positions/colors/indices) fromEmbroideryPatternOpstitches. 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
tessellate_embroidery_pattern(or similar) entry in the kernel that takes the IREmbroideryPatternOpJSON and returns triangle data + per-vertex colors.transform_meshentry in the kernel (or expose aMesh::apply_transformon whatever mesh handle we already have).vcad-kernel-wasm.evaluate.tsthrough the new bindings.Files touched
packages/engine/src/evaluate.ts— deleteembroideryPatternToMesh(~line 326) andtransformMesh(~line 382)packages/engine/src/eval-worker.ts— re-export wiringcrates/vcad-kernel-wasm/src/— add bindingsOut of scope
Replacing the JS
sketch-math.tsfallback path or theexpressions.tsdual implementation — those are tracked separately.