[osg-users] different materials for a geometry and highlight

Trajce Nikolov NICK trajce.nikolov.nick at gmail.com
Wed Sep 21 06:07:54 PDT 2016


Hi Gianni,

the color for the selection is white in your code (at the beginning const
osg::Vec4 selectedColor(1.0f, 1.0f, 1.0f, 0.5f); ) and you have blending
ON, so all is working well as you coded it ..... If you want red selection,
turn off the blending and change the color ...

this is the snippet:

const osg::Vec4 selectedColor(1.0f, 0.0f, 0.0f, 0.5f);
const osg::Vec4 color1(1.0f, 0.0f, 0.0f, 1.0f);
const osg::Vec4 color2(0.0f, 1.0f, 0.0f, 1.0f);
const osg::Vec4 color3(0.0f, 0.0f, 1.0f, 1.0f);
const osg::Vec4 color4(1.0f, 0.0f, 1.0f, 1.0f);

class SelectModelHandler : public osgGA::GUIEventHandler
{
public:
    SelectModelHandler() : _selector(0), currentPrimitiveIndex(0) {}

    osg::Geode* createFaceSelector()
    {
        osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array(1);
        (*colors)[0] = selectedColor;

        _selector = new osg::Geometry;
        _selector->setDataVariance( osg::Object::DYNAMIC );
        _selector->setUseDisplayList( false );
        _selector->setUseVertexBufferObjects( true );
        _selector->setVertexArray( new osg::Vec3Array(3) );
        _selector->setColorArray( colors.get() );
        _selector->setColorBinding( osg::Geometry::BIND_OVERALL );
        _selector->addPrimitiveSet( new osg::DrawArrays(GL_TRIANGLES, 0, 3)
);

        osg::ref_ptr<osg::Geode> geode = new osg::Geode;
        geode->addDrawable( _selector.get() );
        geode->getOrCreateStateSet()->setMode( GL_LIGHTING,
osg::StateAttribute::OFF );
        //geode->getOrCreateStateSet()->setMode( GL_BLEND,
osg::StateAttribute::ON );
        //geode->getOrCreateStateSet()->setRenderingHint(
osg::StateSet::TRANSPARENT_BIN );

On Wed, Sep 21, 2016 at 1:39 PM, Gianni Ambrosio <g.ambrosio+osg at gmail.com>
wrote:

> Hi Nick,
> the problem I have is that I change the content of primitive sets but the
> color does not change in the 3D view.
>
> Regards,
> Gianni
>
> ------------------
> Read this topic online here:
> http://forum.openscenegraph.org/viewtopic.php?p=68681#68681
>
>
>
>
>
> _______________________________________________
> 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/20160921/9cc6d87c/attachment-0003.htm>


More information about the osg-users mailing list