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

630 lines
28 KiB
HTML

<!doctype html>
<!-- Menivor original loop: first-person voxel parkour over floating pillars.
Procedural textures + geometry only. World repeats every LOOP_LEN along -z,
camera covers exactly LOOP_LEN in 8 s => seamless loop. See render-loops.mjs.
?v=1 is the base look; ?v=2..6 are seeded variants (course layout, sky/time of
day, block palette, scenery props, weather) defined in THEMES below. -->
<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';
const W = 720, H = 1280, FPS = 30, LOOP_S = 8;
const EYE = 1.62;
const V = Math.max(1, parseInt(new URLSearchParams(location.search).get('v') || '1', 10) || 1);
// Seeded RNG (mulberry32) so every run produces identical pixels.
function rng(seed) {
let a = seed >>> 0;
return () => {
a = (a + 0x6d2b79f5) >>> 0;
let t = a;
t = Math.imul(t ^ (t >>> 15), t | 1);
t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
};
}
// ---------- themes (all palettes are our own) ----------
const THEMES = {
1: { // base: bright day, mint meadow + clay + blue slate + coral
sky: [[0, '#4f9fe8'], [0.45, '#8cc6f2'], [0.62, '#dff0fb'], [0.75, '#f6ecdc'], [1, '#f3e5cf']],
fog: ['#dff0fb', 22, 78], hemi: ['#d7ecff', '#7a6450', 1.35], sun: ['#fff1dc', 1.9, [-6, 14, 4]],
top: ['#63c96b', '#72d477', '#58b862', '#86de83', '#4fae5c'],
soil: ['#a86f4c', '#b67c56', '#9a6343', '#8d5a3d', '#c08a60'],
stone: ['#7d8ea3', '#8898ad', '#71829a', '#93a3b6', '#6a7a90'],
accent: ['#f08a6c', '#f59a7a', '#e57b5e', '#f7ab8c', '#d86f55'],
style: 'base', clouds: { n: 7, color: '#ffffff', em: '#e8f2ff', ei: 0.55, y: [16, 24] },
vignette: 'rgba(10,20,40,0.28)', legacy: true,
},
2: { // autumn sunrise: violet-to-peach sky, low warm sun, amber leaf-litter tops
sky: [[0, '#4d5aa8'], [0.3, '#9a7fc4'], [0.5, '#f29fb0'], [0.62, '#ffc9a8'], [0.78, '#ffe0bf'], [1, '#f7d2b4']],
fog: ['#ffc9a8', 18, 70], hemi: ['#ffd8c8', '#5a3c46', 1.25], sun: ['#ffb57a', 2.1, [-12, 5, -6]],
top: ['#e39a3b', '#eeb04c', '#c9782f', '#f3c25f', '#b8612a'],
soil: ['#6f4a3c', '#7b5444', '#633f33', '#57372d', '#86604d'],
stone: ['#8f7f96', '#9b8ba3', '#83738c', '#a898ae', '#76677f'],
accent: ['#f2c14e', '#f7d06a', '#e3ad3c', '#fbe08e', '#d69a2f'],
style: 'leaves', stoneStyle: 'bond', cap: 3, decor: 'tree', trunk: ['#6b4a36', '#5c3f2e', '#7a5640'],
leaf: ['#d9543a', '#e8703f', '#c2412f', '#f08a4a', '#b53a2c'],
clouds: { n: 9, color: '#ffd9c7', em: '#ffb59a', ei: 0.6, y: [13, 22] },
disc: { color: '#fff0c8', glow: 'rgba(255,190,120,', size: 40, dir: [-0.35, 0.12, -1] },
vignette: 'rgba(60,20,40,0.26)',
course: { seed: 202, n: 8, spacing: 5.2, xMax: 2, yMax: 2, dMin: 2, dMax: 3, wMin: 2, accentP: 0.2 },
},
3: { // violet dusk: teal turf, plum soil, indigo stone, glowing crystal spires
sky: [[0, '#1d1646'], [0.3, '#4a2d78'], [0.5, '#9b4f95'], [0.62, '#e57f8c'], [0.74, '#f7ab86'], [1, '#e79b82']],
fog: ['#d9818c', 16, 64], hemi: ['#c9a2ff', '#2a1e3a', 1.1], sun: ['#ffae84', 1.5, [10, 4, -8]],
top: ['#3fb8a0', '#4cc7ad', '#33a18d', '#6ad6bd', '#2b8f7e'],
soil: ['#5a3f5e', '#654867', '#4d3552', '#43304a', '#70546f'],
stone: ['#4b4f7a', '#565a86', '#41456e', '#636894', '#393d62'],
accent: ['#e45ab8', '#ef72c7', '#d048a6', '#f693d6', '#b83c92'],
accentGlow: ['#ff5fc8', 0.35],
style: 'speckle', stoneStyle: 'cobble', cap: 4, decor: 'crystal', crystal: ['#7ef0ff', '#a6f6ff', '#5fd8f0', '#c8fbff'],
clouds: { n: 8, color: '#f3b3c8', em: '#b8659a', ei: 0.5, y: [14, 22] },
stars: 140, disc: { color: '#ffe3b8', glow: 'rgba(255,150,120,', size: 30, dir: [0.4, 0.06, -1] },
vignette: 'rgba(30,10,50,0.34)',
course: { seed: 303, n: 10, spacing: 4.2, xMax: 3, yMax: 2, dMin: 1, dMax: 2, wMin: 1, accentP: 0.25, zig: true },
},
4: { // starry night: moonlit blue-green turf, deep slate, glowing lantern blocks
sky: [[0, '#030716'], [0.35, '#0b1638'], [0.56, '#1b2f68'], [0.64, '#23397a'], [1, '#15234d']],
fog: ['#23397a', 16, 60], hemi: ['#8fa6ff', '#1e1a3a', 1.75], sun: ['#c4d2ff', 1.5, [8, 12, 2]],
top: ['#48a89f', '#52b5aa', '#3d948d', '#68c6b9', '#34827c'],
soil: ['#4a4058', '#554a64', '#3f3650', '#362e45', '#62566f'],
stone: ['#4a5580', '#56628e', '#414b72', '#65729e', '#363f63'],
accent: ['#ffc861', '#ffd684', '#f2b64a', '#ffe3a3', '#e0a23c'],
accentGlow: ['#ffb84a', 1.25],
style: 'speckle', stoneStyle: 'bond', cap: 3, decor: 'lantern', lanternsOnCourse: true,
clouds: null, stars: 520, disc: { color: '#f4f7ff', glow: 'rgba(170,190,255,', size: 26, dir: [0.28, 0.5, -1], moon: true },
vignette: 'rgba(0,0,12,0.4)',
course: { seed: 404, n: 7, spacing: 5.8, xMax: 2, yMax: 3, dMin: 2, dMax: 4, wMin: 2, accentP: 0.28 },
},
5: { // overcast snowfall: snow-capped blocks, ice accents, pines
sky: [[0, '#8e9aab'], [0.4, '#b5bfcc'], [0.6, '#d7dde5'], [0.75, '#e2e6ec'], [1, '#d5dae2']],
fog: ['#d9dee6', 10, 50], hemi: ['#eef3ff', '#7c8290', 1.5], sun: ['#ffffff', 0.8, [-4, 12, 6]],
top: ['#f4f8fc', '#ffffff', '#e8eef6', '#dbe6f2', '#f9fbfe'],
soil: ['#6e5a4b', '#7a6555', '#625041', '#574638', '#84705f'],
stone: ['#8c96a3', '#98a2ae', '#808a97', '#a5aeb9', '#737d8a'],
accent: ['#8fd3f0', '#a7def5', '#78c4e6', '#c4ebfa', '#62b2d8'],
accentGlow: ['#bfe9ff', 0.2],
style: 'snow', stoneStyle: 'cobble', cap: 3, decor: 'pine', trunk: ['#5b4636', '#4e3b2e', '#664f3d'],
leaf: ['#2f5f4a', '#376b54', '#285341', '#40775e', '#224a39'],
clouds: { n: 12, color: '#c9d0d9', em: '#aab3bf', ei: 0.35, y: [11, 17], big: true },
snow: true, vignette: 'rgba(40,50,70,0.3)',
course: { seed: 505, n: 9, spacing: 4.8, xMax: 2, yMax: 2, dMin: 2, dMax: 3, wMin: 2, accentP: 0.22 },
},
6: { // desert: hot haze, rippled sand tops, sandstone strata, terracotta, turquoise tiles, cacti
sky: [[0, '#2f8fc9'], [0.35, '#7cc3e0'], [0.56, '#d6ead8'], [0.64, '#f7e2b8'], [0.8, '#f3d19c'], [1, '#e9c28c']],
fog: ['#f4ddb2', 20, 76], hemi: ['#fff1d6', '#9a6a45', 1.35], sun: ['#fff0cc', 2.2, [8, 16, 3]],
top: ['#ecce8f', '#f2d9a2', '#dfbd7c', '#f7e3b6', '#d4ae6b'],
soil: ['#d9955a', '#e4a86b', '#c9814a', '#efbb7e', '#b8703f'],
stone: ['#c46a45', '#cf7a52', '#b55e3c', '#d98b62', '#a55234'],
accent: ['#3cc2b4', '#55cfc2', '#2eab9f', '#7adcd0', '#23968b'],
style: 'sand', stoneStyle: 'strata', cap: 2, decor: 'cactus',
leaf: ['#5f9a4a', '#6aa955', '#548a41', '#79b862', '#467a37'],
clouds: { n: 3, color: '#fff8ea', em: '#f7e6c8', ei: 0.5, y: [20, 26] },
disc: { color: '#fffbe8', glow: 'rgba(255,240,200,', size: 22, dir: [0.25, 0.55, -1] },
vignette: 'rgba(60,30,10,0.22)',
course: { seed: 606, n: 8, spacing: 5.5, xMax: 3, yMax: 3, dMin: 2, dMax: 3, wMin: 2, accentP: 0.18, zig: true },
},
};
const T = THEMES[V] || THEMES[1];
function shade(hex, f) {
const c = new THREE.Color(hex);
c.r = Math.min(1, c.r * f); c.g = Math.min(1, c.g * f); c.b = Math.min(1, c.b * f);
return '#' + c.getHexString();
}
// 16x16 pixel-art texture painted by a callback(x, y, rand) -> css color.
function pixelTexture(seed, paint) {
const c = document.createElement('canvas');
c.width = c.height = 16;
const g = c.getContext('2d');
const r = rng(seed);
for (let y = 0; y < 16; y++) for (let x = 0; x < 16; x++) {
g.fillStyle = paint(x, y, r);
g.fillRect(x, y, 1, 1);
}
const t = new THREE.CanvasTexture(c);
t.magFilter = THREE.NearestFilter;
t.minFilter = THREE.NearestMipmapLinearFilter;
t.colorSpace = THREE.SRGBColorSpace;
t.anisotropy = 4;
return t;
}
// Beveled "stylized voxel" tiles: light top-left rim, dark bottom-right rim, gentle speckle.
function bevel(x, y, base, r, amt = 0.07) {
let f = 1 + (r() - 0.5) * amt * 2;
if (x === 0 || y === 0) f *= 1.16;
else if (x === 15 || y === 15) f *= 0.8;
else if (x === 1 || y === 1) f *= 1.06;
return shade(base, f);
}
// ---------- textures per theme ----------
const S = V * 100; // texture seed offset for variants
const TOP = T.top, SOIL = T.soil, STONE = T.stone, ACC = T.accent;
let texTop, texSide, texSoil, texStone, texAccent;
if (T.legacy) {
texTop = pixelTexture(11, (x, y, r) => bevel(x, y, r() < 0.08 ? TOP[3] : TOP[0], r));
texSide = pixelTexture(12, (x, y, r) => {
if (y < 4) return bevel(x, y, TOP[2], r);
if (y === 4) return shade(SOIL[3], 0.8);
const strata = y === 9 || y === 13 ? 0.9 : 1;
return bevel(x, y, shade(SOIL[0], strata), r);
});
texSoil = pixelTexture(13, (x, y, r) => bevel(x, y, SOIL[0], r));
texStone = pixelTexture(14, (x, y, r) => bevel(x % 8 === 0 ? 0 : x % 8 === 7 ? 15 : 5, y % 8 === 0 ? 0 : y % 8 === 7 ? 15 : 5, STONE[0], r, 0.05));
texAccent = pixelTexture(15, (x, y, r) => bevel(x, y, r() < 0.06 ? ACC[3] : ACC[0], r, 0.05));
} else {
const colJitter = rng(S + 7);
const capDepth = [...Array(16)].map(() => T.cap + (T.style === 'snow' ? Math.floor(colJitter() * 3) : Math.floor(colJitter() * 1.6)));
const topPaint = {
speckle: (x, y, r) => bevel(x, y, r() < 0.1 ? TOP[3] : r() < 0.12 ? TOP[4] : TOP[0], r),
leaves: (x, y, r) => bevel(x, y, TOP[Math.floor(r() * r() * TOP.length)], r, 0.05),
snow: (x, y, r) => bevel(x, y, r() < 0.12 ? TOP[3] : TOP[0], r, 0.03),
sand: (x, y, r) => bevel(x, y, Math.sin((x + y * 0.55) * 1.1) > 0.55 ? TOP[2] : r() < 0.06 ? TOP[3] : TOP[0], r, 0.04),
}[T.style];
texTop = pixelTexture(S + 11, topPaint);
texSide = pixelTexture(S + 12, (x, y, r) => {
const cd = capDepth[x];
if (y < cd) return bevel(x, y, T.style === 'snow' ? TOP[2] : TOP[2], r, 0.04);
if (y === cd) return shade(T.style === 'snow' ? TOP[3] : SOIL[3], T.style === 'snow' ? 0.92 : 0.8);
if (T.style === 'sand') return bevel(x, y, SOIL[Math.floor(y / 3) % 4], r, 0.04);
const strata = y === 9 || y === 13 ? 0.9 : 1;
return bevel(x, y, shade(SOIL[0], strata), r);
});
texSoil = pixelTexture(S + 13, (x, y, r) => T.style === 'sand'
? bevel(x, y, SOIL[Math.floor(y / 3) % 4], r, 0.04)
: bevel(x, y, r() < 0.1 ? SOIL[2] : SOIL[0], r));
const stonePaint = {
bond: (x, y, r) => {
const row = Math.floor(y / 4), xo = (x + (row % 2) * 4) % 8;
const mortar = y % 4 === 3 || xo === 7;
return mortar ? shade(STONE[4], 0.85) : bevel(xo === 0 ? 0 : 5, y % 4 === 0 ? 0 : 5, STONE[row % 3 === 1 ? 1 : 0], r, 0.05);
},
cobble: (() => {
// Voronoi-ish cobbles from 6 fixed seeds, tileable by wrapping.
const cr = rng(S + 31);
const pts = [...Array(7)].map(() => [cr() * 16, cr() * 16, Math.floor(cr() * 4)]);
return (x, y, r) => {
let d1 = 1e9, d2 = 1e9, id = 0;
for (const [px, py, c] of pts) for (let ox = -16; ox <= 16; ox += 16) for (let oy = -16; oy <= 16; oy += 16) {
const d = Math.hypot(x + 0.5 - px - ox, y + 0.5 - py - oy);
if (d < d1) { d2 = d1; d1 = d; id = c; } else if (d < d2) d2 = d;
}
return d2 - d1 < 1.1 ? shade(STONE[4], 0.8) : shade(STONE[id], 1 + (r() - 0.5) * 0.08 + (d1 < 2 ? 0.06 : 0));
};
})(),
strata: (x, y, r) => {
const band = Math.floor((y + (x > 7 ? 1 : 0)) / 4);
return bevel(x, y % 4, STONE[band % 4], r, 0.05);
},
}[T.stoneStyle];
texStone = pixelTexture(S + 14, stonePaint);
texAccent = pixelTexture(S + 15, (x, y, r) => {
if (T.decor === 'lantern') { // lantern: bright core with dark frame bars
if (x === 0 || x === 15 || y === 0 || y === 15 || x === 7 || x === 8) return shade(ACC[4], 0.45);
return bevel(x, y, (x - 7.5) ** 2 + (y - 7.5) ** 2 < 20 ? ACC[3] : ACC[0], r, 0.05);
}
if (T.style === 'sand') { // turquoise glazed tile with inset diamond
const d = Math.abs(x - 7.5) + Math.abs(y - 7.5);
return bevel(x, y, d < 4 ? ACC[3] : d < 5 ? ACC[4] : ACC[0], r, 0.04);
}
return bevel(x, y, r() < 0.08 ? ACC[3] : ACC[0], r, 0.05);
});
}
const lam = (map) => new THREE.MeshLambertMaterial({ map });
const MATS = {
grass: [lam(texSide), lam(texSide), lam(texTop), lam(texSoil), lam(texSide), lam(texSide)],
slate: lam(texStone),
coral: lam(texAccent),
soil: lam(texSoil),
};
if (T.accentGlow) {
MATS.coral.emissive = new THREE.Color(T.accentGlow[0]);
MATS.coral.emissiveMap = texAccent;
MATS.coral.emissiveIntensity = T.accentGlow[1];
}
if (T.trunk) MATS.trunk = lam(pixelTexture(S + 16, (x, y, r) => bevel(0 + (x % 4 === 0 ? 0 : 5), 5, T.trunk[x % 4 === 0 ? 1 : r() < 0.2 ? 2 : 0], r, 0.06)));
if (T.leaf) MATS.leaf = lam(pixelTexture(S + 17, T.decor === 'cactus'
? (x, y, r) => bevel(5, y, x % 4 === 1 ? T.leaf[3] : x % 4 === 3 ? T.leaf[4] : T.leaf[0], r, 0.05)
: (x, y, r) => bevel(x, y, T.leaf[Math.floor(r() * r() * T.leaf.length)], r, 0.06)));
if (T.crystal) {
const m = lam(pixelTexture(S + 18, (x, y, r) => bevel(x, y, (x + y) % 7 === 0 ? T.crystal[3] : T.crystal[Math.floor(r() * 3)], r, 0.04)));
m.emissive = new THREE.Color(T.crystal[0]);
m.emissiveMap = m.map;
m.emissiveIntensity = 0.55;
MATS.crystal = m;
}
if (T.style === 'snow') MATS.snowcap = lam(texTop);
// ---------- course (periodic) ----------
const LEGACY_PLATFORMS = [
{ x: 0, y: 0, w: 3, d: 3, kind: 'grass' },
{ x: 1, y: 1, w: 2, d: 3, kind: 'grass' },
{ x: -1, y: 1, w: 2, d: 3, kind: 'coral' },
{ x: 0, y: 0, w: 3, d: 3, kind: 'grass' },
{ x: 2, y: 1, w: 2, d: 3, kind: 'grass' },
{ x: 1, y: 2, w: 2, d: 3, kind: 'coral' },
{ x: -1, y: 1, w: 3, d: 3, kind: 'grass' },
{ x: 0, y: 0, w: 2, d: 3, kind: 'grass' },
];
// Seeded course: closed loop of n platforms; every hop (incl. the wrap n-1 -> 0) climbs at most
// 1 block, drops at most 2, and shifts at most 2 sideways, so every jump reads as makeable.
function makeCourse(c) {
const r = rng(c.seed);
const ri = (lo, hi) => lo + Math.floor(r() * (hi - lo + 1));
for (let attempt = 0; attempt < 20000; attempt++) {
const ys = [], xs = [];
for (let k = 0; k < c.n; k++) {
ys.push(ri(0, c.yMax));
if (c.zig) { // run in one direction then turn: sweeping S-curves
const phase = Math.sin((2 * Math.PI * k) / c.n + 0.6);
xs.push(Math.max(-c.xMax, Math.min(c.xMax, Math.round(phase * c.xMax + (r() - 0.5) * 1.2))));
} else xs.push(ri(-c.xMax, c.xMax));
}
let ok = true, turns = 0, climbs = 0;
for (let k = 0; k < c.n; k++) {
const dy = ys[(k + 1) % c.n] - ys[k], dx = xs[(k + 1) % c.n] - xs[k];
if (dy > 1 || dy < -2 || Math.abs(dx) > 2) ok = false;
if (dy > 0 && Math.abs(dx) > 1) ok = false;
if (dx !== 0) turns++;
if (dy !== 0) climbs++;
}
if (!ok || turns < Math.ceil(c.n * 0.5) || climbs < Math.ceil(c.n * 0.5)) continue;
const plats = [];
let prevAccent = false;
for (let k = 0; k < c.n; k++) {
const accent = !prevAccent && r() < c.accentP;
prevAccent = accent;
plats.push({ x: xs[k], y: ys[k], w: ri(c.wMin, 3), d: ri(c.dMin, c.dMax), kind: accent ? 'coral' : 'grass' });
}
return plats;
}
throw new Error('no valid course');
}
const PLATFORMS = T.legacy ? LEGACY_PLATFORMS : makeCourse(T.course);
const N = PLATFORMS.length;
const SPACING = T.legacy ? 5 : T.course.spacing;
const LOOP_LEN = N * SPACING;
const HOP_T = LOOP_S / N; // seconds per platform
const plat = (k) => PLATFORMS[((k % N) + N) % N];
const renderer = new THREE.WebGLRenderer({ antialias: true, preserveDrawingBuffer: true, powerPreference: 'high-performance' });
renderer.setPixelRatio(1);
renderer.setSize(W, H);
renderer.outputColorSpace = THREE.SRGBColorSpace;
const scene = new THREE.Scene();
const FOG_FAR = T.fog[2];
scene.fog = new THREE.Fog(new THREE.Color(T.fog[0]), T.fog[1], FOG_FAR);
// Sky gradient, painted procedurally.
{
const c = document.createElement('canvas');
c.width = 8; c.height = 512;
const g = c.getContext('2d');
const grad = g.createLinearGradient(0, 0, 0, 512);
for (const [s, col] of T.sky) grad.addColorStop(s, col);
g.fillStyle = grad;
g.fillRect(0, 0, 8, 512);
const t = new THREE.CanvasTexture(c);
t.colorSpace = THREE.SRGBColorSpace;
scene.background = t;
}
scene.add(new THREE.HemisphereLight(T.hemi[0], T.hemi[1], T.hemi[2]));
const sun = new THREE.DirectionalLight(T.sun[0], T.sun[1]);
sun.position.set(...T.sun[2]);
scene.add(sun);
scene.add(sun.target);
const unit = new THREE.BoxGeometry(1, 1, 1);
const cubes = Object.fromEntries(Object.keys(MATS).map((k) => [k, []]));
// Platforms cover the camera path plus fog distance at every loop phase.
const K_MAX = T.legacy ? 26 : Math.ceil((LOOP_LEN + FOG_FAR + 12) / SPACING);
const PILLAR_SEED = T.legacy ? 1000 : 1000 + S;
for (let k = -3; k <= K_MAX; k++) {
const p = plat(k);
const zc = -k * SPACING;
const x0 = p.x - (p.w - 1) / 2;
const z0 = zc - (p.d - 1) / 2;
for (let i = 0; i < p.w; i++) for (let j = 0; j < p.d; j++) {
cubes[p.kind === 'coral' ? 'coral' : 'grass'].push([x0 + i, p.y - 0.5, z0 + j]);
}
// Night lanterns: one glowing block on an outer corner of wide platforms (off the run line).
if (T.lanternsOnCourse && p.w >= 3 && p.kind !== 'coral' && ((k % 2) + 2) % 2 === 0) {
cubes.coral.push([x0 + (k % 4 === 0 ? 0 : p.w - 1), p.y + 0.5, z0]);
}
// Pillar: a thinner stone column under the platform, reaching into the fog.
const pr = rng(PILLAR_SEED + (((k % N) + N) % N));
const depth = 9 + Math.floor(pr() * 5);
for (let s = 1; s <= depth; s++) {
const inset = s > 2 ? 1 : 0;
// (base keeps its original inset rule; variants never inset a footprint down to nothing)
const wLo = T.legacy ? inset : p.w > 2 ? inset : 0, wHi = p.w - (p.w > 2 ? inset : 0);
const dLo = T.legacy || p.d > 2 ? inset : 0, dHi = p.d - dLo;
for (let i = wLo; i < wHi; i++) for (let j = dLo; j < dHi; j++) {
cubes[s === 1 && p.kind === 'grass' ? 'soil' : 'slate'].push([x0 + i, p.y - 0.5 - s, z0 + j]);
}
}
}
// Scenery props standing on top of a distant island (top surface at y = ty).
function decor(kind, x, ty, z, r) {
const put = (m, dx, dy, dz) => cubes[m].push([x + dx, ty + 0.5 + dy, z + dz]);
if (kind === 'tree') {
const h = 2 + Math.floor(r() * 2);
for (let s = 0; s < h; s++) put('trunk', 0, s, 0);
for (let i = -1; i <= 1; i++) for (let j = -1; j <= 1; j++) {
put('leaf', i, h, j);
if (Math.abs(i) + Math.abs(j) < 2) put('leaf', i, h + 1, j);
}
put('leaf', 0, h + 2, 0);
} else if (kind === 'pine') {
put('trunk', 0, 0, 0);
for (let i = -1; i <= 1; i++) for (let j = -1; j <= 1; j++) put('leaf', i, 1, j);
for (const [i, j] of [[0, 0], [1, 0], [-1, 0], [0, 1], [0, -1]]) put(i || j ? 'snowcap' : 'leaf', i, 2, j);
put('leaf', 0, 3, 0);
put('snowcap', 0, 4, 0);
} else if (kind === 'cactus') {
const h = 3 + Math.floor(r() * 2);
for (let s = 0; s < h; s++) put('leaf', 0, s, 0);
const side = r() < 0.5 ? 1 : -1;
put('leaf', side, 1, 0); put('leaf', side, 2, 0);
if (r() < 0.6) { put('leaf', -side, 2, 0); put('leaf', -side, 3, 0); }
} else if (kind === 'lantern') {
put('slate', 0, 0, 0); put('slate', 0, 1, 0); put('coral', 0, 2, 0); put('slate', 0, 3, 0);
} else if (kind === 'crystal') {
const h = 3 + Math.floor(r() * 4);
for (let s = 0; s < h; s++) put('crystal', 0, s, 0);
put('crystal', 1, 0, 0); put('crystal', 0, 0, -1);
if (h > 4) put('crystal', -1, 1, 0);
}
}
// Distant floating islands and towers, periodic in z with LOOP_LEN.
{
const r = rng(T.legacy ? 77 : 77 + S);
const base = [];
for (let i = 0; i < 16; i++) {
const side = i % 2 ? 1 : -1;
base.push({
x: side * (9 + r() * 22),
z: -r() * LOOP_LEN,
y: -4 + r() * 10,
w: 2 + Math.floor(r() * 4),
h: 2 + Math.floor(r() * 7),
coral: r() < 0.2,
seed: S + 7919 * (i + 1), // not drawn from r(): keeps the base island layout unchanged
});
}
const copies = T.legacy ? 3 : Math.ceil((LOOP_LEN + FOG_FAR + 12) / LOOP_LEN);
for (let c = -1; c <= copies; c++) for (const b of base) {
const zb = b.z - c * LOOP_LEN;
for (let i = 0; i < b.w; i++) for (let j = 0; j < b.w; j++) {
cubes[b.coral ? 'coral' : 'grass'].push([b.x + i, b.y - 0.5, zb - j]);
for (let s = 1; s < b.h; s++) {
if (i === 0 || j === 0 || i === b.w - 1 || j === b.w - 1 || s < 2) {
const tip = s > b.h - 2 && (i + j) % 2 === 1;
if (!tip) cubes.slate.push([b.x + i, b.y - 0.5 - s, zb - j]);
}
}
}
if (T.decor && !b.coral && b.w >= 2) {
const dr = rng(b.seed);
const mid = Math.floor((b.w - 1) / 2);
decor(T.decor, b.x + mid, b.y, zb - mid, dr);
if (b.w >= 4) decor(T.decor, b.x + b.w - 1, b.y, zb - b.w + 1, dr);
}
}
}
function instanced(list, mat) {
if (!list.length) return;
const m = new THREE.InstancedMesh(unit, mat, list.length);
const o = new THREE.Object3D();
list.forEach(([x, y, z], i) => { o.position.set(x, y, z); o.updateMatrix(); m.setMatrixAt(i, o.matrix); });
m.instanceMatrix.needsUpdate = true;
scene.add(m);
}
for (const k of Object.keys(MATS)) instanced(cubes[k], MATS[k]);
// Blocky clouds (flat slabs), periodic in z.
if (T.clouds) {
const cl = T.clouds;
const cloudMat = new THREE.MeshLambertMaterial({ color: cl.color, emissive: cl.em, emissiveIntensity: cl.ei });
const r = rng(T.legacy ? 99 : 99 + S);
const base = [];
const sz = cl.big ? 1.6 : 1;
for (let i = 0; i < cl.n; i++) base.push({ x: -34 + r() * 68, y: cl.y[0] + r() * (cl.y[1] - cl.y[0]), z: -r() * LOOP_LEN, w: (6 + r() * 8) * sz, d: (4 + r() * 6) * sz });
const copies = T.legacy ? 3 : Math.ceil((LOOP_LEN + FOG_FAR + 30) / LOOP_LEN);
for (let c = -1; c <= copies; c++) for (const b of base) {
const m = new THREE.Mesh(new THREE.BoxGeometry(b.w, 1.2, b.d), cloudMat);
m.position.set(b.x, b.y, b.z - c * LOOP_LEN);
scene.add(m);
}
}
// Sky dome props that travel with the camera: stars and a sun/moon disc (never fogged).
const skyGroup = new THREE.Group();
scene.add(skyGroup);
if (T.stars) {
const r = rng(S + 41);
const pos = [], col = [];
for (let i = 0; i < T.stars; i++) {
const az = (r() - 0.5) * 2.6, el = 0.08 + Math.pow(r(), 0.7) * 1.4;
const d = 160;
pos.push(Math.cos(el) * Math.sin(az) * d, Math.sin(el) * d, -Math.cos(el) * Math.cos(az) * d);
const b = 0.45 + r() * 0.55;
col.push(b, b, Math.min(1, b + 0.1));
}
const g = new THREE.BufferGeometry();
g.setAttribute('position', new THREE.Float32BufferAttribute(pos, 3));
g.setAttribute('color', new THREE.Float32BufferAttribute(col, 3));
skyGroup.add(new THREE.Points(g, new THREE.PointsMaterial({ size: 2.2, sizeAttenuation: false, vertexColors: true, fog: false, depthWrite: false })));
}
if (T.disc) {
const c = document.createElement('canvas');
c.width = c.height = 256;
const g = c.getContext('2d');
const gl = g.createRadialGradient(128, 128, 0, 128, 128, 128);
gl.addColorStop(0, T.disc.glow + '0.9)');
gl.addColorStop(0.28, T.disc.glow + '0.45)');
gl.addColorStop(1, T.disc.glow + '0)');
g.fillStyle = gl; g.fillRect(0, 0, 256, 256);
g.fillStyle = T.disc.color;
g.beginPath(); g.arc(128, 128, 34, 0, Math.PI * 2); g.fill();
if (T.disc.moon) { // soft craters
g.fillStyle = 'rgba(160,175,215,0.35)';
for (const [x, y, rr] of [[116, 118, 9], [140, 138, 6], [124, 145, 5], [143, 114, 4]]) { g.beginPath(); g.arc(x, y, rr, 0, Math.PI * 2); g.fill(); }
}
const tex = new THREE.CanvasTexture(c);
tex.colorSpace = THREE.SRGBColorSpace;
const sp = new THREE.Sprite(new THREE.SpriteMaterial({ map: tex, fog: false, depthWrite: false, transparent: true }));
const d = new THREE.Vector3(...T.disc.dir).normalize().multiplyScalar(150);
sp.position.copy(d);
sp.scale.setScalar(T.disc.size);
skyGroup.add(sp);
}
// Snowfall: world-space flakes, periodic in z (LOOP_LEN) and in fall height over 8 s.
let snow = null;
if (T.snow) {
const r = rng(S + 51);
const PER = 900, RANGE = 26, Y0 = -8;
const copies = Math.ceil((LOOP_LEN + FOG_FAR) / LOOP_LEN) + 1;
const base = [];
for (let i = 0; i < PER; i++) base.push([-22 + r() * 44, r() * RANGE, -r() * LOOP_LEN, r() * Math.PI * 2, 1 + Math.floor(r() * 2)]);
const flakes = [];
for (let c = -1; c <= copies; c++) for (const b of base) flakes.push([b[0], b[1], b[2] - c * LOOP_LEN, b[3], b[4]]);
const g = new THREE.BufferGeometry();
g.setAttribute('position', new THREE.Float32BufferAttribute(new Float32Array(flakes.length * 3), 3));
const fc = document.createElement('canvas');
fc.width = fc.height = 32;
const fg = fc.getContext('2d');
const grd = fg.createRadialGradient(16, 16, 0, 16, 16, 16);
grd.addColorStop(0, 'rgba(255,255,255,1)'); grd.addColorStop(0.5, 'rgba(255,255,255,0.8)'); grd.addColorStop(1, 'rgba(255,255,255,0)');
fg.fillStyle = grd; fg.fillRect(0, 0, 32, 32);
const ft = new THREE.CanvasTexture(fc);
const pts = new THREE.Points(g, new THREE.PointsMaterial({ size: 0.2, map: ft, transparent: true, depthWrite: false, color: '#ffffff' }));
scene.add(pts);
snow = { g, flakes, RANGE, Y0 };
}
function updateSnow(t) {
if (!snow) return;
const a = snow.g.attributes.position.array;
snow.flakes.forEach(([x, y, z, ph, m], i) => {
// falls m*RANGE per loop (integer laps) and sways once per loop -> periodic in 8 s
const fall = (y - (m * snow.RANGE * t) / LOOP_S) % snow.RANGE;
a[i * 3] = x + 0.5 * Math.sin((2 * Math.PI * t) / LOOP_S + ph);
a[i * 3 + 1] = snow.Y0 + (fall < 0 ? fall + snow.RANGE : fall);
a[i * 3 + 2] = z + 0.4 * Math.cos((4 * Math.PI * t) / LOOP_S + ph);
});
snow.g.attributes.position.needsUpdate = true;
}
const camera = new THREE.PerspectiveCamera(78, W / H, 0.05, 200);
// ---------- deterministic camera path ----------
const smooth = (a, b, x) => { const u = Math.min(1, Math.max(0, (x - a) / (b - a))); return u * u * (3 - 2 * u); };
// Fraction of hop k spent before the jump / at landing. Variants take off at the platform edge
// and land at the next edge, so seeded gaps and depths read as real jumps.
function hopPhase(k) {
if (T.legacy) return [0.3, 0.7];
const a = plat(k), b = plat(k + 1);
const to = Math.max(0.12, (a.d / 2 - 0.15) / SPACING);
const la = Math.min(0.88, 1 - (b.d / 2 - 0.15) / SPACING);
return [to, la];
}
function groundY(t) {
const k = Math.floor(t / HOP_T);
const u = t / HOP_T - k;
const [TAKEOFF, LAND] = hopPhase(k);
const y0 = plat(k).y, y1 = plat(k + 1).y;
if (u < TAKEOFF) return y0;
if (u >= LAND) return y1;
const s = (u - TAKEOFF) / (LAND - TAKEOFF);
const apex = 1.25;
return y0 + (y1 - y0) * s + 4 * apex * s * (1 - s);
}
function airborne(t) {
const k = Math.floor(t / HOP_T);
const u = t / HOP_T - k;
const [TAKEOFF, LAND] = hopPhase(k);
return u >= TAKEOFF && u < LAND;
}
function pathX(t) {
const k = Math.floor(t / HOP_T);
const u = t / HOP_T - k;
const [TAKEOFF, LAND] = hopPhase(k);
return plat(k).x + (plat(k + 1).x - plat(k).x) * smooth(TAKEOFF - 0.1, LAND + 0.05, u);
}
function landingDip(t) {
const k = Math.floor(t / HOP_T);
const u = t / HOP_T - k;
const [, LAND] = hopPhase(k);
const since = (u - LAND) * HOP_T; // seconds since landing in this hop
if (since < 0) return 0;
return -0.22 * Math.sin(Math.min(1, since / 0.28) * Math.PI) * Math.exp(-since * 3);
}
function cameraAt(t) {
const z = -(t / LOOP_S) * LOOP_LEN;
const x = pathX(t);
const onGround = airborne(t) ? 0 : 1;
const bob = onGround * 0.055 * Math.sin(2 * Math.PI * 4 * t); // 4 steps/s -> 32 per loop
const sway = onGround * 0.03 * Math.sin(2 * Math.PI * 2 * t);
const y = groundY(t) + EYE + bob + landingDip(t);
// Look ahead along the path; smooth the look height so jumps feel natural.
const ahead = 0.75;
const lookY = (groundY(t + ahead) + groundY(t + ahead * 0.5) + groundY(t)) / 3 + EYE - 2.4;
camera.position.set(x + sway, y, z);
camera.up.set(Math.sin((pathX(t + 0.4) - x) * -0.06), 1, 0).normalize();
camera.lookAt(pathX(t + ahead), lookY, z - 7);
skyGroup.position.copy(camera.position);
}
// Composite: WebGL frame + crosshair + soft vignette in a 2D canvas.
const out = document.createElement('canvas');
out.width = W; out.height = H;
const g2 = out.getContext('2d');
document.body.appendChild(out);
function overlay() {
const vg = g2.createRadialGradient(W / 2, H / 2, W * 0.45, W / 2, H / 2, H * 0.72);
vg.addColorStop(0, 'rgba(0,0,0,0)');
vg.addColorStop(1, T.vignette);
g2.fillStyle = vg;
g2.fillRect(0, 0, W, H);
g2.fillStyle = 'rgba(255,255,255,0.85)';
g2.fillRect(W / 2 - 11, H / 2 - 1.5, 22, 3);
g2.fillRect(W / 2 - 1.5, H / 2 - 11, 3, 22);
}
window.renderFrame = (i) => {
const t = (i % (FPS * LOOP_S)) / FPS;
cameraAt(t);
updateSnow(t);
renderer.render(scene, camera);
g2.drawImage(renderer.domElement, 0, 0);
overlay();
return out.toDataURL('image/png');
};
window.sceneReady = true;
</script>
</body>
</html>