Browse Source

Updated builds.

Mr.doob 11 years ago
parent
commit
0d2d02c0e3
2 changed files with 465 additions and 373 deletions
  1. 215 124
      build/three.js
  2. 250 249
      build/three.min.js

+ 215 - 124
build/three.js

@@ -7961,27 +7961,6 @@ THREE.Projector = function () {
 
 	};
 
-	var projectVertex = function ( vertex ) {
-
-		var position = vertex.position;
-		var positionWorld = vertex.positionWorld;
-		var positionScreen = vertex.positionScreen;
-
-		positionWorld.copy( position ).applyMatrix4( _modelMatrix );
-		positionScreen.copy( positionWorld ).applyMatrix4( _viewProjectionMatrix );
-
-		var invW = 1 / positionScreen.w;
-
-		positionScreen.x *= invW;
-		positionScreen.y *= invW;
-		positionScreen.z *= invW;
-
-		vertex.visible = positionScreen.x >= -1 && positionScreen.x <= 1 &&
-				 positionScreen.y >= -1 && positionScreen.y <= 1 &&
-				 positionScreen.z >= -1 && positionScreen.z <= 1;
-
-	};
-
 	var projectObject = function ( object ) {
 
 		if ( object.visible === false ) return;
@@ -8030,11 +8009,105 @@ THREE.Projector = function () {
 
 	};
 
+	var RenderState = function () {
+
+		var object = null;
+
+		var setObject = function ( value ) {
+
+			object = value;
+
+		};
+
+		var projectVertex = function ( vertex ) {
+
+			var position = vertex.position;
+			var positionWorld = vertex.positionWorld;
+			var positionScreen = vertex.positionScreen;
+
+			positionWorld.copy( position ).applyMatrix4( _modelMatrix );
+			positionScreen.copy( positionWorld ).applyMatrix4( _viewProjectionMatrix );
+
+			var invW = 1 / positionScreen.w;
+
+			positionScreen.x *= invW;
+			positionScreen.y *= invW;
+			positionScreen.z *= invW;
+
+			vertex.visible = positionScreen.x >= -1 && positionScreen.x <= 1 &&
+					 positionScreen.y >= -1 && positionScreen.y <= 1 &&
+					 positionScreen.z >= -1 && positionScreen.z <= 1;
+
+		};
+
+		var handleVertex = function ( x, y, z ) {
+
+			_vertex = getNextVertexInPool();
+			_vertex.position.set( x, y, z );
+
+			projectVertex( _vertex );
+
+		};
+
+		var checkTriangleVisibility = function ( v1, v2, v3 ) {
+
+			_points3[ 0 ] = v1.positionScreen;
+			_points3[ 1 ] = v2.positionScreen;
+			_points3[ 2 ] = v3.positionScreen;
+
+			if ( v1.visible === true || v2.visible === true || v3.visible === true ||
+				_clipBox.isIntersectionBox( _boundingBox.setFromPoints( _points3 ) ) ) {
+
+				return ( ( v3.positionScreen.x - v1.positionScreen.x ) *
+					    ( v2.positionScreen.y - v1.positionScreen.y ) -
+					    ( v3.positionScreen.y - v1.positionScreen.y ) *
+					    ( v2.positionScreen.x - v1.positionScreen.x ) ) < 0;
+
+			}
+
+			return false;
+
+		};
+
+		var handleTriangle = function ( a, b, c ) {
+
+			var v1 = _vertexPool[ a ];
+			var v2 = _vertexPool[ b ];
+			var v3 = _vertexPool[ c ];
+
+			if ( checkTriangleVisibility( v1, v2, v3 ) === true ) {
+
+				_face = getNextFace3InPool();
+
+				_face.id = object.id;
+				_face.v1.copy( v1 );
+				_face.v2.copy( v2 );
+				_face.v3.copy( v3 );
+
+				_face.material = object.material;
+
+				_renderData.elements.push( _face );
+
+			}
+
+		};
+
+		return {
+			setObject: setObject,
+			projectVertex: projectVertex,
+			checkTriangleVisibility: checkTriangleVisibility,
+			handleVertex: handleVertex,
+			handleTriangle: handleTriangle
+		}
+
+	};
+
+	var renderState = new RenderState();
+
 	this.projectScene = function ( scene, camera, sortObjects, sortElements ) {
 
-		var visible = false,
-		object, geometry, vertices, faces, face, faceVertexNormals, faceVertexUvs, uvs,
-		v1, v2, v3, v4, isFaceMaterial, objectMaterials;
+		var object, geometry, vertices, faces, face, faceVertexNormals, faceVertexUvs, uvs,
+		isFaceMaterial, objectMaterials;
 
 		_face3Count = 0;
 		_lineCount = 0;
@@ -8058,6 +8131,8 @@ THREE.Projector = function () {
 
 			object = _renderData.objects[ o ].object;
 
+			renderState.setObject( object );
+
 			_modelMatrix = object.matrixWorld;
 
 			_vertexCount = 0;
@@ -8066,176 +8141,192 @@ THREE.Projector = function () {
 
 				geometry = object.geometry;
 
-				vertices = geometry.vertices;
-				faces = geometry.faces;
-				faceVertexUvs = geometry.faceVertexUvs;
+				if ( geometry instanceof THREE.BufferGeometry ) {
 
-				_normalMatrix.getNormalMatrix( _modelMatrix );
+					var attributes = geometry.attributes;
 
-				isFaceMaterial = object.material instanceof THREE.MeshFaceMaterial;
-				objectMaterials = isFaceMaterial === true ? object.material : null;
+					if ( attributes.position !== undefined ) {
 
-				for ( var v = 0, vl = vertices.length; v < vl; v ++ ) {
+						var positions = attributes.position.array;
 
-					_vertex = getNextVertexInPool();
-					_vertex.position.copy( vertices[ v ] );
+						for ( var i = 0, l = positions.length; i < l; i += 3 ) {
 
-					projectVertex( _vertex );
+							renderState.handleVertex( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] );
 
-				}
+						}
 
-				for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
+						if ( attributes.index !== undefined ) {
 
-					face = faces[ f ];
+							var indices = attributes.index.array;
 
-					var material = isFaceMaterial === true
-						? objectMaterials.materials[ face.materialIndex ]
-						: object.material;
+							for ( var i = 0, l = indices.length; i < l; i += 3 ) {
 
-					if ( material === undefined ) continue;
+								renderState.handleTriangle( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
 
-					var side = material.side;
+							}
 
-					v1 = _vertexPool[ face.a ];
-					v2 = _vertexPool[ face.b ];
-					v3 = _vertexPool[ face.c ];
+						} else {
 
-					if ( material.morphTargets === true ) {
+							for ( var i = 0, l = positions.length; i < l; i += 3 ) {
 
-						var morphTargets = geometry.morphTargets;
-						var morphInfluences = object.morphTargetInfluences;
+								renderState.handleTriangle( i, i + 1, i + 2 );
 
-						var v1p = v1.position;
-						var v2p = v2.position;
-						var v3p = v3.position;
+							}
 
-						_vA.set( 0, 0, 0 );
-						_vB.set( 0, 0, 0 );
-						_vC.set( 0, 0, 0 );
+						}
 
-						for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
+					}
 
-							var influence = morphInfluences[ t ];
+				} else if ( geometry instanceof THREE.Geometry ) {
 
-							if ( influence === 0 ) continue;
+					vertices = geometry.vertices;
+					faces = geometry.faces;
+					faceVertexUvs = geometry.faceVertexUvs;
 
-							var targets = morphTargets[ t ].vertices;
+					_normalMatrix.getNormalMatrix( _modelMatrix );
 
-							_vA.x += ( targets[ face.a ].x - v1p.x ) * influence;
-							_vA.y += ( targets[ face.a ].y - v1p.y ) * influence;
-							_vA.z += ( targets[ face.a ].z - v1p.z ) * influence;
+					isFaceMaterial = object.material instanceof THREE.MeshFaceMaterial;
+					objectMaterials = isFaceMaterial === true ? object.material : null;
 
-							_vB.x += ( targets[ face.b ].x - v2p.x ) * influence;
-							_vB.y += ( targets[ face.b ].y - v2p.y ) * influence;
-							_vB.z += ( targets[ face.b ].z - v2p.z ) * influence;
+					for ( var v = 0, vl = vertices.length; v < vl; v ++ ) {
 
-							_vC.x += ( targets[ face.c ].x - v3p.x ) * influence;
-							_vC.y += ( targets[ face.c ].y - v3p.y ) * influence;
-							_vC.z += ( targets[ face.c ].z - v3p.z ) * influence;
+						var vertex = vertices[ v ];
+						renderState.handleVertex( vertex.x, vertex.y, vertex.z );
 
-						}
+					}
 
-						v1.position.add( _vA );
-						v2.position.add( _vB );
-						v3.position.add( _vC );
+					for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
 
-						projectVertex( v1 );
-						projectVertex( v2 );
-						projectVertex( v3 );
+						face = faces[ f ];
 
-					}
+						var material = isFaceMaterial === true
+							? objectMaterials.materials[ face.materialIndex ]
+							: object.material;
 
-					_points3[ 0 ] = v1.positionScreen;
-					_points3[ 1 ] = v2.positionScreen;
-					_points3[ 2 ] = v3.positionScreen;
+						if ( material === undefined ) continue;
 
-					if ( v1.visible === true || v2.visible === true || v3.visible === true ||
-						_clipBox.isIntersectionBox( _boundingBox.setFromPoints( _points3 ) ) ) {
+						var side = material.side;
 
-						visible = ( ( v3.positionScreen.x - v1.positionScreen.x ) *
-							    ( v2.positionScreen.y - v1.positionScreen.y ) -
-							    ( v3.positionScreen.y - v1.positionScreen.y ) *
-							    ( v2.positionScreen.x - v1.positionScreen.x ) ) < 0;
+						var v1 = _vertexPool[ face.a ];
+						var v2 = _vertexPool[ face.b ];
+						var v3 = _vertexPool[ face.c ];
 
-						if ( side === THREE.DoubleSide || visible === ( side === THREE.FrontSide ) ) {
+						if ( material.morphTargets === true ) {
 
-							_face = getNextFace3InPool();
+							var morphTargets = geometry.morphTargets;
+							var morphInfluences = object.morphTargetInfluences;
 
-							_face.id = object.id;
-							_face.v1.copy( v1 );
-							_face.v2.copy( v2 );
-							_face.v3.copy( v3 );
+							var v1p = v1.position;
+							var v2p = v2.position;
+							var v3p = v3.position;
 
-						} else {
+							_vA.set( 0, 0, 0 );
+							_vB.set( 0, 0, 0 );
+							_vC.set( 0, 0, 0 );
 
-							continue;
+							for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
 
-						}
+								var influence = morphInfluences[ t ];
 
-					} else {
+								if ( influence === 0 ) continue;
 
-						continue;
+								var targets = morphTargets[ t ].vertices;
 
-					}
+								_vA.x += ( targets[ face.a ].x - v1p.x ) * influence;
+								_vA.y += ( targets[ face.a ].y - v1p.y ) * influence;
+								_vA.z += ( targets[ face.a ].z - v1p.z ) * influence;
 
-					_face.normalModel.copy( face.normal );
+								_vB.x += ( targets[ face.b ].x - v2p.x ) * influence;
+								_vB.y += ( targets[ face.b ].y - v2p.y ) * influence;
+								_vB.z += ( targets[ face.b ].z - v2p.z ) * influence;
 
-					if ( visible === false && ( side === THREE.BackSide || side === THREE.DoubleSide ) ) {
+								_vC.x += ( targets[ face.c ].x - v3p.x ) * influence;
+								_vC.y += ( targets[ face.c ].y - v3p.y ) * influence;
+								_vC.z += ( targets[ face.c ].z - v3p.z ) * influence;
 
-						_face.normalModel.negate();
+							}
 
-					}
+							v1.position.add( _vA );
+							v2.position.add( _vB );
+							v3.position.add( _vC );
 
-					_face.normalModel.applyMatrix3( _normalMatrix ).normalize();
+							renderState.projectVertex( v1 );
+							renderState.projectVertex( v2 );
+							renderState.projectVertex( v3 );
 
-					_face.normalModelView.copy( _face.normalModel ).applyMatrix3( _normalViewMatrix );
+						}
+
+						var visible = renderState.checkTriangleVisibility( v1, v2, v3 );
 
-					_face.centroidModel.copy( face.centroid ).applyMatrix4( _modelMatrix );
+						if ( visible === ( side === THREE.BackSide ) ) continue;
 
-					faceVertexNormals = face.vertexNormals;
+						_face = getNextFace3InPool();
 
-					for ( var n = 0, nl = Math.min( faceVertexNormals.length, 3 ); n < nl; n ++ ) {
+						_face.id = object.id;
+						_face.v1.copy( v1 );
+						_face.v2.copy( v2 );
+						_face.v3.copy( v3 );
 
-						var normalModel = _face.vertexNormalsModel[ n ];
-						normalModel.copy( faceVertexNormals[ n ] );
+						_face.normalModel.copy( face.normal );
 
 						if ( visible === false && ( side === THREE.BackSide || side === THREE.DoubleSide ) ) {
 
-							normalModel.negate();
+							_face.normalModel.negate();
 
 						}
 
-						normalModel.applyMatrix3( _normalMatrix ).normalize();
+						_face.normalModel.applyMatrix3( _normalMatrix ).normalize();
 
-						var normalModelView = _face.vertexNormalsModelView[ n ];
-						normalModelView.copy( normalModel ).applyMatrix3( _normalViewMatrix );
+						_face.normalModelView.copy( _face.normalModel ).applyMatrix3( _normalViewMatrix );
 
-					}
+						_face.centroidModel.copy( face.centroid ).applyMatrix4( _modelMatrix );
+
+						faceVertexNormals = face.vertexNormals;
+
+						for ( var n = 0, nl = Math.min( faceVertexNormals.length, 3 ); n < nl; n ++ ) {
+
+							var normalModel = _face.vertexNormalsModel[ n ];
+							normalModel.copy( faceVertexNormals[ n ] );
 
-					_face.vertexNormalsLength = faceVertexNormals.length;
+							if ( visible === false && ( side === THREE.BackSide || side === THREE.DoubleSide ) ) {
 
-					for ( var c = 0, cl = Math.min( faceVertexUvs.length, 3 ); c < cl; c ++ ) {
+								normalModel.negate();
 
-						uvs = faceVertexUvs[ c ][ f ];
+							}
+
+							normalModel.applyMatrix3( _normalMatrix ).normalize();
+
+							var normalModelView = _face.vertexNormalsModelView[ n ];
+							normalModelView.copy( normalModel ).applyMatrix3( _normalViewMatrix );
+
+						}
+
+						_face.vertexNormalsLength = faceVertexNormals.length;
 
-						if ( uvs === undefined ) continue;
+						for ( var c = 0, cl = Math.min( faceVertexUvs.length, 3 ); c < cl; c ++ ) {
 
-						for ( var u = 0, ul = uvs.length; u < ul; u ++ ) {
+							uvs = faceVertexUvs[ c ][ f ];
 
-							_face.uvs[ c ][ u ] = uvs[ u ];
+							if ( uvs === undefined ) continue;
+
+							for ( var u = 0, ul = uvs.length; u < ul; u ++ ) {
+
+								_face.uvs[ c ][ u ] = uvs[ u ];
+
+							}
 
 						}
 
-					}
+						_face.color = face.color;
+						_face.material = material;
 
-					_face.color = face.color;
-					_face.material = material;
+						_centroid.copy( _face.centroidModel ).applyProjection( _viewProjectionMatrix );
 
-					_centroid.copy( _face.centroidModel ).applyProjection( _viewProjectionMatrix );
+						_face.z = _centroid.z;
 
-					_face.z = _centroid.z;
+						_renderData.elements.push( _face );
 
-					_renderData.elements.push( _face );
+					}
 
 				}
 

File diff suppressed because it is too large
+ 250 - 249
build/three.min.js


Some files were not shown because too many files changed in this diff