diff --git a/slice_test.html b/slice_test.html index 5d20c83..2ad4928 100644 --- a/slice_test.html +++ b/slice_test.html @@ -55,7 +55,7 @@ var camera = new THREE.PerspectiveCamera(75, renderer.domElement.width/renderer. applyMouseControls(renderer, camera, 1000); var material = new THREE.MeshLambertMaterial({color: 0x000000, wireframe: true}); -var geometry = new THREE.TorusGeometry(20, 10, 4, 6); +var geometry = new THREE.TorusGeometry(20, 10, 10, 10); //var geometry = new THREE.BoxGeometry(10, 10, 10, 1, 1, 1); //var geometry = new THREE.SphereGeometry(40, 10, 10); var mesh = new THREE.Mesh(geometry, material); @@ -89,12 +89,9 @@ CAL.Scene.draw(); CAL.Scene.context.strokeStyle = "#FF0000"; - for (var i = 0; i < shapes.length; i ++) { var shape = shapes[i]; - console.log(shape.points.length); - for (var j = 0; j < shape.points.length; j ++) { var normal = shape.getNormal(j).scale(20); var point = shape.points[j]; diff --git a/src/slicer.js b/src/slicer.js index 09cae83..02ee79a 100644 --- a/src/slicer.js +++ b/src/slicer.js @@ -39,7 +39,8 @@ D3D.Slicer.prototype.addLine = function (a, b) { this.lines.push({ line: new THREE.Line3(this.geometry.vertices[a], this.geometry.vertices[b]), - connects: [] + connects: [], + normals: [] }); } @@ -53,6 +54,7 @@ D3D.Slicer.prototype.createLines = function () { for (var i = 0; i < this.geometry.faces.length; i ++) { var face = this.geometry.faces[i]; + var normal = new THREE.Vector2().set(face.normal.x, face.normal.z).normalize(); //check for only adding unique lines //returns index of said line @@ -64,8 +66,12 @@ D3D.Slicer.prototype.createLines = function () { //something wrong here, 3 face can go in different direction this.lines[a].connects.push(b, c); - this.lines[b].connects.push(a, c); + this.lines[b].connects.push(c, a); this.lines[c].connects.push(a, b); + + this.lines[a].normals.push(normal, normal); + this.lines[b].normals.push(normal, normal); + this.lines[c].normals.push(normal, normal); } //sort lines on min height @@ -119,18 +125,25 @@ D3D.Slicer.prototype.slice = function (height, step) { done.push(index); var connects = this.lines[index].connects; + var faceNormals = this.lines[index].normals; for (var j = 0; j < connects.length; j ++) { index = connects[j]; if (intersections[index] && done.indexOf(index) === -1) { - break; + var normal = new THREE.Vector2().copy(intersection).sub(intersections[index]).normal().normalize(); + var faceNormal = faceNormals[j]; + + if (normal.dot(faceNormal) < 0) { + break; + } + else { + index = -1; + } } else { index = -1; } } - - console.log(j); } //think this check is not nescesary, always higher as 0 diff --git a/src/utils.js b/src/utils.js index f9c90ef..f89ae7a 100644 --- a/src/utils.js +++ b/src/utils.js @@ -11,6 +11,13 @@ var D3D = { "contact": "develop@doodle3d.com" }; +THREE.Vector2.prototype.normal = function () { + var x = this.y; + var y = -this.x; + + return this.set(x, y); +}; + function sendAPI (url, data, callback) { "use strict";