Doodle3D-Slicer/src/sliceActions/generateInfills.js

70 lines
2.2 KiB
JavaScript
Raw Normal View History

2016-04-23 00:24:01 +02:00
import { PRECISION } from '../constants.js'
import getFillTemplate from './getFillTemplate.js';
2017-07-20 11:51:48 +02:00
import Shape from 'clipper-js';
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-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-04-22 21:14:21 +02:00
for (let layer = 0; layer < slices.length; layer ++) {
const slice = slices[layer];
2016-04-22 21:14:21 +02:00
let surroundingLayer;
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-04-22 21:14:21 +02:00
for (let i = 0; i < slice.parts.length; i ++) {
const part = slice.parts[i];
if (!part.closed) continue;
const innerShell = part.shell[part.shell.length - 1];
if (innerShell.paths.length === 0) continue;
const fillArea = innerShell.offset(-nozzleRadius);
let innerFillArea;
let outerFillArea;
if (surroundingLayer) {
outerFillArea = fillArea.difference(surroundingLayer).intersect(fillArea);
innerFillArea = fillArea.difference(outerFillArea);
} else {
outerFillArea = fillArea;
}
if (innerFillArea && innerFillArea.paths.length > 0) {
const bounds = innerFillArea.shapeBounds();
const innerFillTemplate = getFillTemplate(bounds, infillGridSize, true, true);
part.innerFill.join(innerFillTemplate.intersect(innerFillArea));
}
if (outerFillArea.paths.length > 0) {
const bounds = outerFillArea.shapeBounds();
const even = (layer % 2 === 0);
const outerFillTemplate = getFillTemplate(bounds, outerFillTemplateSize, even, !even);
part.outerFill.join(outerFillTemplate.intersect(outerFillArea));
}
}
}
}