Skip to content

Commit

Permalink
Add a test for loading gltf with external textures (#409)
Browse files Browse the repository at this point in the history
Signed-off-by: Luca Della Vedova <[email protected]>

Signed-off-by: Luca Della Vedova <[email protected]>
Co-authored-by: Louise Poubel <[email protected]>
  • Loading branch information
luca-della-vedova and chapulina authored Aug 31, 2022
1 parent aec75f5 commit 629a9be
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 0 deletions.
24 changes: 24 additions & 0 deletions graphics/src/AssimpLoader_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,30 @@ TEST_F(AssimpLoader, LoadGlTF2Box)
EXPECT_DOUBLE_EQ(mat->Transparency(), 0.0);
}

/////////////////////////////////////////////////
// Open a gltf mesh with an external texture
TEST_F(AssimpLoader, LoadGlTF2BoxExternalTexture)
{
common::AssimpLoader loader;
common::Mesh *mesh = loader.Load(
common::testing::TestFile("data", "gltf", "PurpleCube.gltf"));

EXPECT_STREQ("unknown", mesh->Name().c_str());

// Make sure we can read the submesh name
EXPECT_STREQ("PurpleCube", mesh->SubMeshByIndex(0).lock()->Name().c_str());

EXPECT_EQ(mesh->MaterialCount(), 1u);

const common::MaterialPtr mat = mesh->MaterialByIndex(0u);
ASSERT_TRUE(mat.get());
// No data (it is a file), but a populated filename
EXPECT_EQ(nullptr, mat->TextureData());
auto testTextureFile =
common::testing::TestFile("data/gltf", "PurpleCube_Diffuse.png");
EXPECT_EQ(testTextureFile, mat->TextureImage());
}

/////////////////////////////////////////////////
// Use a fully featured glb test asset, including PBR textures, emissive maps
// embedded textures, lightmaps, animations to test advanced glb features
Expand Down
Binary file added test/data/gltf/PurpleCube.bin
Binary file not shown.
133 changes: 133 additions & 0 deletions test/data/gltf/PurpleCube.gltf
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
{
"asset" : {
"generator" : "Khronos glTF Blender I/O v1.8.19",
"version" : "2.0"
},
"scene" : 0,
"scenes" : [
{
"name" : "Scene",
"nodes" : [
0
]
}
],
"nodes" : [
{
"mesh" : 0,
"name" : "PurpleCube"
}
],
"materials" : [
{
"doubleSided" : true,
"name" : "PurpleCube",
"pbrMetallicRoughness" : {
"baseColorTexture" : {
"index" : 0
},
"metallicFactor" : 0,
"roughnessFactor" : 0.5
}
}
],
"meshes" : [
{
"name" : "PurpleCube",
"primitives" : [
{
"attributes" : {
"POSITION" : 0,
"NORMAL" : 1,
"TEXCOORD_0" : 2
},
"indices" : 3,
"material" : 0
}
]
}
],
"textures" : [
{
"sampler" : 0,
"source" : 0
}
],
"images" : [
{
"mimeType" : "image/png",
"name" : "PurpleCube_Diffuse",
"uri" : "PurpleCube_Diffuse.png"
}
],
"accessors" : [
{
"bufferView" : 0,
"componentType" : 5126,
"count" : 24,
"max" : [
1,
1,
2
],
"min" : [
-1,
-1,
0
],
"type" : "VEC3"
},
{
"bufferView" : 1,
"componentType" : 5126,
"count" : 24,
"type" : "VEC3"
},
{
"bufferView" : 2,
"componentType" : 5126,
"count" : 24,
"type" : "VEC2"
},
{
"bufferView" : 3,
"componentType" : 5123,
"count" : 36,
"type" : "SCALAR"
}
],
"bufferViews" : [
{
"buffer" : 0,
"byteLength" : 288,
"byteOffset" : 0
},
{
"buffer" : 0,
"byteLength" : 288,
"byteOffset" : 288
},
{
"buffer" : 0,
"byteLength" : 192,
"byteOffset" : 576
},
{
"buffer" : 0,
"byteLength" : 72,
"byteOffset" : 768
}
],
"samplers" : [
{
"magFilter" : 9729,
"minFilter" : 9987
}
],
"buffers" : [
{
"byteLength" : 840,
"uri" : "PurpleCube.bin"
}
]
}
Binary file added test/data/gltf/PurpleCube_Diffuse.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 629a9be

Please sign in to comment.