Beispiel #1
0
 virtual void apply(osg::Node& node)
 {
     if (node.getStateSet())
     {
         node.setStateSet(0);
         ++_numStateSetRemoved;
     }
     traverse(node);
 }
Beispiel #2
0
	virtual void apply(osg::Node& node)
	{
		for(int i=0;i<_indent;++i)
			std::cout<<"   ";
		std::cout<<"["<<_indent+1<<"]"<<node.libraryName()
			<<"::"<<node.className()<<std::endl;
		_indent++;
		traverse(node);
		_indent--;
	}
void
CountStateSets::apply( osg::Node& node )
{
    if( !processStateSet( node.getStateSet() ) && _removeEmptyStateSets )
    {
        node.setStateSet( NULL );
        _removedStateSets++;
    }
    traverse( node );
}
Beispiel #4
0
void RemoveQueries::apply( osg::Node& node )
{
    QueryCullCallback* qcc = dynamic_cast< QueryCullCallback* >(
        node.getCullCallback() );

    if( qcc != NULL )
        node.setCullCallback( NULL );

    traverse( node );
}
Beispiel #5
0
void osgManipulator::setMaterialColor(const osg::Vec4& color, osg::Node& node)
{
    osg::Material* mat = dynamic_cast<osg::Material*>(node.getOrCreateStateSet()->getAttribute(osg::StateAttribute::MATERIAL));
    if (! mat)
    {
        mat = new osg::Material;
        node.getOrCreateStateSet()->setAttribute(mat);
    }
    mat->setDiffuse(osg::Material::FRONT_AND_BACK, color);
}
Beispiel #6
0
 void apply( osg::Node& node )
 {
     if ( !node.getName().empty() )
     {
         output() << node.getName() << std::endl;
         enter();
         traverse( node );
         leave();
     }
     else osgUtil::PrintVisitor::apply(node);
 }
// ### provide a name to node
std::string daeWriter::getNodeName(const osg::Node &node, const std::string &defaultName)
{
    std::string nodeName;

    if (node.getName().empty())
        nodeName = uniquify(defaultName);
    else
        nodeName = uniquify(node.getName());

    return nodeName;
}
 void ShaderVisitor::apply(osg::Node& node)
 {
     if (node.getStateSet())
     {
         pushRequirements();
         applyStateSet(node.getStateSet(), node);
         traverse(node);
         popRequirements();
     }
     else
         traverse(node);
 }
