Browse Source

Projector: Implemented BufferGeometry normals.

Mr.doob 11 years ago
parent
commit
086f108d10
1 changed files with 33 additions and 0 deletions
  1. 33 0
      src/core/Projector.js

+ 33 - 0
src/core/Projector.js

@@ -155,11 +155,17 @@ THREE.Projector = function () {
 
 
 	var RenderList = function () {
 	var RenderList = function () {
 
 
+		var normals = [];
+
 		var object = null;
 		var object = null;
+		var normalMatrix = new THREE.Matrix3();
 
 
 		var setObject = function ( value ) {
 		var setObject = function ( value ) {
 
 
 			object = value;
 			object = value;
+			normalMatrix.getNormalMatrix( object.matrixWorld );
+
+			normals.length = 0;
 
 
 		};
 		};
 
 
@@ -193,6 +199,12 @@ THREE.Projector = function () {
 
 
 		};
 		};
 
 
+		var pushNormal = function ( x, y, z ) {
+
+			normals.push( x, y, z );
+
+		};
+
 		var checkTriangleVisibility = function ( v1, v2, v3 ) {
 		var checkTriangleVisibility = function ( v1, v2, v3 ) {
 
 
 			_points3[ 0 ] = v1.positionScreen;
 			_points3[ 0 ] = v1.positionScreen;
@@ -247,6 +259,18 @@ THREE.Projector = function () {
 				_face.v3.copy( v3 );
 				_face.v3.copy( v3 );
 				_face.z = ( v1.positionScreen.z + v2.positionScreen.z + v3.positionScreen.z ) / 3;
 				_face.z = ( v1.positionScreen.z + v2.positionScreen.z + v3.positionScreen.z ) / 3;
 
 
+				for ( var i = 0; i < 3; i ++ ) {
+
+					var offset = arguments[ i ] * 3;
+					var normal = _face.vertexNormalsModel[ i ];
+
+					normal.set( normals[ offset + 0 ], normals[ offset + 1 ], normals[ offset + 2 ] );
+					normal.applyMatrix3( normalMatrix ).normalize();
+
+				}
+
+				_face.vertexNormalsLength = 3;
+
 				_face.material = object.material;
 				_face.material = object.material;
 
 
 				_renderData.elements.push( _face );
 				_renderData.elements.push( _face );
@@ -260,6 +284,7 @@ THREE.Projector = function () {
 			projectVertex: projectVertex,
 			projectVertex: projectVertex,
 			checkTriangleVisibility: checkTriangleVisibility,
 			checkTriangleVisibility: checkTriangleVisibility,
 			pushVertex: pushVertex,
 			pushVertex: pushVertex,
+			pushNormal: pushNormal,
 			pushLine: pushLine,
 			pushLine: pushLine,
 			pushTriangle: pushTriangle
 			pushTriangle: pushTriangle
 		}
 		}
@@ -318,6 +343,14 @@ THREE.Projector = function () {
 
 
 						}
 						}
 
 
+						var normals = attributes.normal.array;
+
+						for ( var i = 0, l = normals.length; i < l; i += 3 ) {
+
+							renderList.pushNormal( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] );
+
+						}
+
 						if ( attributes.index !== undefined ) {
 						if ( attributes.index !== undefined ) {
 
 
 							var indices = attributes.index.array;
 							var indices = attributes.index.array;