Paul Melis wrote:
Stephan Huber wrote:
Mao.. schrieb:
Thank you very much, Rafa Gaitan!

Your suggestion works. But I'm wondering one thing: all of the models have passed the more or less same preproccessor, however, some models without the
renderbin affairs will not "hide" but turn blue as I expected. The only
difference between these two is the renderbin. I'm a little confused.

This is because Renderbin 10 enables GL_BLEND automatically, so the
alpha-value of your material applies to the models. Without enabling
GL_BLEND, the alpha-value is ignored by OpenGL.
I don't think blending is enabled automatically for bin 10.
There does seem to be something fishy with overriding materials though.

Try the attached file. It loads the standard dumptruck.osg model, which consists of
Group -> Geode -> 3 * Geometry

The first Geometry declares a StateSet (StateSet_1), which the other 2 re-use ("Use StateSet_1").

But when you set a material override on the Group's stateset not all of the model uses that material. It feels like only the Geometry to which the stateset is attached listens to the override (although I would need to check that).

Secondly, I'm surprised that the override settings are not saved when writing the model back to a .osg file.

This is with 2.6 and without explicitly running osgUtil::Optimizer.

Regards,
Paul

#include <osg/Material>
#include <osg/StateSet>
#include <osgDB/ReadFile>
#include <osgDB/WriteFile>
#include <osgViewer/Viewer>

int main()
{
    osg::ref_ptr<osg::Node>     model;

    model = osgDB::readNodeFile("dumptruck.osg");

    osg::ref_ptr<osg::Material> mat;
    mat = new osg::Material();
    mat->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
    mat->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0, 0.99, 0.9, 0));

    osg::StateSet *ss = model->getOrCreateStateSet();
    ss->setAttributeAndModes(mat.get(), osg::StateAttribute::ON|osg::StateAttribute::OVERRIDE);

    osgDB::writeNodeFile(*(model.get()), "mat.osg");

    osgViewer::Viewer   viewer;

    viewer.setSceneData(model.get());
    viewer.run();
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to