[osg-users] Extract an embedded texture from an .ive

冯晨 forrestgump at 126.com
Wed Jul 9 19:01:39 PDT 2008


 
 
 Hi,
    I've also been doing the same thing lately. I've writen some code to achieve that, maybe help, :)

class TextureVisitor : public osg::NodeVisitor
{
public:
    TextureVisitor(int sizelimit, int levelnum):_sizelimit(sizelimit), _levelnum(levelnum),
        osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
    {}

    virtual void apply(osg::Group& node)
    {
        osg::StateSet* ss = node.getStateSet();
        if(ss!=NULL)
            traverseTexture(ss);
        traverse(node);
    }

    virtual void apply(osg::Node& node)
    {
        osg::StateSet* ss = node.getStateSet();
        if(ss!=NULL)
            traverseTexture(ss);
        traverse(node);
    }

    virtual void apply(osg::Geode& node)
    {
        osg::StateSet* ss = node.getStateSet();
        if(ss!=NULL)
            traverseTexture(ss);

        int numdrawables = node.getNumDrawables();
        for(int i=0; i<numdrawables; ++i)
        {
            ss = node.getDrawable(i)->getStateSet();
            if(ss!=NULL)
                traverseTexture(ss);
        }
        traverse(node);
    }

    void traverseTexture(osg::StateSet* ss)
    {
        osg::StateSet::TextureAttributeList texAbl =
            ss->getTextureAttributeList();
        int i=0;
        for(osg::StateAttribute* sa = ss->getTextureAttribute(i, osg::StateAttribute::TEXTURE);
            i<texAbl.size(); ++i)
        {
            osg::Texture2D* tex2d = dynamic_cast<osg::Texture2D*>(sa);
            if(tex2d==NULL)
                continue;
            //对于每一个image
            int numImg = tex2d->getNumImages();
            for(int j=0; j<numImg; ++j)
            {
                osg::Image* img = tex2d->getImage(j);
                SaveTexture(img);
            }
        }
    }
    string getName(const string& filename)
    {
        string::size_type pos = filename.find_last_of("\\");
        string::size_type pointpos = filename.find_last_of(".");
        string name;
        for(string::size_type i = pos+1; i<pointpos; ++i)
        {
            name += filename[i];
        }
        return name;
    }
    void SaveTexture(osg::Image* img)
    {
        osgDB::writeImageFile(img, img->getFileName());
    }
private:
    int _sizelimit;
    int _levelnum;
};

 


在2008-07-09 21:32:46,Doug <taecmcpt at comcast.net> 写道:
>Hi,
>
>I have a model in .ive format with an embedded texture. I need to bring 
>the model into 3dsMax to work on it. I can use osgconv to convert it to 
>one of several different formats that Max can import (obj, dae, etc.), 
>but I also need the texture that is embedded. Can anyone point me in the 
>right direction as to how to extract a texture that is embedded in an 
>.ive file?
>
>Thanks,
>
>Doug
>_______________________________________________
>osg-users mailing list
>osg-users at lists.openscenegraph.org
>http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20080710/dc13ba8d/attachment-0003.htm>


More information about the osg-users mailing list