SkinResource*
ResourceLibrary::getSkin( const SkinSymbol* symbol, Random& prng, const osgDB::Options* dbOptions ) const
{
    const_cast<ResourceLibrary*>(this)->initialize( dbOptions );

    if (symbol->name().isSet())
    {
        return getSkin(symbol->name()->eval(), dbOptions);
    }

    SkinResourceVector candidates;
    getSkins( symbol, candidates );
    unsigned size = candidates.size();
    if ( size == 0 )
    {
        return 0L;
    }
    else if ( size == 1 )
    {
        return candidates[0].get();
    }
    else
    {
        return candidates[ prng.next(size) ].get();
    }
}
예제 #2
0
void SkinTextureArray::build(SkinResourceVector& skins, const osgDB::Options* dbOptions)
{        
    _texture = 0;
    _layerIndex.clear();

    unsigned int maxWidth = 0;
    unsigned int maxHeight = 0;

    std::vector< osg::ref_ptr< osg::Image > > images;

    for (unsigned int i = 0; i < skins.size(); i++)
    {
        osg::ref_ptr< osg::Image > image = skins[i]->createImage( dbOptions );
        if (image.valid())
        {
            if (maxWidth < image->s()) maxWidth = image->s();
            if (maxHeight < image->t()) maxHeight = image->t();            
            _layerIndex[ skins[i]->name() ] = i;
            images.push_back( image.get() );
        }
    }

    // Now resize all the images to the largest size.
    for (unsigned int i = 0; i < images.size(); i++)
    {
        osg::ref_ptr< osg::Image> resized;
        if (images[i]->s() != maxWidth || images[i]->t() != maxHeight)
        {            
            OE_DEBUG << "resizing image to " << maxWidth << "x" << maxHeight << std::endl;
            ImageUtils::resizeImage( images[i].get(), maxWidth, maxHeight, resized, 0, true);
        }        
        else
        {
             resized = images[i].get();
        }
        resized = ImageUtils::convertToRGBA8( resized.get() );
        images[i] = resized.get();
    }

    osg::Texture2DArray* texture = new osg::Texture2DArray();
    texture->setTextureDepth( images.size() );
    texture->setTextureWidth( maxWidth );
    texture->setTextureHeight( maxHeight );
    texture->setSourceFormat( GL_RGBA );
    texture->setInternalFormat( GL_RGBA8 );

    texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR_MIPMAP_LINEAR);
    texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
    texture->setWrap(osg::Texture::WRAP_S,osg::Texture::REPEAT);
    texture->setWrap(osg::Texture::WRAP_T,osg::Texture::REPEAT);
    texture->setResizeNonPowerOfTwoHint(false);
    for (unsigned int i = 0; i < images.size(); i++)
    {
        texture->setImage(i, images[i].get() );
    }
    _texture = texture;
}
예제 #3
0
SkinResource*
ResourceLibrary::getSkin( const SkinSymbol* symbol, Random& prng ) const
{
    SkinResourceVector candidates;
    getSkins( symbol, candidates );
    unsigned size = candidates.size();
    if ( size == 0 )
    {
        return 0L;
    }
    else if ( size == 1 )
    {
        return candidates[0].get();
    }
    else
    {
        return candidates[ prng.next(size) ].get();
    }
}