improves slicing algorithm

fixed https://github.com/Doodle3D/Doodle3D-Slicer/issues/4
This commit is contained in:
casperlamboo 2015-07-10 15:06:51 +02:00 committed by Simon Voordouw
parent 890bc8bb56
commit c0cfa8de9d
3 changed files with 8 additions and 28 deletions

View File

@ -61,13 +61,13 @@ D3D.Slicer.prototype.getGCode = function (printer) {
var slices = this._slice(lines, printer);
this._generateInnerLines(slices, printer);
this._generateInfills(slices, printer);
if (useSupport) {
this._generateSupport(slices, printer);
}
this._optimizePaths(slices, printer);
var gcode = this._slicesToGCode(slices, printer);
@ -132,15 +132,13 @@ D3D.Slicer.prototype._slice = function (lines, printer) {
var layerHeight = printer.config["layerHeight"];
var height = printer.config["dimensionsZ"];
//var testData = [];
var numLayers = height / layerHeight;
var layersIntersections = [];
for (var layer = 0; layer < numLayers; layer ++) {
layersIntersections[layer] = [];
}
for (var lineIndex = 0; lineIndex < lines.length; lineIndex ++) {
var line = lines[lineIndex].line;
@ -155,7 +153,6 @@ D3D.Slicer.prototype._slice = function (lines, printer) {
}
var slices = [];
//var testPoints = [];
for (var layer = 1; layer < layersIntersections.length; layer ++) {
var layerIntersections = layersIntersections[layer];
@ -179,14 +176,6 @@ D3D.Slicer.prototype._slice = function (lines, printer) {
var z = line.end.z * alpha + line.start.z * (1 - alpha);
}
intersections[index] = new THREE.Vector2(z, x);
/*testPoints.push({
x: z,
y: x,
connects: lines[index].connects,
index: index,
normals: lines[index].normals
});*/
}
var done = [];
@ -216,7 +205,7 @@ D3D.Slicer.prototype._slice = function (lines, printer) {
var faceNormal = faceNormals[Math.floor(j/2)];
if (a.distanceTo(b) === 0 || faceNormal.length() === 0) {
if (a.distanceTo(b) < 0.0001 || faceNormal.length() === 0) {
done.push(index);
connects = connects.concat(lines[index].connects);
@ -268,18 +257,9 @@ D3D.Slicer.prototype._slice = function (lines, printer) {
}
slices.push(slice);
/*if (layer === 218) {
testData.push({
testPoints: testPoints,
pathData: slice.parts
});
}*/
}
}
//console.log(JSON.stringify(testData));
this.progress.sliced = true;
this._updateProgress(printer);

View File

@ -160,7 +160,7 @@ Sidebar.Slicer = function ( editor ) {
slicer.setSettings(USER_SETTINGS, PRINTER_SETTINGS[selectedPrinter]);
var matrix = new THREE.Matrix().setPosition(new THREE.Vector(0, -geometryCombined.boundingBox.min.y, 0));
var matrix = new THREE.Matrix4().setPosition(new THREE.Vector3(0, -geometryCombined.boundingBox.min.y, 0));
slicer.setGeometry(geometryCombined, matrix);
slicer.slice();

View File

@ -14,7 +14,7 @@
<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%; transition: width 0.5s;}
.block {border: 1px solid black; width: 400px; height: 400px; display: inline-block;}
#start_print, #download {display: none;}
</style>
@ -57,7 +57,7 @@ function init () {
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('print_batches').innerHTML = doodleBox._printBatches.length;
};
printer = new D3D.Printer().updateConfig(USER_SETTINGS).updateConfig(PRINTER_SETTINGS['ultimaker2go']);
@ -101,7 +101,7 @@ function init () {
var mesh = new THREE.Mesh(geometry, material);
mesh.rotation.x = -Math.PI/2;
mesh.scale.x = mesh.scale.y = mesh.scale.z = 0.7;
//mesh.scale.x = mesh.scale.y = mesh.scale.z = 0.7;
mesh.position.x = 60;
mesh.position.z = 60;