Compute Normals seems not correct

@JohnK ,
Thanks so much for your solutions.
1、convertToFlatShadedMesh does can fix it, but has side effect( mesh will increase vertexdata, and convert more than 100000 meshes is a heavy work).
2、change the z values in your last post will change the shape of the mesh. Actually, it is a wall with thickness, not a plane :smiley:

I don’t kown the alogorithm in the shader to calculate the normals, is it possible to implement in ComputeNormals function?

And another question for SPS, in the document describes as below:
“As it is just a mesh, the SPS has all the same properties than any other BJS mesh : not more, not less.”
Why SPS must provide normals when buildMesh, while for other BJS mesh, the normals are optional?(shader will calculate it ) @jerome

Thanks

It really is a matter of defining your mesh correctly. For your mesh to have thickness it needs a front plane and a back plane and side planes. To obtain the appearance you need vertices where planes meet cannot share indices otherwise you have the average normal problem.

Easier way see Irregular Polygon Extrusion | Babylon.js Documentation

Custom Way - Steps are

  1. For front plane determine vertex positions needed for the wall with doors and windows and triangulate the front plane. Give each vertex an index. Arrange vertex positions in the positions array in the correct order. In the index array assign the three indices needed for each triangle, shared vertices can share indices.

  2. For back plane determine vertex positions needed for the wall with doors and windows and triangulate the back plane. Give each vertex an index counting on from the last index from the front pane, Arrange vertex positions in the positions array in the correct order. In the index array assign the three indices needed for each triangle, shared vertices can share indices.

  3. For each side wall, in turn, determine vertex positions needed for the wall and triangulate. Give each vertex an index counting on from the last index, Arrange vertex positions in the positions array in the correct order. In the index array assign the three indices needed for each triangle.

ComputeNormals and proceed.

Already agreed

Sorry had not picked that up - definitely the source of shared vertices and averaged normals where planes meet.

I think the issue is that the shader renders dynamically, ie it takes a single facet triangle calculates the normal if not given and renders immediately. Whereas the ComputeNormal function stores normal values so if vertex A is shared by three facet triangles what value do you store for the normal at A. If you store the normal for the last facet visited then the other facets it shares have normals in the wrong direction. The choice is to use the average of the normals.

Because the processing is different

SPS is like a model made of the same Lego brick. The process of constructing each Lego brick which involves pouring liquid plastic into molds is different to producing the SPS model where the process is putting together a construction from made bricks. It would be much more of a problem to construct the SPS model by pouring liquid plastic into a complex pre-made forma.

1 Like

@JohnK
Thanks for the detailed reply.
Now it seems the only choice is not sharing vertices in different faces to avoid this normals issue.
(I think why some exporters share vertices only want to benefit from the smaller model size and GPU memory :smiley:)

That is true :smiley: It’s always a tradeoff between visual quality and performance