mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-11-22 21:47:59 +01:00
Merge branch 'develop'
This commit is contained in:
commit
beb02f5216
@ -3100,7 +3100,7 @@
|
|||||||
if (this.m_ExecuteLocked)
|
if (this.m_ExecuteLocked)
|
||||||
return false;
|
return false;
|
||||||
if (this.m_HasOpenPaths)
|
if (this.m_HasOpenPaths)
|
||||||
ClipperLib.Error("Error: PolyTree struct is need for open path clipping.");
|
//ClipperLib.Error("Error: PolyTree struct is need for open path clipping.");
|
||||||
this.m_ExecuteLocked = true;
|
this.m_ExecuteLocked = true;
|
||||||
ClipperLib.Clear(solution);
|
ClipperLib.Clear(solution);
|
||||||
this.m_SubjFillType = subjFillType;
|
this.m_SubjFillType = subjFillType;
|
135
slice_test.html
135
slice_test.html
@ -6,6 +6,7 @@
|
|||||||
<script src="library/jquery.js"></script>
|
<script src="library/jquery.js"></script>
|
||||||
<script src="library/three.js"></script>
|
<script src="library/three.js"></script>
|
||||||
<script src="library/cal.js"></script>
|
<script src="library/cal.js"></script>
|
||||||
|
<script src="library/clipper.js"></script>
|
||||||
|
|
||||||
<script src="src/utils.js"></script>
|
<script src="src/utils.js"></script>
|
||||||
<script src="src/box.js"></script>
|
<script src="src/box.js"></script>
|
||||||
@ -24,25 +25,41 @@ canvas {border: 1px solid black;}
|
|||||||
<canvas id="canvas" width="400" height="400"></canvas>
|
<canvas id="canvas" width="400" height="400"></canvas>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var localIp = location.hash.substring(1);
|
var printerConfig = {
|
||||||
var doodleBox = new D3D.Box(localIp);
|
"printer.baudrate": "115200",
|
||||||
|
"printer.bed.temperature": 70,
|
||||||
|
"printer.bottomFlowRate": 1.0,
|
||||||
|
"printer.bottomLayerSpeed": 35,
|
||||||
|
"printer.dimensions.x": 200,
|
||||||
|
"printer.dimensions.y": 200,
|
||||||
|
"printer.dimensions.z": 200,
|
||||||
|
"printer.enableTraveling": true,
|
||||||
|
"printer.endcode": "M107 ;fan off\nG91 ;relative positioning\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\nG1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 X0 Y0 ;move X/Y to min endstops, so the head is out of the way\nM84 ;disable axes / steppers\nG90 ;absolute positioning\nM104 S{preheatTemp}\n{if heatedBed}M140 S{preheatBedTemp}\nM117 Done ;display message (20 characters to clear whole screen)",
|
||||||
|
"printer.filamentThickness": 2.89,
|
||||||
|
"printer.firstLayerSlow": true,
|
||||||
|
"printer.heatedbed": false,
|
||||||
|
"printer.heatup.bed.temperature": 70,
|
||||||
|
"printer.heatup.enabled": true,
|
||||||
|
"printer.heatup.temperature": 180,
|
||||||
|
"printer.layerHeight": 0.3,
|
||||||
|
"printer.retraction.amount": 3,
|
||||||
|
"printer.retraction.enabled": true,
|
||||||
|
"printer.retraction.minDistance": 5,
|
||||||
|
"printer.retraction.speed": 50,
|
||||||
|
"printer.screenToMillimeterScale": 0.3,
|
||||||
|
"printer.speed": 70,
|
||||||
|
"printer.startcode": ";Generated with Doodle3D (default)\nM109 S{printingTemp} ;set target temperature \n{if heatedBed}M190 S{printingBedTemp} ;set target bed temperature\nG21 ;metric values\nG91 ;relative positioning\nM107 ;start with the fan off\nG28 X0 Y0 ;move X/Y to min endstops\nG28 Z0 ;move Z to min endstops\nG1 Z15 F9000 ;move the platform down 15mm\nG92 E0 ;zero the extruded length\nG1 F200 E10 ;extrude 10mm of feed stock\nG92 E0 ;zero the extruded length again\nG92 E0 ;zero the extruded length again\nG1 F9000\nG90 ;absolute positioning\nM117 Printing Doodle... ;display message (20 characters to clear whole screen)",
|
||||||
|
"printer.temperature": 230,
|
||||||
|
"printer.travelSpeed": 200,
|
||||||
|
"printer.type": "ultimaker",
|
||||||
|
"printer.useSubLayers": true,
|
||||||
|
"printer.wallThickness": 0.5
|
||||||
|
};
|
||||||
|
|
||||||
doodleBox.onload = function () {
|
//var localIp = location.hash.substring(1);
|
||||||
"use strict";
|
//var doodleBox = new D3D.Box(localIp);
|
||||||
|
var doodleBox = {
|
||||||
/*var gcode = slicer.getGcode(doodleBox.printer);
|
printer: new D3D.Printer(printerConfig)
|
||||||
|
|
||||||
var print = $(document.createElement("a")).html("Print").on("click", function () {
|
|
||||||
doodleBox.print(gcode);
|
|
||||||
});
|
|
||||||
var stop = $(document.createElement("a")).html("Stop").on("click", function () {
|
|
||||||
doodleBox.stop();
|
|
||||||
});
|
|
||||||
var download = $(document.createElement("a")).html("Download").attr({
|
|
||||||
download: "test.gcode",
|
|
||||||
href: "data:text/plain," + encodeURIComponent(gcode.join("\n"))
|
|
||||||
});
|
|
||||||
$("body").append(print, stop, download);*/
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var scene = new THREE.Scene();
|
var scene = new THREE.Scene();
|
||||||
@ -54,52 +71,78 @@ var camera = new THREE.PerspectiveCamera(75, renderer.domElement.width/renderer.
|
|||||||
|
|
||||||
applyMouseControls(renderer, camera, 1000);
|
applyMouseControls(renderer, camera, 1000);
|
||||||
|
|
||||||
|
var geometry = (function () {
|
||||||
|
var circle = new THREE.Shape();
|
||||||
|
circle.absarc(0, 0, 20, 0, Math.PI*2, false);
|
||||||
|
|
||||||
|
var hole = new THREE.Path();
|
||||||
|
hole.absarc(0, 0, 10, 0, Math.PI*2, true );
|
||||||
|
|
||||||
|
circle.holes.push(hole);
|
||||||
|
|
||||||
|
var matrix = new THREE.Matrix4();
|
||||||
|
matrix.makeRotationX(Math.PI*1.5);
|
||||||
|
|
||||||
|
var geometry = new THREE.ExtrudeGeometry(circle, {
|
||||||
|
amount: 1,
|
||||||
|
bevelEnabled: false,
|
||||||
|
steps: 1
|
||||||
|
});
|
||||||
|
geometry.applyMatrix(matrix);
|
||||||
|
|
||||||
|
return geometry;
|
||||||
|
})();
|
||||||
|
|
||||||
var material = new THREE.MeshLambertMaterial({color: 0x000000, wireframe: true});
|
var material = new THREE.MeshLambertMaterial({color: 0x000000, wireframe: true});
|
||||||
var geometry = new THREE.TorusGeometry(20, 10, 10, 10);
|
//var geometry = new THREE.TorusGeometry(40, 20, 10, 10);
|
||||||
//var geometry = new THREE.BoxGeometry(10, 10, 10, 1, 1, 1);
|
//var geometry = new THREE.BoxGeometry(10, 10, 10, 1, 1, 1);
|
||||||
//var geometry = new THREE.SphereGeometry(40, 10, 10);
|
//var geometry = new THREE.SphereGeometry(10, 10, 10);
|
||||||
var mesh = new THREE.Mesh(geometry, material);
|
var mesh = new THREE.Mesh(geometry, material);
|
||||||
scene.add(mesh);
|
scene.add(mesh);
|
||||||
|
|
||||||
(function () {
|
|
||||||
var slicer = new D3D.Slicer().setGeometry(geometry);
|
var slicer = new D3D.Slicer().setGeometry(geometry);
|
||||||
var slices = slicer.slice(200, 0.2);
|
|
||||||
//var slices = slicer.slice(1, 1);
|
|
||||||
|
|
||||||
CAL.Scene.setCanvas(document.getElementById("canvas"));
|
var canvas = document.getElementById("canvas");
|
||||||
|
var context = canvas.getContext("2d");
|
||||||
|
|
||||||
//error at layer 0;
|
var slicer = new D3D.Slicer().setGeometry(geometry);
|
||||||
//maybe because of geomety
|
//slicer.draw(1, context);
|
||||||
var layer = 4;
|
|
||||||
|
|
||||||
var shapes = [];
|
var gcode = slicer.getGcode(printerConfig);
|
||||||
|
|
||||||
var slice = slices[layer];
|
var canvas = document.getElementById("canvas");
|
||||||
|
var context = canvas.getContext("2d");
|
||||||
|
|
||||||
for (var i = 0; i < slice.length; i ++) {
|
function drawPolygons (paths, color) {
|
||||||
var shape = new CAL.Shape({shapeColor: false});
|
context.fillStyle = color;
|
||||||
shapes.push(shape);
|
context.strokeStyle = color;
|
||||||
|
context.beginPath();
|
||||||
|
|
||||||
for (var j = 0; j < slice[i].length; j ++) {
|
for (var i = 0; i < paths.length; i ++) {
|
||||||
var point = slice[i][j];
|
var path = paths[i];
|
||||||
shape.addPoint(new CAL.Vector((point.x-100) * 5 + 200, (point.y-100) * 5 + 200));
|
|
||||||
|
context.moveTo((path[0].X- 100) * 8.0 + 200, (path[0].Y- 100) * 8.0 + 200);
|
||||||
|
|
||||||
|
for (var j = 0; j < path.length; j ++) {
|
||||||
|
var point = path[j];
|
||||||
|
context.lineTo((point.X- 100) * 8.0 + 200, (point.Y- 100) * 8.0 + 200);
|
||||||
}
|
}
|
||||||
|
context.closePath();
|
||||||
|
}
|
||||||
|
context.stroke();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < shapes.length; i ++) {
|
//for (var layer = 0; layer < gcode.length; layer ++) {
|
||||||
var shape = shapes[i];
|
var layer = 0;
|
||||||
|
var slice = gcode[layer];
|
||||||
|
|
||||||
shape.draw(CAL.Scene.context);
|
console.log(gcode.length);
|
||||||
CAL.Scene.context.strokeStyle = "#FF0000";
|
|
||||||
|
|
||||||
for (var j = 0; j < shape.points.length; j ++) {
|
drawPolygons(slice.outerLayer, "red");
|
||||||
var normal = shape.getNormal(j).scale(20);
|
drawPolygons(slice.innerLayer, "green");
|
||||||
var point = shape.points[j];
|
drawPolygons(slice.fill, "blue");
|
||||||
|
//}*/
|
||||||
|
|
||||||
normal.draw(CAL.Scene.context, point.x, point.y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})();
|
|
||||||
|
|
||||||
(function animate () {
|
(function animate () {
|
||||||
requestAnimationFrame(animate);
|
requestAnimationFrame(animate);
|
||||||
|
@ -20,6 +20,8 @@ D3D.Box = function (localIp) {
|
|||||||
this.localIp = localIp;
|
this.localIp = localIp;
|
||||||
this.api = "http://" + localIp + "/d3dapi/";
|
this.api = "http://" + localIp + "/d3dapi/";
|
||||||
|
|
||||||
|
this.config = {};
|
||||||
|
|
||||||
this.printBatches = [];
|
this.printBatches = [];
|
||||||
this.currentBatch = 0;
|
this.currentBatch = 0;
|
||||||
|
|
||||||
@ -31,7 +33,7 @@ D3D.Box = function (localIp) {
|
|||||||
|
|
||||||
for (var i in data) {
|
for (var i in data) {
|
||||||
if (i.indexOf("doodle3d") === 0) {
|
if (i.indexOf("doodle3d") === 0) {
|
||||||
self[i] = data[i];
|
self.config[i] = data[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,7 +67,7 @@ D3D.Box.prototype.updateState = function () {
|
|||||||
|
|
||||||
//que api calls so they don't overload the d3d box
|
//que api calls so they don't overload the d3d box
|
||||||
getAPI(this.api + "info/status", function (data) {
|
getAPI(this.api + "info/status", function (data) {
|
||||||
self.printer.data = data;
|
self.printer.status = data;
|
||||||
|
|
||||||
self.update();
|
self.update();
|
||||||
});
|
});
|
||||||
|
@ -8,18 +8,19 @@
|
|||||||
D3D.Printer = function (config) {
|
D3D.Printer = function (config) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
this.data = {};
|
this.status = {};
|
||||||
|
this.config = {};
|
||||||
|
|
||||||
for (var i in config) {
|
for (var i in config) {
|
||||||
if (i.indexOf("printer") === 0) {
|
if (i.indexOf("printer") === 0) {
|
||||||
this[i] = config[i];
|
this.config[i] = config[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
D3D.Printer.prototype.getStartCode = function () {
|
D3D.Printer.prototype.getStartCode = function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var gcode = this["printer.startcode"];
|
var gcode = this.config["printer.startcode"];
|
||||||
gcode = this.subsituteVariables(gcode);
|
gcode = this.subsituteVariables(gcode);
|
||||||
|
|
||||||
return gcode.split("\n");
|
return gcode.split("\n");
|
||||||
@ -27,7 +28,7 @@ D3D.Printer.prototype.getStartCode = function () {
|
|||||||
D3D.Printer.prototype.getEndCode = function () {
|
D3D.Printer.prototype.getEndCode = function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var gcode = this["printer.endcode"];
|
var gcode = this.config["printer.endcode"];
|
||||||
gcode = this.subsituteVariables(gcode);
|
gcode = this.subsituteVariables(gcode);
|
||||||
|
|
||||||
return gcode.split("\n");
|
return gcode.split("\n");
|
||||||
@ -35,12 +36,12 @@ D3D.Printer.prototype.getEndCode = function () {
|
|||||||
D3D.Printer.prototype.subsituteVariables = function (gcode) {
|
D3D.Printer.prototype.subsituteVariables = function (gcode) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var temperature = this["printer.temperature"];
|
var temperature = this.config["printer.temperature"];
|
||||||
var bedTemperature = this["printer.bed.temperature"];
|
var bedTemperature = this.config["printer.bed.temperature"];
|
||||||
var preheatTemperature = this["printer.heatup.temperature"];
|
var preheatTemperature = this.config["printer.heatup.temperature"];
|
||||||
var preheatBedTemperature = this["printer.heatup.bed.temperature"];
|
var preheatBedTemperature = this.config["printer.heatup.bed.temperature"];
|
||||||
var printerType = this["printer.type"];
|
var printerType = this.config["printer.type"];
|
||||||
var heatedbed = this["printer.heatedbed"];
|
var heatedbed = this.config["printer.heatedbed"];
|
||||||
|
|
||||||
switch (printerType) {
|
switch (printerType) {
|
||||||
case "makerbot_replicator2": printerType = "r2"; break;
|
case "makerbot_replicator2": printerType = "r2"; break;
|
||||||
|
250
src/slicer.js
250
src/slicer.js
@ -5,6 +5,10 @@
|
|||||||
* TODO (optimalisatie)
|
* TODO (optimalisatie)
|
||||||
* sorteer lijnen op laagste hoogte -> stop loop wanneer hij een lijn zonder intersectie heeft gevonden
|
* sorteer lijnen op laagste hoogte -> stop loop wanneer hij een lijn zonder intersectie heeft gevonden
|
||||||
* verwijder lijnen die ooit interactie gehad hebben, maar nu niet meer
|
* verwijder lijnen die ooit interactie gehad hebben, maar nu niet meer
|
||||||
|
* helft van lijnen toevoegen omdat 4face altijd recht is, en 3face dus te veel data bevat
|
||||||
|
*
|
||||||
|
* omliggende lagen -> difference && sum omliggende lijnen
|
||||||
|
* voor laag 5 = 5 diff (3 && 4 && 6 && 7))
|
||||||
*
|
*
|
||||||
******************************************************/
|
******************************************************/
|
||||||
|
|
||||||
@ -69,9 +73,9 @@ D3D.Slicer.prototype.createLines = function () {
|
|||||||
this.lines[b].connects.push(c, a);
|
this.lines[b].connects.push(c, a);
|
||||||
this.lines[c].connects.push(a, b);
|
this.lines[c].connects.push(a, b);
|
||||||
|
|
||||||
this.lines[a].normals.push(normal, normal);
|
this.lines[a].normals.push(normal);
|
||||||
this.lines[b].normals.push(normal, normal);
|
this.lines[b].normals.push(normal);
|
||||||
this.lines[c].normals.push(normal, normal);
|
this.lines[c].normals.push(normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
//sort lines on min height
|
//sort lines on min height
|
||||||
@ -119,7 +123,7 @@ D3D.Slicer.prototype.slice = function (height, step) {
|
|||||||
|
|
||||||
while (index !== -1) {
|
while (index !== -1) {
|
||||||
var intersection = intersections[index];
|
var intersection = intersections[index];
|
||||||
shape.push(intersection);
|
shape.push({X: intersection.x, Y: intersection.y});
|
||||||
|
|
||||||
done.push(index);
|
done.push(index);
|
||||||
|
|
||||||
@ -129,8 +133,10 @@ D3D.Slicer.prototype.slice = function (height, step) {
|
|||||||
index = connects[j];
|
index = connects[j];
|
||||||
|
|
||||||
if (intersections[index] && done.indexOf(index) === -1) {
|
if (intersections[index] && done.indexOf(index) === -1) {
|
||||||
var normal = new THREE.Vector2().copy(intersection).sub(intersections[index]).normal().normalize();
|
var a = new THREE.Vector2().set(intersection.x, intersection.y);
|
||||||
var faceNormal = faceNormals[j];
|
var b = intersections[index];
|
||||||
|
var normal = a.sub(b).normal().normalize();
|
||||||
|
var faceNormal = faceNormals[Math.floor(j/2)];
|
||||||
|
|
||||||
if (normal.dot(faceNormal) > 0) {
|
if (normal.dot(faceNormal) > 0) {
|
||||||
break;
|
break;
|
||||||
@ -152,6 +158,7 @@ D3D.Slicer.prototype.slice = function (height, step) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//stop when ther are no intersects
|
||||||
if (slice.length > 0) {
|
if (slice.length > 0) {
|
||||||
slices.push(slice);
|
slices.push(slice);
|
||||||
}
|
}
|
||||||
@ -162,44 +169,154 @@ D3D.Slicer.prototype.slice = function (height, step) {
|
|||||||
|
|
||||||
return slices;
|
return slices;
|
||||||
};
|
};
|
||||||
D3D.Slicer.prototype.getGcode = function (printer) {
|
D3D.Slicer.prototype.getInset = function (slice, offset) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var normalSpeed = doodleBox.printer["printer.speed"];
|
var solution = new ClipperLib.Paths();
|
||||||
var bottomSpeed = doodleBox.printer["printer.bottomLayerSpeed"];
|
var co = new ClipperLib.ClipperOffset(1, 1);
|
||||||
var firstLayerSlow = doodleBox.printer["printer.firstLayerSlow"];
|
co.AddPaths(slice, ClipperLib.JoinType.jtRound, ClipperLib.EndType.etClosedPolygon);
|
||||||
var bottomFlowRate = doodleBox.printer["printer.bottomFlowRate"];
|
co.Execute(solution, -offset);
|
||||||
var travelSpeed = doodleBox.printer["printer.travelSpeed"];
|
|
||||||
var filamentThickness = doodleBox.printer["printer.filamentThickness"];
|
|
||||||
var wallThickness = doodleBox.printer["printer.wallThickness"];
|
|
||||||
var layerHeight = doodleBox.printer["printer.layerHeight"];
|
|
||||||
var enableTraveling = doodleBox.printer["printer.enableTraveling"];
|
|
||||||
var retractionEnabled = doodleBox.printer["printer.retraction.enabled"];
|
|
||||||
var retractionSpeed = doodleBox.printer["printer.retraction.speed"];
|
|
||||||
var retractionminDistance = doodleBox.printer["printer.retraction.minDistance"];
|
|
||||||
var retractionAmount = doodleBox.printer["printer.retraction.amount"];
|
|
||||||
var dimensionsZ = doodleBox.printer["printer.dimensions.z"];
|
|
||||||
|
|
||||||
var gcode = doodleBox.printer.getStartCode();
|
return solution;
|
||||||
|
};
|
||||||
|
D3D.Slicer.prototype.getFillTemplate = function (dimension, size, even, uneven) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
var extruder = 0.0;
|
var paths = new ClipperLib.Paths();
|
||||||
var speed = firstLayerSlow ? (bottomSpeed*60).toFixed(3) : (normalSpeed*60).toFixed(3);
|
|
||||||
var flowRate = bottomFlowRate;
|
if (even) {
|
||||||
var filamentSurfaceArea = Math.pow((filamentThickness/2), 2) * Math.PI;
|
for (var length = 0; length <= dimension; length += size) {
|
||||||
|
paths.push([{X: length, Y: 0}, {X: length, Y: dimension}]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (uneven) {
|
||||||
|
for (var length = 0; length <= dimension; length += size) {
|
||||||
|
paths.push([{X: 0, Y: length}, {X: dimension, Y: length}]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return paths;
|
||||||
|
};
|
||||||
|
D3D.Slicer.prototype.slicesToData = function (slices, config) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var data = [];
|
||||||
|
|
||||||
|
//scale because of clipper crap
|
||||||
|
var scale = 100;
|
||||||
|
|
||||||
|
var layerHeight = config["printer.layerHeight"] * scale;
|
||||||
|
var dimensionsZ = config["printer.dimensions.z"] * scale;
|
||||||
|
//variables should come from config
|
||||||
|
//aan rick voorleggen
|
||||||
|
var nozzleSize = 0.4 * scale;
|
||||||
|
var shellThickness = 0.8 * scale;
|
||||||
|
var fillSize = 5 * scale;
|
||||||
|
|
||||||
|
var lowFillTemplate = this.getFillTemplate(dimensionsZ, fillSize, true, true);
|
||||||
|
|
||||||
var slices = this.slice(dimensionsZ, layerHeight);
|
|
||||||
|
|
||||||
for (var layer = 0; layer < slices.length; layer ++) {
|
for (var layer = 0; layer < slices.length; layer ++) {
|
||||||
var slice = slices[layer];
|
var slice = slices[layer];
|
||||||
|
var highFillTemplate = this.getFillTemplate(dimensionsZ, nozzleSize*2, (layer % 2 === 0), (layer % 2 === 1));
|
||||||
|
|
||||||
//turn on fan on layer 2
|
//var outerLayer = ClipperLib.JS.Clean(slice, 1.0);
|
||||||
if (layer === 2) {
|
var outerLayer = slice.clone();
|
||||||
gcode.push("M106");
|
ClipperLib.JS.ScaleUpPaths(outerLayer, scale);
|
||||||
speed = (normalSpeed*60).toFixed(3);
|
|
||||||
flowRate = 1;
|
var innerLayer = [];
|
||||||
|
|
||||||
|
for (var i = nozzleSize; i < shellThickness; i += nozzleSize) {
|
||||||
|
var inset = this.getInset(outerLayer, i);
|
||||||
|
|
||||||
|
innerLayer = innerLayer.concat(inset);
|
||||||
}
|
}
|
||||||
|
|
||||||
var z = ((layer + 1) * layerHeight).toFixed(3);
|
var fillArea = this.getInset((inset || outerLayer), nozzleSize);
|
||||||
|
|
||||||
|
var highFill;
|
||||||
|
|
||||||
|
var fillAbove;
|
||||||
|
for (var i = 1; i < shellThickness/layerHeight; i ++) {
|
||||||
|
var newLayer = ClipperLib.JS.Clone(slices[layer + i]);
|
||||||
|
ClipperLib.JS.ScaleUpPaths(newLayer, scale);
|
||||||
|
|
||||||
|
if (newLayer.length === 0) {
|
||||||
|
fillAbove = [];
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else if (fillAbove === undefined) {
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fillAbove === undefined) {
|
||||||
|
fillAbove = newLayer;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// var c = new ClipperLib.Clipper();
|
||||||
|
// var solution = new ClipperLib.Paths();
|
||||||
|
// c.AddPaths(fillArea, ClipperLib.PolyType.ptSubject, true);
|
||||||
|
// c.AddPaths(fillAbove, ClipperLib.PolyType.ptClip, true);
|
||||||
|
// c.Execute(ClipperLib.ClipType.ctDifference, solution);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//kijkt alleen nog naar boven
|
||||||
|
//omliggende lagen hebben inhoud van lowFill;
|
||||||
|
//inset moet opgevult worden;
|
||||||
|
//verschill tussen lowFill en inset moet vol, rest is raster
|
||||||
|
|
||||||
|
var clipper = new ClipperLib.Clipper();
|
||||||
|
var highFillArea = new ClipperLib.Paths();
|
||||||
|
clipper.AddPaths(fillArea, ClipperLib.PolyType.ptSubject, true);
|
||||||
|
clipper.AddPaths(fillAbove, ClipperLib.PolyType.ptClip, true);
|
||||||
|
clipper.Execute(ClipperLib.ClipType.ctDifference, highFillArea);
|
||||||
|
|
||||||
|
var clipper = new ClipperLib.Clipper();
|
||||||
|
var lowFillArea = new ClipperLib.Paths();
|
||||||
|
clipper.AddPaths(fillArea, ClipperLib.PolyType.ptSubject, true);
|
||||||
|
clipper.AddPaths(highFillArea, ClipperLib.PolyType.ptClip, true);
|
||||||
|
clipper.Execute(ClipperLib.ClipType.ctDifference, lowFillArea);
|
||||||
|
|
||||||
|
var fill = [];
|
||||||
|
|
||||||
|
var clipper = new ClipperLib.Clipper();
|
||||||
|
var lowFillStrokes = new ClipperLib.Paths();
|
||||||
|
clipper.AddPaths(lowFillTemplate, ClipperLib.PolyType.ptSubject, false);
|
||||||
|
clipper.AddPaths(lowFillArea, ClipperLib.PolyType.ptClip, true);
|
||||||
|
clipper.Execute(ClipperLib.ClipType.ctIntersection, lowFillStrokes);
|
||||||
|
|
||||||
|
fill = fill.concat(lowFillStrokes);
|
||||||
|
|
||||||
|
var clipper = new ClipperLib.Clipper();
|
||||||
|
var highFillStrokes = new ClipperLib.Paths();
|
||||||
|
clipper.AddPaths(highFillTemplate, ClipperLib.PolyType.ptSubject, false);
|
||||||
|
clipper.AddPaths(highFillArea, ClipperLib.PolyType.ptClip, true);
|
||||||
|
clipper.Execute(ClipperLib.ClipType.ctIntersection, highFillStrokes);
|
||||||
|
|
||||||
|
fill = fill.concat(highFillStrokes);
|
||||||
|
|
||||||
|
ClipperLib.JS.ScaleDownPaths(outerLayer, scale);
|
||||||
|
ClipperLib.JS.ScaleDownPaths(innerLayer, scale);
|
||||||
|
ClipperLib.JS.ScaleDownPaths(fill, scale);
|
||||||
|
|
||||||
|
data.push({
|
||||||
|
outerLayer: outerLayer,
|
||||||
|
innerLayer: innerLayer,
|
||||||
|
fill: fill
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
D3D.Slicer.prototype.getGcode = function (config) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
function sliceToGcode (slice) {
|
||||||
|
var gcode = [];
|
||||||
|
|
||||||
for (var i = 0; i < slice.length; i ++) {
|
for (var i = 0; i < slice.length; i ++) {
|
||||||
var shape = slice[i];
|
var shape = slice[i];
|
||||||
@ -213,7 +330,7 @@ D3D.Slicer.prototype.getGcode = function (printer) {
|
|||||||
if (j === 0) {
|
if (j === 0) {
|
||||||
//TODO
|
//TODO
|
||||||
//add retraction
|
//add retraction
|
||||||
if (extruder > retractionAmount && retractionEnabled) {
|
if (extruder > retractionMinDistance && retractionEnabled) {
|
||||||
gcode.push([
|
gcode.push([
|
||||||
"G0",
|
"G0",
|
||||||
"E" + (extruder - retractionAmount).toFixed(3),
|
"E" + (extruder - retractionAmount).toFixed(3),
|
||||||
@ -223,11 +340,11 @@ D3D.Slicer.prototype.getGcode = function (printer) {
|
|||||||
|
|
||||||
gcode.push([
|
gcode.push([
|
||||||
"G0",
|
"G0",
|
||||||
"X" + point.x.toFixed(3) + " Y" + point.y.toFixed(3) + " Z" + z,
|
"X" + point.X.toFixed(3) + " Y" + point.Y.toFixed(3) + " Z" + z,
|
||||||
"F" + (travelSpeed*60)
|
"F" + (travelSpeed*60)
|
||||||
].join(" "));
|
].join(" "));
|
||||||
|
|
||||||
if (extruder > retractionAmount && retractionEnabled) {
|
if (extruder > retractionMinDistance && retractionEnabled) {
|
||||||
gcode.push([
|
gcode.push([
|
||||||
"G0",
|
"G0",
|
||||||
"E" + extruder.toFixed(3),
|
"E" + extruder.toFixed(3),
|
||||||
@ -236,12 +353,15 @@ D3D.Slicer.prototype.getGcode = function (printer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var lineLength = new THREE.Vector2().copy(point).sub(previousPoint).length();
|
var a = new THREE.Vector2().set(point.X, point.Y);
|
||||||
|
var b = new THREE.Vector2().set(previousPoint.X, previousPoint.Y);
|
||||||
|
var lineLength = a.distanceTo(b);
|
||||||
|
|
||||||
extruder += lineLength * wallThickness * layerHeight / filamentSurfaceArea * flowRate;
|
extruder += lineLength * wallThickness * layerHeight / filamentSurfaceArea * flowRate;
|
||||||
|
|
||||||
gcode.push([
|
gcode.push([
|
||||||
"G1",
|
"G1",
|
||||||
"X" + point.x.toFixed(3) + " Y" + point.y.toFixed(3) + " Z" + z,
|
"X" + point.X.toFixed(3) + " Y" + point.Y.toFixed(3) + " Z" + z,
|
||||||
"F" + speed,
|
"F" + speed,
|
||||||
"E" + extruder.toFixed(3)
|
"E" + extruder.toFixed(3)
|
||||||
].join(" "));
|
].join(" "));
|
||||||
@ -250,6 +370,60 @@ D3D.Slicer.prototype.getGcode = function (printer) {
|
|||||||
previousPoint = point;
|
previousPoint = point;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return gcode;
|
||||||
|
}
|
||||||
|
|
||||||
|
var normalSpeed = config["printer.speed"];
|
||||||
|
var bottomSpeed = config["printer.bottomLayerSpeed"];
|
||||||
|
var firstLayerSlow = config["printer.firstLayerSlow"];
|
||||||
|
var bottomFlowRate = config["printer.bottomFlowRate"];
|
||||||
|
var travelSpeed = config["printer.travelSpeed"];
|
||||||
|
var filamentThickness = config["printer.filamentThickness"];
|
||||||
|
var wallThickness = config["printer.wallThickness"];
|
||||||
|
var layerHeight = config["printer.layerHeight"];
|
||||||
|
var enableTraveling = config["printer.enableTraveling"];
|
||||||
|
var retractionEnabled = config["printer.retraction.enabled"];
|
||||||
|
var retractionSpeed = config["printer.retraction.speed"];
|
||||||
|
var retractionMinDistance = config["printer.retraction.minDistance"];
|
||||||
|
var retractionAmount = config["printer.retraction.amount"];
|
||||||
|
var dimensionsZ = config["printer.dimensions.z"];
|
||||||
|
|
||||||
|
var gcode = doodleBox.printer.getStartCode();
|
||||||
|
|
||||||
|
var extruder = 0.0;
|
||||||
|
var speed = firstLayerSlow ? (bottomSpeed*60).toFixed(3) : (normalSpeed*60).toFixed(3);
|
||||||
|
var filamentSurfaceArea = Math.pow((filamentThickness/2), 2) * Math.PI;
|
||||||
|
var flowRate = bottomFlowRate;
|
||||||
|
|
||||||
|
var slices = [];
|
||||||
|
|
||||||
|
var slices = this.slice(dimensionsZ, layerHeight);
|
||||||
|
//still error in first layer, so remove first layer
|
||||||
|
//see https://github.com/Doodle3D/Doodle3D-Slicer/issues/1
|
||||||
|
slices.shift();
|
||||||
|
|
||||||
|
//code for only printing the first layer
|
||||||
|
//var slices = [slices.shift()];
|
||||||
|
|
||||||
|
var data = this.slicesToData(slices, config);
|
||||||
|
return data;
|
||||||
|
|
||||||
|
for (var layer = 0; layer < data.length; layer ++) {
|
||||||
|
var slice = data[layer];
|
||||||
|
|
||||||
|
//turn on fan on layer 2
|
||||||
|
if (layer === 2) {
|
||||||
|
gcode.push("M106");
|
||||||
|
speed = (normalSpeed*60).toFixed(3);
|
||||||
|
flowRate = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
var z = ((layer + 1) * layerHeight).toFixed(3);
|
||||||
|
|
||||||
|
gcode = gcode.concat(sliceToGcode(slice.outerLayer));
|
||||||
|
gcode = gcode.concat(sliceToGcode(slice.innerLayer));
|
||||||
|
gcode = gcode.concat(sliceToGcode(slice.fill));
|
||||||
}
|
}
|
||||||
|
|
||||||
gcode = gcode.concat(doodleBox.printer.getEndCode());
|
gcode = gcode.concat(doodleBox.printer.getEndCode());
|
||||||
|
@ -11,6 +11,7 @@ var D3D = {
|
|||||||
"contact": "develop@doodle3d.com"
|
"contact": "develop@doodle3d.com"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
//add normal function to Three.js Vector class
|
||||||
THREE.Vector2.prototype.normal = function () {
|
THREE.Vector2.prototype.normal = function () {
|
||||||
var x = this.y;
|
var x = this.y;
|
||||||
var y = -this.x;
|
var y = -this.x;
|
||||||
@ -87,7 +88,6 @@ Array.prototype.clone = function () {
|
|||||||
return array;
|
return array;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
function applyMouseControls (renderer, camera, maxDistance) {
|
function applyMouseControls (renderer, camera, maxDistance) {
|
||||||
"use strict";
|
"use strict";
|
||||||
//TODO
|
//TODO
|
||||||
|
Loading…
Reference in New Issue
Block a user