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
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.
198 lines
8.9 KiB
JavaScript
198 lines
8.9 KiB
JavaScript
#!/usr/bin/env node
|
|
/*
|
|
* Menivor procedural background loops — frame renderer + encoder.
|
|
*
|
|
* Renders ORIGINAL, rights-clean 720x1280 / 30 fps / 8 s seamless loops for the
|
|
* split-screen video styles. Every pixel comes from code in this folder:
|
|
* block-runner.html first-person voxel parkour run over floating pillars (three.js)
|
|
* sand-slice.html pastel layered "kinetic sand" block sliced by a blade (2D canvas)
|
|
* marble-run.html glossy marbles on a zig-zag track + slotted lift wheel (three.js)
|
|
* No downloaded footage, game capture, third-party art or trademarks.
|
|
*
|
|
* Determinism: each page exposes `window.renderFrame(i)` which draws the scene at
|
|
* t = i / 30 with a fixed timestep (no clock), and returns a PNG data URL. All
|
|
* motion is periodic in 8 s, so frame 240 == frame 0 (loop by construction).
|
|
*
|
|
* Regenerate (from repo root, needs ffmpeg + a Chromium browser + playwright-core):
|
|
* node scripts/background-loops/render-loops.mjs # all three
|
|
* node scripts/background-loops/render-loops.mjs block-runner # just one
|
|
* node scripts/background-loops/render-loops.mjs --preview # 4 stills per scene only
|
|
* Variants (different seeded course / palette / camera; base = variant 1):
|
|
* node scripts/background-loops/render-loops.mjs --variants # every variant (not the bases)
|
|
* node scripts/background-loops/render-loops.mjs block-runner@3 # one variant -> block-runner-3.mp4
|
|
* node scripts/background-loops/render-loops.mjs sand-slice@2-3 # a range
|
|
* Each page reads `?v=<n>`; variant n>1 is written as <name>-<n>.mp4.
|
|
* Env overrides:
|
|
* PLAYWRIGHT_CORE path to a playwright-core package dir
|
|
* BROWSER_BIN Chromium-family executable (default: Brave)
|
|
* THREE_DIR three package dir (default: ../vcglass/node_modules/three)
|
|
* WORK_DIR scratch dir for frames (default: /tmp/menivor-loops)
|
|
* Output: apps/api/app/domains/content/assets/backgrounds/<name>.mp4, plus a
|
|
* mid-loop still at /tmp/menivor-landing/frames/<name>.png. Frame PNGs are deleted
|
|
* after encoding (pass --keep-frames to keep them).
|
|
*/
|
|
import { createRequire } from 'node:module';
|
|
import { createServer } from 'node:http';
|
|
import { execFileSync } from 'node:child_process';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
|
|
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
const REPO = path.resolve(HERE, '..', '..');
|
|
const PRODUCTS = path.resolve(REPO, '..');
|
|
const OUT_DIR = path.join(REPO, 'apps/api/app/domains/content/assets/backgrounds');
|
|
const WORK = process.env.WORK_DIR || '/tmp/menivor-loops';
|
|
const STILLS = '/tmp/menivor-landing/frames';
|
|
const WIDTH = 720;
|
|
const HEIGHT = 1280;
|
|
const FPS = 30;
|
|
const SECONDS = 8;
|
|
const FRAME_COUNT = FPS * SECONDS;
|
|
const SCENES = ['block-runner', 'sand-slice', 'marble-run'];
|
|
// Extra variants per scene (variant 1 is the base file).
|
|
const VARIANTS = { 'block-runner': [2, 3, 4, 5, 6], 'sand-slice': [2, 3], 'marble-run': [2, 3] };
|
|
const outName = (name, v) => (v > 1 ? `${name}-${v}` : name);
|
|
const BROWSER_BIN = process.env.BROWSER_BIN || '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser';
|
|
const THREE_DIR = process.env.THREE_DIR || path.join(PRODUCTS, 'vcglass/node_modules/three');
|
|
|
|
function loadPlaywright() {
|
|
const candidates = [
|
|
process.env.PLAYWRIGHT_CORE,
|
|
'/private/tmp/sr/node_modules/playwright-core',
|
|
path.join(PRODUCTS, 'vcglass/node_modules/playwright-core'),
|
|
path.join(PRODUCTS, 'storeshots/node_modules/playwright-core'),
|
|
].filter(Boolean);
|
|
const require = createRequire(import.meta.url);
|
|
for (const dir of candidates) {
|
|
if (fs.existsSync(path.join(dir, 'package.json'))) return require(dir);
|
|
}
|
|
throw new Error(`playwright-core not found; set PLAYWRIGHT_CORE (tried ${candidates.join(', ')})`);
|
|
}
|
|
|
|
function stageWebRoot() {
|
|
const www = path.join(WORK, 'www');
|
|
fs.mkdirSync(www, { recursive: true });
|
|
for (const f of ['three.module.js', 'three.core.js']) {
|
|
fs.copyFileSync(path.join(THREE_DIR, 'build', f), path.join(www, f));
|
|
}
|
|
fs.copyFileSync(
|
|
path.join(THREE_DIR, 'examples/jsm/environments/RoomEnvironment.js'),
|
|
path.join(www, 'RoomEnvironment.js'),
|
|
);
|
|
for (const f of fs.readdirSync(HERE)) {
|
|
if (f.endsWith('.html') || f.endsWith('.js')) fs.copyFileSync(path.join(HERE, f), path.join(www, f));
|
|
}
|
|
return www;
|
|
}
|
|
|
|
function serve(root) {
|
|
const types = { '.html': 'text/html', '.js': 'text/javascript' };
|
|
const server = createServer((req, res) => {
|
|
const rel = decodeURIComponent(new URL(req.url, 'http://x').pathname).replace(/^\/+/, '');
|
|
const file = path.join(root, rel);
|
|
if (!file.startsWith(root) || !fs.existsSync(file)) {
|
|
res.writeHead(404).end();
|
|
return;
|
|
}
|
|
res.writeHead(200, { 'content-type': types[path.extname(file)] || 'application/octet-stream' });
|
|
fs.createReadStream(file).pipe(res);
|
|
});
|
|
return new Promise((resolve) => server.listen(0, '127.0.0.1', () => resolve(server)));
|
|
}
|
|
|
|
function writeDataUrl(dataUrl, file) {
|
|
const b64 = dataUrl.slice(dataUrl.indexOf(',') + 1);
|
|
fs.writeFileSync(file, Buffer.from(b64, 'base64'));
|
|
}
|
|
|
|
async function renderScene(browser, port, name, variant, { preview, keepFrames }) {
|
|
const scene = name;
|
|
name = outName(scene, variant);
|
|
const page = await browser.newPage({ viewport: { width: WIDTH, height: HEIGHT }, deviceScaleFactor: 1 });
|
|
page.on('pageerror', (e) => console.error(`[${name}] page error:`, e.message));
|
|
page.on('console', (m) => m.type() === 'error' && console.error(`[${name}] console:`, m.text()));
|
|
await page.goto(`http://127.0.0.1:${port}/${scene}.html?v=${variant}`);
|
|
await page.waitForFunction(() => window.sceneReady === true, null, { timeout: 60000 });
|
|
|
|
const frameDir = path.join(WORK, name);
|
|
fs.rmSync(frameDir, { recursive: true, force: true });
|
|
fs.mkdirSync(frameDir, { recursive: true });
|
|
fs.mkdirSync(STILLS, { recursive: true });
|
|
|
|
const indices = preview ? [0, 45, 75, 130, 200] : [...Array(FRAME_COUNT).keys()];
|
|
const started = Date.now();
|
|
for (const i of indices) {
|
|
const url = await page.evaluate((f) => window.renderFrame(f), i);
|
|
const target = preview
|
|
? path.join(STILLS, `${name}-f${String(i).padStart(3, '0')}.png`)
|
|
: path.join(frameDir, `${String(i).padStart(5, '0')}.png`);
|
|
writeDataUrl(url, target);
|
|
}
|
|
// Loop check: frame 240 must equal frame 0 (periodic by construction).
|
|
const [a, b] = await page.evaluate(() => [window.renderFrame(0), window.renderFrame(240)]);
|
|
console.log(`[${name}] ${indices.length} frames in ${((Date.now() - started) / 1000).toFixed(1)}s; loop seam identical: ${a === b}`);
|
|
await page.close();
|
|
if (preview) return;
|
|
|
|
fs.mkdirSync(OUT_DIR, { recursive: true });
|
|
const out = path.join(OUT_DIR, `${name}.mp4`);
|
|
execFileSync('ffmpeg', [
|
|
'-hide_banner', '-loglevel', 'error', '-y',
|
|
'-framerate', String(FPS), '-i', path.join(frameDir, '%05d.png'),
|
|
'-c:v', 'libx264', '-pix_fmt', 'yuv420p', '-crf', process.env.CRF || '27', '-preset', 'slow',
|
|
'-g', String(FPS * 2), '-map_metadata', '-1', '-movflags', '+faststart', '-an', out,
|
|
], { stdio: 'inherit' });
|
|
execFileSync('ffmpeg', [
|
|
'-hide_banner', '-loglevel', 'error', '-y', '-ss', '4', '-i', out, '-frames:v', '1',
|
|
path.join(STILLS, `${name}.png`),
|
|
], { stdio: 'inherit' });
|
|
if (!keepFrames) fs.rmSync(frameDir, { recursive: true, force: true });
|
|
console.log(`[${name}] wrote ${out} (${(fs.statSync(out).size / 1024 / 1024).toFixed(2)} MB)`);
|
|
}
|
|
|
|
async function main() {
|
|
const args = process.argv.slice(2);
|
|
const preview = args.includes('--preview');
|
|
const keepFrames = args.includes('--keep-frames');
|
|
const picked = args.filter((a) => !a.startsWith('--'));
|
|
const jobs = [];
|
|
if (args.includes('--variants') && !picked.length) {
|
|
for (const s of SCENES) for (const v of VARIANTS[s]) jobs.push([s, v]);
|
|
}
|
|
for (const tok of picked.length ? picked : jobs.length ? [] : SCENES) {
|
|
const [s, spec] = tok.split('@');
|
|
if (!SCENES.includes(s)) throw new Error(`unknown scene ${s}`);
|
|
if (!spec) {
|
|
if (args.includes('--variants')) for (const v of VARIANTS[s]) jobs.push([s, v]);
|
|
else jobs.push([s, 1]);
|
|
continue;
|
|
}
|
|
const [lo, hi = lo] = spec.split('-').map(Number);
|
|
if (!Number.isInteger(lo) || !Number.isInteger(hi) || lo < 1 || hi < lo) throw new Error(`bad variant spec ${tok}`);
|
|
for (let v = lo; v <= hi; v++) {
|
|
if (v > 1 && !VARIANTS[s].includes(v)) throw new Error(`${s} has no variant ${v}`);
|
|
jobs.push([s, v]);
|
|
}
|
|
}
|
|
|
|
const { chromium } = loadPlaywright();
|
|
const server = await serve(stageWebRoot());
|
|
const browser = await chromium.launch({
|
|
executablePath: BROWSER_BIN,
|
|
headless: true,
|
|
args: ['--use-angle=swiftshader', '--enable-unsafe-swiftshader', '--ignore-gpu-blocklist'],
|
|
});
|
|
try {
|
|
for (const [s, v] of jobs) await renderScene(browser, server.address().port, s, v, { preview, keepFrames });
|
|
} finally {
|
|
await browser.close();
|
|
server.close();
|
|
}
|
|
}
|
|
|
|
main().catch((e) => {
|
|
console.error(e);
|
|
process.exit(1);
|
|
});
|