mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2025-01-05 09:23:48 +01:00
changed gcode implementation from array to string
Makes more sense to store it as string rather then store it as array. Doesn’t work with the doodle box though; think the doodle box adds \n after each batch
This commit is contained in:
parent
ec447ab56e
commit
20e80b390e
2
.gitignore
vendored
2
.gitignore
vendored
@ -19,3 +19,5 @@ bower_components/
|
|||||||
src/oldcode.js
|
src/oldcode.js
|
||||||
|
|
||||||
test.html
|
test.html
|
||||||
|
|
||||||
|
print_manager.html
|
||||||
|
@ -1578,6 +1578,18 @@ THREE.Vector2.prototype = {
|
|||||||
|
|
||||||
return new THREE.Vector2( this.x, this.y );
|
return new THREE.Vector2( this.x, this.y );
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
normal : function () {
|
||||||
|
|
||||||
|
var x = this.y;
|
||||||
|
var y = -this.x;
|
||||||
|
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
Binary file not shown.
@ -28,7 +28,7 @@ canvas {border: 1px solid black;}
|
|||||||
<script>
|
<script>
|
||||||
//nieuwe config
|
//nieuwe config
|
||||||
//geimplimenteerd worden in de doodlebox?
|
//geimplimenteerd worden in de doodlebox?
|
||||||
var printerConfig = {
|
var printer = new D3D.Printer({
|
||||||
"printer.baudrate": "115200", //wat is dit?
|
"printer.baudrate": "115200", //wat is dit?
|
||||||
"printer.bottomFlowRate": 1.0,
|
"printer.bottomFlowRate": 1.0,
|
||||||
"printer.bottomLayerSpeed": 35,
|
"printer.bottomLayerSpeed": 35,
|
||||||
@ -56,8 +56,7 @@ var printerConfig = {
|
|||||||
|
|
||||||
"printer.speed": 50,
|
"printer.speed": 50,
|
||||||
"printer.wallThickness": 0.4, //nozzle
|
"printer.wallThickness": 0.4, //nozzle
|
||||||
"printer.layerHeight": 0.2,
|
"printer.layerHeight": 0.3,
|
||||||
|
|
||||||
|
|
||||||
//variabele toevoegen;
|
//variabele toevoegen;
|
||||||
//-snelheid, retraction etc voor verschillende types (outerlayer, innerlayer, fill)
|
//-snelheid, retraction etc voor verschillende types (outerlayer, innerlayer, fill)
|
||||||
@ -66,8 +65,7 @@ var printerConfig = {
|
|||||||
"printer.shellThickness": 0.4,
|
"printer.shellThickness": 0.4,
|
||||||
"printer.fillSize": 5, //dit is het raster aan de binnen kant van de geometry
|
"printer.fillSize": 5, //dit is het raster aan de binnen kant van de geometry
|
||||||
"printer.brimOffset": 5
|
"printer.brimOffset": 5
|
||||||
};
|
});
|
||||||
var printer = new D3D.Printer(printerConfig);
|
|
||||||
|
|
||||||
var localIp = location.hash.substring(1);
|
var localIp = location.hash.substring(1);
|
||||||
var doodleBox = new D3D.Box(localIp);
|
var doodleBox = new D3D.Box(localIp);
|
||||||
@ -75,7 +73,7 @@ var doodleBox = new D3D.Box(localIp);
|
|||||||
|
|
||||||
var scene = new THREE.Scene();
|
var scene = new THREE.Scene();
|
||||||
|
|
||||||
var renderer = new THREE.WebGLRenderer({canvas: document.getElementById("3d-preview")});
|
var renderer = new THREE.WebGLRenderer({canvas: document.getElementById("3d-preview"), antialias: true});
|
||||||
renderer.setClearColor(0xffffff, 1);
|
renderer.setClearColor(0xffffff, 1);
|
||||||
|
|
||||||
var camera = new THREE.PerspectiveCamera(75, renderer.domElement.width/renderer.domElement.height, 1, 10000);
|
var camera = new THREE.PerspectiveCamera(75, renderer.domElement.width/renderer.domElement.height, 1, 10000);
|
||||||
@ -90,7 +88,7 @@ camera.add(directionalLight);
|
|||||||
applyMouseControls(renderer, camera, new THREE.Vector3(100, 0, 100), 1000);
|
applyMouseControls(renderer, camera, new THREE.Vector3(100, 0, 100), 1000);
|
||||||
|
|
||||||
var loader = new THREE.STLLoader();
|
var loader = new THREE.STLLoader();
|
||||||
loader.load("models/d20.stl", function (geometry) {
|
loader.load("models/pikachu.stl", function (geometry) {
|
||||||
//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(10, 10, 10);
|
//var geometry = new THREE.SphereGeometry(10, 10, 10);
|
||||||
//var geometry = new THREE.TorusGeometry(20, 10, 30, 30);
|
//var geometry = new THREE.TorusGeometry(20, 10, 30, 30);
|
||||||
@ -119,7 +117,6 @@ loader.load("models/d20.stl", function (geometry) {
|
|||||||
return geometry;
|
return geometry;
|
||||||
})();
|
})();
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var material = new THREE.MeshPhongMaterial({color: 0x00ff00});
|
var material = new THREE.MeshPhongMaterial({color: 0x00ff00});
|
||||||
var mesh = new THREE.Mesh(geometry, material);
|
var mesh = new THREE.Mesh(geometry, material);
|
||||||
|
|
||||||
@ -128,11 +125,10 @@ loader.load("models/d20.stl", function (geometry) {
|
|||||||
mesh.scale.x = mesh.scale.y = mesh.scale.z = 1;
|
mesh.scale.x = mesh.scale.y = mesh.scale.z = 1;
|
||||||
mesh.position.x = 100;
|
mesh.position.x = 100;
|
||||||
mesh.position.z = 100;
|
mesh.position.z = 100;
|
||||||
//mesh.position.y = -2;
|
|
||||||
|
|
||||||
scene.add(mesh);
|
scene.add(mesh);
|
||||||
|
|
||||||
var slicer = new D3D.Slicer().setMesh(mesh);
|
slicer = new D3D.Slicer().setMesh(mesh);
|
||||||
|
|
||||||
var canvas = document.getElementById("canvas");
|
var canvas = document.getElementById("canvas");
|
||||||
var context = canvas.getContext("2d");
|
var context = canvas.getContext("2d");
|
||||||
|
19
src/box.js
19
src/box.js
@ -16,13 +16,15 @@ D3D.Box = function (localIp) {
|
|||||||
"use strict";
|
"use strict";
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.batchSize = 512;
|
this.batchSize = 1024 * 10; //10kb
|
||||||
this.maxBufferedLines = 4096;
|
this.maxBufferSize = 1024 * 1024 * 2; //2mb
|
||||||
|
this.bytesSend = 0;
|
||||||
|
|
||||||
this.localIp = localIp;
|
this.localIp = localIp;
|
||||||
this.api = "http://" + localIp + "/d3dapi/";
|
this.api = "http://" + localIp + "/d3dapi/";
|
||||||
|
|
||||||
this.config = {};
|
this.config = {};
|
||||||
|
this.status = {};
|
||||||
|
|
||||||
this.printBatches = [];
|
this.printBatches = [];
|
||||||
this.currentBatch = 0;
|
this.currentBatch = 0;
|
||||||
@ -59,7 +61,7 @@ D3D.Box.prototype.update = function () {
|
|||||||
//Bij error wordt gelijk zelfde data opnieuw gestuurd
|
//Bij error wordt gelijk zelfde data opnieuw gestuurd
|
||||||
//Als DoodleBox ontkoppeld wordt komt er een error in de loop waardoor pagina breekt en ververst moet worden
|
//Als DoodleBox ontkoppeld wordt komt er een error in de loop waardoor pagina breekt en ververst moet worden
|
||||||
|
|
||||||
if (this.printBatches.length > 0 && (this.printer.status["buffered_lines"] + this.batchSize) <= this.maxBufferedLines) {
|
if (this.printBatches.length > 0 && (this.status["buffered_lines"]*30 + this.batchSize) <= this.maxBufferSize) {
|
||||||
//if (this.printBatches.length > 0 ) {
|
//if (this.printBatches.length > 0 ) {
|
||||||
this.printBatch();
|
this.printBatch();
|
||||||
}
|
}
|
||||||
@ -73,7 +75,7 @@ D3D.Box.prototype.updateState = function () {
|
|||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
this.getInfoStatus(function (data) {
|
this.getInfoStatus(function (data) {
|
||||||
self.printer.status = data;
|
self.status = data;
|
||||||
|
|
||||||
if (self.onupdate !== undefined) {
|
if (self.onupdate !== undefined) {
|
||||||
self.onupdate(data);
|
self.onupdate(data);
|
||||||
@ -87,12 +89,9 @@ D3D.Box.prototype.print = function (gcode) {
|
|||||||
|
|
||||||
this.currentBatch = 0;
|
this.currentBatch = 0;
|
||||||
|
|
||||||
//clone gcode to remove array links
|
|
||||||
gcode = gcode.clone();
|
|
||||||
|
|
||||||
//gcode split in batches
|
//gcode split in batches
|
||||||
while (gcode.length > 0) {
|
for (var i = 0; i < gcode.length; i += this.batchSize) {
|
||||||
var gcodeBatch = gcode.splice(0, Math.min(this.batchSize, gcode.length));
|
var gcodeBatch = gcode.substring(i, Math.min(i + this.batchSize, gcode.length));
|
||||||
this.printBatches.push(gcodeBatch);
|
this.printBatches.push(gcodeBatch);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,7 +106,7 @@ D3D.Box.prototype.printBatch = function () {
|
|||||||
this.setPrinterPrint({
|
this.setPrinterPrint({
|
||||||
"start": ((this.currentBatch === 0) ? true : false),
|
"start": ((this.currentBatch === 0) ? true : false),
|
||||||
"first": ((this.currentBatch === 0) ? true : false),
|
"first": ((this.currentBatch === 0) ? true : false),
|
||||||
"gcode": gcode.join("\n")
|
"gcode": gcode
|
||||||
}, function (data) {
|
}, function (data) {
|
||||||
console.log("batch sent: " + self.currentBatch, data);
|
console.log("batch sent: " + self.currentBatch, data);
|
||||||
|
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
D3D.Printer = function (config) {
|
D3D.Printer = function (config) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
this.status = {};
|
|
||||||
this.config = {};
|
this.config = {};
|
||||||
|
|
||||||
this.updateConfig(config);
|
this.updateConfig(config);
|
||||||
@ -30,7 +29,7 @@ D3D.Printer.prototype.getStartCode = function () {
|
|||||||
var gcode = this.config["printer.startcode"];
|
var gcode = this.config["printer.startcode"];
|
||||||
gcode = this.subsituteVariables(gcode);
|
gcode = this.subsituteVariables(gcode);
|
||||||
|
|
||||||
return gcode.split("\n");
|
return gcode;
|
||||||
};
|
};
|
||||||
D3D.Printer.prototype.getEndCode = function () {
|
D3D.Printer.prototype.getEndCode = function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
@ -38,7 +37,7 @@ D3D.Printer.prototype.getEndCode = function () {
|
|||||||
var gcode = this.config["printer.endcode"];
|
var gcode = this.config["printer.endcode"];
|
||||||
gcode = this.subsituteVariables(gcode);
|
gcode = this.subsituteVariables(gcode);
|
||||||
|
|
||||||
return gcode.split("\n");
|
return gcode;
|
||||||
};
|
};
|
||||||
D3D.Printer.prototype.subsituteVariables = function (gcode) {
|
D3D.Printer.prototype.subsituteVariables = function (gcode) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
@ -163,7 +163,7 @@ 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 a = new THREE.Vector2().set(intersection.x, intersection.y);
|
var a = new THREE.Vector2(intersection.x, intersection.y);
|
||||||
var b = intersections[index];
|
var b = intersections[index];
|
||||||
var normal = a.sub(b).normal().normalize();
|
var normal = a.sub(b).normal().normalize();
|
||||||
var faceNormal = faceNormals[Math.floor(j/2)];
|
var faceNormal = faceNormals[Math.floor(j/2)];
|
||||||
@ -248,7 +248,7 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) {
|
|||||||
|
|
||||||
var layerHeight = printer.config["printer.layerHeight"] * scale;
|
var layerHeight = printer.config["printer.layerHeight"] * scale;
|
||||||
var dimensionsZ = printer.config["printer.dimensions.z"] * scale;
|
var dimensionsZ = printer.config["printer.dimensions.z"] * scale;
|
||||||
var wallThickness = printer.config["printer.wallThickness"] * scale;
|
var wallThickness = printer.config["printer.wallThickness"] * scale / 2;
|
||||||
var shellThickness = printer.config["printer.shellThickness"] * scale;
|
var shellThickness = printer.config["printer.shellThickness"] * scale;
|
||||||
var fillSize = printer.config["printer.fillSize"] * scale;
|
var fillSize = printer.config["printer.fillSize"] * scale;
|
||||||
var brimOffset = printer.config["printer.brimOffset"] * scale;
|
var brimOffset = printer.config["printer.brimOffset"] * scale;
|
||||||
@ -452,7 +452,7 @@ D3D.Slicer.prototype.dataToGcode = function (data, printer) {
|
|||||||
return gcode;
|
return gcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
var gcode = printer.getStartCode();
|
var gcode = printer.getStartCode().split("\n");
|
||||||
|
|
||||||
var extruder = 0.0;
|
var extruder = 0.0;
|
||||||
var speed = firstLayerSlow ? (bottomSpeed*60).toFixed(3) : (normalSpeed*60).toFixed(3);
|
var speed = firstLayerSlow ? (bottomSpeed*60).toFixed(3) : (normalSpeed*60).toFixed(3);
|
||||||
@ -480,8 +480,7 @@ D3D.Slicer.prototype.dataToGcode = function (data, printer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gcode = gcode.concat(printer.getEndCode());
|
return gcode.join("\n") + "\n" + printer.getEndCode();
|
||||||
return gcode;
|
|
||||||
};
|
};
|
||||||
//only for debug purposes
|
//only for debug purposes
|
||||||
D3D.Slicer.prototype.drawPaths = function (printer, min, max) {
|
D3D.Slicer.prototype.drawPaths = function (printer, min, max) {
|
||||||
|
26
src/utils.js
26
src/utils.js
@ -11,16 +11,6 @@ var D3D = {
|
|||||||
"contact": "develop@doodle3d.com"
|
"contact": "develop@doodle3d.com"
|
||||||
};
|
};
|
||||||
|
|
||||||
//add normal function to Three.js Vector class
|
|
||||||
THREE.Vector2.prototype.normal = function () {
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var x = this.y;
|
|
||||||
var y = -this.x;
|
|
||||||
|
|
||||||
return this.set(x, y);
|
|
||||||
};
|
|
||||||
|
|
||||||
function sendAPI (url, data, callback) {
|
function sendAPI (url, data, callback) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -72,20 +62,10 @@ function getAPI (url, callback) {
|
|||||||
function downloadFile (file, data) {
|
function downloadFile (file, data) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
var blob = new Blob([data], {type:'text/plain'});
|
||||||
|
|
||||||
var button = document.createElement("a");
|
var button = document.createElement("a");
|
||||||
button.download = file;
|
button.download = file;
|
||||||
button.href = "data:text/plain," + data;
|
button.href = window.URL.createObjectURL(blob);
|
||||||
button.click();
|
button.click();
|
||||||
}
|
}
|
||||||
|
|
||||||
Array.prototype.clone = function () {
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var array = [];
|
|
||||||
|
|
||||||
for (var i = 0; i < this.length; i ++) {
|
|
||||||
array[i] = this[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
return array;
|
|
||||||
};
|
|
Loading…
Reference in New Issue
Block a user