fixed shape point order

only dot product is supposed to be > 0 in my code it’s < 0. some where
mathmatical problem maybe fix some where in the future (it works just
ugly)
This commit is contained in:
casperlamboo 2015-04-28 17:54:46 +02:00
parent 2f3f60a921
commit 9d188bb0de
3 changed files with 26 additions and 9 deletions

View File

@ -55,7 +55,7 @@ var camera = new THREE.PerspectiveCamera(75, renderer.domElement.width/renderer.
applyMouseControls(renderer, camera, 1000); applyMouseControls(renderer, camera, 1000);
var material = new THREE.MeshLambertMaterial({color: 0x000000, wireframe: true}); 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.BoxGeometry(10, 10, 10, 1, 1, 1);
//var geometry = new THREE.SphereGeometry(40, 10, 10); //var geometry = new THREE.SphereGeometry(40, 10, 10);
var mesh = new THREE.Mesh(geometry, material); var mesh = new THREE.Mesh(geometry, material);
@ -89,12 +89,9 @@ CAL.Scene.draw();
CAL.Scene.context.strokeStyle = "#FF0000"; CAL.Scene.context.strokeStyle = "#FF0000";
for (var i = 0; i < shapes.length; i ++) { for (var i = 0; i < shapes.length; i ++) {
var shape = shapes[i]; var shape = shapes[i];
console.log(shape.points.length);
for (var j = 0; j < shape.points.length; j ++) { for (var j = 0; j < shape.points.length; j ++) {
var normal = shape.getNormal(j).scale(20); var normal = shape.getNormal(j).scale(20);
var point = shape.points[j]; var point = shape.points[j];

View File

@ -39,7 +39,8 @@ D3D.Slicer.prototype.addLine = function (a, b) {
this.lines.push({ this.lines.push({
line: new THREE.Line3(this.geometry.vertices[a], this.geometry.vertices[b]), 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 ++) { for (var i = 0; i < this.geometry.faces.length; i ++) {
var face = this.geometry.faces[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 //check for only adding unique lines
//returns index of said line //returns index of said line
@ -64,8 +66,12 @@ D3D.Slicer.prototype.createLines = function () {
//something wrong here, 3 face can go in different direction //something wrong here, 3 face can go in different direction
this.lines[a].connects.push(b, c); 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[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 //sort lines on min height
@ -119,18 +125,25 @@ D3D.Slicer.prototype.slice = function (height, step) {
done.push(index); done.push(index);
var connects = this.lines[index].connects; var connects = this.lines[index].connects;
var faceNormals = this.lines[index].normals;
for (var j = 0; j < connects.length; j ++) { for (var j = 0; j < connects.length; j ++) {
index = connects[j]; index = connects[j];
if (intersections[index] && done.indexOf(index) === -1) { 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 { else {
index = -1; index = -1;
} }
} }
console.log(j);
} }
//think this check is not nescesary, always higher as 0 //think this check is not nescesary, always higher as 0

View File

@ -11,6 +11,13 @@ var D3D = {
"contact": "develop@doodle3d.com" "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) { function sendAPI (url, data, callback) {
"use strict"; "use strict";