mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-12-23 03:23:48 +01:00
remove settings from gcode class
This commit is contained in:
parent
34f6a91db9
commit
bcf62c71ec
@ -10,16 +10,15 @@ const POSITION_Y = 'Y';
|
||||
const POSITION_Z = 'Z';
|
||||
|
||||
export default class {
|
||||
constructor(settings) {
|
||||
constructor(nozzleToFilamentRatio) {
|
||||
this._nozzleToFilamentRatio = nozzleToFilamentRatio;
|
||||
|
||||
this._gcode = '';
|
||||
this._currentValues = {};
|
||||
this._settings = settings;
|
||||
this._nozzlePosition = new THREE.Vector2(0, 0);
|
||||
this._extruder = 0.0;
|
||||
this._isRetracted = false;
|
||||
this._isFanOn = false;
|
||||
|
||||
this.bottom = true;
|
||||
}
|
||||
|
||||
_addGCode(command) {
|
||||
@ -62,14 +61,8 @@ export default class {
|
||||
return this;
|
||||
}
|
||||
|
||||
moveTo(x, y, layer) {
|
||||
const {
|
||||
layerHeight,
|
||||
travelSpeed
|
||||
} = this._settings;
|
||||
|
||||
const z = layer * layerHeight + 0.2;
|
||||
const speed = travelSpeed * 60;
|
||||
moveTo(x, y, z, { speed }) {
|
||||
speed *= 60;
|
||||
|
||||
this._addGCode({
|
||||
[MOVE]: 0,
|
||||
@ -84,30 +77,13 @@ export default class {
|
||||
return this;
|
||||
}
|
||||
|
||||
lineTo(x, y, layer, type) {
|
||||
lineTo(x, y, z, { speed, flowRate }) {
|
||||
const newNozzlePosition = new THREE.Vector2(x, y);
|
||||
|
||||
const {
|
||||
layerHeight,
|
||||
nozzleDiameter,
|
||||
filamentThickness,
|
||||
travelSpeed
|
||||
} = this._settings;
|
||||
|
||||
const profile = this._settings[(this.bottom ? 'bottom' : type)];
|
||||
|
||||
let {
|
||||
speed,
|
||||
flowRate
|
||||
} = profile;
|
||||
|
||||
speed *= 60;
|
||||
const z = layer * layerHeight + 0.2;
|
||||
|
||||
const lineLength = this._nozzlePosition.distanceTo(newNozzlePosition);
|
||||
|
||||
const filamentSurfaceArea = Math.pow((filamentThickness / 2), 2) * Math.PI;
|
||||
this._extruder += lineLength * nozzleDiameter * layerHeight / filamentSurfaceArea * flowRate;
|
||||
this._extruder += this._nozzleToFilamentRatio * lineLength * flowRate;
|
||||
|
||||
this._addGCode({
|
||||
[MOVE]: 1,
|
||||
@ -123,16 +99,8 @@ export default class {
|
||||
return this;
|
||||
}
|
||||
|
||||
unRetract() {
|
||||
const {
|
||||
retraction: {
|
||||
enabled: retractionEnabled,
|
||||
minDistance: retractionMinDistance,
|
||||
speed: retractionSpeed
|
||||
}
|
||||
} = this._settings;
|
||||
|
||||
if (this._isRetracted && retractionEnabled) {
|
||||
unRetract({ enabled, speed, minDistance }) {
|
||||
if (this._isRetracted && enabled) {
|
||||
this._isRetracted = false;
|
||||
|
||||
const speed = retractionSpeed * 60;
|
||||
@ -149,17 +117,8 @@ export default class {
|
||||
return this;
|
||||
}
|
||||
|
||||
retract() {
|
||||
const {
|
||||
retraction: {
|
||||
amount: retractionAmount,
|
||||
enabled: retractionEnabled,
|
||||
minDistance: retractionMinDistance,
|
||||
speed: retractionSpeed
|
||||
}
|
||||
} = this._settings;
|
||||
|
||||
if (!this._isRetracted && retractionEnabled) {
|
||||
retract({ enabled, speed, minDistance }) {
|
||||
if (!this._isRetracted && enabled) {
|
||||
this._isRetracted = true;
|
||||
|
||||
const speed = retractionSpeed * 60;
|
||||
|
@ -1,47 +1,82 @@
|
||||
import GCode from './helpers/GCode.js';
|
||||
|
||||
export default function slicesToGCode(slices, settings) {
|
||||
const gcode = new GCode(settings);
|
||||
const PROFILE_TYPES = ['brim', 'outerLine', 'innerLine', 'fill', 'support'];
|
||||
|
||||
export default function slicesToGCode(slices, settings) {
|
||||
const {
|
||||
layerHeight,
|
||||
filamentThickness,
|
||||
nozzleDiameter,
|
||||
travelSpeed,
|
||||
retraction,
|
||||
retractionEnabled
|
||||
} = settings;
|
||||
|
||||
const filamentSurfaceArea = Math.pow((filamentThickness / 2), 2) * Math.PI;
|
||||
const lineSurfaceArea = nozzleDiameter * layerHeight;
|
||||
const nozzleToFilamentRatio = lineSurfaceArea / filamentSurfaceArea;
|
||||
|
||||
const gcode = new GCode(nozzleToFilamentRatio);
|
||||
|
||||
const defaultProfile = {
|
||||
travelProfile: {
|
||||
speed: travelSpeed
|
||||
},
|
||||
retractProfile: {
|
||||
...retraction,
|
||||
enabled: retractionEnabled
|
||||
}
|
||||
};
|
||||
|
||||
let isBottom = true;
|
||||
for (let layer = 0; layer < slices.length; layer ++) {
|
||||
const slice = slices[layer];
|
||||
const z = layer * layerHeight + 0.2;
|
||||
|
||||
if (layer === 1) {
|
||||
gcode.turnFanOn();
|
||||
gcode.bottom = false;
|
||||
isBottom = false;
|
||||
}
|
||||
|
||||
const profiles = PROFILE_TYPES.reduce((profiles, profileType) => {
|
||||
profiles[profileType] = {
|
||||
...defaultProfile,
|
||||
lineProfile: isBottom ? settings.bottom : settings[profileType]
|
||||
}
|
||||
return profiles;
|
||||
}, {});
|
||||
|
||||
if (typeof slice.brim !== 'undefined') {
|
||||
pathToGCode(gcode, slice.brim, true, true, layer, 'brim');
|
||||
pathToGCode(gcode, slice.brim, true, true, z, profiles.brim);
|
||||
}
|
||||
|
||||
for (let i = 0; i < slice.parts.length; i ++) {
|
||||
const part = slice.parts[i];
|
||||
|
||||
if (part.shape.closed) {
|
||||
pathToGCode(gcode, part.outerLine, false, true, layer, 'outerLine');
|
||||
pathToGCode(gcode, part.outerLine, false, true, profiles.outerLine);
|
||||
|
||||
for (let i = 0; i < part.innerLines.length; i ++) {
|
||||
const innerLine = part.innerLines[i];
|
||||
pathToGCode(gcode, innerLine, false, false, layer, 'innerLine');
|
||||
pathToGCode(gcode, innerLine, false, false, z, profiles.innerLine);
|
||||
}
|
||||
|
||||
pathToGCode(gcode, part.fill, true, false, layer, 'fill');
|
||||
pathToGCode(gcode, part.fill, true, false, z, profiles.fill);
|
||||
} else {
|
||||
const retract = !(slice.parts.length === 1 && typeof slice.support === 'undefined');
|
||||
pathToGCode(gcode, part.shape, retract, retract, layer, 'outerLine');
|
||||
pathToGCode(gcode, part.shape, retract, retract, z, profiles.outerLine);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof slice.support !== 'undefined') {
|
||||
pathToGCode(gcode, slice.support, true, true, layer, 'support');
|
||||
pathToGCode(gcode, slice.support, true, true, z, profiles.support);
|
||||
}
|
||||
}
|
||||
|
||||
return gcode.getGCode();
|
||||
}
|
||||
|
||||
function pathToGCode(gcode, shape, retract, unRetract, layer, type) {
|
||||
function pathToGCode(gcode, shape, retract, unRetract, z, { lineProfile, travelProfile, retractProfile }) {
|
||||
const { closed } = shape;
|
||||
const paths = shape.mapToLower();
|
||||
|
||||
@ -55,18 +90,18 @@ function pathToGCode(gcode, shape, retract, unRetract, layer, type) {
|
||||
if (i === 0) {
|
||||
// TODO
|
||||
// moveTo should impliment combing
|
||||
gcode.moveTo(point.x, point.y, layer);
|
||||
gcode.moveTo(point.x, point.y, z, travelProfile);
|
||||
|
||||
if (unRetract) {
|
||||
gcode.unRetract();
|
||||
gcode.unRetract(retractProfile);
|
||||
}
|
||||
} else {
|
||||
gcode.lineTo(point.x, point.y, layer, type);
|
||||
gcode.lineTo(point.x, point.y, z, lineProfile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (retract) {
|
||||
gcode.retract();
|
||||
gcode.retract(retractProfile);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user