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>
This commit is contained in:
@@ -1,24 +1,18 @@
|
||||
import type {NativeWorkflowInput} from '../../../protocol/native-workflow';
|
||||
import {sha256Hex} from '../../../protocol/render-assets';
|
||||
import {readNativeResourceArchive,removeNativeResourceArchive,writeNativeResourceArchive} from '../storage/native-resources-opfs';
|
||||
|
||||
type Binding=NonNullable<NativeWorkflowInput['resources']>;
|
||||
type Stored={archive:Blob;sha256:string};
|
||||
const endpoint='/api/blender-resources';
|
||||
|
||||
// Archives live in OPFS, one file per project. `null` removes the entry and
|
||||
// `undefined` reads it, matching the previous IndexedDB call sites.
|
||||
async function stored(project:string,value?:Stored|null):Promise<Stored|undefined>{
|
||||
const db=await new Promise<IDBDatabase>((resolve,reject)=>{
|
||||
const request=indexedDB.open('blender-native-resources',1);
|
||||
request.onupgradeneeded=()=>request.result.createObjectStore('projects');
|
||||
request.onsuccess=()=>resolve(request.result);request.onerror=()=>reject(request.error);
|
||||
});
|
||||
try{return await new Promise((resolve,reject)=>{
|
||||
const transaction=db.transaction('projects',value===undefined?'readonly':'readwrite');
|
||||
const store=transaction.objectStore('projects');
|
||||
const request=value===undefined?store.get(project):value===null?store.delete(project):store.put(value,project);
|
||||
transaction.oncomplete=()=>resolve(value===undefined?request.result:undefined);
|
||||
transaction.onabort=()=>reject(transaction.error??new Error('RESOURCE_STORAGE_ABORTED'));
|
||||
transaction.onerror=()=>reject(transaction.error);
|
||||
});}finally{db.close();}
|
||||
if(value===null){await removeNativeResourceArchive(project);return undefined;}
|
||||
if(value===undefined)return await readNativeResourceArchive(project);
|
||||
await writeNativeResourceArchive(project,value);
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Store the actual bytes, not a short-lived service token. Each project has its own archive.
|
||||
|
||||
@@ -498,7 +498,7 @@ export class WebEngineClient {
|
||||
try {
|
||||
const result = await this.request({ type: "gpuUI", op: "frame", session, ownerGeneration, width, height, pixelRatio, events,
|
||||
...(typeof document === "undefined" ? {} : { fullscreen: Boolean(document.fullscreenElement) }),
|
||||
...(interrupt ? { interrupt } : {}) }, [], undefined, undefined, signal);
|
||||
...(interrupt ? { interrupt } : {}) }, [], undefined, undefined, signal, 300_000);
|
||||
return this.applyGPUResult(result);
|
||||
} finally {
|
||||
if (this.gpuInterrupts.get(session) === signal) this.gpuInterrupts.delete(session);
|
||||
@@ -585,15 +585,19 @@ export class WebEngineClient {
|
||||
throw this.report("INVALID_ARGUMENT", "无法打开空的 .blend 文件", true);
|
||||
}
|
||||
this.abortServerJobsForMainReplacement();
|
||||
const result = await this.request({ type: "openBlend", buffer, libraries, replacements }, [buffer, ...libraries.map(library => library.buffer)], onProgress, signal);
|
||||
/* Large imported scenes need more than the ordinary frame budget to rebuild Main and
|
||||
* project SceneIR; a 30 s timeout would leave `mainUncertain` and block later edits. */
|
||||
const result = await this.request({ type: "openBlend", buffer, libraries, replacements }, [buffer, ...libraries.map(library => library.buffer)], onProgress, signal, undefined, 180_000);
|
||||
if (!result.snapshot) throw this.report("BLEND_READ_FAILED", "WebEngine 未返回 SceneIR", true);
|
||||
this.geometryBuffers = result.geometryBuffers ?? [];
|
||||
this.nonMeshGeometryBuffers = result.nonMeshGeometryBuffers ?? [];
|
||||
return { status: result.status, snapshot: result.snapshot, geometryBuffers: [...this.geometryBuffers], nonMeshGeometryBuffers: [...this.nonMeshGeometryBuffers] };
|
||||
}
|
||||
|
||||
async importScene(format: string, fileName: string, mimeType: string, base64: string): Promise<BlendOpenResult & { delta: SceneDelta; importResult?: unknown }> {
|
||||
const result = await this.request({ type: "jsonCommand", cmd: "importScene", params: { format, fileName, mimeType, base64 } });
|
||||
async importScene(format: string, fileName: string, mimeType: string, base64: string, timeoutMs = 300_000): Promise<BlendOpenResult & { delta: SceneDelta; importResult?: unknown }> {
|
||||
/* Import builds the native Main, refreshes SceneIR and captures history; a 130k-face
|
||||
* model legitimately exceeds the ordinary frame timeout. */
|
||||
const result = await this.request({ type: "jsonCommand", cmd: "importScene", params: { format, fileName, mimeType, base64 } }, [], undefined, undefined, undefined, timeoutMs);
|
||||
if (!result.snapshot || !result.delta) throw this.report("INVALID_ARGUMENT", "IO 导入未返回场景结果", true);
|
||||
this.geometryBuffers = result.geometryBuffers ?? this.geometryBuffers;
|
||||
this.nonMeshGeometryBuffers = result.nonMeshGeometryBuffers ?? this.nonMeshGeometryBuffers;
|
||||
@@ -607,6 +611,15 @@ export class WebEngineClient {
|
||||
};
|
||||
}
|
||||
|
||||
async exportScene(format: string, fileName: string): Promise<{ format: string; base64: string }> {
|
||||
const result = await this.request({ type: "jsonCommand", cmd: "exportScene", params: { format, fileName } });
|
||||
const payload = result.json as { text?: unknown } | undefined;
|
||||
if (!payload || typeof payload.text !== "string" || payload.text.length === 0) {
|
||||
throw this.report("INVALID_ARGUMENT", "原生导出未返回数据", true);
|
||||
}
|
||||
return { format, base64: payload.text };
|
||||
}
|
||||
|
||||
async evaluateCompositor(sceneId: string): Promise<{ width: number; height: number; pixelsBase64: string }> {
|
||||
const result = await this.request({ type: "jsonCommand", cmd: "compositorEvaluate", params: { sceneId } });
|
||||
const payload = result.json as { width?: unknown; height?: unknown; pixelsBase64?: unknown } | undefined;
|
||||
@@ -1150,7 +1163,10 @@ export class WebEngineClient {
|
||||
if (!getWebEngineCommandCapability((payload as { type?: unknown }).type)) {
|
||||
throw this.report("INVALID_ARGUMENT", `Unsupported WebEngine command: ${String((payload as { type?: unknown }).type)}`, true);
|
||||
}
|
||||
const result = await this.request({ type: "applyCommand", payload });
|
||||
/* Undo/redo rebuild the whole Main and its SceneIR; a large imported scene exceeds the
|
||||
* ordinary frame budget even though the native operation completes normally. */
|
||||
const heavy = payload.type === "undo" || payload.type === "redo" ? 300_000 : undefined;
|
||||
const result = await this.request({ type: "applyCommand", payload }, [], undefined, undefined, undefined, heavy);
|
||||
if (!result.snapshot || !result.delta) throw this.report("INVALID_ARGUMENT", "WebEngine 未返回命令结果", true);
|
||||
this.geometryBuffers = result.geometryDelta
|
||||
? applyMeshGeometryDelta(this.geometryBuffers, result.geometryDelta)
|
||||
@@ -1272,8 +1288,10 @@ export class WebEngineClient {
|
||||
return { status: result.status, depsgraph: result.depsgraph };
|
||||
}
|
||||
|
||||
async saveBlend(): Promise<ArrayBuffer> {
|
||||
const result = await this.request({ type: "saveBlend" });
|
||||
async saveBlend(timeoutMs = 180_000): Promise<ArrayBuffer> {
|
||||
/* A full Main write serializes every object; large imports exceed the ordinary 30 s
|
||||
* frame budget, and a timeout would leave `mainUncertain` blocking undo/save. */
|
||||
const result = await this.request({ type: "saveBlend" }, [], undefined, undefined, undefined, timeoutMs);
|
||||
if (!result.blend) throw this.report("BLEND_WRITE_FAILED", "WebEngine 未返回 .blend 数据", true);
|
||||
return result.blend;
|
||||
}
|
||||
@@ -1380,7 +1398,11 @@ export class WebEngineClient {
|
||||
}
|
||||
const pending = this.pending.get(requestId);
|
||||
if (!pending) return;
|
||||
this.mainUncertain = true;
|
||||
/* A display-frame timeout says nothing about Main authority; treating it as
|
||||
* uncertain would block every later undo/save after one slow import frame. */
|
||||
const frameOnly = command.type === "gpuUI" && (command as { op?: string }).op === "frame";
|
||||
this.mainUncertain = !frameOnly;
|
||||
console.error(`[web-engine] request timed out: ${command.type}${command.type === "jsonCommand" ? `/${(command as { cmd?: string }).cmd}` : ""}${frameOnly ? " (frame; Main remains certain)" : ""}`);
|
||||
pending.timedOut = true;
|
||||
pending.timeoutError = this.report("WORKER_TERMINATED", `WebEngine 请求超时: ${command.type}`, true);
|
||||
pending.cleanup?.(); pending.cleanup = undefined; pending.reject(pending.timeoutError!);
|
||||
|
||||
@@ -18,7 +18,7 @@ r = scene.render
|
||||
if p.get('engine') == 'CYCLES' or r.engine == 'CYCLES':
|
||||
import sys, addon_utils
|
||||
if '/python/scripts/addons_core' not in sys.path: sys.path.append('/python/scripts/addons_core')
|
||||
if not hasattr(scene, 'cycles'):
|
||||
if not hasattr(scene, 'cycles'):
|
||||
if addon_utils.enable('cycles', default_set=True) is None or not hasattr(scene, 'cycles'): raise RuntimeError('CYCLES_REGISTRATION_FAILED')
|
||||
old_render = {key: getattr(r, key) for key in ('engine', 'resolution_percentage', 'filepath', 'use_file_extension')}
|
||||
old_frames = (scene.frame_start, scene.frame_end, scene.frame_step, scene.frame_current, scene.frame_subframe)
|
||||
@@ -43,7 +43,9 @@ try:
|
||||
scene.frame_set(frame)
|
||||
r.filepath = p['root'] + '/frame_' + str(frame).zfill(6)
|
||||
if 'FINISHED' not in bpy.ops.render.render('EXEC_DEFAULT', write_still=True, scene=scene.name): raise RuntimeError('NATIVE_RENDER_CANCELLED')
|
||||
files.append({'path': r.frame_path(frame=frame), 'frame': frame})
|
||||
# pipeline.cc writes single frames from rd.pic with use_frames=False,
|
||||
# so the still lands at r.filepath plus the ensured extension.
|
||||
files.append({'path': bpy.path.ensure_ext(r.filepath, '.exr' if p['format'] == 'OPEN_EXR' else '.png'), 'frame': frame})
|
||||
if sum(os.path.getsize(item['path']) for item in files) > 256 * 1024 * 1024: raise RuntimeError('NATIVE_RENDER_OUTPUT_BUDGET')
|
||||
if not files or sum(os.path.getsize(item['path']) for item in files) > 256 * 1024 * 1024: raise RuntimeError('NATIVE_RENDER_OUTPUT_BUDGET')
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user