Skip to content

Commit

Permalink
Fix AssimpLoader collada texture coordinates (#634)
Browse files Browse the repository at this point in the history
Fixes UNIT_AssimpLoader_TEST with assimp 5.4.3. This should fix homebrew CI.

This PR tweaks the way we checks for texture coordinates from assimp. Empty texture coordinate slots are now allowed as of assimp/assimp#5636. The new logic should be compatible with assimp 5.4.3 and prior versions

Signed-off-by: Ian Chen <ichen@openrobotics.org>
  • Loading branch information
iche033 authored and scpeters committed Sep 23, 2024
1 parent 2faf830 commit 4dec38d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions graphics/src/AssimpLoader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -650,15 +650,14 @@ SubMesh AssimpLoader::Implementation::CreateSubMesh(
subMesh.AddVertex(vertex);
subMesh.AddNormal(normal);
// Iterate over sets of texture coordinates
int uvIdx = 0;
while(_assimpMesh->HasTextureCoords(uvIdx))
for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i)
{
if (!_assimpMesh->HasTextureCoords(i))
continue;
math::Vector3d texcoords;
texcoords.X(_assimpMesh->mTextureCoords[uvIdx][vertexIdx].x);
texcoords.Y(_assimpMesh->mTextureCoords[uvIdx][vertexIdx].y);
// TODO(luca) why do we need 1.0 - Y?
subMesh.AddTexCoordBySet(texcoords.X(), 1.0 - texcoords.Y(), uvIdx);
++uvIdx;
texcoords.X(_assimpMesh->mTextureCoords[i][vertexIdx].x);
texcoords.Y(_assimpMesh->mTextureCoords[i][vertexIdx].y);
subMesh.AddTexCoordBySet(texcoords.X(), texcoords.Y(), i);
}
}
for (unsigned faceIdx = 0; faceIdx < _assimpMesh->mNumFaces; ++faceIdx)
Expand Down Expand Up @@ -695,6 +694,7 @@ Mesh *AssimpLoader::Load(const std::string &_filename)
aiProcess_JoinIdenticalVertices |
aiProcess_RemoveRedundantMaterials |
aiProcess_SortByPType |
aiProcess_FlipUVs |
#ifndef GZ_ASSIMP_PRE_5_2_0
aiProcess_PopulateArmatureData |
#endif
Expand Down Expand Up @@ -756,11 +756,17 @@ Mesh *AssimpLoader::Load(const std::string &_filename)
// Recursive call to keep track of transforms,
// mesh is passed by reference and edited throughout
this->dataPtr->RecursiveCreate(scene, rootNode, rootTransform, mesh);
auto rootSkeleton = mesh->MeshSkeleton();
// Add the animations
for (unsigned animIdx = 0; animIdx < scene->mNumAnimations; ++animIdx)
{
auto& anim = scene->mAnimations[animIdx];
auto animName = ToString(anim->mName);
if (animName.empty())
{
animName = "animation" +
std::to_string(rootSkeleton->AnimationCount() + 1);
}
SkeletonAnimation* skelAnim = new SkeletonAnimation(animName);
for (unsigned chanIdx = 0; chanIdx < anim->mNumChannels; ++chanIdx)
{
Expand Down

0 comments on commit 4dec38d

Please sign in to comment.