[SOLVED] Model imported from Blender is darker than others


forgive me if this post has errors, but the editor is half a line big. (with chrome and firefox on ubuntu linux)

We imported multiple Blender models via jMonkey Platform (from .blend to .j3o)
Some models though, are darker than the others.
The ambient lighting setting and all texture/materials settings are the same in blender (we compared them all twice)

The male head model is light and the body is dark. (transparent hands are not the problem, it’s a forgotten checkbox)
We cannot find any difference between the objects in the .blend files and don’t know what is different between them.
In the jMonkeyPlatform Model Preview (.j3o) it is lighted correctly. In the game scene it is much too dark.
We use the same import code for all body parts. (male and female)

Thanks for any hints you can give us.

If they use normal maps, maybe you forgot to generate the tangents? or maybe the normals are backward in your 3D editing software.


The normals are correct. The models faces are displayed correctly in Blender and in jMonkeyPlatforms Model Viewer.

We do not use normal maps yet. Only DIffuse. Textures are also the same between the male head and male bodyparts.

If I invert the normals, they are incorrect within the game, so it cannot be some accidential normal-flipping or so.

Maybe you have some vertex color ?
Hard to say, it’s just guessing.

Hmm, you’re right, guessing won’t help us much.
I just checked and the model has no vertex colors.

Thanks for the ideas.
I will setup a minimal working example with a working model and a “too dark” model by the end of this week.
I will post here again when I have the example ready and uploaded. :smile:

Could also be that one has a black ambient color and the others not. Probably worth generating the materials in the scene composer to see what they say and if there are differences between the objects’ materials (if you haven’t already done it).

I just tried adding an Ambient light in jMonkey Scene Composer. The Models Ambient Color is Black.
In Blender, the Models Ambient Color is set to white and it also displays correctly.

The other Model model, which works, has a white Ambient lighting in Blender and in jMonkey.

Now I know what the problem is, but I have to find out why this happens, as the World Ambient Color is set to white in Blender.


The generated j3m materials are identical:

Material MyMaterial : Common/MatDefs/Light/Lighting.j3md {
    MaterialParameters {
    AdditionalRenderState {
        FaceCull Back
        Wireframe Off
        DepthWrite On
        PolyOffset 0.0 0.0
        AlphaTestFalloff 0.0
        Blend Alpha
        PointSprite Off
        ColorWrite On
        DepthTest On

yet ambient light affects some models and some not.

Are the models on the same Node in your scene?

Are you sure you are looking at the right materials? I have never seen the SDK generate a material with an empty MaterialParameters block.

Yes, these are the right materials.
I generated them via the SceneComposers Property Window for the objects.

The male head and body are attached to the same node. The head works, but body doesn’t.

I have uploaded two .blend files.
The female body works 100% after converting from .blend → .j3o via the jMonkey Platform.
The male body has black ambient color after converting from .blend → .j3o via the jMonkey Platform.
I cannot tell see difference between the two models lighting configuration in blender.

female body with working ambient:

male body with wrong ambient:

it does sometimes…Already got it. I don’t know how though.

EDIT : mhh wait…there is no mat param at all…this material shouldn’t work at all…

This seems to be a bug in the blender importer.
It seems to happen randomly when I edit some models.

One way that I can reproduce it is:

  • having a functional model in blender. (works in jME with ambient light)
  • In Blender, select a part of the model and “seperate by selection”, so that I have 2 models
  • Now import the file (with 2 objects) in jMonkeyEngine: AmbientColor is black.

But this is not the only way, it seems… It happened with a model where I only changed the texture path right now. The material definitions are as broken as the one I posted… (but those are also the material definition for the functional models)

I used seperate by selection (in Blender, press ‘P’ and then choose by selection)
to cut up my character and save the parts into files, so all characters that I cut up in this more efficient way, are broken.

For now I will remove Ambient lighting out of our project because it is eating too much time.
Also we cannot limit artists and give him a “whitelist” of what tools he may use while modelling.

You could just fix the materials after you load them. Visit the Geometry objects, grab their material, fix the parameters that need fixing.

Okay so I checked the sources of current Jme3, the new one at git and Blender sources and I found these things:
This is how the jme3 SDK does the ambient color import in MaterialContext.java

float r = ((Number) structure.getFieldValue("ambr")).floatValue();
float g = ((Number) structure.getFieldValue("ambg")).floatValue();
float b = ((Number) structure.getFieldValue("ambb")).floatValue();
float alpha = ((Number) structure.getFieldValue("alpha")).floatValue();
ambientColor = new ColorRGBA(r, g, b, alpha);

From Blender sources I found the place where those values are inited, in convertblender.c line 5182:

void RE_Database_FromScene(...) {
copy_v3_v3(amb, &re->wrld.ambr);

Now what does this mean. Well it means that the material ambient color is set from the world ambient color only when this method is executed in blender. In other way, this pretty much mean that the culprit is in blender sources and not in the jme importer.
Well, the solution is quite simple. All we have to do now is to execute that method. And the simplest one I’ve found is to simply change Viewport Shading to rendered or render your scene at least once. That will set the material color to the ambient color of the world.

Other solution would be to overwrite the ambient color in code:

 Spatial m = assetManager.loadModel("Scenes/male-body-wrong-ambient.j3o");
.getMaterial().setColor("Ambient", ColorRGBA.White);

Now since i checked how the newer version of jme does things as well, I will comment on those as well.
In the MaterialContext.java:

ambientFactor = ((Number) structure.getFieldValue("amb")).floatValue();
material.setColor("Ambient", new ColorRGBA(ambientFactor, ambientFactor, ambientFactor, 1f));

Well, simply speaking that’s an obvious bug of sort, as one float is used for a color.

1 Like

@pspeed We would like to not edit all materials when loading, because some models could have a different ambient color.

I didn’t think that blender could have such a simple bug after all the time it has been around.
Should I report this @ their bugtracker? It was unexpected behaviour to me.

Or is it normal that you must make a render to set some properties in Blender?

Yes, it definitely is a strange behavior. As it stands now, each material in Blender has its ambient color, however you can’t set it directly, instead when you render the world ambient color is copied to the material. I think you could report it as a bug.

Regarding the blender to jme importer, instead of reading the material’s ambient, we could read the world ambient and set it to each material.