| 95 | |
| 96 | template<class PositionData> |
| 97 | void IndexedFaceMesh::updateNormals(const PositionData &pd, const unsigned int offset) |
| 98 | { |
| 99 | m_normals.resize(numFaces()); |
| 100 | |
| 101 | #pragma omp parallel default(shared) |
| 102 | { |
| 103 | #pragma omp for schedule(static) |
| 104 | for (int i = 0; i < (int) numFaces(); i++) |
| 105 | { |
| 106 | // Get first three points of face |
| 107 | const Vector3r &a = pd.getPosition(m_indices[m_verticesPerFace*i] + offset); |
| 108 | const Vector3r &b = pd.getPosition(m_indices[m_verticesPerFace*i + 1] + offset); |
| 109 | const Vector3r &c = pd.getPosition(m_indices[m_verticesPerFace*i + 2] + offset); |
| 110 | |
| 111 | // Create normal |
| 112 | Vector3r v1 = b - a; |
| 113 | Vector3r v2 = c - a; |
| 114 | |
| 115 | m_normals[i] = v1.cross(v2); |
| 116 | m_normals[i].normalize(); |
| 117 | // fix normals of degenerate triangles that can become zero vectors |
| 118 | if (m_normals[i].squaredNorm() < 1e-6f) |
| 119 | m_normals[i] = Vector3r::UnitX(); |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | template<class PositionData> |
| 125 | void IndexedFaceMesh::updateVertexNormals(const PositionData &pd) |
no test coverage detected