From 57f7ee62bc9a8dde5f17ffca7f2e481d2a2f89fc Mon Sep 17 00:00:00 2001 From: casperlamboo Date: Tue, 16 Jun 2015 01:25:06 +0200 Subject: [PATCH] made diagonal infill --- .gitignore | 2 ++ src/slicer.js | 37 +++++++++++++++++++++++-------------- webworker_test.html | 4 ++-- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index ff9e52f..12ab0fa 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,5 @@ test.html print_manager.html testdata.json + +test2.html diff --git a/src/slicer.js b/src/slicer.js index 8a52632..42b0d3c 100644 --- a/src/slicer.js +++ b/src/slicer.js @@ -23,12 +23,18 @@ D3D.Slicer.prototype.setMesh = function (geometry, matrix) { if (geometry instanceof THREE.BufferGeometry) { geometry = new THREE.Geometry().fromBufferGeometry(geometry); } - else { + else if (geometry instanceof THREE.Geometry) { geometry = geometry.clone(); } + else { + console.warn("Geometry is not an instance of BufferGeometry or Geometry"); + return; + } //apply mesh matrix on geometry; - geometry.applyMatrix(matrix); + if (matrix instanceof THREE.Matrix4) { + geometry.applyMatrix(matrix); + } geometry.computeBoundingBox(); geometry.computeFaceNormals(); geometry.mergeVertices(); @@ -247,7 +253,7 @@ D3D.Slicer.prototype.slice = function (layerHeight, height) { slices.push(slice); - if (layer === 222) { + if (layer === 218) { testData.push({ testPoints: testPoints, pathData: slice.parts @@ -448,25 +454,28 @@ D3D.Slicer.prototype.getFillTemplate = function (bounds, size, even, uneven) { var paths = new D3D.Paths([], false); - if (even) { - var left = Math.floor(bounds.left / size) * size; - var right = Math.ceil(bounds.right / size) * size; + var left = Math.floor(bounds.left / size) * size; + var right = Math.ceil(bounds.right / size) * size; + var top = Math.floor(bounds.top / size) * size; + var bottom = Math.floor(bounds.bottom / size) * size; - for (var length = left; length <= right; length += size) { + var width = right - left; + + if (even) { + + for (var y = top; y <= bottom + width; y += size) { paths.push([ - {X: length, Y: bounds.top}, - {X: length, Y: bounds.bottom} + {X: left, Y: y}, + {X: right, Y: y - width} ]); } } if (uneven) { - var top = Math.floor(bounds.top / size) * size; - var bottom = Math.floor(bounds.bottom / size) * size; - for (var length = top; length <= bottom; length += size) { + for (var y = top - width; y <= bottom; y += size) { paths.push([ - {X: bounds.left, Y: length}, - {X: bounds.right, Y: length} + {X: left, Y: y}, + {X: right, Y: y + width} ]); } } diff --git a/webworker_test.html b/webworker_test.html index 0f3a20f..14e415d 100644 --- a/webworker_test.html +++ b/webworker_test.html @@ -47,7 +47,7 @@ function init () { var scene = createScene(); var localIp = location.hash.substring(1); - doodleBox = new D3D.Box(localIp).init(); + /*doodleBox = new D3D.Box(localIp).init(); doodleBox.onupdate = function (data) { document.getElementById('state').innerHTML = data.state; document.getElementById('bed_temp').innerHTML = data.bed; @@ -58,7 +58,7 @@ function init () { document.getElementById('buffered_lines').innerHTML = data.buffered_lines; document.getElementById('total_lines').innerHTML = data.total_lines; document.getElementById('print_batches').innerHTML = doodleBox.printBatches.length; - }; + };*/ printer = new D3D.Printer().updateConfig(USER_SETTINGS).updateConfig(PRINTER_SETTINGS['ultimaker2go']);