0
votes

I have a rather large mesh, (which I load with osgDB). It also has several sub-meshes.

I am trying to set the emission lighting. However I can see (suspect) that only the 1st sub-mesh is lit up. How is it possible to light up all the sub-meshes. I am not using lighting to lit up the scene.

What is the recommended approach?

int main()
{
    osg::Node * cytBuilding = osgDB::readNodeFile( OBJ_FILE );


    osg::Group * root = new osg::Group();
    osg::PositionAttitudeTransform * scenePAT = new osg::PositionAttitudeTransform();
    root->addChild(scenePAT);
    scenePAT->addChild( cytBuilding );




    //material
    osg::Material* material = new osg::Material();
    material->setAmbient(osg::Material::FRONT, osg::Vec4(1.0,1.0f,1.0f,1.0f));
    material->setDiffuse(osg::Material::FRONT, osg::Vec4(1.0,1.0f,1.0f,1.0f));
    material->setSpecular(osg::Material::FRONT, osg::Vec4(0.0,0.0f,0.0f,1.0f));
    material->setEmission(osg::Material::FRONT, osg::Vec4(1.0,1.0f,1.0f,1.0f));
    osg::StateSet* stateset = new osg::StateSet();
    stateset->setAttributeAndModes(material,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
    root->setStateSet(stateset);


    // viewer
    osgViewer::Viewer viewer;

    viewer.setSceneData( root );
    viewer.realize();
    return viewer.run();

As I read the mesh (osgDB::readNodeFile()), it display following error messages

*** line not handled *** :map_bump
*** line not handled *** :bump
*** line not handled *** :map_opacity
*** line not handled *** :map_d
*** line not handled *** :refl
*** line not handled *** :map_kS
*** line not handled *** :map_Ns

Resulting display was: enter image description here

Same mesh when I display with meshlab, I see enter image description here

1

1 Answers

0
votes

This largely depends on how the StateSets within the model are organized. Could you try to enforce lighting on your root node?

stateset->setMode( GL_LIGHTING, osg::StateAttribute::OVERRIDE | osg::StateAttribute::ON );

You could also try to implement a small visitor to dump all Materials and StateSets within the model to see how they are assigned, maybe its overridden per node with a OVERRIDE|PROTECTED flag. Just for testing, did you try to apply your Material to all Geodes or Geometries within the model?