Example #1
0
void
ShaderGenerator::apply(osg::Group& group)
{
    if ( !_active ) return;

    traverse(group);

#if 0
    std::set<VirtualProgram*> childVPs;
    unsigned childrenWithVP = 0;
    for(unsigned i=0; i<group.getNumChildren(); ++i)
    {
        osg::StateSet* stateset = group.getChild(i)->getStateSet();
        if ( !stateset )
            break;

        VirtualProgram* vp = dynamic_cast<VirtualProgram*>(stateset->getAttribute(VirtualProgram::SA_TYPE));
        if ( vp )
        {
            childVPs.insert( vp );
            childrenWithVP++;
        }
    }
    if ( childrenWithVP == group.getNumChildren() && childVPs.size() == 1 )
    {
        group.getOrCreateStateSet()->setAttributeAndModes( *childVPs.begin(), 1 );
        for(unsigned i=0; i<group.getNumChildren(); ++i)
        {
            group.getChild(i)->getStateSet()->removeAttribute(VirtualProgram::SA_TYPE);
        }
    }
#endif
}
// apply method for groups
void GeometryExtractorVisitor::apply( osg::Group& group ) {
	
	// call the appropriate apply method for all children
	if( group.getNumChildren() > 0 ) {
		for( unsigned int i = 0; i < group.getNumChildren(); i++) {
			osg::Node* node = group.getChild( i );
			apply( *node );
		}
	}
}
Example #3
0
void CVRCullVisitor::PreCullVisitor::apply(osg::Group& group)
{
    bool setMask = false;
    for(int i = 0; i < group.getNumChildren(); i++)
    {
        _setMask = false;
        group.getChild(i)->accept(*this);
        if(_setMask)
        {
            setMask = true;
        }
    }

    if(group.getNodeMask() & FIRST_CULL_STATUS)
    {
        _setMask = true;
    }
    else if(setMask)
    {
        //std::cerr << "Pulling up node mask." << std::endl;
        _setMask = true;
        group.setNodeMask(group.getNodeMask() | FIRST_CULL_STATUS);
    }

}
void
RemoveEmptyGroupsVisitor::apply( osg::Group& group )
{
    bool removed = true;
    while( removed )
    {
        removed = false;
        for( unsigned i = 0; i < group.getNumChildren(); ++i )
        {
            osg::Group* child = group.getChild(i)->asGroup();
            if ( child )
            {
                if (child->className() == std::string("Group") &&
                    child->getStateSet() == 0L            &&
                    child->getCullCallback() == 0L        &&
                    child->getUpdateCallback() == 0L      &&
                    child->getUserData() == 0L            &&
                    child->getName().empty()              &&
                    child->getDescriptions().size() == 0 )
                {
                    for( unsigned j = 0; j < child->getNumChildren(); ++j )
                    {
                        group.addChild( child->getChild( j ) );
                    }

                    group.removeChild( i-- );
                    removed = true;
                }                
            }
        }
    }

    traverse(group);
}
Example #5
0
File: Group.cpp Project: aalex/osg
static bool writeChildren( osgDB::OutputStream& os, const osg::Group& node )
{
    unsigned int size = node.getNumChildren();
    os << size << osgDB::BEGIN_BRACKET << std::endl;
    for ( unsigned int i=0; i<size; ++i )
    {
        os << node.getChild(i);
    }
    os << osgDB::END_BRACKET << std::endl;
    return true;
}
Example #6
0
	virtual void apply(osg::Group &group ) {
		for (unsigned int i = 0; i<group.getNumChildren(); ) {
			if( dynamic_cast<osgAL::SoundRoot*>(group.getChild(i)) && _mode==SEARCH_AND_DESTROY ) {
				group.removeChild(i);
			} else {
				if (dynamic_cast<osgAL::SoundRoot*>(group.getChild(i)) && _mode==SEARCH)
					_found_count++;

				group.getChild(i)->accept(*this);
				i++;
			}
		}
	}
 virtual void apply(osg::Group& group)
 {
     for (unsigned int i = 0; i < group.getNumChildren(); i++)
     {
         osg::Node* child = group.getChild(i);
         osg::Node* seam = seamReplacement(child);
         if (child != seam)
         {
             group.replaceChild(child,seam);
         }
         else
         {
             child->accept(*this);
         }
     }
 }
Example #8
0
void
GeometryValidator::apply(osg::Group& group)
{
    for(unsigned i=0; i<group.getNumChildren(); ++i)
    {
        osg::Geometry* geom = group.getChild(i)->asGeometry();
        if ( geom )
        {
            apply( *geom );
            if ( geom->getVertexArray() == 0L )
            {
                OE_NOTICE << "removing " << geom->getName() << " b/c of null vertex array\n";
                group.removeChild(geom);
                --i;
            }
        }
    }
}
Example #9
0
void
CountsVisitor::apply(osg::Group& node)
{
    pushStateSet(node.getStateSet());

    _groups++;
    osg::ref_ptr<osg::Object> rp = (osg::Object*)&node;
    _uGroups.insert(rp);
    _totalChildren += node.getNumChildren();
    apply(node.getStateSet());

    if (++_depth > _maxDepth)
        _maxDepth = _depth;
    traverse((osg::Node&)node);
    _depth--;

    popStateSet();
}
Example #10
0
File: Group.cpp Project: aalex/osg
static bool checkChildren( const osg::Group& node )
{
    return node.getNumChildren()>0;
}