Color an imported .OBJ?

Hello,



My question is simple :

I want to choose the color of an imported .OBJ file.

The file is imported without any problem and when I use the

model.setDefaultColor(ColorRGBA.randomColor());

the color doesn’t change it is still white.

I also tried to color it with the light :

lightState.setGlobalAmbient(ColorRGBA.pink);



No changes either.







Could you help me ?



Best regards,



rXp>!<

Try using a material state.

MaterialState ms = DisplaySystem.getDisplaySystem().getRenderer().createMaterialState();
ms.setDiffuse(ColorRGBA.randomColor());
ms.setAmbient(ColorRGBA.randomColor());
model.setRenderState(ms);
model.updateRenderState();



depending on the complexity of the model node, you may need to write a small recursive function to go through all of the spatials under the node:


private void applyColor(Spatial s){
     if(s instanceof Node){
          Iterator<Spatial> it = Node.getChildren().iterator();
          while(it.hasNext()){
               applyColor(it.next());
          }
     }
     else{
          s.setRenderState(ms);
     }
}


// Use it here:
applyColor(model);
model.updateRenderState();



That should do it..

Thank you that’s what I needed but is it “normal” that one face is black on one model and gray on the other ?



PS : I use 2 trimeshes

If you set all 3 color types (ambient, diffuse and specular) it should fix it.

It didn't, the gray/black side is still there.

:expressionless: