Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check normal presence before trying to read asMesh normals (backport #654) #657

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions graphics/src/AssimpLoader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -667,18 +667,20 @@ SubMesh AssimpLoader::Implementation::CreateSubMesh(
{
// Add the vertex
math::Vector3d vertex;
math::Vector3d normal;
vertex.X(_assimpMesh->mVertices[vertexIdx].x);
vertex.Y(_assimpMesh->mVertices[vertexIdx].y);
vertex.Z(_assimpMesh->mVertices[vertexIdx].z);
normal.X(_assimpMesh->mNormals[vertexIdx].x);
normal.Y(_assimpMesh->mNormals[vertexIdx].y);
normal.Z(_assimpMesh->mNormals[vertexIdx].z);
vertex = _transform * vertex;
normal = rot * normal;
normal.Normalize();
subMesh.AddVertex(vertex);
subMesh.AddNormal(normal);
if (_assimpMesh->HasNormals()) {
math::Vector3d normal;
normal.X(_assimpMesh->mNormals[vertexIdx].x);
normal.Y(_assimpMesh->mNormals[vertexIdx].y);
normal.Z(_assimpMesh->mNormals[vertexIdx].z);
normal = rot * normal;
normal.Normalize();
subMesh.AddNormal(normal);
}
// Iterate over sets of texture coordinates
for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i)
{
Expand All @@ -698,6 +700,9 @@ SubMesh AssimpLoader::Implementation::CreateSubMesh(
subMesh.AddIndex(face.mIndices[2]);
}
subMesh.SetMaterialIndex(_assimpMesh->mMaterialIndex);
if (subMesh.NormalCount() == 0u){
subMesh.RecalculateNormals();
}
return subMesh;
}

Expand Down
Loading