[osg-users] setAttribute / Material issue
Paul Bigeon
paulbigeon at hotmail.fr
Wed Aug 16 01:15:47 PDT 2017
Hi,
I'm very new to OSG, but here's a problem I've stumbled upon.
I'll try to give as many as possible infos about the context, but in the case that I miss something please do ask me for more.
So, basically, I use OpenSceneGraph 3.5.6.148 with Qt 5.6 to create a 3D Viewer that display a specific group of nodes that I have loaded in the view. Further on the execution of this program, the user has the possibility to add more group of nodes in the view, by adding a child to the main group of nodes that has been loaded.
For this purpose I use
osgQt\GraphicsWindowQt
To interact with the groups of nodes that are loaded in the GraphicsWindowQt, I use a osgUtil::LineSegmentIntersector which return to me the group of nodes under the cursor by sending a Qt signal to a function designed for coloring the group if it has not been selected yet or to reset the default color if it has already been selected.
The coloring function for it's main part consists of this :
This part is called if the group has to be selected :
Code:
osg::ref_ptr<osg::StateSet> stateset = grp->getOrCreateStateSet(); // Get the StateSet of the group
osg::Material* material_previous = (osg::Material*)stateset->getAttribute(osg::StateAttribute::MATERIAL); // Get the default Material of this group
if (material_previous)
{
selected_entity->m_material_previous = material_previous; // Store the default material in the selected object
}
stateset->setAttribute(m_material_selected, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE); // Set the new Material to this node.
selected_entity->m_material_selected = m_material_selected; // Store default material in the selected object
This part is called if the node has to be deselected:
Code:
osg::ref_ptr<osg::StateSet> stateset_selected_node = selected_entity->m_osg_group->getOrCreateStateSet(); // Get the StateSet of the group
if (selected_entity->m_material_previous)
{
stateset_selected_node->setAttribute(selected_entity->m_material_previous, osg::StateAttribute::ON); // Restore the previous material to this group
}
else if (selected_entity->m_material_selected)
{
stateset_selected_node->removeAttribute(selected_entity->m_material_selected); // Remove the attribute if there is no previous material stored on this group
}
Here's the problem :
Under certain camera angles, and before the user has selected any of the nodes that are in the scene, some nodes are already colored.
It seems to me that if the camera doesn't show some groups, others will be colored without any interaction at all from the user.
See the attached files to see what's happening on screen :
Thank in advance for your intereset in this request, and my apologies if my english is bad.
Cheers,
Paul[/img]
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=71425#71425
Attachments:
http://forum.openscenegraph.org//files/osg_material_issue_4_150.png
http://forum.openscenegraph.org//files/osg_material_issue_3_198.png
http://forum.openscenegraph.org//files/osg_material_issue_2_182.png
http://forum.openscenegraph.org//files/osg_material_issue_1_169.png
More information about the osg-users
mailing list