added gcode class, removed gulp

gulp didn’t make any more sense to use because it is build modulair
feature/interface
casperlamboo 7 years ago
parent 67362c4ba8
commit 38bf3c74f3
  1. 1319
      build/d3d.js
  2. 1
      build/d3d.min.js
  3. 27
      gulpfile.js
  4. 4
      index.html
  5. BIN
      models/ultimaker_robot.stl
  6. 32
      settings/printer_settings.json
  7. 2
      settings/user_settings.json
  8. 3
      slice_test.html
  9. 23
      src/box.js
  10. 132
      src/gcode.js
  11. 3
      src/printer.js
  12. 146
      src/slicer.js
  13. 50
      src/slicerworker.js
  14. 1
      webworker/worker.js
  15. 108
      webworker_test.html

1319
build/d3d.js vendored

File diff suppressed because it is too large Load Diff

1
build/d3d.min.js vendored

File diff suppressed because one or more lines are too long

@ -1,27 +0,0 @@
'use strict';
var gulp = require('gulp');
var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var watch = require('gulp-watch');
var files = [
"src/utils.js",
"src/box.js",
"src/printer.js",
"src/paths.js",
"src/slicer.js"
];
var destination = 'build/';
gulp.task('default', function () {
return gulp.src(files)
// .pipe(watch(files))
.pipe(concat('d3d.js'))
.pipe(gulp.dest(destination))
.pipe(uglify())
.pipe(rename({extname: '.min.js'}))
.pipe(gulp.dest(destination));
});

