Ver código fonte

Removed scene.__objectsAdded and scene.__objectsRemoved.

Mr.doob 11 anos atrás
pai
commit
62c269b596
3 arquivos alterados com 13 adições e 155 exclusões
  1. 0 32
      src/core/Object3D.js
  2. 13 42
      src/renderers/WebGLRenderer.js
  3. 0 81
      src/scenes/Scene.js

+ 0 - 32
src/core/Object3D.js

@@ -329,22 +329,6 @@ THREE.Object3D.prototype = {
 
 
 			this.children.push( object );
 			this.children.push( object );
 
 
-			// add to scene
-
-			var scene = this;
-
-			while ( scene.parent !== undefined ) {
-
-				scene = scene.parent;
-
-			}
-
-			if ( scene !== undefined && scene instanceof THREE.Scene )  {
-
-				scene.__addObject( object );
-
-			}
-
 		} else {
 		} else {
 		
 		
 			console.error( "THREE.Object3D.add:", object, "is not an instance of THREE.Object3D." );
 			console.error( "THREE.Object3D.add:", object, "is not an instance of THREE.Object3D." );
@@ -376,22 +360,6 @@ THREE.Object3D.prototype = {
 
 
 			this.children.splice( index, 1 );
 			this.children.splice( index, 1 );
 
 
-			// remove from scene
-
-			var scene = this;
-
-			while ( scene.parent !== undefined ) {
-
-				scene = scene.parent;
-
-			}
-
-			if ( scene !== undefined && scene instanceof THREE.Scene ) {
-
-				scene.__removeObject( object );
-
-			}
-
 		}
 		}
 
 
 	},
 	},

+ 13 - 42
src/renderers/WebGLRenderer.js

@@ -434,8 +434,6 @@ THREE.WebGLRenderer = function ( parameters ) {
 		_oldDoubleSided = - 1;
 		_oldDoubleSided = - 1;
 		_oldFlipSided = - 1;
 		_oldFlipSided = - 1;
 
 
-		initObjects( scene );
-
 		this.shadowMapPlugin.update( scene, camera );
 		this.shadowMapPlugin.update( scene, camera );
 
 
 	};
 	};
@@ -3198,7 +3196,12 @@ THREE.WebGLRenderer = function ( parameters ) {
 		_projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
 		_projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
 		_frustum.setFromMatrix( _projScreenMatrix );
 		_frustum.setFromMatrix( _projScreenMatrix );
 
 
-		initObjects( scene );
+		if ( ! scene.__webglObjects ) {
+
+			scene.__webglObjects = {};
+			scene.__webglObjectsImmediate = [];
+
+		}
 
 
 		lights.length = 0;
 		lights.length = 0;
 		opaqueObjects.length = 0;
 		opaqueObjects.length = 0;
@@ -3319,11 +3322,13 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 		}
 		}
 		
 		
