Hello,

I am trying out some things by creating scene graphs on the fly, and one thing
seems weird in my opinion.

Say I have a ShapeDrawable (with a sphere Shape) attached to a Geode, which is a
child of a Transform. I can call setColor() on the ShapeDrawable to make the
sphere red. That works fine. But I would think that adding a Material with a
diffuse color of red in the stateSet for either the geode or the transform
would have the same effect. But it doesn't seem to.

In other words:

    // The sphere
    osg::ref_ptr<osg::Shape> sphere = new osg::Sphere(osg::Vec3f(0.0, 0.0, 0.0),
1.0);
    osg::ref_ptr<osg::ShapeDrawable> sphereDrawable = new
osg::ShapeDrawable(sphere.get());
    osg::ref_ptr<osg::Geode> sphereGeode = new osg::Geode;
    sphereGeode->addDrawable(sphereDrawable.get());

    // Its transform
    osg::ref_ptr<osg::PositionAttitudeTransform> sphereTransform = new
osg::PositionAttitudeTransform;
    sphereTransform->setPosition(osg::Vec3d(0.0, 0.5, 0.0));
    sphereTransform->addChild(sphereGeode.get());


    // Now try to make the sphere red.
    // This works
    //sphereDrawable->setColor(osg::Vec4f(1, 0, 0, 1));

    // Try it with a Material
    osg::ref_ptr<osg::Material> material = new osg::Material;
    material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4f(1, 0, 0, 1));

    // This does not work
    //sphereTransform->getOrCreateStateSet()->setAttribute(material.get());

    // This does not work either
    //sphereDrawable->getOrCreateStateSet()->setAttribute(material.get());

In all cases except setting the color on the drawable directly, the sphere stays
white (default color I guess).

I tried to pass either osg::StateAttribute::ON or osg::StateAttribute::OVERRIDE
as the second argument to setAttribute(), which changed nothing. Am I missing
something? Is this intended?

I guess I could just fire up some 3D authoring tool, make a unit sphere, load it
into the subgraph under the transform and then I would not use the ShapeDrawable
and that might work, but I would expect the ShapeDrawable to inherit the state
of the geode it's attached to...

Thanks,

J-S
--
______________________________________________________
Jean-Sebastien Guay     [EMAIL PROTECTED]
                        http://whitestar02.webhop.org/
_______________________________________________
osg-users mailing list
[email protected]
http://openscenegraph.net/mailman/listinfo/osg-users
http://www.openscenegraph.org/

Reply via email to