In addition to Robert's comments, I'll add the following:

If you intend to turn the clip plane on and off, make sure to set your
StateSet data variance to DYNAMIC.

Also, I recently wrote code to dynamically update a ClipPlane based on the
view vector to create a cross section that always shows the back half.
Again, set the DataVariance on the ClipPlane to DYNAMIC for this type of
algorithm. (This is part of a larger app that I intend to demo at the OSG
BOF at SIGGRAPH this year.)

Paul Martz
Skew Matrix Software LLC
http://www.skew-matrix.com
+1 303 859 9466

-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Robert
Osfield
Sent: Monday, May 11, 2009 1:18 PM
To: OpenSceneGraph Users
Subject: Re: [osg-users] dynamic clipping node

Hi Lee,

Clip planes are position state, so have to be positioned in space by the
osg::ClipNode, but the actually enabling of clip planes is decoupled from
this and control through osg::StateSet::setMode(GL_CLIP_PLANE0+i,
osg::StateAttribute::ON).
You typically wouldn't decorate your scene with the ClipNode, rather you
would usually place the ClipNode in your scene and positioned appropriately,
then enable the individual clip planes for the subgraphs you want them to be
on by just setting the modes (as above) via a StateSet that is attached to
root of subgraph that you want to enable it for.

Robert.

On Mon, May 11, 2009 at 8:02 PM, Butler, Lee Mr CIV USA USAMC
<[email protected]> wrote:
> I want to turn a cutting plane on and off at various levels in the 
> graph and update it under user control.  The osgclip example was 
> enough to show me how to add the clipping plane.  Getting it turned on 
> and off is something that somehow eludes me.  I'm having trouble 
> understanding the "OSG way" of doing this.
>
> Code looks like this:
>
>   // load geometry, etc ...
>   // add clip node
>   decorate_with_clip_node(scene);
>
>   // set attributes on stateset ...
>
>   MyVisitor myVisitor(stateset);
>
>   while (!viewer.done()) {
>         viewer.advance();
>         viewer.eventTraversal();
>         viewer.updateTraversal();
>         viewer.renderingTraversals();
>   }
>
> When the user presses a key to toggle the clipping plane I do:
>
>   clipped_subgraph->accept(myVisitor);
>
> which in turn does:
>
>     if (node.getStateSet()) {
>         node.setStateSet(NULL);
>     } else {
>         node.setStateSet( _stateset );
>     }
>
>
> The first time the NodeVisitor runs it claims to turn off the StateSet 
> on the graphNode.  Yet the clipping still occurs.  On the second pass 
> through, the stateset pointer is no longer valid, as if it had been 
> freed.  I've checked the reference count on the stateset after the 
> call to node.setStateSet(NULL) and the it is still 2, so I wouldn't have
anticipated it getting destroyed.
>
> Clearly I'm lost in newbie-land.  I've tried searching the archives, 
> but I haven't found the right posting and the website doesn't seem to 
> be very stable this month.
>
> Help?
>
> Lee
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.
> org
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to