Imported mesh, how to "shade" sides

I don’t know the terminology so I don’t know what to search for.

When you create a box (MeshBuilder.CreateBox), the sides are darker and lighter depending on the rotation (and probably also the direction of light). When I import a mesh (SceneLoader.ImportMesh) it does not.

How can I add the same behavior for an imported mesh? Right now all sides have the same color, so you really cannot see the shape of the mesh.

does your model gltf have normals?
Did you add some shading? Also, is there a light in your scene?
Please provide a playground so we can take a look.

1 Like

Hi!

I am loading an obj file with only a geometry and nothing else. I have a light in the scene and I can show a box in the same scene.

I tried to use the Playground but I don’t know how to reference an external file. You can however see what I mean in the Sandbox (https://sandbox.babylonjs.com/). This is the file I am loading:

v 20 -10 20
v 20 -10 -20
v 20 10 -20
v 20 10 20
v 15 15 0
v -15 15 0
v -20 -10 20
v -20 10 20
v -20 10 -20
v -20 -10 -20

f 1 2 3 4
f 7 1 4 8
f 10 7 8 9
f 2 10 9 3
f 10 2 1 7
f 8 4 5 6
f 4 3 5
f 9 8 6
f 3 9 6 5

I will continue to try to use the playground.

this .obj file does not contain normals.
You can either generate them in your DCC tool or force a flat shaded normal computation using convertToFlatShadedMesh

like in this pg : Babylon.js Playground

2 Likes

Thanks! That was it!

1 Like