Skip to content

Commit 4dec38d

Browse files
iche033scpeters
authored andcommitted
Fix AssimpLoader collada texture coordinates (#634)
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 <[email protected]>
1 parent 2faf830 commit 4dec38d

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

graphics/src/AssimpLoader.cc

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -650,15 +650,14 @@ SubMesh AssimpLoader::Implementation::CreateSubMesh(
650650
subMesh.AddVertex(vertex);
651651
subMesh.AddNormal(normal);
652652
// Iterate over sets of texture coordinates
653-
int uvIdx = 0;
654-
while(_assimpMesh->HasTextureCoords(uvIdx))
653+
for (unsigned int i = 0; i < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i)
655654
{
655+
if (!_assimpMesh->HasTextureCoords(i))
656+
continue;
656657
math::Vector3d texcoords;
657-
texcoords.X(_assimpMesh->mTextureCoords[uvIdx][vertexIdx].x);
658-
texcoords.Y(_assimpMesh->mTextureCoords[uvIdx][vertexIdx].y);
659-
// TODO(luca) why do we need 1.0 - Y?
660-
subMesh.AddTexCoordBySet(texcoords.X(), 1.0 - texcoords.Y(), uvIdx);
661-
++uvIdx;
658+
texcoords.X(_assimpMesh->mTextureCoords[i][vertexIdx].x);
659+
texcoords.Y(_assimpMesh->mTextureCoords[i][vertexIdx].y);
660+
subMesh.AddTexCoordBySet(texcoords.X(), texcoords.Y(), i);
662661
}
663662
}
664663
for (unsigned faceIdx = 0; faceIdx < _assimpMesh->mNumFaces; ++faceIdx)
@@ -695,6 +694,7 @@ Mesh *AssimpLoader::Load(const std::string &_filename)
695694
aiProcess_JoinIdenticalVertices |
696695
aiProcess_RemoveRedundantMaterials |
697696
aiProcess_SortByPType |
697+
aiProcess_FlipUVs |
698698
#ifndef GZ_ASSIMP_PRE_5_2_0
699699
aiProcess_PopulateArmatureData |
700700
#endif
@@ -756,11 +756,17 @@ Mesh *AssimpLoader::Load(const std::string &_filename)
756756
// Recursive call to keep track of transforms,
757757
// mesh is passed by reference and edited throughout
758758
this->dataPtr->RecursiveCreate(scene, rootNode, rootTransform, mesh);
759+
auto rootSkeleton = mesh->MeshSkeleton();
759760
// Add the animations
760761
for (unsigned animIdx = 0; animIdx < scene->mNumAnimations; ++animIdx)
761762
{
762763
auto& anim = scene->mAnimations[animIdx];
763764
auto animName = ToString(anim->mName);
765+
if (animName.empty())
766+
{
767+
animName = "animation" +
768+
std::to_string(rootSkeleton->AnimationCount() + 1);
769+
}
764770
SkeletonAnimation* skelAnim = new SkeletonAnimation(animName);
765771
for (unsigned chanIdx = 0; chanIdx < anim->mNumChannels; ++chanIdx)
766772
{

0 commit comments

Comments
 (0)