Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
casperlamboo committed Jul 28, 2017
2 parents f390f1c + 484a641 commit 48f2cef
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 182 deletions.
3 changes: 2 additions & 1 deletion simpleExample/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const settings = {
};

const geometry = new THREE.TorusGeometry(20, 10, 30, 30).clone();
geometry.mergeVertices();

const onProgress = ({ progress: { done, total, action } }) => {
const percentage = `${(done / total * 100).toFixed()}%`
Expand All @@ -17,4 +18,4 @@ const onProgress = ({ progress: { done, total, action } }) => {

sliceGeometry(settings, geometry, null, false, onProgress).then(gcode => {
document.body.innerHTML = gcode.replace(/(?:\r\n|\r|\n)/g, '<br />');
});
});
42 changes: 21 additions & 21 deletions src/settings/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,49 @@ dimensions:
x: 200
y: 200
z: 200
temperature: 210
bedTemperature: 70
# heatBedTemperature: 20
# heatTemperature: 20
# heatupEnabled: true
travelSpeed: 200.0
layerHeight: 0.15
heatedBed: false
nozzleDiameter: 0.4
filamentThickness: 2.85
temperature: 210
bedTemperature: 70
layerHeight: 0.15
thickness:
top: 1.2
bottom: 1.2
shell: 0.8
retraction:
amount: 3.0
enabled: true
amount: 3.0
speed: 50.0
minDistance: 0.0
travel:
speed: 200.0
support:
enabled: false
acceptanceMargin: 1.5
distanceY: 0.4
enabled: false
gridSize: 6.0
margin: 2.0
plateSize: 4.0
flowRate: 0.8
speed: 40.0
outerLine:
innerShell:
flowRate: 1.0
speed: 50.0
outerShell:
flowRate: 1.0
speed: 40.0
innerLine:
innerInfill:
flowRate: 1.0
speed: 50.0
fill:
speed: 80.0
gridSize: 5.0
outerInfill:
flowRate: 1.0
speed: 50.0
gridSize: 5.0
brim:
offset: 4.0
flowRate: 1.0
speed: 40.0
offset: 4.0
top:
thickness: 1.2
bottom:
firstLayer:
flowRate: 1.2
speed: 40.0
thickness: 0.4
shell:
thickness: 0.4
7 changes: 4 additions & 3 deletions src/sliceActions/applyPrecision.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { PRECISION } from '../constants.js'

export default function applyPrecision(shapes) {
for (let i = 0; i < shapes.length; i ++) {
const { closedShapes, openShapes } = shapes[i];
const { fillShapes, lineShapesOpen, lineShapesClosed } = shapes[i];

scaleUpShape(closedShapes);
scaleUpShape(openShapes);
scaleUpShape(fillShapes);
scaleUpShape(lineShapesOpen);
scaleUpShape(lineShapesClosed);
}
}

