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