Advance M8-M11 parity workflows
This commit is contained in:
@@ -11,6 +11,7 @@ import {
|
||||
} from "../vendor/three/three.module.js";
|
||||
import type { MaterialIR, SceneSnapshotIR, WorldIR } from "../../../protocol/scene-ir";
|
||||
import { RenderAssetValidationError, validateGPUTextureAsset, type GPUTextureAsset, type GPUTextureColorSpace, type GPUTextureUsage } from "../../../protocol/render-assets";
|
||||
import { planPBRTextureBudget, type PBRDeviceLimits, type PBRRenderBackend, type PBRTextureBudgetReport } from "../../../protocol/render-budget";
|
||||
|
||||
export interface TextureUploadStatus {
|
||||
loaded: number;
|
||||
@@ -18,6 +19,7 @@ export interface TextureUploadStatus {
|
||||
bytes: number;
|
||||
errors: string[];
|
||||
errorCodes: string[];
|
||||
budget: PBRTextureBudgetReport;
|
||||
}
|
||||
|
||||
function key(imageId: string, usage: GPUTextureUsage): string {
|
||||
@@ -48,6 +50,11 @@ export class GPUTextureStore {
|
||||
private readonly udimTileCounts = new Map<string, number>();
|
||||
private revision = 0;
|
||||
|
||||
constructor(
|
||||
private readonly backend: PBRRenderBackend = "THREE_WEBGL2",
|
||||
private readonly deviceLimits: PBRDeviceLimits = {},
|
||||
) {}
|
||||
|
||||
getRevision(): number {
|
||||
return this.revision;
|
||||
}
|
||||
@@ -61,7 +68,20 @@ export class GPUTextureStore {
|
||||
}
|
||||
|
||||
async upload(assets: readonly GPUTextureAsset[]): Promise<TextureUploadStatus> {
|
||||
const status: TextureUploadStatus = { loaded: 0, rejected: 0, bytes: 0, errors: [], errorCodes: [] };
|
||||
const candidate = new Map(this.assets);
|
||||
for (const asset of assets) {
|
||||
const lookupUsage = asset.usage === "UDIM_TILE" ? "BASE_COLOR" : asset.usage;
|
||||
candidate.set(key(asset.imageId, lookupUsage), asset);
|
||||
}
|
||||
const budget = planPBRTextureBudget([...candidate.values()], this.backend, this.deviceLimits);
|
||||
const status: TextureUploadStatus = { loaded: 0, rejected: 0, bytes: 0, errors: [], errorCodes: [], budget };
|
||||
if (budget.status === "BLOCKED") {
|
||||
status.rejected = assets.length;
|
||||
status.errors.push(...budget.issues.map((issue) => issue.message));
|
||||
status.errorCodes.push(...budget.issues.map((issue) => issue.code));
|
||||
this.revision += 1;
|
||||
return status;
|
||||
}
|
||||
const incomingUDIMCounts = new Map<string, number>();
|
||||
for (const asset of assets) if (asset.usage === "UDIM_TILE") incomingUDIMCounts.set(asset.imageId, (incomingUDIMCounts.get(asset.imageId) ?? 0) + 1);
|
||||
for (const asset of assets) {
|
||||
@@ -92,12 +112,17 @@ export class GPUTextureStore {
|
||||
|
||||
applyMaterial(material: MeshPhysicalMaterial, definition?: MaterialIR): void {
|
||||
if (!definition) return;
|
||||
const baseImageId = definition.imageIds?.find((imageId) => imageId !== definition.normalImageId) ?? definition.nodes?.find((node) => node.type === "IMAGE_TEXTURE" && node.imageId && node.imageId !== definition.normalImageId)?.imageId;
|
||||
const compile = material.userData.shaderCompile as { status?: string; textureBindings?: Array<{ imageId: string; usage: "BASE_COLOR" | "NORMAL" }> } | undefined;
|
||||
const baseImageId = compile?.status === "COMPILED"
|
||||
? compile.textureBindings?.find((binding) => binding.usage === "BASE_COLOR")?.imageId
|
||||
: definition.imageIds?.find((imageId) => imageId !== definition.normalImageId) ?? definition.nodes?.find((node) => node.type === "IMAGE_TEXTURE" && node.imageId && node.imageId !== definition.normalImageId)?.imageId;
|
||||
if (baseImageId) {
|
||||
const texture = this.get(baseImageId, "BASE_COLOR");
|
||||
if (texture) material.map = texture;
|
||||
}
|
||||
const normalImageId = definition.normalImageId ?? definition.nodes?.find((node) => node.type === "IMAGE_TEXTURE" && node.imageId)?.imageId;
|
||||
const normalImageId = compile?.status === "COMPILED"
|
||||
? compile.textureBindings?.find((binding) => binding.usage === "NORMAL")?.imageId
|
||||
: definition.normalImageId ?? definition.nodes?.find((node) => node.type === "IMAGE_TEXTURE" && node.imageId)?.imageId;
|
||||
if (normalImageId) {
|
||||
const texture = this.get(normalImageId, "NORMAL");
|
||||
if (texture) material.normalMap = texture;
|
||||
|
||||
Reference in New Issue
Block a user