Browse Source

Projector: Support BufferGeometry uvs.

Mr.doob 11 years ago
parent
commit
8972557e5c

+ 31 - 7
src/core/Projector.js

@@ -142,6 +142,7 @@ THREE.Projector = function () {
 	var RenderList = function () {
 	var RenderList = function () {
 
 
 		var normals = [];
 		var normals = [];
+		var uvs = [];
 
 
 		var object = null;
 		var object = null;
 		var material = null;
 		var material = null;
@@ -156,6 +157,7 @@ THREE.Projector = function () {
 			normalMatrix.getNormalMatrix( object.matrixWorld );
 			normalMatrix.getNormalMatrix( object.matrixWorld );
 
 
 			normals.length = 0;
 			normals.length = 0;
+			uvs.length = 0;
 
 
 		};
 		};
 
 
@@ -195,6 +197,12 @@ THREE.Projector = function () {
 
 
 		};
 		};
 
 
+		var pushUv = function ( x, y ) {
+
+			uvs.push( x, y );
+
+		};
+
 		var checkTriangleVisibility = function ( v1, v2, v3 ) {
 		var checkTriangleVisibility = function ( v1, v2, v3 ) {
 
 
 			if ( v1.visible === true || v2.visible === true || v3.visible === true ) return true;
 			if ( v1.visible === true || v2.visible === true || v3.visible === true ) return true;
@@ -257,9 +265,14 @@ THREE.Projector = function () {
 					var offset = arguments[ i ] * 3;
 					var offset = arguments[ i ] * 3;
 					var normal = _face.vertexNormalsModel[ i ];
 					var normal = _face.vertexNormalsModel[ i ];
 
 
-					normal.set( normals[ offset + 0 ], normals[ offset + 1 ], normals[ offset + 2 ] );
+					normal.set( normals[ offset ], normals[ offset + 1 ], normals[ offset + 2 ] );
 					normal.applyMatrix3( normalMatrix ).normalize();
 					normal.applyMatrix3( normalMatrix ).normalize();
 
 
+					var offset2 = arguments[ i ] * 2;
+
+					var uv = _face.uvs[ i ];
+					uv.set( uvs[ offset2 ], uvs[ offset2 + 1 ] );
+
 				}
 				}
 
 
 				_face.vertexNormalsLength = 3;
 				_face.vertexNormalsLength = 3;
@@ -279,6 +292,7 @@ THREE.Projector = function () {
 			checkBackfaceCulling: checkBackfaceCulling,
 			checkBackfaceCulling: checkBackfaceCulling,
 			pushVertex: pushVertex,
 			pushVertex: pushVertex,
 			pushNormal: pushNormal,
 			pushNormal: pushNormal,
+			pushUv: pushUv,
 			pushLine: pushLine,
 			pushLine: pushLine,
 			pushTriangle: pushTriangle
 			pushTriangle: pushTriangle
 		}
 		}
@@ -348,6 +362,18 @@ THREE.Projector = function () {
 
 
 					}
 					}
 
 
+					if ( attributes.uv !== undefined ) {
+
+						var uvs = attributes.uv.array;
+
+						for ( var i = 0, l = uvs.length; i < l; i += 2 ) {
+
+							renderList.pushUv( uvs[ i ], uvs[ i + 1 ] );
+
+						}
+
+					}
+
 					if ( attributes.index !== undefined ) {
 					if ( attributes.index !== undefined ) {
 
 
 						var indices = attributes.index.array;
 						var indices = attributes.index.array;
@@ -391,7 +417,7 @@ THREE.Projector = function () {
 
 
 					vertices = geometry.vertices;
 					vertices = geometry.vertices;
 					faces = geometry.faces;
 					faces = geometry.faces;
-					faceVertexUvs = geometry.faceVertexUvs;
+					faceVertexUvs = geometry.faceVertexUvs[ 0 ];
 
 
 					_normalMatrix.getNormalMatrix( _modelMatrix );
 					_normalMatrix.getNormalMatrix( _modelMatrix );
 
 
@@ -511,15 +537,13 @@ THREE.Projector = function () {
 
 
 						_face.vertexNormalsLength = faceVertexNormals.length;
 						_face.vertexNormalsLength = faceVertexNormals.length;
 
 
-						for ( var c = 0, cl = Math.min( faceVertexUvs.length, 3 ); c < cl; c ++ ) {
-
-							uvs = faceVertexUvs[ c ][ f ];
+						uvs = faceVertexUvs[ f ];
 
 
-							if ( uvs === undefined ) continue;
+						if ( uvs !== undefined ) {
 
 
 							for ( var u = 0, ul = uvs.length; u < ul; u ++ ) {
 							for ( var u = 0, ul = uvs.length; u < ul; u ++ ) {
 
 
-								_face.uvs[ c ][ u ] = uvs[ u ];
+								_face.uvs[ u ].copy( uvs[ u ] );
 
 
 							}
 							}
 
 

+ 1 - 1
src/renderers/CanvasRenderer.js

@@ -658,7 +658,7 @@ THREE.CanvasRenderer = function ( parameters ) {
 
 
 				if ( material.map.mapping instanceof THREE.UVMapping ) {
 				if ( material.map.mapping instanceof THREE.UVMapping ) {
 
 
-					_uvs = element.uvs[ 0 ];
+					_uvs = element.uvs;
 					patternPath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _uvs[ uv1 ].x, _uvs[ uv1 ].y, _uvs[ uv2 ].x, _uvs[ uv2 ].y, _uvs[ uv3 ].x, _uvs[ uv3 ].y, material.map );
 					patternPath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, _uvs[ uv1 ].x, _uvs[ uv1 ].y, _uvs[ uv2 ].x, _uvs[ uv2 ].y, _uvs[ uv3 ].x, _uvs[ uv3 ].y, material.map );
 
 
 				}
 				}

+ 1 - 1
src/renderers/renderables/RenderableFace.js

@@ -17,7 +17,7 @@ THREE.RenderableFace = function () {
 
 
 	this.color = null;
 	this.color = null;
 	this.material = null;
 	this.material = null;
-	this.uvs = [[]];
+	this.uvs = [ new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() ];
 
 
 	this.z = 0;
 	this.z = 0;