Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualgchewood

Posted 04 March 2013 - 03:45 PM

I have a model with multiple materials/textures in .X format. If I load it and draw with BasicEffect, it renders just fine.

However, I need do it with a custom effect and so far my efforts are in vain. The model is being rendered with just one of the textures being used for all parts (where it shouldn't be).

So here's my loading of the model:

 

private void LoadModel(string assetName, out Model model)
        {
            model = content.Load<Model>(assetName);
            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (ModelMeshPart part in mesh.MeshParts)
                {
                    BasicEffect basicEffect = part.Effect as BasicEffect;
                    if (basicEffect != null)
                        modelTextures[mesh.GetHashCode()] = basicEffect.Texture;
                    
                    part.Effect = myEffect;
                }
            }
        }

modelTextures being an array of Texture2Ds.

 

And then here's my drawing the model:

 

public void DrawModel()
        {
            foreach (ModelMesh m in model.Meshes)
            {
                foreach (Effect e in m.Effects)
                {
                        e.CurrentTechnique = e.Techniques["Shadow"];
                        e.Parameters["world"].SetValue(Matrix.CreateTranslation(0, 100, 0));
                        e.Parameters["view"].SetValue(view);
                        e.Parameters["projection"].SetValue(projection);
                        e.Parameters["colorMap"].SetValue(modelTextures[m.GetHashCode()]);
                }
                m.Draw();
            }
        }

This actually works fine for a different model I've got (that someone else made). But not my model!

But since my model renders just fine with the basiceffect, I don't know where the problem is I should be trying to fix?

Worst case scenario, I can break my model up into separate models, each with a single texture. But I prefer a real solution,

any help would be very much appreciated!

 

Thanks


#1gchewood

Posted 04 March 2013 - 03:44 PM

I have a model with multiple materials/textures in .X format. If I load it and draw with BasicEffect, it renders just fine.

However, I need do it with a custom effect and so far my efforts are in vain. The model is being rendered with just one of the textures being used for all parts (where it shouldn't be).

So here's my loading of the model:

 

private void LoadModel(string assetName, out Model model)
        {
            model = content.Load<Model>(assetName);
            foreach (ModelMesh mesh in model.Meshes)
            {
                foreach (ModelMeshPart part in mesh.MeshParts)
                {
                    BasicEffect basicEffect = part.Effect as BasicEffect;
                    if (basicEffect != null)
                        modelTextures[mesh.GetHashCode()] = basicEffect.Texture;
                    
                    part.Effect = myEffect;
                }
            }
        }

modelTextures being an array of Texture2Ds.

 

And then here's my drawing the model:

 

public void DrawModelS(Matrix view, Matrix projection, Vector3 playerPos)
        {
            foreach (ModelMesh m in model.Meshes)
            {
                foreach (Effect e in m.Effects)
                {
                        e.CurrentTechnique = e.Techniques["Shadow"];
                        e.Parameters["world"].SetValue(Matrix.CreateTranslation(0, 100, 0));
                        e.Parameters["view"].SetValue(view);
                        e.Parameters["projection"].SetValue(projection);
                        e.Parameters["colorMap"].SetValue(modelTextures[m.GetHashCode()]);
                }
                m.Draw();
            }
        }

This actually works fine for a different model I've got (that someone else made). But not my model!

But since my model renders just fine with the basiceffect, I don't know where the problem is I should be trying to fix?

Worst case scenario, I can break my model up into separate models, each with a single texture. But I prefer a real solution,

any help would be very much appreciated!

 

Thanks


PARTNERS