How to automatically load textures associated with a 3D model

Started by
2 comments, last by Anzipane 11 years, 2 months ago

Hi,

I'm trying to figure out how to automatically load textures (associated with a 3D model) into XNA without having to load them manually (like BasiEffect does for example, you just need to load the model).

Now, I can't use the BasicEffect class because I'm using a custom effect to draw the models, so how can I proceed with this? Do I have to make a Custom content processor or what? Thanks.

Advertisement

As long the texture name is part of the file you can have your loader extract the name and load it. Alot of the time the texture path will point to something that is usually match whoever did the export. So the filepath will be very different then what you have on your machine. So what you can do in that case is assume that the texture needs to be in the same path as the model and just extract the name and load it in your content loader.

As the saying goes, why re-invent the wheel. The default behaviour for the ModelProcessor loads associated textures into into BasicEffect instances, so the least complicated way to load the textures and use your own effect is to load the Model then replace the effects with your own versions (copying the textures from the old BasicEffect instances).

If you are writing your own ModelProcessor where you set a custom effect upon build, then I'd recommend looking at the skinned model example as that demonstrates replacing effects in a content processor: http://xbox.create.msdn.com/en-US/education/catalog/sample/skinned_model

There is no need for you to do this manually, so get studying and good luck :)

Aimee

We are now on Tumblr, so please come and check out our site!

http://xpod-games.com

Thank you AmzBee for your detailed reply :)

This topic is closed to new replies.

Advertisement