Sign in to follow this  
Neith

Cut 3d model in half

Recommended Posts

Neith    144

I'm wondering if there's a way to take a loaded model in XNA and slice it, similar to this but in 3D.  Is there a way to manipulate vertices on the fly and actually seperate a model dynamically?

Share this post


Link to post
Share on other sites
Yourself    1961

If you only want to cut the model when rendering, you could use clip planes (or emulate it in the shader using a dot product).

You could also use the stencil buffer if you want to cut out more advanced shapes.

 

If you want to cut your model on CPU side (so you end up with 2 models, not 1 model that is only partially drawn), take a look at Sutherland-Hodgman clipping

Share this post


Link to post
Share on other sites
Neith    144

Yeah, I'd want to end up with 2 models.  The basic idea is to be able to saw a wooden beam, and have two beams depending on the cut.

Share this post


Link to post
Share on other sites
Promit    13246

In the case of a wooden beam, it may be relatively straightforward because you already know the cross sectional shape. In the general case, it's doable on well formed meshes but kind of a pain. Essentially you'll have to calculate where the vertices should be and create a new mesh. Shouldn't make much of a difference that it's in XNA.

Share this post


Link to post
Share on other sites
Jason Z    6434

I haven't ever tried it, so I'm not positive about this (end caveat...).  I think clip planes are implemented in the rasterizer stage, which means you can't stream the resulting geometry out through the stream output channel.  However, in your geometry shader you can replicate what the clip planes are doing.  They are more or less just measuring the distance from each vertex to a plane, then keeping the geometry that is on one side of the plane.

 

The trick would be to handle the cases where a triangle intersects the clip plane.  It would more or less require you to create a mini-triangle clipper in your geometry shader, which should be possible to do.  It won't be the most efficient thing ever, but it would get you what you are looking for.  And once you put it into the GS, then you can stream the results out to your CPU buffers and store them to disk for use later on.

Share this post


Link to post
Share on other sites
ongamex92    3255

if you need your model cutted in half for non real time purpouses you can use discard pixel for those pixel that are at the wrong side of the plane http://msdn.microsoft.com/en-us/library/windows/desktop/bb943995(v=vs.85).aspx (for example, you can use the transformed world posotion in the pixel shader for the plane equation)
 

Actually that is not that slow but it really depends on the final object size in pixel and the pixel shader complexity , ect

Edited by imoogiBG

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this