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;
|
|
|
|
const hightemplateSize = 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
|
|
|
|
2016-04-21 22:14:22 +02:00
|
|
|
if (!part.shape.closed) {
|
2016-03-29 00:26:58 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-04-22 21:14:21 +02:00
|
|
|
const outerLine = part.outerLine;
|
2016-03-29 00:26:58 +02:00
|
|
|
|
2016-04-22 19:38:06 +02:00
|
|
|
if (outerLine.paths.length > 0) {
|
2016-04-22 21:14:21 +02:00
|
|
|
const inset = (part.innerLines.length > 0) ? part.innerLines[part.innerLines.length - 1] : outerLine;
|
2016-03-29 00:26:58 +02:00
|
|
|
|
2016-04-22 19:38:06 +02:00
|
|
|
const fillArea = inset.offset(-nozzleRadius);
|
|
|
|
let lowFillArea;
|
|
|
|
let highFillArea;
|
2016-03-29 00:26:58 +02:00
|
|
|
if (surroundingLayer) {
|
2017-07-27 12:42:14 +02:00
|
|
|
highFillArea = fillArea.difference(surroundingLayer).intersect(fillArea);
|
2016-04-22 19:38:06 +02:00
|
|
|
lowFillArea = fillArea.difference(highFillArea);
|
2016-04-22 21:15:33 +02:00
|
|
|
} else {
|
2016-04-22 19:38:06 +02:00
|
|
|
highFillArea = fillArea;
|
2016-03-29 00:26:58 +02:00
|
|
|
}
|
|
|
|
|
2016-04-22 19:38:06 +02:00
|
|
|
if (lowFillArea && lowFillArea.paths.length > 0) {
|
2016-04-22 21:14:21 +02:00
|
|
|
const bounds = lowFillArea.shapeBounds();
|
2017-07-27 18:33:25 +02:00
|
|
|
const lowFillTemplate = getFillTemplate(bounds, infillGridSize, true, true);
|
2016-03-29 00:26:58 +02:00
|
|
|
|
|
|
|
part.fill.join(lowFillTemplate.intersect(lowFillArea));
|
|
|
|
}
|
|
|
|
|
2016-04-22 19:38:06 +02:00
|
|
|
if (highFillArea.paths.length > 0) {
|
2016-04-22 21:14:21 +02:00
|
|
|
const bounds = highFillArea.shapeBounds();
|
|
|
|
const even = (layer % 2 === 0);
|
|
|
|
const highFillTemplate = getFillTemplate(bounds, hightemplateSize, even, !even);
|
2016-03-29 00:26:58 +02:00
|
|
|
|
|
|
|
part.fill.join(highFillTemplate.intersect(highFillArea));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|