Problem with lighting after importing OBJ file

In my code, there’s a PointLight source which is set to follow the camera position, so that the side of the object from which you look at it will always be illuminated. Everything works fine when I import meshes from Babylon files. But when I import meshes from any OBJ file, the way the light moves while the camera moves looks strange to me. You can see it in Babylon.js Playground

I want it to illuminate the object from the same point where the camera is. Any help is appreciated.

Hey I think that your mesh has no normal:
https://www.babylonjs-playground.com/#66HJ29#2

I created some by code and it works (also I recommend to not set the minZ to such a small value as it will create a lot of precision issues)

Thank you very much :slightly_smiling_face:. That was it. And thanks for the advice about the value of minZ too.

1 Like

One more thing. Does Babylon.js 2.5 has a function similar to mesh.createNormals()?

Ouch. I don’t think so. This is a rather old version now:(

Yeah, it is :slightly_smiling_face:

There is a new property on objFileloader BABYLON.OBJFileLoader.COMPUTE_NORMALS. you could always try the playground to see if it works for you, or inline the missing code.

It’s using a method on VertexData:

1 Like