The Geometry module provides tools for computing geometric properties of meshes.
Include the module with:
#include <trueform/geometry.hpp>
Compute face normals for polygon meshes:
// Compute polygon normals for all polygons
auto polygon_normals = tf::compute_normals(polygons);
// Result is a unit_vectors_buffer with one normal per face
for (auto normal : polygon_normals.unit_vectors()) {
// Each normal is a tf::unit_vector<T, 3>
auto [nx, ny, nz] = normal;
}
// Access underlying flat memory for export
float* normal_data = polygon_normals.data_buffer().data();
Compute vertex normals by averaging adjacent face normals. This requires the polygons to have both face_membership and normals tagged:
// First compute polygon normals
auto polygon_normals = tf::compute_normals(polygons);
// Build face membership for adjacency queries
tf::face_membership<int> fm;
fm.build(polygons);
// Tag the polygons with topology and normals
auto tagged_polygons = polygons
| tf::tag(fm)
| tf::zip_normals(polygon_normals.unit_vectors());
// Compute point normals (averages adjacent face normals)
auto point_normals = tf::compute_point_normals(tagged_polygons);
// Result is a unit_vectors_buffer with one normal per vertex
for (auto normal : point_normals.unit_vectors()) {
auto [nx, ny, nz] = normal;
}