Expand Down
60 changes: 29 additions & 31 deletions src/sliceActions/generateInfills.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@ import Shape from 'clipper-js';
export default function generateInfills(slices, settings) {
let {
layerHeight,
fill: { gridSize: fillGridSize },
bottom: { thickness: bottomThickness },
top: { thickness: topThickness },
innerInfill: { gridSize: infillGridSize },
thickness: {
top: topThickness,
bottom: bottomThickness
},
nozzleDiameter
} = settings;

fillGridSize /= PRECISION;
infillGridSize /= PRECISION;
nozzleDiameter /= PRECISION;

const bottomSkinCount = Math.ceil(bottomThickness/layerHeight);
const topSkinCount = Math.ceil(topThickness/layerHeight);
const nozzleRadius = nozzleDiameter / 2;
const hightemplateSize = Math.sqrt(2 * Math.pow(nozzleDiameter, 2));
const outerFillTemplateSize = Math.sqrt(2 * Math.pow(nozzleDiameter, 2));

for (let layer = 0; layer < slices.length; layer ++) {
const slice = slices[layer];
Expand All @@ -32,39 +34,35 @@ export default function generateInfills(slices, settings) {
for (let i = 0; i < slice.parts.length; i ++) {
const part = slice.parts[i];

if (!part.shape.closed) {
continue;
}
if (!part.closed) continue;

const outerLine = part.outerLine;
const innerShell = part.shell[part.shell.length - 1];

if (outerLine.paths.length > 0) {
const inset = (part.innerLines.length > 0) ? part.innerLines[part.innerLines.length - 1] : outerLine;
if (innerShell.paths.length === 0) continue;

const fillArea = inset.offset(-nozzleRadius);
let lowFillArea;
let highFillArea;
if (surroundingLayer) {
highFillArea = fillArea.difference(surroundingLayer).intersect(fillArea);
lowFillArea = fillArea.difference(highFillArea);
} else {
highFillArea = fillArea;
}
const fillArea = innerShell.offset(-nozzleRadius);
let innerFillArea;
let outerFillArea;
if (surroundingLayer) {
outerFillArea = fillArea.difference(surroundingLayer).intersect(fillArea);
innerFillArea = fillArea.difference(outerFillArea);
} else {
outerFillArea = fillArea;
}

if (lowFillArea && lowFillArea.paths.length > 0) {
const bounds = lowFillArea.shapeBounds();
const lowFillTemplate = getFillTemplate(bounds, fillGridSize, true, true);
if (innerFillArea && innerFillArea.paths.length > 0) {
const bounds = innerFillArea.shapeBounds();
const innerFillTemplate = getFillTemplate(bounds, infillGridSize, true, true);

part.fill.join(lowFillTemplate.intersect(lowFillArea));
}
part.innerFill.join(innerFillTemplate.intersect(innerFillArea));
}

if (highFillArea.paths.length > 0) {
const bounds = highFillArea.shapeBounds();
const even = (layer % 2 === 0);
const highFillTemplate = getFillTemplate(bounds, hightemplateSize, even, !even);
if (outerFillArea.paths.length > 0) {
const bounds = outerFillArea.shapeBounds();
const even = (layer % 2 === 0);
const outerFillTemplate = getFillTemplate(bounds, outerFillTemplateSize, even, !even);

part.fill.join(highFillTemplate.intersect(highFillArea));
}
part.outerFill.join(outerFillTemplate.intersect(outerFillArea));
}
}
}
Expand Down
20 changes: 11 additions & 9 deletions src/sliceActions/generateInnerLines.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,36 @@ export default function generateInnerLines(slices, settings) {
let {
layerHeight,
nozzleDiameter,
shell: { thickness: shellThickness }
thickness: { shell: shellThickness }
} = settings;

nozzleDiameter /= PRECISION;
shellThickness /= PRECISION;

const nozzleRadius = nozzleDiameter / 2;
const shells = Math.round(shellThickness / nozzleDiameter);
const numShells = Math.round(shellThickness / nozzleDiameter);

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) continue;
if (!part.closed) continue;

const outerLine = part.shape.offset(-nozzleRadius, offsetOptions);

if (outerLine.paths.length > 0) {
part.outerLine.join(outerLine);
part.shell.push(outerLine);

// start with 1 because outerLine is the 1st (0) shell
for (let shell = 1; shell < shells; shell += 1) {
const offset = shell * nozzleDiameter;
for (let inset = 1; inset < numShells; inset += 1) {
const offset = inset * nozzleDiameter;

const innerLine = outerLine.offset(-offset, offsetOptions);
const shell = outerLine.offset(-offset, offsetOptions);

if (innerLine.paths.length > 0) {
part.innerLines.push(innerLine);
if (shell.paths.length > 0) {
part.shell.push(shell);
} else {
break;
}
Expand Down
5 changes: 4 additions & 1 deletion src/sliceActions/generateOutlines.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ export default function calculateOutlines(slices, settings) {
const slice = slices[layer];

slice.outline = slice.parts.reduce((shape, part) => {
if (part.outerLine) shape.join(part.outerLine);
if (part.closed) {
const [outerLine] = part.shell;
shape.join(outerLine);
}
return shape;
}, new Shape([], true));
}
Expand Down
73 changes: 16 additions & 57 deletions src/sliceActions/helpers/GCode.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -123,21 +99,13 @@ 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;
speed *= 60;

if (this._extruder > retractionMinDistance) {
if (this._extruder > minDistance) {
this._addGCode({
[MOVE]: 0,
[EXTRUDER]: this._extruder.toFixed(3),
Expand All @@ -149,25 +117,16 @@ 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, amount }) {
if (!this._isRetracted && enabled) {
this._isRetracted = true;

const speed = retractionSpeed * 60;
speed *= 60;

if (this._extruder > retractionMinDistance) {
if (this._extruder > minDistance) {
this._addGCode({
[MOVE]: 0,
[EXTRUDER]: (this._extruder - retractionAmount).toFixed(3),
[EXTRUDER]: (this._extruder - amount).toFixed(3),
[SPEED]: speed.toFixed(3)
});
}
Expand Down
12 changes: 6 additions & 6 deletions src/sliceActions/helpers/Slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ export default class {
constructor() {
this.parts = [];
}
add(shape) {
const part = { shape };
add(shape, closed) {
const part = { shape, closed };

if (shape.closed) {
part.innerLines = [];
part.outerLine = new Shape([], true);
part.fill = new Shape([], false);
if (closed) {
part.shell = [];
part.innerFill = new Shape([], false);
part.outerFill = new Shape([], false);
}

this.parts.push(part);
Expand Down
Loading

0 comments on commit 48f2cef

Please sign in to comment.