Avoid faceted surfaces

Technical discussions
Post Reply
gerard12
Posts: 21
Joined: Fri Jul 26, 2013 8:34 am

Avoid faceted surfaces

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 to 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 glm.
If you have a mesh which looks faceted the normals can be recalculated at runtime like:
IMeshMods iMeshMods = m_iModel;
iMeshMods.FixupNormals(30, 5);

Or you can load the model with KernelCAD_4_3\Samples\NET\C#\Enterprise\Morphe sample and execute the “Fixup Normals” menu command

Cheers
Gerard

Per-face normal:
Image

Correct per-vertex averaged normal:
Image

Post Reply