Getting Textures from a Mesh

Started by
-1 comments, last by ddamicoAVI 16 years, 2 months ago
I'm using XNA to create some basic simulation. I created a model using 3D World Studio. Which I then exported to a .X file. I am using an effect file i created to light the scene. One of the parameters of the effect file is the texture that needs to be drawn. What is the best way to get the textures associated with a mesh during my drawn method? Here is the loop of my draw method:

foreach (ModelMesh mesh in buildingModel.Meshes)
            {
                roomLighting.Parameters["World"].SetValue(transforms[mesh.ParentBone.Index] * Matrix.Identity);
                roomLighting.Parameters["modelTexture"].SetValue(currentTexture);  // <---- how do i get currentTexture

                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {

                    graphics.GraphicsDevice.Vertices[0].SetSource(mesh.VertexBuffer, meshPart.StreamOffset, meshPart.VertexStride);
                    graphics.GraphicsDevice.VertexDeclaration = meshPart.VertexDeclaration;
                    graphics.GraphicsDevice.Indices = mesh.IndexBuffer;

                    roomLighting.Begin(SaveStateMode.None);
                    foreach (EffectPass pass in roomLighting.CurrentTechnique.Passes)
                    {
                        pass.Begin();
                        graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 
                             meshPart.BaseVertex, 0, meshPart.NumVertices, meshPart.StartIndex, meshPart.PrimitiveCount);
                        pass.End();
                    }
                    roomLighting.End();
                }
            }



This topic is closed to new replies.

Advertisement