From ce50b840104e84fe9415d15ae3abc16c9a455440 Mon Sep 17 00:00:00 2001 From: casperlamboo Date: Fri, 10 Jul 2015 15:06:51 +0200 Subject: [PATCH] improves slicing algorithm fixed https://github.com/Doodle3D/Doodle3D-Slicer/issues/4 --- src/slicer.js | 28 +++---------------- .../editor_slicer/js/Sidebar.Slicer.js | 2 +- webworker_test.html | 6 ++-- 3 files changed, 8 insertions(+), 28 deletions(-) diff --git a/src/slicer.js b/src/slicer.js index 32b71cb..c589ac8 100644 --- a/src/slicer.js +++ b/src/slicer.js @@ -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); diff --git a/three.js-master/editor_slicer/js/Sidebar.Slicer.js b/three.js-master/editor_slicer/js/Sidebar.Slicer.js index 6f09ae8..279fdba 100644 --- a/three.js-master/editor_slicer/js/Sidebar.Slicer.js +++ b/three.js-master/editor_slicer/js/Sidebar.Slicer.js @@ -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(); diff --git a/webworker_test.html b/webworker_test.html index f4bb086..f9dc9e3 100644 --- a/webworker_test.html +++ b/webworker_test.html @@ -14,7 +14,7 @@ @@ -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;