Sign in to follow this  
MessyO

Problem with D3DXLoadMeshFromX and textures

Recommended Posts

Hi guys, I've been using the very handy D3DXLoadMeshFromX function for sometime now in the usual manner of loading a mesh, getting it's material buffer and then iterating through the number of materials seeing if a texture filename is also present and if so loading the tetxures. My code looks just like every mesh loading smaple you've seen. I have one particular mesh which shows up absolutely fine and textured in the D3D Mesh Viewer tool, but when I load it through code some of the tetxure names are read as NULL pointers - even though they show up fine in the viewer tool. As a result I can't render the mesh subsets that use those textures, this happens for 5 out of 21 subsets. I was just wondering if this was a known problem or if anyone knows a possible solution? Many thanks, Oli.

Share this post


Link to post
Share on other sites
Hi Oli,

Interesting problem. Would it be possible for you to upload you're .x file anywhere, it could be some type of promlem with this. Although, this seems rare because it loads in the viewer. Can you show the code you are using to load the .x file?

Share this post


Link to post
Share on other sites
Are you saying that the pTextureFilename pointer for some of the materials is NULL? If so, there is something wrong with the .x file.

If not, then it could be that the texture file name includes more than just the file name itself, like the drive and/or directory the file is supposed to be in. You can use the _tsplitpath WIN32 function to break up the string into its parts and then put the filename and its extension back together in another string to pass to the D3DXCreateTextureFromFile function.

I do this when I want the textures to be in the same directory as the .x file, and use the SetCurrentDirectory function to set the working directory to that of the .x file (using _tsplitpath to extract the path from the .x file name chosen in an openfile dialog).

Share this post


Link to post
Share on other sites
Hi Guys!

The model is 22.5 MB so I can't really upload it easily :/

You're exactly right, the pTextureFilename is NULL for 5 of the textures even though the viewer tool loads the model correctly. I was assuming it was a bad export from 3D Studio Max but the fact that the tool can view it fine is really confusing me...

Share this post


Link to post
Share on other sites
What does the viewer do for the subsets that don't have a texture? I would think that it is at least drawing them with a material.

Share this post


Link to post
Share on other sites
It renders them with the textures they *should* have :s

Something else I've noticed and I don't know there's a fix for this, but some of the mesh's textures aren't correctly oriented as they were in 3D Studio, perhaps that's an exporter limitation?

Now I can see why people make their own mesh formats...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this