Skip to content

Commit

Permalink
SubMesh::RecalculateNormals improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
ntfshard committed May 12, 2024
1 parent 27f7017 commit a27e8e0
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions graphics/src/SubMesh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ void SubMesh::FillArrays(double **_vertArr, int **_indArr) const
//////////////////////////////////////////////////
void SubMesh::RecalculateNormals()
{
if (this->dataPtr->normals.size() < 3u)
if (this->dataPtr->indices.size() < 3u)
return;

// Reset all the normals
Expand All @@ -597,14 +597,9 @@ void SubMesh::RecalculateNormals()
this->dataPtr->vertices[this->dataPtr->indices[i+2]];
gz::math::Vector3d n = gz::math::Vector3d::Normal(v1, v2, v3);

for (unsigned int j = 0; j < this->dataPtr->vertices.size(); ++j)
{
gz::math::Vector3d v = this->dataPtr->vertices[j];
if (v == v1 || v == v2 || v == v3)
{
this->dataPtr->normals[j] += n;
}
}
this->dataPtr->normals[this->dataPtr->indices[i]] += n;
this->dataPtr->normals[this->dataPtr->indices[i+1]] += n;
this->dataPtr->normals[this->dataPtr->indices[i+2]] += n;
}

// Normalize the results
Expand Down

0 comments on commit a27e8e0

Please sign in to comment.