[osg-users] removing texture from stateset

Trajce Nikolov NICK trajce.nikolov.nick at gmail.com
Sat Jan 13 12:36:45 PST 2018


Hi Community,

this should be simple, but I can not make it work. I have ive file with
embedded texture and it is big file. All I want is to remove the texture
and save it back. When I do this with the code bellow, and save the file,
the file is not changing it's size. Any clue/hint?

Thanks a bunch as always!!!!

Nick

code
struct RemoveTextureVisitor : public osg::NodeVisitor
{
RemoveTextureVisitor()
: osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
{
}

virtual void apply(osg::Node& node)
{
osg::ref_ptr<osg::StateSet> ss = node.getStateSet();
if (ss.valid())
{
osg::StateSet::AttributeList& attrs = ss->getAttributeList();
osg::StateSet::AttributeList::iterator itr = attrs.begin();
for (; itr != attrs.end(); ++itr)
{
const osg::StateSet::RefAttributePair& attrp = itr->second;
const osg::ref_ptr<osg::StateAttribute>& attr = attrp.first;

osg::ref_ptr<osg::Texture2D> texture =
dynamic_cast<osg::Texture2D*>(attr.get());
if (texture.valid())
{
attrs.erase(itr);
break;
}
}
}

traverse(node);
}
};

-- 
trajce nikolov nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20180113/b77edae5/attachment.html>


More information about the osg-users mailing list