mirror of
https://github.com/Doodle3D/Doodle3D-Slicer.git
synced 2024-11-26 07:24:57 +01:00
Merge branch 'develop'
This commit is contained in:
commit
dce9f5ed68
@ -5,6 +5,7 @@
|
|||||||
<!--<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>-->
|
<!--<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>-->
|
||||||
<script src="library/jquery.js"></script>
|
<script src="library/jquery.js"></script>
|
||||||
<script src="library/three.js"></script>
|
<script src="library/three.js"></script>
|
||||||
|
<script src="library/cal.js"></script>
|
||||||
|
|
||||||
<script src="src/utils.js"></script>
|
<script src="src/utils.js"></script>
|
||||||
<script src="src/box.js"></script>
|
<script src="src/box.js"></script>
|
||||||
@ -14,10 +15,13 @@
|
|||||||
<script src="gcode/testgcode.js"></script>
|
<script src="gcode/testgcode.js"></script>
|
||||||
<script src="gcode/easterbunny.js"></script>
|
<script src="gcode/easterbunny.js"></script>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
canvas {border: 1px solid black;}
|
||||||
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<canvas id="3d-preview" height="480" width="720"></canvas>
|
<canvas id="3d-preview" height="400" width="400"></canvas>
|
||||||
<canvas id="canvas" width="200" height="200"></canvas>
|
<canvas id="canvas" width="400" height="400"></canvas>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var localIp = location.hash.substring(1);
|
var localIp = location.hash.substring(1);
|
||||||
@ -26,15 +30,19 @@ var doodleBox = new D3D.Box(localIp);
|
|||||||
doodleBox.onload = function () {
|
doodleBox.onload = function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var gcode = slicer.getGcode(doodleBox.printer);
|
/*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);
|
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();
|
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();
|
var scene = new THREE.Scene();
|
||||||
@ -46,38 +54,52 @@ var camera = new THREE.PerspectiveCamera(75, renderer.domElement.width/renderer.
|
|||||||
|
|
||||||
applyMouseControls(renderer, camera, 1000);
|
applyMouseControls(renderer, camera, 1000);
|
||||||
|
|
||||||
var material = new THREE.MeshBasicMaterial({color: 0x000000, wireframe: true});
|
var material = new THREE.MeshLambertMaterial({color: 0x000000, wireframe: true});
|
||||||
var geometry = new THREE.TorusGeometry(20, 10, 20, 20);
|
var geometry = new THREE.TorusGeometry(20, 10, 10, 10);
|
||||||
//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(5, 32, 32);
|
//var geometry = new THREE.SphereGeometry(40, 10, 10);
|
||||||
var mesh = new THREE.Mesh(geometry, material);
|
var mesh = new THREE.Mesh(geometry, material);
|
||||||
scene.add(mesh);
|
scene.add(mesh);
|
||||||
|
|
||||||
var slicer = new D3D.Slicer(geometry);
|
(function () {
|
||||||
|
var slicer = new D3D.Slicer().setGeometry(geometry);
|
||||||
var slices = slicer.slice(200, 0.2);
|
var slices = slicer.slice(200, 0.2);
|
||||||
//document.write(JSON.stringify(slices));
|
//var slices = slicer.slice(1, 1);
|
||||||
|
|
||||||
/*var canvas = document.getElementById("canvas");
|
CAL.Scene.setCanvas(document.getElementById("canvas"));
|
||||||
var context = canvas.getContext("2d");
|
|
||||||
|
//error at layer 0;
|
||||||
|
//maybe because of geomety
|
||||||
|
var layer = 4;
|
||||||
|
|
||||||
|
var shapes = [];
|
||||||
|
|
||||||
for (var layer = 0; layer < slices.length; layer ++) {
|
|
||||||
var slice = slices[layer];
|
var slice = slices[layer];
|
||||||
|
|
||||||
for (var i = 0; i < slice.length; i ++) {
|
for (var i = 0; i < slice.length; i ++) {
|
||||||
var shape = slice[i];
|
var shape = new CAL.Shape({shapeColor: false});
|
||||||
|
shapes.push(shape);
|
||||||
|
|
||||||
context.beginPath();
|
for (var j = 0; j < slice[i].length; j ++) {
|
||||||
for (var j = 0; j < shape.length; j ++) {
|
var point = slice[i][j];
|
||||||
var point = shape[(j % shape.length)];
|
shape.addPoint(new CAL.Vector((point.x-100) * 5 + 200, (point.y-100) * 5 + 200));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
context.lineTo((point.x-100) * 3 + 100, (point.y-100) * 3 + 100);
|
for (var i = 0; i < shapes.length; i ++) {
|
||||||
|
var shape = shapes[i];
|
||||||
|
|
||||||
|
shape.draw(CAL.Scene.context);
|
||||||
|
CAL.Scene.context.strokeStyle = "#FF0000";
|
||||||
|
|
||||||
|
for (var j = 0; j < shape.points.length; j ++) {
|
||||||
|
var normal = shape.getNormal(j).scale(20);
|
||||||
|
var point = shape.points[j];
|
||||||
|
|
||||||
|
normal.draw(CAL.Scene.context, point.x, point.y);
|
||||||
}
|
}
|
||||||
context.closePath();
|
|
||||||
context.strokeStyle = "rgb(" + Math.round(Math.random()*255) + ", " + Math.round(Math.random()*255) + ", " + Math.round(Math.random()*255) + ")";
|
|
||||||
context.stroke();
|
|
||||||
}
|
}
|
||||||
}*/
|
})();
|
||||||
|
|
||||||
(function animate () {
|
(function animate () {
|
||||||
requestAnimationFrame(animate);
|
requestAnimationFrame(animate);
|
||||||
|
27
src/box.js
27
src/box.js
@ -29,6 +29,12 @@ D3D.Box = function (localIp) {
|
|||||||
getAPI(self.api + "config/all", function (data) {
|
getAPI(self.api + "config/all", function (data) {
|
||||||
//self.config = 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.printer = new D3D.Printer(data);
|
||||||
self.update();
|
self.update();
|
||||||
|
|
||||||
@ -58,26 +64,11 @@ D3D.Box.prototype.updateState = function () {
|
|||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
//que api calls so they don't overload the d3d box
|
//que api calls so they don't overload the d3d box
|
||||||
getAPI(this.api + "printer/state", function (data) {
|
getAPI(this.api + "info/status", function (data) {
|
||||||
self.state = data.state;
|
self.printer.data = data;
|
||||||
|
|
||||||
if (data.state !== "connecting" && data.state !== "disconnected") {
|
|
||||||
|
|
||||||
getAPI(self.api + "printer/temperature", function (data) {
|
|
||||||
self.temperature = data;
|
|
||||||
|
|
||||||
getAPI(self.api + "printer/progress", function (data) {
|
|
||||||
self.progress = data;
|
|
||||||
|
|
||||||
//finish updating state
|
|
||||||
self.update();
|
self.update();
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
self.update();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
D3D.Box.prototype.print = function (gcode) {
|
D3D.Box.prototype.print = function (gcode) {
|
||||||
"use strict";
|
"use strict";
|
||||||
@ -140,6 +131,6 @@ D3D.Box.prototype.stop = function () {
|
|||||||
"gcode": finishMove.join("\n")
|
"gcode": finishMove.join("\n")
|
||||||
//"gcode": {}
|
//"gcode": {}
|
||||||
}, function (data) {
|
}, function (data) {
|
||||||
console.log(data);
|
console.log("Printer stop command sent");
|
||||||
});
|
});
|
||||||
};
|
};
|
6985
src/clipper.js
Executable file
6985
src/clipper.js
Executable file
File diff suppressed because it is too large
Load Diff
@ -8,6 +8,8 @@
|
|||||||
D3D.Printer = function (config) {
|
D3D.Printer = function (config) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
this.data = {};
|
||||||
|
|
||||||
for (var i in config) {
|
for (var i in config) {
|
||||||
if (i.indexOf("printer") === 0) {
|
if (i.indexOf("printer") === 0) {
|
||||||
this[i] = config[i];
|
this[i] = config[i];
|
||||||
|
@ -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";
|
"use strict";
|
||||||
|
|
||||||
this.geometry = geometry;
|
this.geometry = geometry;
|
||||||
this.geometry.mergeVertices();
|
this.geometry.mergeVertices();
|
||||||
|
|
||||||
this.lines = [];
|
this.createLines();
|
||||||
this.lineLookup = {};
|
|
||||||
|
return this;
|
||||||
};
|
};
|
||||||
D3D.Slicer.prototype.addLine = function (a, b) {
|
D3D.Slicer.prototype.addLine = function (a, b) {
|
||||||
"use stict";
|
"use stict";
|
||||||
@ -30,7 +39,8 @@ D3D.Slicer.prototype.addLine = function (a, b) {
|
|||||||
|
|
||||||
this.lines.push({
|
this.lines.push({
|
||||||
line: new THREE.Line3(this.geometry.vertices[a], this.geometry.vertices[b]),
|
line: new THREE.Line3(this.geometry.vertices[a], this.geometry.vertices[b]),
|
||||||
connects: []
|
connects: [],
|
||||||
|
normals: []
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,6 +54,7 @@ D3D.Slicer.prototype.createLines = function () {
|
|||||||
|
|
||||||
for (var i = 0; i < this.geometry.faces.length; i ++) {
|
for (var i = 0; i < this.geometry.faces.length; i ++) {
|
||||||
var face = this.geometry.faces[i];
|
var face = this.geometry.faces[i];
|
||||||
|
var normal = new THREE.Vector2().set(face.normal.x, face.normal.z).normalize();
|
||||||
|
|
||||||
//check for only adding unique lines
|
//check for only adding unique lines
|
||||||
//returns index of said line
|
//returns index of said line
|
||||||
@ -52,9 +63,15 @@ D3D.Slicer.prototype.createLines = function () {
|
|||||||
var c = this.addLine(face.c, face.a);
|
var c = this.addLine(face.c, face.a);
|
||||||
|
|
||||||
//set connecting lines (based on face)
|
//set connecting lines (based on face)
|
||||||
|
|
||||||
|
//something wrong here, 3 face can go in different direction
|
||||||
this.lines[a].connects.push(b, c);
|
this.lines[a].connects.push(b, c);
|
||||||
this.lines[b].connects.push(a, c);
|
this.lines[b].connects.push(c, a);
|
||||||
this.lines[c].connects.push(a, b);
|
this.lines[c].connects.push(a, b);
|
||||||
|
|
||||||
|
this.lines[a].normals.push(normal, normal);
|
||||||
|
this.lines[b].normals.push(normal, normal);
|
||||||
|
this.lines[c].normals.push(normal, normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
//sort lines on min height
|
//sort lines on min height
|
||||||
@ -65,8 +82,6 @@ D3D.Slicer.prototype.createLines = function () {
|
|||||||
D3D.Slicer.prototype.slice = function (height, step) {
|
D3D.Slicer.prototype.slice = function (height, step) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
this.createLines();
|
|
||||||
|
|
||||||
var slices = [];
|
var slices = [];
|
||||||
|
|
||||||
var plane = new THREE.Plane();
|
var plane = new THREE.Plane();
|
||||||
@ -75,7 +90,6 @@ D3D.Slicer.prototype.slice = function (height, step) {
|
|||||||
plane.set(new THREE.Vector3(0, -1, 0), z);
|
plane.set(new THREE.Vector3(0, -1, 0), z);
|
||||||
|
|
||||||
var slice = [];
|
var slice = [];
|
||||||
slices.push(slice);
|
|
||||||
|
|
||||||
var intersections = [];
|
var intersections = [];
|
||||||
|
|
||||||
@ -98,7 +112,7 @@ D3D.Slicer.prototype.slice = function (height, step) {
|
|||||||
var done = [];
|
var done = [];
|
||||||
for (var i = 0; i < intersections.length; i ++) {
|
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 index = i;
|
||||||
|
|
||||||
var shape = [];
|
var shape = [];
|
||||||
@ -110,16 +124,25 @@ D3D.Slicer.prototype.slice = function (height, step) {
|
|||||||
done.push(index);
|
done.push(index);
|
||||||
|
|
||||||
var connects = this.lines[index].connects;
|
var connects = this.lines[index].connects;
|
||||||
|
var faceNormals = this.lines[index].normals;
|
||||||
for (var j = 0; j < connects.length; j ++) {
|
for (var j = 0; j < connects.length; j ++) {
|
||||||
index = connects[j];
|
index = connects[j];
|
||||||
|
|
||||||
if (done.indexOf(index) === -1 && intersections[index]) {
|
if (intersections[index] && done.indexOf(index) === -1) {
|
||||||
|
var normal = new THREE.Vector2().copy(intersection).sub(intersections[index]).normal().normalize();
|
||||||
|
var faceNormal = faceNormals[j];
|
||||||
|
|
||||||
|
if (normal.dot(faceNormal) > 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
index = -1;
|
index = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
index = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//think this check is not nescesary, always higher as 0
|
//think this check is not nescesary, always higher as 0
|
||||||
@ -128,6 +151,13 @@ D3D.Slicer.prototype.slice = function (height, step) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (slice.length > 0) {
|
||||||
|
slices.push(slice);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return slices;
|
return slices;
|
||||||
|
14
src/utils.js
14
src/utils.js
@ -11,6 +11,13 @@ var D3D = {
|
|||||||
"contact": "develop@doodle3d.com"
|
"contact": "develop@doodle3d.com"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
THREE.Vector2.prototype.normal = function () {
|
||||||
|
var x = this.y;
|
||||||
|
var y = -this.x;
|
||||||
|
|
||||||
|
return this.set(x, y);
|
||||||
|
};
|
||||||
|
|
||||||
function sendAPI (url, data, callback) {
|
function sendAPI (url, data, callback) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -61,6 +68,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 () {
|
Array.prototype.clone = function () {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user