I can't create two materials without them interfering with each other

I am trying to make a floor, and a base on top of it. I create the geometries like this.

[java]Box bFloor = new Box(33, 1, 33);
Geometry floor = new Geometry(“Box”, bFloor);
floor.setLocalTranslation(0, -5, 0);
Material orange = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
orange.setColor(“Color”, ColorRGBA.Orange);
floor.setMaterial(orange);

    Box bBase = new Box(3, 3, 2);
    Geometry base = new Geometry("Box", bBase);
    floor.setLocalTranslation(0, -5, 0);
    Material yellow = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    yellow.setColor("Color", ColorRGBA.Yellow);
    floor.setMaterial(yellow);[/java] 

I’m super n00b. The material yellow is seems to changes the Material orange’s color to yellow as well, so everything is yellow. I want the floor to be orange, and the base to be yellow.

By the way, is it normal to have such n00bish problems for a newbie?

Ummm, if you want the base to be a different color, you should probably give it a material :wink:

Your code:
[java]Box bBase = new Box(3, 3, 2);
Geometry base = new Geometry(“Box”, bBase);
floor.setLocalTranslation(0, -5, 0);
Material yellow = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
yellow.setColor(“Color”, ColorRGBA.Yellow);
floor.setMaterial(yellow);[/java]

New code:
[java]Box bBase = new Box(3, 3, 2);
Geometry base = new Geometry(“Box”, bBase);
floor.setLocalTranslation(0, -5, 0);
Material yellow = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
yellow.setColor(“Color”, ColorRGBA.Yellow);
base.setMaterial(yellow);[/java]

You were setting the floor’s material as yellow instead of base’s… Just gotta read your code deeper.

@nomnom said: Ummm, if you want the base to be a different color, you should probably give it a material ;)

Your code:
[java]Box bBase = new Box(3, 3, 2);
Geometry base = new Geometry(“Box”, bBase);
floor.setLocalTranslation(0, -5, 0);
Material yellow = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
yellow.setColor(“Color”, ColorRGBA.Yellow);
floor.setMaterial(yellow);[/java]

New code:
[java]Box bBase = new Box(3, 3, 2);
Geometry base = new Geometry(“Box”, bBase);
floor.setLocalTranslation(0, -5, 0);
Material yellow = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”);
yellow.setColor(“Color”, ColorRGBA.Yellow);
base.setMaterial(yellow);[/java]

You were setting the floor’s material as yellow instead of base’s… Just gotta read your code deeper.

Man, thanks bro. Do you have any tips to avoid such stupidity?

@coolman50544 said: Man, thanks bro. Do you have any tips to avoid such stupidity?

I think the biggest thing to remember is that a Node can contain multiple geometries and you can apply a material to the Node, which in turn, effects all child Geometry’s Materials. So, you can either:

  1. Nest Nodes containing a single Geometry and apply Materials to the individual Nodes within.
  2. Apply Materials to the individual Geometries themselves.
  3. A combination of the above (or whatever best suites your purposes).

Just keep in mind that applying a Material will have a cascading effect to the contained children. The same thing will apply to transforms… you apply a rotation (for instance) to the parent and this will effect child Node’s/Geometry’s world transform, etc.

1 Like