diff --git a/src/mode/fdm/fill.js b/src/mode/fdm/fill.js index f44c7fb8..a29da86f 100644 --- a/src/mode/fdm/fill.js +++ b/src/mode/fdm/fill.js @@ -110,18 +110,88 @@ let tile_z = 1 / tile; let gyroid = BASE.gyroid.slice(target.zValue() * tile_z, (1 - density) * 500); - gyroid.polys.forEach(poly => { - for (let tx=0; tx<=tile_x; tx++) { - for (let ty=0; ty<=tile_y; ty++) { + // gyroid.polys.forEach(poly => { + // for (let tx=0; tx<=tile_x; tx++) { + // for (let ty=0; ty<=tile_y; ty++) { + // target.newline(); + // let bx = tx * tile + bounds.min.x; + // let by = ty * tile + bounds.min.y; + // poly.forEach(point => { + // target.emit(bx + point.x * tile, by + point.y * tile); + // }); + // } + // } + // }); + + let polys = []; + for (let tx=0; tx<=tile_x; tx++) { + for (let ty=0; ty<=tile_y; ty++) { + for (let poly of gyroid.polys) { target.newline(); - let bx = tx * tile + bounds.min.x; - let by = ty * tile + bounds.min.y; - poly.forEach(point => { - target.emit(bx + point.x * tile, by + point.y * tile); + 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)); } } - }); + } + polys = connectOpenPolys(polys.filter(p => p.perimeter() > 2)); + for (let poly of polys) { + target.newline(); + for (let point of poly.points) { + target.emit(point.x, point.y); + } + } + } + + function connectOpenPolys(noff, dist = 0.1) { + if (noff.length <= 1) { + return noff; + } + let heal = 0; + // heal/rejoin open segments that have close endpoints + outer: for(;; heal++) { + let ntmp = noff, tlen = ntmp.length; + for (let i=0; i 0) { + // cull nulls + noff = noff.filter(o => o); + } + return noff; } function fillGrid(target) {