[Solved] Lighting problem with models imported from sketchup

Hello,

I have a problem with my models i try to incorporate from Google Sketchup in JMonkeyEngine:
The lighting works correctly on directionnalLight but the ambiantLight have no effect on it : the non exposed side of object is full black.

I have seen in others topics that this problem was solved by editing the materials in the *.mtl file, but the problem is that i don’t have *.mtl files at all, the materials seems to be inside the *.j3o file.

Here is my importing pipeline:

  • In sketchup, export model in collada, it generates the following file:

modelname.dae
modelname/texture1.jpg
modelname/texture2.jpg

  • I edit by hand the *.dae file to strip the “modelname” path, and i put textures files in the same directory as the *.dae:

modelname.dae
texture1.jpg
texture2.jpg

(if i don’t do this, textures wouldn’t show in jme)

  • I import the *.dae file in jmonkeyengine in the assets, i got this at the desired location in my project:

modelname.j3o
modelname.j3odata
texture1.jpg
texture2.jpg

  • In my code, i load the model like this:
    assetManager.loadModel(“assets/Models/modelname.j3o”);

As you see, there is no *.mtl file so i can’t edit it to solve my lighting problem.

My two questions are the following:

  • Why i don’t get the *.mtl file ? is there a way to generate/extract it afterward from the j3o file ? Or is there another importing pipeline which generate it ?

  • Is there another way to solve my lighting problem than editing that non-existent file ?

Thanks in advance

Because mtl files are specific to ogre exports and the advice is not very helpful for (insert every other file format in the world here).

Yes, either generate the material file in the SDK and modify that… or just grab the Material object in code and modify that.

The issue is that your j3o’s material must somehow be saying to use the material colors but then has not provided an ambient color (so it’s left as black)… or it’s specifically setting it to black. When useMaterialColors is false then a more appropriate gray ambient is used.

…unless you are using the ancient 3.0 JME instead of 3.1… then the default in all cases is black, I guess.

1 Like

Thanks for the answer !

Ok for the *.mtl files.

So i tried two workarounds:

  • I tried to generate the material in the SDK, but i have to do it for each mesh of the model (30 meshs) in the scene composer, and some of them have the same materials.
    Is there a way to automatically generate all the materials of a j3o file, without doublons ?
    At least, i’ve seen where is the problem by generating one of the material:

Material MyMaterial : Common/MatDefs/Light/Lighting.j3md {
MaterialParameters {
DiffuseMap : Flip Repeat textureurl.jpg
Minnaert : false
Specular : 1.0 1.0 1.0 1.0
Diffuse : 1.0 1.0 1.0 1.0
UseMaterialColors : true
ParallaxHeight : 0.05
Ambient : 0.0 0.0 0.0 1.0
Shininess : 20.0
WardIso : false
}
}

The Ambient is set to black, that’s why i’ve got black face in the sides not directly under directionalLight.

  • I tried to set the Ambient directly to the node i get from the model loading in the hope it would recursively apply to the childrens:
    Material material = new Material(assetManager,“Common/MatDefs/Light/Lighting.j3md”);
    material.setBoolean(“UseMaterialColors”,true);
    material.setColor(“Ambient”, ColorRGBA.Blue);
    objectModel.setMaterial(material);

It works but it also replace every others material value already present (textures goes blank, diffuse goes black etc …). Is there a way to only modify the Ambient of all material childrens of a node without crushing others values ?

  • Maybe another way: Is it possible to choose the default material applied to the model when we load it with the model importer ? I saw a “Default Material” field but it’s not editable and inside it’s written “No property editor”.

http://javadoc.jmonkeyengine.org/com/jme3/scene/Spatial.html#depthFirstTraversal-com.jme3.scene.SceneGraphVisitor-

http://javadoc.jmonkeyengine.org/com/jme3/scene/SceneGraphVisitorAdapter.html

With that, in a few lines of code you could visit all of the geometries, grab their materials, and set the ambient color to white.

2 Likes

A Big Thank you ! It works and it exactly what i wanted to do !

If someone else have a similar problem, here is the code:

public class AmbientRepairer extends SceneGraphVisitorAdapter {
@Override
public void visit(Geometry c) {
c.getMaterial().setColor(“Ambient”, ColorRGBA.DarkGray);
c.getMaterial().setBoolean(“UseMaterialColors”,true);
}
}

objectModel.depthFirstTraversal(new AmbientRepairer());