Very simple question about Materials

Guys I am sorry in advance, this is probably a very simple question, but I couldn’t figure it out.

I import objects (of type .j3o) to my scene using assetManager.loadModel() which works great and my object materials look just perfect. The problem I am having is that sometimes I want to change the colors of these objects and whenever I use something like:

[java]
Material material = new Material(getAssetManager(), “Common/MatDefs/Misc/Unshaded.j3md”);
material.setColor(“Color”, AnimationColor.valueOf(colorName)
.getRGBAColor());
spatialToColor.setMaterial(material);
[/java]

where AnimationColor is an enum I wrote to convert the color name to RGBA (a very large library of colors).

So the issue is that the colors are correct however the material is not the same (not as shiny and something terribly missing) - which I am assuming is b/c I am using hte Unshaded material. So the question is , how can I use the material of the .j3o on the new color? to preserve the quality

again sorry I’m still in the process of learning jME

If you are using the lighting material… setColor(“Color”, whatever); shouldn’t do anything. You have Diffuse, Ambient, etc…applying the color with various alpha settings will probably achieve the effect you are looking for… i.e.:

ColorRGBA(1,0,0,0.45f) is going to blend a heck of a lot better than:
ColorRGBA(1,0,0,1);

1 Like

I tried playing around with the materials by ended up with different colors (hence my noobness in Jme)

I tried playing with the alpha variable using the UnShaded.j3md material and there was no difference at all, I also took ur approach and tried to use the following material:

[java]
Material material = new Material(getAssetManager(), “Common/MatDefs/Light/Lighting.j3md”);

        material.setColor("Diffuse", AnimationColor.valueOf(colorName).getRGBAColor());
        material.setColor("Specular", ColorRGBA.White);
        material.setColor("Ambient", AnimationColor.valueOf(colorName).getRGBAColor());
        material.setFloat("Shininess", 5f);   
        spatialToColor.setMaterial(material);

[/java]

and now the color change is wrong (getting grey instead of orange). what am I missing? :frowning:

@homsi said: I tried playing around with the materials by ended up with different colors (hence my noobness in Jme)

I tried playing with the alpha variable using the UnShaded.j3md material and there was no difference at all, I also took ur approach and tried to use the following material:

[java]
Material material = new Material(getAssetManager(), “Common/MatDefs/Light/Lighting.j3md”);

        material.setColor("Diffuse", AnimationColor.valueOf(colorName).getRGBAColor());
        material.setColor("Specular", ColorRGBA.White);
        material.setColor("Ambient", AnimationColor.valueOf(colorName).getRGBAColor());
        material.setFloat("Shininess", 5f);   
        spatialToColor.setMaterial(material);

[/java]

and now the color change is wrong (getting grey instead of orange). what am I missing? :frowning:

In my case (I use this same sort of technique…), I do it the following way:

  1. My diffuse image is greyscale
  2. I apply the color only to the material Color Diffuse when using lighting.
  3. Make sure you set the boolean UseMaterialColors
3 Likes

thanks!!! that did it!!! I forgot to add the UseMaterialColors.

Thank you!