Cutaway skill: build, film and score a 3D object that takes itself apart from one picture

The skill (SKILL.md), the kit for building one HTML page and capturing a 60 fps film, the procedural sound engine, the green page and look, and 3 complete examples: a tarantula, a piranha and a wasp, each with a full film and a 10-second version. The method docs move into docs/ with the README's GIFs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Nyxera0x
2026-11-06 12:57:09 +03:00
parent ca143f35f4
commit 5d8f1c6efe
93 changed files with 15705 additions and 39 deletions
+360
View File
@@ -0,0 +1,360 @@
// The Vesper AX-6 console, copied from the hummingbird's (robohum-shared/console.js, itself the bee's) and laid out the
// same at 1600 x 900: the orange AX-6 badge and title with the sim status cells, the fin stroke with its live chart of
// the tail and the pectorals, power, the six fin, tail, jaw, lure and dorsal servos, dive telemetry with an attitude
// ball and the bank, the assemblies, the display toggles, the subsystem registry, the dive log with the operator's
// actions on its timeline, the swim-mode word in the viewport, the labels with leaders into the fish and the
// operator's pointer. Panels are light paper over the near-white studio; the fish's orange is the one accent.
// update(s) redraws every live part from the frame's state.
export const C = {ink: '#24211d', mute: '#9a8f82', faint: '#e0d7ca', line: '#ece5da', panel: 'rgba(253,251,247,.95)', or: '#ff5a1f', green: '#2fa36b', track: '#efe8de'};
export const VIEWS = ['hero', 'front', 'side', 'wing', 'legs'];
export const VIEW_LABEL = {hero: 'HERO', front: 'FRONT', side: 'SIDE', wing: 'WING', legs: 'LEGS'};
export const DISPLAY = ['labels', 'xray', 'exploded', 'blur', 'orbit'];
export const DISPLAY_LABEL = {labels: 'LABELS', xray: 'X-RAY', exploded: 'EXPLODED', blur: 'MOTION BLUR', orbit: 'ORBIT'};
// the viewport: the 3D shows between the side columns, above the flight log
export const VIEWPORT = {x0: 330, x1: 1270, y0: 108, y1: 744};
const CSS = `
#app{font-family:Inter,system-ui,sans-serif;color:${C.ink};-webkit-font-smoothing:antialiased;font-variant-numeric:tabular-nums}
.ui{position:absolute;inset:0;pointer-events:none}
.mo{font-family:'JetBrains Mono',ui-monospace,monospace}
.cp{position:absolute;background:${C.panel};border:1px solid ${C.line};border-radius:6px;box-shadow:0 2px 10px rgba(120,90,50,.07)}
.ph{position:absolute;display:flex;align-items:center;gap:9px;font:700 10.5px 'JetBrains Mono',monospace;letter-spacing:1.8px}
.ph i{display:block;width:3px;height:13px;background:${C.or}}
.pn{position:absolute;font:500 9.5px 'JetBrains Mono',monospace;color:${C.mute};letter-spacing:1px}
.sm{font:500 9px 'JetBrains Mono',monospace;letter-spacing:1.6px;color:${C.mute};text-transform:uppercase;white-space:nowrap}
.v{font:600 11px 'JetBrains Mono',monospace;color:${C.ink};white-space:nowrap}
.bt{position:absolute;height:23px;padding:0 10px;display:flex;align-items:center;justify-content:center;border:1px solid ${C.faint};border-radius:4px;background:#fffdf9;font:700 9.4px 'JetBrains Mono',monospace;letter-spacing:1.3px;color:${C.ink};white-space:nowrap;box-sizing:border-box}
.call{position:absolute;white-space:nowrap;padding:3px 6px 3px 5px;margin:-3px 0 0 -5px;background:rgba(253,251,247,.86);border-radius:3px}
.call b{display:flex;align-items:center;gap:6px;font:700 9.4px 'JetBrains Mono',monospace;letter-spacing:1.3px;color:${C.ink}}
.call b i{display:block;width:6px;height:6px;background:${C.or}}
.call span{display:block;font:500 7.8px 'JetBrains Mono',monospace;letter-spacing:1.2px;color:${C.mute};margin-top:2px}
.chip{position:absolute;height:15px;padding:0 6px;border-radius:3px;font:700 7.6px 'JetBrains Mono',monospace;letter-spacing:1.1px;display:flex;align-items:center;white-space:nowrap}
.cur{position:absolute;left:0;top:0;z-index:50;filter:drop-shadow(0 1px 2px rgba(0,0,0,.3))}
.ring{position:absolute;width:34px;height:34px;margin:-17px 0 0 -17px;border-radius:50%;border:1.5px solid ${C.or};opacity:0;z-index:49}
`;
const el = (h) => {
const d = document.createElement('div');
d.innerHTML = h.trim();
return d.firstElementChild;
};
const SUBS = [
['OPTIC HEAD', '2 × 60 MM DOME · IRIS'],
['LURE ARRAY', '7-LINK STALK · CAGED LAMP'],
['RIBCAGE DRIVE', '2 DRIVE RINGS · 16 PISTONS'],
['PECTORAL FINS', '2 × 10 RAYS · QUICK RELEASE'],
['JAW & FANGS', 'HINGED JAW · 64 GLASS FANGS'],
['HULL', '12 SHIELDS · 2,140 PARTS'],
];
const SERVOS = ['FIN R', 'FIN L', 'TAIL', 'JAW', 'LURE', 'DORSAL'];
// opts (all optional, the first film's console when absent): views / viewLabel / viewsTitle / viewRows for the view
// panel (the second film puts its assemblies there, in two rows), display / displayLabel for the toggles; the panels
// below move down to make room and the subsystem rows close up.
export function createConsole(app, opts = {}) {
const views = opts.views ?? VIEWS;
const viewLabel = opts.viewLabel ?? VIEW_LABEL;
const display = opts.display ?? DISPLAY;
const displayLabel = opts.displayLabel ?? DISPLAY_LABEL;
const viewRows = opts.viewRows ?? 1;
const style = document.createElement('style');
style.textContent = CSS;
document.head.appendChild(style);
const ui = el(`<div class="ui"></div>`);
app.appendChild(ui);
const add = (h) => {
const n = el(h);
ui.appendChild(n);
return n;
};
const panel = (x, y, w, h, title, n) => {
add(`<div class="cp" style="left:${x}px;top:${y}px;width:${w}px;height:${h}px"></div>`);
add(`<div class="ph" style="left:${x + 14}px;top:${y + 13}px"><i></i>${title}</div>`);
add(`<div class="pn" style="right:${1600 - x - w + 14}px;top:${y + 15}px">${n}</div>`);
};
const hr = (x, y, w) => add(`<div style="position:absolute;left:${x}px;top:${y}px;width:${w}px;height:1px;background:${C.line}"></div>`);
const L = {x: 24, w: 290};
const R = {x: 1286, w: 290};
// ------------------------------------------------------------ header: badge, title, the lift bar, the status cells
add(`<div style="position:absolute;left:0;top:0;width:160px;height:88px;background:${C.or}"></div>`);
add(`<svg style="position:absolute;left:20px;top:22px" width="52" height="44" viewBox="0 0 52 44"><g fill="none" stroke="#fff" stroke-width="2.1" stroke-linejoin="round" stroke-linecap="round"><path d="M8 30c4-9 13-13 22-11l9 4-9 3 9 3-9 4c-9 2-18-1-22-3z"/><path d="M8 30L1 24v13z"/><path d="M24 19c-2-7 2-14 10-16 7-1 12 4 11 10"/><circle cx="45" cy="17" r="3.4"/><circle cx="24" cy="26" r="1.6"/></g></svg>`);
add(`<div class="mo" style="position:absolute;left:80px;top:34px;color:#fff;font-size:16px;font-weight:600;letter-spacing:3px">AX-6</div>`);
add(`<div class="sm" style="position:absolute;left:182px;top:20px;letter-spacing:2.4px">ROBOTIC ANGLERFISH · DEEP-WATER SURVEY DRONE</div>`);
add(`<div style="position:absolute;left:181px;top:35px;font-size:33px;font-weight:700;letter-spacing:-.6px;line-height:1">Vesper AX-6 <span style="color:${C.or};font-weight:400">/</span></div>`);
add(`<div class="mo" style="position:absolute;left:182px;top:74px;font-size:11.2px;letter-spacing:2.2px;color:#6d6357">BIOLUMINESCENT LURE PLATFORM / FIELD SIMULATOR</div>`);
add(`<div class="sm" style="position:absolute;left:700px;top:22px">THRUST LOAD</div>`);
const liftPct = add(`<div class="mo" style="position:absolute;right:${1600 - 1040}px;top:21px;font-size:10px;font-weight:700"></div>`);
const liftCells = [];
for (let i = 0; i < 40; i++) liftCells.push(add(`<div style="position:absolute;left:${700 + i * 8.5}px;top:38px;width:6px;height:13px;border-radius:1px;background:${C.track}"></div>`));
add(`<div class="sm" style="position:absolute;left:700px;top:57px;font-size:7.6px">IDLE</div>`);
add(`<div class="sm" style="position:absolute;left:852px;top:57px;font-size:7.6px">CRUISE</div>`);
add(`<div class="sm" style="position:absolute;left:1010px;top:57px;font-size:7.6px">LUNGE</div>`);
const cells = [
['SIM ID', 'AX6-1101'],
['RUNTIME', ''],
['STATUS', ''],
['OPERATOR', 'LAB 4 · M.V.'],
];
const cellV = cells.map(([k, v], i) => {
const x = 1086 + i * 118;
if (i) add(`<div style="position:absolute;left:${x - 12}px;top:20px;width:1px;height:44px;background:${C.faint}"></div>`);
add(`<div class="sm" style="position:absolute;left:${x}px;top:22px">${k}</div>`);
return add(`<div class="mo" style="position:absolute;left:${x}px;top:40px;font-size:12px;font-weight:600;letter-spacing:.4px">${v}</div>`);
});
{
let h = '';
for (let r = 0; r < 2; r++) for (let c = 0; c < 14; c++) h += `<path d="M${c * 25 + 4} ${r * 22}v8M${c * 25} ${r * 22 + 4}h8" stroke="${C.or}" stroke-width="1.1" opacity=".55"/>`;
add(`<svg style="position:absolute;left:640px;top:84px" width="352" height="34">${h}</svg>`);
}
// ------------------------------------------------------------ 01 wing beat
panel(L.x, 108, L.w, 226, 'FIN STROKE', '01');
const fq = add(`<div style="position:absolute;left:38px;top:140px;font-size:34px;font-weight:700;letter-spacing:-1px;line-height:1"></div>`);
add(`<div class="sm" style="position:absolute;left:39px;top:178px">STROKE FREQUENCY</div>`);
const amp = add(`<div style="position:absolute;right:${1600 - 300}px;top:146px;font-size:22px;font-weight:700;line-height:1"></div>`);
add(`<div class="sm" style="position:absolute;right:${1600 - 300}px;top:178px">AMPLITUDE</div>`);
const chart = add(`<svg style="position:absolute;left:38px;top:198px" width="262" height="96"></svg>`);
hr(38, 302, 262);
add(`<div class="sm" style="position:absolute;left:38px;top:312px">PLAYBACK</div>`);
const pb = add(`<div class="v" style="position:absolute;left:104px;top:310px"></div>`);
const shutter = add(`<div class="sm" style="position:absolute;right:${1600 - 300}px;top:312px"></div>`);
// ------------------------------------------------------------ 02 power
panel(L.x, 346, L.w, 148, 'POWER', '02');
const batt = add(`<div style="position:absolute;left:38px;top:378px;font-size:28px;font-weight:700;letter-spacing:-.8px;line-height:1"></div>`);
add(`<div class="sm" style="position:absolute;left:39px;top:410px">BATTERY</div>`);
const battCells = [];
for (let i = 0; i < 10; i++) battCells.push(add(`<div style="position:absolute;left:${150 + i * 15}px;top:383px;width:11px;height:20px;border-radius:2px;background:${C.track}"></div>`));
hr(38, 428, 262);
const pw = [['DRAW', 444], ['CELL', 444], ['MOTOR', 444]].map(([k], i) => {
const x = 38 + i * 90;
add(`<div class="sm" style="position:absolute;left:${x}px;top:440px">${k}</div>`);
return add(`<div class="v" style="position:absolute;left:${x}px;top:458px;font-size:13px"></div>`);
});
// ------------------------------------------------------------ 03 servos: the wings, the fans, the tail, the neck
panel(L.x, 506, L.w, 238, 'SERVOS', '03');
const legState = add(`<div class="chip" style="right:${1600 - 300}px;top:536px"></div>`);
add(`<div class="sm" style="position:absolute;left:38px;top:540px">LOAD PER JOINT · TORQUE</div>`);
const servo = SERVOS.map((n, i) => {
const y = 566 + i * 27;
add(`<div class="mo" style="position:absolute;left:38px;top:${y}px;font-size:10px;font-weight:700">${n}</div>`);
add(`<div style="position:absolute;left:94px;top:${y + 4}px;width:150px;height:6px;background:${C.track};border-radius:3px"></div>`);
const f = add(`<div style="position:absolute;left:94px;top:${y + 4}px;height:6px;background:${C.ink};border-radius:3px"></div>`);
const v = add(`<div class="v" style="position:absolute;right:${1600 - 300}px;top:${y - 1}px"></div>`);
return {f, v};
});
// ------------------------------------------------------------ 04 flight
panel(R.x, 108, R.w, 196, 'DIVE', '04');
const ball = add(`<svg style="position:absolute;left:1300px;top:142px" width="96" height="96"></svg>`);
const fl = [['DEPTH', 0], ['CLIMB', 1], ['PITCH', 2], ['BANK', 3]].map(([k], i) => {
const y = 142 + i * 24;
add(`<div class="sm" style="position:absolute;left:1412px;top:${y + 2}px">${k}</div>`);
return add(`<div class="v" style="position:absolute;right:${1600 - 1562}px;top:${y}px"></div>`);
});
hr(1300, 252, 262);
add(`<div class="sm" style="position:absolute;left:1300px;top:264px">TRIM</div>`);
const hold = add(`<div class="v" style="position:absolute;left:1350px;top:262px"></div>`);
add(`<div class="sm" style="position:absolute;left:1440px;top:264px">SPEED</div>`);
const air = add(`<div class="v" style="position:absolute;right:${1600 - 1562}px;top:262px"></div>`);
// ------------------------------------------------------------ 05 views, 06 display
const btn = {};
const btnRow = (keys, labels, x0, y, wmax = 262, pad = 22) => {
let x = x0;
let yy = y;
for (const k of keys) {
const w = Math.round(labels[k].length * 7.1 + pad);
if (x + w > x0 + wmax) {
x = x0;
yy += 30;
}
btn[k] = add(`<div class="bt" style="left:${x}px;top:${yy}px;width:${w}px">${labels[k]}</div>`);
x += w + 6;
}
};
const viewsH = 50 + 30 * viewRows;
panel(R.x, 316, R.w, viewsH, opts.viewsTitle ?? 'VIEWS', '05');
btnRow(views, viewLabel, 1300, 353, 262, 16);
const dispY = 316 + viewsH + 12;
panel(R.x, dispY, R.w, 110, 'DISPLAY', '06');
btnRow(display, displayLabel, 1300, dispY + 37);
const subY = dispY + 122;
const subStep = Math.min(29, (744 - subY - 40) / 6);
// ------------------------------------------------------------ 07 subsystems
panel(R.x, subY, R.w, 744 - subY, 'SUBSYSTEMS', '07');
const subs = SUBS.map(([n, d], i) => {
const y = subY + 34 + i * subStep;
const bar = add(`<div style="position:absolute;left:1296px;top:${y}px;width:2px;height:22px;background:transparent"></div>`);
add(`<div class="mo" style="position:absolute;left:1304px;top:${y + 1}px;font-size:9px;color:${C.mute}">0${i + 1}</div>`);
const name = add(`<div class="mo" style="position:absolute;left:1328px;top:${y}px;font-size:9.4px;font-weight:700;letter-spacing:1.2px">${n}</div>`);
add(`<div class="sm" style="position:absolute;left:1328px;top:${y + 13}px;font-size:7.6px">${d}</div>`);
const chip = add(`<div class="chip" style="right:${1600 - 1562}px;top:${y + 3}px"></div>`);
return {bar, name, chip};
});
// ------------------------------------------------------------ 08 flight log
panel(330, 760, 940, 98, 'DIVE LOG', '08');
add(`<div class="bt" style="left:346px;top:796px;width:44px;height:44px;border-radius:50%;border:none;background:${C.or};color:#fff;font-size:14px">❚❚</div>`);
const logMode = add(`<div class="mo" style="position:absolute;left:406px;width:780px;top:790px;text-align:center;font-size:9.6px;font-weight:700;letter-spacing:1.6px;color:${C.or}"></div>`);
add(`<div class="sm" style="position:absolute;left:406px;top:791px">DESCENT</div>`);
add(`<div class="sm" style="position:absolute;right:${1600 - 1250}px;top:791px">SURFACE</div>`);
const TLB = {x: 408, w: 840};
add(`<div style="position:absolute;left:${TLB.x}px;top:818px;width:${TLB.w}px;height:3px;background:${C.track};border-radius:2px"></div>`);
const tlFill = add(`<div style="position:absolute;left:${TLB.x}px;top:818px;height:3px;background:${C.or};border-radius:2px"></div>`);
const tlTicks = add(`<div style="position:absolute;inset:0"></div>`);
const tlKnob = add(`<div style="position:absolute;top:812px;width:15px;height:15px;margin-left:-7.5px;border-radius:50%;background:#fff;border:2px solid ${C.or};box-sizing:border-box"></div>`);
const tlTime = add(`<div class="mo" style="position:absolute;left:406px;top:834px;font-size:9.6px;color:${C.mute};letter-spacing:1px"></div>`);
const tlNext = add(`<div class="sm" style="position:absolute;right:${1600 - 1250}px;top:836px"></div>`);
// ------------------------------------------------------------ viewport notes: model, the view, the flight mode
add(`<div class="sm" style="position:absolute;left:346px;top:122px;letter-spacing:2px">MODEL AX-6 · REV A</div>`);
const viewNote = add(`<div class="sm" style="position:absolute;right:${1600 - 1254}px;top:122px;letter-spacing:2px"></div>`);
add(`<svg style="position:absolute;left:346px;top:140px" width="60" height="60"><path d="M0 60V0h60" fill="none" stroke="${C.or}" stroke-width="1" stroke-dasharray="3 3" opacity=".6"/></svg>`);
add(`<svg style="position:absolute;left:1194px;top:680px" width="60" height="60"><path d="M60 0v60H0" fill="none" stroke="${C.or}" stroke-width="1" stroke-dasharray="3 3" opacity=".6"/></svg>`);
add(`<div class="sm" style="position:absolute;left:346px;top:666px">SWIM MODE</div>`);
const mode = add(`<div style="position:absolute;left:345px;top:680px;font-size:30px;font-weight:700;letter-spacing:-.4px;line-height:1;color:${C.or}"></div>`);
const modeSub = add(`<div class="sm" style="position:absolute;left:346px;top:716px"></div>`);
// ------------------------------------------------------------ footer
add(`<div class="sm" style="position:absolute;left:27px;top:878px;letter-spacing:2.2px">FIELD SIMULATOR &nbsp;·&nbsp; PROCEDURAL MODEL &nbsp;·&nbsp; 64 GLASS FANGS · 7-LINK LURE · 2 OPTICS</div>`);
add(`<div class="sm" style="position:absolute;right:28px;top:878px;letter-spacing:2.2px">VESPER MARINE · ABYSS LAB <span style="color:${C.or}">//////</span></div>`);
// ------------------------------------------------------------ labels, the pointer
const callSvg = add(`<svg style="position:absolute;inset:0;overflow:visible" width="1600" height="900"></svg>`);
const callG = add(`<div style="position:absolute;inset:0"></div>`);
const ring = add(`<div class="ring"></div>`);
const cur = add(`<div class="cur"><svg width="22" height="22" viewBox="0 0 34 34"><path d="M4 3 L30 13.5 L17.5 17.5 L13.5 30 Z" fill="#111" stroke="#fff" stroke-width="2.2" stroke-linejoin="round"/></svg></div>`);
const centre = (n) => {
const r = n.getBoundingClientRect();
return [r.left + r.width / 2, r.top + r.height / 2];
};
const spots = Object.fromEntries(Object.entries(btn).map(([k, n]) => [k, centre(n)]));
const pointer = (c) => {
cur.style.display = c.x < 0 ? 'none' : 'block';
cur.style.transform = `translate(${(c.x - 3).toFixed(2)}px, ${(c.y - 2).toFixed(2)}px) scale(${c.press ? 0.88 : 1})`;
ring.style.left = `${c.ringX}px`;
ring.style.top = `${c.ringY}px`;
ring.style.opacity = String(c.ring * 0.85);
ring.style.transform = `scale(${(0.35 + 0.9 * (1 - c.ring)).toFixed(3)})`;
};
const clock = (s) => `${String(Math.floor(s / 60)).padStart(2, '0')}:${String(Math.floor(s) % 60).padStart(2, '0')}`;
const chipStyle = (n, kind, text) => {
const k = {ok: [C.green, '#fff'], warn: [C.or, '#fff'], idle: [C.track, C.mute]}[kind];
n.style.background = k[0];
n.style.color = k[1];
n.textContent = text;
};
let tickKey = '';
return {
spots,
btn,
root: ui,
TLB,
update(s) {
// header
const lift = Math.round(s.lift * 40);
liftCells.forEach((c, i) => (c.style.background = i < lift ? (i > 30 ? C.or : C.ink) : C.track));
liftPct.textContent = `${Math.round(s.lift * 100)}%`;
cellV[1].textContent = `00:00:${String(Math.floor(s.time)).padStart(2, '0')}`;
cellV[2].innerHTML = `<span style="color:${s.statusKind === 'ok' ? C.green : C.or}">●</span> ${s.status}`;
// wing beat: the frequency, the amplitude, the stroke of the near wing (orange) and the far one (grey) over the
// last 1.2 s of playback, with the now marker on the right
fq.innerHTML = `${s.freq.toFixed(2)}<span style="font-size:14px;font-weight:600;color:${C.mute}"> HZ</span>`;
amp.textContent = `±${Math.round(s.amp)}°`;
{
const W = 262;
const H = 96;
const Y = (a) => H / 2 - (a / (s.chartMax ?? 62)) * (H / 2 - 8);
let g = `<line x1="0" x2="${W}" y1="${H / 2}" y2="${H / 2}" stroke="${C.faint}" stroke-width="1"/>`;
for (const a of s.chartTicks ?? [-55, 55]) g += `<line x1="0" x2="${W}" y1="${Y(a)}" y2="${Y(a)}" stroke="${C.line}" stroke-width="1" stroke-dasharray="2 3"/><text x="${W - 2}" y="${Y(a) - 3}" text-anchor="end" font-size="7" fill="${C.mute}" font-family="JetBrains Mono">${a > 0 ? '+' : ''}${a}°</text>`;
const path = (k) => s.stroke.map((p, i) => `${i ? 'L' : 'M'}${((i / (s.stroke.length - 1)) * (W - 10)).toFixed(1)} ${Y(p[k]).toFixed(1)}`).join('');
g += `<path d="${path(1)}" fill="none" stroke="${C.mute}" stroke-width="1" opacity=".7"/><path d="${path(0)}" fill="none" stroke="${C.or}" stroke-width="1.6"/>`;
const last = s.stroke[s.stroke.length - 1];
g += `<line x1="${W - 10}" x2="${W - 10}" y1="4" y2="${H - 4}" stroke="${C.ink}" stroke-width=".8" stroke-dasharray="2 2"/><circle cx="${W - 10}" cy="${Y(last[0]).toFixed(1)}" r="3.4" fill="${C.or}"/>`;
g += `<text x="0" y="${H - 1}" font-size="7" fill="${C.mute}" font-family="JetBrains Mono" letter-spacing="1">${s.chartSpan ?? '−1.2 S'}</text><text x="${W - 14}" y="${H - 1}" text-anchor="end" font-size="7" fill="${C.mute}" font-family="JetBrains Mono" letter-spacing="1">NOW</text>`;
chart.innerHTML = g;
}
pb.textContent = `${s.playback.toFixed(1)}×`;
shutter.textContent = s.shutter ?? (s.blur > 0.5 ? 'SHUTTER 1/60' : 'HI-SPEED 1/2000');
// power
batt.innerHTML = `${Math.round(s.battery * 100)}<span style="font-size:13px;color:${C.mute}">%</span>`;
const bc = Math.round(s.battery * 10);
battCells.forEach((c, i) => (c.style.background = i < bc ? (i < 2 ? C.or : C.green) : C.track));
pw[0].textContent = `${s.power.toFixed(1)} W`;
pw[1].textContent = `${s.volt.toFixed(2)} V`;
pw[2].textContent = `${s.motorT.toFixed(0)} °C`;
// servos
chipStyle(legState, s.legsFree ? 'warn' : 'ok', s.legsFree ? 'DETACHED' : 'HOLDING');
servo.forEach((b, i) => {
const v = s.servos[i];
b.f.style.width = `${(v * 150).toFixed(1)}px`;
const free = s.legFreeEach ? s.legFreeEach[i] : s.legsFree;
b.f.style.background = v > 0.6 ? C.or : C.ink;
b.v.textContent = free ? 'DETACHED' : `${Math.round(v * 100)}%`;
b.v.style.color = free ? C.or : C.ink;
b.v.style.fontSize = free ? '8.6px' : '11px';
});
// flight: the attitude ball (the horizon tilts with roll and slides with pitch) and the numbers
{
const r = 44;
const off = s.pitch * 2.2;
ball.innerHTML = `<defs><clipPath id="bc"><circle cx="48" cy="48" r="${r}"/></clipPath></defs><circle cx="48" cy="48" r="${r}" fill="#fbf8f3" stroke="${C.faint}"/><g clip-path="url(#bc)"><g transform="rotate(${(-s.roll).toFixed(2)} 48 48) translate(0 ${off.toFixed(2)})"><rect x="-20" y="48" width="136" height="70" fill="${C.track}"/><line x1="-20" x2="116" y1="48" y2="48" stroke="${C.ink}" stroke-width="1"/>${[-20, -10, 10, 20].map((p) => `<line x1="${48 - (Math.abs(p) > 10 ? 12 : 7)}" x2="${48 + (Math.abs(p) > 10 ? 12 : 7)}" y1="${48 - p * 2.2}" y2="${48 - p * 2.2}" stroke="${C.mute}" stroke-width=".8"/>`).join('')}</g></g><path d="M26 48h14l4 5 4-5h22" fill="none" stroke="${C.or}" stroke-width="2"/><circle cx="48" cy="48" r="2" fill="${C.or}"/>`;
fl[0].textContent = `${s.depth.toFixed(1)} M`;
fl[1].textContent = `${s.vs >= 0 ? '+' : '−'}${Math.abs(s.vs).toFixed(2)} M/S`;
fl[2].textContent = `${s.pitch >= 0 ? '+' : '−'}${Math.abs(s.pitch).toFixed(2)}°`;
fl[3].textContent = `${s.roll >= 0 ? '+' : '−'}${Math.abs(s.roll).toFixed(2)}°`;
hold.textContent = s.trim ?? 'NEUTRAL';
air.textContent = `${s.airspeed.toFixed(2)} M/S`;
}
// views, display
const onBtn = (k, on) => {
btn[k].style.background = on ? C.or : '#fffdf9';
btn[k].style.color = on ? '#fff' : C.ink;
btn[k].style.borderColor = on ? C.or : C.faint;
};
for (const k of views) onBtn(k, s.view === k);
for (const k of display) onBtn(k, !!s.display[k]);
// subsystems: a status chip each, the row the current view looks at marked
subs.forEach((r, i) => {
const [kind, text] = s.subs[i];
chipStyle(r.chip, kind, text);
r.bar.style.background = s.focus === i ? C.or : 'transparent';
r.name.style.color = s.focus === i ? C.or : C.ink;
});
// flight log: the film's progress, a tick for every press, the mode
const kx = TLB.x + (s.time / s.dur) * TLB.w;
tlFill.style.width = `${(kx - TLB.x).toFixed(1)}px`;
tlKnob.style.left = `${kx.toFixed(1)}px`;
const key = s.events.length;
if (key !== tickKey) {
tickKey = key;
tlTicks.innerHTML = s.events.map((e) => `<div style="position:absolute;left:${(TLB.x + (e / s.dur) * TLB.w - 1).toFixed(1)}px;top:813px;width:2px;height:13px;background:${C.ink};opacity:.35"></div>`).join('');
}
tlTime.textContent = `${clock(s.time)} / ${clock(s.dur)}`;
tlNext.textContent = s.next;
logMode.textContent = s.log;
viewNote.textContent = s.viewNote ?? `VIEW · ${viewLabel[s.view]}${s.display.orbit ? ' · ORBIT' : ''}`;
mode.textContent = s.mode;
modeSub.textContent = s.modeSub;
// labels: an orange square, the name, the note, a thin leader to the part
let lh = '';
let ch = '';
for (const c of s.callouts) {
if (c.o < 0.02 || !c.at) continue;
const [ax, ay] = c.at;
const [lx, ly] = c.label;
const right = lx > ax;
const ex = right ? lx - 6 : lx + c.w + 6;
lh += `<polyline points="${ax.toFixed(1)},${ay.toFixed(1)} ${ex.toFixed(1)},${(ly + 6).toFixed(1)}" fill="none" stroke="${C.or}" stroke-width=".9" opacity="${c.o.toFixed(2)}"/><circle cx="${ax.toFixed(1)}" cy="${ay.toFixed(1)}" r="2.4" fill="${C.or}" opacity="${c.o.toFixed(2)}"/>`;
ch += `<div class="call" style="left:${lx.toFixed(1)}px;top:${(ly - 1).toFixed(1)}px;opacity:${c.o.toFixed(2)}"><b><i></i>${c.name}</b><span>${c.sub}</span></div>`;
}
callSvg.innerHTML = lh;
callG.innerHTML = ch;
pointer(s.cursor);
},
pointer,
};
}
+139
View File
@@ -0,0 +1,139 @@
// The construction drawing around the bee: hairline arcs and dashed circles in a few tilted planes, dots and small
// hollow markers riding on them, short ticks. All in world space round the bee, so a camera orbit gives them depth.
// Lines are fat lines with a width in device pixels; resize() keeps them hairline at any pixel ratio.
import * as THREE from 'three';
import {Line2} from 'three/addons/lines/Line2.js';
import {LineGeometry} from 'three/addons/lines/LineGeometry.js';
import {LineMaterial} from 'three/addons/lines/LineMaterial.js';
import {rng} from '../kit/util.js';
const V3 = THREE.Vector3;
const INK = '#8a8178';
export function buildGuides({centre = [0.05, 0.1, 0], seed = 5} = {}) {
const R = rng(seed);
const group = new THREE.Group();
const lines = [];
const C = new V3(...centre);
// two unit vectors spanning the plane with normal n
const basis = (n) => {
const a = Math.abs(n.y) < 0.9 ? new V3(0, 1, 0) : new V3(1, 0, 0);
const u = new V3().crossVectors(a, n).normalize();
return [u, new V3().crossVectors(n, u)];
};
const circ = (c, r, n, a) => {
const [u, v] = basis(n.clone().normalize());
return c.clone().addScaledVector(u, Math.cos(a) * r).addScaledVector(v, Math.sin(a) * r);
};
const arc = (c, r, n, a0, a1, {dashed = false, width = 1, opacity = 0.5, dash = 0.045} = {}) => {
const N = Math.max(24, Math.round(Math.abs(a1 - a0) * r * 60));
const pts = [];
for (let i = 0; i <= N; i++) {
const p = circ(c, r, n, a0 + ((a1 - a0) * i) / N);
pts.push(p.x, p.y, p.z);
}
const g = new LineGeometry();
g.setPositions(pts);
const m = new LineMaterial({color: INK, linewidth: width, transparent: true, opacity, dashed, dashSize: dash, gapSize: dash * 0.8, depthWrite: false, worldUnits: false});
const l = new Line2(g, m);
l.computeLineDistances();
l.renderOrder = 4;
group.add(l);
lines.push({m, width, opacity});
return l;
};
const seg = (a, b, opts = {}) => {
const g = new LineGeometry();
g.setPositions([a.x, a.y, a.z, b.x, b.y, b.z]);
const m = new LineMaterial({color: INK, linewidth: opts.width ?? 1, transparent: true, opacity: opts.opacity ?? 0.45, dashed: !!opts.dashed, dashSize: 0.04, gapSize: 0.035, depthWrite: false});
const l = new Line2(g, m);
l.computeLineDistances();
l.renderOrder = 4;
group.add(l);
lines.push({m, width: opts.width ?? 1, opacity: opts.opacity ?? 0.45});
};
// the rings: [radius, normal, arcs, dashed, width, opacity]
const RINGS = [
[2.75, new V3(0.35, 0.25, 1), [[0.15, 1.9], [2.4, 3.5], [4.1, 5.6]], false, 1.0, 0.42],
[2.05, new V3(0.1, 1, 0.3), [[0, Math.PI * 2]], true, 1.0, 0.45],
[1.35, new V3(1, 0.15, 0.05), [[0.3, 2.6], [3.3, 5.5]], false, 1.1, 0.5],
[3.45, new V3(0.55, 0.75, 0.35), [[0.6, 2.2], [3.6, 4.6]], false, 0.9, 0.32],
[1.7, new V3(-0.4, 0.3, 1), [[0, Math.PI * 2]], true, 0.9, 0.36],
[2.35, new V3(0.9, -0.2, 0.4), [[1.0, 2.9], [4.2, 5.9]], false, 0.9, 0.34],
];
const onRing = [];
for (const [r, n, arcs, dashed, w, o] of RINGS) {
for (const [a0, a1] of arcs) arc(C, r, n, a0, a1, {dashed, width: w, opacity: o});
onRing.push([r, n, arcs]);
}
// a small ring round the eye and one round the tail, offset from the main centre
arc(new V3(1.2, 0.14, 0.1), 0.62, new V3(0.55, 0.05, 0.85), 0, Math.PI * 2, {dashed: true, width: 0.9, opacity: 0.4, dash: 0.03});
arc(new V3(-1.15, -0.25, 0), 0.75, new V3(-0.9, -0.3, 0.3), 0.4, 4.6, {width: 0.9, opacity: 0.38});
// dots and hollow markers riding on the rings, ticks across them
const dots = [];
const marks = new THREE.Group();
group.add(marks);
const dotGeo = new THREE.SphereGeometry(1, 10, 8);
const dotMat = new THREE.MeshBasicMaterial({color: '#5d5751', transparent: true, opacity: 0.75, depthWrite: false});
const ringGeo = new THREE.RingGeometry(0.62, 1, 28);
const ringMat = new THREE.MeshBasicMaterial({color: '#6e675f', transparent: true, opacity: 0.7, depthWrite: false, side: THREE.DoubleSide});
for (const [r, n, arcs] of onRing) {
for (const [a0, a1] of arcs) {
const k = Math.max(1, Math.round((a1 - a0) * 1.6));
for (let i = 0; i < k; i++) {
const a = a0 + (a1 - a0) * R();
const p = circ(C, r, n, a);
if (R() < 0.6) {
const d = new THREE.Mesh(dotGeo, dotMat);
d.position.copy(p);
d.scale.setScalar(0.009 + R() * 0.012);
d.renderOrder = 5;
group.add(d);
dots.push(d);
} else {
const m = new THREE.Mesh(ringGeo, ringMat);
m.position.copy(p);
m.scale.setScalar(0.022 + R() * 0.016);
m.renderOrder = 5;
marks.add(m);
}
// a short tick across the ring at some of them
if (R() < 0.35) {
const t = circ(C, r * 1.04, n, a);
const b = circ(C, r * 0.96, n, a);
seg(t, b, {width: 1, opacity: 0.5});
}
}
}
}
// a few straight dashed leaders out from the body
for (const [a, b] of [
[new V3(0.9, 0.55, 0.2), new V3(1.9, 1.6, 0.4)],
[new V3(-0.6, -0.4, 0.3), new V3(-1.9, -1.1, 0.9)],
[new V3(0.2, 0.5, -0.3), new V3(0.6, 1.9, -0.8)],
]) {
seg(a, b, {dashed: true, width: 0.9, opacity: 0.38});
}
return {
group,
resize(w, h, pr) {
for (const L of lines) {
L.m.resolution.set(w, h);
L.m.linewidth = L.width * pr;
}
},
// ops.guides 0..1 fades the whole drawing
update(camera, ops = {}) {
const k = ops.guides ?? 1;
group.userData.show = k > 0.001;
group.visible = group.userData.show;
for (const L of lines) L.m.opacity = Math.min(1, L.opacity * 1.1 * k);
dotMat.opacity = 0.75 * k;
ringMat.opacity = 0.7 * k;
for (const m of marks.children) m.quaternion.copy(camera.quaternion);
},
};
}
+416
View File
@@ -0,0 +1,416 @@
// The robotic anglerfish's kitbash shop, copied from the bee's (robobee-shared/parts.js): the materials (gloss white
// shell, orange accent, graphite and black mechanism, steel, the lens, clear glass and the fin membrane) and the
// geometry every part is cut from. Added here: taperTube (from the scorpion) and plate, a thick panel cut out of any
// parametric surface, which the skull and the jaws are made of. Everything is
// built along +x and placed by the caller: sweepX turns a closed (x, r) profile round the x axis, whole or as an arc
// with capped ends, which gives rings, collars, domes, shell plates and capsules from one function; gearGeo cuts a
// toothed wheel with a bore; tube runs a cable along points.
import * as THREE from 'three';
import {RoundedBoxGeometry} from 'three/addons/geometries/RoundedBoxGeometry.js';
import {mergeGeometries} from 'three/addons/utils/BufferGeometryUtils.js';
export const V3 = THREE.Vector3;
export const D2R = Math.PI / 180;
export const PAL = {white: '#f4f2ee', orange: '#ff5a1f', graphite: '#2f3238', black: '#111214', steel: '#cdd1d6'};
export function makeMaterials() {
const phys = (o) => new THREE.MeshPhysicalMaterial(o);
const std = (o) => new THREE.MeshStandardMaterial(o);
return {
// the white plastic: a soft base under a hard clear coat, so the softboxes sit on it as crisp bars
shell: phys({color: PAL.white, roughness: 0.34, metalness: 0, clearcoat: 1, clearcoatRoughness: 0.05}),
// inside faces of the shells, a shade darker and matte
shellIn: phys({color: '#dedad4', roughness: 0.6, metalness: 0, clearcoat: 0.2, clearcoatRoughness: 0.4, side: THREE.DoubleSide}),
orange: phys({color: PAL.orange, roughness: 0.3, metalness: 0, clearcoat: 1, clearcoatRoughness: 0.08}),
// the orange panel at a wing tip: a film on the membrane, both faces, pulled forward so it never fights it
orangeFilm: phys({color: PAL.orange, roughness: 0.32, metalness: 0, clearcoat: 1, clearcoatRoughness: 0.08, side: THREE.DoubleSide, polygonOffset: true, polygonOffsetFactor: -2, polygonOffsetUnits: -2}),
graphite: std({color: PAL.graphite, roughness: 0.36, metalness: 0.72}),
gunmetal: std({color: '#555a62', roughness: 0.28, metalness: 0.9}),
black: phys({color: PAL.black, roughness: 0.3, metalness: 0.15, clearcoat: 0.8, clearcoatRoughness: 0.12}),
rubber: std({color: '#1b1c1f', roughness: 0.7, metalness: 0}),
steel: std({color: PAL.steel, roughness: 0.2, metalness: 1}),
// the camera eye: a deep black inner element under a dark glass dome; its colour darkens only what shows
// through it, the highlights stay at full strength
lens: phys({color: '#020203', roughness: 0.05, metalness: 0, clearcoat: 1, clearcoatRoughness: 0.02, envMapIntensity: 1.4}),
lensGlass: phys({color: '#6f7277', roughness: 0, metalness: 0, transmission: 1, thickness: 0, ior: 1.5, clearcoat: 1, clearcoatRoughness: 0, specularIntensity: 1, envMapIntensity: 2.4}),
amber: std({color: '#000000', emissive: '#ffa040', emissiveIntensity: 4.5}),
// circuit boards in the thorax: a dark green-black laminate
pcb: std({color: '#1b241f', roughness: 0.55, metalness: 0.1}),
// the clear abdomen window: real transmission, so the mechanism inside refracts a touch
glass: phys({color: '#ffffff', roughness: 0.0, metalness: 0, transmission: 1, thickness: 0, ior: 1.3, specularIntensity: 0.6, clearcoat: 0.5, clearcoatRoughness: 0.02}),
// the wing film: a faint grey-white sheet; the veins and the rim carry the read
membrane: phys({color: '#eef0f2', roughness: 0.38, metalness: 0, transparent: true, opacity: 0.3, depthWrite: false, side: THREE.DoubleSide, clearcoat: 1, clearcoatRoughness: 0.04, iridescence: 0.35, iridescenceIOR: 1.3}),
// the wing rim: a pale clear-ish tube
rim: phys({color: '#e4e7ea', roughness: 0.12, metalness: 0, clearcoat: 1, clearcoatRoughness: 0.04, transparent: true, opacity: 0.55, depthWrite: false}),
vein: std({color: '#4a4d53', roughness: 0.5, metalness: 0.2, transparent: true, opacity: 0.72}),
veinCore: std({color: '#5a5d63', roughness: 0.5, metalness: 0.2}),
led: std({color: '#000000', emissive: PAL.orange, emissiveIntensity: 1.4}),
};
}
// ------------------------------------------------------------ sweepX: a closed (x, r) profile turned round the x axis
// profile: [[x, r], ...] closed loop, either winding. a0..a1: the arc, angle 0 at +y, 90° at +z. Profile corners
// sharper than `smooth` degrees keep a hard edge; softer ones are shaded smooth. A partial arc gets capped ends.
export function sweepX(profile, {a0 = 0, a1 = Math.PI * 2, segs = 64, smooth = 32} = {}) {
let P = profile.map(([x, r]) => [x, Math.max(0, r)]);
let area = 0;
for (let i = 0; i < P.length; i++) {
const [x0, r0] = P[i];
const [x1, r1] = P[(i + 1) % P.length];
area += x0 * r1 - x1 * r0;
}
if (area < 0) P = P.reverse();
const n = P.length;
// outward edge normals in the (x, r) plane
const EN = [];
for (let i = 0; i < n; i++) {
const [x0, r0] = P[i];
const [x1, r1] = P[(i + 1) % n];
const l = Math.hypot(x1 - x0, r1 - r0) || 1;
EN.push([(r1 - r0) / l, -(x1 - x0) / l]);
}
const cosS = Math.cos(smooth * D2R);
const vN = (i, e) => {
// normal at vertex i as seen from edge e (e is i-1 or i)
const other = e === i ? (i - 1 + n) % n : i;
const a = EN[e];
const b = EN[other];
if (a[0] * b[0] + a[1] * b[1] < cosS) return a;
const x = a[0] + b[0];
const y = a[1] + b[1];
const l = Math.hypot(x, y) || 1;
return [x / l, y / l];
};
const full = Math.abs(a1 - a0) >= Math.PI * 2 - 1e-6;
const pos = [];
const nor = [];
const idx = [];
const cs = [];
for (let j = 0; j <= segs; j++) {
const th = a0 + ((a1 - a0) * j) / segs;
cs.push([Math.cos(th), Math.sin(th)]);
}
for (let e = 0; e < n; e++) {
const i0 = e;
const i1 = (e + 1) % n;
const [x0, r0] = P[i0];
const [x1, r1] = P[i1];
if (Math.hypot(x1 - x0, r1 - r0) < 1e-9) continue;
const n0 = vN(i0, e);
const n1 = vN(i1, e);
const base = pos.length / 3;
for (let j = 0; j <= segs; j++) {
const [c, s] = cs[j];
pos.push(x0, r0 * c, r0 * s, x1, r1 * c, r1 * s);
nor.push(n0[0], n0[1] * c, n0[1] * s, n1[0], n1[1] * c, n1[1] * s);
}
for (let j = 0; j < segs; j++) {
const a = base + j * 2;
const b = a + 1;
const c = a + 3;
const d = a + 2;
idx.push(a, b, c, a, c, d);
}
}
if (!full) {
const tri = THREE.ShapeUtils.triangulateShape(
P.map(([x, r]) => new THREE.Vector2(x, r)),
[],
);
for (const [th, flip] of [
[a0, true],
[a1, false],
]) {
const c = Math.cos(th);
const s = Math.sin(th);
// the cap's normal: -d/dθ at a0, +d/dθ at a1
const nx = 0;
const ny = flip ? s : -s;
const nz = flip ? -c : c;
const base = pos.length / 3;
for (const [x, r] of P) {
pos.push(x, r * c, r * s);
nor.push(nx, ny, nz);
}
for (const t of tri) {
if (flip) idx.push(base + t[0], base + t[2], base + t[1]);
else idx.push(base + t[0], base + t[1], base + t[2]);
}
}
}
const g = new THREE.BufferGeometry();
g.setAttribute('position', new THREE.Float32BufferAttribute(pos, 3));
g.setAttribute('normal', new THREE.Float32BufferAttribute(nor, 3));
g.setIndex(idx);
return g;
}
// a rounded rectangle profile for a ring: x0..x1 wide, r0..r1 deep, corners rounded by `round`
export function ringProfile(x0, x1, r0, r1, round = 0.01, steps = 3) {
const rr = Math.min(round, (x1 - x0) / 2.01, (r1 - r0) / 2.01);
const pts = [];
const corner = (cx, cr, a0) => {
for (let k = 0; k <= steps; k++) {
const a = a0 + (k / steps) * (Math.PI / 2);
pts.push([cx + Math.cos(a) * rr, cr + Math.sin(a) * rr]);
}
};
corner(x1 - rr, r0 + rr, -Math.PI / 2);
corner(x1 - rr, r1 - rr, 0);
corner(x0 + rr, r1 - rr, Math.PI / 2);
corner(x0 + rr, r0 + rr, Math.PI);
return pts;
}
export const ring = (x0, x1, r0, r1, round, opts) => sweepX(ringProfile(x0, x1, r0, r1, round), opts);
// a thick spherical shell from polar angle p0 to p1 (0 = +x pole), outer radius R, wall t; the rims stay sharp so
// the clear coat draws a crisp line along them
export function domeProfile(R, t, p0, p1, steps = 24) {
const out = [];
const inn = [];
for (let k = 0; k <= steps; k++) {
const p = p0 + ((p1 - p0) * k) / steps;
out.push([R * Math.cos(p), R * Math.sin(p)]);
inn.push([(R - t) * Math.cos(p), (R - t) * Math.sin(p)]);
}
return [...out, ...inn.reverse()];
}
export const dome = (R, t, p0, p1, opts) => sweepX(domeProfile(R, t, p0, p1), opts);
// a solid of revolution from a radius function: r(u) for u in 0..1 along x0..x1, closed to the axis at both ends
export function solidProfile(x0, x1, rFn, steps = 32) {
const pts = [[x0, 0]];
for (let k = 0; k <= steps; k++) {
const u = k / steps;
pts.push([x0 + (x1 - x0) * u, rFn(u)]);
}
pts.push([x1, 0]);
return pts;
}
export const solid = (x0, x1, rFn, opts, steps) => sweepX(solidProfile(x0, x1, rFn, steps), opts);
// a capsule-like rounded radius: r0 at the start, r1 at the end, ends rounded over `cap` of the length
export const capsuleR = (r0, r1, cap = 0.12) => (u) => {
const r = r0 + (r1 - r0) * u;
const e = Math.min(u, 1 - u) / cap;
return e >= 1 ? r : r * Math.sqrt(Math.max(0, 1 - (1 - e) * (1 - e)));
};
// ------------------------------------------------------------ gears, boxes, tubes
// a spur gear around +z: `teeth` teeth between rRoot and rOut, `width` thick, a bore of holeR, lightening holes
export function gearGeo(teeth, rOut, rRoot, width, holeR = 0, spokes = 0) {
const sh = new THREE.Shape();
for (let i = 0; i < teeth; i++) {
const a0 = (i / teeth) * Math.PI * 2;
const da = (Math.PI * 2) / teeth;
const pts = [
[rRoot, a0],
[rRoot, a0 + da * 0.18],
[rOut, a0 + da * 0.32],
[rOut, a0 + da * 0.6],
[rRoot, a0 + da * 0.74],
];
pts.forEach(([r, a], k) => (i === 0 && k === 0 ? sh.moveTo(r * Math.cos(a), r * Math.sin(a)) : sh.lineTo(r * Math.cos(a), r * Math.sin(a))));
}
sh.closePath();
if (holeR) {
const h = new THREE.Path();
h.absarc(0, 0, holeR, 0, Math.PI * 2, true);
sh.holes.push(h);
}
// round lightening holes between the bore and the rim
if (spokes) {
const rc = (holeR + rRoot) / 2;
const rh = Math.min((rRoot - holeR) * 0.3, (Math.PI * rc) / spokes * 0.55);
for (let k = 0; k < spokes; k++) {
const a = (k / spokes) * Math.PI * 2;
const h = new THREE.Path();
h.absarc(Math.cos(a) * rc, Math.sin(a) * rc, rh, 0, Math.PI * 2, true);
sh.holes.push(h);
}
}
const bev = Math.min(width * 0.18, (rOut - rRoot) * 0.3);
const g = new THREE.ExtrudeGeometry(sh, {depth: width - bev * 2, bevelEnabled: true, bevelThickness: bev, bevelSize: bev * 0.8, bevelSegments: 1, curveSegments: 10});
g.translate(0, 0, -(width - bev * 2) / 2);
return g;
}
// the same gear with its axis along +x
export const gearX = (...a) => gearGeo(...a).rotateY(Math.PI / 2);
export const rbox = (w, h, d, r = 0.01) => new RoundedBoxGeometry(w, h, d, 3, Math.min(r, w / 2.01, h / 2.01, d / 2.01));
export const cylX = (r0, r1, len, seg = 32) => new THREE.CylinderGeometry(r1, r0, len, seg).rotateZ(-Math.PI / 2);
export const cylZ = (r0, r1, len, seg = 32) => new THREE.CylinderGeometry(r1, r0, len, seg).rotateX(Math.PI / 2);
/** A cable or rod through points (Vector3 or arrays), radius r. */
export function tube(points, r, tubular = 64, radial = 10, closed = false) {
const pts = points.map((p) => (p.isVector3 ? p : new V3(...p)));
return new THREE.TubeGeometry(new THREE.CatmullRomCurve3(pts, closed, 'catmullrom', 0.5), tubular, r, radial, closed);
}
/** A coil spring along +x: radius R, wire r, `turns` over len. */
export function coil(R, r, turns, len, seg = 240) {
const pts = [];
for (let i = 0; i <= seg; i++) {
const u = i / seg;
const a = u * turns * Math.PI * 2;
pts.push(new V3(u * len, Math.cos(a) * R, Math.sin(a) * R));
}
return new THREE.TubeGeometry(new THREE.CatmullRomCurve3(pts), seg, r, 8, false);
}
export const merge = (geos) => mergeGeometries(geos.map((g) => (g.index ? g.toNonIndexed() : g)).map((g) => {
// mergeGeometries wants identical attribute sets: keep position and normal only
const o = new THREE.BufferGeometry();
o.setAttribute('position', g.attributes.position);
o.setAttribute('normal', g.attributes.normal);
return o;
}));
/** Put a mesh of geo/mat at (x, y, z) into parent; returns it. Every mesh casts and takes shadows. */
export function put(parent, geo, mat, x = 0, y = 0, z = 0) {
const m = new THREE.Mesh(geo, mat);
m.position.set(x, y, z);
m.castShadow = true;
m.receiveShadow = true;
parent.add(m);
return m;
}
/** Rotate an object so its local +x points along dir. */
export function aimX(obj, dir) {
obj.quaternion.setFromUnitVectors(new V3(1, 0, 0), dir.clone().normalize());
return obj;
}
/** Instances of one geometry at a list of matrices (casts and takes shadows). */
export function instances(parent, geo, mat, mats) {
const im = new THREE.InstancedMesh(geo, mat, mats.length);
mats.forEach((m, i) => im.setMatrixAt(i, m));
im.castShadow = true;
im.receiveShadow = true;
parent.add(im);
return im;
}
/** A tube through points whose radius runs from r0 to r1 along its length (a fang, a fin ray, a tapered link). */
export function taperTube(points, r0, r1, tubular = 48, radial = 14, pow = 1) {
const pts = points.map((p) => (p.isVector3 ? p : new V3(...p)));
const curve = new THREE.CatmullRomCurve3(pts, false, 'catmullrom', 0.5);
const g = new THREE.TubeGeometry(curve, tubular, 1, radial, false);
const pos = g.attributes.position;
const nor = g.attributes.normal;
const c = new V3();
for (let i = 0; i <= tubular; i++) {
const u = i / tubular;
const r = r1 + (r0 - r1) * Math.pow(1 - u, pow);
curve.getPointAt(u, c);
for (let j = 0; j <= radial; j++) {
const k = i * (radial + 1) + j;
pos.setXYZ(k, c.x + nor.getX(k) * r, c.y + nor.getY(k) * r, c.z + nor.getZ(k) * r);
}
}
pos.needsUpdate = true;
g.computeVertexNormals();
return g;
}
/**
* A thick panel cut from a parametric surface. S(u, v) -> Vector3 is the outer face over [u0, u1] x [v0, v1]; nrm(p)
* gives the outward normal there (or null: taken from the surface's partials). t: the wall, nu x nv: the grid. The
* outer and inner faces are smooth; the four edge walls are flat, and the outer face's border row leans its normal
* toward the wall (bevel), so the clear coat draws a crisp line along every edge of the panel.
*/
export function plate(S, [u0, u1], [v0, v1], t, nu, nv, nrm = null, bevel = 0.55) {
const P = [];
const N = [];
const e = 1e-4;
for (let i = 0; i <= nu; i++) {
for (let j = 0; j <= nv; j++) {
const u = u0 + ((u1 - u0) * i) / nu;
const v = v0 + ((v1 - v0) * j) / nv;
const p = S(u, v);
let n = nrm ? nrm(p) : null;
if (!n) {
const du = S(u + e, v).sub(S(u - e, v));
const dv = S(u, v + e).sub(S(u, v - e));
n = new V3().crossVectors(du, dv).normalize();
}
P.push(p);
N.push(n);
}
}
const id = (i, j) => i * (nv + 1) + j;
// the orientation: the grid's own winding against the outward normal, at the middle of the panel
const mi = Math.max(0, Math.floor(nu / 2) - (nu > 1 ? 0 : 0));
const mj = Math.floor(nv / 2);
const ia = Math.min(mi, nu - 1);
const ja = Math.min(mj, nv - 1);
const w = new V3().crossVectors(P[id(ia + 1, ja)].clone().sub(P[id(ia, ja)]), P[id(ia, ja + 1)].clone().sub(P[id(ia, ja)]));
const ccw = w.dot(N[id(ia, ja)]) > 0;
// bevel: the border row of the outer face leans toward the wall
const NO = N.map((n) => n.clone());
const lean = (i, j, d) => NO[id(i, j)].addScaledVector(d.normalize(), bevel).normalize();
if (bevel > 0) {
for (let i = 0; i <= nu; i++) {
lean(i, 0, P[id(i, 0)].clone().sub(P[id(i, 1)]));
lean(i, nv, P[id(i, nv)].clone().sub(P[id(i, nv - 1)]));
}
for (let j = 0; j <= nv; j++) {
lean(0, j, P[id(0, j)].clone().sub(P[id(1, j)]));
lean(nu, j, P[id(nu, j)].clone().sub(P[id(nu - 1, j)]));
}
}
const pos = [];
const nor = [];
const idx = [];
const V = (nGrid) => (nGrid + 1) * (nv + 1);
// outer
for (let k = 0; k < P.length; k++) {
pos.push(P[k].x, P[k].y, P[k].z);
nor.push(NO[k].x, NO[k].y, NO[k].z);
}
// inner
for (let k = 0; k < P.length; k++) {
pos.push(P[k].x - N[k].x * t, P[k].y - N[k].y * t, P[k].z - N[k].z * t);
nor.push(-N[k].x, -N[k].y, -N[k].z);
}
const off = V(nu);
for (let i = 0; i < nu; i++) {
for (let j = 0; j < nv; j++) {
const a = id(i, j);
const b = id(i + 1, j);
const c = id(i, j + 1);
const d = id(i + 1, j + 1);
if (ccw) idx.push(a, b, c, c, b, d, off + a, off + c, off + b, off + c, off + d, off + b);
else idx.push(a, c, b, c, d, b, off + a, off + b, off + c, off + c, off + b, off + d);
}
}
const face = new THREE.BufferGeometry();
face.setAttribute('position', new THREE.Float32BufferAttribute(pos, 3));
face.setAttribute('normal', new THREE.Float32BufferAttribute(nor, 3));
face.setIndex(idx);
// the walls: a strip between the outer border and the inner one, flat shaded, facing away from the panel
const wp = [];
const edge = (list, outDir) => {
for (let k = 0; k < list.length - 1; k++) {
const [ka, kb] = [list[k], list[k + 1]];
const oa = P[ka];
const ob = P[kb];
if (oa.distanceTo(ob) < 1e-7) continue;
const ia2 = oa.clone().addScaledVector(N[ka], -t);
const ib2 = ob.clone().addScaledVector(N[kb], -t);
const fn = new V3().crossVectors(ob.clone().sub(oa), ia2.clone().sub(oa));
const tri = fn.dot(outDir(k)) > 0 ? [oa, ob, ia2, ob, ib2, ia2] : [oa, ia2, ob, ob, ia2, ib2];
for (const p of tri) wp.push(p.x, p.y, p.z);
}
};
const row = (j) => [...Array(nu + 1).keys()].map((i) => id(i, j));
const col = (i) => [...Array(nv + 1).keys()].map((j) => id(i, j));
edge(row(0), (k) => P[id(k, 0)].clone().sub(P[id(k, 1)]));
edge(row(nv), (k) => P[id(k, nv)].clone().sub(P[id(k, nv - 1)]));
edge(col(0), (k) => P[id(0, k)].clone().sub(P[id(1, k)]));
edge(col(nu), (k) => P[id(nu, k)].clone().sub(P[id(nu - 1, k)]));
const walls = new THREE.BufferGeometry();
walls.setAttribute('position', new THREE.Float32BufferAttribute(wp, 3));
walls.computeVertexNormals();
return wp.length ? merge([face, walls]) : face;
}
File diff suppressed because it is too large Load Diff
+104
View File
@@ -0,0 +1,104 @@
"""Score for the VESPER AX-6 film cut 1:1 on the bee's (entry roboangler-film, tour_bee.js), mixed like the
hummingbird's (robohum-shared/score_bee.py): a bed in D minor (Dm9, Bbmaj7, Gm9, A7sus at 92 bpm: e-piano, bass, soft
drums and a pad on the same changes) at one level the whole way, a quiet click on every button press, and for every act
short quiet accents on its own moves: a slow wash for the swim-in and a snap as the jaw shuts at its end, thread ticks
as the lens rings unscrew and screw back, a swish as the fin leaves its root, air through its turn and a snap as it
seats, a servo tick per lure link, a run of glass ticks as the cage blooms and a soft rising tone for the flare, a
hinge click per rib shield and servo blips as the drive rings slide out, a drop and a run of glass ticks along the fang
rows and a snap as the jaw seats, a whoosh into the explode and three clicks as the fish seats again, a rising air on
the wind-up and a snap and a rush for the lunge. No drones.
python run_sfx.py sims/piranha-shared/score.py
Every cue comes from the script in roboangler-film/timeline.json, with the offsets inside each act taken from
tour_bee.js (the bee's ACT clocks, WING_FLIP, CAGE, FLARE, the snap at 2.3 s, the explode out 0.2-1.8 s and home
0-1.0 s, the lunge 1.0 s after HERO).
"""
import os
from sfx.score_kit import airy, bed, chords, hz, thud # noqa: E402
from sfx.synth import blip, click, envelope, pad # noqa: E402
# TL / OUT in the environment score another cut of the film (roboangler-cut) without touching this one
TIMELINE = os.environ.get("TL", "../piranha-film/timeline.json")
OUT = os.environ.get("OUT", os.path.join(os.environ.get("CUTAWAY_OUT", "cutaway-out"), "piranha-score.wav"))
TARGET_LUFS = -14.0
SEED = 41
CHORDS = chords("Dm9:D3 F3 A3 C4 E4/D2", "Bbmaj7:Bb2 D3 F3 A3 D4/Bb1", "Gm9:G2 Bb2 D3 F3 A3/G1", "A7sus:A2 D3 E3 G3 C4/A1")
MOTIF = [(0.5, hz("A5")), (1.5, hz("F5")), (2.5, hz("E5"))]
SNAP_IN = 2.3
DEP = 1.0
def snap(mix, t, level=0.06, pan=0.0):
"""The jaw shutting: a short click on a soft low knock."""
mix.put(t, click(1500, 0.03), level, pan=pan)
mix.put(t, thud(110, 0.06, 0.25), level * 0.5, pan=pan)
def score(mix, tl):
dur = tl["duration"]
left, right, low, drums = bed(dur, 92, CHORDS, MOTIF, motif_voice="blip", kicks=(0, 2.5), snares=(1, 3), hats=8, swing=0.08, keys_vel=0.75, keys_lp=3600)
mix.put_stereo(0, left, right, 0.13)
mix.put(0, low, 0.13)
mix.put(0, drums, 0.05)
bar = 4 * 60 / 92
changes = [(0.12 + b * bar, [f for f in CHORDS[b % len(CHORDS)][0][:4]]) for b in range(int(dur / bar) + 1)]
pl, pr = pad(dur, changes, volume=envelope([(0, 0), (1.0, 1), (dur - 1.6, 1), (dur, 0)]), detune=0.8, tremolo=0.18, xfade=0.5)
mix.put_stereo(0, pl, pr, 0.07)
# the swim-in and the snap at its end
mix.put(0.0, airy(2.4, 400, 1200, 0.6), 0.02, pan=-0.3)
snap(mix, SNAP_IN + 0.12, 0.05, pan=0.2)
for e in tl["script"]:
t, act = e["t"], e["act"]
mix.put(t, click(2400, 0.025), 0.055, pan=0.45)
if act == "optics":
mix.put(t + 0.35, airy(0.6, 1200, 2600, 0.5), 0.012, pan=-0.15)
for i, dt in enumerate((0.45, 0.62, 0.79, 0.96, 1.13)):
mix.put(t + dt, click(3200 - 180 * i, 0.018), 0.033, pan=-0.1)
for i, dt in enumerate((2.2, 2.34, 2.48, 2.6)):
mix.put(t + dt, click(2500 + 180 * i, 0.018), 0.03, pan=-0.1)
elif act == "wing":
mix.put(t + 0.45, airy(0.8, 600, 2000, 0.6), 0.024, pan=-0.3)
mix.put(t + 0.9, airy(1.4, 800, 1400, 0.5), 0.016, pan=-0.2)
mix.put(t + 2.35, airy(0.35, 1800, 800, 0.5), 0.012, pan=-0.3)
mix.put(t + 2.68, click(1800, 0.03), 0.06, pan=-0.2)
elif act == "leg":
for k in range(7):
mix.put(t + 0.35 + 0.07 * k, click(2800 + 90 * k, 0.016), 0.028, pan=0.3)
for j in range(12):
mix.put(t + 0.78 + 0.05 * (j % 4) + 0.012 * j, click(3600 + 60 * j, 0.012), 0.018, pan=0.35)
mix.put(t + 1.05, blip(hz("D6"), 0.6, 0.25), 0.014, pan=0.35)
mix.put(t + 1.05, airy(0.8, 900, 2400, 0.5), 0.012, pan=0.35)
for k in range(4):
mix.put(t + 2.15 + 0.09 * k, click(2600 - 120 * k, 0.016), 0.026, pan=0.3)
mix.put(t + 2.55, click(1900, 0.03), 0.05, pan=0.3)
elif act == "thorax":
for k in range(5):
mix.put(t + 0.3 + 0.077 * k, click(2300 - 90 * k, 0.022), 0.034, pan=0.1)
for i, dt in enumerate((0.6, 0.85, 1.1)):
mix.put(t + dt, blip(hz("A5") * 2 ** (i / 6), 0.18, 0.06), 0.016)
mix.put(t + 2.1, airy(0.4, 1600, 800, 0.5), 0.011)
mix.put(t + 2.6, click(2100, 0.03), 0.055)
elif act == "abdomen":
mix.put(t + 0.3, airy(0.7, 1400, 500, 0.6), 0.02, pan=0.15)
for j in range(12):
mix.put(t + 0.38 + 0.045 * j, click(3300 + 70 * j, 0.012), 0.02, pan=0.1 + 0.03 * j)
mix.put(t + 2.0, airy(0.4, 600, 1600, 0.5), 0.012, pan=0.15)
snap(mix, t + 2.42, 0.06, pan=0.15)
elif act == "exploded":
mix.put(t + 0.2, airy(1.4, 450, 2400, 0.7), 0.032, pan=-0.15)
mix.put(t + 0.25, blip(hz("D6"), 0.3, 0.1), 0.025)
elif act == "assemble":
mix.put(t, airy(1.0, 2200, 600, 0.5), 0.02, pan=0.15)
for i, dt in enumerate((0.6, 0.8, 1.0)):
mix.put(t + dt, click(2000 + 300 * i, 0.03), 0.05, pan=-0.3 + 0.3 * i)
mix.put(t + 0.9, airy(0.6, 400, 1300, 0.6), 0.016)
elif act == "hero":
mix.put(t + 0.1, airy(0.9, 500, 1500, 0.5), 0.016, pan=0.2)
snap(mix, t + DEP + 0.12, 0.065, pan=0.3)
mix.put(t + DEP, airy(2.2, 450, 2600, 0.7), 0.032, pan=0.45)
+129
View File
@@ -0,0 +1,129 @@
// SERRASAL PX-7, the robotic piranha's film on the green page (entry piranha-film), made 2026-11-06: the approved
// angler film's tour (tour_bee.js, the cut's beats as the hammerhead ran them) with the piranha's body (piranha.js,
// round 3 of its still). The beats: the eye, the tail stalk telescoping out, the glass flank opening over its gears, the
// jaw dropping with its glass fangs, the explode on a turntable and the lunge at the lens. The scene is mirrored across
// x (the fish and every camera, not the lights or the page) as its still was shot, head on the left, near side to the
// key. Green look and page from ../green; TL.film plays the scene's timeline faster for a demo.
import * as THREE from 'three';
import {runSim} from '../kit/runtime.js';
import {createConsole} from '../green/console.js';
import {makeCursor, makeLabels, nice, ORANGE_TO, PAPER_GREEN, retint, SHIFT} from '../green/look.js';
import {PAL} from './parts.js';
import {buildPiranha, FLOOR_Y} from './piranha.js';
import {createStage, PAPER} from './stage.js';
import {makeBeeTour} from './tour_bee.js';
const D2R = Math.PI / 180;
Object.assign(PAL, {orange: ORANGE_TO});
Object.assign(PAPER, PAPER_GREEN);
const ACTS = [['optics', 'Eye'], ['wing', 'Fin'], ['leg', 'Tail'], ['thorax', 'Glass flank'], ['abdomen', 'Jaw'], ['exploded', 'Teardown'], ['hero', 'Release']];
const PAGE = {
name: 'Serrasal',
code: 'PX-7',
title: 'Robotic Piranha, Taken Apart',
date: '2026-11-6',
sub: {
overview: ['2 rows of glass fangs', 'Glass flank, 2 drive gears'],
optics: ['Lens under the brow', 'Iris: 10 blades'],
wing: ['Pectoral fin, frosted', 'Root: pivot drum'],
leg: ['Tail stalk, 4 segments', 'Telescopes on servos'],
thorax: ['Glass barrel, 2 big gears', '2 lit coils'],
abdomen: ['Jaw drops off the hinge', 'Glass fangs fly out'],
exploded: ['Every part apart', 'Turntable 330°'],
hero: ['Tail to full stroke', 'Lunge at the lens'],
},
cards: [{k: 'Tail beat', kind: 'wave', unit: 'Hz'}, {k: 'Thrust', kind: 'bar', unit: '%'}, {k: 'Servo load', kind: 'bars', n: 6}, {k: 'Battery', kind: 'bar', unit: '%'}],
};
const STATUS = {BANKING: 'Banking in', CRUISE: 'Cruising', 'OPTICS OPEN': 'Eye open', 'FIN OFF': 'Fin off', 'TAIL OUT': 'Tail out', 'FLANK OPEN': 'Flank open', 'JAW DROPPED': 'Jaw dropped', TEARDOWN: 'Teardown', REASSEMBLY: 'Reassembly', 'WIND-UP': 'Winding up', LUNGE: 'Lunging'};
export function makePiranhaGreen(TL) {
const FILM = TL.film ?? TL.duration;
// the angler's camera distances, scaled by TL.push; the eye shot pushes in by TL.opt
const PUSH = TL.push ?? 1;
const OPT = TL.opt ?? 0.9;
const SPEED = TL.duration / FILM;
// only the acts this cut runs get a pill and a line in the list (a demo names its set in TL.pills)
const used = new Set(TL.pills ?? TL.script.map((e) => (e.act === 'assemble' ? 'exploded' : e.act)));
const acts = ACTS.filter(([k]) => used.has(k));
return async ({canvas, capture}) => {
const app = document.getElementById('app');
const st = createStage({canvas, floorY: FLOOR_Y, span: 3.8});
const fish = buildPiranha();
fish.pose({t: 0, idle: 0});
fish.root.updateMatrixWorld(true);
const at = (k) => fish.anchorAt(k).toArray();
const mid = (...ps) => ps.reduce((a, p) => a.map((v, i) => v + p[i] / ps.length), [0, 0, 0]);
const A = {
lens: at('lens'),
eyeAxis: new THREE.Vector3(1, 0, 0).transformDirection(fish.anchors.lens.obj.matrixWorld).toArray(),
finHub: at('finHub'),
lureMid: mid(at('stalk'), at('joint'), at('bulb')),
core: at('core'),
jaw: at('jaw'),
};
const T = makeBeeTour(TL, A);
st.addBody(fish);
retint(fish.root);
fish.root.rotation.order = 'YXZ';
fish.root.scale.x = -1;
const m = -1;
const ui = createConsole(app, {...PAGE, nav: [['overview', 'Overview'], ...acts], pills: acts});
const cursorAt = makeCursor(ui, T.SCRIPT);
const labels = makeLabels(st, fish.anchors);
const fit = () => (app.style.transform = `scale(${Math.min(innerWidth / 1600, innerHeight / 900)})`);
const resize = () => {
fit();
st.resize(1600, 900, capture ? devicePixelRatio || 1 : Math.min(devicePixelRatio || 1, 2));
};
resize();
window.PIRANHA = {st, fish, T, A};
const sm = (x) => {
const u = Math.min(1, Math.max(0, x));
return u * u * u * (u * (u * 6 - 15) + 10);
};
const SCR = [...TL.script].sort((a, b) => a.t - b.t);
const optWin = (t) => {
let w = 0;
SCR.forEach((e, i) => {
if (e.act !== 'optics') return;
const t1 = SCR[i + 1]?.t ?? TL.duration;
w = Math.max(w, sm((t - e.t) / 0.85) * (1 - sm((t - t1) / 0.85)));
});
return w;
};
return {
resize,
render(tf) {
// a demo plays the scene's timeline a little faster: TL.film seconds of film for TL.duration of scene
const t = tf * SPEED;
const s = T.stateAt(t);
fish.pose({t, idle: 1, gape: s.gape, swim: s.swim, eye: s.eye, fin: s.fin, finFlip: s.finFlip, lure: s.lure, cage: s.cage, flare: s.flare, rib: s.rib, drop: s.drop, explode: s.explode, spinT: s.spinT, bend: s.bend});
retint(fish.root);
const f = s.flight;
fish.root.position.set(m * f.pos.x, f.pos.y, f.pos.z);
fish.root.rotation.set(f.roll * D2R, m * f.yaw * D2R, m * f.pitch * D2R);
const c = s.cam;
st.frame({...c, az: m * c.az * D2R, el: c.el * D2R, d: c.d * PUSH * (1 - (1 - OPT) * optWin(t)), tx: m * c.tx, sx: m * (c.sx ?? 0) + SHIFT[0], sy: (c.sy ?? 0) + SHIFT[1]}, {guides: s.guides});
const tel = T.telemetry(t, s);
const v = s.view;
const lift = Math.min(1, tel.lift);
ui.update({
time: tf,
dur: FILM,
status: STATUS[tel.status] ?? nice(tel.status),
cards: [{v: tel.freq.toFixed(1), wave: tel.stroke.map((p) => p[0] / 40)}, {v: Math.round(lift * 100), bar: lift}, {bars: tel.servos}, {v: Math.round(tel.battery * 100), bar: tel.battery}],
apart: Math.round(Math.max(s.open?.[v] ?? 0, s.explode) * 100),
view: v === 'intro' ? 'overview' : v,
callouts: labels(tel.labelSet),
cursor: cursorAt(t),
});
return {};
},
};
};
}
export const runPiranhaGreen = (TL, title = 'piranha-film') =>
runSim({duration: TL.film ?? TL.duration, fps: 60, theme: 'light', hud: {enabled: false, title, subtitle: ''}, director: {enabled: false}, watermark: ''}, makePiranhaGreen(TL));
+345
View File
@@ -0,0 +1,345 @@
// The robotic anglerfish's stage, copied from the bee's (robobee-shared/stage.js); the key's shadow box and the floor
// shadow's window take a span (the fish is longer than the bee). A near-white product studio. A warm paper backdrop with no horizon, a soft shadow pooled
// on the floor under the bee (the bee's silhouette seen from below, blurred wide, plus a tighter pass for what hangs
// close to the floor), a softbox environment for the clear coat to catch, a key with VSM self-shadows, a rim and a
// fill, GTAO kept off the backdrop and the clear parts, MSAA. The tone curve is linear up to 0.8 and rolls off
// above, hue preserved; the backdrop writes the inverse of that curve, so the paper lands on its exact colour and the
// floor shadow darkens it as drawn. frame(cam, ops) draws one frame; cam = {tx, ty, tz, az, el, d, sx, sy}.
import * as THREE from 'three';
import {EffectComposer} from 'three/addons/postprocessing/EffectComposer.js';
import {GTAOPass} from 'three/addons/postprocessing/GTAOPass.js';
import {OutputPass} from 'three/addons/postprocessing/OutputPass.js';
import {FullScreenQuad, Pass} from 'three/addons/postprocessing/Pass.js';
import {RenderPass} from 'three/addons/postprocessing/RenderPass.js';
import {buildGuides} from './guides.js';
const V3 = THREE.Vector3;
// the paper: top, middle, the floor band (sRGB), and the shadow's tint
export const PAPER = {top: '#fefcf8', mid: '#fcf9f3', low: '#f5efe7', shadow: '#c9bcae'};
const KNEE = 0.8;
THREE.ShaderChunk.tonemapping_pars_fragment = THREE.ShaderChunk.tonemapping_pars_fragment.replace(
'vec3 CustomToneMapping( vec3 color ) { return color; }',
`vec3 CustomToneMapping( vec3 color ) {
color *= toneMappingExposure;
float p = max( color.r, max( color.g, color.b ) );
if ( p <= ${KNEE.toFixed(2)} ) return color;
float np = ${KNEE.toFixed(2)} + ${(1 - KNEE).toFixed(2)} * ( 1.0 - exp( -( p - ${KNEE.toFixed(2)} ) / ${(1 - KNEE).toFixed(2)} ) );
return color * ( np / p );
}`,
);
export const BEE_LAYER = 1;
const BACK_VERT = /* glsl */ `varying vec3 vW;
void main(){
#ifdef SCREEN
vW = vec3(0.0); gl_Position = vec4(position.xy, 0.99999, 1.0);
#else
vec4 w = modelMatrix * vec4(position, 1.0); vW = w.xyz; gl_Position = projectionMatrix * viewMatrix * w;
#endif
}`;
const BACK_FRAG = /* glsl */ `uniform vec3 uTop, uMid, uLow, uTint; uniform vec2 uRes;
uniform sampler2D tSoft, tNear; uniform mat4 uVP; uniform float uSoft, uNear;
varying vec3 vW;
vec3 paper(float y){ return y > 0.42 ? mix(uMid, uTop, smoothstep(0.42, 1.0, y)) : mix(uLow, uMid, smoothstep(0.0, 0.42, y)); }
// the inverse of the tone curve's shoulder: what to write so the output lands on c
vec3 untone(vec3 c){
float p = max(c.r, max(c.g, c.b));
if (p <= ${KNEE.toFixed(2)}) return c;
float pin = ${KNEE.toFixed(2)} - ${(1 - KNEE).toFixed(2)} * log(max(1e-4, 1.0 - (p - ${KNEE.toFixed(2)}) / ${(1 - KNEE).toFixed(2)}));
return c * (pin / p);
}
float tap(sampler2D t, vec3 w){
vec4 c = uVP * vec4(w, 1.0);
vec2 uv = c.xy / c.w * 0.5 + 0.5;
if (uv.x < 0.0 || uv.y < 0.0 || uv.x > 1.0 || uv.y > 1.0) return 0.0;
vec2 e = smoothstep(0.0, 0.08, uv) * smoothstep(0.0, 0.08, 1.0 - uv);
return texture2D(t, uv).r * e.x * e.y;
}
void main(){
vec3 c = paper(gl_FragCoord.y / uRes.y);
#ifndef SCREEN
float s = clamp(tap(tSoft, vW) * uSoft + tap(tNear, vW) * uNear, 0.0, 1.0);
c = mix(c, c * uTint, s);
#endif
gl_FragColor = vec4(untone(c), 1.0);
}`;
const QUAD_VERT = /* glsl */ `varying vec2 vUv; void main(){ vUv = uv; gl_Position = vec4(position.xy, 0.0, 1.0); }`;
const BLUR_FRAG = /* glsl */ `uniform sampler2D tSrc; uniform vec2 uDir; varying vec2 vUv;
void main(){
float w[5]; w[0] = 0.2270270270; w[1] = 0.1945945946; w[2] = 0.1216216216; w[3] = 0.0540540541; w[4] = 0.0162162162;
vec4 c = texture2D(tSrc, vUv) * w[0];
for (int i = 1; i < 5; i++) { c += texture2D(tSrc, vUv + uDir * float(i)) * w[i]; c += texture2D(tSrc, vUv - uDir * float(i)) * w[i]; }
gl_FragColor = c;
}`;
// silhouette from below: everything counts, what hangs low counts more
const SIL_VERT = /* glsl */ `varying float vH; uniform float uFloor; void main(){ vec4 w = modelMatrix * vec4(position, 1.0); vH = w.y - uFloor; gl_Position = projectionMatrix * viewMatrix * w; }`;
const SIL_FRAG = /* glsl */ `varying float vH; uniform float uFar, uBase; void main(){ float k = 1.0 - clamp(vH / uFar, 0.0, 1.0); gl_FragColor = vec4(uBase + (1.0 - uBase) * k * k, 0.0, 0.0, 1.0); }`;
export function createStage({canvas, floorY = -1.55, span = 3.4}) {
const renderer = new THREE.WebGLRenderer({canvas, antialias: false, preserveDrawingBuffer: true, powerPreference: 'high-performance'});
renderer.toneMapping = THREE.CustomToneMapping;
renderer.toneMappingExposure = 1.0;
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.VSMShadowMap;
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(30, 16 / 9, 0.05, 80);
const composer = new EffectComposer(renderer, new THREE.WebGLRenderTarget(4, 4, {type: THREE.HalfFloatType, samples: 8}));
composer.addPass(new RenderPass(scene, camera));
const gtao = new GTAOPass(scene, camera, 4, 4);
gtao.output = GTAOPass.OUTPUT.Default;
gtao.blendIntensity = 1.0;
gtao.updateGtaoMaterial({radius: 0.13, distanceExponent: 1.6, thickness: 0.9, scale: 1.0, samples: 16, distanceFallOff: 1.0, screenSpaceRadius: false});
gtao.updatePdMaterial({lumaPhi: 10, depthPhi: 2, normalPhi: 3, radius: 5, rings: 2, samples: 16});
class Toggle extends Pass {
constructor(fn) {
super();
this.needsSwap = false;
this.fn = fn;
}
render() {
this.fn();
}
}
// the backdrop, the guides and every clear part stay out of the AO pass
const skip = [];
// extra: meshes skipped only while a mode asks (the shells under x-ray)
let extra = [];
const aoSkip = (on) => {
for (const o of skip) o.visible = on && o.userData.show !== false;
for (const o of extra) o.visible = on;
};
composer.addPass(new Toggle(() => aoSkip(false)));
composer.addPass(gtao);
composer.addPass(new Toggle(() => aoSkip(true)));
composer.addPass(new OutputPass());
// ------------------------------------------------------------ the studio the clear coat reflects
{
const env = new THREE.Scene();
env.background = new THREE.Color('#d8d4ce');
const box = (w, h, pos, k, tint = [1, 0.985, 0.96]) => {
const m = new THREE.Mesh(new THREE.PlaneGeometry(w, h), new THREE.MeshBasicMaterial({color: new THREE.Color(...tint).multiplyScalar(k), side: THREE.DoubleSide}));
m.position.copy(pos);
m.lookAt(0, 0, 0);
env.add(m);
};
box(16, 10, new V3(-4, 16, 6), 3.2); // the big top box
box(3, 16, new V3(-15, 4, 8), 2.6); // a tall strip, left front
box(3, 16, new V3(14, 5, -6), 2.0, [0.96, 0.98, 1]); // the rim strip behind
box(20, 3, new V3(2, 2, 16), 1.5); // a low card in front
box(8, 8, new V3(10, 2, 12), 1.1); // fill, right front
const g = new THREE.Mesh(new THREE.CircleGeometry(40, 32), new THREE.MeshBasicMaterial({color: '#e9e3da', side: THREE.DoubleSide}));
g.rotation.x = -Math.PI / 2;
g.position.y = -3;
env.add(g);
const pm = new THREE.PMREMGenerator(renderer);
scene.environment = pm.fromScene(env, 0.025).texture;
scene.environmentIntensity = 0.62;
pm.dispose();
}
const KEY = new V3(-0.3, 0.86, 0.55).normalize();
const key = new THREE.DirectionalLight('#fffaf3', 3.0);
key.castShadow = true;
Object.assign(key.shadow.camera, {left: -span, right: span, top: span, bottom: -span, near: 1, far: 18});
key.shadow.mapSize.set(4096, 4096);
key.shadow.radius = 6;
key.shadow.blurSamples = 20;
key.shadow.bias = -0.0005;
key.shadow.normalBias = 0.01;
scene.add(key, key.target);
const rim = new THREE.DirectionalLight('#f2f6ff', 1.1);
rim.position.set(3, 3, -5);
scene.add(rim);
const fill = new THREE.DirectionalLight('#fff6ec', 0.3);
fill.position.set(4, -1, 5);
scene.add(fill);
scene.add(new THREE.HemisphereLight('#ffffff', '#d9cfc2', 0.32));
// ------------------------------------------------------------ backdrop: the paper behind, the floor with its shadow
const lin = (hex) => new THREE.Color(hex);
const backU = {
uTop: {value: lin(PAPER.top)},
uMid: {value: lin(PAPER.mid)},
uLow: {value: lin(PAPER.low)},
uTint: {value: lin(PAPER.shadow)},
uRes: {value: new THREE.Vector2(1, 1)},
tSoft: {value: null},
tNear: {value: null},
uVP: {value: new THREE.Matrix4()},
uSoft: {value: 0.42},
uNear: {value: 0.55},
};
const paper = new THREE.Mesh(new THREE.PlaneGeometry(2, 2), new THREE.ShaderMaterial({vertexShader: BACK_VERT, fragmentShader: BACK_FRAG, uniforms: backU, defines: {SCREEN: ''}, depthWrite: false, depthTest: false}));
paper.frustumCulled = false;
paper.renderOrder = -10;
scene.add(paper);
const floor = new THREE.Mesh(new THREE.PlaneGeometry(200, 200).rotateX(-Math.PI / 2), new THREE.ShaderMaterial({vertexShader: BACK_VERT, fragmentShader: BACK_FRAG, uniforms: backU, depthWrite: false}));
floor.position.y = floorY;
floor.renderOrder = -9;
scene.add(floor);
skip.push(paper, floor);
// the floor shadow: the bee from below into two targets, one blurred wide, one tight
const SR = 512;
const HALF = span + 0.8;
const mkRT = () => new THREE.WebGLRenderTarget(SR, SR, {type: THREE.HalfFloatType});
const soft = [mkRT(), mkRT()];
const near = [mkRT(), mkRT()];
backU.tSoft.value = soft[0].texture;
backU.tNear.value = near[0].texture;
const shCam = new THREE.OrthographicCamera(-HALF, HALF, HALF, -HALF, 0, 6);
shCam.up.set(0, 0, -1);
shCam.layers.set(BEE_LAYER);
const silU = {uFloor: {value: floorY}, uFar: {value: 1.6}, uBase: {value: 1.0}};
const silMat = new THREE.ShaderMaterial({vertexShader: SIL_VERT, fragmentShader: SIL_FRAG, uniforms: silU, side: THREE.DoubleSide});
const blurMat = new THREE.ShaderMaterial({vertexShader: QUAD_VERT, fragmentShader: BLUR_FRAG, uniforms: {tSrc: {value: null}, uDir: {value: new THREE.Vector2()}}, depthTest: false, depthWrite: false});
const blurQuad = new FullScreenQuad(blurMat);
const blur = ([a, b], px, passes) => {
for (let i = 0; i < passes; i++) {
blurMat.uniforms.tSrc.value = a.texture;
blurMat.uniforms.uDir.value.set(px / SR, 0);
renderer.setRenderTarget(b);
blurQuad.render(renderer);
blurMat.uniforms.tSrc.value = b.texture;
blurMat.uniforms.uDir.value.set(0, px / SR);
renderer.setRenderTarget(a);
blurQuad.render(renderer);
}
};
const black = new THREE.Color(0, 0, 0);
const prevClear = new THREE.Color();
// floor: 'full' (a wide pass and a tight one), 'one' (the wide pass only), 'half' / 'quarter' (that, every 2nd / 4th
// frame)
let floorMode = 'full';
let floorTick = 0;
const floorShadow = (c) => {
if ((floorMode === 'half' && floorTick++ % 2) || (floorMode === 'quarter' && floorTick++ % 4)) return;
shCam.position.set(c.x, floorY - 0.01, c.z);
shCam.lookAt(c.x, floorY + 1, c.z);
shCam.updateMatrixWorld();
shCam.updateProjectionMatrix();
renderer.getClearColor(prevClear);
const prevA = renderer.getClearAlpha();
const prevOv = scene.overrideMaterial;
const prevSh = renderer.shadowMap.autoUpdate;
renderer.shadowMap.autoUpdate = false;
renderer.setClearColor(black, 1);
scene.overrideMaterial = silMat;
const passes = floorMode === 'full' ? [
[soft, 1.0, 1.0, 3.2, 4],
[near, 0.0, 1.5, 1.2, 2],
] : [[soft, 1.0, 1.0, 3.2, 3]];
backU.uNear.value = floorMode === 'full' ? 0.55 : 0;
for (const [rt, base, far, px, passes2] of passes) {
silU.uBase.value = base;
silU.uFar.value = far;
renderer.setRenderTarget(rt[0]);
renderer.clear();
renderer.render(scene, shCam);
blur(rt, px, passes2);
}
scene.overrideMaterial = prevOv;
renderer.shadowMap.autoUpdate = prevSh;
renderer.setRenderTarget(null);
renderer.setClearColor(prevClear, prevA);
backU.uVP.value.multiplyMatrices(shCam.projectionMatrix, shCam.matrixWorldInverse);
};
// a dark studio for the camera lenses only: black all round with a few hard softboxes, so the glass reads deep
// black with crisp highlights instead of mirroring the pale studio as a grey haze
const lensEnv = (() => {
const env = new THREE.Scene();
env.background = new THREE.Color('#050506');
const box = (w, h, dir, k) => {
const m = new THREE.Mesh(new THREE.PlaneGeometry(w, h), new THREE.MeshBasicMaterial({color: new THREE.Color(1, 0.98, 0.95).multiplyScalar(k), side: THREE.DoubleSide}));
m.position.copy(new V3(...dir).normalize().multiplyScalar(15));
m.lookAt(0, 0, 0);
env.add(m);
};
box(10, 6, [-0.2, 1, 0.2], 6); // overhead
box(1.6, 12, [-0.85, 0.3, 0.45], 7); // a tall strip, left
box(3.2, 2.2, [0.42, 0.62, 0.66], 9); // a small box above the camera: the hot spot on the dome
box(1.2, 10, [0.75, 0.2, -0.6], 3); // a rim strip behind
const pm = new THREE.PMREMGenerator(renderer);
const tex = pm.fromScene(env, 0.01).texture;
pm.dispose();
return tex;
})();
// ------------------------------------------------------------ the bee and the guides
let bee = null;
const addBee = (b) => {
bee = b;
scene.add(b.root);
b.root.traverse((o) => {
if (o.isMesh && !b.clear.includes(o)) o.layers.enable(BEE_LAYER);
});
skip.push(...b.clear);
for (const m of [b.M.lens, b.M.lensGlass]) {
if (!m) continue;
m.envMap = lensEnv;
m.needsUpdate = true;
}
};
const guides = buildGuides();
scene.add(guides.group);
skip.push(guides.group);
const size = {w: 1920, h: 1080, pr: 1};
const resize = (w, h, pr) => {
Object.assign(size, {w, h, pr});
renderer.setPixelRatio(pr);
renderer.setSize(w, h, false);
composer.setPixelRatio(pr);
composer.setSize(w, h);
camera.aspect = w / h;
camera.updateProjectionMatrix();
backU.uRes.value.set(Math.round(w * pr), Math.round(h * pr));
guides.resize(Math.round(w * pr), Math.round(h * pr), pr);
};
// cam: target (tx, ty, tz), azimuth from +z toward +x, elevation, distance, screen shift sx/sy in CSS px
const frame = (cam, ops = {}) => {
const {tx, ty, tz, az, el, d} = cam;
camera.position.set(tx + d * Math.cos(el) * Math.sin(az), ty + d * Math.sin(el), tz + d * Math.cos(el) * Math.cos(az));
camera.lookAt(tx, ty, tz);
camera.setViewOffset(size.w, size.h, -(cam.sx ?? 0), -(cam.sy ?? 0), size.w, size.h);
camera.updateMatrixWorld();
const c = bee ? bee.root.position : new V3();
key.target.position.set(c.x + 0.1, c.y, c.z);
key.position.copy(key.target.position).addScaledVector(KEY, 8);
key.target.updateMatrixWorld();
guides.update(camera, ops);
floorShadow(c);
composer.render();
};
const pv = new V3();
/** World point to CSS px, or null behind the camera. Call after frame(). */
const project = (p) => {
pv.copy(p).project(camera);
if (pv.z > 1) return null;
return [(pv.x * 0.5 + 0.5) * size.w, (-pv.y * 0.5 + 0.5) * size.h];
};
const setAOSkip = (list) => {
extra = list;
};
// a live page's quality knobs: MSAA samples, the AO pass, the key's shadow map
const setQuality = ({samples, ao, shadow, floor, self, blur}) => {
if (blur !== undefined) key.shadow.blurSamples = blur;
if (floor !== undefined) floorMode = floor;
if (self !== undefined) key.castShadow = self;
if (samples !== undefined) {
for (const t of [composer.renderTarget1, composer.renderTarget2]) {
t.samples = samples;
t.dispose();
}
}
if (ao !== undefined) gtao.enabled = ao;
if (shadow !== undefined && shadow !== key.shadow.mapSize.x) {
key.shadow.mapSize.set(shadow, shadow);
key.shadow.map?.dispose();
key.shadow.map = null;
}
};
return {renderer, scene, camera, composer, gtao, key, resize, frame, addBee, addBody: addBee, size, floorY, project, setAOSkip, setQuality};
}
+481
View File
@@ -0,0 +1,481 @@
// The Vesper AX-6 tour cut 1:1 on the bee's (robobee-shared/tour_v2.js, robobee-sim2/timeline.json), the way the
// hummingbird's was (robohum-shared/tour_bee.js): the same beat times in the same order, the same push-ins and orbits,
// the same 330° explode turntable with the fast reassembly, distances scaled to the fish. The bee's banking fly-in is
// the fish swimming in with a bank and a roll, its tail sweeping and its jaw snapping once near the end of the 3 s; the
// bee's fly-off is a lunge (the jaw snaps and it shoots past the camera). The five assemblies map beat for beat:
// OPTICS = the eye (the bubble lifts, the lens rings unscrew out along the axis, the iris opens), WING = the near
// pectoral fin (it leaves its root and turns over in the air), LEG = the lure (the stalk comes apart link by link with
// a servo spinning in each joint, the cage blooms and the light flares), THORAX = the ribcage (the shields swing off
// and the drive rings slide out spinning 5× faster), ABDOMEN = the jaw (it drops away, the fang rows fly out along their
// rims and snap back).
// The camera rules on top: frame 0 is already the front three-quarter hero view of the still (the eye side and
// the open mouth toward the camera, the fish big and moving); every teardown is shot from that side within about ±35°
// and pushed in on the part; sides change only in the orbits, the turntable and the exit; the camera rides smooth
// splines and follows only the fish's path, never its sway. Labels show only while parts move.
// Script: the entry's timeline.json, {duration, script: [{t, act}]}; act is optics, wing, leg, thorax, abdomen,
// 'exploded', 'assemble' or 'hero' (the lunge). Everything is a pure function of film time t.
import * as THREE from 'three';
import {GAPE_LO} from './piranha.js';
import {VIEWPORT} from './console.js';
const smoother = (x) => {
const u = Math.min(1, Math.max(0, x));
return u * u * u * (u * (u * 6 - 15) + 10);
};
const ss = (a, b, t) => smoother((t - a) / (b - a));
const lerp = (a, b, k) => a + (b - a) * k;
const D2R = Math.PI / 180;
// the bee's distances scaled to the fish (tail tip to lure bulb about 5.3 units against the bee's 3)
const S = 1.6;
// the tail's stroke: radians per second of its sweep while swimming (about 0.5 Hz, heavy), and the cruise level
const STROKE_W = 3.1;
export const STROKE_HZ = STROKE_W / (2 * Math.PI);
const CRUISE = 0.65;
// fish units to metres for the dive panel (the fish is a 1.6 m drone)
const M_PER = 0.3;
const DEPTH0 = 412.6;
export const ASSEMBLIES = ['hero', 'optics', 'wing', 'leg', 'thorax', 'abdomen'];
export const ASSEMBLY_LABEL = {hero: 'HERO', optics: 'OPTICS', wing: 'FIN', leg: 'TAIL', thorax: 'FLANK', abdomen: 'JAW'};
export const DISPLAY2 = ['labels', 'exploded', 'flare', 'turntable'];
export const DISPLAY2_LABEL = {labels: 'LABELS', exploded: 'EXPLODED', flare: 'COIL FLARE', turntable: 'TURNTABLE'};
const BUTTON = {optics: 'optics', wing: 'wing', leg: 'leg', thorax: 'thorax', abdomen: 'abdomen', exploded: 'exploded', assemble: 'exploded', hero: 'hero'};
// each act's own clock, the bee's (seconds after its click): when it opens, when it closes, whether the swim eases off
// (only the ribcage: the fish keeps its slow stroke through the others, its own motion between the beats)
const ACT = {
optics: {open: [0.35, 1.5], close: [2.2, 2.65], stop: false},
wing: {open: [0.45, 1.25], close: [2.35, 2.7], stop: false},
leg: {open: [0.35, 1.45], close: [2.15, 2.55], stop: false},
thorax: {open: [0.3, 1.4], close: [2.1, 2.6], stop: true},
abdomen: {open: [0.3, 1.3], close: [2.0, 2.45], stop: false},
};
// the fin: the bee's full turn over 0.9-2.3 s; the lure's cage blooms behind the stalk and the light flares in it
const WING_FLIP = [0.9, 2.3];
const CAGE = {open: [0.75, 1.6], close: [2.05, 2.5]};
const FLARE = {open: [1.05, 1.5], close: [1.95, 2.4]};
// the jaw's snaps: the one at the end of the swim-in and the one that starts the lunge (start of the shut, seconds)
const SNAP_IN = 2.3;
const DEP = 1.0;
// ------------------------------------------------------------ cameras: [az, el, d, tx, ty, tz, sx, sy], u = seconds on
// az from +z (the fish's right flank, the near side) toward +x (its face): the still's hero view is az 30. The bee's
// angles map onto the hero side: every teardown sits between az -5 and 65. A = the world points of the parts at rest.
export function makeBeeCams(A) {
const add = (p, d) => p.map((v, i) => v + d[i]);
const mid = (a, b, k = 0.5) => a.map((v, i) => v + (b[i] - v) * k);
// the fish's middle at rest (the bulb to the tail, the lure's top to the fins): every close-up aims between it and
// its part, so the push-in lands on the part and the whole fish stays inside the viewport
const C0 = [0.15, 0.3, 0.1];
const lens = mid(C0, add(A.lens, A.eyeAxis.map((v) => v * 0.45)), 0.45).map((v, i) => (i === 1 ? C0[1] + 0.2 : v));
const wing = mid(C0, add(A.finHub, [0.9, -0.35, 1.0]), 0.35).map((v, i) => (i === 1 ? 0.2 : v));
const lure = add(mid(C0, A.lureMid, 0.3), [0.1, 0.06, 0]);
const rib = mid(C0, A.core, 0.4).map((v, i) => (i === 1 ? C0[1] - 0.1 : i === 0 ? v + 0.25 : v));
const jaw = mid(C0, A.jaw, 0.4).map((v, i) => (i === 1 ? -0.03 : v));
// the piranha's close-up targets sit on the parts themselves
const eye = mid(add(A.lens, A.eyeAxis.map((v) => v * 0.3)), C0, 0.15);
const stalk = add(A.lureMid, [0.18, -0.05, 0.05]);
const flank = add(A.core, [0, 0.05, 0.15]);
const mouth = add(A.jaw, [-0.1, 0.25, 0]);
// every close-up keeps pushing in through its whole act and keeps orbiting about 14°/s, so a hold never parks
const push = (a, b, u) => lerp(a, b, ss(0, 2.5, u));
// the explode: wide while it is apart, pushing in through the reassembly toward the hero distance
const ASM = A.asm ?? 3.2;
return {
intro: (u) => {
const k = ss(0, 3.0, u);
return [lerp(2, 32, k), lerp(13, 8, k), lerp(11.2, 10.4, k), C0[0], C0[1] + 0.08, C0[2], 0, -24];
},
// 2026-11-06, the piranha's own cameras: the angler's ones parked the shot (az
// 20-50, el 6-10, the same distance in every beat). Every beat now sits on its part from its own side and height
// and pushes in while the part hangs open: the eye in macro from the face side, the tail stalk from behind, the
// glass flank from above, the jaw from below, the explode passing low round the parts.
optics: (u) => [72 - 8 * u, lerp(10, 18, ss(0, 2.5, u)), push(6.2, 5.0, u), ...eye, 0, -24],
wing: (u) => [10 + 14 * u, 13, push(12.6, 11.1, u), ...wing, 0, -24],
leg: (u) => [-42 + 9 * u, 14, push(8.0, 6.8, u), ...stalk, 0, -24],
thorax: (u) => [4 + 8 * u, 40 - 3 * u, push(8.2, 6.9, u), ...flank, 0, -24],
abdomen: (u) => [56 - 7 * u, -4 + 2 * u, push(8.8, 7.4, u), ...mouth, 0, -24],
// the explode: while the parts fly the camera swings 38° toward the face and drops under them to look up, then
// through the reassembly swings back against the turntable onto the hero side, rises and pushes in, so the whole
// fish turns into the hero view as it snaps together
exploded: (u) => {
const go = ss(0.3, 2.8, u);
const back = ss(ASM, ASM + 1.5, u);
return [34 + 38 * go - 67 * back, lerp(16, 0, go) + 9 * back, lerp(lerp(16.8, 14.8, go), 11.0, ss(ASM + 0.1, ASM + 1.2, u)), 0.1, lerp(0.58, 0.3, ss(ASM, ASM + 1.0, u)) - 0.22 * Math.sin(Math.PI * ss(1.8, 3.0, u)), 0.0, 0, -24];
},
// the turntable stops at 330°, so the fish comes out of it turned -30°: the hero view after it sits 30° lower in
// the world to land on the same side of the fish
hero: (u) => [-2 + 12 * u, 8, 10.3, ...C0, 0, -24],
};
}
export function makeBeeTour(TL, A) {
const CAM2 = makeBeeCams(A);
const SCRIPT = [...TL.script].sort((a, b) => a.t - b.t);
const DURATION = TL.duration;
const EVENTS = SCRIPT.map((e) => e.t);
const AT = {};
for (const e of SCRIPT) (AT[e.act] ??= []).push(e.t);
const at = (act) => AT[act] ?? [];
const T_EXP = at('exploded')[0] ?? 999;
const T_ASM = at('assemble')[0] ?? 999;
const T_END = at('hero')[0] ?? 999;
const T_LUNGE = T_END + DEP;
const win = (act, W, t) => {
let v = 0;
for (const t0 of at(act)) v = Math.max(v, ss(t0 + W.open[0], t0 + W.open[1], t) * (1 - ss(t0 + W.close[0], t0 + W.close[1], t)));
return v;
};
const openOf = (act, t) => win(act, ACT[act], t);
// the full explode: out 0.2-1.8 s after EXPLODED, home 0-1.0 s after it goes off (fast, it snaps)
const explodeAt = (t) => ss(T_EXP + 0.2, T_EXP + 1.8, t) * (1 - ss(T_ASM, T_ASM + 1.0, t));
// the turntable: 330° from the explode to just after the fish is whole again, steady in the middle
const TT = [T_EXP + 0.2, T_ASM + 1.5];
const turnAt = (t) => {
const [a, b] = TT;
if (t <= a) return 0;
const R = 0.6;
const span = b - a;
const v = 330 / (span - R);
const x = Math.min(t, b) - a;
if (x < R) return (v * x * x) / (2 * R);
if (x < span - R) return v * (x - R / 2);
const y = x - (span - R);
return v * (span - 1.5 * R) + v * y - (v * y * y) / (2 * R);
};
const stopAt = (t) => {
let v = 0;
for (const act of Object.keys(ACT)) {
if (!ACT[act].stop) continue;
for (const t0 of at(act)) v = Math.max(v, ss(t0, t0 + 0.45, t) * (1 - ss(t0 + ACT[act].close[1], t0 + ACT[act].close[1] + 0.5, t)));
}
return Math.max(v, ss(T_EXP, T_EXP + 0.45, t) * (1 - ss(T_ASM + 0.9, T_ASM + 1.5, t)));
};
const activity = (t) => Math.max(...Object.keys(ACT).map((a) => openOf(a, t)), explodeAt(t));
const DT = 1 / 240;
const SPIN = [0];
for (let i = 1; i * DT <= DURATION + 1; i++) SPIN.push(SPIN[i - 1] + (1 + 5 * activity((i - 0.5) * DT)) * DT);
const look = (A2, t) => {
const u = Math.max(0, Math.min(A2.length - 2, t / DT));
const i = Math.floor(u);
return A2[i] + (A2[i + 1] - A2[i]) * (u - i);
};
const spinAt = (t) => (t < 0 ? t : look(SPIN, t));
// the swim stroke: heavy while it swims in, a cruise between the beats, held still while a part is off, the full
// stroke again for the wind-up and the lunge
const swimAt = (t) => Math.max(1 - ss(2.5, 3.6, t), CRUISE * (1 - 0.6 * stopAt(t) - 0.4 * Math.min(1, explodeAt(t) * 3)), ss(T_END + 0.1, T_END + 0.8, t));
// the jaw: its gape in degrees, with the snap at the end of the swim-in, the wide wind-up before the lunge and the
// snap that starts it
const snap = (t, t0) => ss(t0, t0 + 0.12, t) * (1 - ss(t0 + 0.2, t0 + 0.55, t));
const gapeAt = (t) => GAPE_LO + 9 * ss(T_END + 0.15, T_END + 0.85, t) * (1 - ss(T_LUNGE, T_LUNGE + 0.12, t)) - 22 * snap(t, SNAP_IN) - 24 * snap(t, T_LUNGE);
// the swim: in from behind-left banking through a turn toward the camera, the cruise, the turntable, the wind-up and
// the lunge past the camera. path is the smooth part the camera follows; the stroke's sway rides on top for the fish
// alone.
const flightAt = (t) => {
const kIn = ss(-0.3, 2.6, t);
const ex = explodeAt(t);
const calm = 1 - Math.min(1, ex * 2.5);
const sw = swimAt(t);
const path = new THREE.Vector3(lerp(-1.3 * S, 0, kIn), lerp(0.4 * S, 0, kIn), lerp(-1.7 * S, 0, kIn));
let yaw = lerp(-48, 0, kIn) + 12 * Math.sin(Math.PI * kIn);
let roll = -22 * Math.sin(Math.PI * Math.min(1, kIn * 1.05)) + (2.2 * Math.sin(t * 1.3 + 1.1) + 3.2 * Math.sin(t * 0.85 + 0.4)) * calm;
let pitch = 5 * Math.sin(Math.PI * kIn) + (1.6 * Math.sin(t * 1.9 + 0.6) + 2.4 * Math.sin(t * 1.2 + 2.0)) * calm;
yaw += turnAt(t);
// the wind-up: it draws back along its heading and turns its head a little toward the camera; the lunge turns it
// back onto the hero line, so it shoots forward and toward the lens and passes the camera on the right
const wind = ss(T_END + 0.1, T_END + 0.9, t);
yaw -= 9 * wind;
pitch += 4 * wind;
{
const h0 = new THREE.Vector3(Math.cos(yaw * D2R), 0, -Math.sin(yaw * D2R));
path.addScaledVector(h0, -0.4 * wind * (1 - ss(T_LUNGE, T_LUNGE + 0.3, t)));
}
if (t > T_LUNGE) {
const u = t - T_LUNGE;
const k = ss(0, 0.8, u);
yaw += 6 * k;
roll += 16 * k;
pitch -= 5 * k;
const h = new THREE.Vector3(Math.cos(yaw * D2R), 0, -Math.sin(yaw * D2R));
path.addScaledVector(h, 1.15 * S * u * u + 0.4 * S * u).add(new THREE.Vector3(0, 0.05 * S * u * u, 0));
}
// the stroke sways the head against the tail; the camera never sees it
const sway = 3.4 * sw * Math.sin(t * STROKE_W + Math.PI) * calm;
const pos = path.clone().add(new THREE.Vector3(0, 0.07 * S * Math.sin(t * 1.1) * calm, 0));
return {pos, path, yaw: yaw + sway, roll, pitch, calm, swim: sw, heading: yaw};
};
// the lure lags the turns: each joint takes the turn the fish made a moment earlier
const LAG = 0.085;
const bendAt = (t) => {
const out = [];
let a = flightAt(t);
for (let k = 0; k < 7; k++) {
const b = flightAt(t - LAG * (k + 1));
out.push([0.55 * D2R * (b.pitch - a.pitch), 0.55 * D2R * (b.yaw - a.yaw) + 0.25 * D2R * (b.roll - a.roll)]);
a = b;
}
return out;
};
// the camera: each act's view, blended over 0.85 s with a short dolly out, tracking the fish's path
const VIEWS = [{t: -1, key: 'intro'}, ...SCRIPT.map((e) => ({t: e.t, key: e.act === 'assemble' ? 'exploded' : e.act}))];
const viewIdx = (t) => {
let i = 0;
while (i < VIEWS.length - 1 && VIEWS[i + 1].t <= t) i++;
return i;
};
const camFn = (V, t) => CAM2[V.key](t - (V.key === 'intro' ? 0 : V.t));
// the reassembly keeps the explode's camera running on the explode's clock, also while the next view blends in
const runOf = (j) => {
while (j > 0 && VIEWS[j].key === 'exploded' && VIEWS[j - 1].key === 'exploded') j--;
return VIEWS[j];
};
const camAt = (t) => {
const i = viewIdx(t);
let o = camFn(runOf(i), t);
if (i > 0 && runOf(i) === VIEWS[i]) {
const k = ss(VIEWS[i].t, VIEWS[i].t + 0.85, t);
if (k < 1) {
const a = camFn(runOf(i - 1), t);
const dAz = ((o[0] - a[0] + 540) % 360) - 180;
const b = o.map((v, j) => lerp(a[j], v, k));
b[0] = a[0] + dAz * k;
b[2] += 0.9 * Math.sin(Math.PI * k);
o = b;
}
}
const f = flightAt(t);
const track = 0.85 - 0.5 * ss(T_LUNGE, T_LUNGE + 1.0, t);
return {az: o[0], el: o[1], d: o[2], tx: o[3] + f.path.x * track, ty: o[4] + f.path.y * track, tz: o[5] + f.path.z * track, sx: o[6], sy: o[7]};
};
const actAt = (t) => VIEWS[viewIdx(t)].key;
const stateAt = (t) => {
const ex = explodeAt(t);
const f = flightAt(t);
const open = Object.fromEntries(Object.keys(ACT).map((a) => [a, openOf(a, t)]));
let finFlip = 0;
for (const t0 of at('wing')) finFlip = Math.max(finFlip, ss(t0 + WING_FLIP[0], t0 + WING_FLIP[1], t));
if (finFlip >= 1) finFlip = 0;
const cage = win('leg', CAGE, t);
// the light flares in the lure act, glows up through the explode and flashes on the wind-up
const flare = Math.max(win('leg', FLARE, t), 0.55 * ss(T_END + 0.2, T_END + 0.8, t) * (1 - ss(T_LUNGE + 0.6, T_LUNGE + 1.4, t)));
const view = actAt(t);
return {
t,
spinT: spinAt(t),
explode: ex,
swim: f.swim,
gape: gapeAt(t),
eye: open.optics,
fin: open.wing,
finFlip,
lure: open.leg,
cage,
flare,
rib: open.thorax,
drop: open.abdomen,
open,
flight: f,
bend: bendAt(t),
cam: camAt(t),
view,
guides: 0.45 + 0.55 * Math.min(1, ex * 2.5 + activity(t)),
turn: turnAt(t),
};
};
const LABELS = {
optics: [['eyeGlass', 'EYE RING', 'LIT · UNDER THE BROW'], ['lensRing', 'LENS RINGS', '3 × THREADED'], ['iris', 'IRIS', '10 BLADES · OPENS 4×'], ['barrel', 'LENS BARREL', 'SLIDES OUT']],
wing: [['fin', 'PECTORAL FIN', 'FROSTED FILM'], ['finHub', 'FIN ROOT', 'PIVOT DRUM']],
leg: [['stalk', 'TAIL STALK', '4 SEGMENTS · TELESCOPING'], ['joint', 'SEGMENT SERVO', 'SPINNING FREE'], ['tailHub', 'TAIL HUB', 'BRACKET · 2 LOBES'], ['tail', 'TAIL FIN', '11 RAYS · FROSTED FILM']],
thorax: [['flank', 'GLASS BARREL', 'CLEAR · LIFTS OFF'], ['rib', 'RIB BANDS', 'HINGED · SWING UP'], ['gear', 'DRIVE GEARS', '2 BIG · 5× SPEED'], ['coil', 'LIT COILS', '2 · GREEN']],
abdomen: [['jaw', 'LOWER JAW', 'DROPS · UNDERBITE'], ['fang', 'LOWER FANGS', 'GLASS · 2 ROWS'], ['upfang', 'UPPER FANGS', 'GLASS · 2 ROWS']],
exploded: [['lens', 'OPTIC HEAD', '2 × LENS'], ['tailHub', 'TAIL', '4 SEGMENTS'], ['gear', 'DRIVE GEARS', 'SPINNING FREE'], ['fin', 'PECTORAL FIN', 'FROSTED FILM'], ['jaw', 'LOWER JAW', 'GLASS FANGS']],
};
const labelAt = (t, s) => {
const v = s.view;
if (ACT[v]) {
const t0 = at(v).filter((x) => x <= t).pop();
const A2 = ACT[v];
return {set: LABELS[v], o: ss(t0 + A2.open[0] + 0.1, t0 + A2.open[0] + 0.45, t) * (1 - ss(t0 + A2.close[0] - 0.25, t0 + A2.close[0], t))};
}
if (v === 'exploded') return {set: LABELS.exploded, o: ss(T_EXP + 0.4, T_EXP + 0.8, t) * (1 - ss(T_EXP + 2.3, T_EXP + 2.6, t))};
return {set: [], o: 0};
};
// the tail's and the near pectoral's angles in degrees, as pose() draws them
const tailDeg = (tt) => (0.14 * Math.sin(tt * 1.6) + 0.4 * swimAt(tt) * Math.sin(tt * STROKE_W)) / D2R;
const finDeg = (tt) => ((0.12 + 0.2 * swimAt(tt)) * Math.sin(tt * 2.2)) / D2R;
const telemetry = (t, s) => {
const f = s.flight;
const stroke = [];
for (let i = 0; i <= 90; i++) {
const tt = t - 4 + (i / 90) * 4;
stroke.push([tailDeg(tt), finDeg(tt)]);
}
const ex = s.explode > 0.04;
const sw = s.swim;
// the servos: FIN R, FIN L, TAIL, JAW, TAIL STALK, DORSAL; a part that is off its mount reads DETACHED
const free = [ex || s.fin > 0.08, ex, ex, ex || s.drop > 0.08, ex || s.lure > 0.08, ex];
const gapeLoad = Math.abs(s.gape - GAPE_LO) / 24;
const base = [0.3 + 0.4 * sw, 0.28 + 0.4 * sw, 0.22 + 0.62 * sw, 0.24 + 0.6 * gapeLoad, 0.3 + 0.08 * Math.abs(s.bend[3][1]) * 40, 0.2 + 0.2 * sw];
const servos = base.map((b, i) => (free[i] ? 0 : Math.max(0, Math.min(1, b + 0.04 * Math.sin(t * 7 + i) + 0.1 * Math.abs(f.roll) / 30))));
const v = s.view;
const opening = ACT[v] ? s.open[v] : 0;
const NAME = {optics: 'OPTICS OPEN', wing: 'FIN OFF', leg: 'TAIL OUT', thorax: 'FLANK OPEN', abdomen: 'JAW DROPPED'};
let status = 'CRUISE';
let kind = 'ok';
if (t < 2.6) status = 'BANKING';
if (ACT[v] && opening > 0.05) [status, kind] = [NAME[v], 'warn'];
if (v === 'exploded') [status, kind] = t < T_ASM ? ['TEARDOWN', 'warn'] : s.explode > 0.04 ? ['REASSEMBLY', 'warn'] : ['CRUISE', 'ok'];
if (t > T_END + 0.1 && t <= T_LUNGE) status = 'WIND-UP';
if (t > T_LUNGE) [status, kind] = ['LUNGE', 'warn'];
const ROW = {optics: 0, leg: 1, thorax: 2, wing: 3, abdomen: 4};
const sub = (i) => {
if (ex) return ['warn', 'DETACHED'];
if (ROW[v] === i && opening > 0.05) return ['warn', i === 3 || i === 4 ? 'DETACHED' : 'OPEN'];
if (i === 3) return sw > 0.05 ? ['ok', `${(STROKE_HZ * 60).toFixed(0)} SPM`] : ['idle', 'FEATHERED'];
if (i === 2) return sw > 0.05 ? ['ok', 'RUNNING'] : ['idle', 'IDLE'];
if (i === 1) return s.flare > 0.1 ? ['warn', 'FLARE'] : ['ok', 'LIT 18%'];
return ['ok', ['TRACKING', '', '', '', 'ARMED', 'SEALED'][i]];
};
const last = SCRIPT.filter((e) => e.t <= t).pop();
const say = (e) => (e.act === 'exploded' ? 'EXPLODED ON' : e.act === 'assemble' ? 'EXPLODED OFF · REASSEMBLE' : e.act === 'hero' ? 'HERO · RELEASE' : `ISOLATE ${ASSEMBLY_LABEL[e.act]}`);
const lungeV = t > T_LUNGE ? (2.3 * S * (t - T_LUNGE) + 0.4 * S) * M_PER : 0;
const speed = lungeV + M_PER * (0.9 * (1 - ss(1.5, 3.0, t)) + 0.35 * sw);
const labels = labelAt(t, s);
const amp = (0.14 + 0.4 * sw) / D2R;
return {
time: t,
dur: DURATION,
lift: Math.max(0, Math.min(1, 0.18 + 0.55 * sw + 0.25 * ss(T_LUNGE, T_LUNGE + 0.4, t) + 0.05 * Math.sin(t * STROKE_W))),
status,
statusKind: kind,
freq: STROKE_HZ * Math.min(1, 0.4 + sw),
amp,
stroke,
chartMax: 40,
chartTicks: [-30, 30],
chartSpan: '−4 S',
playback: 1,
blur: 1,
shutter: 'TAIL · R PECTORAL',
battery: 0.912 - 0.0021 * t,
power: 41 + 120 * Math.pow(sw, 1.4) + 60 * activity(t) + 8 * Math.sin(t * STROKE_W),
volt: 48.2,
motorT: 22 + 0.35 * t,
servos,
legsFree: free.some((x) => x),
legFreeEach: free,
depth: DEPTH0 - M_PER * f.pos.y * 4,
vs: -M_PER * 0.07 * S * 1.1 * Math.cos(t * 1.1) * f.calm,
pitch: f.pitch,
roll: f.roll,
airspeed: speed,
trim: s.explode > 0.04 ? 'FREE' : t > T_LUNGE ? 'STRIKE' : 'NEUTRAL',
view: v === 'intro' ? 'hero' : v === 'exploded' ? null : v,
display: {labels: labels.o > 0.5, exploded: t >= T_EXP && t < T_ASM, flare: s.flare > 0.2, turntable: s.turn > 0 && t < TT[1]},
subs: [0, 1, 2, 3, 4, 5].map(sub),
focus: ROW[v] ?? (v === 'exploded' ? 5 : -1),
events: EVENTS,
next: `${EVENTS.length} OPERATOR ACTIONS`,
log: last ? `OPERATOR · ${say(last)}` : 'INBOUND · BANKING IN',
mode: status,
modeSub:
status === 'BANKING'
? `BANK ${f.roll.toFixed(0)}° · INBOUND`
: status === 'TEARDOWN' || status === 'REASSEMBLY'
? `TURNTABLE ${Math.round(s.turn)}° · ${Math.round(s.explode * 100)}% APART`
: status === 'LUNGE'
? `STRIKE · ${speed.toFixed(1)} M/S`
: status === 'WIND-UP'
? `JAW ${s.gape.toFixed(0)}° · MOUTH OPEN`
: ACT[v] && opening > 0.05
? `${ASSEMBLY_LABEL[v]} · ${Math.round(opening * 100)}% APART`
: `DEPTH ${(DEPTH0 - M_PER * f.pos.y * 4).toFixed(1)} M · STATION`,
viewNote: `ISOLATE · ${v === 'intro' || v === 'hero' ? 'HERO' : v === 'exploded' ? 'ALL' : ASSEMBLY_LABEL[v]}`,
labelSet: labels,
};
};
return {SCRIPT, DURATION, stateAt, telemetry, camAt, flightAt};
}
/** Labels in two columns at the viewport's edges, from a set of anchors. */
export function makeLabels(st, fish) {
const p = new THREE.Vector3();
return ({set, o}) => {
if (o < 0.02) return [];
const pts = [];
for (const [key, name, sub] of set) {
const A = fish.anchors[key];
if (!A) continue;
A.obj.updateWorldMatrix(true, false);
const at = st.project(A.obj.localToWorld(p.copy(A.at)));
if (at && at[0] > VIEWPORT.x0 + 30 && at[0] < VIEWPORT.x1 - 30 && at[1] > VIEWPORT.y0 + 40 && at[1] < VIEWPORT.y1 - 70) pts.push({name, sub, at});
}
const mid = (VIEWPORT.x0 + VIEWPORT.x1) / 2;
const out = [];
const stack = (col, x, w) => {
let y = Math.max(VIEWPORT.y0 + 48, Math.min(col.length ? col[0].at[1] - 10 : 0, VIEWPORT.y1 - 110 - 34 * col.length));
for (const c of col) {
y = Math.max(y, Math.min(VIEWPORT.y1 - 110, c.at[1] - 10));
out.push({name: c.name, sub: c.sub, at: c.at, label: [x, y], w, o});
y += 34;
}
};
stack(pts.filter((x) => x.at[0] < mid).sort((a, b) => a.at[1] - b.at[1]), VIEWPORT.x0 + 16, 168);
stack(pts.filter((x) => x.at[0] >= mid).sort((a, b) => a.at[1] - b.at[1]), VIEWPORT.x1 - 160, 150);
return out;
};
}
// ------------------------------------------------------------ the operator's pointer, on the act buttons
const GUTTER_X = 1262;
export function makeCursor(ui, SCRIPT) {
const EV = SCRIPT.filter((e) => e.t > 0).map((e) => ({t: e.t, spot: ui.spots[BUTTON[e.act]]}));
const WP = [[0, GUTTER_X, EV[0].spot[1] + 60]];
let [px, py, pt] = [GUTTER_X, EV[0].spot[1] + 60, 0];
EV.forEach((e, n) => {
const [x, y] = e.spot;
const travel = Math.min(0.7, 0.3 + Math.hypot(x - px, y - py) / 900);
const arrive = e.t - 0.1;
if (arrive - travel - pt > 1.4) {
const rest = [GUTTER_X, Math.max(170, Math.min(720, y + 40))];
WP.push([pt + 0.7, ...rest]);
WP.push([arrive - travel, ...rest]);
} else WP.push([Math.max(pt + 0.01, arrive - travel), px, py]);
WP.push([arrive, x, y], [e.t + 0.18, x, y]);
[px, py, pt] = [x, y, e.t + 0.18];
const next = EV[n + 1];
if (!next || next.t - 0.1 - 0.7 - pt > 0.8) {
[px, py, pt] = [GUTTER_X, y + 12, pt + 0.55];
WP.push([pt, px, py]);
}
});
WP.push([pt + 0.9, GUTTER_X, Math.min(720, py + 50)]);
return (t) => {
let i = 0;
while (i < WP.length - 2 && t > WP[i + 1][0]) i++;
const [t0, x0, y0] = WP[i];
const [t1, x1, y1] = WP[i + 1];
const k = ss(t0, t1, t);
const len = Math.hypot(x1 - x0, y1 - y0);
const bow = Math.sin(Math.PI * k) * Math.min(22, len * 0.07);
let press = false;
let ring = 0;
let rx = 0;
let ry = 0;
for (const e of EV) {
if (t >= e.t - 0.07 && t < e.t + 0.09) press = true;
if (t >= e.t && t < e.t + 0.55) {
ring = 1 - (t - e.t) / 0.55;
[rx, ry] = e.spot;
}
}
return {x: x0 + (x1 - x0) * k + (len ? (-(y1 - y0) / len) * bow : 0), y: y0 + (y1 - y0) * k + (len ? ((x1 - x0) / len) * bow : 0), press, ring, ringX: rx, ringY: ry};
};
}