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:
@@ -0,0 +1,18 @@
|
||||
// print a film's anchor table A, the parts' rest points the close-up cameras aim at (node sims/green/anchors_dump.mjs <entry> <global>)
|
||||
import {pathToFileURL} from 'node:url';
|
||||
import path from 'node:path';
|
||||
import {CHROMIUM, CHROMIUM_ARGS, DIST, playwright} from '../../paths.mjs';
|
||||
|
||||
const [entry, glob] = process.argv.slice(2);
|
||||
const {chromium} = playwright();
|
||||
const browser = await chromium.launch({executablePath: CHROMIUM, args: CHROMIUM_ARGS});
|
||||
const page = await browser.newPage({viewport: {width: 1600, height: 900}, deviceScaleFactor: 1});
|
||||
await page.addInitScript(() => {
|
||||
window.__CAPTURE = true;
|
||||
window.__SIM_CONFIG = {};
|
||||
});
|
||||
await page.goto(pathToFileURL(path.join(DIST, `${entry}.html`)).href);
|
||||
await page.waitForFunction(() => window.SIM && window.SIM.ready, null, {timeout: 60000});
|
||||
const out = await page.evaluate((g) => JSON.stringify(Object.fromEntries(Object.entries(window[g].A).map(([k, v]) => [k, v.map((x) => +x.toFixed(2))]))), glob);
|
||||
console.log(out);
|
||||
await browser.close();
|
||||
@@ -0,0 +1,23 @@
|
||||
// print a film's camera every 0.5 s (node sims/green/cam_track.mjs <entry> <global> [step])
|
||||
import {pathToFileURL} from 'node:url';
|
||||
import path from 'node:path';
|
||||
import {CHROMIUM, CHROMIUM_ARGS, DIST, playwright} from '../../paths.mjs';
|
||||
const [entry, glob, step = '0.5'] = process.argv.slice(2);
|
||||
const {chromium} = playwright();
|
||||
const browser = await chromium.launch({executablePath: CHROMIUM, args: CHROMIUM_ARGS});
|
||||
const page = await browser.newPage({viewport: {width: 1600, height: 900}, deviceScaleFactor: 1});
|
||||
await page.addInitScript(() => { window.__CAPTURE = true; window.__SIM_CONFIG = {}; });
|
||||
await page.goto(pathToFileURL(path.join(DIST, `${entry}.html`)).href);
|
||||
await page.waitForFunction(() => window.SIM && window.SIM.ready, null, {timeout: 60000});
|
||||
const rows = await page.evaluate(([glob, step]) => {
|
||||
const T = window[glob].T;
|
||||
const out = [];
|
||||
for (let t = 0; t <= window.SIM.duration + 1e-6; t += Number(step)) {
|
||||
const s = T.stateAt(t);
|
||||
const c = s.cam;
|
||||
out.push(`${t.toFixed(1).padStart(5)} ${String(s.view).padEnd(9)} az ${c.az.toFixed(0).padStart(4)} el ${c.el.toFixed(0).padStart(3)} d ${c.d.toFixed(1)}`);
|
||||
}
|
||||
return out;
|
||||
}, [glob, step]);
|
||||
console.log(rows.join('\n'));
|
||||
await browser.close();
|
||||
@@ -0,0 +1,187 @@
|
||||
// The green page around a creature, in the look of a model-launch blog (first made for longcat/wasp, Vespera-07): white
|
||||
// paper with mint haze in the top corners, a wordmark, a centred title with a green rule and a row of pill buttons the
|
||||
// operator's cursor presses, a section list on the left that follows the act, white metric cards on the right, labels
|
||||
// as soft cards with leader lines. Shared by every creature's green film; what changes per creature (name, title, the
|
||||
// acts and their notes) comes in as options. 1600 x 900 layout px. update(s) redraws every live part from one frame.
|
||||
export const VIEWPORT = {x0: 250, x1: 1320, y0: 236, y1: 836};
|
||||
export const REST = [1250, 272];
|
||||
export const GREEN = '#16b364';
|
||||
|
||||
const CSS = `
|
||||
#app{width:1600px!important;height:900px!important;inset:auto!important;left:0;top:0;transform-origin:0 0;background:#fff}
|
||||
.vp{position:absolute;inset:0;pointer-events:none;font-family:'Inter',system-ui,sans-serif;color:#0f172a;-webkit-font-smoothing:antialiased}
|
||||
.vp *{box-sizing:border-box}
|
||||
.vp .haze{position:absolute;inset:0;mix-blend-mode:multiply;background:
|
||||
radial-gradient(520px 360px at 60px -40px, rgba(22,179,100,.16), rgba(22,179,100,0) 70%),
|
||||
radial-gradient(620px 420px at 1600px 20px, rgba(22,179,100,.14), rgba(22,179,100,0) 70%)}
|
||||
.vp .dots{position:absolute;right:0;top:0;width:420px;height:300px;opacity:.5;mix-blend-mode:multiply;
|
||||
background-image:radial-gradient(rgba(22,179,100,.35) 1px, transparent 1.4px);background-size:9px 9px;
|
||||
-webkit-mask-image:radial-gradient(360px 240px at 100% 0%, #000, transparent 75%);mask-image:radial-gradient(360px 240px at 100% 0%, #000, transparent 75%)}
|
||||
.vp .logo{position:absolute;left:46px;top:22px;display:flex;align-items:center;gap:10px;font:800 23px/1 'Inter',sans-serif;letter-spacing:-.3px}
|
||||
.vp .logo i{width:30px;height:30px;border-radius:9px;background:linear-gradient(135deg,#22c55e,#0e9f55);position:relative;display:block}
|
||||
.vp .logo i:after{content:'';position:absolute;left:8px;top:8px;width:14px;height:14px;border:3px solid #fff;border-radius:50%;border-right-color:transparent}
|
||||
.vp .lang{position:absolute;right:46px;top:20px;height:32px;padding:0 14px;border:1px solid #e2e8f0;border-radius:16px;display:flex;align-items:center;gap:8px;font:600 13px/1 'Inter',sans-serif;background:#fff}
|
||||
.vp .lang b{width:8px;height:8px;border-radius:50%;background:${GREEN};display:block;box-shadow:0 0 0 4px rgba(22,179,100,.15)}
|
||||
.vp .head{position:absolute;left:0;right:0;top:52px;text-align:center}
|
||||
.vp .head .ver{font:800 22px/1 'Inter',sans-serif;letter-spacing:-.3px}
|
||||
.vp .head .ver em{font-style:normal;color:${GREEN}}
|
||||
.vp .head h1{margin:10px 0 0;font:800 36px/1.05 'Inter',sans-serif;letter-spacing:-.8px}
|
||||
.vp .head .rule{width:84px;height:4px;border-radius:3px;margin:12px auto 0;background:linear-gradient(90deg,rgba(22,179,100,0),${GREEN} 30%,${GREEN} 70%,rgba(22,179,100,0))}
|
||||
.vp .head .date{margin-top:9px;font:500 13px/1 'Inter',sans-serif;color:#64748b}
|
||||
.vp .pills{position:absolute;left:0;right:0;top:180px;display:flex;justify-content:center;gap:10px}
|
||||
.vp .pill{height:34px;padding:0 15px;border:1px solid #e2e8f0;border-radius:17px;background:#fff;display:flex;align-items:center;gap:8px;font:600 13px/1 'Inter',sans-serif;color:#334155;transition:none}
|
||||
.vp .pill i{width:15px;height:15px;border-radius:50%;border:1.6px solid #94a3b8;display:block;position:relative}
|
||||
.vp .pill i:after{content:'';position:absolute;left:4px;top:3px;border-left:5px solid #94a3b8;border-top:3.5px solid transparent;border-bottom:3.5px solid transparent}
|
||||
.vp .pill.on{border-color:${GREEN};background:#effbf4;color:#0b7a43}
|
||||
.vp .pill.on i{border-color:${GREEN}}
|
||||
.vp .pill.on i:after{border-left-color:${GREEN}}
|
||||
.vp .pill.press{transform:scale(.95)}
|
||||
.vp .nav{position:absolute;left:58px;top:300px;width:190px;border-left:1.5px solid #e2e8f0;padding-left:0}
|
||||
.vp .nav div{position:relative;padding:7px 0 7px 18px;font:500 15px/1.2 'Inter',sans-serif;color:#94a3b8}
|
||||
.vp .nav div.on{color:#0f172a;font-weight:700}
|
||||
.vp .nav div.on:before{content:'';position:absolute;left:-2px;top:7px;bottom:7px;width:3px;border-radius:2px;background:#0f172a}
|
||||
.vp .nav div.sub{padding:4px 0 4px 30px;font:500 12.5px/1.2 'Inter',sans-serif;color:#64748b}
|
||||
.vp .cards{position:absolute;left:1340px;top:290px;width:220px;display:flex;flex-direction:column;gap:12px}
|
||||
.vp .card{background:rgba(255,255,255,.92);border:1px solid #e8edf3;border-radius:14px;padding:14px 16px;box-shadow:0 1px 2px rgba(15,23,42,.04),0 6px 18px rgba(15,23,42,.05)}
|
||||
.vp .card .k{font:600 11px/1 'Inter',sans-serif;letter-spacing:.6px;text-transform:uppercase;color:#64748b}
|
||||
.vp .card .v{margin-top:8px;font:800 28px/1 'Inter',sans-serif;letter-spacing:-.5px;font-variant-numeric:tabular-nums}
|
||||
.vp .card .v small{font-size:14px;font-weight:600;color:#64748b;margin-left:4px}
|
||||
.vp .card svg{display:block;margin-top:8px}
|
||||
.vp .bar{height:6px;border-radius:3px;background:#edf2f7;margin-top:10px;overflow:hidden}
|
||||
.vp .bar b{display:block;height:100%;background:${GREEN};border-radius:3px}
|
||||
.vp .servos{display:flex;gap:6px;align-items:flex-end;height:46px;margin-top:10px}
|
||||
.vp .servos b{flex:1;background:${GREEN};border-radius:3px 3px 1px 1px;opacity:.9}
|
||||
.vp .foot{position:absolute;left:262px;right:280px;top:852px;display:flex;align-items:center;gap:14px}
|
||||
.vp .foot .st{height:28px;padding:0 12px;border-radius:14px;background:#effbf4;color:#0b7a43;font:600 12.5px/28px 'Inter',sans-serif;white-space:nowrap;display:flex;align-items:center;gap:7px}
|
||||
.vp .foot .st b{width:7px;height:7px;border-radius:50%;background:${GREEN};display:block}
|
||||
.vp .foot .track{flex:1;height:3px;border-radius:2px;background:#e2e8f0;position:relative}
|
||||
.vp .foot .track b{position:absolute;left:0;top:0;bottom:0;background:${GREEN};border-radius:2px}
|
||||
.vp .foot .tm{font:600 12.5px/1 'Inter',sans-serif;color:#64748b;font-variant-numeric:tabular-nums}
|
||||
.vp svg.lines{position:absolute;left:0;top:0;width:1600px;height:900px;overflow:visible}
|
||||
.vp .lab{position:absolute;padding:8px 12px;background:#fff;border:1px solid #e2e8f0;border-radius:10px;box-shadow:0 4px 14px rgba(15,23,42,.08);white-space:nowrap}
|
||||
.vp .lab b{display:block;font:700 13.5px/1.15 'Inter',sans-serif;color:#0f172a}
|
||||
.vp .lab span{display:block;margin-top:3px;font:500 11.5px/1.1 'Inter',sans-serif;color:#64748b}
|
||||
.vp .cur{position:absolute;left:0;top:0;width:26px;height:26px}
|
||||
.vp .ring{position:absolute;width:46px;height:46px;margin:-23px 0 0 -23px;border-radius:50%;border:2px solid ${GREEN}}
|
||||
`;
|
||||
|
||||
export function createConsole(app, opts) {
|
||||
const {name, code, title, date} = opts;
|
||||
// the 4 cards: a value with a trace ('wave'), a value with a bar ('bar') or a row of load bars ('bars'); a plain
|
||||
// title string keeps the flying creatures' set (wingbeat, lift, servo load, battery)
|
||||
const KIND = ['wave', 'bar', 'bars', 'bar'];
|
||||
const UNIT = ['Hz', '%', '', '%'];
|
||||
const CARDS = (opts.cards ?? ['Wingbeat', 'Lift', 'Servo load', 'Battery']).map((c, i) => (typeof c === 'string' ? {k: c, kind: KIND[i], unit: UNIT[i], n: 6} : {n: 6, unit: '', ...c}));
|
||||
const cardHtml = (c, i) =>
|
||||
c.kind === 'wave'
|
||||
? `<div class="card"><div class="k">${c.k}</div><div class="v" data-c="${i}">0<small>${c.unit}</small></div><svg width="188" height="38" viewBox="0 0 188 38"><path data-w="${i}" fill="none" stroke="${GREEN}" stroke-width="2" stroke-linejoin="round"/></svg></div>`
|
||||
: c.kind === 'bars'
|
||||
? `<div class="card"><div class="k">${c.k}</div><div class="servos" data-s="${i}">${'<b></b>'.repeat(c.n)}</div></div>`
|
||||
: `<div class="card"><div class="k">${c.k}</div><div class="v" data-c="${i}">0<small>${c.unit}</small></div><div class="bar"><b data-b="${i}"></b></div></div>`;
|
||||
const NAV = opts.nav;
|
||||
const SUB = opts.sub;
|
||||
const PILLS = opts.pills;
|
||||
const st = document.createElement('style');
|
||||
st.textContent = CSS;
|
||||
document.head.appendChild(st);
|
||||
const root = document.createElement('div');
|
||||
root.className = 'vp';
|
||||
root.innerHTML = `
|
||||
<div class="haze"></div><div class="dots"></div>
|
||||
<div class="logo"><i></i>${name}</div>
|
||||
<div class="lang"><b></b>Live sim</div>
|
||||
<div class="head"><div class="ver">${name} <em>${code}</em></div><h1>${title}</h1><div class="rule"></div><div class="date">${date}</div></div>
|
||||
<div class="pills">${PILLS.map(([k, t]) => `<div class="pill" data-p="${k}"><i></i>${t}</div>`).join('')}</div>
|
||||
<div class="nav"></div>
|
||||
<div class="cards">${CARDS.map(cardHtml).join('')}
|
||||
</div>
|
||||
<div class="foot"><div class="st"><b></b><span data-v="status">Banking in</span></div><div class="track"><b data-v="prog"></b></div><div class="tm" data-v="time">00:00.0</div></div>
|
||||
<svg class="lines"></svg>
|
||||
<div class="labs"></div>
|
||||
<div class="ring" style="opacity:0"></div>
|
||||
<svg class="cur" viewBox="0 0 26 26" style="display:none"><path d="M3 2 L3 22 L8.5 17 L12.5 25 L16 23.4 L12 15.5 L19 15.5 Z" fill="#0f172a" stroke="#fff" stroke-width="1.6" stroke-linejoin="round"/></svg>`;
|
||||
app.appendChild(root);
|
||||
const $ = (q) => root.querySelector(q);
|
||||
const V = Object.fromEntries([...root.querySelectorAll('[data-v]')].map((e) => [e.dataset.v, e]));
|
||||
const pills = Object.fromEntries([...root.querySelectorAll('[data-p]')].map((e) => [e.dataset.p, e]));
|
||||
const cardV = CARDS.map((c, i) => root.querySelector(`[data-c="${i}"]`));
|
||||
const cardW = CARDS.map((c, i) => root.querySelector(`[data-w="${i}"]`));
|
||||
const cardB = CARDS.map((c, i) => root.querySelector(`[data-b="${i}"]`));
|
||||
const cardS = CARDS.map((c, i) => [...root.querySelectorAll(`[data-s="${i}"] b`)]);
|
||||
const nav = $('.nav');
|
||||
const lines = $('svg.lines');
|
||||
const labs = $('.labs');
|
||||
const cur = $('.cur');
|
||||
const ring = $('.ring');
|
||||
const spots = Object.fromEntries(Object.entries(pills).map(([k, e]) => [k, [e.offsetLeft + e.parentElement.offsetLeft + e.offsetWidth * 0.42, e.offsetTop + e.parentElement.offsetTop + e.offsetHeight * 0.58]]));
|
||||
let lastNav = '';
|
||||
const pool = [];
|
||||
const pad = (n) => String(Math.floor(n)).padStart(2, '0');
|
||||
|
||||
return {
|
||||
root,
|
||||
spots,
|
||||
pills,
|
||||
update(s) {
|
||||
// pills and the section list follow the act
|
||||
for (const [k, e] of Object.entries(pills)) e.classList.toggle('on', k === s.view);
|
||||
if (s.view !== lastNav) {
|
||||
lastNav = s.view;
|
||||
nav.innerHTML = NAV.map(([k, t]) => (k === s.view ? `<div class="on">${t}</div>${(SUB[k] ?? []).map((x) => `<div class="sub">${x}</div>`).join('')}` : `<div>${t}</div>`)).join('');
|
||||
}
|
||||
// cards: s.cards [{v, wave (-1..1) | bar (0..1) | bars (0..1 each)}], or the flying creatures' fields
|
||||
const cards = s.cards ?? [
|
||||
{v: s.freq.toFixed(1), wave: s.stroke.map((a) => a / 32)},
|
||||
{v: Math.round(Math.min(1, s.lift) * 100), bar: Math.min(1, s.lift)},
|
||||
{bars: s.servos},
|
||||
{v: Math.round(s.battery * 100), bar: s.battery},
|
||||
];
|
||||
cards.forEach((c, i) => {
|
||||
if (cardV[i]) cardV[i].innerHTML = `${c.v}<small>${CARDS[i].unit}</small>`;
|
||||
if (cardW[i] && c.wave) cardW[i].setAttribute('d', `M${c.wave.map((a, j) => `${((j / (c.wave.length - 1)) * 188).toFixed(1)},${(19 - Math.max(-1, Math.min(1, a)) * 15).toFixed(1)}`).join(' L')}`);
|
||||
if (cardB[i]) cardB[i].style.width = `${Math.round(Math.max(0, Math.min(1, c.bar ?? 0)) * 100)}%`;
|
||||
cardS[i].forEach((e, j) => (e.style.height = `${Math.round(8 + 38 * Math.max(0, Math.min(1, c.bars?.[j] ?? 0)))}px`));
|
||||
});
|
||||
V.status.textContent = s.status + (s.apart > 2 && s.status !== 'Hovering' ? ` · ${s.apart}% apart` : '');
|
||||
V.prog.style.width = `${Math.min(100, (s.time / s.dur) * 100)}%`;
|
||||
V.time.textContent = `00:${pad(s.time)}.${Math.floor((s.time % 1) * 10)}`;
|
||||
// labels
|
||||
let path = '';
|
||||
(s.callouts || []).forEach((c, i) => {
|
||||
let el = pool[i];
|
||||
if (!el) {
|
||||
el = document.createElement('div');
|
||||
el.className = 'lab';
|
||||
labs.appendChild(el);
|
||||
pool[i] = el;
|
||||
}
|
||||
el.style.display = 'block';
|
||||
el.style.opacity = String(c.o);
|
||||
el.innerHTML = `<b>${c.name}</b><span>${c.sub}</span>`;
|
||||
const w = el.offsetWidth;
|
||||
const left = c.w === 'l' ? c.label[0] : c.label[0] - w;
|
||||
el.style.left = `${left}px`;
|
||||
el.style.top = `${c.label[1]}px`;
|
||||
const ex = c.w === 'l' ? left + w : left;
|
||||
const ey = c.label[1] + 21;
|
||||
const k = Math.min(1, c.o * 1.2);
|
||||
const ax = ex + (c.at[0] - ex) * k;
|
||||
const ay = ey + (c.at[1] - ey) * k;
|
||||
path += `<path d="M${ex} ${ey} L${(ex + ax) / 2} ${ey} L${ax} ${ay}" stroke="rgba(100,116,139,${0.8 * c.o})" stroke-width="1.3" fill="none"/><circle cx="${c.at[0]}" cy="${c.at[1]}" r="${4.5 * k}" fill="${GREEN}" fill-opacity="${c.o}" stroke="#fff" stroke-width="1.5"/>`;
|
||||
});
|
||||
for (let i = (s.callouts || []).length; i < pool.length; i++) pool[i].style.display = 'none';
|
||||
lines.innerHTML = path;
|
||||
// cursor
|
||||
const c = s.cursor;
|
||||
if (c) {
|
||||
cur.style.display = 'block';
|
||||
cur.style.transform = `translate(${c.x - 3}px, ${c.y - 2}px) scale(${c.press ? 0.86 : 1})`;
|
||||
ring.style.opacity = String(c.ring * 0.9);
|
||||
ring.style.left = `${c.ringX}px`;
|
||||
ring.style.top = `${c.ringY}px`;
|
||||
ring.style.transform = `scale(${0.45 + (1 - c.ring) * 0.9})`;
|
||||
for (const [k, e] of Object.entries(pills)) e.classList.toggle('press', c.press && Math.hypot(spots[k][0] - c.x, spots[k][1] - c.y) < 40);
|
||||
} else cur.style.display = 'none';
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
// The green look for any creature film (first made for longcat/wasp and longcat/tarantula): the palette swap, the warm
|
||||
// glows turned green, the labels as two columns of soft cards inside the green page's viewport, and the operator's
|
||||
// pointer on its pill buttons. A creature's own film keeps its tour (movement, cameras, timing) and only routes its
|
||||
// state through these.
|
||||
import * as THREE from 'three';
|
||||
import {REST, VIEWPORT} from './console.js';
|
||||
|
||||
export const HUE = 0.405;
|
||||
export const ORANGE_TO = '#17b865';
|
||||
export const PAPER_GREEN = {top: '#ffffff', mid: '#fcfefd', low: '#f0f6f2', shadow: '#b4c6bd'};
|
||||
// the old consoles centre the subject in a 3D window at (800, 426); the green page's window centres at (785, 536)
|
||||
export const SHIFT = [-15, 110];
|
||||
|
||||
const ss = (a, b, t) => {
|
||||
const u = Math.min(1, Math.max(0, (t - a) / (b - a)));
|
||||
return u * u * u * (u * (u * 6 - 15) + 10);
|
||||
};
|
||||
|
||||
/** Every warm accent left in a creature's materials and lights (glows, tints, rims) turned to the same green. */
|
||||
export function retint(root) {
|
||||
const hsl = {};
|
||||
const fix = (c, minS = 0.4) => {
|
||||
if (!c?.isColor) return;
|
||||
// a glow colour above 1 (an HDR basic material, the octopus's coils and rings) is read and written at unit peak
|
||||
const k = Math.max(1, c.r, c.g, c.b);
|
||||
c.multiplyScalar(1 / k);
|
||||
c.getHSL(hsl);
|
||||
if ((hsl.h < 0.15 || hsl.h > 0.96) && hsl.s > minS) c.setHSL(HUE, Math.min(0.85, hsl.s), hsl.l);
|
||||
c.multiplyScalar(k);
|
||||
};
|
||||
const vc = new THREE.Color();
|
||||
root.traverse((o) => {
|
||||
// colours baked into a geometry's vertices (the shark's fang tips), turned once per geometry
|
||||
const ca = o.geometry?.attributes?.color;
|
||||
if (ca && !o.geometry.userData.tinted && [].concat(o.material || []).some((m) => m.vertexColors)) {
|
||||
o.geometry.userData.tinted = true;
|
||||
for (let i = 0; i < ca.count; i++) {
|
||||
vc.setRGB(ca.getX(i), ca.getY(i), ca.getZ(i));
|
||||
fix(vc);
|
||||
ca.setXYZ(i, vc.r, vc.g, vc.b);
|
||||
}
|
||||
ca.needsUpdate = true;
|
||||
}
|
||||
if (o.isLight && !o.userData.tinted) {
|
||||
o.userData.tinted = true;
|
||||
fix(o.color, 0.3);
|
||||
}
|
||||
for (const m of [].concat(o.material || [])) {
|
||||
// a colour the creature's pose rewrites every frame (the octopus's pulsing core) is turned again whenever it no
|
||||
// longer matches what was last written here
|
||||
const done = (m.userData.tinted ??= {});
|
||||
for (const key of ['color', 'emissive', 'attenuationColor']) {
|
||||
const c = m[key];
|
||||
if (!c?.isColor || done[key]?.equals(c)) continue;
|
||||
fix(c);
|
||||
done[key] = c.clone();
|
||||
}
|
||||
const u = m.uniforms?.uColor?.value;
|
||||
if (u?.isColor && !done.u?.equals(u)) {
|
||||
fix(u, 0.2);
|
||||
done.u = u.clone();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// the old consoles' capitals in the page's voice: units, axes and part codes keep their case
|
||||
const fixCase = (x) =>
|
||||
x
|
||||
.replace(/ø/g, 'Ø')
|
||||
.replace(/\bn·m\b/g, 'N·m')
|
||||
.replace(/\b(cpu|imu|ar|dof|led)\b/g, (m) => m.toUpperCase())
|
||||
.replace(/\b([lr])(\d)\b/g, (m, a, d) => a.toUpperCase() + d)
|
||||
.replace(/(\d) k\b/g, '$1 K');
|
||||
/** A part name in capitals, in sentence case. */
|
||||
export const nice = (s) => {
|
||||
const x = fixCase(s.toLowerCase());
|
||||
return x.charAt(0).toUpperCase() + x.slice(1);
|
||||
};
|
||||
/** A part's note in capitals, lower case with commas. */
|
||||
export const niceSub = (s) => fixCase(s.toLowerCase().replace(/ · /g, ', '));
|
||||
|
||||
/** Labels in two columns at the green viewport's edges; text: old capital name -> [name, sub] (or [name] to keep the
|
||||
* converted note) in the page's voice, anything missing converted by nice / niceSub. */
|
||||
export function makeLabels(st, anchors, text = {}) {
|
||||
const p = new THREE.Vector3();
|
||||
return ({set, o}) => {
|
||||
if (o < 0.02) return [];
|
||||
const pts = [];
|
||||
for (const [key, name, sub] of set) {
|
||||
const A = anchors[key];
|
||||
if (!A) continue;
|
||||
// an anchor is {obj, at} (a point on a part) or a function giving the world point (the octopus's)
|
||||
let w;
|
||||
if (typeof A === 'function') w = A();
|
||||
else {
|
||||
A.obj.updateWorldMatrix(true, false);
|
||||
w = A.obj.localToWorld(p.copy(A.at));
|
||||
}
|
||||
const at = st.project(w);
|
||||
const n2 = text[name]?.[0] ?? nice(name);
|
||||
const s2 = text[name]?.[1] ?? niceSub(sub);
|
||||
if (at && at[0] > VIEWPORT.x0 + 30 && at[0] < VIEWPORT.x1 - 30 && at[1] > VIEWPORT.y0 + 30 && at[1] < VIEWPORT.y1 - 60) pts.push({name: n2, sub: s2, at});
|
||||
}
|
||||
const mid = (VIEWPORT.x0 + VIEWPORT.x1) / 2;
|
||||
const out = [];
|
||||
const stack = (col, x, w) => {
|
||||
let y = Math.max(VIEWPORT.y0 + 30, Math.min(col.length ? col[0].at[1] - 10 : 0, VIEWPORT.y1 - 90 - 44 * col.length));
|
||||
for (const c of col) {
|
||||
y = Math.max(y, Math.min(VIEWPORT.y1 - 90, c.at[1] - 10));
|
||||
out.push({name: c.name, sub: c.sub, at: c.at, label: [x, y], w, o});
|
||||
y += 44;
|
||||
}
|
||||
};
|
||||
stack(pts.filter((x) => x.at[0] < mid).sort((a, b) => a.at[1] - b.at[1]), VIEWPORT.x0 + 8, 'l');
|
||||
stack(pts.filter((x) => x.at[0] >= mid).sort((a, b) => a.at[1] - b.at[1]), VIEWPORT.x1 - 8, 'r');
|
||||
return out;
|
||||
};
|
||||
}
|
||||
|
||||
/** The operator's pointer on the pill buttons; button maps an act to its pill. */
|
||||
export function makeCursor(ui, SCRIPT, button = (act) => (act === 'assemble' ? 'exploded' : act)) {
|
||||
const EV = SCRIPT.filter((e) => e.t > 0 && ui.spots[button(e.act)]).map((e) => ({t: e.t, spot: ui.spots[button(e.act)]}));
|
||||
const [RX, RY] = REST;
|
||||
const WP = [[0, RX, RY + 40]];
|
||||
let [px, py, pt] = [RX, RY + 40, 0];
|
||||
EV.forEach((e) => {
|
||||
const [x, y] = e.spot;
|
||||
const travel = Math.min(0.6, 0.28 + Math.hypot(x - px, y - py) / 1000);
|
||||
const arrive = e.t - 0.08;
|
||||
WP.push([Math.max(pt + 0.01, arrive - travel), px, py]);
|
||||
WP.push([arrive, x, y], [e.t + 0.16, x, y]);
|
||||
[px, py, pt] = [x + 30, y + 46, e.t + 0.5];
|
||||
WP.push([pt, px, py]);
|
||||
});
|
||||
WP.push([pt + 0.8, RX, RY + 60]);
|
||||
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(20, 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.5) {
|
||||
ring = 1 - (t - e.t) / 0.5;
|
||||
[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,42 @@
|
||||
// list the warm colours left on a green film's creature at time t (node sims/green/probe_warm.mjs <entry> <t> <global>)
|
||||
import {pathToFileURL} from 'node:url';
|
||||
import path from 'node:path';
|
||||
import {CHROMIUM, CHROMIUM_ARGS, DIST, playwright} from '../../paths.mjs';
|
||||
const [entry, t, glob] = process.argv.slice(2);
|
||||
const {chromium} = playwright();
|
||||
const browser = await chromium.launch({executablePath: CHROMIUM, args: CHROMIUM_ARGS});
|
||||
const page = await browser.newPage({viewport: {width: 1600, height: 900}, deviceScaleFactor: 1});
|
||||
await page.addInitScript(() => { window.__CAPTURE = true; window.__SIM_CONFIG = {}; });
|
||||
await page.goto(pathToFileURL(path.join(DIST, `${entry}.html`)).href);
|
||||
await page.waitForFunction(() => window.SIM && window.SIM.ready, null, {timeout: 60000});
|
||||
const res = await page.evaluate(([t, glob]) => {
|
||||
window.SIM.render(Number(t));
|
||||
const out = {};
|
||||
const warm = (c) => {
|
||||
if (!c?.isColor) return false;
|
||||
const k = Math.max(1e-6, c.r, c.g, c.b);
|
||||
const r = c.r / k, g = c.g / k, b = c.b / k;
|
||||
return r > 0.9 && b < 0.6 && g < 0.85 && r - b > 0.3;
|
||||
};
|
||||
const hex = (c) => [c.r, c.g, c.b].map((v) => v.toFixed(2)).join(',');
|
||||
const scene = window[glob].st.scene ?? null;
|
||||
const roots = [window[glob].oc?.root ?? window[glob].sp?.root ?? window[glob].fish?.root ?? window[glob].bee?.root];
|
||||
if (scene) roots.push(scene);
|
||||
for (const [ri, r] of roots.entries()) r.traverse((o) => {
|
||||
if (o.isLight && warm(o.color)) out[`${ri} light ${o.type} ${hex(o.color)}`] = (out[`${ri} light ${o.type} ${hex(o.color)}`] ?? 0) + 1;
|
||||
for (const m of [].concat(o.material || [])) for (const key of ['color', 'emissive', 'attenuationColor', 'sheenColor', 'specularColor']) if (warm(m[key])) { const id = `${ri} ${m.type} ${key} ${hex(m[key])} map:${!!m.map} emap:${!!m.emissiveMap} vc:${!!m.vertexColors}`; out[id] = (out[id] ?? 0) + 1; }
|
||||
for (const [nm, at] of [['vertex', o.geometry?.attributes?.color], ['instance', o.instanceColor]]) {
|
||||
if (!at) continue;
|
||||
let n = 0;
|
||||
const c = {isColor: true, r: 0, g: 0, b: 0};
|
||||
for (let i = 0; i < at.count; i++) {
|
||||
c.r = at.getX(i); c.g = at.getY(i); c.b = at.getZ(i);
|
||||
if (warm(c)) n++;
|
||||
}
|
||||
if (n) out[`${ri} ${nm} colours warm: ${n} of ${at.count}`] = (out[`${ri} ${nm} colours warm: ${n} of ${at.count}`] ?? 0) + 1;
|
||||
}
|
||||
});
|
||||
return out;
|
||||
}, [t, glob]);
|
||||
console.log(JSON.stringify(res, null, 1));
|
||||
await browser.close();
|
||||
Reference in New Issue
Block a user