Loading a .obj model with a .mtl material using a Targa image as texture, the image is loaded mirrored. It can be noticed in the following image where the left one is .tga and the right one is .png.
Opening both images in an image editor, they show to be the same. And, as long the .png image is loaded correctly, the problem is in the loader I'm using for .tga.
I'm using the TGALoader class to load the texture. The problem seems to be related to the following code from function getTgaRGBA from TGALoader.js:
TGA_ORIGIN_MASK = 0x30,
TGA_ORIGIN_SHIFT = 0x04,
TGA_ORIGIN_BL = 0x00,
TGA_ORIGIN_BR = 0x01,
TGA_ORIGIN_UL = 0x02,
TGA_ORIGIN_UR = 0x03;
function getTgaRGBA( width, height, image, palette ) {
var x_start,
y_start,
x_step,
y_step,
x_end,
y_end,
data = new Uint8Array( width * height * 4 );
//switch ( 0x02 ) {
switch ( ( header.flags & TGA_ORIGIN_MASK ) >> TGA_ORIGIN_SHIFT ) {
default:
case TGA_ORIGIN_UL:
x_start = 0;
x_step = 1;
x_end = width;
y_start = 0;
y_step = 1;
y_end = height;
break;
case TGA_ORIGIN_BL:
x_start = 0;
x_step = 1;
x_end = width;
y_start = height - 1;
y_step = - 1;
y_end = - 1;
break;
case TGA_ORIGIN_UR:
x_start = width - 1;
x_step = - 1;
x_end = - 1;
y_start = 0;
y_step = 1;
y_end = height;
break;
case TGA_ORIGIN_BR:
x_start = width - 1;
x_step = - 1;
x_end = - 1;
y_start = height - 1;
y_step = - 1;
y_end = - 1;
break;
}
If the result from switch was 0x02, the image would be loaded corrected, without being mirrored. I've tested with different .tga images, and all of them resulted the same mirroring.
I don't understand well what does the parameter of switch means... Could you guys help me to figure it out, and how could I solve my problem?
Your texture is flipped. Use this pattern:
var loader = new THREE.TGALoader();
var texture = loader.load( 'myTexture.tga' );
texture.flipY = true;
three.js r.74