[osg-users] How to realize "highlight the picked premitiveSets and remove highlighs when got repicked"?

Yexin Wang xxtop716 at 163.com
Thu Sep 10 23:41:34 PDT 2015


Hi,

Guys, I 'm using polyIntersection to pick out points from several thousands of  points with their color and locations. I read the points and keep them in a node like this:

/////////
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry();
geom->setVertexArray(v.get());  // v is location array
geom->setColorArray(clr.get());  // clr is color array
geom->addPrimitiveSet(new  osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, v->size()));
osg::Geode* geode = new osg::Geode;
geode->addDrawable(geom.get());
/////////

What I want to do is draw a rectangle, highlight the points that I've chosen. And if repick part of the highlighted points, remove their highlighted color and show their original colors. 

I tried Specularhighlights method, which is to define a Specularhilights node and add my points node as its child, like the following code. But this way it change ALL the point's color in the node.
//////////
osgFX::SpecularHighlights* scribe = new osgFX::SpecularHighlights();
scribe->addChild(geode);     //geode is the original points node
parent->replaceChild(node, scribe);   //parent is scene root
scribe->setSpecularColor(osg::Vec4(0.0, 1.0, 0.0, 1.0f));  //this will change All the points' color
////////// 

And I found out that  the intersections I got from polyIntersection actually have the prrmitiveSet index. So I'm able to trace the node and change the selected points. But the problem is, if I do so, the original color would be overwritten, when I repick, I can not get the original color. 


Is there a way to do this, just like SpecularHighlights, but only change the premitiveSets in the node that I picked, and be able to get the original colors if got repicked?
... 

Thank you!

Cheers,
Yexin :D

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








More information about the osg-users mailing list