mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-11-25 06:57:58 +01:00
don't use three.js in worker
This commit is contained in:
parent
c927c7bec1
commit
6a63077b55
@ -1,4 +1,3 @@
|
||||
import * as THREE from 'three';
|
||||
import { normalize } from './helpers/VectorUtils.js';
|
||||
|
||||
function addLine(geometry, lineLookup, lines, a, b, faceIndex) {
|
||||
@ -9,7 +8,7 @@ function addLine(geometry, lineLookup, lines, a, b, faceIndex) {
|
||||
index = lines.length;
|
||||
lineLookup[`${a}_${b}`] = index;
|
||||
|
||||
const line = new THREE.Line3(geometry.vertices[a], geometry.vertices[b]);
|
||||
const line = { start: geometry.vertices[a], end: geometry.vertices[b] };
|
||||
const faces = [];
|
||||
lines.push({ line, faces });
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import * as THREE from 'three';
|
||||
import { divide, distanceTo } from './VectorUtils.js';
|
||||
import { PRECISION, VERSION } from '../../constants.js';
|
||||
|
||||
export const MOVE = 'G';
|
||||
@ -20,7 +20,7 @@ export default class {
|
||||
this._nozzleToFilamentRatio = 1;
|
||||
this._gcode = [`; Generated with Doodle3D Slicer V${VERSION}`];
|
||||
this._currentValues = {};
|
||||
this._nozzlePosition = new THREE.Vector2(0, 0);
|
||||
this._nozzlePosition = { x: 0, y: 0 };
|
||||
this._extruder = 0.0;
|
||||
this._duration = 0.0;
|
||||
this._isRetracted = false;
|
||||
@ -57,8 +57,8 @@ export default class {
|
||||
}
|
||||
|
||||
moveTo(x, y, z, { speed }) {
|
||||
const newNozzlePosition = new THREE.Vector2(x, y).multiplyScalar(PRECISION);
|
||||
const lineLength = this._nozzlePosition.distanceTo(newNozzlePosition);
|
||||
const newNozzlePosition = divide({ x, y }, PRECISION_INVERSE);
|
||||
const lineLength = distanceTo(this._nozzlePosition, newNozzlePosition);
|
||||
|
||||
this._duration += lineLength / speed;
|
||||
|
||||
@ -70,14 +70,14 @@ export default class {
|
||||
[SPEED]: toFixedTrimmed(speed * 60)
|
||||
});
|
||||
|
||||
this._nozzlePosition.copy(newNozzlePosition);
|
||||
this._nozzlePosition = newNozzlePosition;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
lineTo(x, y, z, { speed, flowRate }) {
|
||||
const newNozzlePosition = new THREE.Vector2(x, y).multiplyScalar(PRECISION);
|
||||
const lineLength = this._nozzlePosition.distanceTo(newNozzlePosition);
|
||||
const newNozzlePosition = divide({ x, y }, PRECISION_INVERSE);
|
||||
const lineLength = distanceTo(this._nozzlePosition, newNozzlePosition);
|
||||
|
||||
this._extruder += this._nozzleToFilamentRatio * lineLength * flowRate;
|
||||
this._duration += lineLength / speed;
|
||||
@ -91,7 +91,7 @@ export default class {
|
||||
[EXTRUDER]: toFixedTrimmed(this._extruder)
|
||||
});
|
||||
|
||||
this._nozzlePosition.copy(newNozzlePosition);
|
||||
this._nozzlePosition = newNozzlePosition;
|
||||
|
||||
return this;
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
import * as THREE from 'three';
|
||||
import { length, distanceTo } from './helpers/VectorUtils.js';
|
||||
import Shape from 'clipper-js';
|
||||
|
||||
export default function optimizePaths(slices, settings) {
|
||||
const start = new THREE.Vector2(0, 0);
|
||||
let start = { x: 0, y: 0 };
|
||||
|
||||
for (let layer = 0; layer < slices.length; layer ++) {
|
||||
const slice = slices[layer];
|
||||
|
||||
if (typeof slice.brim !== 'undefined' && slice.brim.paths.length > 0) {
|
||||
slice.brim = optimizeShape(slice.brim, start);
|
||||
start.copy(slice.brim.lastPoint(true));
|
||||
start = slice.brim.lastPoint(true);
|
||||
}
|
||||
|
||||
const parts = [];
|
||||
@ -54,21 +54,21 @@ export default function optimizePaths(slices, settings) {
|
||||
if (shell.paths.length === 0) continue;
|
||||
|
||||
part.shell[i] = optimizeShape(shell, start);
|
||||
start.copy(part.shell[i].lastPoint(true));
|
||||
start = part.shell[i].lastPoint(true);
|
||||
}
|
||||
|
||||
if (part.outerFill.paths.length > 0) {
|
||||
part.outerFill = optimizeShape(part.outerFill, start);
|
||||
start.copy(part.outerFill.lastPoint(true));
|
||||
start = part.outerFill.lastPoint(true);
|
||||
}
|
||||
|
||||
if (part.innerFill.paths.length > 0) {
|
||||
part.innerFill = optimizeShape(part.innerFill, start);
|
||||
start.copy(part.innerFill.lastPoint(true));
|
||||
start = part.innerFill.lastPoint(true);
|
||||
}
|
||||
} else {
|
||||
part.shape = optimizeShape(part.shape, start);
|
||||
start.copy(part.shape.lastPoint(true));
|
||||
start = part.shape.lastPoint(true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -76,14 +76,12 @@ export default function optimizePaths(slices, settings) {
|
||||
|
||||
if (typeof slice.support !== 'undefined' && slice.support.paths.length > 0) {
|
||||
slice.support = optimizeShape(slice.support, start);
|
||||
start.copy(slice.support.lastPoint(true));
|
||||
start = slice.support.lastPoint(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function optimizeShape(shape, start) {
|
||||
start = start.clone();
|
||||
|
||||
const inputPaths = shape.mapToLower();
|
||||
const optimizedPaths = [];
|
||||
const donePaths = [];
|
||||
@ -102,8 +100,7 @@ function optimizeShape(shape, start) {
|
||||
|
||||
if (shape.closed) {
|
||||
for (let j = 0; j < path.length; j += 1) {
|
||||
const point = new THREE.Vector2().copy(path[j]);
|
||||
const length = point.sub(start).length();
|
||||
const length = distanceTo(path[j], start);
|
||||
if (minLength === false || length < minLength) {
|
||||
minPath = path;
|
||||
minLength = length;
|
||||
@ -112,8 +109,7 @@ function optimizeShape(shape, start) {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const startPoint = new THREE.Vector2().copy(path[0]);
|
||||
const lengthToStart = startPoint.sub(start).length();
|
||||
const lengthToStart = distanceTo(path[0], start);
|
||||
if (minLength === false || lengthToStart < minLength) {
|
||||
minPath = path;
|
||||
minLength = lengthToStart;
|
||||
@ -121,8 +117,7 @@ function optimizeShape(shape, start) {
|
||||
pathIndex = i;
|
||||
}
|
||||
|
||||
const endPoint = new THREE.Vector2().copy(path[path.length - 1]);
|
||||
const lengthToEnd = endPoint.sub(start).length();
|
||||
const lengthToEnd = distanceTo(path[path.length - 1], start);
|
||||
if (lengthToEnd < minLength) {
|
||||
minPath = path;
|
||||
minLength = lengthToEnd;
|
||||
@ -132,20 +127,15 @@ function optimizeShape(shape, start) {
|
||||
}
|
||||
}
|
||||
|
||||
let point;
|
||||
if (shape.closed) {
|
||||
minPath = minPath.concat(minPath.splice(0, offset));
|
||||
point = minPath[0];
|
||||
start = minPath[0];
|
||||
} else {
|
||||
if (reverse) {
|
||||
minPath.reverse();
|
||||
}
|
||||
point = minPath[minPath.length - 1];
|
||||
if (reverse) minPath.reverse();
|
||||
start = minPath[minPath.length - 1];
|
||||
}
|
||||
|
||||
donePaths.push(pathIndex);
|
||||
start.copy(point);
|
||||
|
||||
optimizedPaths.push(minPath);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import GCode from './helpers/GCode.js';
|
||||
import comb from './helpers/comb.js';
|
||||
import { divide } from './helpers/VectorUtils.js';
|
||||
import { PRECISION, Z_OFFSET } from '../constants.js';
|
||||
|
||||
const PROFILE_TYPES = ['support', 'innerShell', 'outerShell', 'innerInfill', 'outerInfill', 'brim'];
|
||||
@ -94,7 +95,7 @@ function pathToGCode(outline, combing, gcode, shape, retract, unRetract, z, { li
|
||||
|
||||
if (i === 0) {
|
||||
if (combing) {
|
||||
const combPath = comb(outline, gcode._nozzlePosition.divideScalar(PRECISION), point);
|
||||
const combPath = comb(outline, divide(gcode._nozzlePosition, PRECISION), point);
|
||||
for (let i = 0; i < combPath.length; i ++) {
|
||||
const combPoint = combPath[i];
|
||||
gcode.moveTo(combPoint.x, combPoint.y, z, travelProfile);
|
||||
|
Loading…
Reference in New Issue
Block a user