improvement, starting point for collision fix

This commit is contained in:
casperlamboo 2015-04-28 14:11:41 +02:00
parent 5b8d09616f
commit 5050bc0e40
6 changed files with 7048 additions and 26 deletions

View File

@ -28,13 +28,17 @@ doodleBox.onload = function () {
var gcode = slicer.getGcode(doodleBox.printer);
var print = $(document.createElement("button")).text("Print").on("click", function () {
var print = $(document.createElement("a")).html("Print").on("click", function () {
doodleBox.print(gcode);
});
var stop = $(document.createElement("button")).text("Stop").on("click", function () {
var stop = $(document.createElement("a")).html("Stop").on("click", function () {
doodleBox.stop();
});
$("body").append(print, stop);
var download = $(document.createElement("a")).html("Download").attr({
download: "test.gcode",
href: "data:text/plain," + encodeURIComponent(gcode.join("\n"))
});
$("body").append(print, stop, download);
};
var scene = new THREE.Scene();
@ -46,19 +50,18 @@ var camera = new THREE.PerspectiveCamera(75, renderer.domElement.width/renderer.
applyMouseControls(renderer, camera, 1000);
var material = new THREE.MeshBasicMaterial({color: 0x000000, wireframe: true});
var geometry = new THREE.TorusGeometry(20, 10, 20, 20);
var material = new THREE.MeshLambertMaterial({color: 0x000000, wireframe: true});
var geometry = new THREE.TorusGeometry(20, 10, 4, 6);
//var geometry = new THREE.BoxGeometry(10, 10, 10, 1, 1, 1);
//var geometry = new THREE.SphereGeometry(5, 32, 32);
//var geometry = new THREE.SphereGeometry(40, 10, 10);
var mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
var slicer = new D3D.Slicer(geometry);
var slicer = new D3D.Slicer().setGeometry(geometry);
//var slices = slicer.slice(200, 0.2);
var slices = slicer.slice(1, 1);
var slices = slicer.slice(200, 0.2);
//document.write(JSON.stringify(slices));
/*var canvas = document.getElementById("canvas");
var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d");
for (var layer = 0; layer < slices.length; layer ++) {
@ -68,16 +71,16 @@ for (var layer = 0; layer < slices.length; layer ++) {
var shape = slice[i];
context.beginPath();
for (var j = 0; j < shape.length; j ++) {
for (var j = 0; j <= shape.length; j ++) {
var point = shape[(j % shape.length)];
context.lineTo((point.x-100) * 3 + 100, (point.y-100) * 3 + 100);
}
context.closePath();
//context.closePath();
context.strokeStyle = "rgb(" + Math.round(Math.random()*255) + ", " + Math.round(Math.random()*255) + ", " + Math.round(Math.random()*255) + ")";
context.stroke();
}
}*/
}
(function animate () {
requestAnimationFrame(animate);

View File

@ -29,6 +29,12 @@ D3D.Box = function (localIp) {
getAPI(self.api + "config/all", function (data) {
//self.config = data;
for (var i in data) {
if (i.indexOf("doodle3d") === 0) {
self[i] = data[i];
}
}
self.printer = new D3D.Printer(data);
self.update();
@ -59,15 +65,15 @@ D3D.Box.prototype.updateState = function () {
//que api calls so they don't overload the d3d box
getAPI(this.api + "printer/state", function (data) {
self.state = data.state;
self.printer.state = data.state;
if (data.state !== "connecting" && data.state !== "disconnected") {
getAPI(self.api + "printer/temperature", function (data) {
self.temperature = data;
self.printer.temperature = data;
getAPI(self.api + "printer/progress", function (data) {
self.progress = data;
self.printer.progress = data;
//finish updating state
self.update();
@ -140,6 +146,6 @@ D3D.Box.prototype.stop = function () {
"gcode": finishMove.join("\n")
//"gcode": {}
}, function (data) {
console.log(data);
console.log("Printer stop command sent");
});
};

6985
src/clipper.js Executable file

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,10 @@
D3D.Printer = function (config) {
"use strict";
this.state = "connecting";
this.temperature = {};
this.progress = {};
for (var i in config) {
if (i.indexOf("printer") === 0) {

View File

@ -8,14 +8,23 @@
*
******************************************************/
D3D.Slicer = function (geometry) {
D3D.Slicer = function () {
"use strict";
this.geometry;
this.lines = [];
this.lineLookup = {};
};
D3D.Slicer.prototype.setGeometry = function (geometry) {
"use strict";
this.geometry = geometry;
this.geometry.mergeVertices();
this.lines = [];
this.lineLookup = {};
this.createLines();
return this;
};
D3D.Slicer.prototype.addLine = function (a, b) {
"use stict";
@ -52,6 +61,8 @@ D3D.Slicer.prototype.createLines = function () {
var c = this.addLine(face.c, face.a);
//set connecting lines (based on face)
this.lines[a].connects.push(b, c);
this.lines[b].connects.push(a, c);
this.lines[c].connects.push(a, b);
@ -65,8 +76,6 @@ D3D.Slicer.prototype.createLines = function () {
D3D.Slicer.prototype.slice = function (height, step) {
"use strict";
this.createLines();
var slices = [];
var plane = new THREE.Plane();
@ -75,7 +84,6 @@ D3D.Slicer.prototype.slice = function (height, step) {
plane.set(new THREE.Vector3(0, -1, 0), z);
var slice = [];
slices.push(slice);
var intersections = [];
@ -98,7 +106,7 @@ D3D.Slicer.prototype.slice = function (height, step) {
var done = [];
for (var i = 0; i < intersections.length; i ++) {
if (done.indexOf(i) === -1 && intersections[i]) {
if (intersections[i] && done.indexOf(i) === -1) {
var index = i;
var shape = [];
@ -113,7 +121,9 @@ D3D.Slicer.prototype.slice = function (height, step) {
for (var j = 0; j < connects.length; j ++) {
index = connects[j];
if (done.indexOf(index) === -1 && intersections[index]) {
console.log(j, intersections[index]);
if (intersections[index] && done.indexOf(index) === -1) {
break;
}
else {
@ -128,6 +138,13 @@ D3D.Slicer.prototype.slice = function (height, step) {
}
}
}
if (slice.length > 0) {
slices.push(slice);
}
else {
break;
}
}
return slices;

View File

@ -61,6 +61,13 @@ function getAPI (url, callback) {
});
}
function downloadFile (file, data) {
$(document.createElement("a")).attr({
download: file,
href: "data:text/plain," + data
})[0].click();
}
Array.prototype.clone = function () {
"use strict";