• Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at \$59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.

Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!

#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).

private void LoadModel(string assetName, out Model model)
{
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.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).

private void LoadModel(string assetName, out Model model)
{
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.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