Jump to content

  • Log In with Google      Sign In   
  • Create Account


OpenGL UV Mapping and FBX Loading


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Danicco   Members   -  Reputation: 449

Like
0Likes
Like

Posted 22 March 2014 - 05:13 PM

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.

 

Example_zps3765bc58.jpg

 

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?



Sponsor:

#2 Danicco   Members   -  Reputation: 449

Like
0Likes
Like

Posted 22 March 2014 - 06:35 PM

Another example, probably better explained:

Example2_zps8473a260.jpg

 

The 3DS Max vertex data is upside down in my engine, and I'm guessing it's because the XYZ values in 3DS Max are left handed, and OpenGL is right handed right?

That's manageable, but the UV data is messed around too, and I noticed that the way I was even going on about mirroring textures is wrong because I was assuming a texture that covers the entire image, not just part of it.

 

I'm meaning that, in the example above, if I only put some texture color in the Purple area, and I mirror it horizontally with my current code, I'm just picking the UV values that correspond to the Red area in the texture, and that's wrong... I made this assuming 2D images and square textures and now that I'm loading directly from the FBX, it's not working for 3D models.

 

Using "1.0f - uv" values work for 2D planes, but not for 3D models...


Edited by Danicco, 22 March 2014 - 06:47 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS