Browse Source

More uvs fixes.
About to try to bring Face4 back.

Mr.doob 14 years ago
parent
commit
f35e8092c6

+ 14 - 3
examples/canvas_lights_pointlights.html

@@ -73,15 +73,26 @@
 				light3 = new THREE.PointLight( 0x80ff80 );
 				scene.addLight( light3 );
 
-				particle1 = new THREE.Particle( new THREE.ParticleCircleMaterial( { color: 0xff0040 } ) );
+				var PI2 = Math.PI * 2;
+				var program = function ( context, color ) {
+
+					context.fillStyle = color.__styleString;
+					context.beginPath();
+					context.arc( 0, 0, 1, 0, PI2, true );
+					context.closePath();
+					context.fill();
+
+				}
+
+				particle1 = new THREE.Particle( new THREE.ParticleCanvasMaterial( { color: 0xff0040, program: program } ) );
 				particle1.scale.x = particle1.scale.y = particle1.scale.z = 0.5;
 				scene.addObject( particle1 );
 
-				particle2 = new THREE.Particle( new THREE.ParticleCircleMaterial( { color: 0x0040ff } ) );
+				particle2 = new THREE.Particle( new THREE.ParticleCanvasMaterial( { color: 0x0040ff, program: program } ) );
 				particle2.scale.x = particle2.scale.y = particle2.scale.z = 0.5;
 				scene.addObject( particle2 );
 
-				particle3 = new THREE.Particle( new THREE.ParticleCircleMaterial( { color: 0x80ff80 } ) );
+				particle3 = new THREE.Particle( new THREE.ParticleCanvasMaterial( { color: 0x80ff80, program: program } ) );
 				particle3.scale.x = particle3.scale.y = particle3.scale.z = 0.5;
 				scene.addObject( particle3 );
 

+ 12 - 1
examples/canvas_materials.html

@@ -111,7 +111,18 @@
 
 				}
 
-				particleLight = new THREE.Particle( new THREE.ParticleCircleMaterial( { color: 0xffffff } ) );
+				var PI2 = Math.PI * 2;
+				var program = function ( context, color ) {
+
+					context.fillStyle = color.__styleString;
+					context.beginPath();
+					context.arc( 0, 0, 1, 0, PI2, true );
+					context.closePath();
+					context.fill();
+
+				}
+
+				particleLight = new THREE.Particle( new THREE.ParticleCanvasMaterial( { color: 0xffffff, program: program } ) );
 				particleLight.scale.x = particleLight.scale.y = particleLight.scale.z = 4;
 				scene.addObject( particleLight );
 

+ 1 - 1
examples/canvas_sandbox.html

