mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-12-23 03:23:48 +01:00
cleaned up files
This commit is contained in:
parent
25bee4ebf1
commit
d33f0d336c
@ -16,7 +16,7 @@ doodleBox.onload = function () {
|
||||
var geometry = new THREE.TorusGeometry(40, 20, 10, 10);
|
||||
|
||||
var slicer = new D3D.Slicer().setGeometry(geometry);
|
||||
var gcode = slicer.getGcode(doodlBox.printer.config);
|
||||
var gcode = slicer.getGcode(doodlBox.printer);
|
||||
|
||||
doodleBox.print(gcode);
|
||||
};
|
||||
|
@ -43,7 +43,7 @@ var printerConfig = {
|
||||
"printer.heatup.temperature": 180,
|
||||
"printer.layerHeight": 0.3,
|
||||
"printer.retraction.amount": 3,
|
||||
"printer.retraction.enabled": true,
|
||||
"printer.retraction.enabled": false,
|
||||
"printer.retraction.minDistance": 5,
|
||||
"printer.retraction.speed": 50,
|
||||
"printer.screenToMillimeterScale": 0.3,
|
||||
@ -55,12 +55,10 @@ var printerConfig = {
|
||||
"printer.useSubLayers": true,
|
||||
"printer.wallThickness": 0.5
|
||||
};
|
||||
var printer = new D3D.Printer(printerConfig);
|
||||
|
||||
//var localIp = location.hash.substring(1);
|
||||
//var doodleBox = new D3D.Box(localIp);
|
||||
var doodleBox = {
|
||||
printer: new D3D.Printer(printerConfig)
|
||||
};
|
||||
var localIp = location.hash.substring(1);
|
||||
var doodleBox = new D3D.Box(localIp);
|
||||
|
||||
var scene = new THREE.Scene();
|
||||
|
||||
@ -72,6 +70,8 @@ var camera = new THREE.PerspectiveCamera(75, renderer.domElement.width/renderer.
|
||||
applyMouseControls(renderer, camera, 1000);
|
||||
|
||||
var geometry = (function () {
|
||||
"use strict";
|
||||
|
||||
var circle = new THREE.Shape();
|
||||
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 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 mesh = new THREE.Mesh(geometry, material);
|
||||
scene.add(mesh);
|
||||
@ -108,12 +108,14 @@ var context = canvas.getContext("2d");
|
||||
var slicer = new D3D.Slicer().setGeometry(geometry);
|
||||
//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");
|
||||
|
||||
function drawPolygons (paths, color) {
|
||||
"use strict";
|
||||
|
||||
context.fillStyle = color;
|
||||
context.strokeStyle = color;
|
||||
context.beginPath();
|
||||
@ -132,19 +134,19 @@ function drawPolygons (paths, color) {
|
||||
context.stroke();
|
||||
}
|
||||
|
||||
//for (var layer = 0; layer < gcode.length; layer ++) {
|
||||
var layer = 0;
|
||||
for (var layer = 0; layer < gcode.length; layer ++) {
|
||||
//var layer = 31;
|
||||
var slice = gcode[layer];
|
||||
|
||||
console.log(gcode.length);
|
||||
|
||||
drawPolygons(slice.outerLayer, "red");
|
||||
drawPolygons(slice.innerLayer, "green");
|
||||
drawPolygons(slice.fill, "blue");
|
||||
//}*/
|
||||
}*/
|
||||
|
||||
|
||||
(function animate () {
|
||||
"use strict";
|
||||
|
||||
requestAnimationFrame(animate);
|
||||
|
||||
renderer.render(scene, camera);
|
||||
|
@ -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
|
||||
var index = this.lineLookup[a + "_" + b] || this.lineLookup[b + "_" + a];
|
||||
|
||||
//if (!index) {
|
||||
if (index === undefined) {
|
||||
index = this.lines.length;
|
||||
this.lineLookup[a + "_" + b] = index;
|
||||
@ -197,7 +196,7 @@ D3D.Slicer.prototype.getFillTemplate = function (dimension, size, even, uneven)
|
||||
|
||||
return paths;
|
||||
};
|
||||
D3D.Slicer.prototype.slicesToData = function (slices, config) {
|
||||
D3D.Slicer.prototype.slicesToData = function (slices, printer) {
|
||||
"use strict";
|
||||
|
||||
var data = [];
|
||||
@ -205,20 +204,21 @@ D3D.Slicer.prototype.slicesToData = function (slices, config) {
|
||||
//scale because of clipper crap
|
||||
var scale = 100;
|
||||
|
||||
var layerHeight = config["printer.layerHeight"] * scale;
|
||||
var dimensionsZ = config["printer.dimensions.z"] * scale;
|
||||
var layerHeight = printer.config["printer.layerHeight"] * scale;
|
||||
var dimensionsZ = printer.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 brimOffset = 5 * scale;
|
||||
|
||||
var lowFillTemplate = this.getFillTemplate(dimensionsZ, fillSize, true, true);
|
||||
|
||||
|
||||
for (var layer = 0; layer < slices.length; 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 = slice.clone();
|
||||
@ -241,7 +241,7 @@ D3D.Slicer.prototype.slicesToData = function (slices, config) {
|
||||
var newLayer = ClipperLib.JS.Clone(slices[layer + i]);
|
||||
ClipperLib.JS.ScaleUpPaths(newLayer, scale);
|
||||
|
||||
if (newLayer.length === 0) {
|
||||
if (newLayer.length === 0 || (fillAbove && fillAbove.length === 0)) {
|
||||
fillAbove = [];
|
||||
|
||||
break;
|
||||
@ -299,6 +299,12 @@ D3D.Slicer.prototype.slicesToData = function (slices, config) {
|
||||
|
||||
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(innerLayer, scale);
|
||||
ClipperLib.JS.ScaleDownPaths(fill, scale);
|
||||
@ -312,10 +318,26 @@ D3D.Slicer.prototype.slicesToData = function (slices, config) {
|
||||
|
||||
return data;
|
||||
};
|
||||
D3D.Slicer.prototype.getGcode = function (config) {
|
||||
D3D.Slicer.prototype.dataToGcode = function (data, printer) {
|
||||
"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) {
|
||||
"use strict";
|
||||
|
||||
var gcode = [];
|
||||
|
||||
for (var i = 0; i < slice.length; i ++) {
|
||||
@ -374,41 +396,13 @@ D3D.Slicer.prototype.getGcode = function (config) {
|
||||
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 gcode = 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];
|
||||
|
||||
@ -426,6 +420,28 @@ D3D.Slicer.prototype.getGcode = function (config) {
|
||||
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;
|
||||
};
|
12
src/utils.js
12
src/utils.js
@ -13,6 +13,8 @@ var D3D = {
|
||||
|
||||
//add normal function to Three.js Vector class
|
||||
THREE.Vector2.prototype.normal = function () {
|
||||
"use strict";
|
||||
|
||||
var x = this.y;
|
||||
var y = -this.x;
|
||||
|
||||
@ -29,6 +31,8 @@ function sendAPI (url, data, callback) {
|
||||
dataType: "json",
|
||||
timeout: 10000,
|
||||
success: function (response) {
|
||||
"use strict";
|
||||
|
||||
if (response.status === "success") {
|
||||
if (callback !== undefined) {
|
||||
callback(response.data);
|
||||
@ -39,6 +43,7 @@ function sendAPI (url, data, callback) {
|
||||
}
|
||||
}
|
||||
}).fail(function () {
|
||||
"use strict";
|
||||
|
||||
console.warn("failed connecting to " + url);
|
||||
sendAPI(url, data, callback);
|
||||
@ -53,6 +58,8 @@ function getAPI (url, callback) {
|
||||
dataType: "json",
|
||||
timeout: 5000,
|
||||
success: function (response) {
|
||||
"use strict";
|
||||
|
||||
if (response.status === "success") {
|
||||
if (callback !== undefined) {
|
||||
callback(response.data);
|
||||
@ -63,6 +70,7 @@ function getAPI (url, callback) {
|
||||
}
|
||||
}
|
||||
}).fail(function () {
|
||||
"use strict";
|
||||
|
||||
console.warn("failed connecting to " + url);
|
||||
getAPI(url, callback);
|
||||
@ -70,6 +78,8 @@ function getAPI (url, callback) {
|
||||
}
|
||||
|
||||
function downloadFile (file, data) {
|
||||
"use strict";
|
||||
|
||||
$(document.createElement("a")).attr({
|
||||
download: file,
|
||||
href: "data:text/plain," + data
|
||||
@ -98,6 +108,7 @@ function applyMouseControls (renderer, camera, maxDistance) {
|
||||
var rotX = 0;
|
||||
var rotY = 0;
|
||||
var moveCamera = false;
|
||||
|
||||
function updateCamera () {
|
||||
"use strict";
|
||||
|
||||
@ -127,6 +138,7 @@ function applyMouseControls (renderer, camera, maxDistance) {
|
||||
moveCamera = false;
|
||||
}).on("mousemove", function (e) {
|
||||
"use strict";
|
||||
var event = e.originalEvent;
|
||||
|
||||
if (moveCamera === true) {
|
||||
rotX = (rotX - event.webkitMovementX/100) % (2*Math.PI);
|
||||
|
Loading…
Reference in New Issue
Block a user