feat(web): complete PBR shader, asset library and offscreen render chain
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

- generate a desktop-Blender PBR asset library and seed catalog v2 into OPFS
- add React asset browser, material preview sphere and Web PBR render panel
- extend shader graph/compiler to the finite 14-node set and native properties
- add image colour-space editing, scene-camera still rendering and asset repair
- add focused E2E/unit coverage and implementation status notes

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
mes123456
2026-11-11 14:59:43 +08:00
parent d1e6b63d54
commit a078648297
65 changed files with 6083 additions and 157 deletions

View File

@@ -0,0 +1,13 @@
import type { MaterialIR, WorldIR } from "../../../protocol/scene-ir";
import type { GPUTextureAsset } from "../../../protocol/render-assets";
import type { ShaderCompileReport } from "../../../protocol/shader-compiler";
export type MaterialPreviewRequest =
| { type: "init"; width: number; height: number }
| { type: "render"; requestId: string; material?: MaterialIR; textures: GPUTextureAsset[]; world?: WorldIR }
| { type: "dispose" };
export type MaterialPreviewResponse =
| { type: "ready" }
| { type: "preview"; requestId: string; png: ArrayBuffer; width: number; height: number; compile?: ShaderCompileReport; backend: "THREE_WEBGL2" }
| { type: "error"; requestId?: string; message: string };

View File

@@ -28,6 +28,7 @@ export type OffscreenViewportRequest =
| { type: "pick"; x: number; y: number; mode: "REPLACE" | "ADD" | "SUBTRACT"; baseSelectionRevision: number }
| { type: "greasePencilMarquee"; drawing: GreasePencilDrawingScopeIR; box: GreasePencilMarqueeBoxIR; baseRevision: number; baseSelectionRevision: number; mode: "REPLACE" | "ADD" | "SUBTRACT" }
| { type: "paintDepthVisibility"; requestId: string; request: PaintDepthVisibilityRequestIR }
| { type: "renderStill"; requestId: string; width: number; height: number; cameraMode: "SCENE" | "VIEWPORT"; clean: boolean }
| { type: "dispose" };
export type OffscreenViewportResponse =
@@ -45,4 +46,6 @@ export type OffscreenViewportResponse =
| { type: "paintDepthVisibilityResult"; requestId: string; result: PaintDepthVisibilityResultIR }
| { type: "paintDepthVisibilityError"; requestId: string; message: string }
| { type: "curveGizmoScreenFrame"; frame: CurveGizmoScreenFrameIR | null }
| { type: "still"; requestId: string; png: ArrayBuffer; width: number; height: number; backend: "THREE_WEBGL2" }
| { type: "stillError"; requestId: string; message: string; code?: string }
| { type: "error"; message: string };

View File

