Averaging Normals (recovered thread)

Everything DG Kernel: Technical discussions and issues
Post Reply
gerard12
Posts: 20
Joined: Tue Jun 18, 2024 6:09 am

Averaging Normals (recovered thread)

Post by gerard12 »

Hello guys

I thought I ought to explain a common mistake with handling meshes. This is mostly common with stl import, but can happen with other formats or for programmatically generated meshes.

As you know to render a surface properly any 3D graphical software has to have normals t the surface available. Otherwise, lighting can be weird and scene will be unrealistic. There are two ways to store normals: Per face or per vertex.

Per vertex normals give much better picture with same density of mesh. Compare the images below.

STL stores only per-face normals. KC keeps normals per vertex, but sometimes, particularily when importing large STL the mesh ends up having several normal per vertex one per each adjacent face. This causes the mesh to look as if it has per face normals.

During the STL load KC does analysing of the surface and where the surface appears to be smooth it calculates per-vertex averaged normals. For large STL it is slow so there is a temptation to skip this step. Remember though that this is a one –off operation if you save the result as mdg.

If you have a mesh which looks faceted the normals can be recalculated at runtime like:

Code: Select all

IMesh_DG iMesh = entity.As<IMesh_DG>();
iMesh.FixupNormals(35, 0);
Or you can load the model with the Sample Explorer > MeshOps sample and execute the Tools > Fixup Normals menu command.

Cheers
Gerard
Attachments
PerVtx.jpg
PerVtx.jpg (26.44 KiB) Viewed 4578 times
PerFace.jpg
PerFace.jpg (36.66 KiB) Viewed 4578 times
Post Reply