[osg-users] Get all vertices of an OSG Group

David Knipp David.Knipp at gmx.net
Thu Mar 31 13:31:26 PDT 2016


Hi Bemt,

i think you got something wrong in the beginning. There are 3 possible ways to apply a color to a vertex:

- Material: 
  Materials define how the surface is interacting with lights. 
  Most times you are only intereseted in diffuse value.

osg::Material * mat = dynamic_cast<osg::Material*>(geometry)->getOrCreateStateSet()->getAttribute(osg::StateAttribute::MATERIAL));
mat->getDiffuse(osg::Material::Face::FRONT_AND_BACK));

- ColorArray:
  A simple color value that is just applied to a vertex

ptrOSGNode->getColorArray()

- Texture:
  An image applied on the surface:

osg::Texture2D * texture = dynamic_cast<osg::Texture2D*>(geometry)->getOrCreateStateSet()->getTextureAttribute(0, osg::StateAttribute::TEXTURE));

All these are DIFFERENT ways to apply a color to a vertex. You should have said in the beginning that you apply a texture to all vertices. : )

Your answer should be for one position:

i : index of current vertex

osg::Vec2Array * texCoords = dynamic_cast<osg::Vec2Array *>(geometry->getTexCoordArray(0)); 
osg::Vec4 color = texture->getImage()->getColor(texCoords->operator[](i));

Cheers,
NoxxKn

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








More information about the osg-users mailing list