|
|
|
|
@ -26,7 +26,7 @@
|
|
|
|
|
#include <Corrade/TestSuite/Tester.h> |
|
|
|
|
#include <Corrade/TestSuite/Compare/Container.h> |
|
|
|
|
|
|
|
|
|
#include "Magnum/Math/Vector3.h" |
|
|
|
|
#include "Magnum/Math/Vector4.h" |
|
|
|
|
#include "Magnum/Primitives/Cylinder.h" |
|
|
|
|
#include "Magnum/Trade/MeshData.h" |
|
|
|
|
|
|
|
|
|
@ -37,17 +37,30 @@ struct CylinderTest: TestSuite::Tester {
|
|
|
|
|
|
|
|
|
|
void solidWithoutAnything(); |
|
|
|
|
void solidWithCaps(); |
|
|
|
|
void solidWithTextureCoords(); |
|
|
|
|
void solidWithTextureCoordsAndCaps(); |
|
|
|
|
void solidWithTextureCoordinatesOrTangents(); |
|
|
|
|
void solidWithTextureCoordinatesOrTangentsAndCaps(); |
|
|
|
|
void wireframe(); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
constexpr struct { |
|
|
|
|
const char* name; |
|
|
|
|
CylinderFlags flags; |
|
|
|
|
} TextureCoordinatesOrTangentsData[] { |
|
|
|
|
{"texture coordinates", CylinderFlag::TextureCoordinates}, |
|
|
|
|
{"tangents", CylinderFlag::Tangents}, |
|
|
|
|
{"both", CylinderFlag::TextureCoordinates|CylinderFlag::Tangents} |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
CylinderTest::CylinderTest() { |
|
|
|
|
addTests({&CylinderTest::solidWithoutAnything, |
|
|
|
|
&CylinderTest::solidWithCaps, |
|
|
|
|
&CylinderTest::solidWithTextureCoords, |
|
|
|
|
&CylinderTest::solidWithTextureCoordsAndCaps, |
|
|
|
|
&CylinderTest::wireframe}); |
|
|
|
|
&CylinderTest::solidWithCaps}); |
|
|
|
|
|
|
|
|
|
addInstancedTests({ |
|
|
|
|
&CylinderTest::solidWithTextureCoordinatesOrTangents, |
|
|
|
|
&CylinderTest::solidWithTextureCoordinatesOrTangentsAndCaps}, |
|
|
|
|
Containers::arraySize(TextureCoordinatesOrTangentsData)); |
|
|
|
|
|
|
|
|
|
addTests({&CylinderTest::wireframe}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CylinderTest::solidWithoutAnything() { |
|
|
|
|
@ -162,12 +175,14 @@ void CylinderTest::solidWithCaps() {
|
|
|
|
|
}), TestSuite::Compare::Container); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CylinderTest::solidWithTextureCoords() { |
|
|
|
|
Trade::MeshData cylinder = cylinderSolid(2, 3, 1.5f, CylinderFlag::TextureCoordinates); |
|
|
|
|
void CylinderTest::solidWithTextureCoordinatesOrTangents() { |
|
|
|
|
auto&& data = TextureCoordinatesOrTangentsData[testCaseInstanceId()]; |
|
|
|
|
setTestCaseDescription(data.name); |
|
|
|
|
|
|
|
|
|
Trade::MeshData cylinder = cylinderSolid(2, 3, 1.5f, data.flags); |
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE(cylinder.primitive(), MeshPrimitive::Triangles); |
|
|
|
|
CORRADE_VERIFY(cylinder.isIndexed()); |
|
|
|
|
CORRADE_COMPARE(cylinder.attributeCount(), 3); |
|
|
|
|
|
|
|
|
|
/* First vertex of each ring duplicated because it has different texture
|
|
|
|
|
coordinates */ |
|
|
|
|
@ -188,6 +203,25 @@ void CylinderTest::solidWithTextureCoords() {
|
|
|
|
|
{0.0f, 1.5f, 1.0f}, /* 11 */ |
|
|
|
|
}), TestSuite::Compare::Container); |
|
|
|
|
|
|
|
|
|
if(data.flags & CylinderFlag::Tangents) { |
|
|
|
|
CORRADE_COMPARE_AS(cylinder.attribute<Vector4>(Trade::MeshAttribute::Tangent), Containers::arrayView<Vector4>({ |
|
|
|
|
{1.0f, 0.0f, 0.0f, 1.0f}, /* 0 */ |
|
|
|
|
{-0.5f, 0.0f, -0.866025f, 1.0f}, /* 1 */ |
|
|
|
|
{-0.5f, 0.0f, 0.866025f, 1.0f}, /* 2 */ |
|
|
|
|
{1.0f, 0.0f, 0.0f, 1.0f}, /* 3 */ |
|
|
|
|
|
|
|
|
|
{1.0f, 0.0f, 0.0f, 1.0f}, /* 4 */ |
|
|
|
|
{-0.5f, 0.0f, -0.866025f, 1.0f}, /* 5 */ |
|
|
|
|
{-0.5f, 0.0f, 0.866025f, 1.0f}, /* 6 */ |
|
|
|
|
{1.0f, 0.0f, 0.0f, 1.0f}, /* 7 */ |
|
|
|
|
|
|
|
|
|
{1.0f, 0.0f, 0.0f, 1.0f}, /* 8 */ |
|
|
|
|
{-0.5f, 0.0f, -0.866025f, 1.0f}, /* 9 */ |
|
|
|
|
{-0.5f, 0.0f, 0.866025f, 1.0f}, /* 10 */ |
|
|
|
|
{1.0f, 0.0f, 0.0f, 1.0f} /* 11 */ |
|
|
|
|
}), TestSuite::Compare::Container); |
|
|
|
|
} else CORRADE_VERIFY(!cylinder.hasAttribute(Trade::MeshAttribute::Tangent)); |
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE_AS(cylinder.attribute<Vector3>(Trade::MeshAttribute::Normal), Containers::arrayView<Vector3>({ |
|
|
|
|
{0.0f, 0.0f, 1.0f}, /* 0 */ |
|
|
|
|
{0.866025f, 0.0f, -0.5f}, /* 1 */ |
|
|
|
|
@ -205,22 +239,37 @@ void CylinderTest::solidWithTextureCoords() {
|
|
|
|
|
{0.0f, 0.0f, 1.0f}, /* 11 */ |
|
|
|
|
}), TestSuite::Compare::Container); |
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE_AS(cylinder.attribute<Vector2>(Trade::MeshAttribute::TextureCoordinates), Containers::arrayView<Vector2>({ |
|
|
|
|
{0.0f, 0.0f}, /* 0 */ |
|
|
|
|
{0.333333f, 0.0f}, /* 1 */ |
|
|
|
|
{0.666667f, 0.0f}, /* 2 */ |
|
|
|
|
{1.0f, 0.0f}, /* 3 */ |
|
|
|
|
|
|
|
|
|
{0.0f, 0.5f}, /* 4 */ |
|
|
|
|
{0.333333f, 0.5f}, /* 5 */ |
|
|
|
|
{0.666667f, 0.5f}, /* 6 */ |
|
|
|
|
{1.0f, 0.5f}, /* 7 */ |
|
|
|
|
|
|
|
|
|
{0.0f, 1.0f}, /* 8 */ |
|
|
|
|
{0.333333f, 1.0f}, /* 9 */ |
|
|
|
|
{0.666667f, 1.0f}, /* 10 */ |
|
|
|
|
{1.0f, 1.0f}, /* 11 */ |
|
|
|
|
}), TestSuite::Compare::Container); |
|
|
|
|
if(data.flags & CylinderFlag::TextureCoordinates) { |
|
|
|
|
CORRADE_COMPARE_AS(cylinder.attribute<Vector2>(Trade::MeshAttribute::TextureCoordinates), Containers::arrayView<Vector2>({ |
|
|
|
|
{0.0f, 0.0f}, /* 0 */ |
|
|
|
|
{0.333333f, 0.0f}, /* 1 */ |
|
|
|
|
{0.666667f, 0.0f}, /* 2 */ |
|
|
|
|
{1.0f, 0.0f}, /* 3 */ |
|
|
|
|
|
|
|
|
|
{0.0f, 0.5f}, /* 4 */ |
|
|
|
|
{0.333333f, 0.5f}, /* 5 */ |
|
|
|
|
{0.666667f, 0.5f}, /* 6 */ |
|
|
|
|
{1.0f, 0.5f}, /* 7 */ |
|
|
|
|
|
|
|
|
|
{0.0f, 1.0f}, /* 8 */ |
|
|
|
|
{0.333333f, 1.0f}, /* 9 */ |
|
|
|
|
{0.666667f, 1.0f}, /* 10 */ |
|
|
|
|
{1.0f, 1.0f}, /* 11 */ |
|
|
|
|
}), TestSuite::Compare::Container); |
|
|
|
|
} else CORRADE_VERIFY(!cylinder.hasAttribute(Trade::MeshAttribute::TextureCoordinates)); |
|
|
|
|
|
|
|
|
|
if(data.flags & CylinderFlag::Tangents) { |
|
|
|
|
auto tangents = cylinder.attribute<Vector4>(Trade::MeshAttribute::Tangent); |
|
|
|
|
auto normals = cylinder.attribute<Vector3>(Trade::MeshAttribute::Normal); |
|
|
|
|
for(std::size_t i = 0; i != tangents.size(); ++i) { |
|
|
|
|
CORRADE_ITERATION(i); |
|
|
|
|
CORRADE_ITERATION(tangents[i]); |
|
|
|
|
CORRADE_ITERATION(normals[i]); |
|
|
|
|
CORRADE_VERIFY(tangents[i].xyz().isNormalized()); |
|
|
|
|
CORRADE_VERIFY(normals[i].isNormalized()); |
|
|
|
|
CORRADE_COMPARE(Math::dot(tangents[i].xyz(), normals[i]), 0.0f); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Each ring has an extra vertex for texture coords */ |
|
|
|
|
CORRADE_COMPARE_AS(cylinder.indices<UnsignedInt>(), Containers::arrayView<UnsignedInt>({ |
|
|
|
|
@ -229,12 +278,14 @@ void CylinderTest::solidWithTextureCoords() {
|
|
|
|
|
}), TestSuite::Compare::Container); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CylinderTest::solidWithTextureCoordsAndCaps() { |
|
|
|
|
Trade::MeshData cylinder = cylinderSolid(2, 3, 1.5f, CylinderFlag::TextureCoordinates|CylinderFlag::CapEnds); |
|
|
|
|
void CylinderTest::solidWithTextureCoordinatesOrTangentsAndCaps() { |
|
|
|
|
auto&& data = TextureCoordinatesOrTangentsData[testCaseInstanceId()]; |
|
|
|
|
setTestCaseDescription(data.name); |
|
|
|
|
|
|
|
|
|
Trade::MeshData cylinder = cylinderSolid(2, 3, 1.5f, data.flags|CylinderFlag::CapEnds); |
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE(cylinder.primitive(), MeshPrimitive::Triangles); |
|
|
|
|
CORRADE_VERIFY(cylinder.isIndexed()); |
|
|
|
|
CORRADE_COMPARE(cylinder.attributeCount(), 3); |
|
|
|
|
|
|
|
|
|
/* Bottom ring duplicated because it has different normals, first vertex of
|
|
|
|
|
each ring duplicated because it has different texture coordinates */ |
|
|
|
|
@ -269,6 +320,39 @@ void CylinderTest::solidWithTextureCoordsAndCaps() {
|
|
|
|
|
{0.0f, 1.5f, 0.0f} /* 21 */ |
|
|
|
|
}), TestSuite::Compare::Container); |
|
|
|
|
|
|
|
|
|
if(data.flags & CylinderFlag::Tangents) { |
|
|
|
|
CORRADE_COMPARE_AS(cylinder.attribute<Vector4>(Trade::MeshAttribute::Tangent), Containers::arrayView<Vector4>({ |
|
|
|
|
{-1.0f, 0.0f, 0.0f, 1.0f}, /* 0 */ |
|
|
|
|
|
|
|
|
|
{1.0f, 0.0f, 0.0f, 1.0f}, /* 1 */ |
|
|
|
|
{-0.5f, 0.0f, -0.866025f, 1.0f}, /* 2 */ |
|
|
|
|
{-0.5f, 0.0f, 0.866025f, 1.0f}, /* 3 */ |
|
|
|
|
{1.0f, 0.0f, 0.0f, 1.0f}, /* 4 */ |
|
|
|
|
|
|
|
|
|
{1.0f, 0.0f, 0.0f, 1.0f}, /* 5 */ |
|
|
|
|
{-0.5f, 0.0f, -0.866025f, 1.0f}, /* 6 */ |
|
|
|
|
{-0.5f, 0.0f, 0.866025f, 1.0f}, /* 7 */ |
|
|
|
|
{1.0f, 0.0f, 0.0f, 1.0f}, /* 8 */ |
|
|
|
|
|
|
|
|
|
{1.0f, 0.0f, 0.0f, 1.0f}, /* 9 */ |
|
|
|
|
{-0.5f, 0.0f, -0.866025f, 1.0f}, /* 10 */ |
|
|
|
|
{-0.5f, 0.0f, 0.866025f, 1.0f}, /* 11 */ |
|
|
|
|
{1.0f, 0.0f, 0.0f, 1.0f}, /* 12 */ |
|
|
|
|
|
|
|
|
|
{1.0f, 0.0f, 0.0f, 1.0f}, /* 13 */ |
|
|
|
|
{-0.5f, 0.0f, -0.866025f, 1.0f}, /* 14 */ |
|
|
|
|
{-0.5f, 0.0f, 0.866025f, 1.0f}, /* 15 */ |
|
|
|
|
{1.0f, 0.0f, 0.0f, 1.0f}, /* 16 */ |
|
|
|
|
|
|
|
|
|
{1.0f, 0.0f, 0.0f, 1.0f}, /* 17 */ |
|
|
|
|
{-0.5f, 0.0f, -0.866025f, 1.0f}, /* 18 */ |
|
|
|
|
{-0.5f, 0.0f, 0.866025f, 1.0f}, /* 19 */ |
|
|
|
|
{1.0f, 0.0f, 0.0f, 1.0f}, /* 20 */ |
|
|
|
|
|
|
|
|
|
{1.0f, 0.0f, 0.0f, 1.0f} /* 21 */ |
|
|
|
|
}), TestSuite::Compare::Container); |
|
|
|
|
} else CORRADE_VERIFY(!cylinder.hasAttribute(Trade::MeshAttribute::Tangent)); |
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE_AS(cylinder.attribute<Vector3>(Trade::MeshAttribute::Normal), Containers::arrayView<Vector3>({ |
|
|
|
|
{0.0f, -1.0f, 0.0f}, /* 0 */ |
|
|
|
|
|
|
|
|
|
@ -300,36 +384,51 @@ void CylinderTest::solidWithTextureCoordsAndCaps() {
|
|
|
|
|
{0.0f, 1.0f, 0.0f}, /* 21 */ |
|
|
|
|
}), TestSuite::Compare::Container); |
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE_AS(cylinder.attribute<Vector2>(Trade::MeshAttribute::TextureCoordinates), Containers::arrayView<Vector2>({ |
|
|
|
|
{0.5f, 0.0f}, /* 0 */ |
|
|
|
|
|
|
|
|
|
{0.0f, 0.2f}, /* 1 */ |
|
|
|
|
{0.333333f, 0.2f}, /* 2 */ |
|
|
|
|
{0.666667f, 0.2f}, /* 3 */ |
|
|
|
|
{1.0f, 0.2f}, /* 4 */ |
|
|
|
|
|
|
|
|
|
{0.0f, 0.2f}, /* 5 */ |
|
|
|
|
{0.333333f, 0.2f}, /* 6 */ |
|
|
|
|
{0.666667f, 0.2f}, /* 7 */ |
|
|
|
|
{1.0f, 0.2f}, /* 8 */ |
|
|
|
|
|
|
|
|
|
{0.0f, 0.5f}, /* 9 */ |
|
|
|
|
{0.333333f, 0.5f}, /* 10 */ |
|
|
|
|
{0.666667f, 0.5f}, /* 11 */ |
|
|
|
|
{1.0f, 0.5f}, /* 12 */ |
|
|
|
|
|
|
|
|
|
{0.0f, 0.8f}, /* 13 */ |
|
|
|
|
{0.333333f, 0.8f}, /* 14 */ |
|
|
|
|
{0.666667f, 0.8f}, /* 15 */ |
|
|
|
|
{1.0f, 0.8f}, /* 16 */ |
|
|
|
|
|
|
|
|
|
{0.0f, 0.8f}, /* 17 */ |
|
|
|
|
{0.333333f, 0.8f}, /* 18 */ |
|
|
|
|
{0.666667f, 0.8f}, /* 19 */ |
|
|
|
|
{1.0f, 0.8f}, /* 20 */ |
|
|
|
|
|
|
|
|
|
{0.5f, 1.0f} /* 21 */ |
|
|
|
|
}), TestSuite::Compare::Container); |
|
|
|
|
if(data.flags & CylinderFlag::TextureCoordinates) { |
|
|
|
|
CORRADE_COMPARE_AS(cylinder.attribute<Vector2>(Trade::MeshAttribute::TextureCoordinates), Containers::arrayView<Vector2>({ |
|
|
|
|
{0.5f, 0.0f}, /* 0 */ |
|
|
|
|
|
|
|
|
|
{0.0f, 0.2f}, /* 1 */ |
|
|
|
|
{0.333333f, 0.2f}, /* 2 */ |
|
|
|
|
{0.666667f, 0.2f}, /* 3 */ |
|
|
|
|
{1.0f, 0.2f}, /* 4 */ |
|
|
|
|
|
|
|
|
|
{0.0f, 0.2f}, /* 5 */ |
|
|
|
|
{0.333333f, 0.2f}, /* 6 */ |
|
|
|
|
{0.666667f, 0.2f}, /* 7 */ |
|
|
|
|
{1.0f, 0.2f}, /* 8 */ |
|
|
|
|
|
|
|
|
|
{0.0f, 0.5f}, /* 9 */ |
|
|
|
|
{0.333333f, 0.5f}, /* 10 */ |
|
|
|
|
{0.666667f, 0.5f}, /* 11 */ |
|
|
|
|
{1.0f, 0.5f}, /* 12 */ |
|
|
|
|
|
|
|
|
|
{0.0f, 0.8f}, /* 13 */ |
|
|
|
|
{0.333333f, 0.8f}, /* 14 */ |
|
|
|
|
{0.666667f, 0.8f}, /* 15 */ |
|
|
|
|
{1.0f, 0.8f}, /* 16 */ |
|
|
|
|
|
|
|
|
|
{0.0f, 0.8f}, /* 17 */ |
|
|
|
|
{0.333333f, 0.8f}, /* 18 */ |
|
|
|
|
{0.666667f, 0.8f}, /* 19 */ |
|
|
|
|
{1.0f, 0.8f}, /* 20 */ |
|
|
|
|
|
|
|
|
|
{0.5f, 1.0f} /* 21 */ |
|
|
|
|
}), TestSuite::Compare::Container); |
|
|
|
|
} else CORRADE_VERIFY(!cylinder.hasAttribute(Trade::MeshAttribute::TextureCoordinates)); |
|
|
|
|
|
|
|
|
|
if(data.flags & CylinderFlag::Tangents) { |
|
|
|
|
auto tangents = cylinder.attribute<Vector4>(Trade::MeshAttribute::Tangent); |
|
|
|
|
auto normals = cylinder.attribute<Vector3>(Trade::MeshAttribute::Normal); |
|
|
|
|
for(std::size_t i = 0; i != tangents.size(); ++i) { |
|
|
|
|
CORRADE_ITERATION(i); |
|
|
|
|
CORRADE_ITERATION(tangents[i]); |
|
|
|
|
CORRADE_ITERATION(normals[i]); |
|
|
|
|
CORRADE_VERIFY(tangents[i].xyz().isNormalized()); |
|
|
|
|
CORRADE_VERIFY(normals[i].isNormalized()); |
|
|
|
|
CORRADE_COMPARE(Math::dot(tangents[i].xyz(), normals[i]), 0.0f); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Faces of the caps and sides do not share any vertices due to different
|
|
|
|
|
normals, each ring has an extra vertex for texture coords */ |
|
|
|
|
|