mirror of
https://github.com/minetest/irrlicht.git
synced 2025-07-02 00:00:26 +02:00
Add test for blender cube
This commit is contained in:
@ -1,5 +1,3 @@
|
||||
#include "inMemoryFile.h"
|
||||
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include <catch.hpp>
|
||||
#include <irrlicht.h>
|
||||
@ -40,53 +38,70 @@ private:
|
||||
};
|
||||
|
||||
TEST_CASE("load empty gltf file") {
|
||||
irr::io::InMemoryFile filebuf {"test.gltf", ""};
|
||||
ScopedMesh sm { &filebuf };
|
||||
ScopedMesh sm("source/Irrlicht/tests/assets/empty.gltf");
|
||||
CHECK(sm.getMesh() == nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE("minimal triangle") {
|
||||
ScopedMesh sm { "source/Irrlicht/tests/assets/minimal_triangle.gltf" };
|
||||
|
||||
auto* mesh = sm.getMesh();
|
||||
REQUIRE(mesh != nullptr);
|
||||
REQUIRE(mesh->getMeshBufferCount() == 1);
|
||||
auto* meshbuf = mesh->getMeshBuffer(0);
|
||||
ScopedMesh sm("source/Irrlicht/tests/assets/minimal_triangle.gltf");
|
||||
REQUIRE(sm.getMesh() != nullptr);
|
||||
REQUIRE(sm.getMesh()->getMeshBufferCount() == 1);
|
||||
|
||||
SECTION("vertex coordinates are correct") {
|
||||
REQUIRE(meshbuf->getVertexCount() == 3);
|
||||
auto* vertices = reinterpret_cast<irr::video::S3DVertex*>(
|
||||
meshbuf->getVertices());
|
||||
REQUIRE(sm.getMesh()->getMeshBuffer(0)->getVertexCount() == 3);
|
||||
const auto* vertices = reinterpret_cast<irr::video::S3DVertex*>(
|
||||
sm.getMesh()->getMeshBuffer(0)->getVertices());
|
||||
CHECK(vertices[0].Pos == irr::core::vector3df {0.0f, 0.0f, 0.0f});
|
||||
CHECK(vertices[1].Pos == irr::core::vector3df {-1.0f, 0.0f, 0.0f});
|
||||
CHECK(vertices[2].Pos == irr::core::vector3df {0.0f, 1.0f, 0.0f});
|
||||
}
|
||||
|
||||
SECTION("vertex indices are correct") {
|
||||
REQUIRE(meshbuf->getIndexCount() == 3);
|
||||
auto* indices = reinterpret_cast<irr::u16*>(meshbuf->getIndices());
|
||||
REQUIRE(sm.getMesh()->getMeshBuffer(0)->getIndexCount() == 3);
|
||||
const auto* indices = reinterpret_cast<irr::u16*>(
|
||||
sm.getMesh()->getMeshBuffer(0)->getIndices());
|
||||
CHECK(indices[0] == 0);
|
||||
CHECK(indices[1] == 1);
|
||||
CHECK(indices[2] == 2);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("blender cube") {
|
||||
ScopedMesh sm("source/Irrlicht/tests/assets/blender_cube.gltf");
|
||||
REQUIRE(sm.getMesh() != nullptr);
|
||||
REQUIRE(sm.getMesh()->getMeshBufferCount() == 1);
|
||||
SECTION("vertex coordinates are correct") {
|
||||
REQUIRE(sm.getMesh()->getMeshBuffer(0)->getVertexCount() == 24);
|
||||
const auto* vertices = reinterpret_cast<irr::video::S3DVertex*>(
|
||||
sm.getMesh()->getMeshBuffer(0)->getVertices());
|
||||
CHECK(vertices[0].Pos == irr::core::vector3df{1.0f, -1.0f, 1.0f});
|
||||
CHECK(vertices[3].Pos == irr::core::vector3df{1.0f, 1.0f, 1.0f});
|
||||
CHECK(vertices[6].Pos == irr::core::vector3df{1.0f, -1.0f, -1.0f});
|
||||
CHECK(vertices[9].Pos == irr::core::vector3df{1.0f, 1.0f, -1.0f});
|
||||
CHECK(vertices[12].Pos == irr::core::vector3df{-1.0f, -1.0f, 1.0f});
|
||||
CHECK(vertices[15].Pos == irr::core::vector3df{-1.0f, 1.0f, 1.0f});
|
||||
CHECK(vertices[18].Pos == irr::core::vector3df{-1.0f, -1.0f, -1.0f});
|
||||
CHECK(vertices[21].Pos == irr::core::vector3df{-1.0f, 1.0f, -1.0f});
|
||||
}
|
||||
|
||||
SECTION("vertex indices are correct")
|
||||
{
|
||||
REQUIRE(sm.getMesh()->getMeshBuffer(0)->getIndexCount() == 36);
|
||||
const auto* indices = reinterpret_cast<irr::u16*>(
|
||||
sm.getMesh()->getMeshBuffer(0)->getIndices());
|
||||
CHECK(indices[0] == 0);
|
||||
CHECK(indices[1] == 3);
|
||||
CHECK(indices[2] == 9);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("mesh loader returns nullptr when given null file pointer") {
|
||||
ScopedMesh sm { nullptr };
|
||||
ScopedMesh sm(nullptr);
|
||||
CHECK(sm.getMesh() == nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE("invalid JSON returns nullptr") {
|
||||
SECTION("missing closing brace") {
|
||||
irr::io::InMemoryFile filebuf {"test.gltf", "{"};
|
||||
ScopedMesh sm { &filebuf };
|
||||
CHECK(sm.getMesh() == nullptr);
|
||||
}
|
||||
|
||||
SECTION("missing colon") {
|
||||
irr::io::InMemoryFile filebuf {"test.gltf", "{\"a\" \"b\"}"};
|
||||
ScopedMesh sm { &filebuf };
|
||||
CHECK(sm.getMesh() == nullptr);
|
||||
}
|
||||
ScopedMesh sm("source/Irrlicht/tests/assets/json_missing_brace.gltf");
|
||||
CHECK(sm.getMesh() == nullptr);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user