Clipping a 3D model ( maybe using a clipplane?)

Anything and everything that's related to OGRE or the wider graphics field that doesn't fit into the other forums.
Post Reply
McSwan
Greenskin
Posts: 122
Joined: Tue May 11, 2004 5:40 am
x 1

Clipping a 3D model ( maybe using a clipplane?)

Post by McSwan »

Hi,

Just says I have a 3d mesh, and I want to create a clipplane to cut, so the top doesn't render (ie anything above the plane doesn't render) and people can see inside of the model.
ie bad ascii drawn model
*
***
******


_________ <- clipping plane makes the top of the model not render, so you can see inside it.
***
******

It is ok to have the clipplane clip all models, although might be nice to be able to clip against just 1 model if it's possible and not too hard.

Any suggestion from the experts on the best way of doing it ? Maybe adding an additional Clip plane to the camera would be the go ?
User avatar
nullsquared
Old One
Posts: 3245
Joined: Tue Apr 24, 2007 8:23 pm
Location: NY, NY, USA
x 9

Re: Clipping a 3D model ( maybe using a clipplane?)

Post by nullsquared »

You might use a user-clippane (check RenderSystem), but it's best to just use a shader that manually clips the object.

Basically, just pass the plane to the shader (using a custom renderable parameter, for example), and check the dot product of the plane's normal with the direction of the current fragment from the plane's origin. If it's negative, disard; the texel. Or just use clip(-1); or more simply, clip(dot(planeNormal, directionFromPlaneOriginToFragment));
User avatar
nikki
Old One
Posts: 2730
Joined: Sat Sep 17, 2005 10:08 am
Location: San Francisco
x 13
Contact:

Re: Clipping a 3D model ( maybe using a clipplane?)

Post by nikki »

If the plane is always local-Y-axis aligned, you could do a simple Y-greater check in the shader with the interpolated position.
psquare
Hobgoblin
Posts: 554
Joined: Tue Nov 14, 2006 3:26 pm
x 6

Re: Clipping a 3D model ( maybe using a clipplane?)

Post by psquare »

I concur with nullsquared.

Using a shader is the easiest and most flexible approach. In fact, you can clip with any geometry that can be represented by a simple equation (e.g Sphere)
McSwan
Greenskin
Posts: 122
Joined: Tue May 11, 2004 5:40 am
x 1

Re: Clipping a 3D model ( maybe using a clipplane?)

Post by McSwan »

OK,

I got confirmation that all I need to do is create a clip plane that is horizontal and moves up and down, and affects all objects. It's just for clipping building so you can see inside them.

My knowledge on shaders is really bad atm. I'm slowly reading up. I'd need to use a ?global clipping shader? to do what you suggest ? Obviously I can't apply the same shader clipping material to all objects in my scene, which is my current level of understanding shaders.

I thought all was good when I found Rendersystem::addclipPlane. According to Sinbad, I can't use it? Is this still the case or is there something similar I can use?

http://www.ogre3d.org/forums/viewtopic.php?f=2&t=38943
McSwan
Greenskin
Posts: 122
Joined: Tue May 11, 2004 5:40 am
x 1

Re: Clipping a 3D model ( maybe using a clipplane?)

Post by McSwan »

Thought I'd have a crack at using rendersystem::addplane anyway, but as far as I can tell it doesn't work.

Made a floor plane and clip underneath, but doesn't clip.

Code: Select all

    Entity *ent;
    // Define a floor plane mesh
    Plane p;
    p.normal = Vector3::UNIT_Y;
    p.d = 200;
    Root::getSingleton().getRenderSystem()->addClipPlane(p);
    MeshManager::getSingleton().createPlane("FloorPlane",
        ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, 
        p,2000,2000,1,1,true,1,5,5,Vector3::UNIT_Z);
         // Create an entity (the floor)
    ent = mSceneMgr->createEntity("floor", "FloorPlane");
    //ent->setMaterialName("Examples/RustySteel");

    mSceneMgr->getRootSceneNode()->attachObject(ent);

    // add clip plane
    Plane clipPlane;
    clipPlane.normal = Vector3::UNIT_Y;
    clipPlane.d = 201;
    Root::getSingleton().getRenderSystem()->addClipPlane(clipPlane);
User avatar
madmarx
OGRE Expert User
OGRE Expert User
Posts: 1671
Joined: Mon Jan 21, 2008 10:26 pm
x 49

Re: Clipping a 3D model ( maybe using a clipplane?)

Post by madmarx »

Beware user ClipPlanes from rendersystem, they are used to clip lights & other things internally in ogre.
It is possible, but maybe not ultra easy. If you don't use shader, maybe you can have a try with clipplanes by using listeners and changing things in the renderqueue (I have never tried, so it is maybe a stupid idea). I think to make a direct call either to render system, either to opengl (in my case I am better at opengl..).


Something like :

1/ put a plane with material (colour_write off, depth_write on) in render queue main -1
2/ lets you culled object after...

should visually work if you are able to manage correctly the traditionnal render queue.
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
Post Reply