diff --git a/graphics/src/AssimpLoader_TEST.cc b/graphics/src/AssimpLoader_TEST.cc index 93a0f02c9..87e6b8210 100644 --- a/graphics/src/AssimpLoader_TEST.cc +++ b/graphics/src/AssimpLoader_TEST.cc @@ -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 diff --git a/test/data/gltf/PurpleCube.bin b/test/data/gltf/PurpleCube.bin new file mode 100644 index 000000000..59a9334fb Binary files /dev/null and b/test/data/gltf/PurpleCube.bin differ diff --git a/test/data/gltf/PurpleCube.gltf b/test/data/gltf/PurpleCube.gltf new file mode 100644 index 000000000..48f941f4a --- /dev/null +++ b/test/data/gltf/PurpleCube.gltf @@ -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" + } + ] +} diff --git a/test/data/gltf/PurpleCube_Diffuse.png b/test/data/gltf/PurpleCube_Diffuse.png new file mode 100644 index 000000000..238176473 Binary files /dev/null and b/test/data/gltf/PurpleCube_Diffuse.png differ