Color change makes box invisible

After making one texture of the scene reusable by appling a new material file containing a reference to the texture onto the appropriate mesh within the scene a strange sideeffect happens. Changing the color of some different box geometry makes the box invisible. Did anybody experience this problem before?

Here is the isolated test project for netbeans: Powerpfeil.zip

I think there should be no connection between the texture of the scene an the color of the box. The box gets visible (with and without color change) if the scene has no lights, does not use any materials or if it does not exist at all. Furthermore the box gets visible if I deactivate the color change loop.

it happened with me, when i was creating a tic tac toe game, but this happened cause the sky was obfuscating the color of the boxes.

If you have a material and change something about it and something completely different in the scene changes then without a doubt, they share something.

Either they are using the same material or the same instance of the ColorRGBA or something. This includes if you’ve done bad things like modify the color constants.

There is no other way for state to bleed. JME is extremely conservative in this area.

Why making assumptions when there is code available:
[java]
import com.jme3.app.SimpleApplication;
import com.jme3.asset.AssetManager;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;

/**

  • Demonstrates an invisible box.
    */
    public class Main extends SimpleApplication {

    /*

    • Change one or both of the variables to make the box visible!
      */
      private static final boolean loadScene = true;
      private static final boolean changeColor = true;

    //Material of the box for changing its color
    Material mat;
    float p = 0;

    public static void main(String[] args) {
    Main app = new Main();
    app.start();
    }

    @Override
    public void simpleInitApp() {
    /*
    * A simple scene which contains a light and uses one material.
    */
    if (loadScene) {
    Spatial scene = assetManager.loadModel(“Scenes/sceneWithMaterial.j3o”);
    scene.setLocalTranslation(0, -2, 0);
    rootNode.attachChild(scene);
    }

     /*        
      * BUG: The following box gets invisible during color change.
      * It happens only when there is a scene which uses a material.
      * If the scene would not use materials, then the box is visible!
      */
     Spatial greenBox = getBox(assetManager);
     rootNode.attachChild(greenBox);
    

    }

    @Override
    public void simpleUpdate(float tpf) {
    if (changeColor) {
    p += 1 * tpf;
    updateColor§;
    if (p > 1) {
    p = 0;
    }
    }
    }

    private void updateColor(float powerPercent) {
    if (mat != null) {
    mat.setColor(“Color”, new ColorRGBA(powerPercent, 1 - powerPercent, 0, 0));
    }
    }

    private Spatial getBox(AssetManager assetManager) {
    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry(“Box”, b);

     mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
     mat.setColor("Color", ColorRGBA.Green);
     geom.setMaterial(mat);
     return geom;
    

    }
    }
    [/java]

And here the material used within the scene:
[java]
Material MyMaterial : Common/MatDefs/Light/Lighting.j3md {
MaterialParameters {
DiffuseMap : Repeat Textures/moraf_floor/D.png
SpecularMap : Repeat Textures/moraf_floor/S.png
ParallaxHeight : 0.05
NormalMap : Repeat Textures/moraf_floor/N.png
Shininess : 1.0
}
AdditionalRenderState {
FaceCull Back
Wireframe Off
DepthWrite On
PolyOffset 0.0 0.0
AlphaTestFalloff 0.0
Blend Off
PointSprite Off
ColorWrite On
DepthTest On
}
}[/java]

Might have something to do with this:

[java]mat.setColor(“Color”, new ColorRGBA(powerPercent, 1 – powerPercent, 0, 0));[/java]

edit: oh wait, I might have misread

As wezrule said the problem lies in the color you use.

You are setting an alpha component that is fully transparent, which to the eye is invisible.
new ColorRGBA(powerPercent, 1 – powerPercent, 0, 0)

1 Like
<cite>@mathias4u said:</cite> Why making assumptions when there is code available:

Because you locked it away behind a bunch of clicks and I have better things to do than to jump through hoops to help you sort your problem. You can bet I won’t even bother in the future. Good luck.

<cite>@perfecticus said:</cite> As wezrule said the problem lies in the color you use.

You are setting an alpha component that is fully transparent, which to the eye is invisible.
new ColorRGBA(powerPercent, 1 – powerPercent, 0, 0)

That’s it. Thank you guys.

It totally makes sense why the box was invisible. But it also makes me wonder why the box has been visible before making the scene reference a material file…
That might be a topic for some jme enthusiasts :amused:

<cite>@mathias4u said:</cite> That's it. Thank you guys.

It totally makes sense why the box was invisible. But it also makes me wonder why the box has been visible before making the scene reference a material file…
That might be a topic for some jme enthusiasts :amused:

It didn’t. You are mistaken. If you set alpha to 0 it was not visible. If it was visible then you did not set alpha to 0.

[java]mat.setColor(“Color”, ColorRGBA.Green);
[/java]

ColorRGBA.Green had alpha 1.