Hi, can you try geom->dirtyDisplayLists() after changing the color?
Nick On Wed, Sep 2, 2015 at 12:27 PM, Yexin W <xxtop...@163.com> wrote: > Hi, > > 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. > The loading points process is as follows: > > > Code: > > osg::ref_ptr<osg::Geometry> geom = new osg::Geometry(); > osg::ref_ptr<osg::Vec3Array> v = new osg::Vec3Array; > osg::ref_ptr<osg::Vec4Array> clr = new osg::Vec4Array; > v->push_back(osg::Vec3(0.0, 0.0, 0.0)); > ... // 10 points in total > clr->push_back(osg::Vec4(1.0, 0.0, 1.0, 1.0f)); > ...// set the color > geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, > v->size())); > // after set the color and normal, add the geometry to Geode node > geode->addDrawable(geom.get()); > > > > > > 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: > > > Code: > > if (picker->containsIntersections()) > { > osgUtil::PolytopeIntersector::Intersections intersections = > picker->getIntersections(); > osgUtil::PolytopeIntersector::Intersections::iterator iter; > for (iter = intersections.begin(); iter != intersections.end(); iter++) > { > osg::NodePath nodepath = (*iter).nodePath; > node = (nodepath.size() >= 1) ? nodepath[nodepath.size() - 1] : 0; > int pointIndex = (*iter).primitiveIndex; > osg::Geode * geode = dynamic_cast<osg::Geode*> (node); > osg::Geometry * geom = dynamic_cast<osg::Geometry*>(geode->getDrawable(0)); > osg::Vec4Array * clrary = > dynamic_cast<osg::Vec4Array*>(geom->getColorArray()); > clrary->operator [] (pointIndex) = osg::Vec4(0.0, 1.0, 0.0, 1.0f); > geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX); > node->addUpdateCallback(new CessnaCallback()); // not helpful > viewer->updateTraversal(); //not helpful > //viewer->run();//not helpful > } > } > > > > > > First, I thought may be the colors have not been changed, so I tested > changing several points' color in the main function, like this: > > > Code: > > osg::Geode * geode1 = dynamic_cast<osg::Geode*> (nodePt.get()); > osg::Geometry * geom = > dynamic_cast<osg::Geometry*>(geode1->getDrawable(0)); > osg::Vec4Array * clrary = > dynamic_cast<osg::Vec4Array*>(geom->getColorArray()); > clrary->operator [] (10) = osg::Vec4(0.0, 1.0, 0.0, 1.0f); > clrary->operator [] (6) = osg::Vec4(0.0, 1.0, 0.0, 1.0f); > clrary->operator [] (2) = osg::Vec4(0.0, 1.0, 0.0, 1.0f); > geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX); > > > > > It changed the colors! So it confuses me why it can't work in the pick > function? Any body any idears? > Any ideas and suggestions would be appreciated! > > > Thank you! > > Cheers, > Yexin > > ------------------ > Read this topic online here: > http://forum.openscenegraph.org/viewtopic.php?p=64994#64994 > > > > > > _______________________________________________ > osg-users mailing list > osg-users@lists.openscenegraph.org > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > -- trajce nikolov nick
_______________________________________________ osg-users mailing list osg-users@lists.openscenegraph.org http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org