[osg-users] Getting the effective stateset for a nodepath.

Chris Denham c.m.denham at gmail.com
Mon Nov 16 10:11:26 PST 2009


Given a nodepath, what is the correct way to extract the effective material that will be used to render the node? i.e. to take into account the attribute inheritance and overrides etc.
My first stab looked like the code below, which seemed to work for simple cases, but not when the graph contained overrides etc.
Cheers
Chris.


Code:

osg::ref_ptr<osg::StateSet> stateSet = new osg::StateSet();
osg::NodePath::const_iterator& i = getNodePath().begin();
for (; i != getNodePath().end(); i++)
{
osg::Node* node = *i;
const osg::StateSet* merge = node->getStateSet();
if (merge) stateSet->merge(*merge);
}

const osg::Material* material = NULL;
material = dynamic_cast<const osg::Material*>(stateSet->getAttribute(osg::StateAttribute::MATERIAL));





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







More information about the osg-users mailing list