osgDB::ReaderWriter::WriteResult
ReaderWriterDAE::writeNode( const osg::Node& node,
        const std::string& fname, const osgDB::ReaderWriter::Options* options ) const
{
    SERIALIZER();

    bool bOwnDAE = false;
    DAE* pDAE = NULL;

    std::string ext( osgDB::getLowerCaseFileExtension(fname) );
    if( ! acceptsExtension(ext) ) return WriteResult::FILE_NOT_HANDLED;

    // Process options
    osgDAE::daeWriter::Options pluginOptions;
    std::string srcDirectory( osgDB::getFilePath(node.getName().empty() ? fname : node.getName()) );        // Base dir when relativising images paths
    if( options )
    {
        pDAE = (DAE*)options->getPluginData("DAE");

        const std::string & baseDir = options->getPluginStringData("baseImageDir");        // Rename "srcModelPath" (and call getFilePath() on it)?
        if (!baseDir.empty()) srcDirectory = baseDir;

        const std::string & relativiseImagesPathNbUpDirs = options->getPluginStringData("DAE-relativiseImagesPathNbUpDirs");
        if (!relativiseImagesPathNbUpDirs.empty()) {
            std::istringstream iss(relativiseImagesPathNbUpDirs);
            iss >> pluginOptions.relativiseImagesPathNbUpDirs;
        }

        // Sukender's note: I don't know why DAE seems to accept comma-sparated options instead of space-separated options as other ReaderWriters. However, to avoid breaking compatibility, here's a workaround:
        std::string optString( options->getOptionString() );
        for(std::string::iterator it=optString.begin(); it!=optString.end(); ++it) {
            if (*it == ' ') *it = ',';
        }
        std::istringstream iss( optString );
        std::string opt;

        //while (iss >> opt)
        while( std::getline( iss, opt, ',' ) )
        {
            if( opt == "polygon") pluginOptions.usePolygons = true;
            else if (opt == "GoogleMode") pluginOptions.googleMode = true;
            else if (opt == "NoExtras") pluginOptions.writeExtras = false;
            else if (opt == "daeEarthTex") pluginOptions.earthTex = true;
            else if (opt == "daeZUpAxis") {}    // Nothing (old option)
            else if (opt == "daeLinkOriginalTexturesNoForce") { pluginOptions.linkOrignialTextures = true; pluginOptions.forceTexture = false; }
            else if (opt == "daeLinkOriginalTexturesForce")   { pluginOptions.linkOrignialTextures = true; pluginOptions.forceTexture = true; }
            else if (opt == "daeNamesUseCodepage") pluginOptions.namesUseCodepage = true;
            else if (!opt.empty())
            {
                OSG_NOTICE << std::endl << "COLLADA dae plugin: unrecognized option \"" << opt <<  std::endl;
            }
        }
    }
void SimpleDotVisitor::handle(osg::Node &node, int id)
{
    std::stringstream label;

    label << "<top> Node";
    if (!node.getName().empty())
    {
        label << "| " << node.getName();
    }

    drawNode(id, "record", "solid", label.str(), "black", "white");
}
bool PrimitiveIntersector::enter(const osg::Node& node)
{
    if (reachedLimit()) return false;

    osg::BoundingSphere bs = node.getBound();
    if (bs.valid())
    {
        bs.radius() += (_thickness - _start).length();
    }

    return !node.isCullingActive() || intersects(bs);
}
/// Returns true if the given node is a basic root group with no special information.
/// Used in conjunction with UseFbxRoot option.
/// Identity transforms are considered as basic root nodes.
bool isBasicRootNode(const osg::Node &node)
{
    const osg::Group *osgGroup = node.asGroup();

    if (!osgGroup || node.asGeode())        // WriterNodeVisitor handles Geodes the "old way" (= Derived from Node, not Group as for now). Geodes may be considered "basic root nodes" when WriterNodeVisitor will be adapted.
    {
        // Geodes & such are not basic root nodes
        return false;
    }

    // Test if we've got an empty transform (= a group!)
    const osg::Transform *transform = osgGroup->asTransform();
    if (transform)
    {
        if (const osg::MatrixTransform *matrixTransform = transform->asMatrixTransform())
        {
            if (!matrixTransform->getMatrix().isIdentity())
            {
                // Non-identity matrix transform
                return false;
            }
        }
        else if (const osg::PositionAttitudeTransform *pat = transform->asPositionAttitudeTransform())
        {
            if (pat->getPosition() != osg::Vec3d() ||
                pat->getAttitude() != osg::Quat() ||
                pat->getScale() != osg::Vec3d(1.0f, 1.0f, 1.0f) ||
                pat->getPivotPoint() != osg::Vec3d())
            {
                // Non-identity position attribute transform
                return false;
            }
        }
        else
        {
            // Other transform (not identity or not predefined type)
            return false;
        }
    }

    // Test the presence of a non-empty stateset
    if (node.getStateSet())
    {
        osg::ref_ptr<osg::StateSet> emptyStateSet = new osg::StateSet;
        if (node.getStateSet()->compare(*emptyStateSet, true) != 0)
        {
            return false;
        }
    }

    return true;
}
Beispiel #13
0
void 
ProxyCullVisitor::handle_cull_callbacks_and_traverse(osg::Node& node)
{
#if OSG_VERSION_GREATER_THAN(3,3,1)
    osg::Callback* callback = node.getCullCallback();
    if (callback) callback->run(&node, this);
    else traverse(node);
#else
    osg::NodeCallback* callback = node.getCullCallback();
    if (callback) (*callback)(&node,this);
    else traverse(node);
#endif
}
Beispiel #14
0
    virtual void apply(osg::Node& node)
    {
        std::cout
            << spaces()
            << node.libraryName()
            << "::"
            << node.className()
            << std::endl;

        level_++;
        traverse(node);
        level_--;
    }
Beispiel #15
0
void 
ShaderGenerator::apply( osg::Node& node )
{
    if ( !_active ) return;

    if ( node.getStateSet() )
        _state->pushStateSet( node.getStateSet() );

    traverse(node);

    if ( node.getStateSet() )
        _state->popStateSet();
}
Beispiel #16
0
void
ShaderGenerator::duplicateSharedNode(osg::Node& node)
{
    if ( node.getNumParents() > 1 )
    {
        for(int i=1; i<(int)node.getNumParents(); ++i)
        {
            osg::Group* parent = node.getParent(i);
            osg::Node* replicant = osg::clone(
                &node, 
                osg::CopyOp::DEEP_COPY_NODES | osg::CopyOp::DEEP_COPY_DRAWABLES | osg::CopyOp::DEEP_COPY_ARRAYS);
            parent->replaceChild(&node, replicant);
        }
    }
}
Beispiel #17
0
bool PosterIntersector::enter( const osg::Node& node )
{
    if ( !node.isCullingActive() ) return true;
    if ( _polytope.contains(node.getBound()) )
    {
        if ( node.getCullCallback() )
        {
            const osg::ClusterCullingCallback* cccb =
                dynamic_cast<const osg::ClusterCullingCallback*>( node.getCullCallback() );
            if ( cccb && cccb->cull(_intersectionVisitor, 0, NULL) ) return false;
        }
        return true;
    }
    return false;
}
Beispiel #18
0
void 
ShaderGenerator::apply(osg::Node& node)
{
    if ( !_active )
        return;

    if ( ignore(&node) )
        return;

    if ( _duplicateSharedSubgraphs )
        duplicateSharedNode(node);

    applyNonCoreNodeIfNecessary( node );

    osg::ref_ptr<osg::StateSet> stateset = node.getStateSet();
    if ( stateset.valid() )
    {
        _state->pushStateSet( stateset.get() );
    }

    traverse(node);

    if ( stateset.valid() )
    {
        _state->popStateSet();
    }
}
Beispiel #19
0
/** Return true if the node should be traversed, and false if the bounding sphere
    of the node is small enough to be rendered by one Camera. If the latter
    is true, then store the node's near & far plane distances. */
bool CURRENT_CLASS::shouldContinueTraversal(osg::Node &node)
{
    // Allow traversal to continue if we haven't reached maximum depth.
    bool keepTraversing = (_currentDepth < _maxDepth);

    const osg::BoundingSphere &bs = node.getBound();
    double zNear = 0.0, zFar = 0.0;

    // Make sure bounding sphere is valid and within viewing volume
    if(bs.valid())
    {
      if(!_localFrusta.back().contains(bs)) keepTraversing = false;
      else
      {
        // Compute near and far planes for this node
        zNear = distance(bs._center, _viewMatrices.back());
        zFar = zNear + bs._radius;
        zNear -= bs._radius;

        // If near/far ratio is big enough, then we don't need to keep
        // traversing children of this node.
        if(zNear >= zFar*_nearFarRatio) keepTraversing = false;
      }
    }

    // If traversal should stop, then store this node's (near,far) pair
    if(!keepTraversing) pushDistancePair(zNear, zFar);

    return keepTraversing;
}
Beispiel #20
0
void CVRCullVisitor::PreCullVisitor::apply(osg::Node& node)
{
    if(node.getNodeMask() & FIRST_CULL_STATUS)
    {
        _setMask = true;
    }
}
Beispiel #21
0
bool
FltExportVisitor::complete( const osg::Node& node )
{
    // Always write final pop level
    writePop();
    // Done writing records, close the record data temp file.
    _recordsStr.close();

    // Write OpenFlight file front matter: header, vertex palette, etc.
    writeHeader( node.getName() );

    writeColorPalette();
    _materialPalette->write( _dos );
    _texturePalette->write( _dos );
    _lightSourcePalette->write( _dos );
    _vertexPalette->write( _dos );

    // Write Comment ancillary record and specify the _dos DataOutputStream.
    writeComment( node, &_dos );

    // Copy record data temp file into final OpenFlight file.
    // Yee-uck. TBD need better stream copy routine.
    char buf;
    std::ifstream recIn;
    recIn.open( _recordsTempName.c_str(), std::ios::in | std::ios::binary );
    while (!recIn.eof() )
    {
        recIn.read( &buf, 1 );
        if (recIn.good())
            _dos << buf;
    }
    recIn.close();

    return true;
}
void GeodeFindVisitor::apply(osg::Node &searchNode) {
    if (!strcmp (searchNode.className(), "Geode"))
    {
        _foundGeodes.push_back((osg::Geode*) &searchNode);
    }
    traverse(searchNode);
}
Beispiel #23
0
void 
ProxyCullVisitor::handle_cull_callbacks_and_traverse(osg::Node& node)
{
    osg::NodeCallback* callback = node.getCullCallback();
    if (callback) (*callback)(&node,this);
    else traverse(node);
}
TransformerGraph::GraphDescription TransformerGraph::getGraphDescription(osg::Node& transformer)
{
    GraphDescription result;
    DescriptionVisitor visitor(result);
    transformer.accept(visitor);
    return result;
}
Beispiel #25
0
	virtual void apply (osg::Node& node) {
		if (node.getName() == m_NameToFind) {
			m_FoundNode = &node;
		} else {
			traverse(node);
		}
	}
Beispiel #26
0
void CVRCullVisitor::apply(osg::Node& node)
{
    bool status = _cullingStatus;
    bool firstStatus = _firstCullStatus;
    if(isCulled(node))
    {
        _firstCullStatus = firstStatus;
        _cullingStatus = status;
        return;
    }

    // push the culling mode.
    pushCurrentMask();

    // push the node's state.
    StateSet* node_state = node.getStateSet();
    if(node_state)
        pushStateSet(node_state);

    handle_cull_callbacks_and_traverse(node);

    // pop the node's state off the geostate stack.    
    if(node_state)
        popStateSet();

    // pop the culling mode.
    popCurrentMask();

    _firstCullStatus = firstStatus;
    _cullingStatus = status;
}
 void FindNode::apply(osg::Node &node)
 {
     if(node.getName() == name)
         this->node = &node;
     else
         traverse(node);
 }
Beispiel #28
0
void LinkVisitor::apply(osg::Node& node)
{
    osg::StateSet* st = node.getStateSet();
    if (st)
        handle_stateset(st);

    osg::NodeCallback* cb = node.getUpdateCallback();
    while (cb)
    {
        osgAnimation::AnimationUpdateCallbackBase* cba = dynamic_cast<osgAnimation::AnimationUpdateCallbackBase*>(cb);
        if (cba)
            link(cba);
        cb = cb->getNestedCallback();
    }
    traverse(node);
}
Beispiel #29
0
    void apply(osg::Node& node)
    {
        if (node.getStateSet()) process(node.getStateSet());

        if (node.getUpdateCallback())
        {
            _operatorList.insert(new CallbackOperator(&node, node.getUpdateCallback()));
        }

        LayerAttributes* la = dynamic_cast<LayerAttributes*>(node.getUserData());
        if (la)
        {
            _operatorList.insert(new LayerAttributesOperator(&node, la));
        }

        traverse(node);
    }
Beispiel #30
0
 virtual void apply(osg::Node& node)
 {
     if (node.getName()==_name)
     {
         _foundNodes.push_back(&node);
     }
     traverse(node);
 }