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:
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,359 @@
|
||||
// The Mellis HB-7 console, laid out at 1600 x 900 after the Cessna console and the reference app recordings: the
|
||||
// orange HB-7 badge and title with the sim status cells, the wing beat with its live stroke chart, power, the six leg
|
||||
// servos, flight telemetry with an attitude ball, the views, the display toggles, the subsystem registry, the flight
|
||||
// log with the operator's actions on its timeline, the flight-mode word in the viewport, the labels with leaders into
|
||||
// the bee and the operator's pointer. Panels are light paper over the near-white studio; the bee's orange is the one
|
||||
// accent. update(s) redraws every live part from the frame's state; the film and a live page share it.
|
||||
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 × 18 MM LENS · AMBER IR'],
|
||||
['NECK BEARING', '10-SEGMENT COLLAR'],
|
||||
['THORAX DRIVE', '3 GEARS · 11 ACTUATORS'],
|
||||
['WING ROOTS', '4 HINGES · 7.5 HZ CRANK'],
|
||||
['LEG SERVOS', '6 LEGS × 3 JOINTS'],
|
||||
['ABDOMEN BANDS', '5 SEGMENTS · GLASS STING'],
|
||||
];
|
||||
const LEGS = ['L1', 'L2', 'L3', 'R1', 'R2', 'R3'];
|
||||
|
||||
// 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:24px;top:24px" width="44" height="40" viewBox="0 0 44 40"><g fill="none" stroke="#fff" stroke-width="2.2"><path d="M22 3l9 5.2v10.4l-9 5.2-9-5.2V8.2z"/><path d="M13 14C7 6 1 9 2 14s7 5 11 2M31 14c6-8 12-5 11 0s-7 5-11 2"/><path d="M18 26l-3 10M26 26l3 10M22 24v12"/></g></svg>`);
|
||||
add(`<div class="mo" style="position:absolute;left:80px;top:34px;color:#fff;font-size:16px;font-weight:600;letter-spacing:3px">VX-9</div>`);
|
||||
add(`<div class="sm" style="position:absolute;left:182px;top:20px;letter-spacing:2.4px">ROBOTIC WASP · MICRO AIR VEHICLE</div>`);
|
||||
add(`<div style="position:absolute;left:181px;top:35px;font-size:33px;font-weight:700;letter-spacing:-.6px;line-height:1">Vespion VX-9 <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">FLAPPING-WING DRONE / FIELD SIMULATOR</div>`);
|
||||
add(`<div class="sm" style="position:absolute;left:700px;top:22px">LIFT 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">HOVER</div>`);
|
||||
add(`<div class="sm" style="position:absolute;left:1010px;top:57px;font-size:7.6px">MAX</div>`);
|
||||
const cells = [
|
||||
['SIM ID', 'HB7-0412'],
|
||||
['RUNTIME', ''],
|
||||
['STATUS', ''],
|
||||
['OPERATOR', 'LAB 3 · R.K.'],
|
||||
];
|
||||
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, 'WING BEAT', '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 leg servos
|
||||
panel(L.x, 506, L.w, 238, 'LEG 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 LEG · KNEE TORQUE</div>`);
|
||||
const servo = LEGS.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:66px;top:${y + 4}px;width:178px;height:6px;background:${C.track};border-radius:3px"></div>`);
|
||||
const f = add(`<div style="position:absolute;left:66px;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, 'FLIGHT', '04');
|
||||
const ball = add(`<svg style="position:absolute;left:1300px;top:142px" width="96" height="96"></svg>`);
|
||||
const fl = [['ALT AGL', 0], ['V/S', 1], ['PITCH', 2], ['ROLL', 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">HOLD</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">AIRSPEED</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, 'FLIGHT 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">TAKE-OFF</div>`);
|
||||
add(`<div class="sm" style="position:absolute;right:${1600 - 1250}px;top:791px">LAND</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 VX-9 · 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">FLIGHT 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 · PROCEDURAL MODEL · 6 LEGS · 4 WINGS · 2 OPTICS</div>`);
|
||||
add(`<div class="sm" style="position:absolute;right:28px;top:878px;letter-spacing:2.2px">VESPION ROBOTICS · INTERCEPT 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 forewing (orange) and hindwing (grey) over the
|
||||
// last 1.2 s, with the now marker on the right
|
||||
fq.innerHTML = `${s.freq.toFixed(1)}<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 / 40) * (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 [-32, 32]) 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">−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.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`;
|
||||
// leg 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 * 178).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.airborne ? `${s.alt.toFixed(1)} MM` : '—';
|
||||
fl[1].textContent = s.airborne ? `${s.vs >= 0 ? '+' : '−'}${Math.abs(s.vs).toFixed(1)} MM/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.airborne ? 'POSITION' : 'OFF';
|
||||
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,
|
||||
};
|
||||
}
|
||||
@@ -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);
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,304 @@
|
||||
// The robotic bee's kitbash shop: the materials (gloss white shell, orange accent, graphite and black mechanism,
|
||||
// steel, the lens, the clear abdomen and the wing membrane) and the geometry every part is cut from. 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}),
|
||||
// the wasp: the orange light inside the waist rings, the abdomen gaps and the sting, a touch hotter than led
|
||||
glow: std({color: '#000000', emissive: '#ff6a1c', emissiveIntensity: 1.9}),
|
||||
// the sting: clear glass tinted toward amber, the glow core shows through it
|
||||
// a faint amber tint in the glass itself
|
||||
sting: phys({color: '#fff0e2', roughness: 0.04, metalness: 0, transmission: 1, thickness: 0.035, ior: 1.3, attenuationColor: '#ffb27a', attenuationDistance: 1.4, specularIntensity: 1, clearcoat: 1, clearcoatRoughness: 0.02, envMapIntensity: 1.8}),
|
||||
// the sting's rim: a fresnel edge in warm amber over the glass, strongest where the surface turns from the eye
|
||||
stingRim: new THREE.ShaderMaterial({
|
||||
transparent: true,
|
||||
depthWrite: false,
|
||||
uniforms: {uColor: {value: new THREE.Color('#7c5236')}, uK: {value: 0.85}},
|
||||
vertexShader: 'varying vec3 vN; varying vec3 vV; void main(){ vec4 mv = modelViewMatrix * vec4(position, 1.0); vN = normalize(normalMatrix * normal); vV = normalize(-mv.xyz); gl_Position = projectionMatrix * mv; }',
|
||||
fragmentShader: 'uniform vec3 uColor; uniform float uK; varying vec3 vN; varying vec3 vV; void main(){ float f = pow(1.0 - abs(dot(normalize(vN), normalize(vV))), 2.0); gl_FragColor = vec4(uColor, f * uK); }',
|
||||
}),
|
||||
stingCore: std({color: '#000000', emissive: '#ff7424', emissiveIntensity: 2.0}),
|
||||
};
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ 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;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
"""Score for the VESPION VX-9 wasp film (entry wasp-film), the bee's second-cut score with one more cue (the sting
|
||||
sliding out in the abdomen act). The bee's notes: Score for the MELLIS HB-7 simulator film, second cut (entry robobee-sim2): the same bed as the other bee films (D minor,
|
||||
96 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: thread ticks as the lens unscrews and screws
|
||||
back, a swish as the wing pulls out and turns over and a snap as it seats, servo ticks down the leg, a lift of air as
|
||||
the thorax and the abdomen open and a click as they close, a whoosh into the explode and three clicks as the bee seats
|
||||
again, and a rising air as it banks away. No drones.
|
||||
|
||||
python run_sfx.py sims/wasp-shared/score.py
|
||||
|
||||
Every cue comes from the script in robobee-sim2/timeline.json, with the offsets inside each act taken from tour_v2.js
|
||||
(ACT, the explode out 0.2-1.8 s and home 0-1.0 s, the departure 1.0 s after HERO).
|
||||
"""
|
||||
|
||||
import os
|
||||
|
||||
|
||||
from sfx.score_kit import airy, bed, chords, hz # noqa: E402
|
||||
from sfx.synth import blip, click, envelope, pad # noqa: E402
|
||||
|
||||
TIMELINE = os.environ.get("TL", "../wasp-film/timeline.json")
|
||||
OUT = os.environ.get("OUT", os.path.join(os.environ.get("CUTAWAY_OUT", "cutaway-out"), "wasp-score.wav"))
|
||||
TARGET_LUFS = -14.0
|
||||
SEED = 29
|
||||
|
||||
CHORDS = chords("Dm9:D3 F3 A3 C4 E4/D2", "Bbmaj7:Bb2 D3 F3 A3/Bb1", "Gm9:G2 Bb2 D3 F3 A3/G1", "A7sus:A2 D3 E3 G3/A1")
|
||||
MOTIF = [(0.5, hz("A5")), (1.5, hz("F5")), (2.5, hz("E5"))]
|
||||
|
||||
|
||||
def score(mix, tl):
|
||||
dur = tl["duration"]
|
||||
left, right, low, drums = bed(dur, 96, CHORDS, MOTIF, motif_voice="blip", kicks=(0, 2.5), snares=(1, 3), hats=8, swing=0.08, keys_vel=0.75, keys_lp=3800)
|
||||
mix.put_stereo(0, left, right, 0.13)
|
||||
mix.put(0, low, 0.13)
|
||||
mix.put(0, drums, 0.05)
|
||||
bar = 4 * 60 / 96
|
||||
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 fly-in: one air that follows the bank
|
||||
mix.put(0.0, airy(2.4, 700, 1800, 0.6), 0.02, pan=-0.3)
|
||||
|
||||
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":
|
||||
for i, dt in enumerate((0.4, 0.62, 0.84, 1.06)):
|
||||
mix.put(t + dt, click(3200 - 200 * i, 0.018), 0.035, pan=0.2)
|
||||
for i, dt in enumerate((2.2, 2.36, 2.52)):
|
||||
mix.put(t + dt, click(2600 + 200 * i, 0.018), 0.03, pan=0.2)
|
||||
elif act == "wing":
|
||||
mix.put(t + 0.45, airy(0.8, 600, 2200, 0.6), 0.025, pan=-0.3)
|
||||
mix.put(t + 0.9, airy(1.4, 900, 1500, 0.5), 0.016, pan=-0.2)
|
||||
mix.put(t + 2.68, click(1800, 0.03), 0.06, pan=-0.2)
|
||||
elif act == "leg":
|
||||
for i, dt in enumerate((0.38, 0.6, 0.82, 1.04)):
|
||||
mix.put(t + dt, blip(hz("D6") * 2 ** (i / 6), 0.18, 0.06), 0.02, pan=0.1)
|
||||
mix.put(t + 2.55, click(2000, 0.03), 0.05)
|
||||
elif act in ("thorax", "abdomen"):
|
||||
mix.put(t + 0.3, airy(1.0, 500, 1600, 0.6), 0.024)
|
||||
mix.put(t + (2.6 if act == "thorax" else 2.45), click(2100, 0.03), 0.055)
|
||||
if act == "abdomen":
|
||||
# the sting slides out of its collar and back
|
||||
mix.put(t + 1.05, blip(hz("A5"), 0.22, 0.07), 0.018, pan=-0.2)
|
||||
mix.put(t + 1.5, click(2900, 0.02), 0.035, pan=-0.2)
|
||||
mix.put(t + 2.15, click(2500, 0.02), 0.03, pan=-0.2)
|
||||
elif act == "exploded":
|
||||
mix.put(t + 0.2, airy(1.4, 500, 2600, 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 + 1.0, airy(2.0, 500, 2400, 0.7), 0.03, pan=0.4)
|
||||
@@ -0,0 +1,122 @@
|
||||
"""Score for the MELLIS HB-7 18-second film (entry wasp-demo, tour_10.js): the bee films' bed in D minor (Dm9, Bbmaj7,
|
||||
Gm9, A7sus at 96 bpm: e-piano, bass, soft drums and a pad) at one level the whole way, a quiet click on every button
|
||||
press, and short quiet accents on each act's own moves: a falling air for the dive in from the left, thread ticks as
|
||||
the lens unscrews and screws back, a swish as the wing leaves its hinge and another as it turns over and a snap as it
|
||||
seats, a lift of air and a few gear ticks as the thorax and the abdomen open and a click as they close, a whoosh into
|
||||
the explode with a long falling air and one low note under the 0.4x speed ramp and slow glass ticks as the parts drift
|
||||
apart, three clicks as the bee seats again, and a rising air that swells as the bee darts at the lens and passes to
|
||||
its right. No drones.
|
||||
|
||||
python run_sfx.py sims/wasp-shared/score_demo.py
|
||||
|
||||
Every cue comes from wasp-demo/timeline.json. The offsets inside each act are tour_10.js's, in SCENE seconds, and go
|
||||
through the same speed-ramp warp (RAMP, anchored on EXPLODED) back to film time.
|
||||
"""
|
||||
|
||||
import bisect
|
||||
import os
|
||||
|
||||
|
||||
|
||||
from sfx.score_kit import airy, bed, chords, hz # noqa: E402
|
||||
from sfx.synth import blip, click, envelope, pad # noqa: E402
|
||||
|
||||
TIMELINE = os.environ.get("TL", "../wasp-demo/timeline.json")
|
||||
OUT = os.environ.get("OUT", os.path.join(os.environ.get("CUTAWAY_OUT", "cutaway-out"), "wasp-demo-score.wav"))
|
||||
TARGET_LUFS = -14.0
|
||||
SEED = 53
|
||||
|
||||
CHORDS = chords("Dm9:D3 F3 A3 C4 E4/D2", "Bbmaj7:Bb2 D3 F3 A3/Bb1", "Gm9:G2 Bb2 D3 F3 A3/G1", "A7sus:A2 D3 E3 G3/A1")
|
||||
MOTIF = [(0.5, hz("A5")), (1.5, hz("F5")), (2.5, hz("E5"))]
|
||||
# tour_10.js: the ramp in film seconds after the EXPLODED click, and the dart's start after HERO (scene seconds)
|
||||
RAMP_A, RAMP_B, RAMP_LOW = (0.35, 0.55), (1.9, 2.1), 0.4
|
||||
DEP = 0.75
|
||||
|
||||
|
||||
def _smoother(x):
|
||||
u = min(1.0, max(0.0, x))
|
||||
return u * u * u * (u * (u * 6 - 15) + 10)
|
||||
|
||||
|
||||
def make_warp(t_ramp, dur):
|
||||
"""film time -> scene time and back, the same integral as tour_10.js makeWarp"""
|
||||
dt = 1 / 480
|
||||
n = int((dur + 2) / dt)
|
||||
ts = [i * dt for i in range(n + 1)]
|
||||
tau = [0.0]
|
||||
for i in range(1, n + 1):
|
||||
mid = ts[i] - dt / 2
|
||||
bump = _smoother((mid - t_ramp - RAMP_A[0]) / (RAMP_A[1] - RAMP_A[0])) * (1 - _smoother((mid - t_ramp - RAMP_B[0]) / (RAMP_B[1] - RAMP_B[0])))
|
||||
tau.append(tau[-1] + (1 - (1 - RAMP_LOW) * bump) * dt)
|
||||
|
||||
def interp(x, xs, ys):
|
||||
if x <= xs[0]:
|
||||
return ys[0]
|
||||
if x >= xs[-1]:
|
||||
return ys[-1]
|
||||
j = bisect.bisect_right(xs, x) - 1
|
||||
k = (x - xs[j]) / (xs[j + 1] - xs[j])
|
||||
return ys[j] + (ys[j + 1] - ys[j]) * k
|
||||
|
||||
return (lambda x: interp(x, ts, tau)), (lambda y: interp(y, tau, ts))
|
||||
|
||||
|
||||
def score(mix, tl):
|
||||
dur = tl["duration"]
|
||||
t_exp = next((e["t"] for e in tl["script"] if e["act"] == "exploded"), 999.0)
|
||||
tau_at, film_at = make_warp(t_exp, dur)
|
||||
|
||||
left, right, low, drums = bed(dur, 96, CHORDS, MOTIF, motif_voice="blip", kicks=(0, 2.5), snares=(1, 3), hats=8, swing=0.08, keys_vel=0.75, keys_lp=3800)
|
||||
mix.put_stereo(0, left, right, 0.13)
|
||||
mix.put(0, low, 0.13)
|
||||
mix.put(0, drums, 0.05)
|
||||
bar = 4 * 60 / 96
|
||||
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.4, 1), (dur, 0)]), detune=0.8, tremolo=0.18, xfade=0.5)
|
||||
mix.put_stereo(0, pl, pr, 0.07)
|
||||
# the dive in from high on the left
|
||||
mix.put(0.0, airy(1.6, 2200, 700, 0.6), 0.024, pan=-0.35)
|
||||
|
||||
for e in tl["script"]:
|
||||
t, act = e["t"], e["act"]
|
||||
k0 = tau_at(t)
|
||||
|
||||
def at(dt, t0=k0):
|
||||
"""an offset in scene seconds after the click, in film time"""
|
||||
return film_at(t0 + dt)
|
||||
|
||||
mix.put(t, click(2400, 0.025), 0.055, pan=0.45)
|
||||
if act == "optics":
|
||||
for i, dt in enumerate((0.3, 0.48, 0.66, 0.84)):
|
||||
mix.put(at(dt), click(3200 - 200 * i, 0.018), 0.035, pan=0.2)
|
||||
for i, dt in enumerate((1.58, 1.71, 1.84)):
|
||||
mix.put(at(dt), click(2600 + 200 * i, 0.018), 0.03, pan=0.2)
|
||||
elif act == "wing":
|
||||
mix.put(at(0.2), airy(0.6, 600, 2200, 0.6), 0.025, pan=-0.3)
|
||||
mix.put(at(0.5), airy(0.95, 900, 1500, 0.5), 0.016, pan=-0.2)
|
||||
mix.put(at(1.92), click(1800, 0.03), 0.06, pan=-0.2)
|
||||
elif act in ("thorax", "abdomen"):
|
||||
mix.put(at(0.25), airy(0.8, 500, 1600, 0.6), 0.024)
|
||||
for i in range(4):
|
||||
mix.put(at(0.55 + 0.11 * i), click(3300 + 140 * i, 0.012), 0.02, pan=0.1 - 0.1 * i)
|
||||
mix.put(at(1.9 if act == "thorax" else 1.95), click(2100, 0.03), 0.055)
|
||||
elif act == "exploded":
|
||||
mix.put(at(0.2), airy(1.0, 500, 2600, 0.7), 0.032, pan=-0.15)
|
||||
mix.put(at(0.25), blip(hz("D6"), 0.3, 0.1), 0.024)
|
||||
# the ramp: a long falling air under the slowed parts, one low note as time stretches, slow glass ticks
|
||||
mix.put(t + RAMP_A[0], airy(RAMP_B[1] - RAMP_A[0] + 0.3, 1800, 450, 0.5), 0.022, pan=-0.1)
|
||||
mix.put(t + RAMP_A[1], blip(hz("D4"), 1.1, 0.5), 0.015)
|
||||
for i in range(6):
|
||||
mix.put(t + RAMP_A[1] + 0.22 * i, click(3600 - 150 * i, 0.012), 0.018, pan=0.4 - 0.16 * i)
|
||||
elif act == "assemble":
|
||||
mix.put(t, airy(0.8, 2200, 600, 0.5), 0.02, pan=-0.15)
|
||||
for i, dt in enumerate((0.45, 0.6, 0.75)):
|
||||
mix.put(at(dt), click(2000 + 300 * i, 0.03), 0.05, pan=0.3 - 0.3 * i)
|
||||
mix.put(at(0.7), airy(0.5, 400, 1300, 0.6), 0.016)
|
||||
elif act == "hero":
|
||||
mix.put(at(0.1), airy(0.7, 900, 1600, 0.5), 0.012, pan=-0.1)
|
||||
# the dart: a rising air that swells to the pass by the lens and swings right with it
|
||||
d0 = at(DEP)
|
||||
n = max(0.4, dur - d0)
|
||||
mix.put(d0, airy(n, 400, 3000, 0.7), 0.032, pan=0.15)
|
||||
mix.put(d0 + n * 0.7, airy(n * 0.3, 2600, 1200, 0.6), 0.03, pan=0.6)
|
||||
@@ -0,0 +1,121 @@
|
||||
// VESPION VX-9, the approved wasp film re-shot on the green page (entry wasp-film). Everything that moves comes
|
||||
// from this folder's tour_v2.js unchanged (the wasp, its flight, every assembly, every camera, the timing); what is new
|
||||
// is only the look: green for orange on the wasp, white paper with mint haze, and the green page from ../green instead
|
||||
// of the old console. The subject shifts by green/look.js SHIFT so it sits in the green page's 3D window.
|
||||
import {runSim} from '../kit/runtime.js';
|
||||
import {createConsole} from '../green/console.js';
|
||||
import {makeCursor, makeLabels, ORANGE_TO, PAPER_GREEN, retint, SHIFT} from '../green/look.js';
|
||||
import {buildBee} from './bee.js';
|
||||
import {PAL} from './parts.js';
|
||||
import {createStage, PAPER} from './stage.js';
|
||||
import {FLOOR_Y} from './tour.js';
|
||||
import {makeTour2, REACH} from './tour_v2.js';
|
||||
|
||||
const D2R = Math.PI / 180;
|
||||
|
||||
Object.assign(PAL, {orange: ORANGE_TO});
|
||||
Object.assign(PAPER, PAPER_GREEN);
|
||||
|
||||
const PAGE = {
|
||||
name: 'Vespion',
|
||||
code: 'VX-9',
|
||||
title: 'Robotic Wasp, Taken Apart',
|
||||
date: '2026-11-6',
|
||||
nav: [['overview', 'Overview'], ['optics', 'Optics'], ['wing', 'Wings'], ['leg', 'Legs'], ['thorax', 'Thorax'], ['abdomen', 'Abdomen'], ['exploded', 'Teardown'], ['hero', 'Release']],
|
||||
pills: [['optics', 'Optics'], ['wing', 'Wings'], ['leg', 'Legs'], ['thorax', 'Thorax'], ['abdomen', 'Abdomen'], ['exploded', 'Teardown'], ['hero', 'Release']],
|
||||
sub: {
|
||||
overview: ['Wingspan 2 × 180 mm', '6 legs · 2 camera eyes'],
|
||||
optics: ['Iris: 10 blades', 'Glass Ø 40 mm'],
|
||||
wing: ['Frosted film, 0.1 mm', 'Hinge: quick release'],
|
||||
leg: ['2 servos per leg', 'Foot: twin hooks'],
|
||||
thorax: ['3 spur gears', 'Flight CPU + IMU'],
|
||||
abdomen: ['5 telescoping bands', 'Glass stinger'],
|
||||
exploded: ['Every part apart', 'Turntable 330°'],
|
||||
hero: ['Wings to 7.5 Hz', 'Banking out'],
|
||||
},
|
||||
};
|
||||
// tour_v2's capital labels in the page's voice
|
||||
const TEXT = {
|
||||
'OUTER GLASS': ['Front glass', 'Ø 40 mm, AR coated'],
|
||||
'INNER ELEMENT': ['Inner element', 'Ø 15 mm'],
|
||||
IRIS: ['Iris', '10 blades, opens 3×'],
|
||||
'LENS BARREL': ['Lens barrel', 'threaded, 4 rings'],
|
||||
'WING MEMBRANE': ['Wing film', '0.1 mm, frosted'],
|
||||
'WING HINGE': ['Wing hinge', 'quick release'],
|
||||
'HINDWING HINGE': ['Hindwing hinge', 'phase +40°'],
|
||||
'HIP SERVO': ['Hip servo', 'yaw + lift'],
|
||||
'KNEE SERVO': ['Knee servo', '0.4 N·m'],
|
||||
'FOOT CLAW': ['Foot claw', 'twin hooks'],
|
||||
'SADDLE PLATE': ['Saddle plate', 'polymer shell'],
|
||||
'DRIVE GEAR STACK': ['Drive gears', '3 spur gears'],
|
||||
'ACTUATOR RING': ['Actuator ring', '11 pistons'],
|
||||
'CONTROL BOARDS': ['Flight boards', 'CPU + IMU'],
|
||||
'WAIST STALK': ['Waist stalk', '5 lit beads'],
|
||||
'SHELL BAND': ['Shell band', 'telescoping'],
|
||||
'BAND 4': ['Band 4', '5 riveted segments'],
|
||||
STINGER: ['Stinger', 'glass, extends 30 mm'],
|
||||
'OPTIC HEAD': ['Optic head', '2 lenses'],
|
||||
'NECK BEARING': ['Neck bearing', '10 segments'],
|
||||
'DRIVE GEARS': ['Drive gears', 'spinning free'],
|
||||
'ABDOMEN BANDS': ['Abdomen bands', '5 segments'],
|
||||
};
|
||||
const STATUS = {DIVING: 'Diving in', 'SLOW-MO': 'Slow motion', 'CLIMB-OUT': 'Climbing out', BANKING: 'Banking in', HOVER: 'Hovering', TEARDOWN: 'Teardown', REASSEMBLY: 'Reassembly', DEPARTING: 'Departing', 'OPTICS OPEN': 'Optics open', 'WING OFF': 'Wing off', 'LEG L2 OPEN': 'Leg open', 'THORAX OPEN': 'Thorax open', 'ABDOMEN OPEN': 'Abdomen open'};
|
||||
|
||||
export function makeWaspGreen(TL, {tour = makeTour2} = {}) {
|
||||
const T = tour(TL);
|
||||
return async ({canvas, capture}) => {
|
||||
const app = document.getElementById('app');
|
||||
const st = createStage({canvas, floorY: FLOOR_Y});
|
||||
const bee = buildBee();
|
||||
st.addBee(bee);
|
||||
retint(bee.root);
|
||||
bee.root.rotation.order = 'YXZ';
|
||||
const ui = createConsole(app, PAGE);
|
||||
const cursorAt = makeCursor(ui, T.SCRIPT);
|
||||
const labels = makeLabels(st, bee.anchors, TEXT);
|
||||
const fit = () => {
|
||||
const k = Math.min(innerWidth / 1600, innerHeight / 900);
|
||||
app.style.transform = `scale(${k})`;
|
||||
};
|
||||
const resize = () => {
|
||||
fit();
|
||||
st.resize(1600, 900, capture ? devicePixelRatio || 1 : Math.min(devicePixelRatio || 1, 2));
|
||||
};
|
||||
resize();
|
||||
window.WASP = {st, bee, T};
|
||||
return {
|
||||
resize,
|
||||
render(t) {
|
||||
const s = T.stateAt(t);
|
||||
bee.pose({explode: s.explode, flap: s.flap, flapAmp: s.amp, display: s.display, t: s.spinT, spinT: s.spinT, blur: 1, reach: REACH, sub: s.sub, eye: s.eye, wingOut: s.wingOut, wingFlip: s.wingFlip, legK: s.legK, stingK: s.stingK});
|
||||
retint(bee.root);
|
||||
const f = s.flight;
|
||||
bee.root.position.copy(f.pos);
|
||||
bee.root.rotation.set(f.roll * D2R, f.yaw * D2R, f.pitch * D2R);
|
||||
const c = s.cam;
|
||||
st.frame({...c, az: c.az * D2R, el: c.el * D2R, sx: c.sx + SHIFT[0], sy: c.sy + SHIFT[1]}, {guides: s.guides});
|
||||
const tel = T.telemetry(t, s);
|
||||
const v = s.view;
|
||||
const opening = Math.max(s.open?.[v] ?? 0, v === 'wing' ? s.wingOut : 0);
|
||||
ui.update({
|
||||
time: t,
|
||||
dur: TL.duration,
|
||||
status: STATUS[tel.status] ?? tel.status,
|
||||
freq: tel.freq,
|
||||
stroke: tel.stroke.map((p) => p[0]),
|
||||
lift: tel.lift,
|
||||
battery: tel.battery,
|
||||
servos: tel.servos,
|
||||
apart: Math.round(Math.max(opening, s.explode) * 100),
|
||||
view: v === 'intro' ? 'overview' : v,
|
||||
callouts: labels(tel.labelSet),
|
||||
cursor: cursorAt(t),
|
||||
});
|
||||
return {};
|
||||
},
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export const runWaspGreen = (TL, title = 'wasp-film', opts = {}) =>
|
||||
runSim({duration: TL.duration, fps: 60, theme: 'light', hud: {enabled: false, title, subtitle: ''}, director: {enabled: false}, watermark: ''}, makeWaspGreen(TL, opts));
|
||||
@@ -0,0 +1,344 @@
|
||||
// The robotic bee's stage: 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}) {
|
||||
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: -3.4, right: 3.4, top: 3.4, bottom: -3.4, near: 1, far: 16});
|
||||
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 = 4.2;
|
||||
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, size, floorY, project, setAOSkip, setQuality};
|
||||
}
|
||||
@@ -0,0 +1,363 @@
|
||||
// The HB-7 simulator tour: everything the console film needs from one script (the entry's timeline.json, {duration,
|
||||
// script: [{t, view | display, cam?}]}) as pure functions of film time t. The display toggles and their eased weights,
|
||||
// the motion they drive (the motor winding down before the explode, the reassembly, the wings spinning up, the
|
||||
// high-speed camera slowing playback to 0.2× when MOTION BLUR goes off), the cameras for the five views, the telemetry
|
||||
// the console shows (all read off the same motion, so the numbers agree with the picture), the labels and the
|
||||
// operator's pointer. The film (sim.js) and a later live page share it, the way cessna-shared/live.js reuses film.js.
|
||||
import * as THREE from 'three';
|
||||
import {DISPLAY, 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;
|
||||
|
||||
export const FLAP_HZ = 7.5;
|
||||
export const AMP = 32;
|
||||
export const REACH = 0.6;
|
||||
// bee units to millimetres (the body is 3 units, a 240 mm drone) and the floor under it
|
||||
const MM = 80;
|
||||
export const FLOOR_Y = -1.85;
|
||||
|
||||
// ------------------------------------------------------------ cameras (u = seconds since the view came on)
|
||||
// [az, el, d, tx, ty, tz, sx, sy]; the viewport sits a little above the canvas centre, hence sy
|
||||
export const VIEW_FN = {
|
||||
'hero:intro': (u) => {
|
||||
// from frame 0: an orbit round the front quarter and a push-in, the whole bee big the whole way
|
||||
const k = ss(-0.6, 3.6, u);
|
||||
return [lerp(82, 30, k), lerp(4, 11, k), lerp(9.4, 6.8, k), 0.1, -0.24, 0.25, -30, -14];
|
||||
},
|
||||
hero: (u) => [32 + 2.2 * u, 10, 7.6, -0.1, -0.28, 0.3, -40, -14],
|
||||
'hero:end': (u) => [24 + 2.6 * u, 8, 7.3, -0.05, -0.26, 0.28, -30, -14],
|
||||
front: (u) => [86 + 2 * u, 12, 7.8, 0.35, -0.28, 0.0, 0, -14],
|
||||
side: (u) => [3 + 2 * u, 7, 8.8, -0.2, -0.3, 0.0, 0, -14],
|
||||
// the near forewing from ahead and above: it spans the viewport, its face shows and its stroke sweeps up and down
|
||||
wing: (u) => [70 - 1.2 * u, 36, 6.6, 0.05, 0.22, 1.0, 0, -14],
|
||||
legs: (u) => [40 + 2 * u, 5, 6.8, 0.3, -0.62, 0.3, 0, -14],
|
||||
};
|
||||
const EASE = {labels: 0.5, xray: 0.8, exploded: 1.8, blur: 0.6, orbit: 1.4};
|
||||
const button = (key) => key.split(':')[0];
|
||||
|
||||
/** Everything from one tour. */
|
||||
export function makeTour(TL) {
|
||||
const SCRIPT = [...TL.script].sort((a, b) => a.t - b.t);
|
||||
const DURATION = TL.duration;
|
||||
const EVENTS = SCRIPT.filter((e) => e.t > 0).map((e) => e.t);
|
||||
const displayAt = (t) => {
|
||||
const out = Object.fromEntries(DISPLAY.map((k) => [k, 0]));
|
||||
for (const e of SCRIPT) if (e.display && e.t <= t) out[e.display] = out[e.display] ? 0 : 1;
|
||||
return out;
|
||||
};
|
||||
const lastFlip = (key, t) => SCRIPT.filter((e) => e.display === key && e.t <= t).pop()?.t ?? -99;
|
||||
const eased = (key, t) => {
|
||||
const on = displayAt(t)[key];
|
||||
const k = ss(lastFlip(key, t), lastFlip(key, t) + EASE[key], t);
|
||||
return on ? k : 1 - k;
|
||||
};
|
||||
// the motor and the teardown: EXPLODED on winds the beat down over 0.7 s, then the parts travel out over 1.8 s;
|
||||
// off brings them home over 1.8 s, then the beat spins back up over 0.7 s
|
||||
const motion = (t) => {
|
||||
const on = displayAt(t).exploded;
|
||||
const t0 = lastFlip('exploded', t);
|
||||
if (on) return {explode: ss(t0 + 0.5, t0 + 2.3, t), amp: AMP * (1 - ss(t0, t0 + 0.7, t))};
|
||||
if (t0 < -90) return {explode: 0, amp: AMP};
|
||||
return {explode: 1 - ss(t0, t0 + 1.8, t), amp: AMP * ss(t0 + 1.7, t0 + 2.4, t)};
|
||||
};
|
||||
// playback: 1× with the motion blur on, 0.2× (a high-speed capture) with it off; the bee's own clock integrates it,
|
||||
// and so does the energy the wings draw
|
||||
const rate = (t) => 1 - 0.8 * (1 - eased('blur', t));
|
||||
const DT = 1 / 240;
|
||||
const SIM = [0];
|
||||
const FLY = [0];
|
||||
for (let i = 1; i * DT <= DURATION + 1; i++) {
|
||||
const t = (i - 0.5) * DT;
|
||||
SIM.push(SIM[i - 1] + rate(t) * DT);
|
||||
FLY.push(FLY[i - 1] + (motion(t).amp / AMP) * rate(t) * DT);
|
||||
}
|
||||
const look = (A, t) => {
|
||||
const u = Math.max(0, Math.min(A.length - 2, t / DT));
|
||||
const i = Math.floor(u);
|
||||
return A[i] + (A[i + 1] - A[i]) * (u - i);
|
||||
};
|
||||
// before the film starts the bee was already flying at 1×
|
||||
const simT = (t) => (t < 0 ? t : look(SIM, t));
|
||||
const flyT = (t) => (t < 0 ? 0 : look(FLY, t));
|
||||
|
||||
// cameras: each view blends from the one before over 1.6 s; the explode pulls the camera back so the parts stay in
|
||||
// the viewport; the orbit's turn rate ramps in
|
||||
const VIEWS = SCRIPT.filter((e) => e.view).map((e) => ({t: e.t, key: e.cam ? `${e.view}:${e.cam}` : e.view}));
|
||||
// the orbit: on, it ramps into a steady 16°/s; off, it keeps the turn made so far and coasts to a stop
|
||||
const orbitTurn = (t) => {
|
||||
const f = lastFlip('orbit', t);
|
||||
if (f < -90) return 0;
|
||||
const R = EASE.orbit;
|
||||
const turned = (x) => 16 * (x < R ? (x * x) / (2 * R) : x - R / 2);
|
||||
if (displayAt(t).orbit) return turned(t - f);
|
||||
const on = SCRIPT.filter((e) => e.display === 'orbit' && e.t < f).pop();
|
||||
if (!on) return 0;
|
||||
const c = Math.min(t - f, R);
|
||||
return turned(f - on.t) + 16 * c * (1 - c / (2 * R));
|
||||
};
|
||||
const viewIdx = (t) => {
|
||||
let i = 0;
|
||||
while (i < VIEWS.length - 1 && VIEWS[i + 1].t <= t) i++;
|
||||
return i;
|
||||
};
|
||||
const blendCam = (a, b, k) => {
|
||||
const o = b.map((v, i) => lerp(a[i], v, k));
|
||||
const dAz = ((b[0] - a[0] + 540) % 360) - 180;
|
||||
o[0] = a[0] + dAz * k;
|
||||
const swing = Math.min(1, Math.abs(dAz) / 90);
|
||||
// every move dollies out a little on the way, so between two close views the bee never passes cut by the panels
|
||||
o[2] += Math.max(0, Math.max(a[2], b[2]) + 0.5 * swing + 1.4 - o[2]) * Math.sin(Math.PI * k);
|
||||
return o;
|
||||
};
|
||||
const camAt = (t) => {
|
||||
const i = viewIdx(t);
|
||||
const V = VIEWS[i];
|
||||
let o = VIEW_FN[V.key](t - V.t);
|
||||
if (i > 0) {
|
||||
const k = ss(V.t, V.t + 1.6, t);
|
||||
if (k < 1) o = blendCam(VIEW_FN[VIEWS[i - 1].key](t - VIEWS[i - 1].t), o, k);
|
||||
}
|
||||
const ex = motion(t).explode;
|
||||
o = [...o];
|
||||
o[2] *= 1 + 0.62 * ex;
|
||||
o[4] += 0.15 * ex;
|
||||
o[1] += 6 * ex;
|
||||
// the orbit's turn; once it is off, the next view blends it away
|
||||
let az = orbitTurn(t);
|
||||
if (!displayAt(t).orbit && V.t > lastFlip('orbit', t)) az *= 1 - ss(V.t, V.t + 1.6, t);
|
||||
o[0] += az;
|
||||
return {az: o[0], el: o[1], d: o[2], tx: o[3], ty: o[4], tz: o[5], sx: o[6], sy: o[7]};
|
||||
};
|
||||
const viewAt = (t) => {
|
||||
const V = VIEWS[viewIdx(t)];
|
||||
return [V.t, button(V.key)];
|
||||
};
|
||||
// labels wait 0.9 s into a view before they come in; on a view change the old ones fade out over 0.3 s
|
||||
const labelGate = (t) => {
|
||||
const i = viewIdx(t);
|
||||
const V = VIEWS[i];
|
||||
const g = ss(V.t + 0.9, V.t + 1.5, t);
|
||||
const prev = i > 0 ? ss(VIEWS[i - 1].t + 0.9, VIEWS[i - 1].t + 1.5, V.t) * (1 - ss(V.t, V.t + 0.3, t)) : 0;
|
||||
return Math.min(1, g + prev);
|
||||
};
|
||||
|
||||
/** The bee's state at film time t: pose parameters, hover, x-ray, guides, camera. */
|
||||
const stateAt = (t) => {
|
||||
const m = motion(t);
|
||||
const T = simT(t);
|
||||
const calm = 1 - Math.min(1, m.explode * 2.5);
|
||||
return {
|
||||
t,
|
||||
simT: T,
|
||||
explode: m.explode,
|
||||
amp: m.amp,
|
||||
flap: Math.PI * 2 * FLAP_HZ * T,
|
||||
display: 1 - m.amp / AMP,
|
||||
blur: eased('blur', t),
|
||||
rate: rate(t),
|
||||
xray: eased('xray', t),
|
||||
hover: {y: 0.05 * Math.sin(T * 2.6) * calm, pitch: 0.025 * Math.sin(T * 1.9 + 0.6) * calm, roll: 0.03 * Math.sin(T * 1.3 + 1.1) * calm, calm},
|
||||
guides: 0.45 + 0.55 * Math.max(Math.min(1, m.explode * 2.5), eased('xray', t)),
|
||||
cam: camAt(t),
|
||||
view: viewAt(t)[1],
|
||||
displays: displayAt(t),
|
||||
labels: eased('labels', t) * labelGate(t),
|
||||
};
|
||||
};
|
||||
|
||||
/** What the console shows at t, read off the same motion as the picture. */
|
||||
const telemetry = (t, s) => {
|
||||
const T = s.simT;
|
||||
const D = s.displays;
|
||||
// the stroke angle of the near forewing and hindwing over the last 1.2 s of film time
|
||||
const stroke = [];
|
||||
for (let i = 0; i <= 90; i++) {
|
||||
const tt = t - 1.2 + (i / 90) * 1.2;
|
||||
const a = motion(tt).amp;
|
||||
const ph = Math.PI * 2 * FLAP_HZ * simT(tt);
|
||||
stroke.push([a * Math.sin(ph), a * Math.sin(ph + 0.7)]);
|
||||
}
|
||||
const beat = ss(0.5, 6, s.amp);
|
||||
const fly = flyT(t);
|
||||
const power = 4.2 + 31 * Math.pow(s.amp / AMP, 1.5) * (1 + 0.04 * Math.sin(s.flap)) + 1.1 * s.hover.calm;
|
||||
const ex = s.explode > 0.04;
|
||||
// leg loads follow the hover: the legs take more as the bee decelerates at the bottom of each bob
|
||||
const acc = -Math.sin(T * 2.6);
|
||||
const servos = [0.44, 0.58, 0.49, 0.4, 0.53, 0.46].map((b, i) => (ex ? 0 : Math.max(0, Math.min(1, b * (1 + 0.32 * acc * (i % 3 === 1 ? 1.2 : 1)) + 0.03 * Math.sin(T * 7 + i)))));
|
||||
const reassembling = !D.exploded && s.explode > 0.04;
|
||||
const [status, statusKind] = D.exploded ? ['TEARDOWN', 'warn'] : reassembling ? ['REASSEMBLY', 'warn'] : s.blur < 0.5 ? ['HI-SPEED', 'warn'] : ['HOVER', 'ok'];
|
||||
const modeSub = D.exploded
|
||||
? `EXPLODED VIEW · ${Math.round(s.explode * 100)}% · 128 PARTS`
|
||||
: reassembling
|
||||
? 'PARTS SEATING · MOTOR ARMED'
|
||||
: s.blur < 0.5
|
||||
? 'CAPTURE 2000 FPS · 0.2× PLAYBACK'
|
||||
: `STATION KEEPING · ${((s.hover.y - FLOOR_Y) * MM).toFixed(0)} MM AGL`;
|
||||
const last = SCRIPT.filter((e) => e.t > 0 && e.t <= t).pop();
|
||||
const say = (e) => (e.view ? `VIEW → ${button(e.view).toUpperCase()}` : `${e.display === 'blur' ? 'MOTION BLUR' : e.display === 'xray' ? 'X-RAY' : e.display.toUpperCase()} ${displayAt(e.t + 0.001)[e.display] ? 'ON' : 'OFF'}`);
|
||||
const sub = (i) => {
|
||||
if (ex && i !== 3) return ['warn', 'DETACHED'];
|
||||
if (i === 0) return ['ok', 'TRACKING'];
|
||||
if (i === 1) return ['ok', 'LOCKED'];
|
||||
if (i === 2) return s.xray > 0.5 ? ['warn', 'EXPOSED'] : s.amp > 1 ? ['ok', 'RUNNING'] : ['idle', 'STOPPED'];
|
||||
if (i === 3) return ex ? ['warn', 'DETACHED'] : s.blur < 0.5 ? ['warn', 'HI-SPEED'] : s.amp > 1 ? ['ok', `${FLAP_HZ} HZ`] : ['idle', 'PARKED'];
|
||||
if (i === 4) return ['ok', 'HOLDING'];
|
||||
return s.xray > 0.5 ? ['warn', 'EXPOSED'] : ['ok', 'SEALED'];
|
||||
};
|
||||
const focus = s.view === 'wing' ? 3 : s.view === 'legs' ? 4 : s.view === 'front' ? 0 : s.xray > 0.5 ? 2 : -1;
|
||||
return {
|
||||
time: t,
|
||||
dur: DURATION,
|
||||
lift: Math.max(0, (s.amp / AMP) * (0.68 + 0.02 * Math.sin(s.flap))),
|
||||
status,
|
||||
statusKind,
|
||||
freq: FLAP_HZ * beat,
|
||||
amp: s.amp,
|
||||
stroke,
|
||||
playback: s.rate,
|
||||
blur: s.blur,
|
||||
battery: 0.842 - 0.0024 * fly,
|
||||
power,
|
||||
volt: 3.92 - 0.006 * power,
|
||||
motorT: 34 + 7 * Math.min(1, fly / 20) + 0.08 * power,
|
||||
servos,
|
||||
legsFree: ex,
|
||||
airborne: !ex,
|
||||
alt: (s.hover.y - FLOOR_Y) * MM,
|
||||
vs: MM * 0.05 * 2.6 * Math.cos(T * 2.6) * s.hover.calm * s.rate,
|
||||
pitch: (s.hover.pitch * 180) / Math.PI,
|
||||
roll: (s.hover.roll * 180) / Math.PI,
|
||||
airspeed: Math.abs(MM * 0.05 * 2.6 * Math.cos(T * 2.6) * s.hover.calm * s.rate) / 1000 + 0.004 * s.hover.calm,
|
||||
view: s.view,
|
||||
display: D,
|
||||
subs: [0, 1, 2, 3, 4, 5].map(sub),
|
||||
focus,
|
||||
events: EVENTS,
|
||||
next: `${EVENTS.length} OPERATOR ACTIONS`,
|
||||
log: last ? `OPERATOR · ${say(last)}` : 'AUTO-HOVER · STATION KEEPING',
|
||||
mode: status,
|
||||
modeSub,
|
||||
};
|
||||
};
|
||||
|
||||
return {SCRIPT, DURATION, EVENTS, displayAt, eased, motion, simT, camAt, viewAt, stateAt, telemetry};
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ labels
|
||||
const V3 = THREE.Vector3;
|
||||
const GENERAL = [
|
||||
['lens', 'OPTIC LENS', '18 MM · AMBER IR PUPIL'],
|
||||
['antenna', 'ANTENNA', 'AIRFLOW + SCENT SENSOR'],
|
||||
['collar', 'NECK BEARING', '10-SEGMENT COLLAR'],
|
||||
['hinge', 'WING HINGE', '7.5 HZ CRANK · ±32°'],
|
||||
['gears', 'DRIVE GEAR STACK', '3 SPUR GEARS'],
|
||||
['core', 'CONTROL BOARDS', 'FLIGHT CPU · IMU'],
|
||||
['pad', 'SHOULDER PAD', 'POLYMER SHELL'],
|
||||
['knee2', 'LEG SERVO', 'KNEE · 0.4 N·M'],
|
||||
['capsule', 'ABDOMEN CAPSULE', 'GEAR TRAIN · SPRING'],
|
||||
['sting', 'POLLEN PROBE', 'RETRACTABLE TIP'],
|
||||
];
|
||||
const LEGSET = [
|
||||
['hip1', 'HIP SERVO', 'YAW + LIFT'],
|
||||
['knee1', 'KNEE SERVO L1', '0.4 N·M'],
|
||||
['knee2', 'KNEE SERVO L2', '0.4 N·M'],
|
||||
['knee3', 'KNEE SERVO L3', '0.4 N·M'],
|
||||
['foot', 'FOOT WHEEL', 'GRIP PAD'],
|
||||
['pad', 'SHOULDER PAD', 'POLYMER SHELL'],
|
||||
['core', 'CONTROL BOARDS', 'SERVO DRIVERS'],
|
||||
];
|
||||
const WINGSET = [
|
||||
['hinge', 'WING HINGE', '7.5 HZ CRANK · ±32°'],
|
||||
['wing', 'WING MEMBRANE', 'FROSTED FILM · 0.1 MM'],
|
||||
['hinge2', 'HINDWING HINGE', 'PHASE +40°'],
|
||||
['antenna', 'ANTENNA', 'AIRFLOW + SCENT SENSOR'],
|
||||
['gears', 'DRIVE GEAR STACK', '3 SPUR GEARS'],
|
||||
];
|
||||
/** Labels for a view, in two columns at the viewport's edges, stacked by height so no two touch. */
|
||||
export function makeLabels(st, bee) {
|
||||
const p = new V3();
|
||||
return (view, o) => {
|
||||
if (o < 0.02) return [];
|
||||
const set = view === 'legs' ? LEGSET : view === 'wing' ? WINGSET : GENERAL;
|
||||
const pts = [];
|
||||
for (const [key, name, sub] of set) {
|
||||
const A = bee.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 Lc = pts.filter((x) => x.at[0] < mid).sort((a, b) => a.at[1] - b.at[1]);
|
||||
const Rc = pts.filter((x) => x.at[0] >= mid).sort((a, b) => a.at[1] - b.at[1]);
|
||||
const out = [];
|
||||
const stack = (col, x, w) => {
|
||||
let y = VIEWPORT.y0 + 48;
|
||||
// start low enough that the column ends above the flight-mode word
|
||||
y = Math.max(y, Math.min(col.length ? col[0].at[1] - 10 : y, 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(Lc, VIEWPORT.x0 + 16, 168);
|
||||
stack(Rc, VIEWPORT.x1 - 160, 150);
|
||||
return out;
|
||||
};
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------ the operator's pointer (after cessna-shared/film_v2.js)
|
||||
// It reaches each button 0.1 s before the press, leaves 0.2 s after, travels in an eased bow, and between distant
|
||||
// presses waits in the gutter left of the right-hand panels, never over the bee.
|
||||
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[e.view ?? e.display]}));
|
||||
const first = EV[0].spot;
|
||||
const WP = [[0, GUTTER_X, first[1] + 60]];
|
||||
let [px, py, pt] = [GUTTER_X, first[1] + 60, 0];
|
||||
EV.forEach((e, n) => {
|
||||
const [x, y] = e.spot;
|
||||
const travel = Math.min(0.75, 0.32 + Math.hypot(x - px, y - py) / 900);
|
||||
const arrive = e.t - 0.1;
|
||||
if (arrive - travel - pt > 1.6) {
|
||||
const rest = [GUTTER_X, Math.max(170, Math.min(720, y + 40))];
|
||||
WP.push([pt + 0.75, ...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.2, x, y]);
|
||||
[px, py, pt] = [x, y, e.t + 0.2];
|
||||
const next = EV[n + 1];
|
||||
if (!next || next.t - 0.1 - 0.75 - pt > 0.9) {
|
||||
[px, py, pt] = [GUTTER_X, y + 12, pt + 0.6];
|
||||
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};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,368 @@
|
||||
// The Vespion VX-9 wasp's 10-second demo (entry wasp-demo), made 2026-11-06 for the article: the bee's 18-second
|
||||
// film (robobee-shared/tour_18.js) carried onto the wasp (its tour_v2.js differences: the sting, the abdomen camera's
|
||||
// target, the labels) and cut down to one assembly. What it runs:
|
||||
// - the opening: the wasp dives in from high on the left, banking, and flares nose-up as it brakes;
|
||||
// - one assembly, the WING: pulled out of its hinge and turned over in the air;
|
||||
// - the explode in slow motion (0.4x while the parts leave), the camera passing low under them, a full 360 deg
|
||||
// turntable and a push-in for the reassembly;
|
||||
// - the exit: the wasp turns a little toward the lens, noses up and climbs straight out of the top of the frame.
|
||||
// The speed ramp is a warp of film time t into scene time tau (tauAt), so everything stays a pure function of t.
|
||||
import * as THREE from 'three';
|
||||
import {FLOOR_Y} from './tour.js';
|
||||
import {AMP, ASSEMBLY_LABEL, FLAP_HZ} from './tour_v2.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 bump = (a, b, c, d, t) => ss(a, b, t) * (1 - ss(c, d, t));
|
||||
const D2R = Math.PI / 180;
|
||||
const MM = 80;
|
||||
const S = 1.15;
|
||||
|
||||
// each act's own clock in scene seconds after its click, a beat every 2.2 s
|
||||
export const ACT_R = {
|
||||
optics: {open: [0.25, 1.05], close: [1.55, 1.9], stop: false},
|
||||
wing: {open: [0.2, 0.75], close: [1.6, 1.95], stop: true},
|
||||
thorax: {open: [0.25, 1.0], close: [1.5, 1.9], stop: true},
|
||||
abdomen: {open: [0.25, 1.0], close: [1.55, 1.95], stop: true},
|
||||
};
|
||||
// the pulled wing turns over once while it hangs out of its hinge
|
||||
export const WING_FLIP = [0.45, 1.45];
|
||||
// the ramp in film seconds after the EXPLODED click: down to 0.4x as the parts start to leave, held while they drift
|
||||
// apart, back up as the turntable takes over
|
||||
export const RAMP = {a: [0.35, 0.55], b: [1.9, 2.1], low: 0.4};
|
||||
// the climb starts this long after HERO (scene seconds)
|
||||
export const DEP = 0.75;
|
||||
// the hero camera, low on the front-right so the climb reads against the paper above
|
||||
const HERO_AZ = 32;
|
||||
const HERO_EL = 4;
|
||||
const HERO_D = 7.8;
|
||||
|
||||
export function makeWarp(tRamp, dur) {
|
||||
const rate = (t) => 1 - (1 - RAMP.low) * bump(tRamp + RAMP.a[0], tRamp + RAMP.a[1], tRamp + RAMP.b[0], tRamp + RAMP.b[1], t);
|
||||
const DT = 1 / 480;
|
||||
const TAU = [0];
|
||||
for (let i = 1; i * DT <= dur + 2; i++) TAU.push(TAU[i - 1] + rate((i - 0.5) * DT) * DT);
|
||||
const tauAt = (t) => {
|
||||
if (t <= 0) return t;
|
||||
const u = Math.min(TAU.length - 2, t / DT);
|
||||
const i = Math.floor(u);
|
||||
return TAU[i] + (TAU[i + 1] - TAU[i]) * (u - i);
|
||||
};
|
||||
return {rate, tauAt};
|
||||
}
|
||||
|
||||
export function make10Tour(TL) {
|
||||
const SCRIPT = [...TL.script].sort((a, b) => a.t - b.t);
|
||||
const DURATION = TL.duration;
|
||||
const EVENTS = SCRIPT.map((e) => e.t);
|
||||
const tfOf = (act) => (SCRIPT.find((e) => e.act === act) ?? {t: 999}).t;
|
||||
const tfExp = tfOf('exploded');
|
||||
const tfAsm = tfOf('assemble');
|
||||
const {rate, tauAt} = makeWarp(tfExp, DURATION);
|
||||
const AT = {};
|
||||
for (const e of SCRIPT) (AT[e.act] ??= []).push(tauAt(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_FIRST = Math.min(...Object.keys(ACT_R).flatMap((a) => at(a)), 999);
|
||||
|
||||
const openOf = (act, x) => {
|
||||
let v = 0;
|
||||
for (const t0 of at(act)) {
|
||||
const A2 = ACT_R[act];
|
||||
v = Math.max(v, bump(t0 + A2.open[0], t0 + A2.open[1], t0 + A2.close[0], t0 + A2.close[1], x));
|
||||
}
|
||||
return v;
|
||||
};
|
||||
const explodeAt = (x) => ss(T_EXP + 0.2, T_EXP + 1.5, x) * (1 - ss(T_ASM, T_ASM + 0.8, x));
|
||||
// the turntable: a full +360 deg from the explode to just after the bee is whole again
|
||||
const TT = [T_EXP + 0.2, T_ASM + 1.2];
|
||||
const turnAt = (x) => {
|
||||
const [a, b] = TT;
|
||||
if (x <= a) return 0;
|
||||
const R = 0.5;
|
||||
const span = b - a;
|
||||
const v = 360 / (span - R);
|
||||
const y0 = Math.min(x, b) - a;
|
||||
if (y0 < R) return (v * y0 * y0) / (2 * R);
|
||||
if (y0 < span - R) return v * (y0 - R / 2);
|
||||
const y = y0 - (span - R);
|
||||
return v * (span - 1.5 * R) + v * y - (v * y * y) / (2 * R);
|
||||
};
|
||||
// the wings park for the acts that need still wings and for the explode; when the next act parks them too they stay
|
||||
// parked across the cut instead of spinning up for a moment between
|
||||
const STOPS = [];
|
||||
SCRIPT.forEach((e, n) => {
|
||||
const A2 = ACT_R[e.act];
|
||||
if (!A2?.stop) return;
|
||||
const t0 = tauAt(e.t);
|
||||
const nx = SCRIPT[n + 1];
|
||||
const hold = nx && (ACT_R[nx.act]?.stop || nx.act === 'exploded') ? tauAt(nx.t) - t0 + 0.4 : A2.close[1];
|
||||
STOPS.push([t0, t0 + 0.35, t0 + hold, t0 + hold + 0.45]);
|
||||
});
|
||||
STOPS.push([T_EXP, T_EXP + 0.4, T_ASM + 0.7, T_ASM + 1.2]);
|
||||
const stopAt = (x) => Math.max(0, ...STOPS.map((w) => bump(w[0], w[1], w[2], w[3], x)));
|
||||
const activity = (x) => Math.max(...Object.keys(ACT_R).map((a) => openOf(a, x)), explodeAt(x));
|
||||
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, x) => {
|
||||
const u = Math.max(0, Math.min(A2.length - 2, x / DT));
|
||||
const i = Math.floor(u);
|
||||
return A2[i] + (A2[i + 1] - A2[i]) * (u - i);
|
||||
};
|
||||
const spinAt = (x) => (x < 0 ? x : look(SPIN, x));
|
||||
|
||||
// the bee: dives in from high on the left banking, flares nose-up and hovers through the teardowns, turns on the
|
||||
// explode turntable, turns a little toward the lens on HERO and climbs out of the top of the frame
|
||||
const flightAt = (x) => {
|
||||
const kIn = ss(-0.9, 1.6, x);
|
||||
const ex = explodeAt(x);
|
||||
const calm = 1 - Math.min(1, ex * 2.5);
|
||||
const path = new THREE.Vector3(lerp(-0.8 * S, 0, kIn), lerp(1.0 * S, 0, kIn), lerp(0.45 * S, 0, kIn));
|
||||
let yaw = lerp(-24, 0, kIn);
|
||||
let roll = 28 * Math.sin(Math.PI * Math.min(1, kIn * 1.05)) - 7 * Math.sin(2 * Math.PI * kIn) * kIn + 1.7 * Math.sin(x * 1.3 + 1.1) * calm;
|
||||
let pitch = -16 * (1 - kIn) + 10 * Math.sin(Math.PI * ss(0.55, 1.0, kIn)) + 1.4 * Math.sin(x * 1.9 + 0.6) * calm;
|
||||
yaw += turnAt(x);
|
||||
// HERO: the wasp turns a little toward the lens and lifts its nose, then climbs straight up out of the frame,
|
||||
// pitching up into the climb with one roll
|
||||
const kH = ss(T_END, T_END + 0.8, x);
|
||||
yaw -= 22 * kH;
|
||||
pitch += 8 * kH;
|
||||
roll += 10 * Math.sin(Math.PI * kH);
|
||||
if (x > T_END + DEP) {
|
||||
const u = x - T_END - DEP;
|
||||
const k = ss(0, 0.6, u);
|
||||
pitch += 24 * k;
|
||||
roll -= 12 * Math.sin(Math.PI * ss(0, 1.3, u));
|
||||
path.y += 0.7 * u + 1.8 * u * u;
|
||||
path.x += 0.3 * u * u;
|
||||
}
|
||||
const pos = path.clone().add(new THREE.Vector3(0, 0.05 * Math.sin(x * 2.6) * calm, 0));
|
||||
return {pos, path, yaw, roll, pitch, calm};
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------ cameras: [az, el, d, tx, ty, tz, sx, sy]
|
||||
// az from the right flank (0) toward the face (90); the hero side is about 20-40. The teardown targets and drift
|
||||
// rates are the second cut's.
|
||||
const macro = (act, u, depth = 0.12) => {
|
||||
const A2 = ACT_R[act];
|
||||
return 1 - depth * bump(A2.open[1] - 0.35, A2.open[1] + 0.1, A2.close[0] - 0.1, A2.close[1], u);
|
||||
};
|
||||
const push = (a, b, u, end = 1.9) => lerp(a, b, ss(0, end, u));
|
||||
const EXP_SPAN_F = tfAsm - tfExp;
|
||||
const CAM = {
|
||||
// the dive: the camera comes down from above with the bee, pushing in
|
||||
intro: (u) => {
|
||||
const k = ss(0, 2.0, u);
|
||||
return [lerp(46, 34, k), lerp(22, 10, k), lerp(7.9, 7.4, k), 0.0, -0.2, 0.25, -20, -14];
|
||||
},
|
||||
// the lens from the face side, so the barrel unscrews sideways across the frame
|
||||
optics: (u) => [90 - 9 * u, 6, push(4.9, 4.3, u) * macro('optics', u, 0.07), 1.22, 0.12, 0.45, 0, -14],
|
||||
// the wing from the hero side, rising with it as it leaves the hinge and turns over
|
||||
wing: (u) => {
|
||||
const k = ss(0, 1.9, u);
|
||||
return [38 + 9 * k, lerp(12, 22, k), push(8.8, 7.8, u), -0.5, 0.95, 1.25, 0, -14];
|
||||
},
|
||||
// the thorax from high over the near flank
|
||||
thorax: (u) => [6 + 10 * u, 34, push(6.9, 6.0, u) * macro('thorax', u), 0.0, 0.32, 0.05, 0, -14],
|
||||
// the abdomen from behind the near flank as it telescopes out
|
||||
abdomen: (u) => [-32 + 10 * u, 14, push(6.8, 5.9, u) * macro('abdomen', u, 0.08), -2.45, -0.95, 0.1, 0, -14],
|
||||
// the explode, on FILM time (u = film seconds since the click): while the ramp holds the parts at 0.4x the camera
|
||||
// keeps its own speed and swings round low under them looking up, then rises over the turntable and pushes in for
|
||||
// the reassembly
|
||||
exploded: (u) => {
|
||||
const arc = ss(0.45, 2.0, u);
|
||||
const rise = ss(1.9, 2.9, u);
|
||||
const near = ss(EXP_SPAN_F - 0.3, EXP_SPAN_F + 0.9, u);
|
||||
return [24 + 32 * arc - 14 * rise, lerp(10, -2, arc) + 20 * rise, lerp(11.4, 12.0, arc) - 3.6 * near, 0.0, lerp(-0.15, 0.05, arc) * (1 - rise) - 0.15 * rise, 0.0, -10, -14];
|
||||
},
|
||||
// HERO: low on the front-right, holding still while the wasp turns and climbs out
|
||||
hero: (u) => {
|
||||
const k = ss(0, 0.9, u);
|
||||
return [lerp(42, HERO_AZ, k), lerp(18, HERO_EL, k), lerp(8.4, HERO_D, k), 0.0, -0.15, 0.25, -14, -14];
|
||||
},
|
||||
};
|
||||
|
||||
const VIEWS = [{t: -1, tf: -1, key: 'intro'}, ...SCRIPT.map((e) => ({t: tauAt(e.t), tf: e.t, key: e.act === 'assemble' ? 'exploded' : e.act}))];
|
||||
const viewIdx = (x) => {
|
||||
let i = 0;
|
||||
while (i < VIEWS.length - 1 && VIEWS[i + 1].t <= x) i++;
|
||||
return i;
|
||||
};
|
||||
// ASSEMBLE runs on the EXPLODED view's clock, so both read as one continuous shot (and HERO blends out of it)
|
||||
const resolve = (i) => (VIEWS[i].key === 'exploded' && i > 0 && VIEWS[i - 1].key === 'exploded' ? VIEWS[i - 1] : VIEWS[i]);
|
||||
const camFn = (V, x, t) => CAM[V.key](V.key === 'intro' ? x : V.key === 'exploded' ? t - V.tf : x - V.t);
|
||||
const camAt = (x, t) => {
|
||||
const i = viewIdx(x);
|
||||
let o = camFn(resolve(i), x, t);
|
||||
if (i > 0 && resolve(i) === VIEWS[i]) {
|
||||
const k = ss(VIEWS[i].t, VIEWS[i].t + 0.7, x);
|
||||
if (k < 1) {
|
||||
const a = camFn(resolve(i - 1), x, 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.5 * Math.sin(Math.PI * k);
|
||||
o = b;
|
||||
}
|
||||
}
|
||||
const f = flightAt(x);
|
||||
// the camera follows the wasp's path, and on the climb lets go sideways and follows the rise a third of the way
|
||||
const kOut = ss(T_END + DEP - 0.2, T_END + DEP + 0.5, x);
|
||||
const kIn = 1 - ss(0.2, 1.9, x);
|
||||
const tr = (0.85 - 0.3 * kIn) * (1 - kOut);
|
||||
const trY = (0.85 - 0.35 * kIn) * (1 - 0.65 * kOut);
|
||||
return {az: o[0], el: o[1], d: o[2], tx: o[3] + f.path.x * tr, ty: o[4] + f.path.y * trY, tz: o[5] + f.path.z * tr, sx: o[6], sy: o[7]};
|
||||
};
|
||||
const actAt = (x) => VIEWS[viewIdx(x)].key;
|
||||
|
||||
const stateAt = (t) => {
|
||||
const x = tauAt(t);
|
||||
const ex = explodeAt(x);
|
||||
const amp = AMP * (1 - stopAt(x));
|
||||
const f = flightAt(x);
|
||||
const open = Object.fromEntries(Object.keys(ACT_R).map((a) => [a, openOf(a, x)]));
|
||||
let wingFlip = 0;
|
||||
for (const t0 of at('wing')) wingFlip = Math.max(wingFlip, ss(t0 + WING_FLIP[0], t0 + WING_FLIP[1], x));
|
||||
if (wingFlip >= 1) wingFlip = 0;
|
||||
// the sting: out of its collar once the abdomen hangs open, back in before it closes
|
||||
let stingK = 0;
|
||||
for (const t0 of at('abdomen')) stingK = Math.max(stingK, ss(t0 + 0.75, t0 + 1.15, x) * (1 - ss(t0 + 1.4, t0 + 1.6, x)));
|
||||
return {
|
||||
t,
|
||||
tau: x,
|
||||
rate: rate(t),
|
||||
spinT: spinAt(x),
|
||||
explode: ex,
|
||||
amp,
|
||||
flap: Math.PI * 2 * FLAP_HZ * x,
|
||||
display: 1 - amp / AMP,
|
||||
blur: 1,
|
||||
sub: {thorax: open.thorax, abdomen: open.abdomen},
|
||||
eye: open.optics,
|
||||
wingOut: open.wing,
|
||||
wingFlip,
|
||||
stingK,
|
||||
legK: 0,
|
||||
open,
|
||||
flight: f,
|
||||
cam: camAt(x, t),
|
||||
view: actAt(x),
|
||||
guides: 0.45 + 0.55 * Math.min(1, ex * 2.5 + activity(x)),
|
||||
turn: turnAt(x),
|
||||
};
|
||||
};
|
||||
|
||||
// labels: on while the act's parts are moving apart and while they hang open, gone before they close
|
||||
const LABELS = {
|
||||
optics: [['eyeGlass', 'OUTER GLASS', 'Ø 40 MM · AR COATED'], ['eyeInner', 'INNER ELEMENT', 'Ø 15 MM'], ['iris', 'IRIS', '10 BLADES · OPENS 3×'], ['barrel', 'LENS BARREL', 'THREADED · 4 RINGS']],
|
||||
wing: [['wing', 'WING MEMBRANE', 'FROSTED FILM · 0.1 MM'], ['hinge', 'WING HINGE', 'QUICK RELEASE'], ['hinge2', 'HINDWING HINGE', 'PHASE +40°']],
|
||||
thorax: [['plate', 'SADDLE PLATE', 'POLYMER SHELL'], ['gears', 'DRIVE GEAR STACK', '3 SPUR GEARS'], ['act', 'ACTUATOR RING', '11 PISTONS'], ['core', 'CONTROL BOARDS', 'FLIGHT CPU · IMU']],
|
||||
abdomen: [['waist', 'WAIST STALK', '5 BEADS · LIT RINGS'], ['s1', 'SHELL BAND', 'TELESCOPING'], ['capsule', 'BAND 4', 'RIVETED · 5 SEGMENTS'], ['sting', 'STINGER', 'GLASS · EXTENDS 30 MM']],
|
||||
exploded: [['lens', 'OPTIC HEAD', '2 × LENS'], ['collar', 'NECK BEARING', '10 SEGMENTS'], ['gears', 'DRIVE GEARS', 'SPINNING FREE'], ['capsule', 'ABDOMEN BANDS', '5 SEGMENTS'], ['hinge', 'WING HINGE', 'QUICK RELEASE']],
|
||||
};
|
||||
const labelAt = (x, s) => {
|
||||
const v = s.view;
|
||||
if (ACT_R[v]) {
|
||||
const t0 = at(v).filter((y) => y <= x).pop();
|
||||
const A2 = ACT_R[v];
|
||||
return {set: LABELS[v], o: bump(t0 + A2.open[0] + 0.1, t0 + A2.open[0] + 0.4, t0 + A2.close[0] - 0.25, t0 + A2.close[0], x)};
|
||||
}
|
||||
if (v === 'exploded') return {set: LABELS.exploded, o: bump(T_EXP + 0.4, T_EXP + 0.8, T_EXP + 1.6, T_EXP + 1.9, x)};
|
||||
return {set: [], o: 0};
|
||||
};
|
||||
|
||||
const telemetry = (t, s) => {
|
||||
const x = s.tau;
|
||||
const f = s.flight;
|
||||
const stroke = [];
|
||||
for (let i = 0; i <= 90; i++) {
|
||||
const tt = x - 1.2 + (i / 90) * 1.2;
|
||||
const a = AMP * (1 - stopAt(tt));
|
||||
const ph = Math.PI * 2 * FLAP_HZ * tt;
|
||||
stroke.push([a * Math.sin(ph), a * Math.sin(ph + 0.7)]);
|
||||
}
|
||||
const ex = s.explode > 0.04;
|
||||
const acc = -Math.sin(x * 2.6);
|
||||
const free = [0, 1, 2, 3, 4, 5].map(() => ex);
|
||||
const servos = [0.44, 0.58, 0.49, 0.4, 0.53, 0.46].map((b, i) => (free[i] ? 0 : Math.max(0, Math.min(1, b * (1 + 0.32 * acc) + 0.12 * Math.abs(f.roll) / 30 + 0.03 * Math.sin(x * 7 + i)))));
|
||||
const v = s.view;
|
||||
const opening = ACT_R[v] ? s.open[v] : 0;
|
||||
const NAME = {optics: 'OPTICS OPEN', wing: 'WING OFF', thorax: 'THORAX OPEN', abdomen: 'ABDOMEN OPEN'};
|
||||
const dartU = x - T_END - DEP;
|
||||
const darting = dartU > 0;
|
||||
let status = 'HOVER';
|
||||
let kind = 'ok';
|
||||
if (x < T_FIRST) status = 'DIVING';
|
||||
if (ACT_R[v] && opening > 0.05) [status, kind] = [NAME[v], 'warn'];
|
||||
if (v === 'exploded') [status, kind] = s.rate < 0.9 ? ['SLOW-MO', 'warn'] : x < T_ASM ? ['TEARDOWN', 'warn'] : s.explode > 0.04 ? ['REASSEMBLY', 'warn'] : ['HOVER', 'ok'];
|
||||
if (darting) status = 'CLIMB-OUT';
|
||||
const ROW = {optics: 0, thorax: 2, wing: 3, leg: 4, abdomen: 5};
|
||||
const sub = (i) => {
|
||||
if (ex) return ['warn', 'DETACHED'];
|
||||
if (ROW[v] === i && opening > 0.05) return ['warn', i === 3 ? 'DETACHED' : 'OPEN'];
|
||||
if (i === 3) return s.amp > 1 ? ['ok', `${FLAP_HZ} HZ`] : ['idle', 'PARKED'];
|
||||
if (i === 2) return s.amp > 1 ? ['ok', 'RUNNING'] : ['idle', 'STOPPED'];
|
||||
return ['ok', ['TRACKING', 'LOCKED', '', '', 'HOLDING', '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 · CLIMB-OUT' : `ISOLATE ${ASSEMBLY_LABEL[e.act]}`);
|
||||
const sp = darting ? 0.4 + 1.2 * (1.2 + 3 * dartU) : f.pos.length() > 0.05 ? 0.4 + 0.2 * Math.abs(Math.sin(x)) : 0.004;
|
||||
const labels = labelAt(x, s);
|
||||
return {
|
||||
time: t,
|
||||
dur: DURATION,
|
||||
lift: Math.max(0, (s.amp / AMP) * (0.68 + 0.02 * Math.sin(s.flap)) + 0.12 * Math.abs(f.roll) / 30),
|
||||
status,
|
||||
statusKind: kind,
|
||||
freq: FLAP_HZ * ss(0.5, 6, s.amp),
|
||||
amp: s.amp,
|
||||
stroke,
|
||||
playback: s.rate,
|
||||
blur: 1,
|
||||
battery: 0.842 - 0.0022 * t,
|
||||
power: 4.2 + 31 * Math.pow(s.amp / AMP, 1.5) * (1 + 0.04 * Math.sin(s.flap)) + 3 * Math.abs(f.roll) / 30 + (darting ? 9 * ss(0, 0.5, dartU) : 0),
|
||||
volt: 3.92 - 0.006 * 36,
|
||||
motorT: 34 + 0.35 * t,
|
||||
servos,
|
||||
legsFree: ex,
|
||||
legFreeEach: free,
|
||||
airborne: true,
|
||||
alt: (f.pos.y - FLOOR_Y) * MM,
|
||||
vs: x < T_FIRST ? -MM * S * (ss(-0.9, 1.6, x + 0.05) - ss(-0.9, 1.6, x - 0.05)) * 10 : MM * 0.05 * 2.6 * Math.cos(x * 2.6) * f.calm,
|
||||
pitch: f.pitch,
|
||||
roll: f.roll,
|
||||
airspeed: sp,
|
||||
view: v === 'intro' ? 'hero' : v === 'exploded' ? null : v,
|
||||
display: {labels: labels.o > 0.5, exploded: x >= T_EXP && x < T_ASM, blur: s.amp > 3, turntable: s.turn > 0.5 && x < TT[1]},
|
||||
subs: [0, 1, 2, 3, 4, 5].map(sub),
|
||||
focus: ROW[v] ?? (v === 'exploded' ? 1 : -1),
|
||||
events: EVENTS,
|
||||
next: `${EVENTS.length} OPERATOR ACTIONS`,
|
||||
log: last ? `OPERATOR · ${say(last)}` : 'INBOUND · DIVING · BANK LEFT',
|
||||
mode: status,
|
||||
modeSub:
|
||||
status === 'DIVING'
|
||||
? `BANK ${f.roll.toFixed(0)}° · DIVING IN`
|
||||
: status === 'SLOW-MO'
|
||||
? `PLAYBACK ${s.rate.toFixed(2)}× · ${Math.round(s.explode * 100)}% APART`
|
||||
: status === 'TEARDOWN' || status === 'REASSEMBLY'
|
||||
? `TURNTABLE ${Math.round(s.turn)}° CW · ${Math.round(s.explode * 100)}% APART`
|
||||
: status === 'CLIMB-OUT'
|
||||
? `CLIMBING · ${sp.toFixed(1)} M/S`
|
||||
: ACT_R[v]
|
||||
? `${ASSEMBLY_LABEL[v]} · ${Math.round(opening * 100)}% APART`
|
||||
: `STATION KEEPING · ${((f.pos.y - FLOOR_Y) * MM).toFixed(0)} MM AGL`,
|
||||
viewNote: `ISOLATE · ${v === 'intro' || v === 'hero' ? 'HERO' : v === 'exploded' ? 'ALL' : ASSEMBLY_LABEL[v]}`,
|
||||
labelSet: labels,
|
||||
};
|
||||
};
|
||||
|
||||
return {SCRIPT, DURATION, stateAt, telemetry, camAt, flightAt, tauAt};
|
||||
}
|
||||
@@ -0,0 +1,389 @@
|
||||
// The VX-9 wasp's tour: the bee's (robobee-shared/tour_v2.js) 1:1, the stinger sliding out at the end of the abdomen act.
|
||||
// The HB-7 simulator tour, second cut: the bee itself does something big every 2-3 s. It flies in and banks through a
|
||||
// turn, then the operator opens one assembly after another, each with the camera pushed in on it: the lens unscrews
|
||||
// along its axis and the iris opens, a wing pulls out of its hinge and turns over in the air, a leg comes apart
|
||||
// segment by segment with its servos spinning, the thorax shells lift off over spinning gears, the abdomen telescopes
|
||||
// apart; then the whole bee explodes on a 330° turntable with its parts spinning, snaps back together while it still
|
||||
// turns, spins its wings up and banks away out of frame. Labels show only while parts move.
|
||||
// Script: the entry's timeline.json, {duration, script: [{t, act}]}; act is an assembly (optics, wing, leg, thorax,
|
||||
// abdomen), 'exploded', 'assemble' or 'hero' (the departure). Everything is a pure function of film time t.
|
||||
import * as THREE from 'three';
|
||||
import {VIEWPORT} from './console.js';
|
||||
import {FLOOR_Y} from './tour.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;
|
||||
const MM = 80;
|
||||
export const FLAP_HZ = 7.5;
|
||||
export const AMP = 32;
|
||||
export const REACH = 0.62;
|
||||
|
||||
export const ASSEMBLIES = ['hero', 'optics', 'wing', 'leg', 'thorax', 'abdomen'];
|
||||
export const ASSEMBLY_LABEL = {hero: 'HERO', optics: 'OPTICS', wing: 'WING', leg: 'LEG L2', thorax: 'THORAX', abdomen: 'ABDOMEN'};
|
||||
export const DISPLAY2 = ['labels', 'exploded', 'blur', 'turntable'];
|
||||
export const DISPLAY2_LABEL = {labels: 'LABELS', exploded: 'EXPLODED', blur: 'MOTION BLUR', turntable: 'TURNTABLE'};
|
||||
// the button each act presses
|
||||
const BUTTON = {optics: 'optics', wing: 'wing', leg: 'leg', thorax: 'thorax', abdomen: 'abdomen', exploded: 'exploded', assemble: 'exploded', hero: 'hero'};
|
||||
|
||||
// each act's own clock (seconds after its click): when it opens, when it closes, whether the wings stop for it
|
||||
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: true},
|
||||
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: true},
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------ cameras: [az, el, d, tx, ty, tz, sx, sy], u = seconds on
|
||||
export const CAM2 = {
|
||||
intro: (u) => {
|
||||
const k = ss(0, 3.0, u);
|
||||
return [lerp(150, 34, k), lerp(15, 9, k), lerp(8.6, 7.3, k), 0.0, -0.25, 0.25, -30, -14];
|
||||
},
|
||||
optics: (u) => [88 - 8 * u, 6, lerp(4.9, 4.2, ss(0, 1.6, u)), 1.22, 0.12, 0.45, 0, -14],
|
||||
wing: (u) => [40 + 6 * u, 18, lerp(8.6, 7.6, ss(0, 1.6, u)), -0.5, 0.95, 1.25, 0, -14],
|
||||
leg: (u) => [14 + 9 * u, 6, lerp(6.6, 5.8, ss(0, 1.6, u)), 0.1, -0.8, 0.45, 0, -14],
|
||||
thorax: (u) => [8 + 10 * u, 34, lerp(6.8, 6.0, ss(0, 1.6, u)), 0.0, 0.32, 0.05, 0, -14],
|
||||
abdomen: (u) => [-30 + 9 * u, 14, lerp(6.6, 5.8, ss(0, 1.6, u)), -2.45, -0.95, 0.1, 0, -14],
|
||||
exploded: (u) => [34 + 5 * u, 18, 11.6, 0.0, -0.15, 0.0, -20, -14],
|
||||
hero: (u) => [18 + 14 * u, 9, 6.8, 0.0, -0.22, 0.25, -30, -14],
|
||||
};
|
||||
|
||||
export function makeTour2(TL) {
|
||||
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;
|
||||
// an assembly's opening, 0..1, from its act's clock
|
||||
const openOf = (act, t) => {
|
||||
let v = 0;
|
||||
for (const t0 of at(act)) {
|
||||
const A = ACT[act];
|
||||
v = Math.max(v, ss(t0 + A.open[0], t0 + A.open[1], t) * (1 - ss(t0 + A.close[0], t0 + A.close[1], t)));
|
||||
}
|
||||
return v;
|
||||
};
|
||||
// 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 bee 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;
|
||||
// a trapezoid of speed: ramp up over R, steady, ramp down over R
|
||||
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);
|
||||
};
|
||||
// the wings stop for the acts that need still wings and for the explode, and spin back up after
|
||||
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)));
|
||||
};
|
||||
// the busy clock the gears and loose parts turn on: they run five times faster while something is open
|
||||
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 = (A, t) => {
|
||||
const u = Math.max(0, Math.min(A.length - 2, t / DT));
|
||||
const i = Math.floor(u);
|
||||
return A[i] + (A[i + 1] - A[i]) * (u - i);
|
||||
};
|
||||
const spinAt = (t) => (t < 0 ? t : look(SPIN, t));
|
||||
|
||||
// the flight: in from behind-left banking through a turn, the hover, the turntable, the departure banking away
|
||||
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 pos = new THREE.Vector3(lerp(-2.6, 0, kIn), lerp(0.6, 0, kIn) + 0.05 * Math.sin(t * 2.6) * calm, lerp(-3.2, 0, kIn));
|
||||
let yaw = lerp(-80, 0, kIn) + 14 * Math.sin(Math.PI * kIn);
|
||||
let roll = 30 * Math.sin(Math.PI * Math.min(1, kIn * 1.05)) + 1.7 * Math.sin(t * 1.3 + 1.1) * calm;
|
||||
let pitch = -6 * Math.sin(Math.PI * kIn) + 1.4 * Math.sin(t * 1.9 + 0.6) * calm;
|
||||
yaw += turnAt(t);
|
||||
if (t > T_END + 1.0) {
|
||||
const u = t - T_END - 1.0;
|
||||
const k = ss(0, 1.0, u);
|
||||
yaw += 38 * k;
|
||||
roll -= 30 * k;
|
||||
pitch += 8 * k;
|
||||
const h = new THREE.Vector3(Math.cos(yaw * D2R), 0, -Math.sin(yaw * D2R));
|
||||
pos.addScaledVector(h, 1.6 * u * u).add(new THREE.Vector3(0, 0.45 * u * u, 0));
|
||||
}
|
||||
return {pos, yaw, roll, pitch, calm};
|
||||
};
|
||||
|
||||
// the camera: each act's view, blended over 0.8 s with a short dolly out, tracking the bee as it flies
|
||||
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));
|
||||
const camAt = (t) => {
|
||||
const i = viewIdx(t);
|
||||
let o = camFn(VIEWS[i], t);
|
||||
// the reassembly keeps the explode's camera running from where it was
|
||||
if (VIEWS[i].key === 'exploded' && i > 0 && VIEWS[i - 1].key === 'exploded') o = camFn(VIEWS[i - 1], t);
|
||||
else if (i > 0) {
|
||||
const k = ss(VIEWS[i].t, VIEWS[i].t + 0.85, t);
|
||||
if (k < 1) {
|
||||
const a = camFn(VIEWS[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.7 * Math.sin(Math.PI * k);
|
||||
o = b;
|
||||
}
|
||||
}
|
||||
// the camera follows the bee in, and lets it go on the way out
|
||||
const f = flightAt(t);
|
||||
const track = 0.85 - 0.5 * ss(T_END + 1.0, T_END + 2.0, t);
|
||||
return {az: o[0], el: o[1], d: o[2], tx: o[3] + f.pos.x * track, ty: o[4] + f.pos.y * track, tz: o[5] + f.pos.z * track, sx: o[6], sy: o[7]};
|
||||
};
|
||||
const actAt = (t) => {
|
||||
const i = viewIdx(t);
|
||||
return VIEWS[i].key;
|
||||
};
|
||||
|
||||
const stateAt = (t) => {
|
||||
const ex = explodeAt(t);
|
||||
const amp = AMP * (1 - stopAt(t));
|
||||
const f = flightAt(t);
|
||||
const open = Object.fromEntries(Object.keys(ACT).map((a) => [a, openOf(a, t)]));
|
||||
// the wing's own clock: out, one full turn over, back in fast
|
||||
let wingOut = 0;
|
||||
let wingFlip = 0;
|
||||
for (const t0 of at('wing')) {
|
||||
const A = ACT.wing;
|
||||
wingOut = Math.max(wingOut, ss(t0 + A.open[0], t0 + A.open[1], t) * (1 - ss(t0 + A.close[0], t0 + A.close[1], t)));
|
||||
wingFlip = Math.max(wingFlip, ss(t0 + 0.9, t0 + 2.3, t));
|
||||
}
|
||||
if (wingFlip >= 1) wingFlip = 0;
|
||||
// the sting: out of its collar once the abdomen hangs open, back in before it closes
|
||||
let stingK = 0;
|
||||
for (const t0 of at('abdomen')) stingK = Math.max(stingK, ss(t0 + 1.05, t0 + 1.55, t) * (1 - ss(t0 + 1.9, t0 + 2.2, t)));
|
||||
const view = actAt(t);
|
||||
return {
|
||||
t,
|
||||
spinT: spinAt(t),
|
||||
explode: ex,
|
||||
amp,
|
||||
flap: Math.PI * 2 * FLAP_HZ * t,
|
||||
display: 1 - amp / AMP,
|
||||
blur: 1,
|
||||
sub: {thorax: open.thorax, abdomen: open.abdomen},
|
||||
eye: open.optics,
|
||||
wingOut,
|
||||
wingFlip,
|
||||
legK: open.leg,
|
||||
stingK,
|
||||
open,
|
||||
flight: f,
|
||||
cam: camAt(t),
|
||||
view,
|
||||
guides: 0.45 + 0.55 * Math.min(1, ex * 2.5 + activity(t)),
|
||||
turn: turnAt(t),
|
||||
};
|
||||
};
|
||||
|
||||
// labels: on while the act's parts are moving apart and while they hang open, gone before they close
|
||||
const LABELS = {
|
||||
optics: [['eyeGlass', 'OUTER GLASS', 'Ø 40 MM · AR COATED'], ['eyeInner', 'INNER ELEMENT', 'Ø 15 MM'], ['iris', 'IRIS', '10 BLADES · OPENS 3×'], ['barrel', 'LENS BARREL', 'THREADED · 4 RINGS']],
|
||||
wing: [['wing', 'WING MEMBRANE', 'FROSTED FILM · 0.1 MM'], ['hinge', 'WING HINGE', 'QUICK RELEASE'], ['hinge2', 'HINDWING HINGE', 'PHASE +40°']],
|
||||
leg: [['hip2', 'HIP SERVO', 'YAW + LIFT'], ['knee2', 'KNEE SERVO', '0.4 N·M'], ['foot', 'FOOT CLAW', 'TWIN HOOKS']],
|
||||
thorax: [['plate', 'SADDLE PLATE', 'POLYMER SHELL'], ['gears', 'DRIVE GEAR STACK', '3 SPUR GEARS'], ['act', 'ACTUATOR RING', '11 PISTONS'], ['core', 'CONTROL BOARDS', 'FLIGHT CPU · IMU']],
|
||||
abdomen: [['waist', 'WAIST STALK', '5 BEADS · LIT RINGS'], ['s1', 'SHELL BAND', 'TELESCOPING'], ['capsule', 'BAND 4', 'RIVETED · 5 SEGMENTS'], ['sting', 'STINGER', 'GLASS · EXTENDS 30 MM']],
|
||||
exploded: [['lens', 'OPTIC HEAD', '2 × LENS'], ['collar', 'NECK BEARING', '10 SEGMENTS'], ['gears', 'DRIVE GEARS', 'SPINNING FREE'], ['capsule', 'ABDOMEN BANDS', '5 SEGMENTS'], ['hinge', 'WING HINGE', 'QUICK RELEASE']],
|
||||
};
|
||||
const labelAt = (t, s) => {
|
||||
const v = s.view;
|
||||
if (ACT[v]) {
|
||||
const t0 = at(v).filter((x) => x <= t).pop();
|
||||
const A = ACT[v];
|
||||
return {set: LABELS[v], o: ss(t0 + A.open[0] + 0.1, t0 + A.open[0] + 0.45, t) * (1 - ss(t0 + A.close[0] - 0.25, t0 + A.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};
|
||||
};
|
||||
|
||||
const telemetry = (t, s) => {
|
||||
const f = s.flight;
|
||||
const stroke = [];
|
||||
for (let i = 0; i <= 90; i++) {
|
||||
const tt = t - 1.2 + (i / 90) * 1.2;
|
||||
const a = AMP * (1 - stopAt(tt));
|
||||
const ph = Math.PI * 2 * FLAP_HZ * tt;
|
||||
stroke.push([a * Math.sin(ph), a * Math.sin(ph + 0.7)]);
|
||||
}
|
||||
const ex = s.explode > 0.04;
|
||||
const acc = -Math.sin(t * 2.6);
|
||||
const free = [0, 1, 2, 3, 4, 5].map((i) => ex || (i === 1 && s.legK > 0.08));
|
||||
const servos = [0.44, 0.58, 0.49, 0.4, 0.53, 0.46].map((b, i) => (free[i] ? 0 : Math.max(0, Math.min(1, b * (1 + 0.32 * acc) + 0.12 * Math.abs(f.roll) / 30 + 0.03 * Math.sin(t * 7 + i)))));
|
||||
const v = s.view;
|
||||
const opening = ACT[v] ? s.open[v] : 0;
|
||||
const NAME = {optics: 'OPTICS OPEN', wing: 'WING OFF', leg: 'LEG L2 OPEN', thorax: 'THORAX OPEN', abdomen: 'ABDOMEN OPEN'};
|
||||
let status = 'HOVER';
|
||||
let kind = 'ok';
|
||||
if (t < 2.6) status = 'BANKING';
|
||||
if (ACT[v] && (opening > 0.05 || (v === 'wing' && s.wingOut > 0.05))) [status, kind] = [NAME[v], 'warn'];
|
||||
if (v === 'exploded') [status, kind] = t < T_ASM ? ['TEARDOWN', 'warn'] : s.explode > 0.04 ? ['REASSEMBLY', 'warn'] : ['HOVER', 'ok'];
|
||||
if (t > T_END + 1.0) status = 'DEPARTING';
|
||||
const ROW = {optics: 0, thorax: 2, wing: 3, leg: 4, abdomen: 5};
|
||||
const sub = (i) => {
|
||||
if (ex) return ['warn', 'DETACHED'];
|
||||
if (ROW[v] === i && (opening > 0.05 || (v === 'wing' && s.wingOut > 0.05))) return ['warn', i === 3 ? 'DETACHED' : 'OPEN'];
|
||||
if (i === 3) return s.amp > 1 ? ['ok', `${FLAP_HZ} HZ`] : ['idle', 'PARKED'];
|
||||
if (i === 2) return s.amp > 1 ? ['ok', 'RUNNING'] : ['idle', 'STOPPED'];
|
||||
return ['ok', ['TRACKING', 'LOCKED', '', '', 'HOLDING', '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 sp = f.pos.length() > 0.05 ? 0.4 + 0.2 * Math.abs(Math.sin(t)) : 0.004;
|
||||
const labels = labelAt(t, s);
|
||||
return {
|
||||
time: t,
|
||||
dur: DURATION,
|
||||
lift: Math.max(0, (s.amp / AMP) * (0.68 + 0.02 * Math.sin(s.flap)) + 0.12 * Math.abs(f.roll) / 30),
|
||||
status,
|
||||
statusKind: kind,
|
||||
freq: FLAP_HZ * ss(0.5, 6, s.amp),
|
||||
amp: s.amp,
|
||||
stroke,
|
||||
playback: 1,
|
||||
blur: 1,
|
||||
battery: 0.842 - 0.0022 * t,
|
||||
power: 4.2 + 31 * Math.pow(s.amp / AMP, 1.5) * (1 + 0.04 * Math.sin(s.flap)) + 3 * Math.abs(f.roll) / 30,
|
||||
volt: 3.92 - 0.006 * 36,
|
||||
motorT: 34 + 0.35 * t,
|
||||
servos,
|
||||
legsFree: ex,
|
||||
legFreeEach: free,
|
||||
airborne: true,
|
||||
alt: (f.pos.y - FLOOR_Y) * MM,
|
||||
vs: MM * 0.05 * 2.6 * Math.cos(t * 2.6) * f.calm,
|
||||
pitch: f.pitch,
|
||||
roll: f.roll,
|
||||
airspeed: sp,
|
||||
view: v === 'intro' ? 'hero' : v === 'exploded' ? null : v,
|
||||
display: {labels: labels.o > 0.5, exploded: t >= T_EXP && t < T_ASM, blur: s.amp > 3, turntable: s.turn > 0 && t < TT[1]},
|
||||
subs: [0, 1, 2, 3, 4, 5].map(sub),
|
||||
focus: ROW[v] ?? (v === 'exploded' ? 1 : -1),
|
||||
events: EVENTS,
|
||||
next: `${EVENTS.length} OPERATOR ACTIONS`,
|
||||
log: last ? `OPERATOR · ${say(last)}` : 'INBOUND · BANKING LEFT',
|
||||
mode: status,
|
||||
modeSub:
|
||||
status === 'BANKING'
|
||||
? `ROLL ${f.roll.toFixed(0)}° · INBOUND`
|
||||
: status === 'TEARDOWN' || status === 'REASSEMBLY'
|
||||
? `TURNTABLE ${Math.round(s.turn)}° · ${Math.round(s.explode * 100)}% APART`
|
||||
: status === 'DEPARTING'
|
||||
? `BANK ${f.roll.toFixed(0)}° · RELEASED`
|
||||
: ACT[v]
|
||||
? `${ASSEMBLY_LABEL[v]} · ${Math.round(Math.max(opening, s.wingOut) * 100)}% APART`
|
||||
: `STATION KEEPING · ${((f.pos.y - FLOOR_Y) * MM).toFixed(0)} MM AGL`,
|
||||
viewNote: `ISOLATE · ${v === 'intro' || v === 'hero' ? 'HERO' : v === 'exploded' ? 'ALL' : ASSEMBLY_LABEL[v]}`,
|
||||
labelSet: labels,
|
||||
};
|
||||
};
|
||||
|
||||
return {SCRIPT, DURATION, stateAt, telemetry, camAt};
|
||||
}
|
||||
|
||||
/** Labels in two columns at the viewport's edges, as the first cut, from a set of anchors. */
|
||||
export function makeLabels2(st, bee) {
|
||||
const p = new THREE.Vector3();
|
||||
return ({set, o}) => {
|
||||
if (o < 0.02) return [];
|
||||
const pts = [];
|
||||
for (const [key, name, sub] of set) {
|
||||
const A = bee.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 makeCursor2(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};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user