caelum0x d56639a594
Some checks are pending
build-images / api (push) Waiting to run
build-images / worker-gpu (push) Waiting to run
build-images / web (push) Waiting to run
codeql / Analyze (javascript-typescript) (push) Waiting to run
codeql / Analyze (python) (push) Waiting to run
perf / API hot-path micro-smoke (budgeted) (push) Waiting to run
perf / Desktop engine crates (release build check) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (comfy-workflow-schema) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (effects-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (eventbus-types) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (growth-analytics) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (trends-schema) (push) Waiting to run
vision2026-ci / API phase modules (ruff + pytest) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (provider-adapter-kit) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (publishing-connectors) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (render-core) (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (shot-template-schema) (push) Waiting to run
vision2026-ci / Python SDK resource tests (push) Waiting to run
vision2026-ci / Desktop engine crates (test + clippy + fmt) (push) Waiting to run
vision2026-ci / Alembic upgrade + drift check (push) Waiting to run
vision2026-ci / Shared packages (TS≡Python golden parity) (caption-engine) (push) Waiting to run
Menivor — open source release (MIT), free to use and fork
Paid, hosted product at menivor.com, now retired as a company project.
Fresh squashed history of the cleaned working tree (secret-scanned,
no .env, no customer data, no outreach logs). Built on
MoneyPrinterTurbo (MIT, harry0703) — see NOTICE.
2026-12-04 02:10:26 +03:00

469 lines
19 KiB
HTML

<!doctype html>
<!-- Menivor original loop: glossy marbles roll down a zig-zag track and drop
into the slotted cups of a bucket lift that carries them back to the top.
One cup per marble, one full machine cycle = 8 s => seamless by construction.
?v=1 base (4 ramps, pegboard); ?v=2 six short ramps, mirrored lift, wood-slat wall,
10 jewel marbles; ?v=3 ramp -> peg-bounce column -> long return ramp, spinning
pinwheels, mint tile wall, metallic marbles. -->
<html>
<head>
<meta charset="utf-8" />
<style>html,body{margin:0;background:#000}canvas{display:block}</style>
<script type="importmap">{ "imports": { "three": "./three.module.js" } }</script>
</head>
<body>
<script type="module">
import * as THREE from 'three';
import { RoomEnvironment } from './RoomEnvironment.js';
const W = 720, H = 1280, FPS = 30, LOOP_S = 8;
const V = Math.max(1, parseInt(new URLSearchParams(location.search).get('v') || '1', 10) || 1);
const THEMES = {
1: {
r: 0.24, layout: 'classic', mirror: false, wall: 'pegboard', wallColors: ['#3b3572', '#2a2556'], bg: '#2e2a5c',
colors: ['#ff6f7d', '#ffa552', '#ffd84d', '#5fd68c', '#35c9c1', '#4fa3ff', '#8f7bff', '#ff7ccf'],
rampColors: ['#ffb4a2', '#9ee6c3', '#a9c8ff', '#ffd98f'], plank: '#f7e3c6', base: '#cdb4e6',
roller: '#b9a2e0', spoke: '#8f78c4', belt: '#7d68b3', post: '#cdb4e6', cup: '#ffffff', hemiGround: '#e6d6ee',
metal: 0,
},
2: {
r: 0.17, layout: 'six', mirror: true, wall: 'slats', wallColors: ['#b98a5e', '#a77850', '#c89b6d', '#7d5536'], bg: '#5e3f28',
colors: ['#e63946', '#f4a261', '#e9c46a', '#2a9d8f', '#1d3557', '#8ab17d', '#6d597a', '#b56576', '#457b9d', '#ffb4a2'],
rampColors: ['#2bb3a3', '#f2b84b', '#ef6f5e', '#3d7ea6', '#8ab17d', '#e07a9c'], plank: '#fff3dc', base: '#6b4430',
roller: '#2f4f5f', spoke: '#f2b84b', belt: '#264653', post: '#e9d8b4', cup: '#fff3dc', hemiGround: '#e9c9a8',
metal: 0,
},
3: {
r: 0.22, layout: 'plinko', mirror: false, wall: 'tiles', wallColors: ['#cdeee0', '#b3dccb', '#d8f4e8'], bg: '#9fcfbd',
colors: ['#e8c15a', '#d9824f', '#cfd6de', '#2b2b33', '#f2a7b6', '#2fa37a', '#3a6fd8', '#f4efe6'],
rampColors: ['#ff8a73', '#ffd166'], plank: '#ffffff', base: '#ffb3a7', peg: '#ff8a73', pin: ['#ffd166', '#ff8a73', '#7ec8e3', '#b9a2e0'],
roller: '#ff8a73', spoke: '#ffffff', belt: '#e76f5a', post: '#ffd9cf', cup: '#ffffff', hemiGround: '#d9f2e8',
metal: 0.45,
},
};
const T = THEMES[V] || THEMES[1];
const BALLS = T.colors.length;
const R = T.r; // marble radius
const K = R / 0.24; // size scale vs. base
const COLORS = T.colors;
// ---------- bucket lift (closed belt around two rollers) ----------
const LIFT_X = -1.2, ROLL_R = 0.35, ROLL_Y = 1.75;
const RUN = 2 * ROLL_Y; // straight run length
const BELT_LEN = 2 * RUN + 2 * Math.PI * ROLL_R;
const BELT_V = BELT_LEN / LOOP_S; // each cup laps once per loop
// Belt parameter p -> position + outward normal.
function beltAt(p) {
p = ((p % BELT_LEN) + BELT_LEN) % BELT_LEN;
const arc = Math.PI * ROLL_R;
if (p < RUN) return { x: LIFT_X + ROLL_R, y: -ROLL_Y + p, nx: 1, ny: 0 };
p -= RUN;
if (p < arc) { const a = p / ROLL_R; return { x: LIFT_X + ROLL_R * Math.cos(a), y: ROLL_Y + ROLL_R * Math.sin(a), nx: Math.cos(a), ny: Math.sin(a) }; }
p -= arc;
if (p < RUN) return { x: LIFT_X - ROLL_R, y: ROLL_Y - p, nx: -1, ny: 0 };
p -= RUN;
const a = Math.PI + p / ROLL_R;
return { x: LIFT_X + ROLL_R * Math.cos(a), y: -ROLL_Y + ROLL_R * Math.sin(a), nx: Math.cos(a), ny: Math.sin(a) };
}
const CUP_OUT = 0.27 * K, CUP_UP = 0.22 * K; // marble center relative to belt point
const P_ENTRY = 0.12, P_EXIT = RUN - 0.2; // belt params where a marble boards / leaves
const LIFT_T = (P_EXIT - P_ENTRY) / BELT_V;
// ---------- track: ball-center waypoints ----------
const liftTop = { x: LIFT_X + ROLL_R + CUP_OUT, y: -ROLL_Y + P_EXIT + CUP_UP };
const liftBot = { x: LIFT_X + ROLL_R + CUP_OUT, y: -ROLL_Y + P_ENTRY + CUP_UP };
// Segments of one marble's journey (duration in seconds + position function of s∈[0,1]).
const lerp = (a, b, s) => a + (b - a) * s;
const SEGS = [];
function hop(p, q, d, arc) {
SEGS.push({ d, f: (s) => ({ x: lerp(p.x, q.x, s), y: lerp(p.y, q.y, s) + arc * 4 * s * (1 - s) }) });
}
function roll(p, q, d) {
SEGS.push({ d, f: (s) => { const e = 0.3 * s + 0.7 * s * s; return { x: lerp(p.x, q.x, e), y: lerp(p.y, q.y, e) }; } });
}
function drop(p, q, d) {
// leaves the ledge with forward speed, hits the bumper, falls onto the next ramp
SEGS.push({ d, f: (s) => ({ x: lerp(p.x, q.x, Math.sin(s * Math.PI / 2)), y: p.y + (q.y - p.y) * s * s }) });
}
function finish() {
const used = SEGS.reduce((acc, s) => acc + s.d, 0);
if (used >= LOOP_S - 0.001) throw new Error(`track too long: ${used}`);
return used;
}
// PLANKS: visual ramps {a, b, bumper}. PEGS: [x, y, contact]. PINWHEELS: [x, y, radius, turns].
let PLANKS = [];
const PEGS = [];
const PINWHEELS = [];
SEGS.push({ d: LIFT_T, f: (s) => ({ x: liftTop.x, y: lerp(liftBot.y, liftTop.y, s) }) });
if (T.layout === 'classic' || T.layout === 'six') {
const RAMPS = T.layout === 'classic' ? [
{ a: { x: -0.3, y: 1.52 }, b: { x: 2.75, y: 1.2 } },
{ a: { x: 2.95, y: 0.62 }, b: { x: 0.35, y: 0.32 } },
{ a: { x: 0.15, y: -0.28 }, b: { x: 2.75, y: -0.6 } },
{ a: { x: 2.95, y: -1.18 }, b: { x: -0.3, y: -1.5 } },
] : (() => {
// six short, steeper ramps stacked tighter (smaller marbles), alternating direction
const out = [];
let y = 1.5;
for (let i = 0; i < 6; i++) {
const right = i % 2 === 0;
const a = { x: right ? (i === 0 ? -0.3 : 0.25) : 2.75, y };
const b = { x: right ? 2.55 : (i === 5 ? -0.3 : 0.45), y: y - 0.2 };
out.push({ a, b });
y -= 0.515;
}
return out;
})();
const rampTimes = T.layout === 'classic' ? [1.0, 1.05, 1.05, 1.0] : [0.62, 0.6, 0.6, 0.6, 0.6, 0.62];
const dropT = T.layout === 'classic' ? 0.3 : 0.24;
hop(liftTop, RAMPS[0].a, 0.22, 0.12);
for (let i = 0; i < RAMPS.length; i++) {
roll(RAMPS[i].a, RAMPS[i].b, rampTimes[i]);
if (i < RAMPS.length - 1) drop(RAMPS[i].b, RAMPS[i + 1].a, dropT);
}
hop(RAMPS[RAMPS.length - 1].b, liftBot, LOOP_S - finish(), 0.06); // remaining time: settle into the cup
PLANKS = RAMPS.map((r, i) => ({ ...r, bumper: i > 0 }));
} else {
// ramp -> bouncing peg column -> long return ramp
const r0 = { a: { x: -0.3, y: 1.5 }, b: { x: 1.7, y: 1.22 } };
const r1 = { a: { x: 2.3, y: -0.92 }, b: { x: -0.3, y: -1.4 } };
hop(liftTop, r0.a, 0.22, 0.12);
roll(r0.a, r0.b, 0.9);
const bounces = [
{ x: 1.98, y: 0.78 }, { x: 1.52, y: 0.42 }, { x: 1.98, y: 0.06 },
{ x: 1.52, y: -0.3 }, { x: 1.9, y: -0.62 },
];
drop(r0.b, bounces[0], 0.3);
for (let i = 0; i + 1 < bounces.length; i++) hop(bounces[i], bounces[i + 1], 0.29, 0.16);
const land = { x: 1.7, y: lerp(r1.a.y, r1.b.y, (r1.a.x - 1.7) / (r1.a.x - r1.b.x)) };
hop(bounces[bounces.length - 1], land, 0.3, 0.1);
roll(land, r1.b, 1.75);
hop(r1.b, liftBot, LOOP_S - finish(), 0.06);
PLANKS = [{ ...r0, bumper: false }, { ...r1, bumper: true }];
// contact pegs: just under each bounce, nudged opposite to the next hop direction
const PEG_R = 0.06;
bounces.forEach((p, i) => {
const next = bounces[i + 1] || land;
const off = next.x < p.x ? 0.07 : -0.07;
PEGS.push([p.x + off, p.y - Math.sqrt((R + PEG_R) ** 2 - off * off), true]);
});
// decorative staggered peg field, kept clear of the marble's path
const path = [];
for (let k = 0; k <= 800; k++) path.push(marbleAtRaw((k / 800) * LOOP_S));
PINWHEELS.push([0.42, 0.18, 0.5, 2], [2.95, 0.2, 0.42, -3]);
for (let row = 0; row < 8; row++) for (let col = 0; col < 6; col++) {
const x = 1.05 + col * 0.34 + (row % 2) * 0.17, y = 0.8 - row * 0.21;
if (PINWHEELS.some(([px, py, pr]) => Math.hypot(px - x, py - y) < pr + 0.12)) continue;
if (path.every((q) => Math.hypot(q.x - x, q.y - y) > R + PEG_R + 0.07) &&
PEGS.every(([px, py]) => Math.hypot(px - x, py - y) > 0.2)) PEGS.push([x, y, false]);
}
}
function marbleAtRaw(tau) {
tau = ((tau % LOOP_S) + LOOP_S) % LOOP_S;
for (const s of SEGS) {
if (tau < s.d) return s.f(tau / s.d);
tau -= s.d;
}
return SEGS[0].f(0);
}
const marbleAt = marbleAtRaw;
// Rolling spin: integrate signed arc length / R, then spread the remainder so the
// total over a loop is a whole number of turns (keeps the stripe seamless).
const SPIN_STEPS = 4800;
const spinTable = new Float32Array(SPIN_STEPS + 1);
{
let prev = marbleAt(0), acc = 0;
for (let k = 1; k <= SPIN_STEPS; k++) {
const tau = (k / SPIN_STEPS) * LOOP_S;
const cur = marbleAt(tau - 1e-6 * (k === SPIN_STEPS));
const tauPrev = ((k - 1) / SPIN_STEPS) * LOOP_S;
const onLift = tauPrev < LIFT_T;
const dx = cur.x - prev.x, dy = cur.y - prev.y;
if (!onLift) acc += -Math.sign(dx) * Math.hypot(dx, dy) / R;
spinTable[k] = acc;
prev = cur;
}
const total = spinTable[SPIN_STEPS];
const fix = total - Math.round(total / (2 * Math.PI)) * 2 * Math.PI;
for (let k = 0; k <= SPIN_STEPS; k++) spinTable[k] -= fix * (k / SPIN_STEPS);
}
const spinAt = (tau) => spinTable[Math.round((((tau % LOOP_S) + LOOP_S) % LOOP_S) / LOOP_S * SPIN_STEPS) % SPIN_STEPS];
// ---------- renderer / scene ----------
const renderer = new THREE.WebGLRenderer({ antialias: true, preserveDrawingBuffer: true });
renderer.setPixelRatio(1);
renderer.setSize(W, H);
renderer.outputColorSpace = THREE.SRGBColorSpace;
renderer.toneMapping = THREE.NeutralToneMapping;
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
document.body.appendChild(renderer.domElement);
const scene = new THREE.Scene();
scene.background = new THREE.Color(T.bg);
const pmrem = new THREE.PMREMGenerator(renderer);
scene.environment = pmrem.fromScene(new RoomEnvironment(), 0.04).texture;
scene.environmentIntensity = 0.75;
// Everything machine-side lives in `root`; variant 2 mirrors it (lift on the right).
const root = new THREE.Group();
if (T.mirror) { root.scale.x = -1; root.position.x = 1.6; }
scene.add(root);
const sun = new THREE.DirectionalLight('#fff4ea', 2.2);
sun.position.set(3, 6, 8);
sun.target.position.set(0.8, 0, 0);
sun.castShadow = true;
sun.shadow.mapSize.set(2048, 2048);
sun.shadow.radius = 6;
sun.shadow.bias = -0.0005;
Object.assign(sun.shadow.camera, { left: -6, right: 6, top: 6, bottom: -6, near: 1, far: 30 });
scene.add(sun, sun.target);
scene.add(new THREE.HemisphereLight('#ffffff', T.hemiGround, 0.6));
const std = (color, rough = 0.55) => new THREE.MeshStandardMaterial({ color, roughness: rough, metalness: 0 });
// Backdrop wall (procedural texture).
{
const c = document.createElement('canvas');
const g = c.getContext('2d');
const wc = T.wallColors;
let rep = [24, 40];
if (T.wall === 'pegboard') {
c.width = c.height = 64;
g.fillStyle = wc[0]; g.fillRect(0, 0, 64, 64);
g.fillStyle = wc[1];
g.beginPath(); g.arc(32, 32, 5, 0, Math.PI * 2); g.fill();
} else if (T.wall === 'slats') {
// vertical wooden slats with grain and dark gaps
c.width = 256; c.height = 512;
let s = 7;
const rr = () => ((s = (s * 16807) % 2147483647) / 2147483647);
for (let i = 0; i < 4; i++) {
g.fillStyle = wc[i % 3];
g.fillRect(i * 64, 0, 64, 512);
for (let k = 0; k < 14; k++) {
g.strokeStyle = `rgba(90,55,30,${0.08 + rr() * 0.12})`;
g.lineWidth = 1 + rr() * 2;
const x = i * 64 + 6 + rr() * 52;
g.beginPath(); g.moveTo(x, 0);
g.bezierCurveTo(x + (rr() - 0.5) * 10, 170, x + (rr() - 0.5) * 10, 340, x, 512); g.stroke();
}
g.fillStyle = wc[3];
g.fillRect(i * 64 + 61, 0, 3, 512);
}
rep = [3.5, 3];
} else {
// glazed square tiles with grout
c.width = c.height = 128;
g.fillStyle = wc[1]; g.fillRect(0, 0, 128, 128);
for (const [x, y, col] of [[0, 0, wc[0]], [64, 0, wc[2]], [0, 64, wc[2]], [64, 64, wc[0]]]) {
g.fillStyle = col; g.fillRect(x + 3, y + 3, 58, 58);
g.fillStyle = 'rgba(255,255,255,0.25)'; g.fillRect(x + 6, y + 6, 20, 4);
}
rep = [9, 15];
}
const tex = new THREE.CanvasTexture(c);
tex.colorSpace = THREE.SRGBColorSpace;
tex.wrapS = tex.wrapT = THREE.RepeatWrapping;
tex.repeat.set(...rep);
tex.anisotropy = 8;
const wall = new THREE.Mesh(new THREE.PlaneGeometry(14, 24), new THREE.MeshStandardMaterial({ map: tex, roughness: 0.9 }));
wall.position.set(0.8, 0, -0.75);
wall.receiveShadow = true;
scene.add(wall);
}
// Base shelf
{
const base = new THREE.Mesh(new THREE.BoxGeometry(6.2, 0.3, 1.4), std(T.base, 0.6));
base.position.set(0.85, -2.45, -0.05);
base.castShadow = base.receiveShadow = true;
root.add(base);
}
// Ramps: plank + back rail + low front rail + bumper at the high end.
const RAMP_COLORS = T.rampColors;
PLANKS.forEach((rp, i) => {
const g = new THREE.Group();
const dx = rp.b.x - rp.a.x, dy = rp.b.y - rp.a.y;
const len = Math.hypot(dx, dy);
const ang = Math.atan2(dx < 0 ? -dy : dy, Math.abs(dx)); // keep the plank under the path
const dir = Math.sign(dx);
const extra = 0.45;
const col = RAMP_COLORS[i % RAMP_COLORS.length];
const plank = new THREE.Mesh(new THREE.BoxGeometry(len + extra, 0.09, 0.56), std(T.plank, 0.5));
plank.position.set(0, -R - 0.045, 0);
const back = new THREE.Mesh(new THREE.BoxGeometry(len + extra, 0.2, 0.06), std(col, 0.35));
back.position.set(0, -R + 0.06, -0.27);
const front = new THREE.Mesh(new THREE.BoxGeometry(len + extra, 0.1, 0.06), std(col, 0.35));
front.position.set(0, -R + 0.01, 0.27);
for (const m of [plank, back, front]) { m.castShadow = m.receiveShadow = true; g.add(m); }
g.position.set((rp.a.x + rp.b.x) / 2 - dir * 0.02, (rp.a.y + rp.b.y) / 2, 0);
g.rotation.z = ang;
root.add(g);
if (rp.bumper) {
// bumper wall at the high end the marble drops onto
const bump = new THREE.Mesh(new THREE.BoxGeometry(0.08, 0.5, 0.6), std(col, 0.35));
bump.position.set(rp.a.x + dir * -(R + 0.12), rp.a.y + 0.05, 0);
bump.castShadow = true;
root.add(bump);
}
});
// Peg field (variant 3).
if (PEGS.length) {
const pegGeo = new THREE.CylinderGeometry(0.06, 0.06, 0.5, 20);
const capGeo = new THREE.CylinderGeometry(0.085, 0.085, 0.04, 20);
const pegMat = std(T.peg, 0.3), capMat = std('#ffffff', 0.3);
for (const [x, y, contact] of PEGS) {
const p = new THREE.Mesh(pegGeo, contact ? pegMat : std('#ffffff', 0.35));
p.rotation.x = Math.PI / 2;
p.position.set(x, y, -0.2);
p.castShadow = true;
root.add(p);
const cap = new THREE.Mesh(capGeo, contact ? capMat : pegMat);
cap.rotation.x = Math.PI / 2;
cap.position.set(x, y, 0.07);
root.add(cap);
}
}
// Pinwheels (variant 3): spin a whole number of turns per loop.
const pinwheels = PINWHEELS.map(([x, y, rad, turns], n) => {
const g = new THREE.Group();
for (let b = 0; b < 4; b++) {
const blade = new THREE.Mesh(new THREE.BoxGeometry(rad, rad * 0.34, 0.05), std(T.pin[(b + n) % T.pin.length], 0.4));
blade.position.set(rad / 2, rad * 0.1, 0);
const arm = new THREE.Group();
arm.rotation.z = (b * Math.PI) / 2;
arm.add(blade);
blade.castShadow = true;
g.add(arm);
}
const hub = new THREE.Mesh(new THREE.CylinderGeometry(0.07, 0.07, 0.14, 20), std('#ffffff', 0.3));
hub.rotation.x = Math.PI / 2;
hub.position.z = 0.05;
g.add(hub);
const stick = new THREE.Mesh(new THREE.CylinderGeometry(0.04, 0.04, 0.5, 12), std(T.post, 0.5));
stick.rotation.x = Math.PI / 2;
stick.position.set(x, y, -0.4);
root.add(stick);
g.position.set(x, y, -0.1);
root.add(g);
return { g, turns };
});
// Lift: rollers, belt, frame, cups.
const rollers = [];
for (const y of [ROLL_Y, -ROLL_Y]) {
const r = new THREE.Mesh(new THREE.CylinderGeometry(ROLL_R - 0.03, ROLL_R - 0.03, 0.62, 32), std(T.roller, 0.35));
r.rotation.x = Math.PI / 2;
r.position.set(LIFT_X, y, -0.02);
r.castShadow = true;
root.add(r);
rollers.push(r);
// spokes so roller rotation reads
const sp = new THREE.Mesh(new THREE.BoxGeometry(ROLL_R * 1.7, 0.07, 0.66), std(T.spoke, 0.4));
sp.position.copy(r.position);
root.add(sp);
rollers.push(sp);
}
{
const beltMat = std(T.belt, 0.6);
for (const x of [LIFT_X + ROLL_R, LIFT_X - ROLL_R]) {
const b = new THREE.Mesh(new THREE.BoxGeometry(0.05, RUN, 0.5), beltMat);
b.position.set(x, 0, -0.02);
b.castShadow = true;
root.add(b);
}
for (const [y, rot] of [[ROLL_Y, 0], [-ROLL_Y, Math.PI]]) {
const t = new THREE.Mesh(new THREE.CylinderGeometry(ROLL_R + 0.025, ROLL_R + 0.025, 0.5, 32, 1, true, 0, Math.PI), beltMat);
t.rotation.x = Math.PI / 2;
t.rotation.y = rot + Math.PI / 2;
t.position.set(LIFT_X, y, -0.02);
root.add(t);
}
const post = new THREE.Mesh(new THREE.BoxGeometry(0.18, RUN + 1.2, 0.18), std(T.post, 0.6));
post.position.set(LIFT_X, -0.3, -0.45);
post.castShadow = true;
root.add(post);
}
const cupMat = std(T.cup, 0.3);
const cups = [];
for (let k = 0; k < BALLS; k++) {
const cup = new THREE.Group();
const shelf = new THREE.Mesh(new THREE.BoxGeometry(0.46 * K, 0.06, 0.5), new THREE.MeshStandardMaterial({ color: COLORS[k], roughness: 0.4 }));
shelf.position.set(0.23 * K, 0, 0);
const lip = new THREE.Mesh(new THREE.BoxGeometry(0.06, 0.16 * K, 0.5), cupMat);
lip.position.set(0.46 * K, 0.06 * K, 0);
for (const m of [shelf, lip]) { m.castShadow = true; cup.add(m); }
root.add(cup);
cups.push(cup);
}
// Marbles: clearcoat glossy spheres with a painted meridian stripe so rolling reads.
function marbleTexture(color) {
const c = document.createElement('canvas');
c.width = 256; c.height = 128;
const g = c.getContext('2d');
g.fillStyle = color; g.fillRect(0, 0, 256, 128);
g.fillStyle = color === '#f4efe6' || color === '#cfd6de' ? 'rgba(60,60,80,0.55)' : 'rgba(255,255,255,0.9)';
g.fillRect(56, 0, 16, 128);
g.fillRect(184, 0, 16, 128);
const t = new THREE.CanvasTexture(c);
t.colorSpace = THREE.SRGBColorSpace;
t.anisotropy = 8;
return t;
}
const sphere = new THREE.SphereGeometry(R, 48, 32);
const marbles = COLORS.map((col) => {
const m = new THREE.Mesh(sphere, new THREE.MeshPhysicalMaterial({
map: marbleTexture(col), roughness: T.metal ? 0.22 : 0.12, metalness: T.metal, clearcoat: 1, clearcoatRoughness: 0.05,
}));
m.castShadow = true;
root.add(m);
return m;
});
const camera = new THREE.PerspectiveCamera(30, W / H, 0.1, 100);
camera.position.set(0.9, 2.4, 17);
camera.lookAt(0.75, -0.15, 0);
function update(t) {
// Cup k boards marble k at belt param P_ENTRY when the marble's journey time is 0.
for (let k = 0; k < BALLS; k++) {
const tau = t + (k * LOOP_S) / BALLS;
const p = P_ENTRY + BELT_V * tau;
const b = beltAt(p);
const cup = cups[k];
const lift = CUP_UP - R - 0.03; // shelf sits just under the marble
cup.position.set(b.x - b.ny * lift, b.y + b.nx * lift, 0);
cup.rotation.z = Math.atan2(b.ny, b.nx);
const pos = marbleAt(tau);
const m = marbles[k];
m.position.set(pos.x, pos.y, 0);
m.rotation.set(0, 0, spinAt(tau));
}
const rollAng = -BELT_V * t / ROLL_R;
for (const r of rollers) if (r.geometry.type === 'BoxGeometry') r.rotation.z = rollAng;
for (const { g, turns } of pinwheels) g.rotation.z = (2 * Math.PI * turns * t) / LOOP_S;
}
window.renderFrame = (i) => {
const t = (i % (FPS * LOOP_S)) / FPS;
update(t);
renderer.render(scene, camera);
return renderer.domElement.toDataURL('image/png');
};
window.sceneReady = true;
</script>
</body>
</html>