From 412717c151b9d080e94cde11a9b846acee5ed1b0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Sat, 10 May 2008 17:25:42 +0000 Subject: [PATCH] From Paul Martz, "This change adds support for osg::Billboards to the OpenFlight exporter. It might seem odd that the change actually removes the stub apply(Billboard&) method, but it turns out Billboards are easily supported in subordinate routines of the existing apply(Geode&) method with s dynamic_cast, so there's no need for a separate apply(Billboard&)." --- .../OpenFlight/FltExportVisitor.cpp | 20 +++---------- src/osgPlugins/OpenFlight/FltExportVisitor.h | 1 - .../OpenFlight/expGeometryRecords.cpp | 29 +++++++++++++++---- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/src/osgPlugins/OpenFlight/FltExportVisitor.cpp b/src/osgPlugins/OpenFlight/FltExportVisitor.cpp index c449b468f..8ea917157 100644 --- a/src/osgPlugins/OpenFlight/FltExportVisitor.cpp +++ b/src/osgPlugins/OpenFlight/FltExportVisitor.cpp @@ -28,7 +28,6 @@ #include #include -#include #include #include #include @@ -336,6 +335,10 @@ FltExportVisitor::apply( osg::LightSource& node ) writePushTraverseWritePop( node ); } +// Billboards also go through this code. The Geode is passed +// to writeFace and writeMesh. If those methods successfully cast +// the Geode to a Billboard, then they set the template mode +// bit accordingly. void FltExportVisitor::apply( osg::Geode& node ) { @@ -436,21 +439,6 @@ FltExportVisitor::apply( osg::Geode& node ) // traverse( (osg::Node&)node ); } -void -FltExportVisitor::apply( osg::Billboard& node ) -{ - _firstNode = false; - ScopedStatePushPop guard( this, node.getStateSet() ); - - // TBD -- Not yet implemented, but HIGH priority. - // Face record -- HIGH - // Mesh record -- HIGH - - writeMatrix( node.getUserData() ); - writeComment( node ); - writePushTraverseWritePop( node ); -} - void FltExportVisitor::apply( osg::Node& node ) { diff --git a/src/osgPlugins/OpenFlight/FltExportVisitor.h b/src/osgPlugins/OpenFlight/FltExportVisitor.h index 747429ba5..e41d6aac9 100644 --- a/src/osgPlugins/OpenFlight/FltExportVisitor.h +++ b/src/osgPlugins/OpenFlight/FltExportVisitor.h @@ -77,7 +77,6 @@ public: virtual void apply( osg::Transform& node ); virtual void apply( osg::LightSource& node ); virtual void apply( osg::Geode& node ); - virtual void apply( osg::Billboard& node ); virtual void apply( osg::Node& node ); virtual void apply( osg::ProxyNode& node ); diff --git a/src/osgPlugins/OpenFlight/expGeometryRecords.cpp b/src/osgPlugins/OpenFlight/expGeometryRecords.cpp index 58aed9e32..d54b3a63e 100644 --- a/src/osgPlugins/OpenFlight/expGeometryRecords.cpp +++ b/src/osgPlugins/OpenFlight/expGeometryRecords.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -249,10 +250,18 @@ FltExportVisitor::writeFace( const osg::Geode& geode, const osg::Geometry& geom, } } - // Check for blending. We're not a Billboard (TBD?) - // so use either FIXED_NO_ALPHA_BLENDING or FIXED_ALPHA_BLENDING. + // Set the appropriate template mode based + // on blending or Billboarding. TemplateMode templateMode( FIXED_NO_ALPHA_BLENDING ); - if ( ss->getMode( GL_BLEND ) & osg::StateAttribute::ON ) + const osg::Billboard* bb = dynamic_cast< const osg::Billboard* >( &geode ); + if (bb != NULL) + { + if( bb->getMode() == osg::Billboard::AXIAL_ROT ) + templateMode = AXIAL_ROTATE_WITH_ALPHA_BLENDING; + else + templateMode = POINT_ROTATE_WITH_ALPHA_BLENDING; + } + else if ( ss->getMode( GL_BLEND ) & osg::StateAttribute::ON ) { const osg::BlendFunc* bf = static_cast( ss->getAttribute(osg::StateAttribute::BLENDFUNC) ); @@ -416,10 +425,18 @@ FltExportVisitor::writeMesh( const osg::Geode& geode, const osg::Geometry& geom } } - // Check for blending. We're not a Billboard (TBD?) - // so use either FIXED_NO_ALPHA_BLENDING or FIXED_ALPHA_BLENDING. + // Set the appropriate template mode based + // on blending or Billboarding. TemplateMode templateMode( FIXED_NO_ALPHA_BLENDING ); - if ( ss->getMode( GL_BLEND ) & osg::StateAttribute::ON ) + const osg::Billboard* bb = dynamic_cast< const osg::Billboard* >( &geode ); + if (bb != NULL) + { + if( bb->getMode() == osg::Billboard::AXIAL_ROT ) + templateMode = AXIAL_ROTATE_WITH_ALPHA_BLENDING; + else + templateMode = POINT_ROTATE_WITH_ALPHA_BLENDING; + } + else if ( ss->getMode( GL_BLEND ) & osg::StateAttribute::ON ) { const osg::BlendFunc* bf = static_cast( ss->getAttribute(osg::StateAttribute::BLENDFUNC) );