mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-11-19 04:27:55 +01:00
move scale up and scale down to separate function
This commit is contained in:
parent
492a09cce9
commit
d60c2d46d0
22
src/sliceActions/applyPrecision.js
Normal file
22
src/sliceActions/applyPrecision.js
Normal file
@ -0,0 +1,22 @@
|
||||
import { PRECISION } from '../constants.js'
|
||||
|
||||
export default function applyPrecision(shapes) {
|
||||
for (let i = 0; i < shapes.length; i ++) {
|
||||
const { closedShapes, openShapes } = shapes[i];
|
||||
|
||||
scaleUpShape(closedShapes);
|
||||
scaleUpShape(openShapes);
|
||||
}
|
||||
}
|
||||
|
||||
function scaleUpShape(shape) {
|
||||
for (let i = 0; i < shape.length; i ++) {
|
||||
const path = shape[i];
|
||||
|
||||
for (let i = 0; i < path.length; i ++) {
|
||||
const point = path[i];
|
||||
|
||||
point.copy(point.divideScalar(PRECISION));
|
||||
}
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ export default function generateInnerLines(slices, settings) {
|
||||
|
||||
if (!part.shape.closed) continue;
|
||||
|
||||
const outerLine = part.shape.scaleDown(PRECISION).offset(-nozzleRadius, offsetOptions);
|
||||
const outerLine = part.shape.offset(-nozzleRadius, offsetOptions);
|
||||
|
||||
if (outerLine.paths.length > 0) {
|
||||
part.outerLine.join(outerLine);
|
||||
|
@ -1,35 +1,15 @@
|
||||
import THREE from 'three.js';
|
||||
import { PRECISION } from '../constants.js';
|
||||
|
||||
|
||||
export default function optimizePaths(slices, settings) {
|
||||
console.log("opimize paths");
|
||||
console.log('opimize paths');
|
||||
|
||||
const start = new THREE.Vector2(0, 0);
|
||||
|
||||
for (let layer = 0; layer < slices.length; layer ++) {
|
||||
const slice = slices[layer];
|
||||
|
||||
// start = slice.optimizePaths(start);
|
||||
const end = slice.optimizePaths(start);
|
||||
|
||||
for (let i = 0; i < slice.parts.length; i ++) {
|
||||
const part = slice.parts[i];
|
||||
|
||||
if (part.shape.closed) {
|
||||
part.outerLine.scaleDown(1 / PRECISION);
|
||||
for (let i = 0; i < part.innerLines.length; i ++) {
|
||||
const innerLine = part.innerLines[i];
|
||||
innerLine.scaleDown(1 / PRECISION);
|
||||
}
|
||||
part.fill.scaleDown(1 / PRECISION);
|
||||
}
|
||||
}
|
||||
|
||||
if (slice.support !== undefined) {
|
||||
slice.support.scaleDown(1 / PRECISION);
|
||||
}
|
||||
if (slice.brim !== undefined) {
|
||||
slice.brim.scaleDown(1 / PRECISION);
|
||||
}
|
||||
start.copy(end);
|
||||
}
|
||||
}
|
||||
|
32
src/sliceActions/removePrecision.js
Normal file
32
src/sliceActions/removePrecision.js
Normal file
@ -0,0 +1,32 @@
|
||||
import THREE from 'three.js';
|
||||
import { PRECISION } from '../constants.js';
|
||||
|
||||
export default function removePrecision(slices) {
|
||||
console.log('opimize paths');
|
||||
|
||||
const start = new THREE.Vector2(0, 0);
|
||||
|
||||
for (let layer = 0; layer < slices.length; layer ++) {
|
||||
const slice = slices[layer];
|
||||
|
||||
for (let i = 0; i < slice.parts.length; i ++) {
|
||||
const part = slice.parts[i];
|
||||
|
||||
if (part.shape.closed) {
|
||||
part.outerLine.scaleDown(1 / PRECISION);
|
||||
for (let i = 0; i < part.innerLines.length; i ++) {
|
||||
const innerLine = part.innerLines[i];
|
||||
innerLine.scaleDown(1 / PRECISION);
|
||||
}
|
||||
part.fill.scaleDown(1 / PRECISION);
|
||||
}
|
||||
}
|
||||
|
||||
if (slice.support !== undefined) {
|
||||
slice.support.scaleDown(1 / PRECISION);
|
||||
}
|
||||
if (slice.brim !== undefined) {
|
||||
slice.brim.scaleDown(1 / PRECISION);
|
||||
}
|
||||
}
|
||||
}
|
@ -10,6 +10,8 @@ import addBrim from './sliceActions/addBrim.js';
|
||||
import optimizePaths from './sliceActions/optimizePaths.js';
|
||||
import shapesToSlices from './sliceActions/shapesToSlices.js';
|
||||
import slicesToGCode from './sliceActions/slicesToGCode.js';
|
||||
import applyPrecision from './sliceActions/applyPrecision.js';
|
||||
import removePrecision from './sliceActions/removePrecision.js';
|
||||
|
||||
export default class extends EventDispatcher {
|
||||
constructor () {
|
||||
@ -79,6 +81,8 @@ export default class extends EventDispatcher {
|
||||
this.progress.sliced = true;
|
||||
this._updateProgress(settings);
|
||||
|
||||
applyPrecision(shapes);
|
||||
|
||||
const slices = shapesToSlices(shapes, settings);
|
||||
this.progress.generatedSlices = true;
|
||||
this._updateProgress(settings);
|
||||
@ -103,6 +107,8 @@ export default class extends EventDispatcher {
|
||||
this.progress.optimizedPaths = true;
|
||||
this._updateProgress(settings);
|
||||
|
||||
removePrecision(slices);
|
||||
|
||||
var gcode = slicesToGCode(slices, settings);
|
||||
this.progress.generatedGCode = true;
|
||||
this._updateProgress(settings);
|
||||
|
Loading…
Reference in New Issue
Block a user