I'm reading the FBX file format and getting the UVs from the models, but I'm having weird issues with the UV Mapping from the textures.
Also, I'm using the sbti_image loader to load a PNG file, not sure if it's relevant (I think it reverses the pixels but I think that's common for all image types).
So, when I load a 2D Image, using a texture I have the image mirrored both in horizontal and vertical. That was fine if I just reversed the positions and mirror the texture, but that only works when the texture is full. I didn't want to keep that as a "fix" so I tried to get the correct orientation from the FBX and apply it properly.
The 2nd image is how it is in the 3DS Max, in the first image is how my engine is displaying it.
I'm reversing the V component so the texture is at least correct vertically:
for(int i = 0; i < totaUVs; i++)
{
float u = UVs[uIndex];
float v = UVs[uIndex + 1];
UVs[uIndex] = u;
UVs[uIndex + 1] = 1.0f - v;
}
If I don't do this, the image is also mirrored upside down.
The "1.0f - v" part is correcting the V part, but the U is still incorrectly mapped. I can't do "1.0f - u" because then the U part would be reversed in the image, so in an image of 200 pixels width, a U part of 10 would be 190, meaning it works if the image is full (100% width and 100% height) but not when I'm using a mapped texture like this.
How can I solve this?
I'm thinking in reversing the pixels in my image data but if possible I'd like to find a "smarter" solution, any help with this?