[SOLVED] Lighting Issues or wrong understanding?

Hi,

basicaly I have the box from blender exported as “Example.obj”.
I am loading it to my scene like that

Model = AssetManager.loadModel("\\Modelle\\Menus\\Example.obj");
mat_default = new Material( AssetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat_default.setColor("Color", ColorRGBA.Green);
mat_default.setBoolean("VertexColor",false);
Model.setMaterial(mat_default);
rootNode.attachChild(Model);
Model.setLocalTranslation(0,0,-50);

That works fine and is showing me my green box. Anyhow I read into Material Definition Properties :: jMonkeyEngine Docs about Light and shadow and tutorials etc.

I understand that by the code above I can show my box without additional light source. But I like to use a light source to have the ability to use the effects that come with it.

I tried

Model2 = Assetmanager.loadModel("Example.obj");
Material mat_default2 = new Material( AssetManager, "Common/MatDefs/Light/Lighting.j3md");
mat_default2.setBoolean("UseMaterialColors",true);
mat_default2.setColor("Diffuse", ColorRGBA.Blue);
Model2.setMaterial(mat_default2);
rootNode.attachChild(Model2);
Model2.setLocalTranslation(0,0,-50);
AmbientLight al = new AmbientLight();
rootNode.addLight(al);

But nothing is displayed. Also adding

mat_default2.setColor("Specular",ColorRGBA.White); 
mat_default2.setFloat("Shininess", 64f); 

or adding a directional light dont make a difference.

When I load a “ready to use” model I always have to add the light before I can see it. The wiki says: Add UV Mapping in blender.

Anyhow: What I want is:

Change the color of my model during runtime and have the abillity to use spotlight (with light radius) or even shadow etc.
Currently I can achieve changing color by using the Unshaded.j3md Material and update that material during runtime.
I realy have no experience either with Blender nor with materials/ material definition.
So my question is:
What is the way to load an simple model from blender, being able to change its color while JME is running and how make the visibility depend on added light sources.

Hm, thats a bit odd. Do you see this behaviour with just a coloured cube or only with your model exported from blender?

Could we see a full minimal application that shows the problem?

We don’t see that code. So to everyone reading this code we will immediately think “Of course it won’t work without a directional light.”

So you need to post the code that has the best chance of working… the code that includes the directional light.

Or as richtea says, a minimal FULL example that we can run that might illustrate the problem.

As it is, my answer is: you didn’t setup the directional light correctly.

Thanks for the advice.
I redid the code step by step.
I got one example with DirectionalLight working.
If you could have another look ?

  1. Working example with unshaded material. (I use an Appstate, the following is called from onEnable())
        AssetManager lAss = getApplication().getAssetManager();
        Model = lAss.loadModel("\\Modelle\\Menus\\Example.obj");
        mat_default = new Material( lAss, "Common/MatDefs/Misc/Unshaded.j3md");    
        mat_default.setColor("Color", ColorRGBA.Green);
        mat_default.setBoolean("VertexColor",false);
        Model.setMaterial(mat_default);
        lrootNode.attachChild(Model);
        Model.setLocalTranslation(0,0,-50);
        Model.scale(2f);
  1. with AmbientLight → nothing visible
    Spatial Model2 = lAss.loadModel("\\Modelle\\Menus\\Example.obj");
        Material mat_default2 = new Material( lAss, "Common/MatDefs/Light/Lighting.j3md");
        mat_default2.setBoolean("UseMaterialColors",true);
        mat_default2.setColor("Diffuse", ColorRGBA.Blue);
        Model2.setMaterial(mat_default2);
        lrootNode.attachChild(Model2);
        Model2.setLocalTranslation(0,0,-50);
        Model2.scale(2f);
        AmbientLight al = new AmbientLight();
        lrootNode.addLight(al);
  1. With DirectionalLight → working
        Spatial Model2 = lAss.loadModel("\\Modelle\\Menus\\Example.obj");
        Material mat_default2 = new Material( lAss, "Common/MatDefs/Light/Lighting.j3md");
        mat_default2.setBoolean("UseMaterialColors",true);
        mat_default2.setColor("Diffuse", ColorRGBA.Blue);
        Model2.setMaterial(mat_default2);
        lrootNode.attachChild(Model2);
        Model2.setLocalTranslation(0,0,-50);
        Model2.scale(2f);
        DirectionalLight sun = new DirectionalLight();
        sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
        sun.setColor(ColorRGBA.White);
        lrootNode.addLight(sun);

I dont see a thing if I change the color of the Directionallight to yellow. But I see it with a blue Directionallight .
Any idea why some color combinations of Directionallight and color of material dont work ?

If you use a color that only has blue color components then I think it will behave weirdly with light. There is no aspect that would reflect red or green light so only blue light (or white light) will affect it.

…kind of true in real life, also.

Use a gray color for your diffuse and you should see all light colors.

2 Likes

May I add this advice, that hardcoded relative path won’t end well when running the application on Unix-based operating systems, make sure to refactor this to the Unix ‘/’ relative path from your asset.jar and it will work on all operating systems.

1 Like

I am using

private final String root = System.getProperty("user.dir") + "/Assets";
getApplication().getAssetManager().registerLocator(root.replace('/', (char) File.separatorChar), FileLocator.class);`

in my config AppState. And will probably do similiar at this place. Hoping that will do the trick and avoid future problems.

I will now play a bit around with Light and Colors etc. then I try to put together the stuff I invented during last years but my progress in general is slow. Not sure if I will ever achieve anything.

If so it will come to the WIP article and is basing on a lot of forum suggestions and help.

For now I would say the issue is solved, probably I either choose a wrong Light Color or I did not even set a color at all.

1 Like