OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

removing texture from stateset


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
Trajce Nikolov NICK
Guest





PostPosted: Sat Jan 13, 2018 8:39 pm    Post subject:
removing texture from stateset
Reply with quote

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

------------------
Post generated by Mail2Forum
Back to top
mp3butcher (Julien Valentin)
Appreciator


Joined: 17 Feb 2010
Posts: 462
Location: France

PostPosted: Sat Jan 13, 2018 8:53 pm    Post subject:
Re: removing texture from stateset
Reply with quote

Hi Nickolov
use
Code:
StateSet::removeTextureAttribute(unit,texatt)

to remove a texture.
Moreover when you erase you iterator it invalidates it ...so don't do like this

Cheers


Trajce Nikolov NICK wrote:
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

------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message Visit poster's website
mp3butcher (Julien Valentin)
Appreciator


Joined: 17 Feb 2010
Posts: 462
Location: France

PostPosted: Sat Jan 13, 2018 9:02 pm    Post subject:
Re: removing texture from stateset
Reply with quote

oups i post too fast
I wanted to write
Code:
StateSet::removeTextureAttribute(unit,texatt)


mp3butcher wrote:
Hi Nickolov
use
Code:
StateSet::removeTextureAttribute(unit,texatt)

to remove a texture.
Moreover when you erase you iterator it invalidates it ...so don't do like this

Cheers


Trajce Nikolov NICK wrote:
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

------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message Visit poster's website
Trajce Nikolov NICK
Guest





PostPosted: Sun Jan 14, 2018 9:49 am    Post subject:
removing texture from stateset
Reply with quote

Hi Julien,

yes, removeTextureAttribute did the job. Thanks a bunch!!!  I should have consulted the header too


Cheers,
Nick


On Sat, Jan 13, 2018 at 10:02 PM, Julien Valentin < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)> wrote:
Quote:
oups i post too fast
I wanted to write

Code:
StateSet::removeTextureAttribute(unit,texatt)




mp3butcher wrote:
Quote:
Hi Nickolov
use

Code:
StateSet::removeTextureAttribute(unit,texatt)


to remove a texture.
Moreover when you erase you iterator it invalidates it ...so don't do like this

Cheers



Trajce Nikolov NICK wrote:
Quote:
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

  ------------------
Post generated by Mail2Forum



------------------
Read this topic online here:


http://forum.openscenegraph.org/viewtopic.php?p=72751#72751





_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org






--
trajce nikolov nick

------------------
Post generated by Mail2Forum
Back to top
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Can't share Texture among several tex... mp3butcher General 1 Fri Aug 17, 2018 11:06 pm View latest post
No new posts minor change: move assumeSizedInterna... mp3butcher General 9 Wed Aug 15, 2018 10:07 pm View latest post
No new posts Minor change proposal : Blacklist usa... mp3butcher General 14 Mon Aug 13, 2018 1:42 pm View latest post
No new posts Load an obj file and mapping a given ... aaa3d General 3 Mon Aug 06, 2018 2:27 pm View latest post
No new posts osgOcean - Render to Texture Camera rob_ewbank osgOcean [osgOcean] 3 Wed Jul 04, 2018 11:27 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP