2016-04-23 00:24:01 +02:00
|
|
|
import { PRECISION } from '../constants.js'
|
2016-08-19 14:09:51 +02:00
|
|
|
import getFillTemplate from './getFillTemplate.js';
|
2017-07-20 11:51:48 +02:00
|
|
|
import Shape from 'clipper-js';
|
2016-03-29 00:26:58 +02:00
|
|
|
|
|
|
|
export default function generateInfills(slices, settings) {
|
2016-03-29 08:49:35 +02:00
|
|
|
let {
|
|
|
|
layerHeight,
|
2017-07-27 18:33:25 +02:00
|
|
|
innerInfill: { gridSize: infillGridSize },
|
|
|
|
thickness: {
|
|
|
|
top: topThickness,
|
|
|
|
bottom: bottomThickness
|
|
|
|
},
|
2017-07-27 12:42:14 +02:00
|
|
|
nozzleDiameter
|
2017-07-18 11:39:38 +02:00
|
|
|
} = settings;
|
2016-03-29 08:49:35 +02:00
|
|
|
|
2017-07-27 18:33:25 +02:00
|
|
|
infillGridSize /= PRECISION;
|
2016-04-23 00:24:01 +02:00
|
|
|
nozzleDiameter /= PRECISION;
|
2016-03-29 00:26:58 +02:00
|
|
|
|
2016-04-22 21:14:21 +02:00
|
|
|
const bottomSkinCount = Math.ceil(bottomThickness/layerHeight);
|
|
|
|
const topSkinCount = Math.ceil(topThickness/layerHeight);
|
|
|
|
const nozzleRadius = nozzleDiameter / 2;
|
2017-07-28 11:05:48 +02:00
|
|
|
const outerFillTemplateSize = Math.sqrt(2 * Math.pow(nozzleDiameter, 2));
|
2016-03-29 00:26:58 +02:00
|
|
|
|
2016-04-22 21:14:21 +02:00
|
|
|
for (let layer = 0; layer < slices.length; layer ++) {
|
|
|
|
const slice = slices[layer];
|
2016-03-29 00:26:58 +02:00
|
|
|
|
2016-04-22 21:14:21 +02:00
|
|
|
let surroundingLayer;
|
2016-03-29 00:26:58 +02:00
|
|
|
if (layer - bottomSkinCount >= 0 && layer + topSkinCount < slices.length) {
|
2017-07-19 17:33:55 +02:00
|
|
|
const downSkin = slices[layer - bottomSkinCount].outline;
|
|
|
|
const upSkin = slices[layer + topSkinCount].outline;
|
2016-04-22 21:14:21 +02:00
|
|
|
surroundingLayer = upSkin.intersect(downSkin);
|
2016-03-29 00:26:58 +02:00
|
|
|
}
|
|
|
|
|
2016-04-22 21:14:21 +02:00
|
|
|
for (let i = 0; i < slice.parts.length; i ++) {
|
|
|
|
const part = slice.parts[i];
|
2016-03-29 00:26:58 +02:00
|
|
|
|
2017-07-28 15:02:24 +02:00
|
|
|
if (!part.closed) continue;
|
2016-03-29 00:26:58 +02:00
|
|
|
|
2017-07-28 12:13:53 +02:00
|
|
|
const innerShell = part.shell[part.shell.length - 1];
|
2016-03-29 00:26:58 +02:00
|
|
|
|
2017-07-28 12:13:53 +02:00
|
|
|
if (innerShell.paths.length === 0) continue;
|
2016-03-29 00:26:58 +02:00
|
|
|
|
2017-07-28 12:13:53 +02:00
|
|
|
const fillArea = innerShell.offset(-nozzleRadius);
|
|
|
|
let innerFillArea;
|
|
|
|
let outerFillArea;
|
|
|
|
if (surroundingLayer) {
|
|
|
|
outerFillArea = fillArea.difference(surroundingLayer).intersect(fillArea);
|
|
|
|
innerFillArea = fillArea.difference(outerFillArea);
|
|
|
|
} else {
|
|
|
|
outerFillArea = fillArea;
|
|
|
|
}
|
2016-03-29 00:26:58 +02:00
|
|
|
|
2017-07-28 12:13:53 +02:00
|
|
|
if (innerFillArea && innerFillArea.paths.length > 0) {
|
|
|
|
const bounds = innerFillArea.shapeBounds();
|
|
|
|
const innerFillTemplate = getFillTemplate(bounds, infillGridSize, true, true);
|
2016-03-29 00:26:58 +02:00
|
|
|
|
2017-07-28 12:13:53 +02:00
|
|
|
part.innerFill.join(innerFillTemplate.intersect(innerFillArea));
|
|
|
|
}
|
2016-03-29 00:26:58 +02:00
|
|
|
|
2017-07-28 12:13:53 +02:00
|
|
|
if (outerFillArea.paths.length > 0) {
|
|
|
|
const bounds = outerFillArea.shapeBounds();
|
|
|
|
const even = (layer % 2 === 0);
|
|
|
|
const outerFillTemplate = getFillTemplate(bounds, outerFillTemplateSize, even, !even);
|
2016-03-29 00:26:58 +02:00
|
|
|
|
2017-07-28 12:13:53 +02:00
|
|
|
part.outerFill.join(outerFillTemplate.intersect(outerFillArea));
|
2016-03-29 00:26:58 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|