[osg-users] Update node color on demand

Diego Mancilla dmancillac at gmail.com
Mon Nov 26 07:55:53 PST 2018


Hello,

I have tried Eran's suggestion with no success. I have successfully created the handler, and it gets called but no color change...

My current code:

On main:

Code:
_lines = osgDB::readNodeFile("lines.dxf");
_topo->setDataVariance(osg::Object::DYNAMIC);
osg::Geode* geode = new osg::Geode;

_mViewer->addEventHandler(new ColorHandler);

ColorVisitor newColor;
newColor.setColor( 1.0f, 0.0f, 0.0f );
_lines->accept(newColor);
geode->addChild(_lines);
_mViewer->realize();




The handler:


Code:
bool ColorHandler::handle(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa)
{
	if (ea.getEventType() == ea.USER)
	{
		auto changeColorEvent = dynamic_cast<const ChangeColorEvent*>(ea.getUserData());
		if (changeColorEvent != nullptr)
		{
			std::cout << "Hola Handler!!!" << std::endl;
			std::cout << "new color: " << changeColorEvent->r<<" "<< changeColorEvent->g<< " "<< changeColorEvent->b<<std::endl;
			ColorVisitor newColor;
			newColor.setColor(changeColorEvent->r, changeColorEvent->g, changeColorEvent->b);
			changeColorEvent->node->accept(newColor);
			return true;
		}
	}
	return false;



Thank you!

Cheers,
Diego

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







More information about the osg-users mailing list