<div dir="ltr">Hi,<div><br></div><div>can you try geom->dirtyDisplayLists() after changing the color?</div><div><br></div><div>Nick</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Sep 2, 2015 at 12:27 PM, Yexin W <span dir="ltr"><<a href="mailto:xxtop716@163.com" target="_blank">xxtop716@163.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
Guys, I have a pick problem. What I want to do is loading 10 points with their loactions and colors. I want to use poly pick, and use another color to show the picked points.<br>
The loading points process is as follows:<br>
<br>
<br>
Code:<br>
<br>
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry();<br>
osg::ref_ptr<osg::Vec3Array> v = new osg::Vec3Array;<br>
osg::ref_ptr<osg::Vec4Array> clr = new osg::Vec4Array;<br>
v->push_back(osg::Vec3(0.0, 0.0, 0.0));<br>
... // 10 points in total<br>
clr->push_back(osg::Vec4(1.0, 0.0, 1.0, 1.0f));<br>
...// set the color<br>
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, v->size()));<br>
// after set the color and normal, add the geometry to Geode node<br>
geode->addDrawable(geom.get());<br>
<br>
<br>
<br>
<br>
<br>
Then I want to use ploy pick, the problem is : when I put the following codes in the pick() function in Pickhandler class, I found out that the color of the picked premitiveset has been changed, however, nothing changed in the view window. The following codes are in pick function:<br>
<br>
<br>
Code:<br>
<br>
if (picker->containsIntersections())<br>
{<br>
osgUtil::PolytopeIntersector::Intersections intersections = picker->getIntersections();<br>
osgUtil::PolytopeIntersector::Intersections::iterator iter;<br>
for (iter = intersections.begin(); iter != intersections.end(); iter++)<br>
{<br>
osg::NodePath nodepath = (*iter).nodePath;<br>
node = (nodepath.size() >= 1) ? nodepath[nodepath.size() - 1] : 0;<br>
int pointIndex = (*iter).primitiveIndex;<br>
osg::Geode * geode = dynamic_cast<osg::Geode*> (node);<br>
osg::Geometry * geom = dynamic_cast<osg::Geometry*>(geode->getDrawable(0));<br>
osg::Vec4Array * clrary = dynamic_cast<osg::Vec4Array*>(geom->getColorArray());<br>
clrary->operator [] (pointIndex) = osg::Vec4(0.0, 1.0, 0.0, 1.0f);<br>
geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);<br>
node->addUpdateCallback(new CessnaCallback()); // not helpful<br>
viewer->updateTraversal(); //not helpful<br>
//viewer->run();//not helpful<br>
}<br>
}<br>
<br>
<br>
<br>
<br>
<br>
First, I thought may be the colors have not been changed, so I tested changing several points' color in the main function, like this:<br>
<br>
<br>
Code:<br>
<br>
osg::Geode * geode1 = dynamic_cast<osg::Geode*> (nodePt.get());<br>
osg::Geometry * geom = dynamic_cast<osg::Geometry*>(geode1->getDrawable(0));<br>
osg::Vec4Array * clrary = dynamic_cast<osg::Vec4Array*>(geom->getColorArray());<br>
clrary->operator [] (10) = osg::Vec4(0.0, 1.0, 0.0, 1.0f);<br>
clrary->operator [] (6) = osg::Vec4(0.0, 1.0, 0.0, 1.0f);<br>
clrary->operator [] (2) = osg::Vec4(0.0, 1.0, 0.0, 1.0f);<br>
geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);<br>
<br>
<br>
<br>
<br>
It changed the colors! So it confuses me why it can't work in the pick function? Any body any idears?<br>
Any ideas and suggestions would be appreciated!<br>
<br>
<br>
Thank you!<br>
<br>
Cheers,<br>
Yexin<br>
<br>
------------------<br>
Read this topic online here:<br>
<a href="http://forum.openscenegraph.org/viewtopic.php?p=64994#64994" rel="noreferrer" target="_blank">http://forum.openscenegraph.org/viewtopic.php?p=64994#64994</a><br>
<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature">trajce nikolov nick<br></div>
</div>