Sign in to follow this  

Set titled texture to a loaded model (XNA)

Recommended Posts

Hi. I've got an issue where I want to set custom textures to a loaded model in XNA. I've got the following code which sets the texture to the model, but it gets stretched for the whole model:
public virtual void Draw(Model model, Texture2D tex)
     Matrix[] transforms = new Matrix[model.Bones.Count];

     foreach (ModelMesh mesh in model.Meshes)
          foreach (BasicEffect effect in mesh.Effects)
               effect.Projection = m_projectionMatrix;
               effect.View = m_viewMatrix;

               effect.PreferPerPixelLighting = true;
               effect.TextureEnabled = true;
               effect.Texture = tex;

               effect.World = transforms[mesh.ParentBone.Index] *
               Matrix.CreateFromQuaternion(Quaternion.Identity) *
               elements[0].attributes.attributes[(int)Attrib.depth]) *
               Matrix.CreateTranslation(new Vector3(0.0f, 0.0f, 0.0f));


I'm searching for a way to apply a repeating texture on the model, instead of stretched one, and was hoping there would be someone that could help me? In detail, I have a cube that is being stretched for the walls in my game. And so I want the walls to be able to have custom textures without having to create new cubes for each type of wall. This is working just fine at the moment, but the problem is that I would like to have a titled texture on the walls instead of a stretched one. So, is it possible to apply such a texture on a loaded model? [Edited by - Swiff on February 15, 2010 2:28:52 PM]

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