Hello
This is my problem :
I load a *.3ds file (an aircraft). I don't have the software 3dsMax so I don't
know how it was created...
>From that file, I do bascially :
osg::ref_ptr<osg::Node> Model;
osg::ref_ptr<osg::Group> Root;
Model = osgDB::readNodeFile("name of the file.3ds");
Root = new osg::Group;
Root->addChild(Model.get());
I add other stuff in mRoot... (3 osg::ShapeDrawable like cylinders and 3 like
cones, to simulate 3 axis X Y Z ; a osgText::Text to write some info) In short,
nothing extraordinary !
I have a pick function. When I move the mouse, I check if the cursor intersects
with a part of the aircraft.
I used the examples of OSG :
osgUtil::LineSegmentIntersector::Intersections intersections;
osg::ref_ptr<osg::Drawable> HitDrawable;
osg::Geometry * HitGeometry;
CString strName;
CString strNameParent;
if (m_pViewer->computeIntersections(x, y, intersections))
{
// I keep only the 1st intersection :
osgUtil::LineSegmentIntersector::Intersections::iterator hitr =
intersections.begin();
HitDrawable = hitr->drawable;
HitGeometry = HitDrawable->asGeometry();
strName = CString(hitr->drawable->getName().c_str());
strNameParent = CString(hitr->drawable->getParent(0)->getName().c_str());
// After that I put the drawable in a transparent state :
float transparency = 0.3;
osg::StateSet * stateset = HitDrawable->getOrCreateStateSet();
osg::Material * mm =
dynamic_cast<osg::Material*>(stateset->getAttribute(osg::StateAttribute::MATERIAL));
if (!mm)
mm = new osg::Material;
mm->setAlpha(osg::Material::FRONT, transparency);
stateset->setAttributeAndModes( mm, osg::StateAttribute::OVERRIDE |
osg::StateAttribute::ON);
stateset->setMode(GL_BLEND, osg::StateAttribute::OVERRIDE |
osg::StateAttribute::ON );
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE |
osg::StateAttribute::ON );
stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN);
}
This is Okay, I see a part of the aircraft that becomes transparent, when the
mouse cursor goes in front of it.
What I would want to do, afterwards, is that if the cursor leaves that part of
the aircraft, the rendering comes back to the initial state (not transparent).
But I don 't know how to do... the main question behind my post (sorry for
being so long !) is that I don't understand why the intersector accesses to a
drawable, while the aircraft comes from a Node File.
I believed that drawables were linked to Geode class ?!
When I ask for the strings strName and strNameParent with the functions :
strName = CString(hitr->drawable->getName().c_str());
strNameParent = CString(hitr->drawable->getParent(0)->getName().c_str());
I see "" in strName
and "Tail" or "Wing" or "Rotor"... in strNameParent, depending on where the
cursor is. Logic.
So the intersector reads someting that comes from the node file.
But is this a drawable ??
In the beginning of the appli, can I have the list of all drawables, those
sub-parts of the aircraft model ("tail", "wing" ...) and put a osg::StateSet on
each of them ?
If I could, I would activate/desactivate transparency possibilities as I want.
For the moment, if I have access to a drawable (via the hitr->drawable), I
don't have access to others, so when a drawable becomes transparent, it will
always be. I can't manipulate several drawables in the same time.
I hope I was clear. I've just started working with OSG. It is fascinating but
not easy !
As all information are in the .3ds file, I don't know if can manipulate
something with OSG.
Thanks in advance.
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=29994#29994
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org