[osg-users] Color Change Question

Daniel Lecklider lecklider_daniel at bah.com
Wed Jul 6 15:05:36 PDT 2016


Hi,

At my work we use OSG for simulation purposes and I am looking to display a model with each of its individual parts/components displayed in a different color.

 I am new to OSG so I still dont understand everything yet. But I know I need to remove all of the skins and apply a new color. A co-worker already created a way to give the entire model a color but I need to do it for each sub component. 


Here is the function my co-worker has used to remove the textures and add the new material.

Code:

void removeTextures(osg::Node* x)
{

if(x != nullptr)
     {
          auto state = x->getOrCreateStateSet();
          state->setAttributeAndModes(this->material, osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON);
          state->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::OVERRIDE | osg::StateAttribute::OFF);
          auto group = x->asGroup();
          
          if(group != nullptr)
          {
               auto numChildren = group->getNumChildren();
               for(decltype(numChildren) i = 0; i < numChildren; i++)
               {
                    this->removeTextures(group->getChild(i));
               }
          }
     }
}



How would I go about changing the material of each geode/geometry/drawable and what are the differences between these three classes?

Thank you!

Cheers,
Daniel

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=68032#68032








More information about the osg-users mailing list