Jump to content

  • Log In with Google      Sign In   
  • Create Account

#Actualphil_t

Posted 04 March 2013 - 08:23 PM

Yeah, I see what you mean. Of course, ModelMesh handles this ok with the default BasicEffect, so it can be done.

You have three options:

1) Clone your effect before assigning it to ModelMeshPart.Effect. That creates a unique instance of your effect (which is what I expect each ModelMeshPart has by default... a unique instance of BasicEffect). Assign each effect its appropriate texture. And then you only need to update the parameters that change each frame in your DrawModel method (e.g. view, world, etc...). This is probably the easiest solution; but Clone'ing an effect creates a new GPU resource, so you should remember to call Dispose() on it when you're completely finished with it - you have to manage its lifetime manually since it wasn't loaded through the ContentManager.

2) Avoid using ModelMesh.Draw (which submits a draw call for each ModelMeshPart). Instead loop through all the ModelMeshParts and use DrawIndexedPrimitives after setting the corresponding Effect parameters and Apply()'ing the changes. This way you can still keep a single Effect instance. ModelMeshPart and its ModelMesh parent should have all the necessary information needed for the parameters to DrawIndexedPrimitives, but if you're not familiar with DrawIndexedPrimitives it might take a while to figure it all out. (DrawIndexedPrimitives is essentially what ModelMesh.Draw uses internally).

3) Change your model so it has two ModelMeshes instead of one ModelMesh and two ModelMeshParts :-).

#3phil_t

Posted 04 March 2013 - 08:22 PM

Yeah, I see what you mean. Of course, ModelMesh handles this ok with the default BasicEffect, so it can be done.

You have three options:

1) Clone your effect before assigning it to ModelMeshPart.Effect. That creates a unique instance of your effect (which is what I expect each ModelMeshPart has by default... a unique instance of BasicEffect). And then you only need to update the parameters that change each frame in your DrawModel method (e.g. view, world, etc...). This is probably the easiest solution; but Clone'ing an effect creates a new GPU resource, so you should remember to call Dispose() on it when you're completely finished with it - you have to manage its lifetime manually since it wasn't loaded through the ContentManager.

2) Avoid using ModelMesh.Draw (which submits a draw call for each ModelMeshPart). Instead loop through all the ModelMeshParts and use DrawIndexedPrimitives after setting the corresponding Effect parameters and Apply()'ing the changes. This way you can still keep a single Effect instance. ModelMeshPart and its ModelMesh parent should have all the necessary information needed for the parameters to DrawIndexedPrimitives, but if you're not familiar with DrawIndexedPrimitives it might take a while to figure it all out. (DrawIndexedPrimitives is essentially what ModelMesh.Draw uses internally).

3) Change your model so it has two ModelMeshes instead of one ModelMesh and two ModelMeshParts :-).

#2phil_t

Posted 04 March 2013 - 08:21 PM

Yeah, I see what you mean. Of course, ModelMesh handles this ok with the default BasicEffect, so it can be done.

You have three options:

1) Clone your effect before assigning it to ModelMeshPart.Effect. That creates a unique instance of your effect (which is what I expect each ModelMeshPart has by default... a unique instance of BasicEffect). And then you only need to update the parameters that change each frame in your DrawModel method (e.g. view, world, etc...). This is probably the easiest solution; but Clone'ing an effect creates a new GPU resource, so you should remember to call Dispose() on it when you're completely finished with it - you have to manage its lifetime manually since it wasn't loaded through the ContentManager.

2) Avoid using ModelMesh.Draw (which submits a draw call for each ModelMeshPart). Instead loop through all the ModelMeshParts and use DrawIndexedPrimitives after setting the corresponding Effect parameters and Apply()'ing the changes. This way you can still keep a single Effect instance. ModelMeshPart and its ModelMesh parent should have all the necessary information needed for the parameters to DrawIndexedPrimitives, but if you're not familiar with DrawIndexedPrimitives it might take a while to figure it all out.

3) Change your model so it has two ModelMeshes instead of one ModelMesh and two ModelMeshParts :-).

#1phil_t

Posted 04 March 2013 - 08:18 PM

Yeah, I see what you mean. Of course, ModelMesh handles this ok with the default BasicEffect, so it can be done.

You have three options:

1) Clone your effect before assigning it to ModelMeshPart.Effect. That creates a unique instance of your effect (which is what I expect each ModelMeshPart has by default... a unique instance of BasicEffect). And then you only need to update the parameters that change each frame in your DrawModel method (e.g. view, world, etc...). This is probably the easiest solution; but Clone'ing an effect creates a new GPU resource, so you should remember to call Dispose() on it when you're completely finished with it - you have to manage its lifetime manually since it wasn't loaded through the ContentManager.

2) Avoid using ModelMesh.Draw (which submits a draw call for each ModelMeshPart). Instead loop through all the ModelMeshParts and use DrawIndexedPrimitives after setting the corresponding Effect parameters and Apply()'ing the changes. ModelMeshPart and its ModelMesh parent should have all the necessary information needed for the parameters to DrawIndexedPrimitives, but if you're not familiar with DrawIndexedPrimitives it might take a while to figure it all out.

3) Change your model so it has two ModelMeshes instead of one ModelMesh and two ModelMeshParts :-).

PARTNERS