cleaned files

This commit is contained in:
casperlamboo 2015-05-01 12:10:02 +02:00
parent e17279f7c4
commit 0f8135b4f2
2 changed files with 58 additions and 46 deletions

View File

@ -92,7 +92,7 @@ var geometry = (function () {
matrix.makeRotationX(Math.PI*1.5); matrix.makeRotationX(Math.PI*1.5);
var geometry = new THREE.ExtrudeGeometry(circle, { var geometry = new THREE.ExtrudeGeometry(circle, {
amount: 1, amount: 10,
bevelEnabled: false, bevelEnabled: false,
steps: 1 steps: 1
}); });
@ -114,57 +114,19 @@ var canvas = document.getElementById("canvas");
var context = canvas.getContext("2d"); var context = canvas.getContext("2d");
var slicer = new D3D.Slicer().setGeometry(geometry); var slicer = new D3D.Slicer().setGeometry(geometry);
//slicer.draw(1, context);
var gcode = slicer.getGcode(printer); 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) { var img = slicer.drawPaths(printer, 0, 1);
"use strict"; context.drawImage(img, 0, 0);*/
context.fillStyle = color;
context.strokeStyle = color;
context.beginPath();
for (var i = 0; i < paths.length; i ++) {
var path = paths[i];
context.moveTo((path[0].X- 100) * 6.0 + 200, (path[0].Y- 100) * 6.0 + 200);
for (var j = 0; j < path.length; j ++) {
var point = path[j];
context.lineTo((point.X- 100) * 6.0 + 200, (point.Y- 100) * 6.0 + 200);
}
context.closePath();
}
context.stroke();
}
var layer = 0;
setInterval(function () {
context.clearRect(0, 0, 400, 400);
//for (var layer = 0; layer < gcode.length; layer ++) {
//var layer = 31;
var slice = gcode[layer % gcode.length];
//drawPolygons(slice.outerLayer, "red");
//drawPolygons(slice.innerLayer, "green");
drawPolygons(slice.fill, "blue");
context.fillText("layer: " + layer, 10, 10);
//}
layer ++;
}, 100);
*/
(function animate () { (function animate () {
"use strict"; "use strict";
requestAnimationFrame(animate); requestAnimationFrame(animate);
renderer.render(scene, camera); renderer.render(scene, camera);
})(); })();
</script> </script>

View File

@ -233,7 +233,8 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) {
var highFill; var highFill;
var fillAbove = undefined; var fillAbove = undefined;
for (var i = 1; i < shellThickness/layerHeight; i ++) { //for (var i = 1; i < shellThickness/layerHeight; i ++) {
for (var i = 1; i < shellThickness/layerHeight + 4; i ++) {
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);
@ -283,7 +284,7 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) {
fill = fill.concat(lowFillStrokes); fill = fill.concat(lowFillStrokes);
//optimize //optimize
//make as big as bounding box of highfillArea //make as big as bounding box of highFillArea
var highFillTemplate = this.getFillTemplate(dimensionsZ, wallThickness, (layer % 2 === 0), (layer % 2 === 1)); var highFillTemplate = this.getFillTemplate(dimensionsZ, wallThickness, (layer % 2 === 0), (layer % 2 === 1));
var clipper = new ClipperLib.Clipper(); var clipper = new ClipperLib.Clipper();
@ -295,10 +296,10 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) {
fill = fill.concat(highFillStrokes); fill = fill.concat(highFillStrokes);
//create brim //create brim
if (layer === 0) { /*if (layer === 0) {
var brim = this.getInset(outerLayer, -brimOffset); var brim = this.getInset(outerLayer, -brimOffset);
outerLayer = brim.concat(outerLayer); outerLayer = brim.concat(outerLayer);
} }*/
ClipperLib.JS.ScaleDownPaths(outerLayer, scale); ClipperLib.JS.ScaleDownPaths(outerLayer, scale);
ClipperLib.JS.ScaleDownPaths(innerLayer, scale); ClipperLib.JS.ScaleDownPaths(innerLayer, scale);
@ -418,6 +419,55 @@ D3D.Slicer.prototype.dataToGcode = function (data, printer) {
gcode = gcode.concat(printer.getEndCode()); gcode = gcode.concat(printer.getEndCode());
return gcode; return gcode;
}; };
D3D.Slicer.prototype.drawPaths = function (printer, min, max) {
"use strict";
var canvas = document.createElement("canvas");
canvas.width = 400;
canvas.height = 400;
var context = canvas.getContext("2d");
var layerHeight = printer.config["printer.layerHeight"];
var dimensionsZ = printer.config["printer.dimensions.z"];
function drawPolygons (paths, color) {
"use strict";
context.fillStyle = color;
context.strokeStyle = color;
context.beginPath();
for (var i = 0; i < paths.length; i ++) {
var path = paths[i];
context.moveTo((path[0].X- 100) * 6.0 + 200, (path[0].Y- 100) * 6.0 + 200);
for (var j = 0; j < path.length; j ++) {
var point = path[j];
context.lineTo((point.X- 100) * 6.0 + 200, (point.Y- 100) * 6.0 + 200);
}
context.closePath();
}
context.stroke();
}
var slices = this.slice(dimensionsZ, layerHeight);
slices.shift();
var data = this.slicesToData(slices, printer);
for (var layer = min; layer < max; layer ++) {
var layer = 0;
context.clearRect(0, 0, 400, 400);
var slice = data[layer % data.length];
drawPolygons(slice.outerLayer, "red");
drawPolygons(slice.innerLayer, "green");
drawPolygons(slice.fill, "blue");
}
return canvas;
};
D3D.Slicer.prototype.getGcode = function (printer) { D3D.Slicer.prototype.getGcode = function (printer) {
"use strict"; "use strict";