cleaned up files

This commit is contained in:
casperlamboo 2015-05-01 10:06:52 +02:00
parent 25bee4ebf1
commit d33f0d336c
4 changed files with 82 additions and 52 deletions

View File

@ -16,7 +16,7 @@ doodleBox.onload = function () {
var geometry = new THREE.TorusGeometry(40, 20, 10, 10); var geometry = new THREE.TorusGeometry(40, 20, 10, 10);
var slicer = new D3D.Slicer().setGeometry(geometry); var slicer = new D3D.Slicer().setGeometry(geometry);
var gcode = slicer.getGcode(doodlBox.printer.config); var gcode = slicer.getGcode(doodlBox.printer);
doodleBox.print(gcode); doodleBox.print(gcode);
}; };

View File

@ -43,7 +43,7 @@ var printerConfig = {
"printer.heatup.temperature": 180, "printer.heatup.temperature": 180,
"printer.layerHeight": 0.3, "printer.layerHeight": 0.3,
"printer.retraction.amount": 3, "printer.retraction.amount": 3,
"printer.retraction.enabled": true, "printer.retraction.enabled": false,
"printer.retraction.minDistance": 5, "printer.retraction.minDistance": 5,
"printer.retraction.speed": 50, "printer.retraction.speed": 50,
"printer.screenToMillimeterScale": 0.3, "printer.screenToMillimeterScale": 0.3,
@ -55,12 +55,10 @@ var printerConfig = {
"printer.useSubLayers": true, "printer.useSubLayers": true,
"printer.wallThickness": 0.5 "printer.wallThickness": 0.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);
var doodleBox = {
printer: new D3D.Printer(printerConfig)
};
var scene = new THREE.Scene(); var scene = new THREE.Scene();
@ -72,6 +70,8 @@ var camera = new THREE.PerspectiveCamera(75, renderer.domElement.width/renderer.
applyMouseControls(renderer, camera, 1000); applyMouseControls(renderer, camera, 1000);
var geometry = (function () { var geometry = (function () {
"use strict";
var circle = new THREE.Shape(); var circle = new THREE.Shape();
circle.absarc(0, 0, 20, 0, Math.PI*2, false); circle.absarc(0, 0, 20, 0, Math.PI*2, false);
@ -95,7 +95,7 @@ var geometry = (function () {
var material = new THREE.MeshLambertMaterial({color: 0x000000, wireframe: true}); var material = new THREE.MeshLambertMaterial({color: 0x000000, wireframe: true});
//var geometry = new THREE.TorusGeometry(40, 20, 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(20, 10, 20, 1, 1, 1);
//var geometry = new THREE.SphereGeometry(10, 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);
@ -108,12 +108,14 @@ var context = canvas.getContext("2d");
var slicer = new D3D.Slicer().setGeometry(geometry); var slicer = new D3D.Slicer().setGeometry(geometry);
//slicer.draw(1, context); //slicer.draw(1, context);
var gcode = slicer.getGcode(printerConfig); var gcode = slicer.getGcode(printer);
var canvas = document.getElementById("canvas"); /*var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d"); var context = canvas.getContext("2d");
function drawPolygons (paths, color) { function drawPolygons (paths, color) {
"use strict";
context.fillStyle = color; context.fillStyle = color;
context.strokeStyle = color; context.strokeStyle = color;
context.beginPath(); context.beginPath();
@ -132,19 +134,19 @@ function drawPolygons (paths, color) {
context.stroke(); context.stroke();
} }
//for (var layer = 0; layer < gcode.length; layer ++) { for (var layer = 0; layer < gcode.length; layer ++) {
var layer = 0; //var layer = 31;
var slice = gcode[layer]; var slice = gcode[layer];
console.log(gcode.length);
drawPolygons(slice.outerLayer, "red"); drawPolygons(slice.outerLayer, "red");
drawPolygons(slice.innerLayer, "green"); drawPolygons(slice.innerLayer, "green");
drawPolygons(slice.fill, "blue"); drawPolygons(slice.fill, "blue");
//}*/ }*/
(function animate () { (function animate () {
"use strict";
requestAnimationFrame(animate); requestAnimationFrame(animate);
renderer.render(scene, camera); renderer.render(scene, camera);

View File

@ -36,7 +36,6 @@ D3D.Slicer.prototype.addLine = function (a, b) {
//think lookup can only be b_a, a_b is only possible when face is flipped //think lookup can only be b_a, a_b is only possible when face is flipped
var index = this.lineLookup[a + "_" + b] || this.lineLookup[b + "_" + a]; var index = this.lineLookup[a + "_" + b] || this.lineLookup[b + "_" + a];
//if (!index) {
if (index === undefined) { if (index === undefined) {
index = this.lines.length; index = this.lines.length;
this.lineLookup[a + "_" + b] = index; this.lineLookup[a + "_" + b] = index;
@ -197,7 +196,7 @@ D3D.Slicer.prototype.getFillTemplate = function (dimension, size, even, uneven)
return paths; return paths;
}; };
D3D.Slicer.prototype.slicesToData = function (slices, config) { D3D.Slicer.prototype.slicesToData = function (slices, printer) {
"use strict"; "use strict";
var data = []; var data = [];
@ -205,20 +204,21 @@ D3D.Slicer.prototype.slicesToData = function (slices, config) {
//scale because of clipper crap //scale because of clipper crap
var scale = 100; var scale = 100;
var layerHeight = config["printer.layerHeight"] * scale; var layerHeight = printer.config["printer.layerHeight"] * scale;
var dimensionsZ = config["printer.dimensions.z"] * scale; var dimensionsZ = printer.config["printer.dimensions.z"] * scale;
//variables should come from config //variables should come from config
//aan rick voorleggen //aan rick voorleggen
var nozzleSize = 0.4 * scale; var nozzleSize = 0.4 * scale;
var shellThickness = 0.8 * scale; var shellThickness = 0.8 * scale;
var fillSize = 5 * scale; var fillSize = 5 * scale;
var brimOffset = 5 * scale;
var lowFillTemplate = this.getFillTemplate(dimensionsZ, fillSize, true, true); var lowFillTemplate = this.getFillTemplate(dimensionsZ, fillSize, true, true);
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)); var highFillTemplate = this.getFillTemplate(dimensionsZ, nozzleSize, (layer % 2 === 0), (layer % 2 === 1));
//var outerLayer = ClipperLib.JS.Clean(slice, 1.0); //var outerLayer = ClipperLib.JS.Clean(slice, 1.0);
var outerLayer = slice.clone(); var outerLayer = slice.clone();
@ -241,7 +241,7 @@ D3D.Slicer.prototype.slicesToData = function (slices, config) {
var newLayer = ClipperLib.JS.Clone(slices[layer + i]); var newLayer = ClipperLib.JS.Clone(slices[layer + i]);
ClipperLib.JS.ScaleUpPaths(newLayer, scale); ClipperLib.JS.ScaleUpPaths(newLayer, scale);
if (newLayer.length === 0) { if (newLayer.length === 0 || (fillAbove && fillAbove.length === 0)) {
fillAbove = []; fillAbove = [];
break; break;
@ -299,6 +299,12 @@ D3D.Slicer.prototype.slicesToData = function (slices, config) {
fill = fill.concat(highFillStrokes); fill = fill.concat(highFillStrokes);
//create brim
if (layer === 0) {
var brim = this.getInset(outerLayer, -brimOffset);
outerLayer = brim.concat(outerLayer);
}
ClipperLib.JS.ScaleDownPaths(outerLayer, scale); ClipperLib.JS.ScaleDownPaths(outerLayer, scale);
ClipperLib.JS.ScaleDownPaths(innerLayer, scale); ClipperLib.JS.ScaleDownPaths(innerLayer, scale);
ClipperLib.JS.ScaleDownPaths(fill, scale); ClipperLib.JS.ScaleDownPaths(fill, scale);
@ -312,10 +318,26 @@ D3D.Slicer.prototype.slicesToData = function (slices, config) {
return data; return data;
}; };
D3D.Slicer.prototype.getGcode = function (config) { D3D.Slicer.prototype.dataToGcode = function (data, printer) {
"use strict"; "use strict";
var layerHeight = printer.config["printer.layerHeight"];
var normalSpeed = printer.config["printer.speed"];
var bottomSpeed = printer.config["printer.bottomLayerSpeed"];
var firstLayerSlow = printer.config["printer.firstLayerSlow"];
var bottomFlowRate = printer.config["printer.bottomFlowRate"];
var travelSpeed = printer.config["printer.travelSpeed"];
var filamentThickness = printer.config["printer.filamentThickness"];
var wallThickness = printer.config["printer.wallThickness"];
var enableTraveling = printer.config["printer.enableTraveling"];
var retractionEnabled = printer.config["printer.retraction.enabled"];
var retractionSpeed = printer.config["printer.retraction.speed"];
var retractionMinDistance = printer.config["printer.retraction.minDistance"];
var retractionAmount = printer.config["printer.retraction.amount"];
function sliceToGcode (slice) { function sliceToGcode (slice) {
"use strict";
var gcode = []; var gcode = [];
for (var i = 0; i < slice.length; i ++) { for (var i = 0; i < slice.length; i ++) {
@ -374,41 +396,13 @@ D3D.Slicer.prototype.getGcode = function (config) {
return gcode; return gcode;
} }
var normalSpeed = config["printer.speed"]; var gcode = printer.getStartCode();
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 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);
var filamentSurfaceArea = Math.pow((filamentThickness/2), 2) * Math.PI; var filamentSurfaceArea = Math.pow((filamentThickness/2), 2) * Math.PI;
var flowRate = bottomFlowRate; 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 ++) { for (var layer = 0; layer < data.length; layer ++) {
var slice = data[layer]; var slice = data[layer];
@ -426,6 +420,28 @@ D3D.Slicer.prototype.getGcode = function (config) {
gcode = gcode.concat(sliceToGcode(slice.fill)); gcode = gcode.concat(sliceToGcode(slice.fill));
} }
gcode = gcode.concat(doodleBox.printer.getEndCode()); gcode = gcode.concat(printer.getEndCode());
return gcode;
};
D3D.Slicer.prototype.getGcode = function (printer) {
"use strict";
var layerHeight = printer.config["printer.layerHeight"];
var dimensionsZ = printer.config["printer.dimensions.z"];
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();
var data = this.slicesToData(slices, printer);
//return data;
//TODO
//make the path more optimized for 3d printers
//make the printer follow the shortest path from line to line
var gcode = this.dataToGcode(data, printer);
return gcode; return gcode;
}; };

View File

@ -13,6 +13,8 @@ var D3D = {
//add normal function to Three.js Vector class //add normal function to Three.js Vector class
THREE.Vector2.prototype.normal = function () { THREE.Vector2.prototype.normal = function () {
"use strict";
var x = this.y; var x = this.y;
var y = -this.x; var y = -this.x;
@ -29,6 +31,8 @@ function sendAPI (url, data, callback) {
dataType: "json", dataType: "json",
timeout: 10000, timeout: 10000,
success: function (response) { success: function (response) {
"use strict";
if (response.status === "success") { if (response.status === "success") {
if (callback !== undefined) { if (callback !== undefined) {
callback(response.data); callback(response.data);
@ -39,6 +43,7 @@ function sendAPI (url, data, callback) {
} }
} }
}).fail(function () { }).fail(function () {
"use strict";
console.warn("failed connecting to " + url); console.warn("failed connecting to " + url);
sendAPI(url, data, callback); sendAPI(url, data, callback);
@ -53,6 +58,8 @@ function getAPI (url, callback) {
dataType: "json", dataType: "json",
timeout: 5000, timeout: 5000,
success: function (response) { success: function (response) {
"use strict";
if (response.status === "success") { if (response.status === "success") {
if (callback !== undefined) { if (callback !== undefined) {
callback(response.data); callback(response.data);
@ -63,6 +70,7 @@ function getAPI (url, callback) {
} }
} }
}).fail(function () { }).fail(function () {
"use strict";
console.warn("failed connecting to " + url); console.warn("failed connecting to " + url);
getAPI(url, callback); getAPI(url, callback);
@ -70,6 +78,8 @@ function getAPI (url, callback) {
} }
function downloadFile (file, data) { function downloadFile (file, data) {
"use strict";
$(document.createElement("a")).attr({ $(document.createElement("a")).attr({
download: file, download: file,
href: "data:text/plain," + data href: "data:text/plain," + data
@ -98,6 +108,7 @@ function applyMouseControls (renderer, camera, maxDistance) {
var rotX = 0; var rotX = 0;
var rotY = 0; var rotY = 0;
var moveCamera = false; var moveCamera = false;
function updateCamera () { function updateCamera () {
"use strict"; "use strict";
@ -127,6 +138,7 @@ function applyMouseControls (renderer, camera, maxDistance) {
moveCamera = false; moveCamera = false;
}).on("mousemove", function (e) { }).on("mousemove", function (e) {
"use strict"; "use strict";
var event = e.originalEvent;
if (moveCamera === true) { if (moveCamera === true) {
rotX = (rotX - event.webkitMovementX/100) % (2*Math.PI); rotX = (rotX - event.webkitMovementX/100) % (2*Math.PI);