From 336aa204fb271ae977e562e842a9da2c2ba7c17c Mon Sep 17 00:00:00 2001 From: JosiahWI Date: Mon, 17 Oct 2022 07:34:19 -0500 Subject: [PATCH] Test that minimal triangle has correct vertices --- source/Irrlicht/CGLTFMeshFileLoader.cpp | 21 +++++++++++++++++-- .../tests/testCGLTFMeshFileLoader.cpp | 16 ++++++++++---- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/source/Irrlicht/CGLTFMeshFileLoader.cpp b/source/Irrlicht/CGLTFMeshFileLoader.cpp index 6b1397d9..14e08165 100644 --- a/source/Irrlicht/CGLTFMeshFileLoader.cpp +++ b/source/Irrlicht/CGLTFMeshFileLoader.cpp @@ -1,9 +1,13 @@ #include "CGLTFMeshFileLoader.h" +#include "CMeshBuffer.h" #include "coreutil.h" #include "IAnimatedMesh.h" #include "IReadFile.h" +#include "irrTypes.h" #include "path.h" +#include "S3DVertex.h" #include "SAnimatedMesh.h" +#include "SMesh.h" namespace irr { @@ -28,9 +32,22 @@ IAnimatedMesh* CGLTFMeshFileLoader::createMesh(io::IReadFile* file) } // sorry Bjarne - SAnimatedMesh* mesh { new SAnimatedMesh {} }; + SMeshBuffer* meshbuf { new SMeshBuffer {} }; - return mesh; + const video::S3DVertex* vertices { new video::S3DVertex[3] { + {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, {}, 0.0f, 0.0f}, + {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, {}, 0.0f, 0.0f}, + {1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, {}, 0.0f, 0.0f} } }; + const u16* indices { new u16[3] {} }; + meshbuf->append(vertices, 3, indices, 3); + + SMesh* mesh { new SMesh {} }; + mesh->addMeshBuffer(meshbuf); + + SAnimatedMesh* animatedMesh { new SAnimatedMesh {} }; + animatedMesh->addMesh(mesh); + + return animatedMesh; } } // namespace irr diff --git a/source/Irrlicht/tests/testCGLTFMeshFileLoader.cpp b/source/Irrlicht/tests/testCGLTFMeshFileLoader.cpp index 7dacf2f4..ca357bf8 100644 --- a/source/Irrlicht/tests/testCGLTFMeshFileLoader.cpp +++ b/source/Irrlicht/tests/testCGLTFMeshFileLoader.cpp @@ -7,22 +7,30 @@ TEST_CASE("load empty gltf file") { irr::IrrlichtDevice* device { irr::createDevice(irr::video::EDT_NULL) }; irr::scene::ISceneManager* smgr { device->getSceneManager() }; - irr::io::InMemoryFile filebuf {"test.gltf", ""}; - auto* mesh { smgr->getMesh(&filebuf) }; + CHECK(mesh == nullptr); device->drop(); } -TEST_CASE("load minimal triangle") { +TEST_CASE("minimal triangle has correct vertices") { irr::IrrlichtDevice* device { irr::createDevice(irr::video::EDT_NULL) }; irr::scene::ISceneManager* smgr { device->getSceneManager() }; - auto* mesh { smgr->getMesh( "source/Irrlicht/tests/assets/minimal_triangle.gltf", "") }; + REQUIRE(mesh != nullptr); + REQUIRE(mesh->getMeshBufferCount() == 1); + auto* meshbuf { mesh->getMeshBuffer(0) }; + REQUIRE(meshbuf->getVertexCount() == 3); + irr::video::S3DVertex* vertices { + reinterpret_cast( + meshbuf->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 {1.0f, 1.0f, 0.0f}); device->drop(); }