From cb2b0a5fe84bf862613b46432226a0201005fced Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 5 Oct 2017 12:45:47 +0100 Subject: [PATCH] Steamlined the handling of osg::Geometry --- src/osgPlugins/obj/OBJWriterNodeVisitor.cpp | 24 ++++++++++----------- src/osgPlugins/obj/OBJWriterNodeVisitor.h | 15 ++++++------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/osgPlugins/obj/OBJWriterNodeVisitor.cpp b/src/osgPlugins/obj/OBJWriterNodeVisitor.cpp index 0bc397b6c..ae8ef986f 100644 --- a/src/osgPlugins/obj/OBJWriterNodeVisitor.cpp +++ b/src/osgPlugins/obj/OBJWriterNodeVisitor.cpp @@ -545,27 +545,27 @@ void OBJWriterNodeVisitor::processGeometry(osg::Geometry* geo, osg::Matrix& m) { } +void OBJWriterNodeVisitor::apply(osg::Geometry& geometry) +{ + osg::Matrix m = osg::computeLocalToWorld(getNodePath()); + + pushStateSet(geometry.getStateSet()); + + processGeometry(&geometry,m); + + popStateSet(geometry.getStateSet()); +} + void OBJWriterNodeVisitor::apply( osg::Geode &node ) { - pushStateSet(node.getStateSet()); _nameStack.push_back(node.getName()); - osg::Matrix m = osg::computeLocalToWorld(getNodePath()); unsigned int count = node.getNumDrawables(); for ( unsigned int i = 0; i < count; i++ ) { - osg::Geometry *g = node.getDrawable( i )->asGeometry(); - if ( g != NULL ) - { - pushStateSet(g->getStateSet()); - - processGeometry(g,m); - - popStateSet(g->getStateSet()); - } + node.getDrawable( i )->accept(*this); } - popStateSet(node.getStateSet()); _nameStack.pop_back(); } diff --git a/src/osgPlugins/obj/OBJWriterNodeVisitor.h b/src/osgPlugins/obj/OBJWriterNodeVisitor.h index eb62b078f..8ef33e614 100644 --- a/src/osgPlugins/obj/OBJWriterNodeVisitor.h +++ b/src/osgPlugins/obj/OBJWriterNodeVisitor.h @@ -65,23 +65,20 @@ class OBJWriterNodeVisitor: public osg::NodeVisitor { } } - virtual void apply(osg::Geode &node); + virtual void apply(osg::Geometry & geometry); + virtual void apply(osg::Geode & node); - virtual void apply(osg::Group &node) + virtual void apply(osg::Group & node) { + pushStateSet(node.getStateSet()); + _nameStack.push_back( node.getName().empty() ? node.className() : node.getName() ); _fout << std::endl; _fout << "g " << getUniqueName() << std::endl; osg::NodeVisitor::traverse( node ); + _nameStack.pop_back(); - } - - void traverse (osg::Node &node) - { - pushStateSet(node.getStateSet()); - - osg::NodeVisitor::traverse( node ); popStateSet(node.getStateSet()); }