|
|
|
@ -24,7 +24,9 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
#include <sstream> |
|
|
|
#include <sstream> |
|
|
|
|
|
|
|
#include <Corrade/Containers/StridedArrayView.h> |
|
|
|
#include <Corrade/TestSuite/Tester.h> |
|
|
|
#include <Corrade/TestSuite/Tester.h> |
|
|
|
|
|
|
|
#include <Corrade/TestSuite/Compare/Container.h> |
|
|
|
#include <Corrade/Utility/DebugStl.h> |
|
|
|
#include <Corrade/Utility/DebugStl.h> |
|
|
|
|
|
|
|
|
|
|
|
#include "Magnum/Math/Vector3.h" |
|
|
|
#include "Magnum/Math/Vector3.h" |
|
|
|
@ -36,44 +38,69 @@ struct FlipNormalsTest: TestSuite::Tester { |
|
|
|
explicit FlipNormalsTest(); |
|
|
|
explicit FlipNormalsTest(); |
|
|
|
|
|
|
|
|
|
|
|
void wrongIndexCount(); |
|
|
|
void wrongIndexCount(); |
|
|
|
void flipFaceWinding(); |
|
|
|
template<class T> void flipFaceWinding(); |
|
|
|
void flipNormals(); |
|
|
|
void flipNormals(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T> void flipNormalsFaceWinding(); |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
FlipNormalsTest::FlipNormalsTest() { |
|
|
|
FlipNormalsTest::FlipNormalsTest() { |
|
|
|
addTests({&FlipNormalsTest::wrongIndexCount, |
|
|
|
addTests({&FlipNormalsTest::wrongIndexCount, |
|
|
|
&FlipNormalsTest::flipFaceWinding, |
|
|
|
&FlipNormalsTest::flipFaceWinding<UnsignedByte>, |
|
|
|
&FlipNormalsTest::flipNormals}); |
|
|
|
&FlipNormalsTest::flipFaceWinding<UnsignedShort>, |
|
|
|
|
|
|
|
&FlipNormalsTest::flipFaceWinding<UnsignedInt>, |
|
|
|
|
|
|
|
&FlipNormalsTest::flipNormals, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
&FlipNormalsTest::flipNormalsFaceWinding<UnsignedByte>, |
|
|
|
|
|
|
|
&FlipNormalsTest::flipNormalsFaceWinding<UnsignedShort>, |
|
|
|
|
|
|
|
&FlipNormalsTest::flipNormalsFaceWinding<UnsignedInt>}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void FlipNormalsTest::wrongIndexCount() { |
|
|
|
void FlipNormalsTest::wrongIndexCount() { |
|
|
|
std::stringstream ss; |
|
|
|
std::stringstream ss; |
|
|
|
Error redirectError{&ss}; |
|
|
|
Error redirectError{&ss}; |
|
|
|
|
|
|
|
|
|
|
|
std::vector<UnsignedInt> indices{0, 1}; |
|
|
|
UnsignedByte indices[2]; |
|
|
|
MeshTools::flipFaceWinding(indices); |
|
|
|
MeshTools::flipFaceWindingInPlace(Containers::stridedArrayView(indices)); |
|
|
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE(ss.str(), "MeshTools::flipNormals(): index count is not divisible by 3!\n"); |
|
|
|
CORRADE_COMPARE(ss.str(), "MeshTools::flipNormals(): index count is not divisible by 3!\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void FlipNormalsTest::flipFaceWinding() { |
|
|
|
template<class T> void FlipNormalsTest::flipFaceWinding() { |
|
|
|
std::vector<UnsignedInt> indices{0, 1, 2, |
|
|
|
setTestCaseTemplateName(Math::TypeTraits<T>::name()); |
|
|
|
3, 4, 5}; |
|
|
|
|
|
|
|
MeshTools::flipFaceWinding(indices); |
|
|
|
T indices[]{0, 1, 2, 3, 4, 5}; |
|
|
|
|
|
|
|
MeshTools::flipFaceWindingInPlace(indices); |
|
|
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE(indices, (std::vector<UnsignedInt>{0, 2, 1, |
|
|
|
CORRADE_COMPARE_AS(Containers::arrayView(indices), |
|
|
|
3, 5, 4})); |
|
|
|
Containers::arrayView<T>({0, 2, 1, 3, 5, 4}), |
|
|
|
|
|
|
|
TestSuite::Compare::Container); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void FlipNormalsTest::flipNormals() { |
|
|
|
void FlipNormalsTest::flipNormals() { |
|
|
|
std::vector<Vector3> normals{Vector3::xAxis(), |
|
|
|
Vector3 normals[]{Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis()}; |
|
|
|
Vector3::yAxis(), |
|
|
|
MeshTools::flipNormalsInPlace(normals); |
|
|
|
Vector3::zAxis()}; |
|
|
|
|
|
|
|
MeshTools::flipNormals(normals); |
|
|
|
CORRADE_COMPARE_AS(Containers::arrayView(normals), |
|
|
|
|
|
|
|
Containers::arrayView<Vector3>({ |
|
|
|
CORRADE_COMPARE(normals, (std::vector<Vector3>{-Vector3::xAxis(), |
|
|
|
-Vector3::xAxis(), -Vector3::yAxis(), -Vector3::zAxis() |
|
|
|
-Vector3::yAxis(), |
|
|
|
}), TestSuite::Compare::Container); |
|
|
|
-Vector3::zAxis()})); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<class T> void FlipNormalsTest::flipNormalsFaceWinding() { |
|
|
|
|
|
|
|
setTestCaseTemplateName(Math::TypeTraits<T>::name()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
T indices[]{0, 1, 2, 3, 4, 5}; |
|
|
|
|
|
|
|
Vector3 normals[]{Vector3::xAxis(), Vector3::yAxis(), Vector3::zAxis()}; |
|
|
|
|
|
|
|
MeshTools::flipNormalsInPlace(indices, normals); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CORRADE_COMPARE_AS(Containers::arrayView(indices), |
|
|
|
|
|
|
|
Containers::arrayView<T>({0, 2, 1, 3, 5, 4}), |
|
|
|
|
|
|
|
TestSuite::Compare::Container); |
|
|
|
|
|
|
|
CORRADE_COMPARE_AS(Containers::arrayView(normals), |
|
|
|
|
|
|
|
Containers::arrayView<Vector3>({ |
|
|
|
|
|
|
|
-Vector3::xAxis(), -Vector3::yAxis(), -Vector3::zAxis() |
|
|
|
|
|
|
|
}), TestSuite::Compare::Container); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}}}} |
|
|
|
}}}} |
|
|
|
|