Wrong lighting with 3ds

Hello,



I’m having trouble getting the lighting to work correctly on a 3ds model exported from Blender. The light on the faces are either very hard (looks like no lighting at all) or completely black.







The normals are shown (in SimpleGame) to be facing outwards towards the light source - is this correct? I tried flipping the normals before exporting which made the lighting work correctly but then the collision geometry in jMEphysics doesn’t work (objects fall through). I also tried using Collada instead of 3ds, which made the lighting work but also yielded problems with the collision data in jMEphysics. I have experienced this problem with Collada before with manual triangle picking which had to do with the scaling of an object - if it didn’t have the same scale in the x, y and z axes it would select completely different triangles or no triangles at all…



Any ideas how I can fix this?



Thanks,

Joh

Perhaps it is a triangle winding order issue?  Can you try adding a cullstate and seeing which of back or front causes you to be able to see INTO the object.  (should be FRONT if wound correctly.)

renanse said:

Perhaps it is a triangle winding order issue?  Can you try adding a cullstate and seeing which of back or front causes you to be able to see INTO the object.  (should be FRONT if wound correctly.)


I already have a cullstate which I set to cull the back of triangles:


CullState cs = display.getRenderer().createCullState();
cs.setCullMode(CullState.CS_BACK);
rootNode.setRenderState(cs);



Same problem...

try displaying the normals…  :expressionless:

I didn't say it would fix the issue, just that it would show which way things were wound.  Just to be clear, the code you posted culls hidden surfaces when you don't flip your normals before exporting right?  And if you do flip those normals, that cull state should actually hide the front surfaces (because the flipped normals make them back faces now.)

sfera said:

try displaying the normals...  :|


Here's a screenshot of the model while displaying the normals:

Looks like bigger issues than lighting?  Normals connected to no triangles… or culled triangles probably.

renanse said:

I didn't say it would fix the issue, just that it would show which way things were wound.  Just to be clear, the code you posted culls hidden surfaces when you don't flip your normals before exporting right?  And if you do flip those normals, that cull state should actually hide the front surfaces (because the flipped normals make them back faces now.)


Correct, here's a screenshot of the scene with flipped normals:



renanse said:

Looks like bigger issues than lighting?  Normals connected to no triangles... or culled triangles probably.


They're not connected? :? What do you mean? They're not supposed to be connected to the edges or..?

As for Collada:



I think I am mistaking the picture as a model sitting on terrain?  If the whole thing is a model, your issue makes a bit more sense. 



I find two things disturbing in the images of flipped vs. non-flipped.

  1. Cull state does not seem to be having any effect?
  2. The same triangles are lit up, or iow, the black triangles did not suddenly get lit when you flipped normals.



    Maybe you could export to OBJ and try the latest changes I've made to OBJ importer in CVS?  Alternatively, upload your model as a .jme file and I'll inspect it with tools here at work.

could you please post a wireframe screenshot or the jme model as renanse said?  :expressionless:

renanse said:

I think I am mistaking the picture as a model sitting on terrain?  If the whole thing is a model, your issue makes a bit more sense. 


Define model..? Here's the code I'm using: Level.java and TestLevel.java
The 3ds itself is exported from Blender: bane7.3ds (or collada file: bane7.dae)

renanse said:

I find two things disturbing in the images of flipped vs. non-flipped.
1. Cull state does not seem to be having any effect?
2. The same triangles are lit up, or iow, the black triangles did not suddenly get lit when you flipped normals.


1. I forgot to mention that I turned of culling when I tested the model with flipped normals... And yes, the cull state does have an effect - I tested it just now.
2. When I flipped the normals of the 3ds the black triangles did get lit up correctly as with the collada file. Or am I misunderstanding your question here? :)

renanse said:

Maybe you could export to OBJ and try the latest changes I've made to OBJ importer in CVS?  Alternatively, upload your model as a .jme file and I'll inspect it with tools here at work.


Sure, in what revision did you make those changes? I update jME just a few days ago (2007-04-30 17:07), do I need to update it to include your changes?

sfera said:

could you please post a wireframe screenshot or the jme model as renanse said?  :|


Wireframe screenshot is here: http://joh.deworks.net/dump/3ds-lighting-wireframe.png

I made the OBJ changes mid day April 30, so that may be right?



Anyhow, I’ve pulled down the dae you posted and opened it in our tools and (after fixing an npe in the newest local collada schema code…) it loaded up and looks great - aside from missing textures.




renanse said:

I made the OBJ changes mid day April 30, so that may be right?

Anyhow, I've pulled down the dae you posted and opened it in our tools and (after fixing an npe in the newest local collada schema code...) it loaded up and looks great - aside from missing textures.


Yeah, collada works fine it seems except that something goes wrong with the jMEphysics collision data :| If this worked I would've just gone with collada, no question about it...

I tried exporting to OBJ and couldn't get it to load the textures... Not sure if I exported with the correct options either:


   private void loadObjMap() throws Exception
   {
      ObjToJme converter=new ObjToJme();

      URL mapLoc = Level.class.getClassLoader().getResource(MAP_LOC + "/" + mapfile + ".obj");
      URL texLoc =  Level.class.getClassLoader().getResource(TEX_LOC);

      converter.setProperty("texurl" , texLoc);
      converter.setProperty("mtllib", mapLoc);
      
      ByteArrayOutputStream BO=new ByteArrayOutputStream();
      System.out.println("Starting to convert .obj to .jme");
      converter.convert(mapLoc.openStream(),BO);
      
      map = new Node();
      map.attachChild((Spatial)BinaryImporter.getInstance().load(new ByteArrayInputStream(BO.toByteArray())));
      
      attachChild(map);
   }



These are the options I used when exporting from Blender:

renanse said:

Anyhow, I've pulled down the dae you posted and opened it in our tools and (after fixing an npe in the newest local collada schema code...) it loaded up and looks great - aside from missing textures.


Did you try opening the 3ds?
joh said:


These are the options I used when exporting from Blender:




triangulate, materials are not selected