Pārlūkot izejas kodu

WebGLRenderer: Simplified WebGLObjects.

Mr.doob 10 gadi atpakaļ
vecāks
revīzija
d383c8c0b6

+ 43 - 53
src/renderers/WebGLRenderer.js

@@ -521,7 +521,6 @@ THREE.WebGLRenderer = function ( parameters ) {
 		resetGLState();
 		setDefaultGLState();
 
-		objects.clear();
 		properties.clear();
 
 	};
@@ -1260,91 +1259,82 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		if ( object.visible === false ) return;
 
-		if ( object instanceof THREE.Scene || object instanceof THREE.Group ) {
+		if ( object instanceof THREE.Light ) {
 
-			// skip
+			lights.push( object );
 
-		} else {
-
-			// update Skeleton objects
-			if ( object instanceof THREE.SkinnedMesh ) {
-
-				object.skeleton.update();
-
-			}
-
-			objects.init( object );
+		} else if ( object instanceof THREE.Sprite ) {
 
-			if ( object instanceof THREE.Light ) {
+			sprites.push( object );
 
-				lights.push( object );
+		} else if ( object instanceof THREE.LensFlare ) {
 
-			} else if ( object instanceof THREE.Sprite ) {
+			lensFlares.push( object );
 
-				sprites.push( object );
+		} else if ( object instanceof THREE.ImmediateRenderObject ) {
 
-			} else if ( object instanceof THREE.LensFlare ) {
+			var material = object.material;
 
-				lensFlares.push( object );
+			if ( material.transparent ) {
 
-			} else if ( object instanceof THREE.ImmediateRenderObject ) {
+				transparentImmediateObjects.push( object );
 
-				var material = object.material;
-
-				if ( material.transparent ) {
-
-					transparentImmediateObjects.push( object );
+			} else {
 
-				} else {
+				opaqueImmediateObjects.push( object );
 
-					opaqueImmediateObjects.push( object );
+			}
 
-				}
+		} else if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.PointCloud ){
 
-			} else {
+			if ( object instanceof THREE.SkinnedMesh ) {
 
-				var webglObject = objects.objects[ object.id ];
+				object.skeleton.update();
 
-				if ( webglObject && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
+			}
 
-					var material = object.material;
+			if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
 
-					if ( material.visible === true ) {
+				var material = object.material;
 
-						if ( material instanceof THREE.MeshFaceMaterial ) {
+				if ( material.visible === true ) {
 
-							var materials = material.materials;
+					if ( material instanceof THREE.MeshFaceMaterial ) {
 
-							for ( var i = 0, l = materials.length; i < l; i ++ ) {
+						var materials = material.materials;
 
-								materials[ i ].program = properties.get( materials[ i ] ).program;
+						for ( var i = 0, l = materials.length; i < l; i ++ ) {
 
-							}
+							materials[ i ].program = properties.get( materials[ i ] ).program;
 
-						} else {
+						}
 
-							material.program = properties.get( material ).program;
+					} else {
 
-						}
+						material.program = properties.get( material ).program;
 
-						if ( material.transparent ) {
+					}
 
-							transparentObjects.push( webglObject );
+					if ( _this.sortObjects === true ) {
 
-						} else {
+						_vector3.setFromMatrixPosition( object.matrixWorld );
+						_vector3.applyProjection( _projScreenMatrix );
 
-							opaqueObjects.push( webglObject );
+					}
 
-						}
+					var renderItem = {
+						id: object.id,
+						object: object,
+						z: _vector3.z
+					};
 
-						if ( _this.sortObjects === true ) {
+					if ( material.transparent ) {
 
-							_vector3.setFromMatrixPosition( object.matrixWorld );
-							_vector3.applyProjection( _projScreenMatrix );
+						transparentObjects.push( renderItem );
 
-							webglObject.z = _vector3.z;
+					} else {
 
-						}
+						opaqueObjects.push( renderItem );
 
 					}
 
@@ -1370,8 +1360,8 @@ THREE.WebGLRenderer = function ( parameters ) {
 
 		for ( var i = 0, l = renderList.length; i < l; i ++ ) {
 
-			var webglObject = renderList[ i ];
-			var object = webglObject.object;
+			var renderItem = renderList[ i ];
+			var object = renderItem.object;
 			var geometry = objects.update( object );
 
 			object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );

+ 0 - 69
src/renderers/webgl/WebGLObjects.js

@@ -4,73 +4,10 @@
 
 THREE.WebGLObjects = function ( gl, properties, info ) {
 
-	var objects = {};
-
 	var geometries = new THREE.WebGLGeometries( gl, properties, info );
 
 	//
 
-	function onObjectRemoved( event ) {
-
-		var object = event.target;
-
-		object.traverse( function ( child ) {
-
-			child.removeEventListener( 'remove', onObjectRemoved );
-			removeObject( child );
-
-		} );
-
-	}
-
-	function removeObject( object ) {
-
-		if ( object instanceof THREE.Mesh ||
-			 object instanceof THREE.PointCloud ||
-			 object instanceof THREE.Line ) {
-
-			delete objects[ object.id ];
-
-		}
-
-		properties.delete( object );
-
-	}
-
-	//
-
-	this.objects = objects;
-
-	this.init = function ( object ) {
-
-		var objectProperties = properties.get( object );
-
-		if ( objectProperties.__webglInit === undefined ) {
-
-			objectProperties.__webglInit = true;
-
-			object.addEventListener( 'removed', onObjectRemoved );
-
-		}
-
-		if ( objectProperties.__webglActive === undefined ) {
-
-			objectProperties.__webglActive = true;
-
-			if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.PointCloud ) {
-
-				objects[ object.id ] = {
-					id: object.id,
-					object: object,
-					z: 0
-				};
-
-			}
-
-		}
-
-	};
-
 	function update( object ) {
 
 		// TODO: Avoid updating twice (when using shadowMap). Maybe add frame counter.
@@ -283,10 +220,4 @@ THREE.WebGLObjects = function ( gl, properties, info ) {
 
 	this.update = update;
 
-	this.clear = function () {
-
-		objects = {};
-
-	};
-
 };

+ 11 - 13
src/renderers/webgl/WebGLShadowMap.js

@@ -198,15 +198,11 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
 
 			// render regular objects
 
-			var webglObject, object, geometry, material;
-
 			for ( var j = 0, jl = _renderList.length; j < jl; j ++ ) {
 
-				webglObject = _renderList[ j ];
-
-				object = webglObject.object;
-				geometry = _objects.update( object );
-				material = object.material;
+				var object = _renderList[ j ];
+				var geometry = _objects.update( object );
+				var material = object.material;
 
 				if ( material instanceof THREE.MeshFaceMaterial ) {
 
@@ -295,16 +291,18 @@ THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
 
 		if ( object.visible === false ) return;
 
-		var webglObject = _objects.objects[ object.id ];
+		if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.PointCloud ) {
 
-		if ( webglObject && object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
+			if ( object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
 
-			var material = object.material;
+				var material = object.material;
 
-			if ( material !== null && material.visible === true ) {
+				if ( material.visible === true ) {
 
-				object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
-				_renderList.push( webglObject );
+					object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
+					_renderList.push( object );
+
+				}
 
 			}