bugfix: Fixed the issue that draco compressed gltf files cannot be loaded normally (#5882) (#5883)

Co-authored-by: Kim Kulling <kimkulling@users.noreply.github.com>
This commit is contained in:
HandsomeXi
2024-12-05 05:03:57 +08:00
committed by GitHub
parent ff61095928
commit 164a5ae8cf
3 changed files with 23 additions and 0 deletions

View File

@@ -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;
}

Binary file not shown.

View File

@@ -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
}