move scale up and scale down to separate function

This commit is contained in:
casperlamboo 2016-05-06 19:54:25 +02:00 committed by Simon Voordouw
parent 492a09cce9
commit d60c2d46d0
5 changed files with 64 additions and 24 deletions

View 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));
}
}
}

View File

@ -25,7 +25,7 @@ export default function generateInnerLines(slices, settings) {
if (!part.shape.closed) continue; 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) { if (outerLine.paths.length > 0) {
part.outerLine.join(outerLine); part.outerLine.join(outerLine);

View File

@ -1,35 +1,15 @@
import THREE from 'three.js'; import THREE from 'three.js';
import { PRECISION } from '../constants.js';
export default function optimizePaths(slices, settings) { export default function optimizePaths(slices, settings) {
console.log("opimize paths"); console.log('opimize paths');
const start = new THREE.Vector2(0, 0); const start = new THREE.Vector2(0, 0);
for (let layer = 0; layer < slices.length; layer ++) { for (let layer = 0; layer < slices.length; layer ++) {
const slice = slices[layer]; const slice = slices[layer];
// start = slice.optimizePaths(start); const end = slice.optimizePaths(start);
for (let i = 0; i < slice.parts.length; i ++) { start.copy(end);
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);
}
} }
} }

View 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);
}
}
}

View File

@ -10,6 +10,8 @@ import addBrim from './sliceActions/addBrim.js';
import optimizePaths from './sliceActions/optimizePaths.js'; import optimizePaths from './sliceActions/optimizePaths.js';
import shapesToSlices from './sliceActions/shapesToSlices.js'; import shapesToSlices from './sliceActions/shapesToSlices.js';
import slicesToGCode from './sliceActions/slicesToGCode.js'; import slicesToGCode from './sliceActions/slicesToGCode.js';
import applyPrecision from './sliceActions/applyPrecision.js';
import removePrecision from './sliceActions/removePrecision.js';
export default class extends EventDispatcher { export default class extends EventDispatcher {
constructor () { constructor () {
@ -79,6 +81,8 @@ export default class extends EventDispatcher {
this.progress.sliced = true; this.progress.sliced = true;
this._updateProgress(settings); this._updateProgress(settings);
applyPrecision(shapes);
const slices = shapesToSlices(shapes, settings); const slices = shapesToSlices(shapes, settings);
this.progress.generatedSlices = true; this.progress.generatedSlices = true;
this._updateProgress(settings); this._updateProgress(settings);
@ -103,6 +107,8 @@ export default class extends EventDispatcher {
this.progress.optimizedPaths = true; this.progress.optimizedPaths = true;
this._updateProgress(settings); this._updateProgress(settings);
removePrecision(slices);
var gcode = slicesToGCode(slices, settings); var gcode = slicesToGCode(slices, settings);
this.progress.generatedGCode = true; this.progress.generatedGCode = true;
this._updateProgress(settings); this._updateProgress(settings);