Lighting on TriMesh and Obj 3d model


I’am new to the JME engine. So iam trying to figure stuff out.

Currently i have come to a point where i can’t find the awnser to :?.

The situation is:

I turn on the lights.

Load a skybox with textures.

Add the rotating cube to the scene.

Then add the (famous) maggie model (obj) to the scene.

my problem i cannot solve is:

The cube turns gray -> when lighting is false it has its color.

Maggie has all weird grey-isch(??) triangles.

Textures on the skybox look awfull. texture format is: 512x512 gradient tga (made in photoshop)

an image of the result:

my code:


The Maggie issue is a problem with the OBJ importer, probably winding.  Someone should look at that…  Not sure who will yet though since I'm not sure any of the devs use OBJ format and nobody else seems to be offering a solution here.

The grey cube deal is normal.  If you want vertex coloring AND lighting, you must use a MaterialState with ColorMaterial set to something like CM_DIFFUSE.

The skybox textures probably look bad to you due to them being S3TC compressed.  You can specify not to use compression when you load the textures with the TextureManager using the imageFormat argument and the Image.GUESS_FORMAT_NO_S3TC constant or by setting TextureManager's COMPRESS_BY_DEFAULT field to false.

Thank you for the reply.

  • Textures are exacly the way i like them now.
  • Changed from obj to 3Ds seems good also.

    But for the grey looked cube it seems to stay grey. I added a material state but can't figure it to work.

    The cube current code is :

You are almost there.  Instead of using ms.setDiffuse(xxx) use ms.setColorMaterial(MaterialState.CM_DIFFUSE);  You might also remove the setAmbient(xxx) and instead of CM_DIFFUSE, use CM_AMBIENT_AND_DIFFUSE.

ahh yes that works.

Thank you very much.

I have a small problem,

light problem too.

I'm using a LensFlare.

It has a great look! (GG for the one who did it)

*we can see it's written in french, because i'm french*

but the flare isn't visible from everywhere.

I tried changing the CullMode of other objects and other stuff.

I think i just forget something, but what?

(i'm using a BasicGame)

   protected void initGame() {
         terrain = TerrainManager.getTerrainBlock(TerrainManager.TERRAIN_DEPART);
         ciel = new Ciel("ciel",10,10,10);
         limite = new LimiteTerrain("limite");
          limite.setLocalTranslation(new Vector3f(25, terrain.getHeight(25,25) + 15, 25));
          ENV.JOUEUR = new Joueur("Player Node",properties.getRenderer(),ENV.CAMERA);
          ENV.JOUEUR.setLocalTranslation(new Vector3f(100,0, 100));
         //scene_node.attachChild(ModelLoader.loadModel(ModelLoader.D_arbre1, "arbre1"));

      main_node.updateGeometricState(0.0f, true);

private void initLighting() {
      PointLight dr = new PointLight();
       dr.setLocation(new Vector3f(0f, 0f, 0f));

       lightNode = new LightNode("light", ENV.DISPLAY_LIGHTSTATE);

       Vector3f min2 = new Vector3f( -0.5f, -0.5f, -0.5f);
       Vector3f max2 = new Vector3f(0.5f, 0.5f, 0.5f);
       lightNode.setLocalTranslation(new Vector3f( 100f, 200f, 100f));
         // Setup the lensflare textures.
         TextureState[] tex = new TextureState[4];
         tex[0] = display.getRenderer().createTextureState();

         tex[1] = display.getRenderer().createTextureState();

         tex[2] = display.getRenderer().createTextureState();

         tex[3] = display.getRenderer().createTextureState();

       flare = LensFlareFactory.createBasicLensFlare("flare", tex);
       flare.setLocalTranslation(new Vector3f(-1f,-1f,-1f));

private void optimizer(){
      //Create a ZBuffer to display pixels closest to the camera above farther ones. 
          ZBufferState buf = ENV.DISPLAY_RENDERER.createZBufferState();
       // Time for a little optimization. We don't need to render back face triangles, so lets
        //not. This will give us a performance boost for very little effort.
           CullState cs = ENV.DISPLAY_RENDERER.createCullState();

Thanks about the lensflare. 

You might try putting a small box at the same coordinates as the root of your lensflare to ensure you really should be seeing a flare like you think.

I added the box,

And I see it when i don't see the lensflair.

I would like to have a look in the source but i don't understand
how lights work, with the lightstate and other stuff.

Can someone explain me or a good doc (different from the tutorial)

Hmm, try removing the flare.setRootNode(main_node); line in your code and see if it now shows up properly + when it is behind objects.  Since LensFlare works at a bounding volume level to cull out occluded flares, it may be that it feels it is behind something.  I doubt angle of camera itself has anything to do with it and it works properly in the TestLensFlare demo.


I changed the rootnode,

works better, but visible everywhere.