|
Easy3D 3.0.0
|
Storing a per-face attribute (the face normal) on a SurfaceMesh through a named property.
Overview
This console tutorial applies the property system from Tutorial_102_PointCloud_Property to a surface mesh, using faces instead of points. On the tetrahedron from Tutorial_104 we create a per-face property "f:normal", fill it with each face's normal, and print the results. The same pattern works for per-vertex ("v:") and per-edge ("e:") properties — only the add_*_property / handle type changes.
The technique
A property is a parallel array with one slot per element, indexed by the element handle, so a FaceProperty<vec3> stores one normal per face. The normal of a planar face is the unit vector perpendicular to its plane. For a triangle with corners p0, p1, p2 it is normalize((p1 - p0) x (p2 - p0)): the cross product of two edge vectors gives a perpendicular whose direction follows the face winding (right-hand rule), and normalizing makes it unit length. SurfaceMesh::compute_face_normal() does this for you and also handles general (non-triangular) polygons robustly. Normals are the basis of lighting, shading, offsetting and many geometry-processing operations, which is why meshes routinely cache them as a property.
Easy3D API
Running it
Console-only. It prints one line per face, e.g. "normal of face f0: ...", for the four faces of the tetrahedron. The mesh is heap-allocated and deleted at the end to release its memory.