浏览代码

Traversal code clean up.

Mr.doob 10 年之前
父节点
当前提交
b771d2ae19
共有 3 个文件被更改,包括 65 次插入59 次删除
  1. 13 7
      src/core/Object3D.js
  2. 43 43
      src/renderers/WebGLRenderer.js
  3. 9 9
      src/renderers/webgl/WebGLShadowMap.js

+ 13 - 7
src/core/Object3D.js

@@ -504,9 +504,11 @@ THREE.Object3D.prototype = {
 
 		callback( this );
 
-		for ( var i = 0, l = this.children.length; i < l; i ++ ) {
+		var children = this.children;
+
+		for ( var i = 0, l = children.length; i < l; i ++ ) {
 
-			this.children[ i ].traverse( callback );
+			children[ i ].traverse( callback );
 
 		}
 
@@ -518,9 +520,11 @@ THREE.Object3D.prototype = {
 
 		callback( this );
 
-		for ( var i = 0, l = this.children.length; i < l; i ++ ) {
+		var children = this.children;
 
-			this.children[ i ].traverseVisible( callback );
+		for ( var i = 0, l = children.length; i < l; i ++ ) {
+
+			children[ i ].traverseVisible( callback );
 
 		}
 
@@ -528,11 +532,13 @@ THREE.Object3D.prototype = {
 
 	traverseAncestors: function ( callback ) {
 
-		if ( this.parent ) {
+		var parent = this.parent;
+
+		if ( parent !== undefined ) {
 
-			callback( this.parent );
+			callback( parent );
 
-			this.parent.traverseAncestors( callback );
+			parent.traverseAncestors( callback );
 
 		}
 

+ 43 - 43
src/renderers/WebGLRenderer.js

@@ -1717,81 +1717,79 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 	function projectObject( object ) {
 
-		if ( object.visible === true ) {
+		if ( object.visible === false ) return;
 
-			if ( object instanceof THREE.Scene || object instanceof THREE.Group ) {
+		if ( object instanceof THREE.Scene || object instanceof THREE.Group ) {
 
-				// skip
+			// skip
 
-			} else {
+		} else {
 
-				// update Skeleton objects
-				if ( object instanceof THREE.SkinnedMesh ) {
+			// update Skeleton objects
+			if ( object instanceof THREE.SkinnedMesh ) {
 
-					object.skeleton.update();
+				object.skeleton.update();
 
-				}
+			}
 
-				objects.init( object );
+			objects.init( object );
 
-				if ( object instanceof THREE.Light ) {
+			if ( object instanceof THREE.Light ) {
 
-					lights.push( object );
+				lights.push( object );
 
-				} else if ( object instanceof THREE.Sprite ) {
+			} else if ( object instanceof THREE.Sprite ) {
 
-					sprites.push( object );
+				sprites.push( object );
 
-				} else if ( object instanceof THREE.LensFlare ) {
+			} else if ( object instanceof THREE.LensFlare ) {
 
-					lensFlares.push( object );
+				lensFlares.push( object );
 
-				} else if ( object instanceof THREE.ImmediateRenderObject ) {
+			} else if ( object instanceof THREE.ImmediateRenderObject ) {
 
-					var material = object.material;
+				var material = object.material;
 
-					if ( material.transparent ) {
+				if ( material.transparent ) {
 
-						transparentImmediateObjects.push( object );
+					transparentImmediateObjects.push( object );
 
-					} else {
-
-						opaqueImmediateObjects.push( object );
+				} else {
 
-					}
+					opaqueImmediateObjects.push( object );
 
-				} else {
+				}
 
-					var webglObject = objects.objects[ object.id ];
+			} else {
 
-					if ( webglObject && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
+				var webglObject = objects.objects[ object.id ];
 
-						var material = object.material;
+				if ( webglObject && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
 
-						if ( properties.get( material ) ) {
+					var material = object.material;
 
-							material.program = properties.get( material ).program;
+					if ( properties.get( material ) ) {
 
-						}
+						material.program = properties.get( material ).program;
 
-						if ( material.transparent ) {
+					}
 
-							transparentObjects.push( webglObject );
+					if ( material.transparent ) {
 
-						} else {
+						transparentObjects.push( webglObject );
 
-							opaqueObjects.push( webglObject );
+					} else {
 
-						}
+						opaqueObjects.push( webglObject );
 
-						if ( _this.sortObjects === true ) {
+					}
 
-							_vector3.setFromMatrixPosition( object.matrixWorld );
-							_vector3.applyProjection( _projScreenMatrix );
+					if ( _this.sortObjects === true ) {
 
-							webglObject.z = _vector3.z;
+						_vector3.setFromMatrixPosition( object.matrixWorld );
+						_vector3.applyProjection( _projScreenMatrix );
 
-						}
+						webglObject.z = _vector3.z;
 
 					}
 
@@ -1799,11 +1797,13 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 			}
 
-			for ( var i = 0, l = object.children.length; i < l; i ++ ) {
+		}
 
-				projectObject( object.children[ i ] );
+		var children = object.children;
 
-			}
+		for ( var i = 0, l = children.length; i < l; i ++ ) {
+
+			projectObject( children[ i ] );
 
 		}
 

+ 9 - 9
src/renderers/webgl/WebGLShadowMap.js

@@ -269,22 +269,22 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
 
 	function projectObject( object, camera ) {
 
-		if ( object.visible === true ) {
+		if ( object.visible === false ) return;
 
-			var webglObject = _objects.objects[ object.id ];
+		var webglObject = _objects.objects[ object.id ];
 
-			if ( webglObject && object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
+		if ( webglObject && object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
 
-				object._modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
-				_renderList.push( webglObject );
+			object._modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
+			_renderList.push( webglObject );
 
-			}
+		}
 
-			for ( var i = 0, l = object.children.length; i < l; i ++ ) {
+		var children = object.children;
 
-				projectObject( object.children[ i ], camera );
+		for ( var i = 0, l = children.length; i < l; i ++ ) {
 
-			}
+			projectObject( children[ i ], camera );
 
 		}