MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/FleX / CalculateNormals

Method CalculateNormals

core/mesh.cpp:68–92  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66}
67
68void Mesh::CalculateNormals()
69{
70 m_normals.resize(0);
71 m_normals.resize(m_positions.size());
72
73 int numTris = int(GetNumFaces());
74
75 for (int i=0; i < numTris; ++i)
76 {
77 int a = m_indices[i*3+0];
78 int b = m_indices[i*3+1];
79 int c = m_indices[i*3+2];
80
81 Vec3 n = Cross(m_positions[b]-m_positions[a], m_positions[c]-m_positions[a]);
82
83 m_normals[a] += n;
84 m_normals[b] += n;
85 m_normals[c] += n;
86 }
87
88 int numVertices = int(GetNumVertices());
89
90 for (int i=0; i < numVertices; ++i)
91 m_normals[i] = ::Normalize(m_normals[i]);
92}
93
94namespace
95{

Callers 8

CreateTetrahedronFunction · 0.80
SkinMeshFunction · 0.80
InitializeMethod · 0.80
InitializeMethod · 0.80
InitializeMethod · 0.80
InitializeMethod · 0.80
InitializeMethod · 0.80
InitializeMethod · 0.80

Calls 4

resizeMethod · 0.80
sizeMethod · 0.80
CrossFunction · 0.70
NormalizeFunction · 0.70

Tested by

no test coverage detected