Quantum Vector

I am building a game with 3d models and am having slight texturing problems. My biggest problem is that i don't know how .x files refer to textures.

From a small look at an ascii .x file, it would seem that it holds several filenames, however i am not sure how i would access these at runtime. I think i need to extract the filename from the mesh part and pass it to the effects for that mesh part.

p.s. although this may be more suitable to the direct x 9 forums, i would appreciate XNA related code - thanks




Re: XNA Framework Textures in .x files

areia

Hi,

When you are using the content proccessor in XNA, the textures are also compiled and imported automaticly. I am sure you have found the TextureFilename="....." tag in the .x file. So when you drag a .x file in the importer, the importer will also seek for the texture and will compile it too.
Now in runtime, the .x file is loaded as a Model. A model has meshes and each Mesh is loaded with its effect (or shader), which is the BasicEffect except a different effect is specified within the .x file. Looking at the BasicEffect, there is a Texture property which holds the texture data as Texture2D.
So to reference a texture inside a model it's (Model.Meshes[k].Effects[j] as BasicEffect).Texture, where Model is your model's variable and k and j are the counters to reference to the correct mesh and effect in your model.
It may sound a bit complicated but it's just an automation XNA offers so you don't have to load, render and handle everything manually.





Re: XNA Framework Textures in .x files

Quantum Vector

I have implemented this in a mesh viewing program and it works perfectly.

This basiceffect even solved another problem - i had initially wanted to just use coloured vertices - now all the information in handles automaticly so i don't have to use textures if i don't need them.

Thanks areia