示例#1
0
osg::Node*
ModelResource::createNodeFromURI( const URI& uri, const osgDB::Options* dbOptions ) const
{
    osg::Node* node = 0L;

    ReadResult r = uri.readNode( dbOptions );
    if ( r.succeeded() )
    {
        node = r.releaseNode();

        OE_INFO << LC << "Loaded " << uri.base() << "(from " << (r.isFromCache()? "cache" : "source") << ")"
                << std::endl;

        osgUtil::Optimizer o;
        o.optimize( node,
                    o.DEFAULT_OPTIMIZATIONS |
                    o.INDEX_MESH |
                    o.VERTEX_PRETRANSFORM |
                    o.VERTEX_POSTTRANSFORM );
    }
    else // failing that, fall back on the old encoding format..
    {
        StringVector tok;
        StringTokenizer( *uri, tok, "()" );
        if (tok.size() >= 2)
        {
            node = createNodeFromURI( URI(tok[1]), dbOptions );
        }
    }

    return node;
}
示例#2
0
osg::Node*
ModelResource::createNodeFromURI( const URI& uri, const osgDB::Options* dbOptions ) const
{
    osg::Node* node = 0L;

    ReadResult r = uri.getNode( dbOptions );
    if ( r.succeeded() )
    {
        node = r.releaseNode();
    }
    else // failing that, fall back on the old encoding format..
    {
        StringVector tok;
        StringTokenizer( *uri, tok, "()" );
        if (tok.size() >= 2)
            return createNodeFromURI( URI(tok[1]), dbOptions );
    }

    return node;
}
示例#3
0
osg::Node*
ModelResource::createNodeFromURI( const URI& uri, const osgDB::Options* dbOptions ) const
{
    osg::ref_ptr< osgDB::Options > options = dbOptions ? new osgDB::Options( *dbOptions ) : 0;

    // Explicitly cache images so that models that share images will only load one copy.
    options->setObjectCacheHint( osgDB::Options::CACHE_IMAGES );
    osg::Node* node = 0L;

    ReadResult r = uri.readNode( options.get() );
    if ( r.succeeded() )
    {
        node = r.releaseNode();
        
        OE_INFO << LC << "Loaded " << uri.base() << "(from " << (r.isFromCache()? "cache" : "source") << ")"
            << std::endl;

        osgUtil::Optimizer o;
        o.optimize( node,
            o.DEFAULT_OPTIMIZATIONS |
            o.INDEX_MESH |
            o.VERTEX_PRETRANSFORM |
            o.VERTEX_POSTTRANSFORM );
    }
    else // failing that, fall back on the old encoding format..
    {
        StringVector tok;
        StringTokenizer( *uri, tok, "()" );
        if (tok.size() >= 2)
        {
            node = createNodeFromURI( URI(tok[1]), options.get() );
        }
    }

    return node;
}
示例#4
0
osg::Node*
ModelResource::createNodeFromURI( const URI& uri, const osgDB::Options* dbOptions ) const
{
    if (_status.isError())
        return 0L;

    osg::ref_ptr< osgDB::Options > options = dbOptions ? new osgDB::Options( *dbOptions ) : 0L;

    // Explicitly cache images so that models that share images will only load one copy.
    // If the options struture doesn't contain an object cache, OSG will use the global
    // object cache stored in the Registry. Without this, models that share textures or
    // use an atlas will duplicate memory usage.
    //
    // I don't like having this here - it seems like it belongs elsewhere and the caller
    // should be passing it in. But it needs to be set, so keep for now.
    if ( options.valid() )
    {
        options->setObjectCacheHint( osgDB::Options::CACHE_IMAGES );
    }

    osg::Node* node = 0L;

    ReadResult r = uri.readNode( options.get() );
    if ( r.succeeded() )
    {
        node = r.releaseNode();
        
        OE_INFO << LC << "Loaded " << uri.base() << "(from " << (r.isFromCache()? "cache" : "source") << ")"
            << std::endl;

        osgUtil::Optimizer o;
        o.optimize( node,
            o.REMOVE_REDUNDANT_NODES |
            o.COMBINE_ADJACENT_LODS  |
            o.MERGE_GEOMETRY         |
            o.MAKE_FAST_GEOMETRY     |
            o.CHECK_GEOMETRY         |
            o.SHARE_DUPLICATE_STATE  |
            o.INDEX_MESH             |
            o.VERTEX_PRETRANSFORM    |
            o.VERTEX_POSTTRANSFORM );
        

        // Disable automatic texture unref since resources can be shared/paged.
        SetUnRefPolicyToFalse visitor;
        node->accept( visitor );
    }
    else // failing that, fall back on the old encoding format..
    {
        StringVector tok;
        StringTokenizer( *uri, tok, "()" );
        if (tok.size() >= 2)
        {
            node = createNodeFromURI( URI(tok[1]), options.get() );
        }
    }

    if (node == 0L && _status.isOK())
    {
        Threading::ScopedMutexLock lock(_mutex);
        if (_status.isOK())
        {
            _status = Status::Error(Status::ServiceUnavailable, "Failed to load resource file");
        }
    }

    return node;
}