Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a test for loading gltf with external textures #409

Merged
merged 5 commits into from
Aug 31, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"));
luca-della-vedova marked this conversation as resolved.
Show resolved Hide resolved

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");
luca-della-vedova marked this conversation as resolved.
Show resolved Hide resolved
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.