DirectButton and materials

I’m attempting to create a button that uses custom geometry (via the “geom” keyword parameter), and want to use materials to colour that geometry ( in this case I’d rather not use a texture and found vertex colours a bit of a nuisance to work with). However, I’m hitting the problem that materials don’t show up without a light–and unfortunately, it seems that lighting doesn’t work as I’d expect–and in particular doesn’t cause materials to become visible–when applied to a DirectButton that is parented to one of the 2D scene-graph roots (render2d, aspect2d or pixel2d).

Lights do seem to have some effect, but (when using a DirectionalLight), only seem to result in the button showing entirely as one or another shade of grey, depending on the angle at which the light is set.

A little experimentation indicates that a DIrectButton that is parented to render does show its materials as expected when a light is applied to it; it only fails when parented to one of the 2D scene-graph roots, it seems.

Is there a way to get materials to show up in one of the 2D scene graphs?

You don’t need a light to use colours. You can either use ColorAttrib or ColorScaleAttrib to apply a flat colour without needing to use materials.

True, but materials allow me to apply two or more colours to various parts of the button geometry, rather than covering the entire button with a single colour.

(In my case, I have a single model with two materials, each providing a different colour. I could use vertex-painting, but ended up concluding that changing a colour (for the various button states) was too great a nuisance done that way.)

bump Any further suggestions? Is there no way to have material colours be visible in the 2D branches of the scene graph?

If you have two separate MaterialAttribs, then you can have two separate ColorAttribs as well. They are applied using the same mechanism; there is nothing about materials that makes them more flexible in application than flat colours.

If your model has two materials, that means that the geometry with the materials has to be separated into at least two Geoms, and you should equally be able to apply one colour to one and another colour to the other.

Ahh, thank you–I feel silly for not having thought of using separate geoms. ^^;

What I ended up doing was dropping the materials and simply exporting my button as two geoms in a single egg-file, then colouring the geoms separately in code.

Just to add a bit of clarity: if two parts of the model were using two separate materials, they must have already been loaded as two separate geoms. There is no other way to apply two materials to the same model.

Indeed, I gathered as much, I believe; your pointing that out, however, prompted me to realise that I could simply explicitly separate my button model into two geoms and then colour those appropriately in code, thus getting around the problem of making the materials visible in the 2D branches of the scene graph.