diff --git a/slice_test.html b/slice_test.html index 4363ad1..86b69ad 100644 --- a/slice_test.html +++ b/slice_test.html @@ -81,18 +81,18 @@ var geometry = (function () { "use strict"; var circle = new THREE.Shape(); - circle.absarc(0, 0, 20, 0, Math.PI*2, false); + circle.absarc(0, 0, 10, 0, Math.PI*2, false); var hole = new THREE.Path(); - hole.absarc(0, 0, 10, 0, Math.PI*2, true ); + hole.absarc(0, 0, 5, 0, Math.PI*2, true ); - circle.holes.push(hole); + //circle.holes.push(hole); var matrix = new THREE.Matrix4(); matrix.makeRotationX(Math.PI*1.5); var geometry = new THREE.ExtrudeGeometry(circle, { - amount: 10, + amount: 3, bevelEnabled: false, steps: 1 }); @@ -102,7 +102,7 @@ var geometry = (function () { })(); var material = new THREE.MeshLambertMaterial({color: 0x000000, wireframe: true}); -var geometry = new THREE.TorusGeometry(20, 10, 10, 10); +//var geometry = new THREE.TorusGeometry(20, 10, 10, 10); //var geometry = new THREE.BoxGeometry(20, 5, 20, 1, 1, 1); //var geometry = new THREE.SphereGeometry(10, 10, 10); var mesh = new THREE.Mesh(geometry, material); @@ -120,7 +120,7 @@ var gcode = slicer.getGcode(printer); var canvas = document.getElementById("canvas"); var context = canvas.getContext("2d"); -var layer = 90; +var layer = 9; var img = slicer.drawPaths(printer, layer, layer + 1); context.drawImage(img, 0, 0); diff --git a/src/slicer.js b/src/slicer.js index e347380..d939fce 100644 --- a/src/slicer.js +++ b/src/slicer.js @@ -18,7 +18,6 @@ D3D.Slicer = function () { this.geometry; this.lines = []; - this.lineLookup = {}; }; D3D.Slicer.prototype.setGeometry = function (geometry) { "use strict"; @@ -30,30 +29,32 @@ D3D.Slicer.prototype.setGeometry = function (geometry) { return this; }; -D3D.Slicer.prototype.addLine = function (a, b) { - "use strict"; - - //think lookup can only be b_a, a_b is only possible when face is flipped - var index = this.lineLookup[a + "_" + b] || this.lineLookup[b + "_" + a]; - - if (index === undefined) { - index = this.lines.length; - this.lineLookup[a + "_" + b] = index; - - this.lines.push({ - line: new THREE.Line3(this.geometry.vertices[a], this.geometry.vertices[b]), - connects: [], - normals: [] - }); - } - - return index; -}; D3D.Slicer.prototype.createLines = function () { "use strict"; this.lines = []; - this.lineLookup = {}; + var lineLookup = {}; + + var self = this; + function addLine (a, b) { + "use strict"; + + //think lookup can only be b_a, a_b is only possible when face is flipped + var index = lineLookup[a + "_" + b] || lineLookup[b + "_" + a]; + + if (index === undefined) { + index = self.lines.length; + lineLookup[a + "_" + b] = index; + + self.lines.push({ + line: new THREE.Line3(self.geometry.vertices[a], self.geometry.vertices[b]), + connects: [], + normals: [] + }); + } + + return index; + }; for (var i = 0; i < this.geometry.faces.length; i ++) { var face = this.geometry.faces[i]; @@ -61,9 +62,9 @@ D3D.Slicer.prototype.createLines = function () { //check for only adding unique lines //returns index of said line - var a = this.addLine(face.a, face.b); - var b = this.addLine(face.b, face.c); - var c = this.addLine(face.c, face.a); + var a = addLine(face.a, face.b); + var b = addLine(face.b, face.c); + var c = addLine(face.c, face.a); //set connecting lines (based on face) @@ -228,6 +229,7 @@ D3D.Slicer.prototype.slicesToData = function (slices, printer) { innerLayer = innerLayer.concat(inset); } + //moet fillArea wel kleiner? var fillArea = this.getInset((inset || outerLayer), wallThickness); var fillAbove = false;