/kernelcad-design-skills:kernelcad-trace-from-imagefrom kernelCAD — Parametric CAD & MCP
Convert pixel-space features from a reference photo into normalized [0,1] waypoints, then into mm coordinates feedable to path().spline / path().nurbsSegment. Uses the trace_from_image MCP tool. Load when your blockout is in place and the next step is an organic-curve outline (eyewear brow, ergonomic handle, sneaker midsole) that would take more than a minute to eyeball off the photo.
Ships in kernelCAD — Parametric CAD & MCP. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
This is a coord-extractor, not a vision agent. It takes a reference photo
plus a list of requested features and returns normalized [0,1] waypoints
the agent can convert to mm via a known scale anchor and feed to a
path().spline() / path().nurbsSegment() chain.
Accuracy honesty. opencv's contour is geometrically exact on a uniform-bg
photo. Claude vision is typically 5–10% off on dense landmarks. Every
returned feature carries a per-feature confidence in [0, 1]. Treat the
output as better starting-point waypoints, not pixel-perfect coords —
the model will still need at least one render→inspect pass before finalizing.
Output replaces the burden of eyeballing dozens of (x, y) pairs off a photo;
it does not replace the spec-writer.
.kcad.ts blockout already in place (from blockout-model/SKILL.md)../reference.jpg typically).Load if all three are true:
path().spline(), path().nurbsSegment(),
path().hermiteG2(), or a nurbsCurve(...) ref.(12.3, 4.1) was right).Do not load this skill for:
param().Pick the smallest set of features that captures the outline you want.
Single silhouette. For a one-piece organic outline (eyewear brow as a single curve, sneaker side profile), request one feature:
{ "features": [{ "label": "frame_brow", "kind": "silhouette" }] }
Silhouette + named points. When you also need landmarks that a contour
extractor cannot label (the bridge midpoint between two lenses, the lens
center, the brow tip), add them with kind: "point":
{
"features": [
{ "label": "frame_brow", "kind": "silhouette" },
{ "label": "bridge_top", "kind": "point",
"region": "between the lenses, top edge" },
{ "label": "lens_left_center", "kind": "point",
"region": "center of the left lens" }
]
}
Naming convention. Use snake_case and the form <part>_<role> so that
the same labels can flow into kernelCAD constant names (const bridge_top = [...];). The label is echoed verbatim in the response.
Backend hint. Leave backend unset; let the router pick. The router
falls through to:
'opencv' — uniform background + silhouette/curve features only.'hybrid' — uniform background + any point/bbox feature.'vision-llm' — cluttered background; or you explicitly want the LLM.Forcing 'opencv' on a point/bbox request emits a
tool.trace-from-image.opencv-cannot-label warning — opencv returns the
silhouette for every feature.
trace_from_imagetrace_from_image({
imageUrl: "file:///path/to/reference.jpg",
features: [
{ "label": "frame_brow", "kind": "silhouette" },
{ "label": "bridge_top", "kind": "point" }
],
maxWaypointsPerFeature: 14
})
Picking maxWaypointsPerFeature:
| Curve character | Suggested cap |
|---|---|
| Shallow (one bow, e.g. handle back) | 6–8 |
| Medium (eyewear brow, sneaker top profile) | 10–14 |
| Highly inflected (S-curves, ergonomic grips) | 16–20 |
A cap that's too high wastes context; too low loses inflection points. Start at 12 (the default), adjust on the second call if the curve looks too chunky or too noisy.
Each returned feature has { label, kind, waypoints, confidence, backend }.
Before converting to mm:
| Check | Action if violated |
|---|---|
confidence >= 0.6 | Re-call with a tighter region, OR force backend: "hybrid". If still <0.6 after the retry, add a // confidence N, hand-corrected comment when you commit the mm coords. |
| Waypoint count fits the curve character above | Adjust maxWaypointsPerFeature and re-call. |
| First waypoint sits on the curve's expected start | If not, you cannot just paste — adjust the moveTo() argument to match waypoints[0]. |
Every trace_from_image response also carries a ledger: one fact per
returned feature (visible when opencv measured it deterministically,
inferred when the vision-LLM labeled it), plus a scale fact that is
missing unless you passed scaleAnchor, plus any priors you supplied
recorded as assumed. Do not skip straight to Step 4 while facts are open:
// ledger.facts (excerpt) — scale is missing because no scaleAnchor was passed:
[
{ "id": "frame_brow", "kind": "visible", "confidence": 1, "resolution": "confirmed" },
{ "id": "bridge_top", "kind": "inferred", "confidence": 0.74, "resolution": "open" },
{ "id": "scale", "kind": "missing", "confidence": 0, "resolution": "open" }
]
Resolve open facts with resolve_assumptions before committing geometry:
resolve_assumptions({
ledgerPath: "/path/to/build.ledger.json",
resolutions: [
{ id: "bridge_top", confirm: true },
{ id: "scale", value: 0.1548 } // mm/px derived from the Real Object Brief's scale anchor
]
})
resolve_assumptions returns paramOverrides — feed paramOverrides.scale
straight into the MM_PER_NORM_X calculation in Step 4 instead of hand-typing
the anchor math. If you need a hard stop instead of a warning (e.g. an
unattended batch trace), pass validate: 'error' to trace_from_image — the
call itself fails (ok: false) while scale is still missing and open.
Pick a scale anchor from the Real Object Brief — for example,
frameWidth = 130 mm over 0.84 of the image width.
// Scale anchor: frame outer width 130 mm spans 0.84 of the image width.
const FRAME_WIDTH_MM = 130;
const FRAME_NORM_SPAN = 0.84;
const MM_PER_NORM_X = FRAME_WIDTH_MM / FRAME_NORM_SPAN;
const MM_PER_NORM_Y = MM_PER_NORM_X; // assumes square pixels — confirm
// Center the image's normalized origin (0.5, 0.5) at the model origin.
// Flip Y because the photo's top-left origin disagrees with our XZ plane.
const toMm = ([nx, ny]: [number, number]): [number, number] => [
(nx - 0.5) * MM_PER_NORM_X,
-(ny - 0.5) * MM_PER_NORM_Y,
];
const browWaypointsMm = traced.features[0].waypoints.map(toMm);
const brow = path()
.moveTo(...browWaypointsMm[0])
.spline(browWaypointsMm.slice(1));
The Y flip is load-bearing — image-space y grows downward, the model's
z/y grows upward. Without the flip the brow appears inverted.
Always render the updated .kcad.ts before committing:
kernelcad render build.kcad.ts --width 1920 --height 1080 -o /tmp/trace-check.png
Open /tmp/trace-check.png and confirm the traced curve matches the
reference outline visually. Only after that is plausible, hand off to
image-replicator/SKILL.md for the render→score→iterate loop.
backend: "opencv" forced. opencv returns the
largest dark blob, which on a hand-held photo is usually the camera or
shadow, not the artifact. Fix: drop the override; the router picks
'vision-llm' automatically.hint: "traverse the brow left-to-right along its top edge".moveTo(). The path-builder
emits feature.path.spline.degenerate-points. Fix: update the
moveTo() to match waypoints[0] exactly.region: "left half of the brow only"), then .mirror('YZ') in the model.| Gate | Pass criterion |
|---|---|
| G-trace-confidence | Every feature has confidence >= 0.6, OR the script carries a // confidence N, hand-corrected comment naming that feature. |
| G-trace-scale-anchor | The script contains a comment that names the scale anchor used (e.g. // Scale anchor: frameWidth = 130 mm spans 0.84 of the image width). |
| G-trace-first-waypoint | The PathBuilder chain begins with moveTo(<first traced waypoint>) before any .spline() or .nurbsSegment() taking traced waypoints. |
| G-assumption-ledger | ledger.unresolvedCount === 0, OR every open fact was reviewed and either confirmed/overridden via resolve_assumptions or explicitly accepted with a // assumption <id>: <reason> comment naming it. Never silently ignore an open missing (scale) fact. |
Once the traced curve renders plausibly, proceed to
image-replicator/SKILL.md for the render→score→iterate loop that closes
the gap between the traced outline and the reference photo.
trace_from_image — the MCP tool this skill drives. Caller-supplied
ANTHROPIC_API_KEY is required when the router picks 'vision-llm' or
'hybrid'. Cost ~$0.005 per call against Claude Haiku — do not loop
trace_from_image inside an outer iteration loop. One call per
surface/curve is enough.resolve_assumptions — confirms/overrides the open facts in the
assumption ledger trace_from_image returns. Reads/rewrites
<model>.ledger.json; returns paramOverrides to feed into set_param.What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub w1ne/kernelcad-skills --plugin kernelcad-design-skills28 skills in this plugin
/blockout-modelCoarse parametric blockout of the primary masses before committing to detail. Establishes the bounding envelope, canonical-view alignment, and reference-image plane, then confirms the blockout is plausible before detail work begins./image-replicatorThe render→score→iterate loop for reference-photo reconstruction. How to invoke kernelcad render, run scoreAgainstReference, interpret per-gate numbers, and decide which gate to chase next./kernelcadkernelCAD entry decision tree — what skill to load when, universal conventions that apply everywhere. Load this FIRST; it points at the right specialty skill for your task.Other plugins' skills for the same job