Files
workinf_Blender_Wasm/tools/web/check-monkey-render-video.mjs
mes123456 63db6caf1f
Some checks failed
M6 deployable RC / quick (push) Has been cancelled
M6 deployable RC / chromium (push) Has been cancelled
M6 deployable RC / release (push) Has been cancelled
feat(web): studio worlds, camera-view/offscreen environment parity, material and undo coverage
Environment lighting:
- ship all eight desktop studiolights/world datasets (WBENV1 float32) and a
  shared loader used by both the main viewport and the offscreen worker
- add the N-panel "studio 环境" selector
- rotate the world background together with the environment
  (backgroundRotation/backgroundIntensity), so camera view and offscreen
  renders match the desktop Mapping-node behaviour

Verification (Chromium, OPFS, NOT_CLAIMED):
- environment lighting + 8 world pixel identity
- camera-view rotation correspondence (camera matrices, 207 samples)
- offscreen vs on-screen background parity after hiding geometry (1305 samples)
- metals case extended with material-field OPFS roundtrip
- material Principled edits and rename undo/redo
- eight studio worlds: pairwise frame differences + luminance rank correlation
- undo history depth capped at 64 steps and undo across OPFS save/reopen

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-23 09:27:47 +08:00

104 lines
5.1 KiB
JavaScript

#!/usr/bin/env node
/** Validate the beginner monkey-render lesson MP4, narration, VTT, poster, stills and page. */
import assert from "node:assert/strict";
import { execFileSync } from "node:child_process";
import crypto from "node:crypto";
import fs from "node:fs";
import path from "node:path";
const REPO = path.resolve(import.meta.dirname, "../..");
const OUT = path.join(REPO, "tests/golden/MONKEY-RENDER-VIDEO-001");
const LESSON = path.join(REPO, "web/app/public/tutorial/rendering");
const VIDEO_DIR = path.join(LESSON, "video");
const VIDEO = path.join(VIDEO_DIR, "monkey-render-1080p.mp4");
const VTT = path.join(VIDEO_DIR, "monkey-render.zh-Hans.vtt");
const POSTER = path.join(VIDEO_DIR, "monkey-render-poster.jpg");
const HTML = path.join(LESSON, "monkey-render-lesson.html");
const FFPROBE = "/usr/bin/ffprobe";
const CHAPTERS = 11;
const sha256 = (file) => crypto.createHash("sha256").update(fs.readFileSync(file)).digest("hex");
const exists = (file, label) => assert.ok(fs.existsSync(file), `missing ${label}: ${path.relative(REPO, file)}`);
const readJson = (file) => JSON.parse(fs.readFileSync(file, "utf8"));
const probe = (file) => JSON.parse(execFileSync(FFPROBE, ["-v", "error", "-show_entries",
"format=duration,size,format_name:stream=codec_type,codec_name,width,height", "-of", "json", file], { encoding: "utf8" }));
const report = readJson(path.join(OUT, "video-report.json"));
const timeline = readJson(path.join(OUT, "timeline.json"));
const narration = readJson(path.join(OUT, "narration.json"));
assert.equal(report.status, "PASS");
assert.equal(timeline.status, "PASS");
assert.equal(report.chapters.length, CHAPTERS);
assert.equal(timeline.chapters.length, CHAPTERS);
assert.equal(narration.chapters.length, CHAPTERS);
for (const file of [VIDEO, VTT, POSTER]) exists(file, path.basename(file));
assert.equal(sha256(VIDEO), report.video.sha256, "video SHA mismatch");
assert.equal(sha256(POSTER), report.poster.sha256, "poster SHA mismatch");
assert.equal(sha256(VTT), report.vtt.sha256, "VTT SHA mismatch");
const media = probe(VIDEO);
const duration = Number(media.format?.duration ?? 0);
assert.ok(duration >= 480 && duration <= 800, `video duration ${duration}s outside 8-13 minutes`);
assert.match(String(media.format?.format_name ?? ""), /mp4/);
const videoStream = media.streams.find((stream) => stream.codec_type === "video");
const audioStream = media.streams.find((stream) => stream.codec_type === "audio");
assert.ok(videoStream && audioStream, "video/audio streams missing");
assert.equal(videoStream.codec_name, "h264");
assert.equal(videoStream.width, 1920);
assert.equal(videoStream.height, 1080);
assert.equal(audioStream.codec_name, "aac");
const head = fs.readFileSync(VIDEO).subarray(0, 2 * 1024 * 1024);
const moov = head.indexOf(Buffer.from("moov"));
const mdat = head.indexOf(Buffer.from("mdat"));
assert.ok(moov >= 0 && mdat >= 0 && moov < mdat, "MP4 is not faststart (moov must precede mdat)");
const vttText = fs.readFileSync(VTT, "utf8");
assert.ok(vttText.startsWith("WEBVTT"));
const cues = [...vttText.matchAll(/^(\d{2}:\d{2}:\d{2}\.\d{3}) --> (\d{2}:\d{2}:\d{2}\.\d{3})$/gm)];
assert.equal(cues.length, CHAPTERS, `expected ${CHAPTERS} VTT cues, got ${cues.length}`);
let previous = -1;
for (const cue of cues) {
const parts = cue[1].split(":").map(Number);
const seconds = parts[0] * 3600 + parts[1] * 60 + parts[2];
assert.ok(seconds >= previous, "VTT cue times must be monotonic");
previous = seconds;
}
const posterMedia = probe(POSTER);
const posterStream = posterMedia.streams.find((stream) => stream.codec_type === "video");
assert.equal(posterStream.width, 1920);
assert.equal(posterStream.height, 1080);
for (const chapter of timeline.chapters) {
const file = path.join(REPO, chapter.screenshot);
exists(file, `chapter screenshot ${chapter.id}`);
const published = path.join(LESSON, "video-steps", `${chapter.id}.jpg`);
exists(published, `published chapter screenshot ${chapter.id}`);
const mediaInfo = probe(published);
const stream = mediaInfo.streams.find((item) => item.codec_type === "video");
assert.equal(stream.width, 1920, `chapter ${chapter.id} width`);
assert.equal(stream.height, 1080, `chapter ${chapter.id} height`);
}
assert.equal(new Set(timeline.chapters.map((chapter) => chapter.id)).size, CHAPTERS);
const html = fs.readFileSync(HTML, "utf8");
assert.ok(html.includes('class="lesson-video"'));
assert.ok(html.includes('type="video/mp4"'));
assert.ok(html.includes("monkey-render-1080p.mp4"));
assert.ok(html.includes("monkey-render.zh-Hans.vtt"));
assert.ok(html.includes('poster="/tutorial/rendering/video/monkey-render-poster.jpg"'));
assert.ok(!/https?:\/\//i.test(html), "lesson must not reference remote URLs");
console.log(JSON.stringify({
status: "PASS",
video: {
path: path.relative(REPO, VIDEO), bytes: fs.statSync(VIDEO).size,
durationSeconds: Number(duration.toFixed(2)),
codecs: { video: videoStream.codec_name, audio: audioStream.codec_name },
resolution: `${videoStream.width}x${videoStream.height}`, faststart: true,
},
narration: { voice: narration.voice, chapters: narration.chapters.length },
vttCues: cues.length,
chapters: timeline.chapters.length,
poster: "1920x1080",
}, null, 2));