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

Feature: Inits units tests for fbx and glTF2 #385

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
69 changes: 69 additions & 0 deletions graphics/src/AssimpLoader_TEST.cc
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ TEST_F(AssimpLoader, LoadObjBox)
EXPECT_DOUBLE_EQ(mat->Transparency(), 0.0);
}


/////////////////////////////////////////////////
// This tests opening an OBJ file that has an invalid material reference
TEST_F(AssimpLoader, ObjInvalidMaterial)
Expand All @@ -536,3 +537,71 @@ TEST_F(AssimpLoader, ObjInvalidMaterial)

EXPECT_TRUE(mesh != nullptr);
}

/////////////////////////////////////////////////
// This test opens a FBX file
TEST_F(AssimpLoader, LoadFbxBox)
{
common::AssimpLoader loader;
common::Mesh *mesh = loader.Load(
common::testing::TestFile("data", "box.fbx"));

EXPECT_STREQ("unknown", mesh->Name().c_str());
EXPECT_EQ(math::Vector3d(100, 100, 100), mesh->Max());
EXPECT_EQ(math::Vector3d(-100, -100, -100), mesh->Min());

EXPECT_EQ(24u, mesh->VertexCount());
EXPECT_EQ(24u, mesh->NormalCount());
EXPECT_EQ(36u, mesh->IndexCount());
EXPECT_EQ(24u, mesh->TexCoordCount());
EXPECT_EQ(1u, mesh->SubMeshCount());
EXPECT_EQ(1u, mesh->MaterialCount());

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

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

const common::MaterialPtr mat = mesh->MaterialByIndex(0u);
ASSERT_TRUE(mat.get());

// Make sure we read the material color values
EXPECT_EQ(mat->Ambient(), math::Color(0.0f, 0.0f, 0.0f, 1.0f));
EXPECT_EQ(mat->Diffuse(), math::Color(0.8f, 0.8f, 0.8f, 1.0f));
EXPECT_EQ(mat->Specular(), math::Color(0.8f, 0.8f, 0.8f, 1.0f));
EXPECT_DOUBLE_EQ(mat->Transparency(), 0.0);
}

/////////////////////////////////////////////////
// This test opens a GLB file
TEST_F(AssimpLoader, LoadGlTF2Box)
{
common::AssimpLoader loader;
common::Mesh *mesh = loader.Load(
common::testing::TestFile("data", "box.glb"));

EXPECT_STREQ("unknown", mesh->Name().c_str());
EXPECT_EQ(math::Vector3d(1, 1, 1), mesh->Max());
EXPECT_EQ(math::Vector3d(-1, -1, -1), mesh->Min());

EXPECT_EQ(24u, mesh->VertexCount());
EXPECT_EQ(24u, mesh->NormalCount());
EXPECT_EQ(36u, mesh->IndexCount());
EXPECT_EQ(24u, mesh->TexCoordCount());
EXPECT_EQ(1u, mesh->SubMeshCount());
EXPECT_EQ(1u, mesh->MaterialCount());

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

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

const common::MaterialPtr mat = mesh->MaterialByIndex(0u);
ASSERT_TRUE(mat.get());

// Make sure we read the material color values
EXPECT_EQ(mat->Ambient(), math::Color(0.4f, 0.4f, 0.4f, 1.0f));
EXPECT_EQ(mat->Diffuse(), math::Color(0.8f, 0.8f, 0.8f, 1.0f));
EXPECT_EQ(mat->Specular(), math::Color(0.0f, 0.0f, 0.0f, 1.0f));
EXPECT_DOUBLE_EQ(mat->Transparency(), 0.0);
}
Binary file added test/data/box.fbx
Binary file not shown.
Binary file added test/data/box.glb
Binary file not shown.