diff --git a/src/interface/index.js b/src/interface/index.js index 3f85d5d..feac50a 100644 --- a/src/interface/index.js +++ b/src/interface/index.js @@ -63,7 +63,8 @@ const styles = { sliceInfo: { margin: '10px 0', '& p': { - marginBottom: '5px' + marginBottom: '5px', + fontSize: '11px' } }, sliceButtons: { diff --git a/src/interface/utils.js b/src/interface/utils.js index 51a99b1..2543225 100644 --- a/src/interface/utils.js +++ b/src/interface/utils.js @@ -175,7 +175,7 @@ export async function slice(target, name, mesh, settings, updateProgress) { const centerY = dimensions.y / 2; 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({ action: progress.action, percentage: (currentStep + progress.done / progress.total) / steps diff --git a/src/sliceActions/addBrim.js b/src/sliceActions/addBrim.js index f3e7627..201d0fc 100644 --- a/src/sliceActions/addBrim.js +++ b/src/sliceActions/addBrim.js @@ -1,7 +1,7 @@ import Shape from 'clipper-js'; import { PRECISION } from '../constants.js'; -const offsetOptions = { +const OFFSET_OPTIONS = { jointType: 'jtRound', miterLimit: 2.0, roundPrecision: 0.25, @@ -22,7 +22,7 @@ export default function addBrim(slices, settings) { const brim = firstLayer.parts.reduce((brim, { shape }) => ( brim.join(shape.offset(nozzleRadius, { - ...offsetOptions, + ...OFFSET_OPTIONS, endType: shape.closed ? 'etClosedPolygon' : 'etOpenRound' })) ), new Shape([], true)).simplify('pftNonZero'); @@ -30,7 +30,7 @@ export default function addBrim(slices, settings) { firstLayer.brim = new Shape([], true); 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); } } diff --git a/src/sliceActions/calculateLayersIntersections.js b/src/sliceActions/calculateLayersIntersections.js index 7dc2a45..1f9622a 100644 --- a/src/sliceActions/calculateLayersIntersections.js +++ b/src/sliceActions/calculateLayersIntersections.js @@ -8,7 +8,7 @@ export default function calculateLayersIntersections(lines, settings) { 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(() => []); 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 }; - 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 }; } diff --git a/src/sliceActions/createLines.js b/src/sliceActions/createLines.js index f0deb8a..9fff900 100644 --- a/src/sliceActions/createLines.js +++ b/src/sliceActions/createLines.js @@ -35,18 +35,16 @@ function addLine(vertices, lineLookup, lines, a, b, faceIndex) { if (typeof lineLookup[`${b}_${a}`] !== 'undefined') { index = lineLookup[`${b}_${a}`]; } else { - index = lines.length; - lineLookup[`${a}_${b}`] = index; - const start = getVertex(vertices, a); const end = getVertex(vertices, b); - const line = { start, end }; const faces = []; + + index = lines.length; + lineLookup[`${a}_${b}`] = index; lines.push({ line, faces }); } lines[index].faces.push(faceIndex); - return index; } diff --git a/src/sliceActions/generateInnerLines.js b/src/sliceActions/generateInnerLines.js index 04e981f..2d7e751 100644 --- a/src/sliceActions/generateInnerLines.js +++ b/src/sliceActions/generateInnerLines.js @@ -1,6 +1,6 @@ import { PRECISION } from '../constants.js' -const offsetOptions = { +const OFFSET_OPTIONS = { jointType: 'jtSquare', endType: 'etClosedPolygon', miterLimit: 2.0, @@ -29,7 +29,7 @@ export default function generateInnerLines(slices, settings) { 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; @@ -39,7 +39,7 @@ export default function generateInnerLines(slices, settings) { for (let inset = 1; inset < numShells; inset += 1) { const offset = inset * nozzleDiameter; - const shell = outerLine.offset(-offset, offsetOptions); + const shell = outerLine.offset(-offset, OFFSET_OPTIONS); if (shell.paths.length === 0) { break; diff --git a/src/sliceActions/helpers/GCode.js b/src/sliceActions/helpers/GCode.js index 18dfa96..0288cc3 100644 --- a/src/sliceActions/helpers/GCode.js +++ b/src/sliceActions/helpers/GCode.js @@ -10,7 +10,7 @@ export const POSITION_X = 'X'; export const POSITION_Y = 'Y'; export const POSITION_Z = 'Z'; -export default class { +export default class GCode { constructor(layerHeight) { this._nozzleToFilamentRatio = 1; this._gcode = [`; Generated with Doodle3D Slicer V${VERSION}`]; diff --git a/src/sliceActions/helpers/Slice.js b/src/sliceActions/helpers/Slice.js index 10b22fe..2f5c085 100644 --- a/src/sliceActions/helpers/Slice.js +++ b/src/sliceActions/helpers/Slice.js @@ -1,6 +1,6 @@ import Shape from 'clipper-js'; -export default class { +export default class Slice { constructor() { this.parts = []; } diff --git a/src/sliceActions/helpers/comb.js b/src/sliceActions/helpers/comb.js index 538cda9..671e8fa 100644 --- a/src/sliceActions/helpers/comb.js +++ b/src/sliceActions/helpers/comb.js @@ -45,9 +45,9 @@ export default function comb(outline, start, end) { if (snappedCombPaths.length === 0) { snappedCombPaths.push([start], [end]); - } else if (distanceTo(firstPath[0], start) > 1.0) { + } else if (distanceTo(firstPath[0], start) > 1.) { 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]); } diff --git a/src/sliceActions/intersectionsToShapes.js b/src/sliceActions/intersectionsToShapes.js index 5d5646b..f7a5c39 100644 --- a/src/sliceActions/intersectionsToShapes.js +++ b/src/sliceActions/intersectionsToShapes.js @@ -79,7 +79,7 @@ export default function intersectionsToShapes(layerPoints, layerFaceIndexes, fac endConnects[pointB] = lineSegment; 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 openShape = openObjectIndexes[objectIndex]; - const lines = []; - const connectPoints = []; for (let pathIndex = 0; pathIndex < shape.length; 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 }); } + const lines = []; while (connectPoints.length !== 0) { let { start, end } = connectPoints.pop(); diff --git a/src/sliceActions/shapesToSlices.js b/src/sliceActions/shapesToSlices.js index b681a72..9e439cc 100644 --- a/src/sliceActions/shapesToSlices.js +++ b/src/sliceActions/shapesToSlices.js @@ -32,21 +32,12 @@ export default function shapesToSlices(shapes, settings) { slice.add(fillShape, true); - if (lineShapesClosed.paths.length > 0) { - lineShapesClosed = lineShapesClosed.difference(fillShape); - } - if (lineShapesOpen.paths.length > 0) { - lineShapesOpen = lineShapesOpen.difference(fillShape); - } + if (lineShapesClosed.paths.length > 0) lineShapesClosed = lineShapesClosed.difference(fillShape); + if (lineShapesOpen.paths.length > 0) lineShapesOpen = lineShapesOpen.difference(fillShape); } - if (lineShapesClosed.paths.length > 0) { - slice.add(lineShapesClosed, false); - } - - if (lineShapesOpen.paths.length > 0) { - slice.add(lineShapesOpen, false); - } + if (lineShapesClosed.paths.length > 0) slice.add(lineShapesClosed, false); + if (lineShapesOpen.paths.length > 0) slice.add(lineShapesOpen, false); sliceLayers.push(slice); }