diff --git a/code/AssetLib/glTF2/glTF2Asset.inl b/code/AssetLib/glTF2/glTF2Asset.inl index 3ae5e48b1..bcc5b7ddb 100644 --- a/code/AssetLib/glTF2/glTF2Asset.inl +++ b/code/AssetLib/glTF2/glTF2Asset.inl @@ -294,6 +294,8 @@ inline void SetDecodedIndexBuffer_Draco(const draco::Mesh &dracoMesh, Mesh::Prim // Usually uint32_t but shouldn't assume if (sizeof(dracoMesh.face(draco::FaceIndex(0))[0]) == componentBytes) { memcpy(decodedIndexBuffer->GetPointer(), &dracoMesh.face(draco::FaceIndex(0))[0], decodedIndexBuffer->byteLength); + // Assign this alternate data buffer to the accessor + prim.indices->decodedBuffer.swap(decodedIndexBuffer); return; } diff --git a/test/models/glTF2/draco/robot.glb b/test/models/glTF2/draco/robot.glb new file mode 100644 index 000000000..81679a60f Binary files /dev/null and b/test/models/glTF2/draco/robot.glb differ diff --git a/test/unit/utglTF2ImportExport.cpp b/test/unit/utglTF2ImportExport.cpp index c29d17d33..fea75b8f4 100644 --- a/test/unit/utglTF2ImportExport.cpp +++ b/test/unit/utglTF2ImportExport.cpp @@ -896,6 +896,27 @@ TEST_F(utglTF2ImportExport, import_dracoEncoded) { ASSERT_TRUE(scene->mMetaData->Get(AI_METADATA_SOURCE_GENERATOR, generator)); ASSERT_EQ(strcmp(generator.C_Str(), "COLLADA2GLTF"), 0); } +#endif + const aiScene *robotScene = importer.ReadFile(ASSIMP_TEST_MODELS_DIR "/glTF2/draco/robot.glb", + aiProcess_ValidateDataStructure); +#ifndef ASSIMP_ENABLE_DRACO + // No draco support, scene should not load + ASSERT_EQ(robotScene, nullptr); +#else + ASSERT_NE(robotScene, nullptr); + ASSERT_NE(robotScene->mMetaData, nullptr); + { + ASSERT_TRUE(robotScene->mMetaData->HasKey(AI_METADATA_SOURCE_FORMAT)); + aiString format; + ASSERT_TRUE(robotScene->mMetaData->Get(AI_METADATA_SOURCE_FORMAT, format)); + ASSERT_EQ(strcmp(format.C_Str(), "glTF2 Importer"), 0); + } + { + ASSERT_TRUE(robotScene->mMetaData->HasKey(AI_METADATA_SOURCE_FORMAT_VERSION)); + aiString version; + ASSERT_TRUE(robotScene->mMetaData->Get(AI_METADATA_SOURCE_FORMAT_VERSION, version)); + ASSERT_EQ(strcmp(version.C_Str(), "2.0"), 0); + } #endif }