Browse Source

Deleting middleman *Arrays if Object3D.dynamic == false.

Mr.doob 14 years ago
parent
commit
87d4ddc72d
2 changed files with 88 additions and 74 deletions
  1. 2 0
      src/core/Object3D.js
  2. 86 74
      src/renderers/WebGLRenderer.js

+ 2 - 0
src/core/Object3D.js

@@ -15,6 +15,8 @@ THREE.Object3D = function() {
 	this.rotation = new THREE.Vector3();
 	this.scale = new THREE.Vector3( 1, 1, 1 );
 
+	this.dynamic = false; // when true it retains arrays so they can be updated with __dirty*
+
 	this.rotationAutoUpdate = true;
 
 	this.matrix = new THREE.Matrix4();

+ 86 - 74
src/renderers/WebGLRenderer.js

@@ -653,22 +653,22 @@ THREE.WebGLRenderer = function ( parameters ) {
 					attribute = materials[ m ].attributes[ a ];
 
 					if( !attribute.__webglInitialized || attribute.createUniqueBuffers ) {
-						
+
 						attribute.__webglInitialized = true;
-						
+
 						size = 1;		// "f" and "i"
-	
+
 						if( attribute.type === "v2" ) size = 2;
 						else if( attribute.type === "v3" ) size = 3;
 						else if( attribute.type === "v4" ) size = 4;
 						else if( attribute.type === "c"  ) size = 3;
-	
+
 						attribute.size = size;
 						attribute.needsUpdate = true;
 						attribute.array = new Float32Array( nvertices * size );
 						attribute.buffer = _gl.createBuffer();
 						attribute.buffer.belongsToAttribute = a;
-						
+
 					}
 
 					geometryGroup.__webglCustomAttributes[ a ] = attribute;
@@ -679,11 +679,20 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		}
 
+		geometryGroup.__inittedArrays = true;
+
 	};
 
 
 	function setMeshBuffers ( geometryGroup, object, hint ) {
 
+		if ( ! geometryGroup.__inittedArrays ) {
+
+			// console.log( object );
+			return;
+
+		}
+
 		var f, fl, fi, face,
 		vertexNormals, faceNormal, normal,
 		vertexColors, faceColor,
@@ -840,61 +849,61 @@ THREE.WebGLRenderer = function ( parameters ) {
 							offset_custom = customAttribute.offset;
 							offset_customSrc = customAttribute.offsetSrc;
 
-							if( customAttribute.size === 1 ) {
+							if ( customAttribute.size === 1 ) {
+
+								if ( customAttribute.boundTo === undefined || customAttribute.boundTo === "vertices" ) {
 
-								if( customAttribute.boundTo === undefined || customAttribute.boundTo === "vertices" ) {
-									
 									customAttribute.array[ offset_custom + 0 ] = customAttribute.value[ face.a ];
 									customAttribute.array[ offset_custom + 1 ] = customAttribute.value[ face.b ];
 									customAttribute.array[ offset_custom + 2 ] = customAttribute.value[ face.c ];
-									
-								} else if( customAttribute.boundTo === "faces" ) {
-									
+
+								} else if ( customAttribute.boundTo === "faces" ) {
+
 									customAttribute.array[ offset_custom + 0 ] = customAttribute.value[ offset_customSrc ];
 									customAttribute.array[ offset_custom + 1 ] = customAttribute.value[ offset_customSrc ];
 									customAttribute.array[ offset_custom + 2 ] = customAttribute.value[ offset_customSrc ];
 
-									customAttribute.offsetSrc++;
-								
-								} else if( customAttribute.boundTo === "faceVertices" ) {
-									
+									customAttribute.offsetSrc ++;
+
+								} else if ( customAttribute.boundTo === "faceVertices" ) {
+
 									customAttribute.array[ offset_custom + 0 ] = customAttribute.value[ offset_customSrc + 0 ];
 									customAttribute.array[ offset_custom + 1 ] = customAttribute.value[ offset_customSrc + 1 ];
 									customAttribute.array[ offset_custom + 2 ] = customAttribute.value[ offset_customSrc + 2 ];
-									
+
 									customAttribute.offsetSrc += 3;
-	
+
 								}
 
 								customAttribute.offset += 3;
 
 							} else {
 
-								if( customAttribute.boundTo === undefined || customAttribute.boundTo === "vertices" ) {
-									
+								if ( customAttribute.boundTo === undefined || customAttribute.boundTo === "vertices" ) {
+
 									v1 = customAttribute.value[ face.a ];
 									v2 = customAttribute.value[ face.b ];
 									v3 = customAttribute.value[ face.c ];
-									
-								} else if( customAttribute.boundTo === "faces" ) {
-									
+
+								} else if ( customAttribute.boundTo === "faces" ) {
+
 									v1 = customAttribute.value[ offset_customSrc ];
 									v2 = customAttribute.value[ offset_customSrc ];
 									v3 = customAttribute.value[ offset_customSrc ];
 
-									customAttribute.offsetSrc++;
-									
-								} else if( customAttribute.boundTo === "faceVertices" ) {
-									
+									customAttribute.offsetSrc ++;
+
+								} else if ( customAttribute.boundTo === "faceVertices" ) {
+
 									v1 = customAttribute.value[ offset_customSrc + 0 ];
 									v2 = customAttribute.value[ offset_customSrc + 1 ];
 									v3 = customAttribute.value[ offset_customSrc + 2 ];
-									
+
 									customAttribute.offsetSrc += 3;
 								}
-								
 
-								if( customAttribute.size === 2 ) {
+
+								if ( customAttribute.size === 2 ) {
 
 									customAttribute.array[ offset_custom + 0 ] = v1.x;
 									customAttribute.array[ offset_custom + 1 ] = v1.y;
@@ -907,10 +916,10 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 									customAttribute.offset += 6;
 
-								} else if( customAttribute.size === 3 ) {
+								} else if ( customAttribute.size === 3 ) {
+
+									if ( customAttribute.type === "c" ) {
 
-									if( customAttribute.type === "c" ) {
-										
 										customAttribute.array[ offset_custom + 0 ] = v1.r;
 										customAttribute.array[ offset_custom + 1 ] = v1.g;
 										customAttribute.array[ offset_custom + 2 ] = v1.b;
@@ -922,9 +931,9 @@ THREE.WebGLRenderer = function ( parameters ) {
 										customAttribute.array[ offset_custom + 6 ] = v3.r;
 										customAttribute.array[ offset_custom + 7 ] = v3.g;
 										customAttribute.array[ offset_custom + 8 ] = v3.b;
-										
+
 									} else {
-										
+
 										customAttribute.array[ offset_custom + 0 ] = v1.x;
 										customAttribute.array[ offset_custom + 1 ] = v1.y;
 										customAttribute.array[ offset_custom + 2 ] = v1.z;
@@ -936,7 +945,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 										customAttribute.array[ offset_custom + 6 ] = v3.x;
 										customAttribute.array[ offset_custom + 7 ] = v3.y;
 										customAttribute.array[ offset_custom + 8 ] = v3.z;
-										
+
 									}
 
 									customAttribute.offset += 9;
@@ -1271,31 +1280,31 @@ THREE.WebGLRenderer = function ( parameters ) {
 							offset_custom = customAttribute.offset;
 							offset_customSrc = customAttribute.offsetSrc;
 
-							if( customAttribute.size === 1 ) {
+							if ( customAttribute.size === 1 ) {
+
+								if ( customAttribute.boundTo === undefined || customAttribute.boundTo === "vertices" ) {
 
-								if( customAttribute.boundTo === undefined || customAttribute.boundTo === "vertices" ) {
-									
 									customAttribute.array[ offset_custom + 0 ] = customAttribute.value[ face.a ];
 									customAttribute.array[ offset_custom + 1 ] = customAttribute.value[ face.b ];
 									customAttribute.array[ offset_custom + 2 ] = customAttribute.value[ face.c ];
 									customAttribute.array[ offset_custom + 3 ] = customAttribute.value[ face.d ];
-									
-								} else if( customAttribute.boundTo === "faces" ) {
-									
+
+								} else if ( customAttribute.boundTo === "faces" ) {
+
 									customAttribute.array[ offset_custom + 0 ] = customAttribute.value[ offset_customSrc ];
 									customAttribute.array[ offset_custom + 1 ] = customAttribute.value[ offset_customSrc ];
 									customAttribute.array[ offset_custom + 2 ] = customAttribute.value[ offset_customSrc ];
 									customAttribute.array[ offset_custom + 3 ] = customAttribute.value[ offset_customSrc ];
 
 									customAttribute.offsetSrc++;
-									
-								} else if( customAttribute.boundTo === "faceVertices" ) {
-									
+
+								} else if ( customAttribute.boundTo === "faceVertices" ) {
+
 									customAttribute.array[ offset_custom + 0 ] = customAttribute.value[ offset_customSrc + 0 ];
 									customAttribute.array[ offset_custom + 1 ] = customAttribute.value[ offset_customSrc + 1 ];
 									customAttribute.array[ offset_custom + 2 ] = customAttribute.value[ offset_customSrc + 2 ];
 									customAttribute.array[ offset_custom + 3 ] = customAttribute.value[ offset_customSrc + 3 ];
-									
+
 									customAttribute.offsetSrc += 4;
 								}
 
@@ -1303,34 +1312,34 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 							} else {
 
-								if( customAttribute.boundTo === undefined || customAttribute.boundTo === "vertices" ) {
-									
+								if ( customAttribute.boundTo === undefined || customAttribute.boundTo === "vertices" ) {
+
 									v1 = customAttribute.value[ face.a ];
 									v2 = customAttribute.value[ face.b ];
 									v3 = customAttribute.value[ face.c ];
 									v4 = customAttribute.value[ face.d ];
-									
-								} else if( customAttribute.boundTo === "faces" ) {
-									
+
+								} else if ( customAttribute.boundTo === "faces" ) {
+
 									v1 = customAttribute.value[ offset_customSrc ];
 									v2 = customAttribute.value[ offset_customSrc ];
 									v3 = customAttribute.value[ offset_customSrc ];
 									v4 = customAttribute.value[ offset_customSrc ];
 
 									customAttribute.offsetSrc++;
-									
-								} else if( customAttribute.boundTo === "faceVertices" ) {
-									
+
+								} else if ( customAttribute.boundTo === "faceVertices" ) {
+
 									v1 = customAttribute.value[ offset_customSrc + 0 ];
 									v2 = customAttribute.value[ offset_customSrc + 1 ];
 									v3 = customAttribute.value[ offset_customSrc + 2 ];
 									v4 = customAttribute.value[ offset_customSrc + 3 ];
-									
+
 									customAttribute.offsetSrc += 4;
 								}
 
 
-								if( customAttribute.size === 2 ) {
+								if ( customAttribute.size === 2 ) {
 
 									customAttribute.array[ offset_custom + 0 ] = v1.x;
 									customAttribute.array[ offset_custom + 1 ] = v1.y;
@@ -1346,10 +1355,10 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 									customAttribute.offset += 8;
 
-								} else if( customAttribute.size === 3 ) {
+								} else if ( customAttribute.size === 3 ) {
+
+									if ( customAttribute.type === "c" ) {
 
-									if( customAttribute.type === "c" ) {
-										
 										customAttribute.array[ offset_custom + 0  ] = v1.r;
 										customAttribute.array[ offset_custom + 1  ] = v1.g;
 										customAttribute.array[ offset_custom + 2  ] = v1.b;
@@ -1367,7 +1376,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 										customAttribute.array[ offset_custom + 11 ] = v4.b;
 
 									} else {
-										
+
 										customAttribute.array[ offset_custom + 0  ] = v1.x;
 										customAttribute.array[ offset_custom + 1  ] = v1.y;
 										customAttribute.array[ offset_custom + 2  ] = v1.z;
@@ -1383,7 +1392,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 										customAttribute.array[ offset_custom + 9  ] = v4.x;
 										customAttribute.array[ offset_custom + 10 ] = v4.y;
 										customAttribute.array[ offset_custom + 11 ] = v4.z;
-										
+
 									}
 
 									customAttribute.offset += 12;
@@ -1848,20 +1857,23 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		}
 
-		/*
-		delete geometryGroup.__colorArray;
-		delete geometryGroup.__normalArray;
-		delete geometryGroup.__tangentArray;
-		delete geometryGroup.__uvArray;
-		delete geometryGroup.__uv2Array;
-		delete geometryGroup.__faceArray;
-		delete geometryGroup.__vertexArray;
-		delete geometryGroup.__lineArray;
-		delete geometryGroup.__skinVertexAArray;
-		delete geometryGroup.__skinVertexBArray;
-		delete geometryGroup.__skinIndexArray;
-		delete geometryGroup.__skinWeightArray;
-		*/
+		if ( ! object.dynamic ) {
+
+			delete geometryGroup.__inittedArrays;
+			delete geometryGroup.__colorArray;
+			delete geometryGroup.__normalArray;
+			delete geometryGroup.__tangentArray;
+			delete geometryGroup.__uvArray;
+			delete geometryGroup.__uv2Array;
+			delete geometryGroup.__faceArray;
+			delete geometryGroup.__vertexArray;
+			delete geometryGroup.__lineArray;
+			delete geometryGroup.__skinVertexAArray;
+			delete geometryGroup.__skinVertexBArray;
+			delete geometryGroup.__skinIndexArray;
+			delete geometryGroup.__skinWeightArray;
+
+		}
 
 	};