Jump to content
  • Advertisement
Sign in to follow this  

OBJ texture problem

This topic is 3043 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I've created a obj loader in directx and everything has gone fine until I get to the texture stuff. When I unwrap my model and put a texture on it, it shows up fine in the modeler, but when I export it and load myself, the textures are screwed up, like the uv mappings are wrong or something. So I created a simple teacup to demonstrate.

mtllib teapot.mtl
v 4.3047 7.3796 -0.0000
v 3.9711 7.3796 1.6896
v 3.9157 7.6066 1.6660
v 4.2447 7.6066 -0.0000
v 3.9800 7.6822 1.6934
v 4.3144 7.6822 -0.0000
v 4.1107 7.6066 1.7490
v 4.4561 7.6066 -0.0000
v 4.2548 7.3796 1.8103
v 4.6122 7.3796 -0.0000
v 3.0564 7.3796 3.0564
v 3.0137 7.6066 3.0137
v 3.0632 7.6822 3.0632
v 3.1638 7.6066 3.1638
v 3.2747 7.3796 3.2747
v 1.6896 7.3796 3.9711
v 1.6660 7.6066 3.9157
v 1.6934 7.6822 3.9800
v 1.7490 7.6066 4.1107
v 1.8103 7.3796 4.2548
v 0.0000 7.3796 4.3047
v 0.0000 7.6066 4.2447
v 0.0000 7.6822 4.3144
v 0.0000 7.6066 4.4561
v 0.0000 7.3796 4.6122
v -1.8064 7.3796 3.9711
v -1.7153 7.6066 3.9157
v -1.7080 7.6822 3.9800
v -1.7508 7.6066 4.1107
v -1.8103 7.3796 4.2548
v -3.1601 7.3796 3.0564
v -3.0575 7.6066 3.0137
v -3.0762 7.6822 3.0632
v -3.1654 7.6066 3.1638
v -3.2747 7.3796
  • Share this post

    Link to post
    Share on other sites
    Why don't you try with a simple plane and a texture first. Should be pretty easy for such a simple geometry to find out what's missing. If that flips for the tea pot, I'm sure it will flip for a simpler geometry.

    Share this post

    Link to post
    Share on other sites
    I suspect the modeler and obj file are for a right-hand system and you're using the default DirectX left-hand system to display it.

    That is, when viewed with Y-axis up and X-axis to the right, the modeler expects the +Z axis to point toward the viewer. DirectX, by default, expects the +Z axis to point away from the viewer in tha case.

    NOTE: in the above explanation, depending on the modeler, it may be the X or Y axis to be swapped, instead of the Z-axis.

    If that's the case, the problem isn't the tex coords, it's the vertex positions and you can't "correct" for it when you load. Try pre-multiplying your world matrix by a scaling matrix before you render.


    D3DXMATRIX scale;
    D3DXMatrixScaling(&scale,-1.0f, 1.0f, 1.0f);
    world = scale*world;
    // do your rendering

    The scaling may be ( -1, 1, 1 ) or ( 1, -1, 1 ) or ( 1, 1, -1). You may have to try all 3 to see.

    If one of those combinations works, then you'll either have to use the scaling matrix to render correctly (simplest solution), or load all the data, apply the scaling matrix to all the data and then build your mesh/vertexbuffer.

    Share this post

    Link to post
    Share on other sites
    Wow, thanks a lot Buckeye! I have no idea why i didn't think of that before...This is my first time rendering, so DirectX seems a little overwhelming for me.
    So now it displays correctly, and I'm still using the LH coordinate system, but now it has the teapot's x-axis reversed. So anotherwards when I want it to go left it goes right.
    It's no big deal or anything, I can just code the x position to be negated but I wonder if thats normal.

    Share this post

    Link to post
    Share on other sites
    I can just code the x position to be negated but I wonder if thats normal?

    Yeah, it's a bit of a pain using a scaling matrix like that. You'll have to compensate when you create the translation/rotation matrices for the teapot's world.

    EDIT: You can also apply the scale matrix to the entire mesh after it's loaded.
    For each vertex position: D3DXVec3TransformCoord(&pos, &pos, &scale)
    For each normal: D3DXVec3TransformNormal(&norm,&norm,&scale)

    Then you can set your world translations and rotations without messing with the scale.

    I think that should fix it all.

    Share this post

    Link to post
    Share on other sites
    Sign in to follow this  

    • Advertisement

    Important Information

    By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

    We are the game development community.

    Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

    Sign me up!