mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-11-22 21:47:59 +01:00
Merge remote-tracking branch 'origin/develop' into develop
This commit is contained in:
commit
2356136a3d
@ -7,9 +7,7 @@ export default class {
|
|||||||
setMesh(mesh) {
|
setMesh(mesh) {
|
||||||
mesh.updateMatrix();
|
mesh.updateMatrix();
|
||||||
|
|
||||||
this.setGeometry(mesh.geometry, mesh.matrix);
|
return this.setGeometry(mesh.geometry, mesh.matrix);
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
setGeometry(geometry, matrix) {
|
setGeometry(geometry, matrix) {
|
||||||
if (geometry.isBufferGeometry) {
|
if (geometry.isBufferGeometry) {
|
||||||
@ -20,7 +18,7 @@ export default class {
|
|||||||
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 (matrix) {
|
if (typeof matrix !== 'undefined') {
|
||||||
geometry.applyMatrix(matrix);
|
geometry.applyMatrix(matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,13 +30,16 @@ export default class {
|
|||||||
return slice(this.geometry, settings, onprogress);
|
return slice(this.geometry, settings, onprogress);
|
||||||
}
|
}
|
||||||
slice(settings) {
|
slice(settings) {
|
||||||
const slicerWorker = new SlicerWorker();
|
if (!this.geometry) {
|
||||||
|
throw new Error('Geometry is not set, use Slicer.setGeometry or Slicer.setMesh first');
|
||||||
const geometry = this.geometry.toJSON();
|
}
|
||||||
|
|
||||||
return new ProgressPromise((resolve, reject, progress) => {
|
return new ProgressPromise((resolve, reject, progress) => {
|
||||||
|
// create the slicer worker
|
||||||
|
const slicerWorker = new SlicerWorker();
|
||||||
slicerWorker.onerror = reject;
|
slicerWorker.onerror = reject;
|
||||||
|
|
||||||
|
// listen to messages send from worker
|
||||||
slicerWorker.addEventListener('message', (event) => {
|
slicerWorker.addEventListener('message', (event) => {
|
||||||
const { message, data } = event.data;
|
const { message, data } = event.data;
|
||||||
switch (message) {
|
switch (message) {
|
||||||
@ -54,6 +55,8 @@ export default class {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// send geometry and settings to worker to start the slicing progress
|
||||||
|
const geometry = this.geometry.toJSON();
|
||||||
slicerWorker.postMessage({
|
slicerWorker.postMessage({
|
||||||
message: 'SLICE',
|
message: 'SLICE',
|
||||||
data: { geometry, settings }
|
data: { geometry, settings }
|
||||||
|
@ -26,8 +26,8 @@ export default function generateInfills(slices, settings) {
|
|||||||
|
|
||||||
let surroundingLayer;
|
let surroundingLayer;
|
||||||
if (layer - bottomSkinCount >= 0 && layer + topSkinCount < slices.length) {
|
if (layer - bottomSkinCount >= 0 && layer + topSkinCount < slices.length) {
|
||||||
const downSkin = slices[layer - bottomSkinCount].getOutline();
|
const downSkin = slices[layer - bottomSkinCount].outline;
|
||||||
const upSkin = slices[layer + topSkinCount].getOutline();
|
const upSkin = slices[layer + topSkinCount].outline;
|
||||||
surroundingLayer = upSkin.intersect(downSkin);
|
surroundingLayer = upSkin.intersect(downSkin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
src/sliceActions/generateOutlines.js
Normal file
12
src/sliceActions/generateOutlines.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
import Shape from 'Doodle3D/clipper-js';
|
||||||
|
|
||||||
|
export default function calculateOutlines(slices, settings) {
|
||||||
|
for (let layer = 0; layer < slices.length; layer ++) {
|
||||||
|
const slice = slices[layer];
|
||||||
|
|
||||||
|
slice.outline = slice.parts.reduce((shape, part) => {
|
||||||
|
if (part.outerLine) shape.join(part.outerLine);
|
||||||
|
return shape;
|
||||||
|
}, new Shape([], true));
|
||||||
|
}
|
||||||
|
}
|
@ -30,7 +30,7 @@ export default function generateSupport(slices, settings) {
|
|||||||
if (supportAreas.length > 0) {
|
if (supportAreas.length > 0) {
|
||||||
|
|
||||||
if (layer >= supportDistanceLayers) {
|
if (layer >= supportDistanceLayers) {
|
||||||
var sliceSkin = slices[layer - supportDistanceLayers].getOutline();
|
var sliceSkin = slices[layer - supportDistanceLayers].outline;
|
||||||
sliceSkin = sliceSkin;
|
sliceSkin = sliceSkin;
|
||||||
|
|
||||||
var supportAreasSlimmed = supportAreas.difference(sliceSkin.offset(supportMargin));
|
var supportAreasSlimmed = supportAreas.difference(sliceSkin.offset(supportMargin));
|
||||||
@ -52,7 +52,7 @@ export default function generateSupport(slices, settings) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var supportSkin = slices[layer + supportDistanceLayers - 1].getOutline();
|
var supportSkin = slices[layer + supportDistanceLayers - 1].outline;
|
||||||
|
|
||||||
var slice = slices[layer + supportDistanceLayers];
|
var slice = slices[layer + supportDistanceLayers];
|
||||||
for (var i = 0; i < slice.parts.length; i ++) {
|
for (var i = 0; i < slice.parts.length; i ++) {
|
||||||
|
@ -4,12 +4,6 @@ export default class {
|
|||||||
constructor() {
|
constructor() {
|
||||||
this.parts = [];
|
this.parts = [];
|
||||||
}
|
}
|
||||||
getOutline() {
|
|
||||||
return this.parts.reduce((shape, part) => {
|
|
||||||
if (part.outerLine) shape.join(part.outerLine);
|
|
||||||
return shape;
|
|
||||||
}, new Shape([], true));
|
|
||||||
}
|
|
||||||
add(shape) {
|
add(shape) {
|
||||||
const part = { shape };
|
const part = { shape };
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ import calculateLayersIntersections from './calculateLayersIntersections.js';
|
|||||||
import createLines from './createLines.js';
|
import createLines from './createLines.js';
|
||||||
import generateInfills from './generateInfills.js';
|
import generateInfills from './generateInfills.js';
|
||||||
import generateInnerLines from './generateInnerLines.js';
|
import generateInnerLines from './generateInnerLines.js';
|
||||||
|
import generateOutlines from './generateOutlines.js';
|
||||||
import generateSupport from './generateSupport.js';
|
import generateSupport from './generateSupport.js';
|
||||||
import intersectionsToShapes from './intersectionsToShapes.js';
|
import intersectionsToShapes from './intersectionsToShapes.js';
|
||||||
import addBrim from './addBrim.js';
|
import addBrim from './addBrim.js';
|
||||||
@ -13,7 +14,7 @@ import applyPrecision from './applyPrecision.js';
|
|||||||
import removePrecision from './removePrecision.js';
|
import removePrecision from './removePrecision.js';
|
||||||
|
|
||||||
export default function(geometry, settings, onProgress) {
|
export default function(geometry, settings, onProgress) {
|
||||||
const totalStages = 11;
|
const totalStages = 12;
|
||||||
let current = -1;
|
let current = -1;
|
||||||
const updateProgress = (action) => {
|
const updateProgress = (action) => {
|
||||||
current ++;
|
current ++;
|
||||||
@ -27,7 +28,7 @@ export default function(geometry, settings, onProgress) {
|
|||||||
const lines = createLines(geometry, settings);
|
const lines = createLines(geometry, settings);
|
||||||
|
|
||||||
updateProgress('Detecting open vs closed shapes');
|
updateProgress('Detecting open vs closed shapes');
|
||||||
const openClosed = detectOpenClosed(lines);
|
detectOpenClosed(lines);
|
||||||
|
|
||||||
updateProgress('Calculating layer intersections');
|
updateProgress('Calculating layer intersections');
|
||||||
const {
|
const {
|
||||||
@ -45,6 +46,8 @@ export default function(geometry, settings, onProgress) {
|
|||||||
|
|
||||||
updateProgress('Generating inner lines');
|
updateProgress('Generating inner lines');
|
||||||
generateInnerLines(slices, settings);
|
generateInnerLines(slices, settings);
|
||||||
|
updateProgress('Generating out lines');
|
||||||
|
generateOutlines(slices, settings);
|
||||||
updateProgress('Generating infills');
|
updateProgress('Generating infills');
|
||||||
generateInfills(slices, settings);
|
generateInfills(slices, settings);
|
||||||
updateProgress('Generating support');
|
updateProgress('Generating support');
|
||||||
|
@ -16,7 +16,7 @@ self.addEventListener('message', (event) => {
|
|||||||
case 'SLICE': {
|
case 'SLICE': {
|
||||||
const { geometry: JSONGeometry, settings } = data;
|
const { geometry: JSONGeometry, settings } = data;
|
||||||
|
|
||||||
const { geometry } = new loader.parse(JSONGeometry.data);
|
const { geometry } = loader.parse(JSONGeometry.data);
|
||||||
|
|
||||||
const gcode = slice(geometry, settings, onProgress);
|
const gcode = slice(geometry, settings, onProgress);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user