This commit is contained in:
casperlamboo 2018-02-12 17:36:07 +01:00
parent 2b4941eefb
commit e087fadd80
11 changed files with 27 additions and 42 deletions

View File

@ -63,7 +63,8 @@ const styles = {
sliceInfo: { sliceInfo: {
margin: '10px 0', margin: '10px 0',
'& p': { '& p': {
marginBottom: '5px' marginBottom: '5px',
fontSize: '11px'
} }
}, },
sliceButtons: { sliceButtons: {

View File

@ -175,7 +175,7 @@ export async function slice(target, name, mesh, settings, updateProgress) {
const centerY = dimensions.y / 2; const centerY = dimensions.y / 2;
const matrix = new THREE.Matrix4().makeTranslation(centerY, 0, centerX).multiply(mesh.matrix); const matrix = new THREE.Matrix4().makeTranslation(centerY, 0, centerX).multiply(mesh.matrix);
const { gcode } = await sliceGeometry(settings, mesh.geometry, mesh.material, matrix, false, false, ({ progress }) => { const { gcode } = await sliceGeometry(settings, mesh.geometry, mesh.material, matrix, true, false, ({ progress }) => {
updateProgress({ updateProgress({
action: progress.action, action: progress.action,
percentage: (currentStep + progress.done / progress.total) / steps percentage: (currentStep + progress.done / progress.total) / steps

View File

@ -1,7 +1,7 @@
import Shape from 'clipper-js'; import Shape from 'clipper-js';
import { PRECISION } from '../constants.js'; import { PRECISION } from '../constants.js';
const offsetOptions = { const OFFSET_OPTIONS = {
jointType: 'jtRound', jointType: 'jtRound',
miterLimit: 2.0, miterLimit: 2.0,
roundPrecision: 0.25, roundPrecision: 0.25,
@ -22,7 +22,7 @@ export default function addBrim(slices, settings) {
const brim = firstLayer.parts.reduce((brim, { shape }) => ( const brim = firstLayer.parts.reduce((brim, { shape }) => (
brim.join(shape.offset(nozzleRadius, { brim.join(shape.offset(nozzleRadius, {
...offsetOptions, ...OFFSET_OPTIONS,
endType: shape.closed ? 'etClosedPolygon' : 'etOpenRound' endType: shape.closed ? 'etClosedPolygon' : 'etOpenRound'
})) }))
), new Shape([], true)).simplify('pftNonZero'); ), new Shape([], true)).simplify('pftNonZero');
@ -30,7 +30,7 @@ export default function addBrim(slices, settings) {
firstLayer.brim = new Shape([], true); firstLayer.brim = new Shape([], true);
for (let offset = 0; offset < brimSize; offset += nozzleDiameter) { for (let offset = 0; offset < brimSize; offset += nozzleDiameter) {
const brimPart = brim.offset(offset, offsetOptions); const brimPart = brim.offset(offset, OFFSET_OPTIONS);
firstLayer.brim = firstLayer.brim.join(brimPart); firstLayer.brim = firstLayer.brim.join(brimPart);
} }
} }

View File

@ -8,7 +8,7 @@ export default function calculateLayersIntersections(lines, settings) {
const numLayers = Math.floor((dimensionsZ - Z_OFFSET) / layerHeight); const numLayers = Math.floor((dimensionsZ - Z_OFFSET) / layerHeight);
const layerPoints = Array.from(Array(numLayers)).map(() => []); const layerPoints = Array.from(Array(numLayers)).map(() => {});
const layerFaceIndexes = Array.from(Array(numLayers)).map(() => []); const layerFaceIndexes = Array.from(Array(numLayers)).map(() => []);
for (let lineIndex = 0; lineIndex < lines.length; lineIndex ++) { for (let lineIndex = 0; lineIndex < lines.length; lineIndex ++) {
@ -33,17 +33,13 @@ export default function calculateLayersIntersections(lines, settings) {
} }
layerPoints[layerIndex][lineIndex] = { x: z, y: x }; layerPoints[layerIndex][lineIndex] = { x: z, y: x };
layerFaceIndexes[layerIndex].push(...faces); for (const faceIndex of faces) {
const layerFaceIndex = layerFaceIndexes[layerIndex];
if (!layerFaceIndex.includes(faceIndex)) layerFaceIndex.push(faceIndex);
}
} }
} }
} }
for (let i = 0; i < layerFaceIndexes.length; i ++) {
layerFaceIndexes[i] = layerFaceIndexes[i].reduce((result, faceIndex) => {
if (!result.includes(faceIndex)) result.push(faceIndex);
return result;
}, []);
}
return { layerPoints, layerFaceIndexes }; return { layerPoints, layerFaceIndexes };
} }

View File

@ -35,18 +35,16 @@ function addLine(vertices, lineLookup, lines, a, b, faceIndex) {
if (typeof lineLookup[`${b}_${a}`] !== 'undefined') { if (typeof lineLookup[`${b}_${a}`] !== 'undefined') {
index = lineLookup[`${b}_${a}`]; index = lineLookup[`${b}_${a}`];
} else { } else {
index = lines.length;
lineLookup[`${a}_${b}`] = index;
const start = getVertex(vertices, a); const start = getVertex(vertices, a);
const end = getVertex(vertices, b); const end = getVertex(vertices, b);
const line = { start, end }; const line = { start, end };
const faces = []; const faces = [];
index = lines.length;
lineLookup[`${a}_${b}`] = index;
lines.push({ line, faces }); lines.push({ line, faces });
} }
lines[index].faces.push(faceIndex); lines[index].faces.push(faceIndex);
return index; return index;
} }

View File

@ -1,6 +1,6 @@
import { PRECISION } from '../constants.js' import { PRECISION } from '../constants.js'
const offsetOptions = { const OFFSET_OPTIONS = {
jointType: 'jtSquare', jointType: 'jtSquare',
endType: 'etClosedPolygon', endType: 'etClosedPolygon',
miterLimit: 2.0, miterLimit: 2.0,
@ -29,7 +29,7 @@ export default function generateInnerLines(slices, settings) {
if (!part.closed) continue; if (!part.closed) continue;
const outerLine = part.shape.offset(-nozzleRadius, offsetOptions); const outerLine = part.shape.offset(-nozzleRadius, OFFSET_OPTIONS);
if (outerLine.paths.length === 0) continue; if (outerLine.paths.length === 0) continue;
@ -39,7 +39,7 @@ export default function generateInnerLines(slices, settings) {
for (let inset = 1; inset < numShells; inset += 1) { for (let inset = 1; inset < numShells; inset += 1) {
const offset = inset * nozzleDiameter; const offset = inset * nozzleDiameter;
const shell = outerLine.offset(-offset, offsetOptions); const shell = outerLine.offset(-offset, OFFSET_OPTIONS);
if (shell.paths.length === 0) { if (shell.paths.length === 0) {
break; break;

View File

@ -10,7 +10,7 @@ export const POSITION_X = 'X';
export const POSITION_Y = 'Y'; export const POSITION_Y = 'Y';
export const POSITION_Z = 'Z'; export const POSITION_Z = 'Z';
export default class { export default class GCode {
constructor(layerHeight) { constructor(layerHeight) {
this._nozzleToFilamentRatio = 1; this._nozzleToFilamentRatio = 1;
this._gcode = [`; Generated with Doodle3D Slicer V${VERSION}`]; this._gcode = [`; Generated with Doodle3D Slicer V${VERSION}`];

View File

@ -1,6 +1,6 @@
import Shape from 'clipper-js'; import Shape from 'clipper-js';
export default class { export default class Slice {
constructor() { constructor() {
this.parts = []; this.parts = [];
} }

View File

@ -45,9 +45,9 @@ export default function comb(outline, start, end) {
if (snappedCombPaths.length === 0) { if (snappedCombPaths.length === 0) {
snappedCombPaths.push([start], [end]); snappedCombPaths.push([start], [end]);
} else if (distanceTo(firstPath[0], start) > 1.0) { } else if (distanceTo(firstPath[0], start) > 1.) {
snappedCombPaths.unshift([start]); snappedCombPaths.unshift([start]);
} else if (distanceTo(lastPath[lastPath.length - 1], end) > 1.0) { } else if (distanceTo(lastPath[lastPath.length - 1], end) > 1.) {
snappedCombPaths.push([end]); snappedCombPaths.push([end]);
} }

View File

@ -79,7 +79,7 @@ export default function intersectionsToShapes(layerPoints, layerFaceIndexes, fac
endConnects[pointB] = lineSegment; endConnects[pointB] = lineSegment;
if (!shapes[objectIndex]) shapes[objectIndex] = []; if (!shapes[objectIndex]) shapes[objectIndex] = [];
const shape = shapes[objectIndex].push(lineSegment); shapes[objectIndex].push(lineSegment);
} }
} }
@ -87,8 +87,6 @@ export default function intersectionsToShapes(layerPoints, layerFaceIndexes, fac
const shape = shapes[objectIndex].map(lineSegment => lineSegment.map(pointIndex => points[pointIndex])); const shape = shapes[objectIndex].map(lineSegment => lineSegment.map(pointIndex => points[pointIndex]));
const openShape = openObjectIndexes[objectIndex]; const openShape = openObjectIndexes[objectIndex];
const lines = [];
const connectPoints = []; const connectPoints = [];
for (let pathIndex = 0; pathIndex < shape.length; pathIndex ++) { for (let pathIndex = 0; pathIndex < shape.length; pathIndex ++) {
const path = shape[pathIndex]; const path = shape[pathIndex];
@ -114,6 +112,7 @@ export default function intersectionsToShapes(layerPoints, layerFaceIndexes, fac
if (shapeEndPoint) connectPoints.push({ point: shapeEndPoint, start: null, end: pathIndex }); if (shapeEndPoint) connectPoints.push({ point: shapeEndPoint, start: null, end: pathIndex });
} }
const lines = [];
while (connectPoints.length !== 0) { while (connectPoints.length !== 0) {
let { start, end } = connectPoints.pop(); let { start, end } = connectPoints.pop();

View File

@ -32,21 +32,12 @@ export default function shapesToSlices(shapes, settings) {
slice.add(fillShape, true); slice.add(fillShape, true);
if (lineShapesClosed.paths.length > 0) { if (lineShapesClosed.paths.length > 0) lineShapesClosed = lineShapesClosed.difference(fillShape);
lineShapesClosed = lineShapesClosed.difference(fillShape); if (lineShapesOpen.paths.length > 0) lineShapesOpen = lineShapesOpen.difference(fillShape);
}
if (lineShapesOpen.paths.length > 0) {
lineShapesOpen = lineShapesOpen.difference(fillShape);
}
} }
if (lineShapesClosed.paths.length > 0) { if (lineShapesClosed.paths.length > 0) slice.add(lineShapesClosed, false);
slice.add(lineShapesClosed, false); if (lineShapesOpen.paths.length > 0) slice.add(lineShapesOpen, false);
}
if (lineShapesOpen.paths.length > 0) {
slice.add(lineShapesOpen, false);
}
sliceLayers.push(slice); sliceLayers.push(slice);
} }