Skip to content

Instantly share code, notes, and snippets.

@sreiter
sreiter / triangle_to_vertex_normals.cpp
Last active July 2, 2020 06:02
A short example on how triangle normals can be used to compute vertex normals for either smooth or flat shading.
// Please note: The code below has not been compiled. Includes are missing.
// This snippet is just for illustration purposes. Feedback is highly appreciated, of course.
// First we'll read the stl data into local arrays. Each triplet in `rawPoints` corresponds to one
// 3D point and each triplet in `rawTriNormals` to one 3D triangle normal.
std::vector <float> rawPoints, rawTriNormals;
std::vector <unsigned int> triIndices, solids;
stl_reader::ReadStlFile ("geometry.stl", rawPoints, rawTriNormals, triIndices, solids);