<div dir="ltr"><div><div><div>Hi Robert<br><br></div>Thanks for this great hint! Really good one!<br><br></div>Cheers!<br></div>Nick<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 26, 2016 at 6:27 PM, Robert Osfield <span dir="ltr"><<a href="mailto:robert.osfield@gmail.com" target="_blank">robert.osfield@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On 26 August 2016 at 17:13, Trajce Nikolov NICK<br>
<span class=""><<a href="mailto:trajce.nikolov.nick@gmail.com">trajce.nikolov.nick@gmail.com</a><wbr>> wrote:<br>
> Ok :-) .. I will answer it too .....<br>
><br>
> I am working with older version of osg where the Geometry was still not<br>
> inherited from Node so I had to apply a special case for Geodes ... Sorry<br>
> for the noise ;-)<br>
<br>
</span>Glad to hear you spotted the problem.<br>
<br>
One thing that jumped out at me when I read the code was that you call<br>
getOrCreateStateSet(), this might simplify the code but is terribly<br>
inefficient for both this traversal and any subsequent use of the<br>
scene graph as it will force the creation of StateSet's for all nodes<br>
in the scene graph. Most nodes in a scene graph should never need a<br>
StateSet so you certainly don't want to go around assigning empty<br>
ones.<br>
<br>
What a better check would be:<br>
<br>
void apply(osg::Node& node)<br>
{<br>
if (node.getStateSet()) apply(*node.getStateSet())l<br>
}<br>
<br>
void apply(osg::StateSet& stateset)<br>
{<br>
osg::StateAttribute* attr =<br>
stateset>getAttribute(osg::<wbr>StateAttribute::MATERIAL);<br>
<span class=""> if (attr)<br>
{<br>
std::cout << "ATTRIBUTE: " << attr->getName() << std::endl;<br>
<br>
osg::Material* material = dynamic_cast<osg::Material*>(<wbr>attr);<br>
if (material && (material->getName() != "@RootMaterial@"))<br>
{<br>
std::cout << "MATERIAL: " << material->getName() <<<br>
std::endl;<br>
}<br>
}<br>
}<br>
</span>______________________________<wbr>_________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.<wbr>openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.<wbr>org/listinfo.cgi/osg-users-<wbr>openscenegraph.org</a><br>
</blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">trajce nikolov nick<br></div>
</div>