MCPAsk AI

Search

Search skills, authors and topics

Moh4696 / inkworks-skill

inkworks

Builds interactive 3D "how it works" explainer pages for any machine or mechanism (engines, pumps, locks, gearboxes, turbines, printers, hearts) in the Inkworks look, a white engineering drawing with ink-outlined three.js parts, numbered balloon labels and a cycle you can slow down, step, scrub and orbit. Two layouts, a full drafting sheet with instruments and a cycle chart, or a clean figure card with the model alone. You write one mechanism file of geometry, kinematics and words, the kit does

Install

npx skills add https://github.com/Moh4696/inkworks-skill --skill inkworks

Mechanism file API

A mechanism is one ES module in kit/js/mechanisms/ that default-exports a plain object. The page (kit/js/sheet.js) reads its metadata to build the DOM, calls build(kit, api) once, then calls model.pose(theta, dt, state) every frame. starter.js is the shortest complete example; engine.js shows several instances, pump.js shows moving phase bounds, mechanism state and an action button.

Top-level fields

FieldRequiredMeaning
idyesShort name, matches the file name
meta.pageTitleBrowser tab title
meta.fig, meta.captionyesSheet top bar, e.g. Fig. 01 and Inline-4 · four-stroke petrol · cutaway
meta.titleyesHeadline HTML. Wrap one phrase in <em> for the red italic
meta.ledeyesOne or two sentences under the headline (sheet layout)
meta.titleBlockyes{ title, dwg, scale? } for the title block (sheet layout)
meta.altAccessible name for the 3D canvas
meta.layout'sheet' or 'figure': this mechanism's default
cycleyesDriver degrees per full cycle (360 for most, 720 for a four-stroke)
startInitial theta
phasesyesArray of { name, nick, list, short, key, color, text }. name big title, nick the one-word nickname, list the phase-list button, short the chart label (caps), key the chart legend, color one of HUES, text 2 to 3 sentences
bounds(state)Phase start angles, length = phases. Omit for equal slices. Called every frame, so bounds may depend on state.mech
instancesyes{ count, label, short, offset[] }. offset[i] is where unit i sits in the cycle (engine [0, 540, 180, 360] fires 1-3-4-2). One unit: count: 1, offset: [0]
driveryesThe reader's input and the rate it drives, below
speeds, speedyesSlow-motion divisors shown as buttons ([200, 60, 12], [4, 2, 1]; 1 shows as 1x) and the default
gaugeSheet layout dial: { max, red?, minor, major, tick?(v), label, unit, value(state), readout?(v) }
plotSheet layout x-y loop: { label, x(phi, state) -> 0..1, y(phi, state), yUnit, xTicks: [left, mid, right], yMin }. Drawn per phase in phase colours with a dot for the followed unit
chart{ label, note, markers: [{ at, kind: 'spark' or 'tick' }] }. at may be a function of state
layersToggle buttons the mechanism handles: [{ key, label, on }]. Labels and Orbit are added by the page
actionsExtra buttons: [{ label, run(state, api) }], e.g. the pump's "Let air out"
viewyesCamera, below
compactCalloutsCallout numbers to keep on phones
build(kit, api)yesBuilds the model and returns it, below

driver

js
driver: {  inputLabel: 'Accelerator',            // slider label  inputHint: 'Opens the throttle...',   // one line under it (sheet layout)  input: 0.15,                          // slider start, 0..1  start: 850,                           // optional starting rate  target: (x) => 800 + 5600 * x ** 1.15, // rate the input asks for (rpm, strokes/min...)  inputFormat: (x) => `${...}`,         // optional slider readout (default: percent)  inertia: 1.4,                         // how fast the rate follows (per second)  degPerSec: (rate) => rate / 60 * 360, // rate -> driver degrees per second at 1x}

Each frame: state.rate eases toward target(state.input), then theta += degPerSec(rate) / state.slow * dt while playing.

view

js
view: {  target: [0, 1.15, 0],     // what the camera orbits  dir: [6.4, 4, -9],        // direction from target to camera (normalised for you)  radius: 3.9,              // how much of the scene to fit, sheet layout  radiusFigure: 3.75,       // figure layout (default radius * 1.15)  radiusCompact: 4.7,       // phones (default radius * 1.2)  minDist: 7, maxDist: 30,  // orbit zoom limits  box: [[x0, y0, z0], [x1, y1, z1]],   // bounding box of everything at full travel; callout columns sit outside it}

The layout centres target in the free area between the panels (or inside the card) with camera.setViewOffset, and picks the distance that fits radius.

build(kit, api)

kit is everything from kit/js/kit.js:

NameUse
THREE, scene, camera, controls, rendererthree.js r169 and the live scene
part(geo, mat, { edges, outline })Solid: toon mesh + ink feature edges + silhouette outline
ghost(geo)Hidden-line housing: faint fill + dashed edges
ghostRings(curve, r, n)Dashed rings along a translucent tube
inkRing(r, y, mat?, seg?)Ink circle in the XZ plane (piston rings, focus rings)
markLine(len, r0)Red timing mark that makes rotation visible
stream(points, color, { count, size, parent })Particle flow along a path; move with .advance(fraction), fade with .mat.opacity
flash(size)Spark/impact sprite; scale it in pose()
xCyl(r, len), aimX(dy, dz)Cylinder along X; rotation that aims a -Z feature
gearGeometry(r, teeth, depth), springGeometry(r, turns, wire), hull(points)Gears, coil springs (scale.y to compress), belts
toon(hex), MMaterial maker and the shared palette: steel alloy dark valve ceramic rubber copper glass
lineMat, ghostLine, INK, HUES, D2R, mod, clamp01, smoothHelpers

api is { state, phaseOf(phi), phiOf(i), bounds(), cycle }.

state holds: theta, phi[i] (each unit's angle in the cycle, already offset), playing, input, rate, slow, focus, layers, tween, scrubbing, and mech (yours).

The returned model

FieldRequiredMeaning
rootThe group you built (added to the scene if you did not)
pose(theta, dt, state)yesPlace every part for this angle. Use state.phi[i] for per-unit angles. Tie particle movement and accumulation to how far theta moved this frame (theta - lastTheta), never to dt, so scrubbing and stepping stay correct
calloutsyes[{ n, name, at(v, state) }]: at writes the world point the leader touches (use obj.localToWorld(v.set(...)) for moving parts)
readouts[{ label, value(ctx) }], ctx = { phi, i, s, phase, api }. Return a string, or { text, cls } with cls 'on' (blue) or 'hot' (red)
setLayer(key, on)Show or hide what each layer toggle controls
tagAnchor(i, v, where)if count > 1World point for unit i's tag: 'below' (sheet balloons), 'above' (figure tags) and 'point' (where the figure tag's dashed leader ends)
focusChanged(i, state)Called when the reader follows another unit

URL and page switches

  • ?m=pump picks a mechanism file (?m=examples/engine inside a scaffolded project).
  • ?layout=figure or ?layout=sheet overrides the layout.
  • window.__sheet = { state, model, mech, kit, api, setFocus, jumpTo, setPlaying, layout } for scripted shots, the recorder and the console.
  • Keyboard: Space plays and pauses, the left and right arrows step one phase.