@@ -103,6 +103,11 @@ export class OffscreenViewportRenderer implements ViewportBackend {
resolve: (result: PaintDepthVisibilityResultIR) => void;
reject: (error: Error) => void;
}>();
private stillSequence = 0;
private readonly pendingStill = new Map<string, {
resolve: (result: { png: ArrayBuffer; width: number; height: number }) => void;
reject: (error: Error) => void;
}>();
constructor(
canvas: HTMLCanvasElement,
@@ -209,6 +214,14 @@ export class OffscreenViewportRenderer implements ViewportBackend {
this.worker.postMessage({ type: "interaction", editMode, selectionMode } satisfies OffscreenViewportRequest);
}
renderStill(width: number, height: number, cameraMode: "SCENE" | "VIEWPORT" = "VIEWPORT", clean = true): Promise<{ png: ArrayBuffer; width: number; height: number }> {
const requestId = `still-${++this.stillSequence}`;
return new Promise((resolve, reject) => {
this.pendingStill.set(requestId, { resolve, reject });
this.worker.postMessage({ type: "renderStill", requestId, width, height, cameraMode, clean } satisfies OffscreenViewportRequest);
});
}
samplePaintVisibility(requestValue: PaintDepthVisibilityRequestIR): Promise<PaintDepthVisibilityResultIR> {
const request = validatePaintDepthVisibilityRequest(requestValue, this.lastSnapshot?.revision ?? -1);
const requestId = `paint-depth-${++this.paintDepthRequestSequence}`;
@@ -372,6 +385,19 @@ export class OffscreenViewportRenderer implements ViewportBackend {
this.pendingPaintDepth.delete(message.requestId);
pending.reject(new Error(message.message));
}
else if (message.type === "still") {
const pending = this.pendingStill.get(message.requestId);
if (!pending) return;
this.pendingStill.delete(message.requestId);
pending.resolve({ png: message.png, width: message.width, height: message.height });
this.canvas.dataset.lastStill = `${message.width}x${message.height}:${message.png.byteLength}`;
}
else if (message.type === "stillError") {
const pending = this.pendingStill.get(message.requestId);
if (!pending) return;
this.pendingStill.delete(message.requestId);
pending.reject(new Error(message.message));
}
else if (message.type === "frame") {
this.canvas.dataset.rendererPixels = String(message.visiblePixels);
}
@@ -426,5 +452,7 @@ export class OffscreenViewportRenderer implements ViewportBackend {
this.worker.terminate();
for (const pending of this.pendingPaintDepth.values()) pending.reject(new Error("PAINT_DEPTH_UNAVAILABLE: Offscreen viewport disposed"));
this.pendingPaintDepth.clear();
for (const pending of this.pendingStill.values()) pending.reject(new Error("VIEWPORT_DISPOSED: offscreen still render was cancelled"));
this.pendingStill.clear();
}
}

View File

@@ -136,8 +136,23 @@ export class GPUTextureStore {
applyMaterial(material: MeshPhysicalMaterial, definition?: MaterialIR): void {
if (!definition) return;
const compile = material.userData.shaderCompile as { status?: string; textureBindings?: Array<{ imageId: string; usage: "BASE_COLOR" | "NORMAL" }> } | undefined;
const bindings: Array<{ imageId: string; usage: string; strength?: number }> = definition.textureBindings?.length
const compile = material.userData.shaderCompile as {
status?: string;
textureBindings?: Array<{
imageId: string;
usage: "BASE_COLOR" | "NORMAL" | "BUMP";
strength?: number;
uvMap?: string;
uvTransform?: { offset: [number, number]; rotation: number; scale: [number, number] };
}>;
} | undefined;
const bindings: Array<{
imageId: string;
usage: string;
strength?: number;
uvMap?: string;
uvTransform?: { offset: [number, number]; rotation: number; scale: [number, number] };
}> = definition.textureBindings?.length
? definition.textureBindings
: compile?.status === "COMPILED" && compile.textureBindings?.length
? compile.textureBindings
@@ -146,14 +161,25 @@ export class GPUTextureStore {
...(definition.normalImageId ? [{ imageId: definition.normalImageId, usage: "NORMAL" }] : []),
];
const bindingFor = (usage: string) => bindings.find((binding) => binding.usage === usage);
const textureFor = (binding: { imageId: string; uvTransform?: { offset: [number, number]; rotation: number; scale: [number, number] } }, usage: GPUTextureUsage) => {
const source = this.get(binding.imageId, usage);
if (!source || !binding.uvTransform) return source;
const texture = source.clone();
texture.offset.set(binding.uvTransform.offset[0], binding.uvTransform.offset[1]);
texture.repeat.set(binding.uvTransform.scale[0], binding.uvTransform.scale[1]);
texture.rotation = binding.uvTransform.rotation;
texture.center.set(0.5, 0.5);
texture.needsUpdate = true;
return texture;
};
const base = bindingFor("BASE_COLOR");
if (base) {
const texture = this.get(base.imageId, "BASE_COLOR");
const texture = textureFor(base, "BASE_COLOR");
if (texture) { material.map = texture; material.color.setRGB(1, 1, 1); }
}
const normal = bindingFor("NORMAL");
if (normal) {
const texture = this.get(normal.imageId, "NORMAL");
const texture = textureFor(normal, "NORMAL");
if (texture) material.normalMap = texture;
if (typeof normal.strength === "number") material.normalScale.set(normal.strength, normal.strength);
}
@@ -179,7 +205,7 @@ export class GPUTextureStore {
}
const bump = bindingFor("BUMP");
if (bump) {
const texture = this.get(bump.imageId, "BUMP");
const texture = textureFor(bump, "BUMP");
if (texture) { material.bumpMap = texture; material.bumpScale = Math.min(100, Math.max(0, bump.strength ?? 1)); }
}
if (material.map || material.normalMap || material.metalnessMap || material.roughnessMap || material.emissiveMap || material.alphaMap || material.bumpMap) material.needsUpdate = true;