+		initObject( object, scene );
+		
 		var webglObjects = scene.__webglObjects[ object.id ];
 		var webglObjects = scene.__webglObjects[ object.id ];
 		
 		
 		if ( webglObjects && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
 		if ( webglObjects && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
 			
 			
-			updateObject( scene, object );
+			updateObject( object, scene );
 			
 			
 			for ( var i = 0, l = webglObjects.length; i < l; i ++ ) {
 			for ( var i = 0, l = webglObjects.length; i < l; i ++ ) {
 				
 				
@@ -3571,38 +3576,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 	};
 	};
 
 
-	// Objects refresh
-
-	var initObjects = function ( scene ) {
-
-		if ( ! scene.__webglObjects ) {
-
-			scene.__webglObjects = {};
-			scene.__webglObjectsImmediate = [];
-
-		}
-
-		while ( scene.__objectsAdded.length ) {
-
-			addObject( scene.__objectsAdded[ 0 ], scene );
-			scene.__objectsAdded.splice( 0, 1 );
-
-		}
-
-		while ( scene.__objectsRemoved.length ) {
-
-			removeObject( scene.__objectsRemoved[ 0 ], scene );
-			scene.__objectsRemoved.splice( 0, 1 );
-
-		}
-
-	};
-
-	// Objects adding
-
-	function addObject( object, scene ) {
-
-		var g, geometry, geometryGroup;
+	function initObject( object, scene ) {
 
 
 		if ( object.__webglInit === undefined ) {
 		if ( object.__webglInit === undefined ) {
 
 
@@ -3613,7 +3587,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 		}
 		}
 		
 		
-		geometry = object.geometry;
+		var geometry = object.geometry;
 		
 		
 		if ( geometry === undefined ) {
 		if ( geometry === undefined ) {
 
 
@@ -3671,8 +3645,6 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 			if ( object instanceof THREE.Mesh ) {
 			if ( object instanceof THREE.Mesh ) {
 
 
-				geometry = object.geometry;
-
 				if ( geometry instanceof THREE.BufferGeometry ) {
 				if ( geometry instanceof THREE.BufferGeometry ) {
 
 
 					addBuffer( scene.__webglObjects, geometry, object );
 					addBuffer( scene.__webglObjects, geometry, object );
@@ -3681,7 +3653,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 					for ( var i = 0,l = geometry.geometryGroupsList.length; i<l;i++ ) {
 					for ( var i = 0,l = geometry.geometryGroupsList.length; i<l;i++ ) {
 	
 	
-						geometryGroup = geometry.geometryGroupsList[ i ];
+						var geometryGroup = geometry.geometryGroupsList[ i ];
 						addBuffer( scene.__webglObjects, geometryGroup, object );
 						addBuffer( scene.__webglObjects, geometryGroup, object );
 						
 						
 					}
 					}
@@ -3690,7 +3662,6 @@ THREE.WebGLRenderer = function ( parameters ) {
 			} else if ( object instanceof THREE.Line ||
 			} else if ( object instanceof THREE.Line ||
 						object instanceof THREE.PointCloud ) {
 						object instanceof THREE.PointCloud ) {
 
 
-				geometry = object.geometry;
 				addBuffer( scene.__webglObjects, geometry, object );
 				addBuffer( scene.__webglObjects, geometry, object );
 
 
 			} else if ( object instanceof THREE.ImmediateRenderObject || object.immediateRenderCallback ) {
 			} else if ( object instanceof THREE.ImmediateRenderObject || object.immediateRenderCallback ) {
@@ -3789,7 +3760,7 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 
 	// Objects updates
 	// Objects updates
 
 
-	function updateObject(scene, object ) {
+	function updateObject( object, scene ) {
 
 
 		var geometry = object.geometry,
 		var geometry = object.geometry,
 			geometryGroup, customAttributesDirty, material;
 			geometryGroup, customAttributesDirty, material;

+ 0 - 81
src/scenes/Scene.js

@@ -12,91 +12,10 @@ THREE.Scene = function () {
 	this.autoUpdate = true; // checked by the renderer
 	this.autoUpdate = true; // checked by the renderer
 	this.matrixAutoUpdate = false;
 	this.matrixAutoUpdate = false;
 
 
-	this.__objectsAdded = [];
-	this.__objectsRemoved = [];
-
 };
 };
 
 
 THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
 THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
 
 
-THREE.Scene.prototype.__addObject = function ( object ) {
-
-	if ( object instanceof THREE.Light ) {
-
-		if ( object.target && object.target.parent === undefined ) {
-
-			this.add( object.target );
-
-		}
-
-	} else if ( ! ( object instanceof THREE.Camera || object instanceof THREE.Bone ) ) {
-
-		this.__objectsAdded.push( object );
-
-		// check if previously removed
-
-		var i = this.__objectsRemoved.indexOf( object );
-
-		if ( i !== - 1 ) {
-
-			this.__objectsRemoved.splice( i, 1 );
-
-		}
-
-	}
-
-	this.dispatchEvent( { type: 'objectAdded', object: object } );
-	object.dispatchEvent( { type: 'addedToScene', scene: this } );
-
-	for ( var c = 0; c < object.children.length; c ++ ) {
-
-		this.__addObject( object.children[ c ] );
-
-	}
-
-};
-
-THREE.Scene.prototype.__removeObject = function ( object ) {
-
-	if ( object instanceof THREE.Light ) {
-
-		if ( object.shadowCascadeArray ) {
-
-			for ( var x = 0; x < object.shadowCascadeArray.length; x ++ ) {
-
-				this.__removeObject( object.shadowCascadeArray[ x ] );
-
-			}
-
-		}
-
-	} else if ( ! ( object instanceof THREE.Camera ) ) {
-
-		this.__objectsRemoved.push( object );
-
-		// check if previously added
-
-		var i = this.__objectsAdded.indexOf( object );
-
-		if ( i !== - 1 ) {
-
-			this.__objectsAdded.splice( i, 1 );
-
-		}
-
-	}
-
-	this.dispatchEvent( { type: 'objectRemoved', object: object } );
-	object.dispatchEvent( { type: 'removedFromScene', scene: this } );
-
-	for ( var c = 0; c < object.children.length; c ++ ) {
-
-		this.__removeObject( object.children[ c ] );
-
-	}
-
-};
-
 THREE.Scene.prototype.clone = function ( object ) {
 THREE.Scene.prototype.clone = function ( object ) {
 
 
 	if ( object === undefined ) object = new THREE.Scene();
 	if ( object === undefined ) object = new THREE.Scene();