mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-12-23 03:23:48 +01:00
added separate settings files
This commit is contained in:
parent
173e723656
commit
f24e96c5ac
18
README.md
18
README.md
@ -10,18 +10,20 @@ This is an example of code.
|
||||
var localIp = "192.168.5.1";
|
||||
var doodleBox = new D3D.Box(localIp);
|
||||
|
||||
var geometry = new THREE.BoxGeometry(20, 20, 20, 1, 1, 1);
|
||||
var material = new THREE.MeshBasicMaterial({color: 0x000000, wireframe: true});
|
||||
var mesh = new THREE.Mesh(geometry, material);
|
||||
mesh.position.x = 100;
|
||||
mesh.position.z = 100;
|
||||
mesh.position.y = 10;
|
||||
|
||||
doodleBox.onload = function () {
|
||||
"use strict";
|
||||
|
||||
var printer = new D3D.Printer(printerSettings, userSettings);
|
||||
|
||||
var geometry = new THREE.BoxGeometry(20, 20, 20, 1, 1, 1);
|
||||
var material = new THREE.MeshBasicMaterial({color: 0x000000, wireframe: true});
|
||||
var mesh = new THREE.Mesh(geometry, material);
|
||||
mesh.position.x = 100;
|
||||
mesh.position.z = 100;
|
||||
mesh.position.y = 10;
|
||||
|
||||
var slicer = new D3D.Slicer().setMesh(mesh);
|
||||
var gcode = slicer.getGcode(doodleBox.printer);
|
||||
var gcode = slicer.getGcode(printer);
|
||||
|
||||
doodleBox.print(gcode);
|
||||
};
|
||||
|
230
build/d3d.js
vendored
230
build/d3d.js
vendored
@ -11,16 +11,6 @@ var D3D = {
|
||||
"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) {
|
||||
"use strict";
|
||||
|
||||
@ -69,18 +59,33 @@ function getAPI (url, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function loadSettings (url, callback) {
|
||||
"use strict";
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
dataType: "json",
|
||||
success: function (response) {
|
||||
if (callback !== undefined) {
|
||||
callback(response);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function downloadFile (file, data) {
|
||||
"use strict";
|
||||
|
||||
$(document.createElement("a")).attr({
|
||||
download: file,
|
||||
href: "data:text/plain," + data
|
||||
})[0].click();
|
||||
var blob = new Blob([data], {type:'text/plain'});
|
||||
|
||||
var button = document.createElement("a");
|
||||
button.download = file;
|
||||
button.href = window.URL.createObjectURL(blob);
|
||||
button.click();
|
||||
}
|
||||
|
||||
Array.prototype.clone = function () {
|
||||
"use strict";
|
||||
|
||||
var array = [];
|
||||
|
||||
for (var i = 0; i < this.length; i ++) {
|
||||
@ -88,7 +93,7 @@ Array.prototype.clone = function () {
|
||||
}
|
||||
|
||||
return array;
|
||||
};
|
||||
}
|
||||
/******************************************************
|
||||
*
|
||||
* Box
|
||||
@ -114,6 +119,7 @@ D3D.Box = function (localIp) {
|
||||
this.api = "http://" + localIp + "/d3dapi/";
|
||||
|
||||
this.config = {};
|
||||
this.status = {};
|
||||
|
||||
this.printBatches = [];
|
||||
this.currentBatch = 0;
|
||||
@ -123,7 +129,6 @@ D3D.Box = function (localIp) {
|
||||
this.getConfigAll(function (data) {
|
||||
self.updateConfig(data);
|
||||
|
||||
self.printer = new D3D.Printer(data);
|
||||
self.update();
|
||||
|
||||
self.loaded = true;
|
||||
@ -136,9 +141,7 @@ D3D.Box.prototype.updateConfig = function (config) {
|
||||
"use strict";
|
||||
|
||||
for (var i in config) {
|
||||
if (i.indexOf("doodle3d") === 0) {
|
||||
this.config[i] = config[i];
|
||||
}
|
||||
this.config[i] = config[i];
|
||||
}
|
||||
|
||||
return this;
|
||||
@ -150,7 +153,7 @@ D3D.Box.prototype.update = function () {
|
||||
//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
|
||||
|
||||
if (this.printBatches.length > 0 && (this.printer.status["buffered_lines"] + this.batchSize) <= this.maxBufferedLines) {
|
||||
if (this.printBatches.length > 0 && (this.status["buffered_lines"] + this.batchSize) <= this.maxBufferedLines) {
|
||||
//if (this.printBatches.length > 0 ) {
|
||||
this.printBatch();
|
||||
}
|
||||
@ -164,7 +167,7 @@ D3D.Box.prototype.updateState = function () {
|
||||
var self = this;
|
||||
|
||||
this.getInfoStatus(function (data) {
|
||||
self.printer.status = data;
|
||||
self.status = data;
|
||||
|
||||
if (self.onupdate !== undefined) {
|
||||
self.onupdate(data);
|
||||
@ -264,12 +267,10 @@ D3D.Box.prototype.setConfig = function (data, callback) {
|
||||
|
||||
sendAPI(this.api + "config", data, function (response) {
|
||||
for (var i in response.validation) {
|
||||
if (response.validation[i] !== "ok") {
|
||||
delete data[i];
|
||||
if (response.validation[i] === "ok") {
|
||||
self[i] = data[i];
|
||||
}
|
||||
}
|
||||
self.updateConfig(data);
|
||||
self.printer.updateConfig(data);
|
||||
|
||||
if (callback !== undefined) {
|
||||
callback(response);
|
||||
@ -497,13 +498,13 @@ D3D.Box.prototype.setUpdateClear = function (callback) {
|
||||
*
|
||||
******************************************************/
|
||||
|
||||
D3D.Printer = function (config) {
|
||||
D3D.Printer = function (printerSettings, userSettings) {
|
||||
"use strict";
|
||||
|
||||
this.status = {};
|
||||
this.config = {};
|
||||
|
||||
this.updateConfig(config);
|
||||
this.updateConfig(printerSettings);
|
||||
this.updateConfig(userSettings);
|
||||
};
|
||||
D3D.Printer.prototype.updateConfig = function (config) {
|
||||
"use strict";
|
||||
@ -793,8 +794,6 @@ D3D.Paths.prototype.draw = function (context, color) {
|
||||
|
||||
D3D.Slicer = function () {
|
||||
"use strict";
|
||||
|
||||
this.lines = [];
|
||||
};
|
||||
D3D.Slicer.prototype.setMesh = function (mesh) {
|
||||
"use strict";
|
||||
@ -823,6 +822,7 @@ D3D.Slicer.prototype.setMesh = function (mesh) {
|
||||
mesh.updateMatrix();
|
||||
geometry.applyMatrix(mesh.matrix);
|
||||
geometry.computeFaceNormals();
|
||||
geometry.computeBoundingBox();
|
||||
|
||||
this.geometry = geometry;
|
||||
|
||||
@ -841,7 +841,7 @@ D3D.Slicer.prototype.createLines = function () {
|
||||
function addLine (a, b) {
|
||||
|
||||
//think lookup can only be b_a, a_b is only possible when face is flipped
|
||||
var index = lineLookup[a + "_" + b] || lineLookup[b + "_" + a];
|
||||
var index = lineLookup[b + "_" + a] || lineLookup[a + "_" + b];
|
||||
|
||||
if (index === undefined) {
|
||||
index = self.lines.length;
|
||||
@ -861,8 +861,8 @@ D3D.Slicer.prototype.createLines = function () {
|
||||
for (var i = 0; i < this.geometry.faces.length; i ++) {
|
||||
var face = this.geometry.faces[i];
|
||||
|
||||
//if (face.normal.y !== 1 && face.normal.y !== -1) {
|
||||
var normal = new THREE.Vector2().set(face.normal.x, face.normal.z).normalize();
|
||||
if (face.normal.y !== 1 && face.normal.y !== -1) {
|
||||
var normal = new THREE.Vector2().set(face.normal.z, face.normal.x).normalize();
|
||||
|
||||
//check for only adding unique lines
|
||||
//returns index of said line
|
||||
@ -878,7 +878,7 @@ D3D.Slicer.prototype.createLines = function () {
|
||||
this.lines[a].normals.push(normal);
|
||||
this.lines[b].normals.push(normal);
|
||||
this.lines[c].normals.push(normal);
|
||||
//}
|
||||
}
|
||||
}
|
||||
};
|
||||
D3D.Slicer.prototype.slice = function (height, step) {
|
||||
@ -904,7 +904,10 @@ D3D.Slicer.prototype.slice = function (height, step) {
|
||||
|
||||
var slices = [];
|
||||
|
||||
//still error in first layer, so remove first layer & last layer
|
||||
//see https://github.com/Doodle3D/Doodle3D-Slicer/issues/1
|
||||
for (var layer = 1; layer < layersIntersections.length-1; layer ++) {
|
||||
//for (var layer = 0; layer < layersIntersections.length; layer ++) {
|
||||
var layerIntersections = layersIntersections[layer];
|
||||
var y = layer*step;
|
||||
|
||||
@ -917,11 +920,11 @@ D3D.Slicer.prototype.slice = function (height, step) {
|
||||
var x = line.end.x * alpha + line.start.x * (1 - alpha);
|
||||
var z = line.end.z * alpha + line.start.z * (1 - alpha);
|
||||
|
||||
intersections[index] = new THREE.Vector2(x, z);
|
||||
intersections[index] = new THREE.Vector2(z, x);
|
||||
}
|
||||
|
||||
var done = [];
|
||||
var slice = new D3D.Paths([], true);
|
||||
var slice = [];
|
||||
for (var i = 0; i < layerIntersections.length; i ++) {
|
||||
var index = layerIntersections[i];
|
||||
|
||||
@ -940,7 +943,7 @@ D3D.Slicer.prototype.slice = function (height, step) {
|
||||
index = connects[j];
|
||||
|
||||
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 normal = a.sub(b).normal().normalize();
|
||||
var faceNormal = faceNormals[Math.floor(j/2)];
|
||||
@ -1025,21 +1028,25 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) {
|
||||
|
||||
var layerHeight = printer.config["printer.layerHeight"] * 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 fillSize = printer.config["printer.fillSize"] * scale;
|
||||
var brimOffset = printer.config["printer.brimOffset"] * scale;
|
||||
var skinCount = Math.ceil(shellThickness/layerHeight);
|
||||
var bottomThickness = printer.config["printer.bottomThickness"] * scale;
|
||||
var topThickness = printer.config["printer.topThickness"] * scale;
|
||||
|
||||
var bottomSkinCount = Math.ceil(bottomThickness/layerHeight);
|
||||
var topSkinCount = Math.ceil(topThickness/layerHeight);
|
||||
|
||||
var start = new THREE.Vector2(0, 0);
|
||||
|
||||
var data = [];
|
||||
|
||||
var lowFillTemplate = this.getFillTemplate({
|
||||
left: 0,
|
||||
top: 0,
|
||||
right: dimensionsZ,
|
||||
bottom: dimensionsZ
|
||||
left: this.geometry.boundingBox.min.z * scale,
|
||||
top: this.geometry.boundingBox.min.x * scale,
|
||||
right: this.geometry.boundingBox.max.z * scale,
|
||||
bottom: this.geometry.boundingBox.max.x * scale
|
||||
}, fillSize, true, true);
|
||||
|
||||
for (var layer = 0; layer < slices.length; layer ++) {
|
||||
@ -1049,78 +1056,81 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) {
|
||||
data.push(layerData);
|
||||
|
||||
var downSkin = new D3D.Paths([], true);
|
||||
if (layer - skinCount >= 0) {
|
||||
var downLayer = slices[layer - skinCount];
|
||||
if (layer - bottomSkinCount >= 0) {
|
||||
var downLayer = slices[layer - bottomSkinCount];
|
||||
for (var i = 0; i < downLayer.length; i ++) {
|
||||
downSkin.join(downLayer[i]);
|
||||
}
|
||||
}
|
||||
var upSkin = new D3D.Paths([], true);
|
||||
if (layer + skinCount < slices.length) {
|
||||
var downLayer = slices[layer + skinCount];
|
||||
if (layer + topSkinCount < slices.length) {
|
||||
var downLayer = slices[layer + topSkinCount];
|
||||
for (var i = 0; i < downLayer.length; i ++) {
|
||||
upSkin.join(downLayer[i]);
|
||||
}
|
||||
}
|
||||
var surroundingLayer = upSkin.intersect(downSkin).clone().scaleUp(scale);
|
||||
var surroundingLayer = upSkin.intersect(downSkin).scaleUp(scale);
|
||||
var sliceData = [];
|
||||
|
||||
for (var i = 0; i < slice.length; i ++) {
|
||||
var part = slice[i];
|
||||
|
||||
var outerLayer = part.clone();
|
||||
outerLayer.scaleUp(scale);
|
||||
//var outerLayer = part.clone();
|
||||
var outerLayer = part.clone().scaleUp(scale).offset(-wallThickness/2);
|
||||
|
||||
var insets = new D3D.Paths([], true);
|
||||
for (var offset = wallThickness; offset <= shellThickness; offset += wallThickness) {
|
||||
var inset = outerLayer.offset(-offset);
|
||||
if (outerLayer.length > 0) {
|
||||
var insets = new D3D.Paths([], true);
|
||||
for (var offset = wallThickness; offset <= shellThickness; offset += wallThickness) {
|
||||
var inset = outerLayer.offset(-offset);
|
||||
|
||||
insets.join(inset);
|
||||
insets.join(inset);
|
||||
}
|
||||
|
||||
var fillArea = (inset || outerLayer).offset(-wallThickness/2);
|
||||
//var fillArea = (inset || outerLayer).clone();
|
||||
|
||||
var highFillArea = fillArea.difference(surroundingLayer);
|
||||
|
||||
var lowFillArea = fillArea.difference(highFillArea);
|
||||
|
||||
var fill = new D3D.Paths([], false);
|
||||
|
||||
if (lowFillTemplate.length > 0) {
|
||||
fill.join(lowFillTemplate.intersect(lowFillArea));
|
||||
}
|
||||
|
||||
if (highFillArea.length > 0) {
|
||||
var bounds = highFillArea.bounds();
|
||||
var even = (layer % 2 === 0);
|
||||
var highFillTemplate = this.getFillTemplate(bounds, wallThickness, even, !even);
|
||||
fill.join(highFillTemplate.intersect(highFillArea));
|
||||
}
|
||||
|
||||
outerLayer = outerLayer.optimizePath(start);
|
||||
if (insets.length > 0) {
|
||||
insets = insets.optimizePath(outerLayer.lastPoint());
|
||||
fill = fill.optimizePath(insets.lastPoint());
|
||||
}
|
||||
else {
|
||||
fill = fill.optimizePath(outerLayer.lastPoint());
|
||||
}
|
||||
|
||||
if (fill.length > 0) {
|
||||
start = fill.lastPoint();
|
||||
}
|
||||
else if (insets.length > 0) {
|
||||
start = insets.lastPoint();
|
||||
}
|
||||
else {
|
||||
start = outerLayer.lastPoint();
|
||||
}
|
||||
|
||||
layerData.push({
|
||||
outerLayer: outerLayer.scaleDown(scale),
|
||||
fill: fill.scaleDown(scale),
|
||||
insets: insets.scaleDown(scale)
|
||||
});
|
||||
}
|
||||
|
||||
var fillArea = (inset || outerLayer).offset(-wallThickness/2);
|
||||
//var fillArea = (inset || outerLayer).clone();
|
||||
|
||||
var highFillArea = fillArea.difference(surroundingLayer);
|
||||
|
||||
var lowFillArea = fillArea.difference(highFillArea);
|
||||
|
||||
var fill = new D3D.Paths([], false);
|
||||
|
||||
if (lowFillTemplate.length > 0) {
|
||||
fill.join(lowFillTemplate.intersect(lowFillArea));
|
||||
}
|
||||
|
||||
if (highFillArea.length > 0) {
|
||||
var bounds = highFillArea.bounds();
|
||||
var even = (layer % 2 === 0);
|
||||
var highFillTemplate = this.getFillTemplate(bounds, wallThickness, even, !even);
|
||||
fill.join(highFillTemplate.intersect(highFillArea));
|
||||
}
|
||||
|
||||
outerLayer = outerLayer.optimizePath(start);
|
||||
if (insets.length > 0) {
|
||||
insets = insets.optimizePath(outerLayer.lastPoint());
|
||||
fill = fill.optimizePath(insets.lastPoint());
|
||||
}
|
||||
else {
|
||||
fill = fill.optimizePath(outerLayer.lastPoint());
|
||||
}
|
||||
if (fill.length > 0) {
|
||||
start = fill.lastPoint();
|
||||
}
|
||||
else if (insets.length > 0) {
|
||||
start = insets.lastPoint();
|
||||
}
|
||||
else {
|
||||
start = outerLayer.lastPoint();
|
||||
}
|
||||
|
||||
layerData.push({
|
||||
outerLayer: outerLayer.scaleDown(scale),
|
||||
fill: fill.scaleDown(scale),
|
||||
insets: insets.scaleDown(scale)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@ -1132,12 +1142,12 @@ D3D.Slicer.prototype.getFillTemplate = function (bounds, size, even, uneven) {
|
||||
var paths = new D3D.Paths([], false);
|
||||
|
||||
if (even) {
|
||||
for (var length = Math.floor(bounds.left); length <= Math.ceil(bounds.right); length += size) {
|
||||
for (var length = Math.floor(bounds.left/size)*size; length <= Math.ceil(bounds.right/size)*size; length += size) {
|
||||
paths.push([{X: length, Y: bounds.top}, {X: length, Y: bounds.bottom}]);
|
||||
}
|
||||
}
|
||||
if (uneven) {
|
||||
for (var length = Math.floor(bounds.top); length <= Math.floor(bounds.bottom); length += size) {
|
||||
for (var length = Math.floor(bounds.top/size)*size; length <= Math.floor(bounds.bottom/size)*size; length += size) {
|
||||
paths.push([{X: bounds.left, Y: length}, {X: bounds.right, Y: length}]);
|
||||
}
|
||||
}
|
||||
@ -1201,8 +1211,8 @@ D3D.Slicer.prototype.dataToGcode = function (data, printer) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
var a = new THREE.Vector2().set(point.X, point.Y);
|
||||
var b = new THREE.Vector2().set(previousPoint.X, previousPoint.Y);
|
||||
var a = new THREE.Vector2(point.X, point.Y);
|
||||
var b = new THREE.Vector2(previousPoint.X, previousPoint.Y);
|
||||
var lineLength = a.distanceTo(b);
|
||||
|
||||
extruder += lineLength * wallThickness * layerHeight / filamentSurfaceArea * flowRate;
|
||||
@ -1251,6 +1261,7 @@ D3D.Slicer.prototype.dataToGcode = function (data, printer) {
|
||||
}
|
||||
|
||||
gcode = gcode.concat(printer.getEndCode());
|
||||
|
||||
return gcode;
|
||||
};
|
||||
//only for debug purposes
|
||||
@ -1292,29 +1303,16 @@ D3D.Slicer.prototype.getGcode = function (printer) {
|
||||
var start = new Date().getTime();
|
||||
var slices = this.slice(dimensionsZ, layerHeight);
|
||||
var end = new Date().getTime();
|
||||
|
||||
console.log("Slicing: " + (end - start) + "ms");
|
||||
|
||||
//still error in first layer, so remove first layer
|
||||
//see https://github.com/Doodle3D/Doodle3D-Slicer/issues/1
|
||||
|
||||
var start = new Date().getTime();
|
||||
var data = this.slicesToData(slices, printer);
|
||||
var end = new Date().getTime();
|
||||
|
||||
console.log("Data: " + (end - start) + "ms");
|
||||
|
||||
//return data;
|
||||
|
||||
//TODO
|
||||
//make the path more optimized for 3d printers
|
||||
//make the printer follow the shortest path from line to line
|
||||
//see https://github.com/Ultimaker/CuraEngine#gcode-generation
|
||||
|
||||
var start = new Date().getTime();
|
||||
var gcode = this.dataToGcode(data, printer);
|
||||
var end = new Date().getTime();
|
||||
|
||||
console.log("Gcode: " + (end - start) + "ms");
|
||||
|
||||
return gcode;
|
||||
|
2
build/d3d.min.js
vendored
2
build/d3d.min.js
vendored
File diff suppressed because one or more lines are too long
16
settings/printer_settings.json
Normal file
16
settings/printer_settings.json
Normal file
@ -0,0 +1,16 @@
|
||||
{
|
||||
"ultimaker": {
|
||||
"printer.baudrate": "115200",
|
||||
"printer.dimensions.x": 200,
|
||||
"printer.dimensions.y": 200,
|
||||
"printer.dimensions.z": 200,
|
||||
"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.heatedbed": false,
|
||||
"printer.heatup.bed.temperature": 70,
|
||||
"printer.heatup.enabled": true,
|
||||
"printer.heatup.temperature": 180,
|
||||
"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.type": "ultimaker"
|
||||
}
|
||||
}
|
18
settings/user_settings.json
Normal file
18
settings/user_settings.json
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"printer.retraction.speed": 50,
|
||||
"printer.retraction.minDistance": 5,
|
||||
"printer.retraction.amount": 3,
|
||||
"printer.retraction.enabled": true,
|
||||
"printer.speed": 50,
|
||||
"printer.wallThickness": 0.4,
|
||||
"printer.layerHeight": 0.3,
|
||||
"printer.bottomThickness": 0.4,
|
||||
"printer.topThickness": 0.8,
|
||||
"printer.shellThickness": 0.4,
|
||||
"printer.temperature": 230,
|
||||
"printer.travelSpeed": 200,
|
||||
"printer.fillSize": 5,
|
||||
"printer.firstLayerSlow": true,
|
||||
"printer.bottomLayerSpeed": 35,
|
||||
"printer.bottomFlowRate": 1.0
|
||||
}
|
276
slice_test.html
276
slice_test.html
@ -26,172 +26,158 @@ canvas {border: 1px solid black;}
|
||||
<canvas id="canvas" width="400" height="400"></canvas>
|
||||
|
||||
<script>
|
||||
//nieuwe config
|
||||
//geimplimenteerd worden in de doodlebox?
|
||||
var printer = new D3D.Printer({
|
||||
"printer.baudrate": "115200", //wat is dit?
|
||||
"printer.bottomFlowRate": 1.0,
|
||||
"printer.bottomLayerSpeed": 35,
|
||||
"printer.dimensions.x": 200,
|
||||
"printer.dimensions.y": 200,
|
||||
"printer.dimensions.z": 200,
|
||||
"printer.enableTraveling": true, //wat is dit?
|
||||
"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.retraction.amount": 3,
|
||||
"printer.retraction.minDistance": 5,
|
||||
"printer.retraction.speed": 50,
|
||||
"printer.screenToMillimeterScale": 0.3, //????
|
||||
"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, //wat is dit?
|
||||
var USER_SETTINGS, PRINTER_SETTINGS;
|
||||
|
||||
"printer.retraction.enabled": true,
|
||||
"printer.speed": 50,
|
||||
"printer.wallThickness": 0.4, //nozzle
|
||||
"printer.layerHeight": 0.3,
|
||||
function init () {
|
||||
"use strict";
|
||||
var scene = createScene();
|
||||
|
||||
//variabele toevoegen;
|
||||
//-snelheid, retraction etc voor verschillende types (outerlayer, innerlayer, fill)
|
||||
"printer.bottomThickness": 0.4,
|
||||
"printer.topThickness": 0.8,
|
||||
"printer.shellThickness": 0.4,
|
||||
"printer.fillSize": 5, //dit is het raster aan de binnen kant van de geometry
|
||||
"printer.brimOffset": 5
|
||||
});
|
||||
var localIp = location.hash.substring(1);
|
||||
var doodleBox = new D3D.Box(localIp);
|
||||
|
||||
var localIp = location.hash.substring(1);
|
||||
var doodleBox = new D3D.Box(localIp);
|
||||
//var printer = doodleBox.printer;
|
||||
var printer = new D3D.Printer(USER_SETTINGS, PRINTER_SETTINGS);
|
||||
|
||||
var scene = new THREE.Scene();
|
||||
var loader = new THREE.STLLoader();
|
||||
loader.load("models/pikachu.stl", function (geometry) {
|
||||
//var geometry = new THREE.BoxGeometry(10, 10, 10, 1, 1, 1);
|
||||
//var geometry = new THREE.SphereGeometry(10, 10, 10);
|
||||
//var geometry = new THREE.TorusGeometry(20, 10, 30, 30);
|
||||
/*
|
||||
var geometry = (function () {
|
||||
"use strict";
|
||||
|
||||
var renderer = new THREE.WebGLRenderer({canvas: document.getElementById("3d-preview"), antialias: true});
|
||||
renderer.setClearColor(0xffffff, 1);
|
||||
var circle = new THREE.Shape();
|
||||
circle.absarc(0, 0, 10, 0, Math.PI*2, false);
|
||||
|
||||
var camera = new THREE.PerspectiveCamera(75, renderer.domElement.width/renderer.domElement.height, 1, 10000);
|
||||
scene.add(camera);
|
||||
var hole = new THREE.Path();
|
||||
hole.absarc(0, 0, 5, 0, Math.PI*2, true );
|
||||
|
||||
var light = new THREE.AmbientLight(0x404040);
|
||||
scene.add(light);
|
||||
circle.holes.push(hole);
|
||||
|
||||
var directionalLight = new THREE.PointLight(0xffffff, 0.5);
|
||||
camera.add(directionalLight);
|
||||
var matrix = new THREE.Matrix4();
|
||||
matrix.makeRotationX(Math.PI*1.5);
|
||||
|
||||
applyMouseControls(renderer, camera, new THREE.Vector3(100, 0, 100), 1000);
|
||||
var geometry = new THREE.ExtrudeGeometry(circle, {
|
||||
amount: 10,
|
||||
bevelEnabled: false,
|
||||
steps: 1
|
||||
});
|
||||
geometry.applyMatrix(matrix);
|
||||
|
||||
var loader = new THREE.STLLoader();
|
||||
loader.load("models/pikachu.stl", function (geometry) {
|
||||
//var geometry = new THREE.BoxGeometry(10, 10, 10, 1, 1, 1);
|
||||
//var geometry = new THREE.SphereGeometry(10, 10, 10);
|
||||
//var geometry = new THREE.TorusGeometry(20, 10, 30, 30);
|
||||
/*
|
||||
var geometry = (function () {
|
||||
return geometry;
|
||||
})();
|
||||
*/
|
||||
var material = new THREE.MeshPhongMaterial({color: 0x00ff00});
|
||||
var mesh = new THREE.Mesh(geometry, material);
|
||||
|
||||
mesh.rotation.x = -Math.PI/2;
|
||||
//mesh.rotation.z = Math.PI;
|
||||
mesh.scale.x = mesh.scale.y = mesh.scale.z = 1;
|
||||
mesh.position.x = 100;
|
||||
mesh.position.z = 100;
|
||||
|
||||
scene.add(mesh);
|
||||
|
||||
/*(var slicer = new D3D.Slicer().setMesh(mesh);
|
||||
|
||||
var canvas = document.getElementById("canvas");
|
||||
var context = canvas.getContext("2d");
|
||||
|
||||
var img = slicer.drawPaths(printer, 0, 1);
|
||||
context.drawImage(img, 0, 0);
|
||||
|
||||
gcode = slicer.getGcode(printer);*/
|
||||
});
|
||||
}
|
||||
|
||||
function createScene () {
|
||||
var scene = new THREE.Scene();
|
||||
|
||||
var renderer = new THREE.WebGLRenderer({canvas: document.getElementById("3d-preview"), antialias: true});
|
||||
renderer.setClearColor(0xffffff, 1);
|
||||
|
||||
var camera = new THREE.PerspectiveCamera(75, renderer.domElement.width/renderer.domElement.height, 1, 10000);
|
||||
scene.add(camera);
|
||||
|
||||
var light = new THREE.AmbientLight(0x404040);
|
||||
scene.add(light);
|
||||
|
||||
var directionalLight = new THREE.PointLight(0xffffff, 0.5);
|
||||
camera.add(directionalLight);
|
||||
|
||||
applyMouseControls(renderer, camera, new THREE.Vector3(100, 0, 100), 1000);
|
||||
|
||||
(function animate () {
|
||||
"use strict";
|
||||
|
||||
var circle = new THREE.Shape();
|
||||
circle.absarc(0, 0, 10, 0, Math.PI*2, false);
|
||||
|
||||
var hole = new THREE.Path();
|
||||
hole.absarc(0, 0, 5, 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: 10,
|
||||
bevelEnabled: false,
|
||||
steps: 1
|
||||
});
|
||||
geometry.applyMatrix(matrix);
|
||||
|
||||
return geometry;
|
||||
requestAnimationFrame(animate);
|
||||
renderer.render(scene, camera);
|
||||
})();
|
||||
*/
|
||||
var material = new THREE.MeshPhongMaterial({color: 0x00ff00});
|
||||
var mesh = new THREE.Mesh(geometry, material);
|
||||
|
||||
mesh.rotation.x = -Math.PI/2;
|
||||
//mesh.rotation.z = Math.PI;
|
||||
mesh.scale.x = mesh.scale.y = mesh.scale.z = 1;
|
||||
mesh.position.x = 100;
|
||||
mesh.position.z = 100;
|
||||
function applyMouseControls (renderer, camera, center, maxDistance) {
|
||||
var distance = 20;
|
||||
var rotX = 0;
|
||||
var rotY = 0;
|
||||
var moveCamera = false;
|
||||
|
||||
scene.add(mesh);
|
||||
function updateCamera () {
|
||||
camera.position.set(
|
||||
Math.cos(rotY)*Math.sin(rotX)*distance,
|
||||
Math.sin(rotY)*distance,
|
||||
Math.cos(rotY)*Math.cos(rotX)*distance
|
||||
).add(center);
|
||||
camera.lookAt(center);
|
||||
}
|
||||
|
||||
slicer = new D3D.Slicer().setMesh(mesh);
|
||||
$(renderer.domElement).on("mousedown", function (e) {
|
||||
moveCamera = true;
|
||||
}).on("wheel", function (e) {
|
||||
var event = e.originalEvent;
|
||||
|
||||
var canvas = document.getElementById("canvas");
|
||||
var context = canvas.getContext("2d");
|
||||
|
||||
var img = slicer.drawPaths(printer, 0, 1);
|
||||
context.drawImage(img, 0, 0);
|
||||
|
||||
gcode = slicer.getGcode(printer);
|
||||
});
|
||||
|
||||
(function animate () {
|
||||
"use strict";
|
||||
|
||||
requestAnimationFrame(animate);
|
||||
renderer.render(scene, camera);
|
||||
})();
|
||||
|
||||
function applyMouseControls (renderer, camera, center, maxDistance) {
|
||||
"use strict";
|
||||
//TODO
|
||||
//impliment touch controls
|
||||
//windows mouse wheel fix
|
||||
|
||||
var distance = 20;
|
||||
var rotX = 0;
|
||||
var rotY = 0;
|
||||
var moveCamera = false;
|
||||
|
||||
function updateCamera () {
|
||||
camera.position.set(
|
||||
Math.cos(rotY)*Math.sin(rotX)*distance,
|
||||
Math.sin(rotY)*distance,
|
||||
Math.cos(rotY)*Math.cos(rotX)*distance
|
||||
).add(center);
|
||||
camera.lookAt(center);
|
||||
}
|
||||
|
||||
$(renderer.domElement).on("mousedown", function (e) {
|
||||
moveCamera = true;
|
||||
}).on("wheel", function (e) {
|
||||
var event = e.originalEvent;
|
||||
|
||||
event.preventDefault();
|
||||
distance = THREE.Math.clamp(distance - event.wheelDelta, 1, maxDistance);
|
||||
|
||||
updateCamera();
|
||||
});
|
||||
|
||||
$(window).on("mouseup", function (e) {
|
||||
moveCamera = false;
|
||||
}).on("mousemove", function (e) {
|
||||
var event = e.originalEvent;
|
||||
|
||||
if (moveCamera === true) {
|
||||
rotX = (rotX - event.webkitMovementX/100) % (2*Math.PI);
|
||||
rotY = THREE.Math.clamp(rotY + event.webkitMovementY/100, -Math.PI/2, Math.PI/2);
|
||||
event.preventDefault();
|
||||
distance = THREE.Math.clamp(distance - event.wheelDelta, 1, maxDistance);
|
||||
|
||||
updateCamera();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
updateCamera();
|
||||
$(window).on("mouseup", function (e) {
|
||||
moveCamera = false;
|
||||
}).on("mousemove", function (e) {
|
||||
var event = e.originalEvent;
|
||||
|
||||
if (moveCamera === true) {
|
||||
rotX = (rotX - event.webkitMovementX/100) % (2*Math.PI);
|
||||
rotY = THREE.Math.clamp(rotY + event.webkitMovementY/100, -Math.PI/2, Math.PI/2);
|
||||
|
||||
updateCamera();
|
||||
}
|
||||
});
|
||||
|
||||
updateCamera();
|
||||
}
|
||||
|
||||
return scene;
|
||||
}
|
||||
|
||||
//loadSettings;
|
||||
(function () {
|
||||
var loadedItems = 0;
|
||||
function loaded () {
|
||||
loadedItems ++;
|
||||
if (loadedItems === 2) {
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
||||
loadSettings("settings/user_settings.json", function (data) {
|
||||
USER_SETTINGS = data;
|
||||
loaded();
|
||||
});
|
||||
loadSettings("settings/printer_settings.json", function (data) {
|
||||
PRINTER_SETTINGS = data;
|
||||
loaded();
|
||||
});
|
||||
})();
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
11
src/box.js
11
src/box.js
@ -33,7 +33,6 @@ D3D.Box = function (localIp) {
|
||||
this.getConfigAll(function (data) {
|
||||
self.updateConfig(data);
|
||||
|
||||
self.printer = new D3D.Printer(data);
|
||||
self.update();
|
||||
|
||||
self.loaded = true;
|
||||
@ -46,9 +45,7 @@ D3D.Box.prototype.updateConfig = function (config) {
|
||||
"use strict";
|
||||
|
||||
for (var i in config) {
|
||||
if (i.indexOf("doodle3d") === 0) {
|
||||
this.config[i] = config[i];
|
||||
}
|
||||
this.config[i] = config[i];
|
||||
}
|
||||
|
||||
return this;
|
||||
@ -174,12 +171,10 @@ D3D.Box.prototype.setConfig = function (data, callback) {
|
||||
|
||||
sendAPI(this.api + "config", data, function (response) {
|
||||
for (var i in response.validation) {
|
||||
if (response.validation[i] !== "ok") {
|
||||
delete data[i];
|
||||
if (response.validation[i] === "ok") {
|
||||
self[i] = data[i];
|
||||
}
|
||||
}
|
||||
self.updateConfig(data);
|
||||
self.printer.updateConfig(data);
|
||||
|
||||
if (callback !== undefined) {
|
||||
callback(response);
|
||||
|
@ -5,12 +5,13 @@
|
||||
*
|
||||
******************************************************/
|
||||
|
||||
D3D.Printer = function (config) {
|
||||
D3D.Printer = function (printerSettings, userSettings) {
|
||||
"use strict";
|
||||
|
||||
this.config = {};
|
||||
|
||||
this.updateConfig(config);
|
||||
this.updateConfig(printerSettings);
|
||||
this.updateConfig(userSettings);
|
||||
};
|
||||
D3D.Printer.prototype.updateConfig = function (config) {
|
||||
"use strict";
|
||||
|
14
src/utils.js
14
src/utils.js
@ -59,6 +59,20 @@ function getAPI (url, callback) {
|
||||
});
|
||||
}
|
||||
|
||||
function loadSettings (url, callback) {
|
||||
"use strict";
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
dataType: "json",
|
||||
success: function (response) {
|
||||
if (callback !== undefined) {
|
||||
callback(response);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function downloadFile (file, data) {
|
||||
"use strict";
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user