Doodle3D-Slicer/src/sliceActions/generateInfills.js

80 lines
2.5 KiB
JavaScript
Raw Normal View History

2016-04-23 00:24:01 +02:00
import { PRECISION } from '../constants.js'
import getFillTemplate from './getFillTemplate.js';
2016-04-21 22:22:59 +02:00
import Shape from 'Doodle3D/clipper-js';
export default function generateInfills(slices, settings) {
2016-03-29 08:49:35 +02:00
let {
layerHeight,
fill: { gridSize: fillGridSize },
bottom: { thickness: bottomThickness },
top: { thickness: topThickness },
2016-03-29 08:49:35 +02:00
nozzleDiameter,
fill: { overlap: infillOverlap }
2017-07-18 11:39:38 +02:00
} = settings;
2016-03-29 08:49:35 +02:00
2016-04-23 00:24:01 +02:00
fillGridSize /= PRECISION;
nozzleDiameter /= PRECISION;
infillOverlap /= 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;
const hightemplateSize = 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) {
2016-04-22 21:14:21 +02:00
const downSkin = slices[layer - bottomSkinCount].getOutline();
const upSkin = slices[layer + topSkinCount].getOutline();
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];
2016-04-21 22:14:22 +02:00
if (!part.shape.closed) {
continue;
}
2016-04-22 21:14:21 +02:00
const outerLine = part.outerLine;
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-04-22 19:38:06 +02:00
const fillArea = inset.offset(-nozzleRadius);
let lowFillArea;
let highFillArea;
if (surroundingLayer) {
2016-04-22 19:38:06 +02:00
highFillArea = fillArea.difference(surroundingLayer);
if (infillOverlap > 0) {
highFillArea = highFillArea.offset(infillOverlap);
}
highFillArea = highFillArea.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-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();
const lowFillTemplate = getFillTemplate(bounds, fillGridSize, true, true);
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);
part.fill.join(highFillTemplate.intersect(highFillArea));
}
}
}
}
}