Lighting on Blender-Imported Object

After struggling with Blender for a while, I have finally gotten objects in Blender with textures to import into JMP by first exporting them into .obj files and then converting them to .j3o.



When I “Edit in SceneComposer” on the .j3o file, I can see the object lit (if I click the Lightbulb icon) and with the textures as desired. So I assume that I would need to add a light to my scene in order to see the object. However, with a directional light added in JME3, the object appears in black, with no lighting and no textures. If I remove the directional light, I don’t see the object at all.



I noticed that if added a Directional Light in the SceneComposer, the object would become brighter in the preview window and would show properly in JME3. However, I plan on having many other objects and would like to control the lighting directly from JME3.



Is there any way to get the object showing properly with lighting using JME3 code and not using SceneComposer (I believe the file itself is modified to add the lighting)? I tried doing object.addLight(light) and that didn’t work either.

WumpaFruit said:
bla bla bla...........
.............
...................
I tried doing object.addLight(light) and that didn't work either.

Basically what the SceneComposer does when adding a DirectionalLight to the scene is :
[java]
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-1, 1, -1));
rootNode.addLight(dl);
[/java]
or something like this. Instead "-1, 1, -1" you can copy the directional light's direction in the SceneComposer you added as you said.

You have to set the direction of the light, if its zero I am pretty sure the light won’t do anything

glaucomardano said:
Basically what the SceneComposer does when adding a DirectionalLight to the scene is :
[java]
DirectionalLight dl = new DirectionalLight();
dl.setDirection(new Vector3f(-1, 1, -1));
rootNode.addLight(dl);
[/java]
or something like this. Instead "-1, 1, -1" you can copy the directional light's direction in the SceneComposer you added as you said.


Thank you! A direction of (-1, 1, -1) worked, but when I tried (0, -1, 0) to simulate light coming straight down the y-axis, I saw nothing. I positioned the camera to look straight down onto the object, expecting to see the top of the object, but the whole thing was black. Why doesn't (0, -1, 0) work?

Is needed having a good sense of direction for directional light positioning if you are doing it directly in source code. I strongly recommend you to test the directions in SceneComposer for having a nice sense of directions so you can be able to do it directly in source code. But I have a question, why don’t you create the directional light in SceneComposer and set its direction very easily? Just save the scene and load it in source code.

glaucomardano said:
But I have a question, why don't you create the directional light in SceneComposer and set its direction very easily? Just save the scene and load it in source code.


I want to have the light change direction over time to simulate the sun, and that would be easiest to do with code. I'm not sure how I can do that using SceneComposer. Also, how can I change the direction in SceneComposer? I try to select the directional light, and under Properties it says "". I am running jMP Alpha-4 with nightly updates.

A scene you load is no different than a scene you construct programmatically, you can still access and change anything from the code:

[snippet id=“13”]

@WumpaFruit:

WumpaFruit said:

I try to select the directional light, and under Properties it says “”.



Make sure you are typing the direction property right :
[java]
[ 0, -1, 0 ]
[/java]
and after that press enter.
Anyways, did you try set the direction programatically to [ 0, -2, 0 ] instead [ 0, -1, 0 ]? ( 2 or 3 or 4.... ).
normen said:
A scene you load is no different than a scene you construct programmatically, you can still access and change anything from the code:
[snippet id="13"]


I didn't know you could load a scene as a Node, thank you. That will make things much easier since I'll eventually have more than one object in the file and I can access them all easily. I'm still not sure how to change lights though, since all I can do are addLight() and removeLight().

glaucomardano said:
@WumpaFruit:

Make sure you are typing the direction property right :
[java]
[ 0, -1, 0 ]
[/java]
and after that press enter.
Anyways, did you try set the direction programatically to [ 0, -2, 0 ] instead [ 0, -1, 0 ]? ( 2 or 3 or 4.... ).


Funny thing is I tried normen's code and my scene was black at the top with a direction of (-1, 1, -1), but when I changed the direction to (0, -1, 0), the top was lit as desired. I am not sure why (-1, 1, -1) lit the top before and wouldn't now with normen's code.
WumpaFruit said:
Funny thing is I tried normen's code and my scene was black at the top with a direction of (-1, 1, -1), but when I changed the direction to (0, -1, 0), the top was lit as desired. I am not sure why (-1, 1, -1) lit the top before and wouldn't now with normen's code.


It depends of your model's local translation. You know (-1, 1, -1) is (x, y, z) ok :D?
glaucomardano said:
It depends of your model's local translation. You know (-1, 1, -1) is (x, y, z) ok :D?


I do know that, but for some reason it didn't work before. Now it works, so I don't know what I did. But thank you for your help, I'll mess around with the lighting some more and will post if I need any more help.