Hi,
What is a proper way to replace a node in some loop and have the changes
immediately visible?
This code works:
Code:
void doWork(osg::ref_ptr<osg::Geode> geode, ...) //empty geode passed
{
loop
{
//make modifications
geode->removeDrawables(0, geode->getDrawableList().size());
osg::ref_ptr<osg::Geode> temp=qe2osg(*qe); //convert QuadEdge mesh into
osg geode
for (unsigned i=0; i<temp->getDrawableList().size(); i++)
geode->addDrawable(temp->getDrawable(i)); //besides polygons, we
can have normals
QApplication::processEvents(); //update window
}
}
This doesn't:
Code:
void doWork(osg::ref_ptr<osg::Group> container, ...) //empty group node passed
in
{
osg::Geode *geode=qe2osg(*qe); //initial value
vert->addChild(geode); //crashes if not empty
osg::Group* wireframe=new osg::Group;
vert->addChild(wireframe);
loop
{
//make modifications
osg::Geode *g2=qe2osg(*qe);
vert->replaceChild(geode,g2); //crashes
geode=g2;
vert->removeChild(wireframe);
wireframe=toWireframe(temp);
vert->addChild(wireframe); //crashes
QApplication::processEvents();
}
}
Copied from osgScribe and adjusted to my needs:
Code:
osg::ref_ptr<Group> toWireframe(osg::ref_ptr<Geode> geode)
{
osg::ref_ptr<Group> decorator = new osg::Group;
osg::ref_ptr<Geode> poly=new osg::Geode;
poly->addDrawable(geode->getDrawable(0));
decorator->addChild(poly);
osg::StateSet* stateset = new osg::StateSet;
osg::PolygonOffset* polyoffset = new osg::PolygonOffset;
polyoffset->setFactor(-1.0f);
polyoffset->setUnits(-1.0f);
osg::PolygonMode* polymode = new osg::PolygonMode;
polymode->setMode(osg::PolygonMode::FRONT_AND_BACK,osg::PolygonMode::LINE);
stateset->setAttributeAndModes(polyoffset,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
stateset->setAttributeAndModes(polymode,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
osg::Material* material = new osg::Material;
stateset->setAttributeAndModes(material,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
stateset->setTextureMode(0,GL_TEXTURE_2D,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
decorator->setStateSet(stateset);
return decorator;
}
What I want to do is add wireframe to my object. And now I have a feeling I was
doing this wrong (even though it worked).
Thank you!
Cheers,
Dženan
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=31635#31635
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org