OK, from your explanation I attempted a simple "flip the cut plane on and off" 
example.  The graph looks roughly like:

rootnode -+- TransformNode -+- ClipNode
                +- GroupNode -+- Geode1
                                        +- Geode2
and I get:

    ClipNode {
      name "Clip Node"
      nodeMask 0xffffffff
      cullingActive FALSE
      StateSet {
        UniqueID StateSet_0
        rendering_hint DEFAULT_BIN
        renderBinMode INHERIT
        GL_CLIP_PLANE0 ON
      }
      referenceFrame RELATIVE
      ClipPlane {
        clipPlaneNum 0
        plane -1 0 0 0.5
      }
    }

Now the simulation loop code looks like:

    unsigned frame = 0;

#define LIM 10000
    while (!viewer.done()) {
        viewer.advance();
        viewer.eventTraversal();
        viewer.updateTraversal();

        if (frame == 0) {
            fprintf(stderr, "frame %u\n", frame);
            stateset->setMode(GL_CLIP_PLANE0,osg::StateAttribute::OFF);
        } else if (frame == (LIM/2)) {
            fprintf(stderr, "frame %u\n", frame);
            stateset->setMode(GL_CLIP_PLANE0+0,osg::StateAttribute::ON);
        }

        viewer.renderingTraversals();
        frame = (frame+1) % LIM;
    }

This I hoped would "flip" the cutting plane on and off, but the cutting plane 
was always on, despite the logging reporting that setMode was being called.

Lee

----- Original Message -----
From: Robert Osfield <[email protected]>
Date: Monday, May 11, 2009 15:18
Subject: Re: [osg-users] dynamic clipping node
To: OpenSceneGraph Users <[email protected]>


> 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
> < 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