Skip to content

Commit

Permalink
[Tests/Data/Mesh] Added a basic Mesh unit test
Browse files Browse the repository at this point in the history
- This checks the Mesh's basic behavior

- Computing tangents on an empty mesh is now a no-op
  • Loading branch information
Razakhel committed Sep 2, 2023
1 parent c87096e commit 3ba2dbe
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/RaZ/Data/Mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Mesh : public Component {
void createIcosphere(const Sphere& sphere, uint32_t subdivCount);

std::vector<Submesh> m_submeshes {};
AABB m_boundingBox = AABB(Vec3f(), Vec3f());
AABB m_boundingBox = AABB(Vec3f(0.f), Vec3f(0.f));
};

} // namespace Raz
Expand Down
3 changes: 3 additions & 0 deletions src/RaZ/Data/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,9 @@ const AABB& Mesh::computeBoundingBox() {
}

void Mesh::computeTangents() {
if (m_submeshes.empty())
return;

Threading::parallelize(m_submeshes, [] (const auto& range) noexcept {
for (Submesh& submesh : range) {
for (std::size_t i = 0; i < submesh.getTriangleIndexCount(); i += 3) {
Expand Down
30 changes: 30 additions & 0 deletions tests/src/RaZ/Data/Mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,36 @@

#include "RaZ/Data/Mesh.hpp"

TEST_CASE("Mesh basic") {
Raz::Mesh mesh;
CHECK(mesh.getSubmeshes().empty());
CHECK(mesh.getBoundingBox() == Raz::AABB(Raz::Vec3f(0.f), Raz::Vec3f(0.f)));
CHECK(mesh.recoverVertexCount() == 0);
CHECK(mesh.recoverTriangleCount() == 0);

CHECK_NOTHROW(mesh.computeTangents()); // Attempting to compute tangents for an empty mesh does nothing

const Raz::AABB& boundingBox = mesh.computeBoundingBox();
CHECK(boundingBox == Raz::AABB(Raz::Vec3f(std::numeric_limits<float>::max()), Raz::Vec3f(std::numeric_limits<float>::lowest())));
CHECK(boundingBox == mesh.getBoundingBox());

Raz::Submesh& submesh = mesh.addSubmesh();
CHECK(mesh.getSubmeshes().size() == 1);

submesh.getVertices() = {
Raz::Vertex{ Raz::Vec3f(-1.f) },
Raz::Vertex{ Raz::Vec3f(0.f) },
Raz::Vertex{ Raz::Vec3f(1.f) }
};
submesh.getTriangleIndices() = { 0, 1, 2 };
CHECK(mesh.recoverVertexCount() == 3);
CHECK(mesh.recoverTriangleCount() == 1);

mesh.computeBoundingBox();
CHECK(boundingBox == Raz::AABB(Raz::Vec3f(-1.f), Raz::Vec3f(1.f)));
CHECK(boundingBox == mesh.getBoundingBox());
}

TEST_CASE("Mesh plane") {
const Raz::Plane plane(1.5f, Raz::Axis::Y);

Expand Down

0 comments on commit 3ba2dbe

Please sign in to comment.