@ -26,6 +26,10 @@ $(document).ready(function () {
listSliceTest.append("<li><a href='slice_test.html#192.168.5.1'>Wired Printer</a></li>");
listSliceWebworker.append("<li><a href='webworker_test.html#192.168.5.1'>Wired Printer</a></li>");
listDoodle.append("<li><a href='doodle.html#" + window.location.host + ":3000'>Node Server</a></li>");
listSliceTest.append("<li><a href='slice_test.html#" + window.location.host + ":3000'>Node Server</a></li>");
listSliceWebworker.append("<li><a href='webworker_test.html#" + window.location.host + ":3000'>Node Server</a></li>");
/*
printers.push({
name: "wired box",

Binary file not shown.

@ -5,7 +5,7 @@
"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.filamentThickness": 2.85,
"printer.heatedbed": false,
"printer.heatup.bed.temperature": 70,
"printer.heatup.enabled": true,
@ -13,5 +13,35 @@
"printer.nozzleDiameter": 0.4,
"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"
},
"ultimaker2": {
"printer.baudrate": "115200",
"printer.dimensions.x": 223,
"printer.dimensions.y": 223,
"printer.dimensions.z": 205,
"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+5.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 ;home the printer\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.85,
"printer.heatedbed": true,
"printer.heatup.bed.temperature": 70,
"printer.heatup.enabled": true,
"printer.heatup.temperature": 180,
"printer.nozzleDiameter": 0.4,
"printer.startcode": ";Generated with Doodle3D (ultimaker2)\nM109 S{printingTemp} ;set target temperature \n{if heatedBed}M190 S{printingBedTemp} ;set target bed temperature\nG21 ;metric values\nG90 ;absolute positioning\nM107 ;start with the fan off\nG28 ; home to 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\nG1 F9000\nM117 Printing Doodle... ;display message (20 characters to clear whole screen)",
"printer.type": "ultimaker2"
},
"ultimaker2go": {
"printer.baudrate": "115200",
"printer.dimensions.x": 120,
"printer.dimensions.y": 120,
"printer.dimensions.z": 115,
"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+5.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\nG28 ;home the printer\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.85,
"printer.heatedbed": false,
"printer.heatup.bed.temperature": 70,
"printer.heatup.enabled": true,
"printer.heatup.temperature": 180,
"printer.nozzleDiameter": 0.4,
"printer.startcode": ";Generated with Doodle3D (ultimaker2)\nM109 S{printingTemp} ;set target temperature \n{if heatedBed}M190 S{printingBedTemp} ;set target bed temperature\nG21 ;metric values\nG90 ;absolute positioning\nM107 ;start with the fan off\nG28 ; home to 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\nG1 F9000\nM117 Printing Doodle... ;display message (20 characters to clear whole screen)",
"printer.type": "ultimaker2g0"
}
}

@ -12,7 +12,7 @@
"printer.retraction.minDistance": 5.0,
"printer.shellThickness": 0.4,
"printer.speed": 50.0,
"printer.temperature": 230.0,
"printer.temperature": 210.0,
"printer.topThickness": 0.8,
"printer.travelSpeed": 200.0
}

@ -12,6 +12,7 @@
<script src="src/box.js"></script>
<script src="src/printer.js"></script>
<script src="src/paths.js"></script>
<script src="src/gcode.js"></script>
<script src="src/slicer.js"></script>
<style>
@ -36,7 +37,7 @@ function init () {
var loader = new THREE.STLLoader();
loader.load("models/dom.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, 20, 10);
//var geometry = new THREE.TorusGeometry(20, 10, 30, 30);
/*

@ -21,7 +21,7 @@ D3D.Box = function (localIp) {
this.localIp = localIp;
this.api = "http://" + localIp + "/d3dapi/";
this.config = {};
this.status = {};
@ -105,7 +105,8 @@ D3D.Box.prototype.printBatch = function () {
this.setPrinterPrint({
"start": ((this.currentBatch === 0) ? true : false),
"first": ((this.currentBatch === 0) ? true : false),
"gcode": gcode.join("\n")
"gcode": gcode.join("\n"),
"last": ((this.printBatches.length === 0) ? true : false) //only for debug purposes
}, function (data) {
console.log("batch sent: " + self.currentBatch, data);
@ -120,28 +121,14 @@ D3D.Box.prototype.printBatch = function () {
self.updateState();
});
};
D3D.Box.prototype.stopPrint = function () {
D3D.Box.prototype.stopPrint = function (printer) {
"use strict";
this.printBatches = [];
this.currentBatch = 0;
var finishMove = [
"M107 ;fan off",
"G91 ;relative positioning",
"G1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure",
"G1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more",
"G28 X0 Y0 ;move X/Y to min endstops, so the head is out of the way",
"M84 ;disable axes / steppers",
"G90 ;absolute positioning",
"M104 S180",
";M140 S70",
"M117 Done ;display message (20 characters to clear whole screen)"
];
this.setPrinterStop({
//"gcode": {}
"gcode": finishMove.join("\n")
"gcode": printer.getEndCode().join("\n")
}, function (data) {
console.log("Printer stop command sent");
});

@ -0,0 +1,132 @@
/******************************************************
*
* GCode
*
* Manages the gcode
*
******************************************************/
D3D.GCode = function () {
"use strict";
this.extruder = 0.0;
this.bottom = true;
this.isRetracted = false;
this.gcode = [];
this.nozzlePosition = new THREE.Vector2(0, 0);
};
D3D.GCode.prototype.setSettings = function (printer) {
"use strict";
this.settings = printer;
return this;
};
D3D.GCode.prototype.turnOnFan = function () {
"use strict";
this.gcode.push("M106");
};
D3D.GCode.prototype.moveTo = function (extrude, x, y, layer) {
"use strict";
var layerHeight = this.settings.config["printer.layerHeight"];
var firstLayerSlow = this.settings.config["printer.firstLayerSlow"];
var normalSpeed = this.settings.config["printer.speed"];
var bottomSpeed = this.settings.config["printer.bottomLayerSpeed"];
var normalSpeed = this.settings.config["printer.speed"];
var bottomSpeed = this.settings.config["printer.bottomLayerSpeed"];
var nozzleDiameter = this.settings.config["printer.nozzleDiameter"];
var filamentThickness = this.settings.config["printer.filamentThickness"];
var bottomFlowRate = this.settings.config["printer.bottomFlowRate"];
var normalFlowRate = this.settings.config["printer.normalFlowRate"];
var travelSpeed = this.settings.config["printer.travelSpeed"];
if (this.bottom) {
var speed = bottomSpeed * 60;
var flowRate = bottomFlowRate;
}
else {
var speed = normalSpeed * 60;
var flowRate = normalFlowRate;
}
var z = (layer + 1) * layerHeight;
if (extrude) {
var lineLength = this.nozzlePosition.distanceTo(new THREE.Vector2(x, y));
var filamentSurfaceArea = Math.pow((filamentThickness/2), 2) * Math.PI;
this.extruder += lineLength * nozzleDiameter * layerHeight / filamentSurfaceArea * flowRate;
this.gcode.push(
"G1" +
" X" + x.toFixed(3) +
" Y" + y.toFixed(3) +
((z !== this.lastZ) ? (" Z" + z.toFixed(3)) : "") +
((speed !== this.lastSpeed) ? (" F" + speed.toFixed(3)) : "") +
" E" + this.extruder.toFixed(3)
);
}
else {
var speed = travelSpeed * 60;
this.gcode.push(
"G0" +
" X" + x.toFixed(3) + " Y" + y.toFixed(3) + " Z" + z +
" F" + speed.toFixed(3)
);
}
this.lastSpeed = speed;
this.lastZ = z;
this.nozzlePosition = new THREE.Vector2(x, y);
};
D3D.GCode.prototype.unRetract = function () {
"use strict";
this.isRetracted = false;
var retractionAmount = this.settings.config["printer.retraction.amount"];
var retractionEnabled = this.settings.config["printer.retraction.enabled"];
var retractionMinDistance = this.settings.config["printer.retraction.minDistance"];
var retractionSpeed = this.settings.config["printer.retraction.speed"];
var speed = retractionSpeed * 60;
if (this.extruder > retractionMinDistance && retractionEnabled) {
this.gcode.push(
"G0" +
" E" + this.extruder.toFixed(3) +
" F" + (speed * 60).toFixed(3)
);
}
};
D3D.GCode.prototype.retract = function () {
"use strict";
this.isRetracted = true;
var retractionAmount = this.settings.config["printer.retraction.amount"];
var retractionEnabled = this.settings.config["printer.retraction.enabled"];
var retractionMinDistance = this.settings.config["printer.retraction.minDistance"];
var retractionSpeed = this.settings.config["printer.retraction.speed"];
var speed = retractionSpeed * 60;
if (this.extruder > retractionMinDistance && retractionEnabled) {
this.gcode.push(
"G0" +
" E" + (this.extruder - retractionAmount).toFixed(3) +
" F" + speed.toFixed(3)
);
}
this.lastSpeed = speed;
};
D3D.GCode.prototype.getFinal = function () {
"use strict";
return this.settings.getStartCode().concat(this.gcode, this.settings.getEndCode());
};

@ -5,7 +5,7 @@
*
******************************************************/
D3D.Printer = function (printerSettings, userSettings) {
D3D.Printer = function () {
"use strict";
this.config = {};
@ -33,6 +33,7 @@ D3D.Printer.prototype.getEndCode = function () {
"use strict";
var gcode = this.config["printer.endcode"];
gcode = this.subsituteVariables(gcode);
return gcode.split("\n");

@ -8,6 +8,8 @@ D3D.Slicer = function () {
"use strict";
this.progress = {
totalFaces: 0,
currentFace: 0,
totalLayers: 0,
sliceLayer: 0,
dataLayer: 0,
@ -42,7 +44,7 @@ D3D.Slicer.prototype.setMesh = function (geometry, matrix) {
geometry.applyMatrix(matrix);
geometry.computeFaceNormals();
geometry.computeBoundingBox();
this.geometry = geometry;
//get unique lines from geometry;
@ -51,13 +53,25 @@ D3D.Slicer.prototype.setMesh = function (geometry, matrix) {
return this;
};
D3D.Slicer.prototype.updateProgress = function () {
'use strict';
var faces = this.progress.currentFace / (this.progress.totalFaces - 1);
var slice = this.progress.sliceLayer / (this.progress.totalLayers - 1);
var data = this.progress.dataLayer / (this.progress.totalLayers - 2);
var gcode = this.progress.gcodeLayer / (this.progress.totalLayers - 2);
this.progress.procent = (faces + slice + data + gcode) / 4;
if (this.onProgress !== undefined) {
this.onProgress(this.progress);
}
};
D3D.Slicer.prototype.createLines = function () {
"use strict";
this.progress.totalFaces = this.geometry.faces.length;
this.lines = [];
var lineLookup = {};
@ -102,6 +116,9 @@ D3D.Slicer.prototype.createLines = function () {
this.lines[b].normals.push(normal);
this.lines[c].normals.push(normal);
}
this.progress.currentFace = i;
this.updateProgress();
}
};
D3D.Slicer.prototype.slice = function (layerHeight, height) {
@ -129,7 +146,6 @@ D3D.Slicer.prototype.slice = function (layerHeight, height) {
//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 * layerHeight;
@ -139,10 +155,15 @@ D3D.Slicer.prototype.slice = function (layerHeight, height) {
var index = layerIntersections[i];
var line = this.lines[index].line;
var alpha = (y - line.start.y) / (line.end.y - line.start.y);
var x = line.end.x * alpha + line.start.x * (1 - alpha);
var z = line.end.z * alpha + line.start.z * (1 - alpha);
if (line.start.y === line.end.y) {
var x = line.start.x;
var z = line.start.z;
}
else {
var alpha = (y - line.start.y) / (line.end.y - line.start.y);
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(z, x);
}
@ -171,12 +192,12 @@ D3D.Slicer.prototype.slice = function (layerHeight, height) {
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;
//}
//else {
// index = -1;
//}
}
else {
index = -1;
}
}
else {
index = -1;
@ -383,6 +404,7 @@ D3D.Slicer.prototype.getFillTemplate = function (bounds, size, even, uneven) {
//return paths;
return paths;
};
/*
D3D.Slicer.prototype.dataToGcode = function (data, printer) {
"use strict";
@ -418,19 +440,18 @@ D3D.Slicer.prototype.dataToGcode = function (data, printer) {
//TODO
//add retraction
gcode.push([
"G0",
"X" + point.X.toFixed(3) + " Y" + point.Y.toFixed(3) + " Z" + z,
"F" + (travelSpeed * 60)
].join(" "));
gcode.push(
"G0" +
" X" + point.X.toFixed(3) + " Y" + point.Y.toFixed(3) + " Z" + z +
" F" + (travelSpeed * 60)
);
if (extruder > retractionMinDistance && retractionEnabled && j === 0) {
gcode.push([
"G0",
"E" + extruder.toFixed(3),
"F" + (retractionSpeed * 60).toFixed(3)
].join(" "));
gcode.push(
"G0" +
" E" + extruder.toFixed(3) +
" F" + (retractionSpeed * 60).toFixed(3)
);
}
}
@ -441,12 +462,12 @@ D3D.Slicer.prototype.dataToGcode = function (data, printer) {
extruder += lineLength * nozzleDiameter * layerHeight / filamentSurfaceArea * flowRate;
gcode.push([
"G1",
"X" + point.X.toFixed(3) + " Y" + point.Y.toFixed(3) + " Z" + z,
"F" + speed,
"E" + extruder.toFixed(3)
].join(" "));
gcode.push(
"G1" +
" X" + point.X.toFixed(3) + " Y" + point.Y.toFixed(3) + " Z" + z +
" F" + speed +
" E" + extruder.toFixed(3)
);
}
previousPoint = point;
@ -454,11 +475,11 @@ D3D.Slicer.prototype.dataToGcode = function (data, printer) {
}
if (extruder > retractionMinDistance && retractionEnabled) {
gcode.push([
"G0",
"E" + (extruder - retractionAmount).toFixed(3),
"F" + (retractionSpeed * 60).toFixed(3)
].join(" "));
gcode.push(
"G0" +
" E" + (extruder - retractionAmount).toFixed(3) +
" F" + (retractionSpeed * 60).toFixed(3)
);
}
return gcode;
@ -499,35 +520,60 @@ D3D.Slicer.prototype.dataToGcode = function (data, printer) {
return gcode;
};
//only for debug purposes
D3D.Slicer.prototype.drawPaths = function (printer, min, max) {
*/
D3D.Slicer.prototype.dataToGcode = function (data, printer) {
"use strict";
var layerHeight = printer.config["printer.layerHeight"];
var dimensionsZ = printer.config["printer.dimensions.z"];
var gcode = new D3D.GCode().setSettings(printer);
var slices = this.slice(layerHeight, dimensionsZ);
function sliceToGcode (path, retract, unRetract) {
for (var i = 0; i < path.length; i ++) {
var shape = path[i];
var data = this.slicesToData(slices, printer);
var length = path.closed ? (shape.length + 1) : shape.length;
var canvas = document.createElement("canvas");
canvas.width = 400;
canvas.height = 400;
var context = canvas.getContext("2d");
for (var j = 0; j < length; j ++) {
var point = shape[j % shape.length];
for (var layer = min; layer < max; layer ++) {
var slice = data[layer % data.length];
if (j === 0) {
gcode.moveTo(false, point.X, point.Y, layer);
if (unRetract) {
gcode.unRetract();
}
}
else {
gcode.moveTo(true, point.X, point.Y, layer);
}
}
}
if (retract) {
gcode.retract();
}
}
for (var layer = 0; layer < data.length; layer ++) {
var slice = data[layer];
if (layer === 1) {
gcode.turnOnFan();
gcode.bottom = false;
}
for (var i = 0; i < slice.length; i ++) {
var layerPart = slice[i];
layerPart.insets.draw(context, "blue");
layerPart.outerLayer.draw(context, "green");
layerPart.fill.draw(context, "red");
sliceToGcode(layerPart.outerLayer, false, true);
sliceToGcode(layerPart.insets, false, false);
sliceToGcode(layerPart.fill, true, false);
}
this.progress.gcodeLayer = layer;
this.updateProgress();
}
return canvas;
return gcode.getFinal();
};
D3D.Slicer.prototype.getGcode = function (printer) {
"use strict";
@ -535,7 +581,7 @@ D3D.Slicer.prototype.getGcode = function (printer) {
var layerHeight = printer.config["printer.layerHeight"];
var dimensionsZ = printer.config["printer.dimensions.z"];
this.progress.totalLayers = Math.floor(this.geometry.boundingBox.max.y / layerHeight);
this.progress.totalLayers = Math.floor(Math.min(this.geometry.boundingBox.max.y, dimensionsZ) / layerHeight);
this.progress.sliceLayer = 0;
this.progress.dataLayer = 0;
this.progress.gcodeLayer = 0;

@ -1,36 +1,40 @@
D3D.SlicerWorker = function () {
"use strict";
'use strict';
this.worker = new Worker('webworker/worker.js');
var progressBar = document.getElementById("progress-bar");
var scope = this;
this.worker.addEventListener('message', function (event) {
switch (event.data['cmd']) {
case 'PROGRESS':
if (scope.onprogress !== undefined) {
var progress = event.data['progress'];
switch (event.data["cmd"]) {
case "PROGRESS":
var progress = event.data["progress"];
var procent = (progress.sliceLayer + progress.dataLayer + progress.gcodeLayer) / (progress.totalLayers * 3 - 5);
progressBar.style.width = procent * 100 + "%";
scope.onprogress(progress);
}
break;
case "GCODE":
gcode = event.data["gcode"];
case 'GCODE':
if (scope.onfinish !== undefined) {
var gcode = event.data['gcode'];
scope.onfinish(gcode);
}
break;
}
}, false);
}
D3D.SlicerWorker.prototype.setSettings = function (USER_SETTINGS, PRINTER_SETTINGS) {
"use strict";
'use strict';
this.worker.postMessage({
"cmd": "SET_SETTINGS",
"USER_SETTINGS": USER_SETTINGS,
"PRINTER_SETTINGS": PRINTER_SETTINGS
'cmd': 'SET_SETTINGS',
'USER_SETTINGS': USER_SETTINGS,
'PRINTER_SETTINGS': PRINTER_SETTINGS
});
};
D3D.SlicerWorker.prototype.setMesh = function (mesh) {
"use strict";
'use strict';
if (mesh.geometry instanceof THREE.Geometry) {
var geometry = new THREE.BufferGeometry().fromGeometry(mesh.geometry);
@ -49,25 +53,25 @@ D3D.SlicerWorker.prototype.setMesh = function (mesh) {
mesh.updateMatrix();
this.worker.postMessage({
"cmd": "SET_MESH",
"geometry": {
"attributes": geometry.attributes,
"attributesKeys": geometry.attributesKeys
'cmd': 'SET_MESH',
'geometry': {
'attributes': geometry.attributes,
'attributesKeys': geometry.attributesKeys
},
"matrix": mesh.matrix.toArray()
'matrix': mesh.matrix.toArray()
}, buffers);
};
D3D.SlicerWorker.prototype.slice = function () {
"use strict";
'use strict';
this.worker.postMessage({
"cmd": "SLICE"
'cmd': 'SLICE'
});
};
D3D.SlicerWorker.prototype.close = function () {
"use strict";
'use strict';
this.worker.postMessage({
"cmd": "CLOSE"
'cmd': 'CLOSE'
});
};

@ -4,6 +4,7 @@ importScripts("../src/utils.js");
importScripts("../src/printer.js");
importScripts("../src/paths.js");
importScripts("../src/slicer.js");
importScripts("../src/gcode.js");
var printer = new D3D.Printer();
var slicer = new D3D.Slicer();

@ -1,53 +1,101 @@
<!DOCTYPE HTML>
<html lang="en">
<html lang='en'>
<head>
<script src="library/jquery.js"></script>
<script src="library/three.js"></script>
<script src="library/stl_loader.js"></script>
<script src='library/jquery.js'></script>
<script src='library/three.js'></script>
<script src='library/stl_loader.js'></script>
<script src="src/utils.js"></script>
<script src="src/box.js"></script>
<script src="src/slicerworker.js"></script>
<script src='src/utils.js'></script>
<script src='src/box.js'></script>
<script src='src/printer.js'></script>
<script src='src/slicerworker.js'></script>
<title>Doedel Drie Dee || Webworker Test</title>
<style>
canvas {border: 1px solid black;}
#progress {height: 20px; width: 200px; border: 1px solid black; overflow: hidden;}
#progress-bar {height: 20px; background-color: lightblue; width: 0%;}
#progress_bar {height: 20px; background-color: lightblue; width: 0%;}
.block {border: 1px solid black; width: 400px; height: 400px; display: inline-block;}
#start_print {display: none;}
</style>
</head>
<body>
<canvas id="3d-preview" height="400" width="400"></canvas>
<canvas id="canvas" width="400" height="400"></canvas>
<div id="progress"><div id="progress-bar"></div></div>
<canvas id='3d-preview' height='400' width='400'></canvas>
<div class='block'>
<p>State: <span id='state'></span></p>
<p>Bed Temp: <span id='bed_temp'></span></p>
<p>Bed Target Temp: <span id='bed_target_temp'></span></p>
<p>Nozzle Temp: <span id='nozzle_temp'></span></p>
<p>Nozzle Target Temp: <span id='nozzle_target_temp'></span></p>
<p>Current Line: <span id='current_line'></span></p>
<p>Buffered Lines: <span id='buffered_lines'></span></p>
<p>Total Lines: <span id='total_lines'></span></p>
<p>Batches To Send: <span id='print_batches'></span></p>
<div id='progress'><div id='progress_bar'></div></div>
<button id="start_print">Start Print</button>
<button id="stop_print">Stop Print</button>
</div>
<script>
var USER_SETTINGS, PRINTER_SETTINGS, doodleBox, gcode, slicerWorker;
var USER_SETTINGS, PRINTER_SETTINGS, doodleBox, gcode, slicerWorker, printer;
function init () {
"use strict";
'use strict';
var scene = createScene();
var localIp = location.hash.substring(1);
doodleBox = new D3D.Box(localIp);
printer = new D3D.Printer().updateConfig(USER_SETTINGS).updateConfig(PRINTER_SETTINGS['ultimaker2go']);
doodleBox.onupdate = function (data) {
document.getElementById('state').innerHTML = data.state;
document.getElementById('bed_temp').innerHTML = data.bed;
document.getElementById('bed_target_temp').innerHTML = data.bed_target;
document.getElementById('nozzle_temp').innerHTML = data.hotend;
document.getElementById('nozzle_target_temp').innerHTML = data.hotend_target;
document.getElementById('current_line').innerHTML = data.current_line;
document.getElementById('buffered_lines').innerHTML = data.buffered_lines;
document.getElementById('total_lines').innerHTML = data.total_lines;
document.getElementById('print_batches').innerHTML = doodleBox.printBatches.length;
};
document.getElementById('stop_print').onclick = function () {
doodleBox.stopPrint(printer);
};
var slicer = new D3D.SlicerWorker();
slicer.setSettings(USER_SETTINGS, PRINTER_SETTINGS["ultimaker"]);
slicer.setSettings(USER_SETTINGS, PRINTER_SETTINGS['ultimaker2go']);
var progressBar = document.getElementById('progress_bar');
slicer.onprogress = function (progress) {
progressBar.style.width = progress.procent * 100 + '%';
};
slicer.onfinish = function (_gcode) {
gcode = _gcode;
var button = document.getElementById('start_print');
button.style.display = 'initial';
button.onclick = function () {
doodleBox.print(gcode);
};
};
var loader = new THREE.STLLoader();
loader.load("models/dom.stl", function (geometry) {
//var geometry = new THREE.TorusGeometry(20, 10, 30, 30).clone();
loader.load('models/pokemon/pikachu.stl', function (geometry) {
var geometry = new THREE.TorusGeometry(20, 10, 30, 30).clone();
var material = new THREE.MeshPhongMaterial({color: 0x00ff00, wireframe: false});
var mesh = new THREE.Mesh(geometry, material);
mesh.rotation.x = -Math.PI/2;
mesh.scale.x = mesh.scale.y = mesh.scale.z = 1;
//mesh.position.y = -9.260265119962973e-17;
mesh.position.x = 100;
mesh.position.z = 100;
mesh.scale.x = mesh.scale.y = mesh.scale.z = 0.5;
mesh.position.y = -0.1;
mesh.position.x = 60;
mesh.position.z = 60;
scene.add(mesh);
@ -61,7 +109,7 @@ function init () {
function createScene () {
var scene = new THREE.Scene();
var renderer = new THREE.WebGLRenderer({canvas: document.getElementById("3d-preview"), antialias: true});
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);
@ -73,7 +121,7 @@ function createScene () {
var directionalLight = new THREE.PointLight(0xffffff, 0.5);
camera.add(directionalLight);
applyMouseControls(renderer, camera, new THREE.Vector3(100, 0, 100), 1000);
applyMouseControls(renderer, camera, new THREE.Vector3(50, 0, 50), 1000);
function applyMouseControls (renderer, camera, center, maxDistance) {
var distance = 20;
@ -90,9 +138,9 @@ function createScene () {
camera.lookAt(center);
}
$(renderer.domElement).on("mousedown", function (e) {
$(renderer.domElement).on('mousedown', function (e) {
moveCamera = true;
}).on("wheel", function (e) {
}).on('wheel', function (e) {
var event = e.originalEvent;
event.preventDefault();
@ -101,9 +149,9 @@ function createScene () {
updateCamera();
});
$(window).on("mouseup", function (e) {
$(window).on('mouseup', function (e) {
moveCamera = false;
}).on("mousemove", function (e) {
}).on('mousemove', function (e) {
var event = e.originalEvent;
if (moveCamera === true) {
@ -126,7 +174,7 @@ function createScene () {
}
(function () {
"use strict";
'use strict';
var loadedItems = 0;
function loaded () {
@ -136,11 +184,11 @@ function createScene () {
}
}
loadSettings("settings/user_settings.json", function (data) {
loadSettings('settings/user_settings.json', function (data) {
USER_SETTINGS = data;
loaded();
});
loadSettings("settings/printer_settings.json", function (data) {
loadSettings('settings/printer_settings.json', function (data) {
PRINTER_SETTINGS = data;
loaded();
});

Loading…
Cancel
Save