gyroid performance improvement equal to roughly square of volume

This commit is contained in:
Stewart Allen 2025-01-10 22:54:33 -05:00
commit 59d5388b61
2 changed files with 36 additions and 14 deletions

View file

@ -22,7 +22,6 @@ function slice(off, res, val) {
// or the requested resolution or tip values have changed // or the requested resolution or tip values have changed
let now = Date.now(); let now = Date.now();
if (res !== lastRes || val !== lastVal || now - lastSlice > 20000) { if (res !== lastRes || val !== lastVal || now - lastSlice > 20000) {
// console.log({clear_cache: now});
cache = {}; cache = {};
} }
lastVal = val; lastVal = val;

View file

@ -123,21 +123,43 @@ function fillGyroid(target) {
// } // }
// } // }
// }); // });
let polys = []; let polys = [];
for (let tx=0; tx<=tile_x; tx++) { if (gyroid.dir == 'lr') {
for (let ty=0; ty<=tile_y; ty++) { for (let ty=0; ty<=tile_y; ty++) {
for (let poly of gyroid.polys) { let temp = [];
target.newline(); for (let tx=0; tx<=tile_x; tx++) {
let points = poly.map(el => { for (let poly of gyroid.polys) {
return { target.newline();
x: el.x * tile + tx * tile + bounds.min.x, let points = poly.map(el => {
y: el.y * tile + ty * tile + bounds.min.y, return {
z: 0 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)); }
});
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); polys = connectOpenPolys(polys);
@ -180,7 +202,8 @@ function connectOpenPolys(noff, dist = 0.1) {
continue outer; continue outer;
} }
if (s1.last().distTo2D(s2.last()) <= dist) { if (s1.last().distTo2D(s2.last()) <= dist) {
s1.addPoints(s2.points.reverse()); s2.reverse();
s1.addPoints(s2.points);
ntmp[j] = null; ntmp[j] = null;
continue outer; continue outer;
} }