void FltExportVisitor::apply( osg::MatrixTransform& node ) { // Importer reads a Matrix record and inserts a MatrixTransform above // the current node. We need to do the opposite: Write a Matrix record // as an ancillary record for each child. We do that by storing the // MatrixTransform in each child's UserData. Each child then checks // UserData and writes a Matrix record if UserData is a MatrixTransform. _firstNode = false; ScopedStatePushPop guard( this, node.getStateSet() ); osg::ref_ptr< osg::RefMatrix > m = new osg::RefMatrix; m->set( node.getMatrix() ); if (node.getUserData()) { const osg::RefMatrix* rm = dynamic_cast<const osg::RefMatrix*>( node.getUserData() ); if (rm) (*m) *= *rm; } typedef std::vector< osg::ref_ptr< osg::Referenced > > UserDataList; UserDataList saveUserDataList( node.getNumChildren() ); unsigned int idx; for( idx=0; idx<node.getNumChildren(); ++idx ) { saveUserDataList[ idx ] = node.getChild( idx )->getUserData(); node.getChild( idx )->setUserData( m.get() ); } traverse( (osg::Node&)node ); // Restore saved UserData. for( idx=0; idx< node.getNumChildren(); ++idx ) { node.getChild( idx )->setUserData( saveUserDataList[ idx ].get() ); } }
void CountsVisitor::apply(osg::MatrixTransform& node) { pushStateSet(node.getStateSet()); _matrixTransforms++; osg::ref_ptr<osg::Object> rp = (osg::Object*)&node; _uMatrixTransforms.insert(rp); _totalChildren += node.getNumChildren(); apply(node.getStateSet()); if (++_depth > _maxDepth) _maxDepth = _depth; traverse((osg::Node&)node); _depth--; popStateSet(); }