bool FltExportVisitor::atLeastOneMesh( const osg::Geometry& geom ) const { // Return true if at least one PrimitiveSet mode will use a Mesh record. unsigned int jdx; for (jdx=0; jdx < geom.getNumPrimitiveSets(); jdx++) { const osg::PrimitiveSet* prim = geom.getPrimitiveSet( jdx ); if( isMesh( prim->getMode() ) ) return true; } // All PrimitiveSet modes will use Face records. return false; }
// 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 ) { _firstNode = false; ScopedStatePushPop guard( this, node.getStateSet() ); unsigned int idx; for (idx=0; idx<node.getNumDrawables(); idx++) { osg::Geometry* geom = node.getDrawable( idx )->asGeometry(); if (!geom) { std::string warning( "fltexp: Non-Geometry Drawable encountered. Ignoring." ); osg::notify( osg::WARN ) << warning << std::endl; _fltOpt->getWriteResult().warn( warning ); continue; } ScopedStatePushPop drawableGuard( this, geom->getStateSet() ); // Push and pop subfaces if polygon offset is on. SubfaceHelper subface( *this, getCurrentStateSet() ); if (atLeastOneFace( *geom )) { // If at least one record will be a Face record, then we // need to write to the vertex palette. _vertexPalette->add( *geom ); // Iterate over all PrimitiveSets and output Face records. unsigned int jdx; for (jdx=0; jdx < geom->getNumPrimitiveSets(); jdx++) { osg::PrimitiveSet* prim = geom->getPrimitiveSet( jdx ); if ( isMesh( prim->getMode() ) ) continue; if (prim->getType() == osg::PrimitiveSet::DrawArraysPrimitiveType) handleDrawArrays( dynamic_cast<osg::DrawArrays*>( prim ), *geom, node ); else if (prim->getType() == osg::PrimitiveSet::DrawArrayLengthsPrimitiveType) handleDrawArrayLengths( dynamic_cast<osg::DrawArrayLengths*>( prim ), *geom, node ); else if ( (prim->getType() == osg::PrimitiveSet::DrawElementsUBytePrimitiveType) || (prim->getType() == osg::PrimitiveSet::DrawElementsUShortPrimitiveType) || (prim->getType() == osg::PrimitiveSet::DrawElementsUIntPrimitiveType) ) handleDrawElements( dynamic_cast<osg::DrawElements*>( prim ), *geom, node ); else { std::string warning( "fltexp: Unknown PrimitiveSet type." ); osg::notify( osg::WARN ) << warning << std::endl; _fltOpt->getWriteResult().warn( warning ); return; } } } if (atLeastOneMesh( *geom )) { // If at least one Mesh record, write out preamble mesh records // followed by a Mesh Primitive record per PrimitiveSet. writeMesh( node, *geom ); writeMatrix( node.getUserData() ); writeComment( node ); writeMultitexture( *geom ); writeLocalVertexPool( *geom ); writePush(); unsigned int jdx; for (jdx=0; jdx < geom->getNumPrimitiveSets(); jdx++) { osg::PrimitiveSet* prim = geom->getPrimitiveSet( jdx ); if ( !isMesh( prim->getMode() ) ) continue; if (prim->getType() == osg::PrimitiveSet::DrawArraysPrimitiveType) handleDrawArrays( dynamic_cast<osg::DrawArrays*>( prim ), *geom, node ); else if (prim->getType() == osg::PrimitiveSet::DrawArrayLengthsPrimitiveType) handleDrawArrayLengths( dynamic_cast<osg::DrawArrayLengths*>( prim ), *geom, node ); else if ( (prim->getType() == osg::PrimitiveSet::DrawElementsUBytePrimitiveType) || (prim->getType() == osg::PrimitiveSet::DrawElementsUShortPrimitiveType) || (prim->getType() == osg::PrimitiveSet::DrawElementsUIntPrimitiveType) ) handleDrawElements( dynamic_cast<osg::DrawElements*>( prim ), *geom, node ); else { std::string warning( "fltexp: Unknown PrimitiveSet type." ); osg::notify( osg::WARN ) << warning << std::endl; _fltOpt->getWriteResult().warn( warning ); return; } } writePop(); } } // Would traverse here if this node could have children. // traverse( (osg::Node&)node ); }