[SOLVED] ClipPlaneAttribute

hello,

I am trying to set a ClipPlaneAttribute for an additional camera I have implemented.

The Panda Manual isn’t very helpful about this issue.

Does anyone know a bit more about them ?

I am trying to Clip any geometry that lies on the “negative” side of the plane.

I setup the plane like this

	
        myPlaneNode = new PlaneNode("myPlane");
        myPlane = LPlanef(LVector3f(0,0,1), LVector3f(0,0,0));

	myPlaneNode->set_plane(myPlane);
 	myPlaneNP = NodePath(myPlaneNode);

and I try to set the render state of my camera like this

	CPT(RenderState) pRenderState = RenderState::make_empty();
	pRenderState->set_attrib(CullFaceAttrib::make(CullFaceAttrib::M_cull_clockwise));
	CPT(RenderAttrib) attr = ClipPlaneAttrib::make();
	const ClipPlaneAttrib* pClipPlaneAttr = DCAST(ClipPlaneAttrib, attr);
	attr = pClipPlaneAttr->add_on_plane(myPlaneNP);
	pRenderState->set_attrib(attr);
	pReflectionCam->set_initial_state(pRenderState);

anyone care to share their experience with clip planes ? :slight_smile:

Digging through the forums I found a solution to this… not quite sure why my code above doesn’t work though - some explanation by a dev would be really appreciated here.

but if I do this - the clip plane attribute suddently works perfect.

	NodePath someNode = NodePath("SomeNode");
	CPT(RenderAttrib) pCullFaceAttrib = CullFaceAttrib::make(CullFaceAttrib::M_cull_clockwise);
	someNode.set_attrib(pCullFaceAttrib);
	someNode.set_clip_plane(gWaterPlaneNP);

	pReflectionCam->set_initial_state(someNode.get_state());

any explanation ? :question:

You don’t say what issue you’re having, but I don’t see anything wrong with your code. You probably do want to attach your clip plane into the scene graph somewhere, though. The transforms on the clip plane itself affect where the clip happens on any geometry.

Probably the easiest way to experiment with clip planes (as with any other attribute) is to apply the attribute to render first, so you can see it get clipped in your main camera before you start playing around with secondary cameras and the funky “initial_state” nonsense. When you are confident your clip plane is doing what you expect it to, then you can move its attrib to the secondary camera.

I think you’re also building up your initial_state the hard way, by the way. I’d do it like this, taking advantage of the convenience functions on NodePath:

NodePath temp_np("temp");
temp_np.set_two_sided(false);
temp_np.set_clip_plane(myPlaneNP);
pReflectionCam->set_initial_state(temp_np.get_state());

David

Ah, I just saw your second post. Indeed, you were getting confused by the interface of RenderState::set_attrib(). It doesn’t modify the RenderState in-place; instead, it returns a new RenderState that has the attrib added, so you have to replace this:

pRenderState->set_attrib(attr);

with this:

pRenderState = pRenderState->set_attrib(attr);

in both places where you call set_attrib().

But, this is why we have convenience functions on NodePath: so you don’t have to use this clumsy interface.

David

thanks drwr!

updated my code and it works fine!

	CPT(RenderState) pRenderState = RenderState::make_empty();
	pRenderState = pRenderState->set_attrib(CullFaceAttrib::make(CullFaceAttrib::M_cull_clockwise));
	CPT(RenderAttrib) attr = ClipPlaneAttrib::make();
	const ClipPlaneAttrib* pClipPlaneAttr = DCAST(ClipPlaneAttrib, attr);
	attr = pClipPlaneAttr->add_on_plane(clipPlaneNP);
	pRenderState = pRenderState->set_attrib(attr);
	pReflectionCam->set_initial_state(pRenderState);

the nodepath acessors are indeed quite handy though.

to not change the attributes in place is quite counter intuitive though. Ah well another soul who runs into same problems will hopefully find this thread :slight_smile: