From bc0f51cc7b9110dfc4584a26d75d835894a2d4b7 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Fri, 27 Jun 2025 17:25:18 -0400 Subject: [PATCH] experimentally load worker into engine as base64 blob payload --- app.js | 15 ++++++++------- src/geo/csg.js | 6 +++++- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/app.js b/app.js index ccaea770..e2cceb2e 100644 --- a/app.js +++ b/app.js @@ -495,6 +495,7 @@ const script = { "&main/kiri", ], engine : [ + "@kiri_work", "&kiri-run/engine", "&main/kiri", ], @@ -696,6 +697,9 @@ function concatCode(key) { // in debug mode, the script should load dependent // scripts instead of serving a complete bundle if (debug) { + inject.forEach(key => { + code.push(synth[key]); + }); code.push(...[ oversion ? `self.debug_version='${oversion}';self.enable_service=${serviceWorker};` : '', 'self.debug=true;', @@ -709,6 +713,7 @@ function concatCode(key) { ']; function load_next() {', 'let file = load.shift();', 'if (!file) return;', + // 'console.log("loading", file);', 'if (!self.document) { importScripts(file); return load_next() }', 'let s = document.createElement("script");', 's.type = "text/javascript";', @@ -717,11 +722,11 @@ function concatCode(key) { 'document.head.appendChild(s);', '} load_next(); })();' ].join('\n')); + code = code.join('\n'); + } else { inject.forEach(key => { code.push(synth[key]); }); - code = code.join('\n'); - } else { direct.forEach(file => { let cached = getCachedFile(file, path => { return minify(PATH.join(dir,file)); @@ -731,13 +736,9 @@ function concatCode(key) { } code.push(cached); }); - inject.forEach(key => { - code.push(synth[key]); - }); code = code.join(''); + synth[key] = `self.${key} = "${Buffer.from(code).toString('base64')}";\n`; } - // console.log(`SETTING synth[${key}]`); - // synth[key] = `self.${key} = "${Buffer.from(code).toString('base64')}";\n`; return code; } diff --git a/src/geo/csg.js b/src/geo/csg.js index 2a098c26..e93fa19d 100644 --- a/src/geo/csg.js +++ b/src/geo/csg.js @@ -126,11 +126,15 @@ let Instance; ext.manifold.then(mod => { mod.default({ - locateFile() { return "/wasm/manifold.wasm" } + locateFile(a,b,c) { + return "/wasm/manifold.wasm"; + } }).then(inst => { inst.setup(); Instance = inst; CSG.Instance = () => { return Instance }; + }).catch(error => { + console.log('manifold load error', error); }); });