I assume it will probably be a ModelMeshPart, for model mesh parts you can apply your own shaders, it might be best to loop over the model and its mesh parts setting the desired effect on it in a preprocessing step.
The basic idea would be:
foreach (ModelMesh mesh in Model.Meshes) { for (int i = 0; i < Mesh.MeshParts.Count; i++) { mesh.MeshParts.Effect = ContentManager.Load<Effect>(@"Path\To\Effect"); } }
hope that helps
Lostlogic wrote:
//This is where the mesh orientation is set, as well as our camera and projection
foreach (BasicEffect effect in mesh.Effects)
{
I think I understand the issue... Simply change it from foreach( BasicEffect effect... ) to foreach( Effect effect ... ). If you know all effects are of the same type (like MyCustomEffect, if you wrote your own wrapper), then you can use that type instead. For my test projects, where I may have a mix of effect types on each model, I often use something like this:
foreach( Effect effect in mesh.Effects )
{
if( effect is BasicEffect )
{
...basic effect stuff...
}
else if( effect is MyCustomEffect )
{
....my custom stuff...
}
}
Hope that helps!
No you have to change all of that code because the parameters inside the loop only pertain to BasicEffect. When you are using an Effect, you assign an effect to each mesh part as previously described, then you must set the Effect.CurrentTechnique property to the technique within the effect that you want to use, and you have to set all of the global variables of each effect to appropriate values from within your code. For example:
MyModel.Meshes[0].MeshParts[0].Effect.Parameters["WorldViewProj"].SetValue(WorldViewProjection);
The above line of code would set the HLSL global variable called WorldViewProj to the value of the variable WorldViewProjection within your XNA game. After setting all of the appropriate effect variables, you would simply call MyModel.Meshes[0].Draw() iterating through each mesh in the Meshes collection and it will draw all the ModelMeshPart objects on each mesh using their associated effect settings. If the active effect technique contains multiple passes, my understanding is that the Draw() call will iterate through them automatically.