@@ -174,7 +174,7 @@
 				for ( var i = 0; i < 10; i ++ ) {
 
 					sphere = new THREE.Mesh( geometry, material );
-					sphere.overdraw = true;
+					// sphere.overdraw = true;
 
 					sphere.position.x = Math.random() * 1000 - 500;
 					sphere.position.y = Math.random() * 1000 - 500;

+ 2 - 2
examples/obj/Qrcode.js

@@ -1444,13 +1444,13 @@ var Qrcode = function () {
 
 	function f3( a, b, c, material ) {
 
-		scope.faces.push( new THREE.Face3( a, b, c, null, material ) );
+		scope.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
 
 	}
 
 	function f4( a, b, c, d, material ) {
 
-		scope.faces.push( new THREE.Face4( a, b, c, d, null, material ) );
+		scope.faces.push( new THREE.Face4( a, b, c, d, null, null, material ) );
 
 	}
 

+ 2 - 8
examples/obj/WaltHead.js

@@ -4892,15 +4892,9 @@ var WaltHead = function () {
 
 	}
 
-	function f3( a, b, c, nx, ny, nz ) {
+	function f3( a, b, c ) {
 
-		scope.faces.push( new THREE.Face3( a, b, c, (nx || ny || nz) ? new THREE.Vector3( nx, ny, nz ) : null ) );
-
-	}
-
-	function f4( a, b, c, d, nx, ny, nz ) {
-
-		scope.faces.push( new THREE.Face4( a, b, c, d, (nx || ny || nz) ? new THREE.Vector3( nx, ny, nz ) : null ) );
+		scope.faces.push( new THREE.Face3( a, b, c ) );
 
 	}
 

+ 2 - 1
src/renderers/CanvasRenderer.js

@@ -554,7 +554,8 @@ THREE.CanvasRenderer = function () {
 
 					if ( material.map.mapping instanceof THREE.UVMapping ) {
 
-						texturePath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, material.map.image, element.uvs[ 0 ].u, element.uvs[ 0 ].v, element.uvs[ 1 ].u, element.uvs[ 1 ].v, element.uvs[ 2 ].u, element.uvs[ 2 ].v );
+						_uvs = element.uvs[ 0 ];
+						texturePath( _v1x, _v1y, _v2x, _v2y, _v3x, _v3y, material.map.image, _uvs[ 0 ].u, _uvs[ 0 ].v, _uvs[ 1 ].u, _uvs[ 1 ].v, _uvs[ 2 ].u, _uvs[ 2 ].v );
 
 					}
 

+ 56 - 41
src/renderers/Projector.js

@@ -8,7 +8,7 @@ THREE.Projector = function() {
 
 	var _object, _objectCount, _objectPool = [],
 	_vertex, _vertexCount, _vertexPool = [],
-	_face3, _face32, _face3Count, _face3Pool = [],
+	_face, _face3Count, _face3Pool = [], _face4Count, _face4Pool = [],
 	_line, _lineCount, _linePool = [],
 	_particle, _particleCount, _particlePool = [],
 
@@ -95,14 +95,14 @@ THREE.Projector = function() {
 	this.projectScene = function ( scene, camera, sort ) {
 
 		var renderList = [], near = camera.near, far = camera.far,
-		o, ol, v, vl, f, fl, n, nl, u, ul, objects, object,
-		objectMatrix, objectMaterials, objectOverdraw,
-		objectMatrixRotation,
+		o, ol, v, vl, f, fl, n, nl, c, cl, u, ul, objects, object,
+		objectMatrix, objectMatrixRotation, objectMaterials, objectOverdraw,
 		geometry, vertices, vertex, vertexPositionScreen,
 		faces, face, faceVertexNormals, normal, faceVertexUvs, uvs,
 		v1, v2, v3, v4;
 
 		_face3Count = 0;
+		_face4Count = 0;
 		_lineCount = 0;
 		_particleCount = 0;
 
@@ -134,6 +134,7 @@ THREE.Projector = function() {
 				geometry = object.geometry;
 				vertices = geometry.vertices;
 				faces = geometry.faces;
+				faceVertexUvs = geometry.faceVertexUvs;
 
 				for ( v = 0, vl = vertices.length; v < vl; v ++ ) {
 
@@ -162,66 +163,70 @@ THREE.Projector = function() {
 						v2 = _vertexPool[ face.b ];
 						v3 = _vertexPool[ face.c ];
 
-						if ( v1.visible && v2.visible && v3.visible ) {
+						if ( !v1.visible || !v2.visible || !v3.visible ) continue;
 
-							if ( ( object.doubleSided || ( object.flipSided !=
-							   ( 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 ) ) ) {
+						if ( object.doubleSided || ( object.flipSided !=
+						   ( 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 ) ) {
 
-								_face3 = getNextFaceInPool();
+							_face = getNextFace3InPool();
 
-								_face3.v1.copy( v1 );
-								_face3.v2.copy( v2 );
-								_face3.v3.copy( v3 );
+							_face.v1.copy( v1 );
+							_face.v2.copy( v2 );
+							_face.v3.copy( v3 );
 
-								_face3.normalWorld.copy( face.normal );
-								objectMatrixRotation.multiplyVector3( _face3.normalWorld );
+							_face.normalWorld.copy( face.normal );
+							objectMatrixRotation.multiplyVector3( _face.normalWorld );
 
-								_face3.centroidWorld.copy( face.centroid );
-								objectMatrix.multiplyVector3( _face3.centroidWorld );
+							_face.centroidWorld.copy( face.centroid );
+							objectMatrix.multiplyVector3( _face.centroidWorld );
 
-								_face3.centroidScreen.copy( _face3.centroidWorld );
-								_projScreenMatrix.multiplyVector3( _face3.centroidScreen );
+							_face.centroidScreen.copy( _face.centroidWorld );
+							_projScreenMatrix.multiplyVector3( _face.centroidScreen );
 
-								faceVertexNormals = face.vertexNormals;
-								_face3VertexNormals = _face3.vertexNormalsWorld;
+							faceVertexNormals = face.vertexNormals;
 
-								for ( n = 0, nl = faceVertexNormals.length; n < nl; n ++ ) {
+							for ( n = 0, nl = faceVertexNormals.length; n < nl; n ++ ) {
 
-									normal = _face3VertexNormals[ n ];
-									normal.copy( faceVertexNormals[ n ] );
-									objectMatrixRotation.multiplyVector3( normal );
+								normal = _face.vertexNormalsWorld[ n ];
+								normal.copy( faceVertexNormals[ n ] );
+								objectMatrixRotation.multiplyVector3( normal );
 
-								}
-
-								faceVertexUvs = geometry.faceVertexUvs;
+							}
 
-								for ( u = 0, ul = faceVertexUvs.length; u < ul; u ++ ) {
+							for ( c = 0, cl = faceVertexUvs.length; c < cl; c ++ ) {
 
-									uvs = faceVertexUvs[ u ][ f ];
+								uvs = faceVertexUvs[ c ][ f ];
 
-									if ( uvs ) {
+								if ( !uvs ) continue;
 
-										_face3.uvs[ u ][ 0 ] = uvs[ 0 ];
-										_face3.uvs[ u ][ 1 ] = uvs[ 1 ];
-										_face3.uvs[ u ][ 2 ] = uvs[ 2 ];
+								for ( u = 0, ul = uvs.length; u < ul; u ++ ) {
 
-									}
+									_face.uvs[ c ][ u ] = uvs[ u ];
 
 								}
 
-								_face3.meshMaterials = objectMaterials;
-								_face3.faceMaterials = face.materials;
-								_face3.overdraw = objectOverdraw;
+							}
 
-								_face3.z = _face3.centroidScreen.z;
+							_face.meshMaterials = objectMaterials;
+							_face.faceMaterials = face.materials;
+							_face.overdraw = objectOverdraw;
 
-								renderList.push( _face3 );
+							_face.z = _face.centroidScreen.z;
 
-							}
+							renderList.push( _face );
 
 						}
 
+					} else if ( face instanceof THREE.Face4 ) {
+
+						v1 = _vertexPool[ face.a ];
+						v2 = _vertexPool[ face.b ];
+						v3 = _vertexPool[ face.c ];
+						v4 = _vertexPool[ face.d ];
+
+						if ( !v1.visible || !v2.visible || !v3.visible || !v4.visible ) continue;
+
 					} /* else if ( face instanceof THREE.Face4 ) {
 
 						v1 = vertices[ face.a ]; v2 = vertices[ face.b ]; v3 = vertices[ face.c ]; v4 = vertices[ face.d ];
@@ -412,7 +417,7 @@ THREE.Projector = function() {
 
 	}
 
-	function getNextFaceInPool() {
+	function getNextFace3InPool() {
 
 		var face = _face3Pool[ _face3Count ] = _face3Pool[ _face3Count ] || new THREE.RenderableFace3();
 
@@ -422,6 +427,16 @@ THREE.Projector = function() {
 
 	}
 
+	function getNextFace4InPool() {
+
+		var face = _face4Pool[ _face4Count ] = _face4Pool[ _face4Count ] || new THREE.RenderableFace4();
+
+		_face4Count ++;
+
+		return face;
+
+	}
+
 	function getNextLineInPool() {
 
 		var line = _linePool[ _lineCount ] = _linePool[ _lineCount ] || new THREE.RenderableLine();