Doodle3D-Slicer/example/generateRawData.js

55 lines
2.0 KiB
JavaScript
Raw Permalink Normal View History

2016-10-13 16:33:40 +02:00
import calculateLayersIntersections from 'src/sliceActions/calculateLayersIntersections.js';
import createLines from 'src/sliceActions/createLines.js';
import generateInfills from 'src/sliceActions/generateInfills.js';
import generateInnerLines from 'src/sliceActions/generateInnerLines.js';
import generateSupport from 'src/sliceActions/generateSupport.js';
import intersectionsToShapes from 'src/sliceActions/intersectionsToShapes.js';
import addBrim from 'src/sliceActions/addBrim.js';
import optimizePaths from 'src/sliceActions/optimizePaths.js';
import shapesToSlices from 'src/sliceActions/shapesToSlices.js';
import slicesToGCode from 'src/sliceActions/slicesToGCode.js';
import applyPrecision from 'src/sliceActions/applyPrecision.js';
import removePrecision from 'src/sliceActions/removePrecision.js';
export default function generateRawData(geometry, settings) {
2017-05-13 14:48:48 +02:00
const rawData = {};
2016-10-13 16:33:40 +02:00
2017-05-13 14:48:48 +02:00
const lines = createLines(geometry, settings);
2016-10-13 16:33:40 +02:00
2017-05-13 14:48:48 +02:00
const {
layerIntersectionIndexes,
layerIntersectionPoints
} = calculateLayersIntersections(lines, settings);
2016-10-13 16:33:40 +02:00
2017-05-13 14:48:48 +02:00
rawData.layerIntersectionPoints = layerIntersectionPoints
.map(intersectionPoints => intersectionPoints.map(intersectionPoint => intersectionPoint.clone()));
2016-10-13 16:33:40 +02:00
2017-05-13 14:48:48 +02:00
const layerShapes = intersectionsToShapes(layerIntersectionIndexes, layerIntersectionPoints, lines, settings);
2016-10-13 16:33:40 +02:00
2017-05-13 14:48:48 +02:00
rawData.layerShapes = layerShapes
.map(({ closedShapes, openShapes }) => ({
closedShapes: closedShapes.map(closedShape => closedShape.map(vector => vector.clone())),
openShapes: openShapes.map(openShape => openShape.map(vector => vector.clone()))
}));
2016-10-13 16:33:40 +02:00
2017-05-13 14:48:48 +02:00
applyPrecision(layerShapes);
2016-10-13 16:33:40 +02:00
2017-05-13 14:48:48 +02:00
const slices = shapesToSlices(layerShapes, settings);
2016-10-13 16:33:40 +02:00
2017-05-13 14:48:48 +02:00
generateInnerLines(slices, settings);
generateInfills(slices, settings);
generateSupport(slices, settings);
addBrim(slices, settings);
optimizePaths(slices, settings);
removePrecision(slices);
2016-10-13 16:33:40 +02:00
2017-05-13 14:48:48 +02:00
rawData.slices = slices;
2016-10-13 16:33:40 +02:00
2017-05-13 14:48:48 +02:00
const gcode = slicesToGCode(slices, settings);
2016-10-13 16:33:40 +02:00
2017-05-13 14:48:48 +02:00
rawData.gcode = gcode;
2016-10-13 16:33:40 +02:00
2017-05-13 14:48:48 +02:00
return rawData;
2016-10-13 16:33:40 +02:00
}