mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-12-23 19:43:48 +01:00
clean up
This commit is contained in:
parent
ef97f362e3
commit
f4b9d565a7
47
src/GCode.js
47
src/GCode.js
@ -1,6 +1,6 @@
|
|||||||
import * as THREE from 'three.js';
|
import * as THREE from 'three.js';
|
||||||
|
|
||||||
const G_COMMAND = 'G';
|
const MOVE = 'G';
|
||||||
const M_COMMAND = 'M';
|
const M_COMMAND = 'M';
|
||||||
const FAN_SPEED = 'S';
|
const FAN_SPEED = 'S';
|
||||||
const SPEED = 'F';
|
const SPEED = 'F';
|
||||||
@ -11,8 +11,9 @@ const POSITION_Z = 'Z';
|
|||||||
|
|
||||||
export default class {
|
export default class {
|
||||||
constructor(settings) {
|
constructor(settings) {
|
||||||
this.gcode = '';
|
this._gcode = '';
|
||||||
this.current = {};
|
this._currentValues = {};
|
||||||
|
this._settings = settings;
|
||||||
|
|
||||||
this.extruder = 0.0;
|
this.extruder = 0.0;
|
||||||
this.bottom = true;
|
this.bottom = true;
|
||||||
@ -20,18 +21,16 @@ export default class {
|
|||||||
this.isFanOn = false;
|
this.isFanOn = false;
|
||||||
this._nozzlePosition = new THREE.Vector2(0, 0);
|
this._nozzlePosition = new THREE.Vector2(0, 0);
|
||||||
|
|
||||||
if (settings !== undefined) {
|
if (typeof settings !== 'undefined') this.setSettings(settings);
|
||||||
this.setSettings(settings);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_addGCode(command) {
|
_addGCode(command) {
|
||||||
let str = '';
|
let str = '';
|
||||||
let first = true;
|
|
||||||
|
|
||||||
|
let first = true;
|
||||||
for (const action in command) {
|
for (const action in command) {
|
||||||
const value = command[action];
|
const value = command[action];
|
||||||
const currentValue = this.current[action];
|
const currentValue = this._currentAValues[action];
|
||||||
if (first) {
|
if (first) {
|
||||||
str = action + value;
|
str = action + value;
|
||||||
|
|
||||||
@ -39,24 +38,18 @@ export default class {
|
|||||||
} else if (currentValue !== value) {
|
} else if (currentValue !== value) {
|
||||||
str += ` ${action}${value}`;
|
str += ` ${action}${value}`;
|
||||||
|
|
||||||
this.current[action] = value;
|
this._currentAcValues[action] = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.gcode += `${str}\n`;
|
this._gcode += `${str}\n`;
|
||||||
}
|
|
||||||
|
|
||||||
setSettings(settings) {
|
|
||||||
this.settings = settings;
|
|
||||||
|
|
||||||
return this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
turnFanOn(fanSpeed) {
|
turnFanOn(fanSpeed) {
|
||||||
this.isFanOn = true;
|
this.isFanOn = true;
|
||||||
|
|
||||||
const gcode = { [M_COMMAND]: 106 }
|
const gcode = { [M_COMMAND]: 106 }
|
||||||
if (fanSpeed !== undefined) gcode[FAN_SPEED] = fanSpeed;
|
if (typeof fanSpeed !== 'undefined') gcode[FAN_SPEED] = fanSpeed;
|
||||||
|
|
||||||
this._addGCode(gcode);
|
this._addGCode(gcode);
|
||||||
|
|
||||||
@ -75,13 +68,13 @@ export default class {
|
|||||||
const {
|
const {
|
||||||
layerHeight,
|
layerHeight,
|
||||||
travelSpeed
|
travelSpeed
|
||||||
} = this.settings.config;
|
} = this._settings.config;
|
||||||
|
|
||||||
const z = layer * layerHeight + 0.2;
|
const z = layer * layerHeight + 0.2;
|
||||||
const speed = travelSpeed * 60;
|
const speed = travelSpeed * 60;
|
||||||
|
|
||||||
this._addGCode({
|
this._addGCode({
|
||||||
[G_COMMAND]: 0,
|
[MOVE]: 0,
|
||||||
[POSITION_X]: x.toFixed(3),
|
[POSITION_X]: x.toFixed(3),
|
||||||
[POSITION_Y]: y.toFixed(3),
|
[POSITION_Y]: y.toFixed(3),
|
||||||
[POSITION_Z]: z.toFixed(3),
|
[POSITION_Z]: z.toFixed(3),
|
||||||
@ -101,9 +94,9 @@ export default class {
|
|||||||
nozzleDiameter,
|
nozzleDiameter,
|
||||||
filamentThickness,
|
filamentThickness,
|
||||||
travelSpeed
|
travelSpeed
|
||||||
} = this.settings.config;
|
} = this._settings.config;
|
||||||
|
|
||||||
const profile = this.settings.config[(this.bottom ? 'bottom' : type)];
|
const profile = this._settings.config[(this.bottom ? 'bottom' : type)];
|
||||||
|
|
||||||
let {
|
let {
|
||||||
speed,
|
speed,
|
||||||
@ -119,7 +112,7 @@ export default class {
|
|||||||
this.extruder += lineLength * nozzleDiameter * layerHeight / filamentSurfaceArea * flowRate;
|
this.extruder += lineLength * nozzleDiameter * layerHeight / filamentSurfaceArea * flowRate;
|
||||||
|
|
||||||
this._addGCode({
|
this._addGCode({
|
||||||
[G_COMMAND]: 1,
|
[MOVE]: 1,
|
||||||
[POSITION_X]: x.toFixed(3),
|
[POSITION_X]: x.toFixed(3),
|
||||||
[POSITION_Y]: y.toFixed(3),
|
[POSITION_Y]: y.toFixed(3),
|
||||||
[POSITION_Z]: z.toFixed(3),
|
[POSITION_Z]: z.toFixed(3),
|
||||||
@ -137,7 +130,7 @@ export default class {
|
|||||||
retractionEnabled,
|
retractionEnabled,
|
||||||
retractionMinDistance,
|
retractionMinDistance,
|
||||||
retractionSpeed
|
retractionSpeed
|
||||||
} = this.settings.config;
|
} = this._settings.config;
|
||||||
|
|
||||||
if (this.isRetracted && retractionEnabled) {
|
if (this.isRetracted && retractionEnabled) {
|
||||||
this.isRetracted = false;
|
this.isRetracted = false;
|
||||||
@ -146,7 +139,7 @@ export default class {
|
|||||||
|
|
||||||
if (this.extruder > retractionMinDistance) {
|
if (this.extruder > retractionMinDistance) {
|
||||||
this._addGCode({
|
this._addGCode({
|
||||||
[G_COMMAND]: 0,
|
[MOVE]: 0,
|
||||||
[EXTRUDER]: this.extruder.toFixed(3),
|
[EXTRUDER]: this.extruder.toFixed(3),
|
||||||
[SPEED]: speed.toFixed(3)
|
[SPEED]: speed.toFixed(3)
|
||||||
});
|
});
|
||||||
@ -162,7 +155,7 @@ export default class {
|
|||||||
retractionEnabled,
|
retractionEnabled,
|
||||||
retractionMinDistance,
|
retractionMinDistance,
|
||||||
retractionSpeed
|
retractionSpeed
|
||||||
} = this.settings.config;
|
} = this._settings.config;
|
||||||
|
|
||||||
if (!this.isRetracted && retractionEnabled) {
|
if (!this.isRetracted && retractionEnabled) {
|
||||||
this.isRetracted = true;
|
this.isRetracted = true;
|
||||||
@ -171,7 +164,7 @@ export default class {
|
|||||||
|
|
||||||
if (this.extruder > retractionMinDistance && retractionEnabled) {
|
if (this.extruder > retractionMinDistance && retractionEnabled) {
|
||||||
this._addGCode({
|
this._addGCode({
|
||||||
[G_COMMAND]: 0,
|
[MOVE]: 0,
|
||||||
[EXTRUDER]: (this.extruder - retractionAmount).toFixed(3),
|
[EXTRUDER]: (this.extruder - retractionAmount).toFixed(3),
|
||||||
[SPEED]: speed.toFixed(3)
|
[SPEED]: speed.toFixed(3)
|
||||||
});
|
});
|
||||||
@ -182,6 +175,6 @@ export default class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getGCode() {
|
getGCode() {
|
||||||
return this.settings.startCode() + this.gcode + this.settings.endCode();
|
return this._settings.startCode() + this._gcode + this._settings.endCode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,8 @@ export default function calculateLayersIntersections(lines, settings) {
|
|||||||
|
|
||||||
const numLayers = Math.floor(dimensionsZ / layerHeight);
|
const numLayers = Math.floor(dimensionsZ / layerHeight);
|
||||||
|
|
||||||
const layerIntersectionIndexes = [];
|
const layerIntersectionIndexes = Array.from(Array(numLayers)).map(() => []);
|
||||||
const layerIntersectionPoints = [];
|
const layerIntersectionPoints = Array.from(Array(numLayers)).map(() => []);
|
||||||
for (let layer = 0; layer < numLayers; layer ++) {
|
|
||||||
layerIntersectionIndexes[layer] = [];
|
|
||||||
layerIntersectionPoints[layer] = [];
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let lineIndex = 0; lineIndex < lines.length; lineIndex ++) {
|
for (let lineIndex = 0; lineIndex < lines.length; lineIndex ++) {
|
||||||
const line = lines[lineIndex].line;
|
const line = lines[lineIndex].line;
|
||||||
|
@ -7,7 +7,8 @@ function addLine(geometry, lineLookup, lines, a, b) {
|
|||||||
lines.push({
|
lines.push({
|
||||||
line: new THREE.Line3(geometry.vertices[a], geometry.vertices[b]),
|
line: new THREE.Line3(geometry.vertices[a], geometry.vertices[b]),
|
||||||
connects: [],
|
connects: [],
|
||||||
normals: []
|
normals: [],
|
||||||
|
open: false
|
||||||
});
|
});
|
||||||
|
|
||||||
return index;
|
return index;
|
||||||
@ -46,6 +47,8 @@ export default function createLines(geometry, settings, openClosed) {
|
|||||||
lines[indexC].normals.push(normal);
|
lines[indexC].normals.push(normal);
|
||||||
|
|
||||||
lines[indexA].open = open;
|
lines[indexA].open = open;
|
||||||
|
lines[indexB].open = open;
|
||||||
|
lines[indexC].open = open;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,8 +37,7 @@ export default function generateInnerLines(slices, settings) {
|
|||||||
|
|
||||||
if (innerLine.paths.length > 0) {
|
if (innerLine.paths.length > 0) {
|
||||||
part.innerLines.push(innerLine);
|
part.innerLines.push(innerLine);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user