Co-authored-by: Heaust Azure <heaust.azure@gmail.com> Amp-Thread-ID: https://ampcode.com/threads/T-01a01380-b478-77d0-84a0-102880a5c5ae
19 lines
1.0 KiB
JavaScript
19 lines
1.0 KiB
JavaScript
import { createGraphAst } from "@yawn/render-graph-ast";
|
|
|
|
/** Exports FXNode nodes with a `pass` payload and links as the canonical pass DAG. */
|
|
export function adaptFxNodeSnapshot(snapshot, { pipelines = {}, resources = {} } = {}) {
|
|
if (!Array.isArray(snapshot?.nodes) || !Array.isArray(snapshot?.links)) throw new TypeError("FXNODE_GRAPH");
|
|
const passes = snapshot.nodes.map(node => {
|
|
if (!node?.id || !node.pass) throw new TypeError("FXNODE_PASS");
|
|
return { ...structuredClone(node.pass), id: node.id, after: [...(node.pass.after ?? [])] };
|
|
});
|
|
const byId = new Map(passes.map(pass => [pass.id, pass]));
|
|
for (const link of snapshot.links) {
|
|
const source = link.fromNodeId ?? link.from?.node;
|
|
const target = link.toNodeId ?? link.to?.node;
|
|
if (!byId.has(source) || !byId.has(target)) throw new TypeError("FXNODE_LINK");
|
|
if (!byId.get(target).after.includes(source)) byId.get(target).after.push(source);
|
|
}
|
|
return createGraphAst({ id: snapshot.graphId ?? "fxnode", pipelines, resources, passes });
|
|
}
|