From d196b36c513d48ea184cc58ca6471a63519748cb Mon Sep 17 00:00:00 2001 From: "Mr.doob" Date: Thu, 17 Nov 2011 01:00:50 +0100 Subject: [PATCH] Removed useVertexNormals boolean from computeFaceNormals. Bad things (and hard to debug) can happen that affect Ray. --- src/core/Geometry.js | 55 ++++---------------- src/extras/geometries/IcosahedronGeometry.js | 2 +- 2 files changed, 12 insertions(+), 45 deletions(-) diff --git a/src/core/Geometry.js b/src/core/Geometry.js index e9a720f5..75a6bbd1 100644 --- a/src/core/Geometry.js +++ b/src/core/Geometry.js @@ -100,64 +100,31 @@ THREE.Geometry.prototype = { }, - computeFaceNormals: function ( useVertexNormals ) { + computeFaceNormals: function () { var n, nl, v, vl, vertex, f, fl, face, vA, vB, vC, cb = new THREE.Vector3(), ab = new THREE.Vector3(); - /* - for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) { - - vertex = this.vertices[ v ]; - vertex.normal.set( 0, 0, 0 ); - - } - */ - for ( f = 0, fl = this.faces.length; f < fl; f ++ ) { face = this.faces[ f ]; - if ( useVertexNormals && face.vertexNormals.length ) { + vA = this.vertices[ face.a ]; + vB = this.vertices[ face.b ]; + vC = this.vertices[ face.c ]; - cb.set( 0, 0, 0 ); + cb.sub( vC.position, vB.position ); + ab.sub( vA.position, vB.position ); + cb.crossSelf( ab ); - for ( n = 0, nl = face.vertexNormals.length; n < nl; n++ ) { + if ( !cb.isZero() ) { - cb.addSelf( face.vertexNormals[n] ); - - } - - cb.divideScalar( 3 ); - - if ( ! cb.isZero() ) { - - cb.normalize(); - - } - - face.normal.copy( cb ); - - } else { - - vA = this.vertices[ face.a ]; - vB = this.vertices[ face.b ]; - vC = this.vertices[ face.c ]; - - cb.sub( vC.position, vB.position ); - ab.sub( vA.position, vB.position ); - cb.crossSelf( ab ); - - if ( !cb.isZero() ) { - - cb.normalize(); - - } - - face.normal.copy( cb ); + cb.normalize(); } + face.normal.copy( cb ); + } }, diff --git a/src/extras/geometries/IcosahedronGeometry.js b/src/extras/geometries/IcosahedronGeometry.js index f2780cbb..f0dffefb 100644 --- a/src/extras/geometries/IcosahedronGeometry.js +++ b/src/extras/geometries/IcosahedronGeometry.js @@ -85,7 +85,7 @@ THREE.IcosahedronGeometry = function ( subdivisions ) { scope.faceVertexUvs[ 0 ] = tempScope.faceVertexUvs[ 0 ]; this.computeCentroids(); - this.computeFaceNormals( true ); + this.computeFaceNormals(); function v( x, y, z ) {