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,9 +123,29 @@ function fillGyroid(target) {
// } // }
// } // }
// }); // });
let polys = []; let polys = [];
if (gyroid.dir == 'lr') {
for (let ty=0; ty<=tile_y; ty++) {
let temp = [];
for (let tx=0; tx<=tile_x; tx++) { 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 ty=0; ty<=tile_y; ty++) {
for (let poly of gyroid.polys) { for (let poly of gyroid.polys) {
target.newline(); target.newline();
@ -136,9 +156,11 @@ function fillGyroid(target) {
z: 0 z: 0
} }
}); });
polys.push(base.newPolygon().setOpen(true).addObj(points)); temp.push(base.newPolygon().setOpen(true).addObj(points));
} }
} }
polys.appendAll(connectOpenPolys(temp));
}
} }
polys = connectOpenPolys(polys); polys = connectOpenPolys(polys);
for (let poly of polys.filter(p => p.perimeter() > 2)) { for (let poly of polys.filter(p => p.perimeter() > 2)) {
@ -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;
} }