Browse Source

Merge pull request #4995 from gero3/geometrygroupsperformance

Don't use forinstatement in renderer
Mr.doob 11 years ago
parent
commit
604f1d1bbf
2 changed files with 17 additions and 23 deletions
  1. 9 15
      src/core/Geometry.js
  2. 8 8
      src/renderers/WebGLRenderer.js

+ 9 - 15
src/core/Geometry.js

@@ -678,12 +678,13 @@ THREE.Geometry.prototype = {
 		return function ( usesFaceMaterial, maxVerticesInGroup ) {
 		return function ( usesFaceMaterial, maxVerticesInGroup ) {
 
 
 			var f, fl, face, materialIndex,
 			var f, fl, face, materialIndex,
-				groupHash, hash_map = {};
+				groupHash, hash_map = {},geometryGroup;
 
 
 			var numMorphTargets = this.morphTargets.length;
 			var numMorphTargets = this.morphTargets.length;
 			var numMorphNormals = this.morphNormals.length;
 			var numMorphNormals = this.morphNormals.length;
 
 
 			this.geometryGroups = {};
 			this.geometryGroups = {};
+			this.geometryGroupsList = [];
 
 
 			for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
 			for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
 
 
@@ -700,8 +701,9 @@ THREE.Geometry.prototype = {
 
 
 				if ( ! ( groupHash in this.geometryGroups ) ) {
 				if ( ! ( groupHash in this.geometryGroups ) ) {
 
 
-					this.geometryGroups[ groupHash ] = { 'faces3': [], 'materialIndex': materialIndex, 'vertices': 0, 'numMorphTargets': numMorphTargets, 'numMorphNormals': numMorphNormals };
-
+					geometryGroup = { 'id': geometryGroupCounter++, 'faces3': [], 'materialIndex': materialIndex, 'vertices': 0, 'numMorphTargets': numMorphTargets, 'numMorphNormals': numMorphNormals };
+					this.geometryGroups[ groupHash ] = geometryGroup;
+					this.geometryGroupsList.push(geometryGroup);
 				}
 				}
 
 
 				if ( this.geometryGroups[ groupHash ].vertices + 3 > maxVerticesInGroup ) {
 				if ( this.geometryGroups[ groupHash ].vertices + 3 > maxVerticesInGroup ) {
@@ -711,8 +713,10 @@ THREE.Geometry.prototype = {
 
 
 					if ( ! ( groupHash in this.geometryGroups ) ) {
 					if ( ! ( groupHash in this.geometryGroups ) ) {
 
 
-						this.geometryGroups[ groupHash ] = { 'faces3': [], 'materialIndex': materialIndex, 'vertices': 0, 'numMorphTargets': numMorphTargets, 'numMorphNormals': numMorphNormals };
-
+						geometryGroup = { 'id': geometryGroupCounter++, 'faces3': [], 'materialIndex': materialIndex, 'vertices': 0, 'numMorphTargets': numMorphTargets, 'numMorphNormals': numMorphNormals };
+						this.geometryGroups[ groupHash ] = geometryGroup;
+						this.geometryGroupsList.push(geometryGroup);
+						
 					}
 					}
 
 
 				}
 				}
@@ -722,16 +726,6 @@ THREE.Geometry.prototype = {
 
 
 			}
 			}
 
 
-			this.geometryGroupsList = [];
-
-			for ( var g in this.geometryGroups ) {
-
-				this.geometryGroups[ g ].id = geometryGroupCounter ++;
-
-				this.geometryGroupsList.push( this.geometryGroups[ g ] );
-
-			}
-
 		};
 		};
 
 
 	} )(),
 	} )(),

+ 8 - 8
src/renderers/WebGLRenderer.js

@@ -619,9 +619,9 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 			if ( geometry.geometryGroups !== undefined ) {
 			if ( geometry.geometryGroups !== undefined ) {
 
 
-				for ( var g in geometry.geometryGroups ) {
+				for ( var i = 0,l = geometry.geometryGroupsList.length; i<l;i++ ) {
 
 
-					var geometryGroup = geometry.geometryGroups[ g ];
+					var geometryGroup = geometry.geometryGroupsList[ i ];
 
 
 					if ( geometryGroup.numMorphTargets !== undefined ) {
 					if ( geometryGroup.numMorphTargets !== undefined ) {
 
 
@@ -3726,9 +3726,9 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 					// create separate VBOs per geometry chunk
 					// create separate VBOs per geometry chunk
 
 
-					for ( g in geometry.geometryGroups ) {
-
-						geometryGroup = geometry.geometryGroups[ g ];
+					for ( var i = 0,l = geometry.geometryGroupsList.length; i<l;i++ ) {
+	
+						geometryGroup = geometry.geometryGroupsList[ i ];
 
 
 						// initialise VBO on the first access
 						// initialise VBO on the first access
 
 
@@ -3792,9 +3792,9 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 				} else if ( geometry instanceof THREE.Geometry ) {
 				} else if ( geometry instanceof THREE.Geometry ) {
 
 
-					for ( g in geometry.geometryGroups ) {
-
-						geometryGroup = geometry.geometryGroups[ g ];
+					for ( var i = 0,l = geometry.geometryGroupsList.length; i<l;i++ ) {
+	
+						geometryGroup = geometry.geometryGroupsList[ i ];
 
 
 						addBuffer( scene.__webglObjects, geometryGroup, object );
 						addBuffer( scene.__webglObjects, geometryGroup, object );