Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.
Plan: Visual motion-path editor + per-step camera capture (assembly instructions)
Date: 2026-07-06
Branch: claude/confident-maxwell-dy4fvr
Status: Phases 1–4 implemented (viewer helpers + tests, red-path editor, camera
capture, editor/route integration). Gates green: @carbon/viewer typecheck + 64 unit
tests, erp + mes typecheck, biome clean. Phase 5 (browser verification) pending.
Goal
Restore two authoring capabilities to the assembly instruction editor that the number-based motion editor replaced:
- Draggable motion path. When authoring a step's motion, the part's insertion path renders as a red line in the 3D viewer with drag-and-drop waypoints. Editing waypoints edits the motion. (Replaces typing Vec3 direction/distance.)
- Set camera view per step. A button that saves the current viewer camera
as the step's
camerapose, so playback frames that step exactly as the author set it. Plus a "Clear" that returns the step to auto-framing.
Note: neither feature exists in git history — this is a rebuild, not a revert. The number-based editor has been the only motion editor since the first commit;
step.camerahas only ever been set by the geometry planner, never by UI.
What already exists (grounding — verified in code)
Persistence is already done — this is a UI-only feature:
assemblyInstructionStepValidator(production.models.ts:1214) already acceptsmotion: jsonField(motionSchema.optional())andcamera: jsonField(cameraSchema.nullable().optional()).motionSchema(:1053) already includes thepathvariant (keyframes: {t, position, quaternion}[], min 2).cameraSchema(:1095) ={position: vec3, target: vec3, fov: number}.- The step-save route
x+/assembly+/$id.steps.$stepId.tsxvalidates that schema and callsupsertAssemblyInstructionStep— no route/DB/migration changes needed. - Viewer already consumes both fields:
motionToKeyframes/buildStepClip(packages/viewer/src/motion.ts) animatespathmotions;AssemblyScenereadsstep.camera(AssemblyPlayer.tsx:931+) to frame the shot, else auto-frames. - Viewer stack: react-three-fiber 8.18 + drei 9.122 + three 0.163. drei ships
Line,TransformControls,DragControls,PivotControls,Html,Sphere(all present in installed.d.ts) — nothing new to add to deps. nodeId → Object3Dmap (useAssembly.ts:108,nodesById) is already threaded intoAssemblyScene— the bridge for placing handles at part positions.- Live camera is reachable inside
AssemblyScene:camera = useThree(s=>s.camera)(AssemblyPlayer.tsx:510),controls = useThree(s=>s.controls)(:511, OrbitControls viamakeDefault).{camera.position, controls.target, camera.fov}is exactly aCameraPose.
The gaps to close:
- Editor (
AssemblyInstructionProperties.tsx→StepForm) supports onlymotionTypes = ["none","linear","L","helix"](:165) and mapspath → none(makeMotionDraft,:236). It emits no camera. No Hiddencamerafield exists. AssemblyPlayerexposes no way to edit a path or read out the camera (AssemblyPlayerProps,:33): callbacks are onlyonStepChange,onSelectParts,onGraphLoaded.readOnlydisables selection (MES uses it).
Design decisions (recommended defaults — flag any for veto)
- Serialize to RELATIVE motion (
linear/L), not absolutepath. Discovered while grounding: apathmotion's keyframes are absolute world positions, andmotionToKeyframesvalidates the last keyframe equals each part's seated pose — sopathonly works for single-part steps and would throw on multi-part rigid groups.linear/Lare relative (direction+distance applied to each part's own seated pose), exactly how the planner already animates grouped steps. So the editor emitslinearfor 2 waypoints,Lfor 3+ waypoints. Waypoints are world-space for display, anchored so the last waypoint is the seated reference (centroid of the step's parts' seated positions); intermediate + first waypoints are draggable, the last is locked to seated.pathhandling is left untouched (planner may still produce it; we convert it to waypoints on open). - Orientation (v1): pure translation. Parts translate without rotating — no
per-waypoint quaternion authoring (which is why
pathbuys us nothing here). Full 6-DOF is out of scope for v1. - The path editor is the only motion editor. Selecting a step samples its current
motion (
linear/L/helix/path/none) into editable world waypoints via a newmotionToWaypointshelper, so any step is draggable; drags serialize back viawaypointsToMotion. The numeric editor is removed (see Resolved decisions). - Waypoint ops: drag existing (translate gizmo), double-click a segment to insert a waypoint, select + Delete/trash button to remove. Minimum 2 waypoints (start + seated).
- Autosave on drag-end, debounced, via the existing step fetcher — consistent with direct-manipulation UX. No explicit Save click for path edits.
- Camera button lives in the properties panel (with the rest of step editing);
the viewer exposes an imperative
captureCameraPose()viaforwardRefso the button can read the live pose. "Set view" savescamera; "Clear" savesnull. - Edit is Draft-only (
isDisabled/readOnlyalready gate this); MES playback (readOnly) is untouched. Editing pauses playback and pins the part at a preview pose so mixer rebuilds don't fight the handles.
Architecture
Three panels coordinate through the route ($id.tsx), which already owns shared
selection state (selectedNodeIds, selectedStepId, draftPartNodeIds):
- Lift a motion-edit session into
$id.tsx:editingMotion: {stepId} | nullplus adraftMotionfor the step being edited. The viewer renders the red path foreditingMotion.stepId;StepFormtoggles the session and mirrorsdraftMotioninto its existingmotionstate / Hidden field. - Camera capture uses a
playerRef(imperative handle) held by$id.tsx, passed toStepFormas anonCaptureCamera/onClearCameracallback pair.
New/changed files
| File | Change |
|---|---|
packages/viewer/src/motion.ts |
Add motionToWaypoints(motion, seatedPosition, opts) and waypointsToMotion(worldWaypoints, seatedPosition) (pure): sample any motion to world waypoints, and convert dragged waypoints back to linear/L/none. Reuse existing motionToKeyframes. |
packages/viewer/src/MotionPathEditor.tsx (new) |
In-scene overlay: drei Line (red) through waypoints + draggable TransformControls handles; last handle locked; double-click insert / Delete remove. Emits world-space waypoints on change. |
packages/viewer/src/AssemblyPlayer.tsx |
Add props editMotion?: {stepId, motion} | null, onMotionChange?(stepId, motion). Render <MotionPathEditor> in AssemblyScene (sibling of <primitive object={scene}>) when editing the active step. forwardRef + useImperativeHandle exposing captureCameraPose(): CameraPose (bridged from an in-scene reporter that closes over camera/controls). Pause playback while editing. |
packages/viewer/src/index.ts |
Export the new helpers/types if consumed by ERP. |
apps/erp/app/routes/x+/assembly+/$id.tsx |
Hold editingMotion + draftMotion state and playerRef; thread editMotion/onMotionChange to AssemblyPlayer; pass camera + edit callbacks to AssemblyInstructionProperties. |
apps/erp/app/modules/production/ui/Assemblies/AssemblyInstructionProperties.tsx |
StepForm: add "Edit path in 3D" toggle (starts/stops the session; syncs draftMotion ↔ motion); support the path motion type in makeMotionDraft/serializeMotion (stop mapping path → none); add "Set camera to current view" + "Clear view" buttons and a <Hidden name="camera" value=…> field so camera persists on save. Keep numeric editor under an "Advanced" disclosure. |
apps/erp/app/modules/production/AGENTS.md, docs/specs/animated-work-instructions-contracts.md |
Doc the visual editor + camera authoring (keep-docs-in-sync). |
Phases & tasks
Phase 1 — Viewer helpers (pure, testable)
-
motionToWaypoints(motion, seatedPosition, {defaultDistance?}): sample any motion into ordered world-space waypoints (start … seated) viamotionToKeyframes, deduping coincident points. Fornone(or unsamplable), synthesize a short straight default offset so a path always exists to drag. -
waypointsToMotion(worldWaypoints, seatedPosition): force last waypoint to seated, drop degenerate segments; 1 segment →linear, 2+ →L, none →none. Directions/distances matchmotionToKeyframes' reconstruction (verified: exact round-trip for linear/L). - Verify:
pnpm --filter @carbon/viewer typecheck+ extendmotion.test.ts(round-trip linear/L, multi-part safety, none→default, degenerate→none).
Phase 2 — Editable red path in the viewer
-
MotionPathEditor.tsx: dreiLine(red,lineWidth≈3) through waypoints;TransformControls(translate) on each non-terminal handle; terminal handle a static locked marker. Double-click a segment inserts a midpoint; selecting a handle + Delete removes it (min 2). Convert handle positions → world waypoints, callonMotionChange(stepId, waypointsToPathMotion(...))on drag-end (debounced). - Wire into
AssemblyScene: render only wheneditMotion?.stepId === activeStep.idand notreadOnly. DisableOrbitControlswhile dragging a handle (TransformControlsdragging-changed→ togglecontrols.enabled). Pause the mixer; pin the edited part at the current preview pose so clip rebuilds don't clobber handles. - Extend
AssemblyPlayerPropswitheditMotion/onMotionChange; keep all existing props/behavior.readOnlypath unchanged (MES unaffected).
Phase 3 — Camera capture (imperative)
-
forwardRefonAssemblyPlayer;useImperativeHandleexposingcaptureCameraPose(). In-sceneCameraPoseReporterwrites a getter (() => ({position: camera.position.toArray(), target: controls.target.toArray(), fov: (camera as PerspectiveCamera).fov})) into a ref the handle reads. - No behavior change to existing
step.cameraconsumption.
Phase 4 — Editor + route integration
-
$id.tsx: addeditingMotion/draftMotionstate +playerRef; passeditMotion={editingMotion && {stepId, motion: draftMotion}},onMotionChange={(stepId, m) => setDraftMotion(m)}toAssemblyPlayer; passonCaptureCamera/onClearCamera(readplayerRef.current.captureCameraPose(), submit to the step route) and edit-session toggles toAssemblyInstructionProperties. -
StepForm: supportpathinmakeMotionDraft/serializeMotion; add "Edit path in 3D" toggle that opens the session and binds the viewer'sdraftMotionback intomotion(so the Hiddenmotionfield + autosave use it); add "Set camera to current view" / "Clear view" buttons and<Hidden name="camera">. Numeric editor moves under an "Advanced" disclosure (kept, not removed). - Autosave path edits on drag-end via the step fetcher (debounced ~500ms).
Phase 5 — Verify
-
pnpm --filter @carbon/viewer typecheck,pnpm exec turbo run typecheck --filter=erp,pnpm run lint, viewer unit tests. - Browser (agent-browser
/auth+/test): create/open a Draft instruction on a converted model → select a step → "Edit path" shows a red line with handles → drag a waypoint, add one, delete one → play the step and confirm the part follows the new path → "Set camera to current view", reload, confirm the step frames to the saved pose → "Clear view" returns to auto-frame. Confirm MES playback (readOnly) is unchanged. - Screenshots in the PR (surface-designs rule).
Risks / watch-items
- Mixer vs handles. The clip effect (
AssemblyPlayer.tsx:658) rebuilds on step/seek and restores seated poses on cleanup. The editor overlay must live outside that lifecycle and edit must pause playback (decision #7), or drags will fight the animation. - World vs local space. Handles are world-space;
buildStepCliplocalizes to parent. Keep all editing in world space and only convert atwaypointsToPathMotion; verify with a part that has a non-identity parent transform. - TransformControls + OrbitControls conflict. Standard drei pattern: toggle
controls.enabledondragging-changed. Must restore on unmount. readOnly/MES regression. All new UI gates on!readOnly+ Draft. Add an explicit check that the MESAssembly.tsxconsumer compiles and behaves unchanged.- fov edge case. Orthographic camera has no
fov; guard withPerspectiveCamerainstanceof (already the pattern at:820), fall back to 45.
Out of scope (v1)
- 6-DOF waypoint rotation (orientation authoring).
- Editing
helix/Lparameters by 3D manipulation (numeric "Advanced" editor stays). - Timeline-keyframe scrubbing UI beyond the existing playback scrubber.
Resolved decisions (2026-07-06)
- Remove the numeric motion editor entirely. The visual path editor is the only
motion editor. Any planner-produced motion (
linear/L/helix/none) is converted to an editablepathon selection viamotionToWaypoints; there is no numeric Vec3/parameter fallback.motionTypes/MotionDraft/serializeMotion/VectorInput/ScalarInputand theshowMotionEditordisclosure inStepFormare deleted. Consequence: helix/L can no longer be edited parametrically — only as a dragged path. (Accepted.) - Autosave path edits on drag-end (debounced), via the step fetcher. No Save click.
- Camera button in the properties panel, reading the live pose through the
AssemblyPlayerimperative ref.