Add persistent render graph loadouts, grouped node authoring, code-appending apply behavior, explicit playground lighting, and resilient worker startup. Amp-Thread-ID: https://ampcode.com/threads/T-01a033d4-0e44-708e-af0e-6166283416ff Co-authored-by: Heaust Azure <heaust.azure@gmail.com>
56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import { Mesh } from "../src/Mesh";
|
|
import { Scene } from "../src/Scene";
|
|
import type { PBRMaterial } from "../src/materials/PBRMaterial";
|
|
import type { YawnCore } from "./core-mock";
|
|
|
|
export const triangle = {
|
|
positions: [-1, -1, 0, 1, -1, 0, 0, 1, 0],
|
|
normals: [0, 0, 1, 0, 0, 1, 0, 0, 1],
|
|
tangents: [1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1],
|
|
uvs: [0, 0, 1, 0, 0.5, 1],
|
|
uvs2: [0.1, 0.1, 0.9, 0.1, 0.5, 0.9],
|
|
colors: [1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1],
|
|
indices: [0, 1, 2],
|
|
};
|
|
|
|
export async function createScene(
|
|
options: ConstructorParameters<typeof Scene>[1] = {},
|
|
) {
|
|
const scene = new Scene({} as HTMLCanvasElement, options);
|
|
await scene.ready;
|
|
return scene;
|
|
}
|
|
|
|
export function testCore(scene: Scene) {
|
|
return scene.core as unknown as YawnCore;
|
|
}
|
|
|
|
export function latestGraph(scene: Scene): any {
|
|
return testCore(scene).graphs.at(-1);
|
|
}
|
|
|
|
export function renderPipeline(graph: any, id: string) {
|
|
return graph.pipelines.render.find((pipeline: any) => pipeline.id === id);
|
|
}
|
|
|
|
export function pbrPipelines(graph: any) {
|
|
return graph.pipelines.render.filter((pipeline: any) =>
|
|
pipeline.id.startsWith("forward-pbr-"),
|
|
);
|
|
}
|
|
|
|
export function forwardPasses(graph: any) {
|
|
return graph.passes.filter(
|
|
(pass: any) =>
|
|
pass.type === "render" && pass.pipeline.startsWith("forward-"),
|
|
);
|
|
}
|
|
|
|
export function detailedMesh(
|
|
scene: Scene,
|
|
material: PBRMaterial,
|
|
vertexData: Record<string, ArrayLike<number>> = triangle,
|
|
) {
|
|
return new Mesh(scene, { material, vertexData });
|
|
}
|