[osg-users] Changing the color of a model
Andre Sanchez
aurumknight.ak at gmail.com
Thu Oct 8 06:32:01 PDT 2015
Hi OpenSceneGraph forum!
I'm very new to OSG, and while I'm very familiar with programming, and somewhat familiar with 3D graphics, I am now devoting actual time working in a lab to properly learn C++, and OSG as well.
My issue is as follows:
I am loading an existing model as a Node, and I want to be able to change the color of the model in real time. How should I go about doing this?
I know how attach an update callback to the Node, but it's the color that I can't seem to change. I am able to set the diffuse color on a primitive object using a material like so:
Code:
osg::ref_ptr<osg::Material> mat = new osg::Material;
mat->setDiffuse (osg::Material::FRONT_AND_BACK, osg::Vec4(0.8, 0.1, 0.4, 1.0));
myNode->getOrCreateStateSet()->setAttributeAndModes(mat, osg::StateAttribute::ON);
but this doesn't seem to work on the model.
I found that if I changed the model's .osg file to not define material colors on particular components of the model, then this color I defined for the model would affect those parts. However I feel there should be a better way to do this, as I will probably end up using models that actually need these colors within their respective .osg files. I know I can probably do this with a shader, and if that's necessary then fine, but if there's an easier way then that would be great.
So essentially my question is:
What is the easiest way to change the overall diffuse color of an object?
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=65321#65321
More information about the osg-users
mailing list