[osg-users] Changing the color of a model

Trajce Nikolov NICK trajce.nikolov.nick at gmail.com
Thu Oct 8 06:50:17 PDT 2015


Hi,

maybe you try

myNode->getOrCreateStateSet()->setAttributeAndModes(mat,
osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);

On Thu, Oct 8, 2015 at 3:32 PM, Andre Sanchez <aurumknight.ak at gmail.com>
wrote:

> 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
>
>
>
>
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>



-- 
trajce nikolov nick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20151008/c4d312c2/attachment-0002.htm>


More information about the osg-users mailing list