Pocketmnky

Is there a way that I can change the visibility of a particular modelmesh or modelmeshpart at runtime My art assets have collision walls in them added by the artist. I can remove them during the build processors, but I'd like to leave them in so I could optionally draw them for debugging.

Is there any way that I can do this




Re: XNA Framework How do I make a certain ModelMesh invisible at runtime?

Jon Watte

Yes; you can loop over all the pieces of the model, and draw then individually, instead of drawing the entire model with a single call to Draw(). You will have to bind the appropriate effects to do this, though, but that's pretty simple.

You can even take it one step further, and draw only specific subsets of each each mesh. How you figure out what pieces to draw, and what pieces not to, is up to you, but it sounds like you have a handle on that.





Re: XNA Framework How do I make a certain ModelMesh invisible at runtime?

R. Egas

Hi,

That's easy.. During processing (in your custom model processor) just set all mesh' tags to an instance of some custom meta class of your own design, i.e.:

bool struct MeshData

{

public MeshData( bool visible )

{

Visible = visible;

}

public bool Visible

}

....

ModelMesh mesh = ...

mesh.Tag = new MeshData( the_mesh_is_visible );

During rendering you just do something like this:

MeshData meshData = ( MeshData )mesh.Tag;

if( meshData.Visible )

{

Render();

}

else

{

DontRender(); // :)

}

Hope that helps!

Cheers,

Ralph