You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

138 lines
4.4 KiB

  1. #include "UnitTestPCH.h"
  2. #include "utScenePreprocessor.h"
  3. CPPUNIT_TEST_SUITE_REGISTRATION (ScenePreprocessorTest);
  4. // ------------------------------------------------------------------------------------------------
  5. void ScenePreprocessorTest::setUp (void)
  6. {
  7. // setup a dummy scene with a single node
  8. scene = new aiScene();
  9. scene->mRootNode = new aiNode();
  10. scene->mRootNode->mName.Set("<test>");
  11. // add some translation
  12. scene->mRootNode->mTransformation.a4 = 1.f;
  13. scene->mRootNode->mTransformation.b4 = 2.f;
  14. scene->mRootNode->mTransformation.c4 = 3.f;
  15. // and allocate a ScenePreprocessor to operate on the scene
  16. pp = new ScenePreprocessor(scene);
  17. }
  18. // ------------------------------------------------------------------------------------------------
  19. void ScenePreprocessorTest::tearDown (void)
  20. {
  21. delete pp;
  22. delete scene;
  23. }
  24. // ------------------------------------------------------------------------------------------------
  25. // Check whether ProcessMesh() returns flag for a mesh that consist of primitives with num indices
  26. void ScenePreprocessorTest::CheckIfOnly(aiMesh* p,unsigned int num, unsigned int flag)
  27. {
  28. // Triangles only
  29. for (unsigned i = 0; i < p->mNumFaces;++i) {
  30. p->mFaces[i].mNumIndices = num;
  31. }
  32. pp->ProcessMesh(p);
  33. CPPUNIT_ASSERT(p->mPrimitiveTypes == flag);
  34. p->mPrimitiveTypes = 0;
  35. }
  36. // ------------------------------------------------------------------------------------------------
  37. // Check whether a mesh is preprocessed correctly. Case 1: The mesh needs preprocessing
  38. void ScenePreprocessorTest::testMeshPreprocessingPos (void)
  39. {
  40. aiMesh* p = new aiMesh();
  41. p->mNumFaces = 100;
  42. p->mFaces = new aiFace[p->mNumFaces];
  43. p->mTextureCoords[0] = new aiVector3D[10];
  44. p->mNumUVComponents[0] = 0;
  45. p->mNumUVComponents[1] = 0;
  46. CheckIfOnly(p,1,aiPrimitiveType_POINT);
  47. CheckIfOnly(p,2,aiPrimitiveType_LINE);
  48. CheckIfOnly(p,3,aiPrimitiveType_TRIANGLE);
  49. CheckIfOnly(p,4,aiPrimitiveType_POLYGON);
  50. CheckIfOnly(p,1249,aiPrimitiveType_POLYGON);
  51. // Polygons and triangles mixed
  52. unsigned i;
  53. for (i = 0; i < p->mNumFaces/2;++i) {
  54. p->mFaces[i].mNumIndices = 3;
  55. }
  56. for (; i < p->mNumFaces-p->mNumFaces/4;++i) {
  57. p->mFaces[i].mNumIndices = 4;
  58. }
  59. for (; i < p->mNumFaces;++i) {
  60. p->mFaces[i].mNumIndices = 10;
  61. }
  62. pp->ProcessMesh(p);
  63. CPPUNIT_ASSERT(p->mPrimitiveTypes == (aiPrimitiveType_TRIANGLE|aiPrimitiveType_POLYGON));
  64. CPPUNIT_ASSERT(p->mNumUVComponents[0] == 2);
  65. CPPUNIT_ASSERT(p->mNumUVComponents[1] == 0);
  66. delete p;
  67. }
  68. // ------------------------------------------------------------------------------------------------
  69. // Check whether a mesh is preprocessed correctly. Case 1: The mesh doesn't need preprocessing
  70. void ScenePreprocessorTest::testMeshPreprocessingNeg (void)
  71. {
  72. aiMesh* p = new aiMesh();
  73. p->mPrimitiveTypes = aiPrimitiveType_TRIANGLE|aiPrimitiveType_POLYGON;
  74. pp->ProcessMesh(p);
  75. // should be unmodified
  76. CPPUNIT_ASSERT(p->mPrimitiveTypes == (aiPrimitiveType_TRIANGLE|aiPrimitiveType_POLYGON));
  77. delete p;
  78. }
  79. // ------------------------------------------------------------------------------------------------
  80. // Make a dummy animation with a single channel, '<test>'
  81. aiAnimation* MakeDummyAnimation()
  82. {
  83. aiAnimation* p = new aiAnimation();
  84. p->mNumChannels = 1;
  85. p->mChannels = new aiNodeAnim*[1];
  86. aiNodeAnim* anim = p->mChannels[0] = new aiNodeAnim();
  87. anim->mNodeName.Set("<test>");
  88. return p;
  89. }
  90. // ------------------------------------------------------------------------------------------------
  91. // Check whether an anim is preprocessed correctly. Case 1: The anim needs preprocessing
  92. void ScenePreprocessorTest::testAnimationPreprocessingPos (void)
  93. {
  94. aiAnimation* p = MakeDummyAnimation();
  95. aiNodeAnim* anim = p->mChannels[0];
  96. // we don't set the animation duration, but generate scaling channels
  97. anim->mNumScalingKeys = 10;
  98. anim->mScalingKeys = new aiVectorKey[10];
  99. for (unsigned int i = 0; i < 10;++i) {
  100. anim->mScalingKeys[i].mTime = i;
  101. anim->mScalingKeys[i].mValue = aiVector3D((float)i);
  102. }
  103. pp->ProcessAnimation(p);
  104. // we should now have a proper duration
  105. CPPUNIT_ASSERT_DOUBLES_EQUAL(p->mDuration,9.,0.005);
  106. // ... one scaling key
  107. CPPUNIT_ASSERT(anim->mNumPositionKeys == 1 &&
  108. anim->mPositionKeys &&
  109. anim->mPositionKeys[0].mTime == 0.0 &&
  110. anim->mPositionKeys[0].mValue == aiVector3D(1.f,2.f,3.f));
  111. // ... and one rotation key
  112. CPPUNIT_ASSERT(anim->mNumRotationKeys == 1 && anim->mRotationKeys &&
  113. anim->mRotationKeys[0].mTime == 0.0);
  114. delete p;
  115. }