• Advertisement
Sign in to follow this  

Set titled texture to a loaded model (XNA)

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

If you intended to correct an error in the post then please contact us.

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];
     model.CopyAbsoluteBoneTransformsTo(transforms);

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

               effect.EnableDefaultLighting();
               effect.PreferPerPixelLighting = true;
               effect.TextureEnabled = true;
               effect.Texture = tex;

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

     mesh.Draw();
     }
}




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
Advertisement
Sign in to follow this  

  • Advertisement