Skip to content

Commit e5ad64e

Browse files
committed
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).
1 parent f734e10 commit e5ad64e

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

examples/webgl_geometry_minecraft_ao.html

+20-2
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,20 @@
375375

376376
cube = new THREE.CubeGeometry( 100, 100, 100, 1, 1, 1, materials, sides );
377377

378+
// revert back to old flipped UVs
379+
380+
for ( i = 0; i < cube.faceVertexUvs[ 0 ].length; i ++ ) {
381+
382+
uv = cube.faceVertexUvs[ 0 ][ i ];
383+
384+
for ( j = 0; j < uv.length; j++ ) {
385+
386+
uv[j].v = 1 - uv[j].v;
387+
388+
}
389+
390+
}
391+
378392
// set UV tiles
379393

380394
for ( i = 0; i < cube.faceVertexUvs[ 0 ].length; i ++ ) {
@@ -496,6 +510,7 @@
496510
canvas.width = canvas.height = size;
497511

498512
var texture = new THREE.Texture( canvas, new THREE.UVMapping(), THREE.ClampToEdgeWrapping, THREE.ClampToEdgeWrapping, THREE.NearestFilter, THREE.LinearMipMapLinearFilter );
513+
texture.flipY = false;
499514

500515
function generateTexture() {
501516

@@ -535,6 +550,7 @@
535550
canvas.width = canvas.height = size;
536551

537552
var texture = new THREE.Texture( canvas, new THREE.UVMapping(), THREE.ClampToEdgeWrapping, THREE.ClampToEdgeWrapping, THREE.NearestFilter, THREE.LinearMipMapLinearFilter );
553+
texture.flipY = false;
538554

539555
function generateTexture() {
540556

@@ -563,6 +579,7 @@
563579
return new THREE.MeshLambertMaterial( { map: texture } );
564580

565581
}
582+
566583
function generateMegamaterialDebug() {
567584

568585
var canvas = document.createElement( 'canvas' ),
@@ -576,9 +593,9 @@
576593
ctx.textBaseline = "top";
577594
ctx.font = "8pt arial";
578595

579-
for ( i = 0; i < tile; i++ ) {
596+
for ( i = 0; i < tile; i ++ ) {
580597

581-
for ( j = 0; j < tile; j++ ) {
598+
for ( j = 0; j < tile; j ++ ) {
582599

583600
h = i * tile + j;
584601
ctx.fillStyle = "hsl(" + h + ",90%, 50%)";
@@ -645,6 +662,7 @@
645662
ctx.fillRect( sx + a * i, sy + b * i, width, height );
646663

647664
}
665+
648666
}
649667

650668
function drawAOSides( ctx, image, row, column, sides, tile, strength, debug_texture, debug_numbers ) {

0 commit comments

Comments
 (0)