[osg-users] Get all vertices of an OSG Group
Robert Osfield
robert.osfield at gmail.com
Sat Mar 26 03:27:12 PDT 2016
Hi Clement+Tony,
On 26 March 2016 at 02:16, Tony Vasile <minghia at gmail.com> wrote:
> Hi Clement,
> This is rather easy to do. All you need is to define a NodeVisitor and
> run it on the group. Using this way you only need to have an accept call
> for the Geode and process the drawables under the Geode.
>
> Code:
>
> class InfoVisitor : public osg::NodeVisitor
> {
> public:
> InfoVisitor()
> {
> setTraversalMode( osg::NodeVisitor::TRAVERSE_ALL_CHILDREN );
> }
>
> void apply( osg::Geode& geode )
> {
> for ( unsigned int i=0; i<geode.getNumDrawables(); ++i )
> {
> // Do what you have to do, for example store in a data structure
> }
> }
> };
>
In OSG-3.4 onwards osg::Drawable subclasses from osg::Node (this also means
osg::Geometry is a Node as it subclasses from Drawable) so can now be used
directly in NodeVisitor so you can implement:
class InfoVisitor : public osg::NodeVisitor
{
public:
InfoVisitor() :
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN ) {}
void apply( osg::Geometry& geometry )
{
// Do what you have to do, for example store in a data structure
}
};
As Drawable/Geometry is a Node you don't actually required osg::Geode so
the above revision will handle new and old style subgraphs.
Robert.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20160326/4fca6724/attachment-0002.htm>
More information about the osg-users
mailing list