Explorar el Código

initialize face.vertexNormals and __tmpVertices more often, to make sure they are available when computeVertexNormals is called (again) after faces or vertices have changed.

Martin Wicke hace 11 años
padre
commit
089741d0ad
Se han modificado 1 ficheros con 5 adiciones y 9 borrados
  1. 5 9
      src/core/Geometry.js

+ 5 - 9
src/core/Geometry.js

@@ -144,7 +144,7 @@ THREE.Geometry.prototype = {
 		// create internal buffers for reuse when calling this method repeatedly
 		// create internal buffers for reuse when calling this method repeatedly
 		// (otherwise memory allocation / deallocation every frame is big resource hog)
 		// (otherwise memory allocation / deallocation every frame is big resource hog)
 
 
-		if ( this.__tmpVertices === undefined ) {
+		if ( this.__tmpVertices === undefined || this.__tmpVertices.length != this.vertices.length) {
 
 
 			this.__tmpVertices = new Array( this.vertices.length );
 			this.__tmpVertices = new Array( this.vertices.length );
 			vertices = this.__tmpVertices;
 			vertices = this.__tmpVertices;
@@ -155,13 +155,6 @@ THREE.Geometry.prototype = {
 
 
 			}
 			}
 
 
-			for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
-
-				face = this.faces[ f ];
-				face.vertexNormals = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ];
-
-			}
-
 		} else {
 		} else {
 
 
 			vertices = this.__tmpVertices;
 			vertices = this.__tmpVertices;
@@ -225,6 +218,9 @@ THREE.Geometry.prototype = {
 
 
 			face = this.faces[ f ];
 			face = this.faces[ f ];
 
 
+			if (face.vertexNormals === undefined || face.vertexNormals.length !== 3)
+				face.vertexNormals = [ new THREE.Vector3(), new THREE.Vector3(), new THREE.Vector3() ];
+
 			face.vertexNormals[ 0 ].copy( vertices[ face.a ] );
 			face.vertexNormals[ 0 ].copy( vertices[ face.a ] );
 			face.vertexNormals[ 1 ].copy( vertices[ face.b ] );
 			face.vertexNormals[ 1 ].copy( vertices[ face.b ] );
 			face.vertexNormals[ 2 ].copy( vertices[ face.c ] );
 			face.vertexNormals[ 2 ].copy( vertices[ face.c ] );
@@ -573,7 +569,7 @@ THREE.Geometry.prototype = {
 
 
 		for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
 		for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
 			var idx = faceIndicesToRemove[ i ];
 			var idx = faceIndicesToRemove[ i ];
-			
+
 			this.faces.splice( idx, 1 );
 			this.faces.splice( idx, 1 );
 
 
 			for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
 			for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {