OBJ texture problem

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

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.mtlv  4.3047 7.3796 -0.0000v  3.9711 7.3796 1.6896v  3.9157 7.6066 1.6660v  4.2447 7.6066 -0.0000v  3.9800 7.6822 1.6934v  4.3144 7.6822 -0.0000v  4.1107 7.6066 1.7490v  4.4561 7.6066 -0.0000v  4.2548 7.3796 1.8103v  4.6122 7.3796 -0.0000v  3.0564 7.3796 3.0564v  3.0137 7.6066 3.0137v  3.0632 7.6822 3.0632v  3.1638 7.6066 3.1638v  3.2747 7.3796 3.2747v  1.6896 7.3796 3.9711v  1.6660 7.6066 3.9157v  1.6934 7.6822 3.9800v  1.7490 7.6066 4.1107v  1.8103 7.3796 4.2548v  0.0000 7.3796 4.3047v  0.0000 7.6066 4.2447v  0.0000 7.6822 4.3144v  0.0000 7.6066 4.4561v  0.0000 7.3796 4.6122v  -1.8064 7.3796 3.9711v  -1.7153 7.6066 3.9157v  -1.7080 7.6822 3.9800v  -1.7508 7.6066 4.1107v  -1.8103 7.3796 4.2548v  -3.1601 7.3796 3.0564v  -3.0575 7.6066 3.0137v  -3.0762 7.6822 3.0632v  -3.1654 7.6066 3.1638v  -3.2747 7.3796



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 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.

E.g.,
D3DXMATRIX scale;D3DXMatrixScaling(&scale,-1.0f, 1.0f, 1.0f);world = scale*world;dev->SetTransform(D3DTS_WORLD,&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 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 on other sites
Quote:
 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.

1. 1
2. 2
3. 3
4. 4
frob
14
5. 5

• 16
• 13
• 20
• 12
• 19
• Forum Statistics

• Total Topics
632168
• Total Posts
3004543

×