Browse Source

Ninja-hack to make minecraft AO example working again after big deflipping.

Don't try this at home kids. Finally had to do it like this, alternative was just getting slowly insane (I spent lot of time on futile attempts to make it in the "right" way, it doesn't even show any texture with UNPACK_FLIP_Y_WEBGL toggled on).
alteredq 13 years ago
parent
commit
e5ad64e8fe
1 changed files with 20 additions and 2 deletions
  1. 20 2
      examples/webgl_geometry_minecraft_ao.html

+ 20 - 2
examples/webgl_geometry_minecraft_ao.html

@@ -375,6 +375,20 @@
 
 						cube = new THREE.CubeGeometry( 100, 100, 100, 1, 1, 1, materials, sides );
 
+						// revert back to old flipped UVs
+
+						for ( i = 0; i < cube.faceVertexUvs[ 0 ].length; i ++ ) {
+
+							uv = cube.faceVertexUvs[ 0 ][ i ];
+
+							for ( j = 0; j < uv.length; j++ ) {
+
+								uv[j].v = 1 - uv[j].v;
+
+							}
+
+						}
+
 						// set UV tiles
 
 						for ( i = 0; i < cube.faceVertexUvs[ 0 ].length; i ++ ) {
@@ -496,6 +510,7 @@
 				canvas.width = canvas.height = size;
 
 				var texture = new THREE.Texture( canvas, new THREE.UVMapping(), THREE.ClampToEdgeWrapping, THREE.ClampToEdgeWrapping, THREE.NearestFilter, THREE.LinearMipMapLinearFilter );
+				texture.flipY = false;
 
 				function generateTexture() {
 
@@ -535,6 +550,7 @@
 				canvas.width = canvas.height = size;
 
 				var texture = new THREE.Texture( canvas, new THREE.UVMapping(), THREE.ClampToEdgeWrapping, THREE.ClampToEdgeWrapping, THREE.NearestFilter, THREE.LinearMipMapLinearFilter );
+				texture.flipY = false;
 
 				function generateTexture() {
 
@@ -563,6 +579,7 @@
 				return new THREE.MeshLambertMaterial( { map: texture } );
 
 			}
+
 			function generateMegamaterialDebug() {
 
 				var canvas = document.createElement( 'canvas' ),
@@ -576,9 +593,9 @@
 				ctx.textBaseline = "top";
 				ctx.font = "8pt arial";
 
-				for ( i = 0; i < tile; i++ ) {
+				for ( i = 0; i < tile; i ++ ) {
 
-					for ( j = 0; j < tile; j++ ) {
+					for ( j = 0; j < tile; j ++ ) {
 
 						h = i * tile + j;
 						ctx.fillStyle = "hsl(" + h + ",90%, 50%)";
@@ -645,6 +662,7 @@
 					ctx.fillRect( sx + a * i, sy + b * i, width, height );
 
 				}
+
 			}
 
 			function drawAOSides( ctx, image, row, column, sides, tile, strength, debug_texture, debug_numbers ) {