From 87137e44d1dbbeb4cd2291a840dea61ddaab9cc4 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Fri, 27 Jun 2025 16:49:04 -0400 Subject: [PATCH 1/3] add maybe future code for loading workers from blobs --- app.js | 44 +++++++++++++++++++++++--------------------- src/kiri/client.js | 4 ++++ 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/app.js b/app.js index b42b158f..ccaea770 100644 --- a/app.js +++ b/app.js @@ -681,11 +681,12 @@ function generateDevices() { function prepareScripts() { generateDevices(); for (let key of Object.keys(script)) { - code[key] = concatCode(script[key]); + code[key] = concatCode(key); } } -function concatCode(array) { +function concatCode(key) { + let array = script[key]; let code = []; let direct = array.filter(f => f.charAt(0) !== '@'); let inject = array.filter(f => f.charAt(0) === '@').map(f => f.substring(1)); @@ -695,11 +696,11 @@ function concatCode(array) { // in debug mode, the script should load dependent // scripts instead of serving a complete bundle if (debug) { - const code = [ + code.push(...[ oversion ? `self.debug_version='${oversion}';self.enable_service=${serviceWorker};` : '', 'self.debug=true;', '(function() { let load = [ ' - ]; + ]); direct.forEach(file => { const vers = cachever[file] || oversion || dversion || version; code.push(`"/${file.replace(/\\/g,'/')}?${vers}",`); @@ -719,24 +720,25 @@ function concatCode(array) { inject.forEach(key => { code.push(synth[key]); }); - return code.join('\n'); - } - - direct.forEach(file => { - let cached = getCachedFile(file, path => { - return minify(PATH.join(dir,file)); + code = code.join('\n'); + } else { + direct.forEach(file => { + let cached = getCachedFile(file, path => { + return minify(PATH.join(dir,file)); + }); + if (oversion) { + cached = `self.debug_version='${oversion}';self.enable_service=${serviceWorker};` + cached; + } + code.push(cached); }); - if (oversion) { - cached = `self.debug_version='${oversion}';self.enable_service=${serviceWorker};` + cached; - } - code.push(cached); - }); - - inject.forEach(key => { - code.push(synth[key]); - }); - - return code.join(''); + inject.forEach(key => { + code.push(synth[key]); + }); + code = code.join(''); + } + // console.log(`SETTING synth[${key}]`); + // synth[key] = `self.${key} = "${Buffer.from(code).toString('base64')}";\n`; + return code; } function getCachedFile(file, fn) { diff --git a/src/kiri/client.js b/src/kiri/client.js index 82157c71..b9e6e2bb 100644 --- a/src/kiri/client.js +++ b/src/kiri/client.js @@ -70,6 +70,10 @@ const client = exports({ newWorker() { if (self.createWorker) { return self.createWorker(); + } else if (self.kiri_work) { + const work = atob(self.kiri_work); + const blob = new Blob([ work ], { type: 'application/javascript' }); + return new Worker(URL.createObjectURL(blob)); } else { let _ = debug ? '_' : ''; return new Worker(`/code/kiri_work.js?${_}${gapp.version}`); From bc0f51cc7b9110dfc4584a26d75d835894a2d4b7 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Fri, 27 Jun 2025 17:25:18 -0400 Subject: [PATCH 2/3] 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); }); }); From 1fcc2405a099fceb50409c2e00f470c779a01744 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Sun, 29 Jun 2025 12:21:14 -0400 Subject: [PATCH 3/3] fix open but really closed traced, prevent slice on null stock --- src/kiri-mode/cam/slice.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/kiri-mode/cam/slice.js b/src/kiri-mode/cam/slice.js index f7c79fdf..7e97fc32 100644 --- a/src/kiri-mode/cam/slice.js +++ b/src/kiri-mode/cam/slice.js @@ -134,6 +134,10 @@ CAM.slice = async function(settings, widget, onupdate, ondone) { return error('no processes specified'); } + if (stock.x === 0 || stock.y === 0 || stock.z === 0) { + return error("one or more stock dimensions is zero
offset stock or set to non zero value"); + } + if (stock.x && stock.y && stock.z && !isIndexed) { if (stock.x + 0.00001 < bounds.max.x - bounds.min.x) { return error('stock X too small for part. resize stock or use offset stock'); @@ -681,6 +685,12 @@ function contourPolys(widget, polys) { } function healPolys(noff) { + for (let p of noff) { + if (p.appearsClosed()) { + p.points.pop(); + p.setClosed(); + } + } if (noff.length > 1) { let heal = 0; // heal/rejoin open segments that share endpoints