Browse Source

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 11 năm trước cách đây
mục cha
commit
089741d0ad
1 tập tin đã thay đổi với 5 bổ sung9 xóa
  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
 		// (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 );
 			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 {
 
 			vertices = this.__tmpVertices;
@@ -225,6 +218,9 @@ THREE.Geometry.prototype = {
 
 			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[ 1 ].copy( vertices[ face.b ] );
 			face.vertexNormals[ 2 ].copy( vertices[ face.c ] );
@@ -573,7 +569,7 @@ THREE.Geometry.prototype = {
 
 		for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
 			var idx = faceIndicesToRemove[ i ];
-			
+
 			this.faces.splice( idx, 1 );
 
 			for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {