mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-11-26 07:24:57 +01:00
Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
commit
46dd12d6ec
8
.gitignore
vendored
8
.gitignore
vendored
@ -1,8 +1,12 @@
|
|||||||
|
|
||||||
*.DS_Store
|
*.DS_Store
|
||||||
|
|
||||||
jspm_packages/*
|
jspm_packages
|
||||||
|
|
||||||
node_modules/*
|
node_modules
|
||||||
|
|
||||||
|
lib
|
||||||
|
|
||||||
|
module
|
||||||
|
|
||||||
bundle.js
|
bundle.js
|
||||||
|
@ -4,7 +4,7 @@ import SlicerWorker from './slicerWorker.js!worker';
|
|||||||
|
|
||||||
export function sliceMesh(settings, mesh, sync = false, onProgress) {
|
export function sliceMesh(settings, mesh, sync = false, onProgress) {
|
||||||
if (typeof mesh === 'undefined' || !mesh.isMesh) {
|
if (typeof mesh === 'undefined' || !mesh.isMesh) {
|
||||||
throw new Error('Provide mesh is not intance of THREE.Mesh');
|
throw new Error('Provided mesh is not intance of THREE.Mesh');
|
||||||
}
|
}
|
||||||
|
|
||||||
mesh.updateMatrix();
|
mesh.updateMatrix();
|
||||||
@ -23,6 +23,10 @@ export function sliceGeometry(settings, geometry, matrix, sync = false, onProgre
|
|||||||
throw new Error('Geometry is not an instance of BufferGeometry or Geometry');
|
throw new Error('Geometry is not an instance of BufferGeometry or Geometry');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (geometry.faces.length === 0) {
|
||||||
|
throw new Error('Geometry does not contain any data');
|
||||||
|
}
|
||||||
|
|
||||||
if (matrix) {
|
if (matrix) {
|
||||||
geometry.applyMatrix(matrix);
|
geometry.applyMatrix(matrix);
|
||||||
}
|
}
|
||||||
@ -42,7 +46,11 @@ function sliceAsync(settings, geometry, onProgress) {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// create the slicer worker
|
// create the slicer worker
|
||||||
const slicerWorker = new SlicerWorker();
|
const slicerWorker = new SlicerWorker();
|
||||||
slicerWorker.onerror = reject;
|
|
||||||
|
slicerWorker.onerror = error => {
|
||||||
|
slicerWorker.terminate();
|
||||||
|
reject(error);
|
||||||
|
};
|
||||||
|
|
||||||
// listen to messages send from worker
|
// listen to messages send from worker
|
||||||
slicerWorker.addEventListener('message', (event) => {
|
slicerWorker.addEventListener('message', (event) => {
|
||||||
@ -63,11 +71,12 @@ function sliceAsync(settings, geometry, onProgress) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// send geometry and settings to worker to start the slicing progress
|
// send geometry and settings to worker to start the slicing progress
|
||||||
|
geometry = geometry.toJSON();
|
||||||
slicerWorker.postMessage({
|
slicerWorker.postMessage({
|
||||||
message: 'SLICE',
|
message: 'SLICE',
|
||||||
data: {
|
data: {
|
||||||
settings,
|
settings,
|
||||||
geometry: geometry.toJSON()
|
geometry
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -15,11 +15,10 @@ export default function addBrim(slices, settings) {
|
|||||||
|
|
||||||
const [firstLayer] = slices;
|
const [firstLayer] = slices;
|
||||||
|
|
||||||
firstLayer.brim = firstLayer.parts.reduce((brim, { shape }) => {
|
firstLayer.brim = firstLayer.parts.reduce((brim, { shape }) => (
|
||||||
brim.join(shape.offset(brimOffset, {
|
brim.join(shape.offset(brimOffset, {
|
||||||
...offsetOptions,
|
...offsetOptions,
|
||||||
endType: shape.closed ? 'etClosedPolygon' : 'etOpenRound'
|
endType: shape.closed ? 'etClosedPolygon' : 'etOpenRound'
|
||||||
}));
|
}))
|
||||||
return brim;
|
), new Shape([], true)).simplify('pftNonZero');
|
||||||
}, new Shape([], true)).simplify('pftNonZero');
|
|
||||||
}
|
}
|
||||||
|
@ -21,12 +21,8 @@ export default function optimizePaths(slices, settings) {
|
|||||||
for (let i = 0; i < slice.parts.length; i ++) {
|
for (let i = 0; i < slice.parts.length; i ++) {
|
||||||
const part = slice.parts[i];
|
const part = slice.parts[i];
|
||||||
|
|
||||||
let bounds;
|
const shape = part.shape.closed ? part.outerLine : part.shape;
|
||||||
if (part.shape.closed) {
|
const bounds = shape.shapeBounds();
|
||||||
bounds = part.outerLine.shapeBounds();
|
|
||||||
} else {
|
|
||||||
bounds = part.shape.shapeBounds();
|
|
||||||
}
|
|
||||||
|
|
||||||
const top = bounds.top - start.y;
|
const top = bounds.top - start.y;
|
||||||
const bottom = start.y - bounds.bottom;
|
const bottom = start.y - bounds.bottom;
|
||||||
@ -41,7 +37,7 @@ export default function optimizePaths(slices, settings) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const part = slice.parts.splice(closestPart, 1)[0];
|
const [part] = slice.parts.splice(closestPart, 1);
|
||||||
parts.push(part);
|
parts.push(part);
|
||||||
|
|
||||||
if (part.shape.closed) {
|
if (part.shape.closed) {
|
||||||
|
Loading…
Reference in New Issue
Block a user