Add FxNode render graph playground
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>
This commit is contained in:
+48
-5
@@ -16,15 +16,39 @@ const browser = {
|
||||
target: "es2022",
|
||||
};
|
||||
|
||||
const fxNodeSource = path.join(root, "vendor", "fxnode", "src");
|
||||
const fxNodeImports = {
|
||||
name: "yawn-fxnode-imports",
|
||||
setup(builder) {
|
||||
builder.onResolve({ filter: /^fxnode$/ }, () => ({
|
||||
path: path.join(fxNodeSource, "index.ts"),
|
||||
}));
|
||||
builder.onResolve({ filter: /\?worker&url$/ }, () => ({
|
||||
path: "fxnode-worker-url",
|
||||
namespace: "yawn-fxnode-worker",
|
||||
}));
|
||||
builder.onLoad({ filter: /.*/, namespace: "yawn-fxnode-worker" }, () => ({
|
||||
contents: 'export default "./fxnode-worker.js";',
|
||||
loader: "js",
|
||||
}));
|
||||
},
|
||||
};
|
||||
|
||||
const workerFiles = new Map([
|
||||
[path.join(root, "core", "index.js"), "./worker.js"],
|
||||
[
|
||||
path.join(root, "core", "index.js"),
|
||||
{
|
||||
url: "./worker.js",
|
||||
source: await fs.readFile(path.join(root, "core", "worker.js"), "utf8"),
|
||||
},
|
||||
],
|
||||
[
|
||||
path.join(root, "addons", "handles", "src", "importers", "gltf.ts"),
|
||||
"./importer-worker.js",
|
||||
{ url: "./importer-worker.js" },
|
||||
],
|
||||
[
|
||||
path.join(root, "addons", "handles", "src", "bvh", "picking.ts"),
|
||||
"./bvh-worker.js",
|
||||
{ url: "./bvh-worker.js" },
|
||||
],
|
||||
]);
|
||||
|
||||
@@ -37,12 +61,20 @@ const workerURLs = {
|
||||
let contents = await fs.readFile(source, "utf8");
|
||||
const transformed = contents.replace(
|
||||
/new Worker\(new URL\("\.\/worker\.(?:js|ts)", import\.meta\.url\),/,
|
||||
`createYawnWorker(new URL(${JSON.stringify(worker)}, import.meta.url),`,
|
||||
`createYawnWorker(new URL(${JSON.stringify(worker.url)}, import.meta.url), ${worker.source ? JSON.stringify(worker.source) : "undefined"},`,
|
||||
);
|
||||
if (transformed === contents)
|
||||
throw new Error(`worker constructor not found in ${source}`);
|
||||
contents = `
|
||||
function createYawnWorker(url, options) {
|
||||
function createYawnWorker(url, embeddedSource, options) {
|
||||
if (embeddedSource) {
|
||||
const moduleUrl = new URL("./pkg/yawn_core.js", url);
|
||||
const source = embeddedSource.replace("./pkg/yawn_core.js", moduleUrl.href);
|
||||
const bootstrap = URL.createObjectURL(new Blob([source], { type: "text/javascript" }));
|
||||
const worker = new Worker(bootstrap, options);
|
||||
URL.revokeObjectURL(bootstrap);
|
||||
return worker;
|
||||
}
|
||||
if (url.origin === globalThis.location.origin) return new Worker(url, options);
|
||||
const source = "import " + JSON.stringify(url.href) + ";";
|
||||
const bootstrap = URL.createObjectURL(new Blob([source], { type: "text/javascript" }));
|
||||
@@ -70,6 +102,17 @@ await Promise.all([
|
||||
outfile: path.join(output, "handles.js"),
|
||||
plugins: [workerURLs],
|
||||
}),
|
||||
build({
|
||||
...browser,
|
||||
entryPoints: [path.join(root, "addons", "fxnode_rg", "src", "index.ts")],
|
||||
outfile: path.join(output, "fxnode-rg.js"),
|
||||
plugins: [fxNodeImports],
|
||||
}),
|
||||
build({
|
||||
...browser,
|
||||
entryPoints: [path.join(fxNodeSource, "worker", "fxnode.worker.ts")],
|
||||
outfile: path.join(output, "fxnode-worker.js"),
|
||||
}),
|
||||
build({
|
||||
bundle: false,
|
||||
entryPoints: [path.join(root, "core", "worker.js")],
|
||||
|
||||
Reference in New Issue
Block a user