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>
105 lines
4.3 KiB
JavaScript
105 lines
4.3 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* Bake the five `studio/*.sl` presets into a TypeScript module.
|
|
*
|
|
* The desktop parser lives in
|
|
* `blender-5.2.0/source/blender/blenkernel/intern/studiolight.cc:183-226` and is
|
|
* deliberately dumb: for every key it scans all lines with
|
|
* `strstr(line, "<key> ")` — the key must be followed by exactly one space —
|
|
* and runs `atof` on the remainder. There is no version check, no comment
|
|
* syntax, no missing-key error, and a later duplicate overwrites an earlier one.
|
|
* We reproduce that literally so a preset cannot diverge from the desktop.
|
|
*
|
|
* Output is generated rather than fetched at runtime so
|
|
* `createSolidStudioMaterial()` can stay synchronous, and so the app does not
|
|
* need filesystem access to `blender-5.2.0/` outside the vite root.
|
|
*/
|
|
|
|
import { readFile, writeFile } from "node:fs/promises";
|
|
import path from "node:path";
|
|
|
|
const ROOT = "/home/mes123456/workinf_Blender_Wasm";
|
|
const SOURCE_DIR = path.join(ROOT, "blender-5.2.0/release/datafiles/studiolights/studio");
|
|
const OUTPUT = path.join(ROOT, "web/app/src/three-adapter/studio-light-presets.ts");
|
|
|
|
/** Mirrors READ_VAL: substring match on `"<id> "`, last occurrence wins. */
|
|
function readValue(lines, id, parse) {
|
|
const needle = `${id} `;
|
|
let value = null;
|
|
for (const line of lines) {
|
|
const at = line.indexOf(needle);
|
|
if (at < 0) continue;
|
|
value = parse(line.slice(at + needle.length));
|
|
}
|
|
return value;
|
|
}
|
|
|
|
const readFloat = (lines, id) => readValue(lines, id, (text) => Number.parseFloat(text) || 0);
|
|
const readInt = (lines, id) => readValue(lines, id, (text) => Number.parseInt(text, 10) || 0);
|
|
const readVec3 = (lines, id) => [
|
|
readFloat(lines, `${id}.x`) ?? 0,
|
|
readFloat(lines, `${id}.y`) ?? 0,
|
|
readFloat(lines, `${id}.z`) ?? 0,
|
|
];
|
|
|
|
/* SolidLight defaults, DNA_userdef_types.h:727-733 (used when a key is absent). */
|
|
const LIGHT_DEFAULTS = { smooth: 0, col: [0.8, 0.8, 0.8], spec: [0.8, 0.8, 0.8], vec: [0, 0, 1] };
|
|
|
|
function parseSolidLight(text) {
|
|
const lines = text.split("\n");
|
|
const lights = [];
|
|
for (let index = 0; index < 4; index += 1) {
|
|
const flag = readInt(lines, `light[${index}].flag`) ?? 0;
|
|
const light = {
|
|
smooth: readFloat(lines, `light[${index}].smooth`) ?? LIGHT_DEFAULTS.smooth,
|
|
col: readVec3(lines, `light[${index}].col`),
|
|
spec: readVec3(lines, `light[${index}].spec`),
|
|
vec: readVec3(lines, `light[${index}].vec`),
|
|
};
|
|
/* workbench_resources.cc:68 skips a light whose flag is clear. The shader
|
|
* keeps four slots, so a disabled light becomes an exact no-op instead of
|
|
* shifting the array (zero diffuse and zero specular contribute nothing). */
|
|
lights.push(flag
|
|
? light
|
|
: { smooth: 0, col: [0, 0, 0], spec: [0, 0, 0], vec: light.vec });
|
|
}
|
|
return { ambient: readVec3(lines, "light_ambient"), lights };
|
|
}
|
|
|
|
const files = ["basic.sl", "outdoor.sl", "paint.sl", "rim.sl", "studio.sl"];
|
|
const entries = [];
|
|
for (const file of files) {
|
|
const text = await readFile(path.join(SOURCE_DIR, file), "utf8");
|
|
entries.push([file, parseSolidLight(text)]);
|
|
}
|
|
|
|
const fmt = (value) => (Number.isInteger(value) ? String(value) : value.toFixed(6));
|
|
const vec = (value) => `[${value.map(fmt).join(", ")}]`;
|
|
const rig = (entry) => `{
|
|
ambient: ${vec(entry.ambient)},
|
|
lights: [
|
|
${entry.lights.map((light) => ` { smooth: ${fmt(light.smooth)}, col: ${vec(light.col)}, spec: ${vec(light.spec)}, vec: ${vec(light.vec)} },`).join("\n")}
|
|
],
|
|
}`;
|
|
|
|
const body = `import type { StudioLightRig } from "./studio-light";
|
|
|
|
/**
|
|
* GENERATED by /home/mes123456/workinf_Blender_Wasm/tools/web/generate-studiolight-presets.mjs
|
|
* Source: blender-5.2.0/release/datafiles/studiolights/studio/*.sl
|
|
* Do not edit by hand; re-run the generator instead.
|
|
*
|
|
* Keys match the desktop registry, which stores the basename *with* its
|
|
* extension (studiolight.cc:600-618) — so the UI shows "studio.sl", not "studio".
|
|
*/
|
|
export const STUDIO_LIGHT_PRESETS: Record<string, StudioLightRig> = {
|
|
${entries.map(([name, entry]) => ` "${name}": ${rig(entry)},`).join("\n")}
|
|
};
|
|
|
|
/** The internal, non-file light that desktop always lists first. */
|
|
export const STUDIO_LIGHT_PRESET_NAMES: string[] = ["Default", ...Object.keys(STUDIO_LIGHT_PRESETS)];
|
|
`;
|
|
|
|
await writeFile(OUTPUT, body, "utf8");
|
|
console.log(`wrote ${OUTPUT} (${entries.length} presets, ${body.length} bytes)`);
|