From 59d5388b613fa16133887e71c06dd911f9fa594b Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Fri, 10 Jan 2025 22:54:33 -0500 Subject: [PATCH] gyroid performance improvement equal to roughly square of volume --- src/geo/gyroid.js | 1 - src/kiri-mode/fdm/fill.js | 49 ++++++++++++++++++++++++++++----------- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/geo/gyroid.js b/src/geo/gyroid.js index d28e0f6d..b56ca25c 100644 --- a/src/geo/gyroid.js +++ b/src/geo/gyroid.js @@ -22,7 +22,6 @@ function slice(off, res, val) { // or the requested resolution or tip values have changed let now = Date.now(); if (res !== lastRes || val !== lastVal || now - lastSlice > 20000) { - // console.log({clear_cache: now}); cache = {}; } lastVal = val; diff --git a/src/kiri-mode/fdm/fill.js b/src/kiri-mode/fdm/fill.js index b70c1304..de53e4d3 100644 --- a/src/kiri-mode/fdm/fill.js +++ b/src/kiri-mode/fdm/fill.js @@ -123,21 +123,43 @@ function fillGyroid(target) { // } // } // }); - let polys = []; - for (let tx=0; tx<=tile_x; tx++) { + if (gyroid.dir == 'lr') { for (let ty=0; ty<=tile_y; ty++) { - for (let poly of gyroid.polys) { - target.newline(); - let points = poly.map(el => { - return { - x: el.x * tile + tx * tile + bounds.min.x, - y: el.y * tile + ty * tile + bounds.min.y, - z: 0 - } - }); - polys.push(base.newPolygon().setOpen(true).addObj(points)); + let temp = []; + for (let tx=0; tx<=tile_x; tx++) { + for (let poly of gyroid.polys) { + target.newline(); + let points = poly.map(el => { + return { + x: el.x * tile + tx * tile + bounds.min.x, + y: el.y * tile + ty * tile + bounds.min.y, + z: 0 + } + }); + temp.push(base.newPolygon().setOpen(true).addObj(points)); + } } + polys.appendAll(connectOpenPolys(temp)); + // console.log(gyroid.dir, temp.length); + } + } else { + for (let tx=0; tx<=tile_x; tx++) { + let temp = []; + for (let ty=0; ty<=tile_y; ty++) { + for (let poly of gyroid.polys) { + target.newline(); + let points = poly.map(el => { + return { + x: el.x * tile + tx * tile + bounds.min.x, + y: el.y * tile + ty * tile + bounds.min.y, + z: 0 + } + }); + temp.push(base.newPolygon().setOpen(true).addObj(points)); + } + } + polys.appendAll(connectOpenPolys(temp)); } } polys = connectOpenPolys(polys); @@ -180,7 +202,8 @@ function connectOpenPolys(noff, dist = 0.1) { continue outer; } if (s1.last().distTo2D(s2.last()) <= dist) { - s1.addPoints(s2.points.reverse()); + s2.reverse(); + s1.addPoints(s2.points); ntmp[j] = null; continue outer; }