utPretransformVertices.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #include "UnitTestPCH.h"
  2. #include <assimp/scene.h>
  3. #include <PretransformVertices.h>
  4. using namespace std;
  5. using namespace Assimp;
  6. class PretransformVerticesTest : public ::testing::Test
  7. {
  8. public:
  9. virtual void SetUp();
  10. virtual void TearDown();
  11. protected:
  12. aiScene* scene;
  13. PretransformVertices* process;
  14. };
  15. // ------------------------------------------------------------------------------------------------
  16. void AddNodes(unsigned int num, aiNode* father, unsigned int depth)
  17. {
  18. father->mChildren = new aiNode*[father->mNumChildren = 5];
  19. for (unsigned int i = 0; i < 5; ++i) {
  20. aiNode* nd = father->mChildren[i] = new aiNode();
  21. nd->mName.length = sprintf(nd->mName.data,"%i%i",depth,i);
  22. // spawn two meshes
  23. nd->mMeshes = new unsigned int[nd->mNumMeshes = 2];
  24. nd->mMeshes[0] = num*5+i;
  25. nd->mMeshes[1] = 24-(num*5+i); // mesh 12 is special ... it references the same mesh twice
  26. // setup an unique transformation matrix
  27. nd->mTransformation.a1 = num*5.f+i + 1;
  28. }
  29. if (depth > 1) {
  30. for (unsigned int i = 0; i < 5; ++i)
  31. AddNodes(i, father->mChildren[i],depth-1);
  32. }
  33. }
  34. // ------------------------------------------------------------------------------------------------
  35. void PretransformVerticesTest::SetUp()
  36. {
  37. scene = new aiScene();
  38. // add 5 empty materials
  39. scene->mMaterials = new aiMaterial*[scene->mNumMaterials = 5];
  40. for (unsigned int i = 0; i < 5;++i)
  41. scene->mMaterials[i] = new aiMaterial();
  42. // add 25 test meshes
  43. scene->mMeshes = new aiMesh*[scene->mNumMeshes = 25];
  44. for (unsigned int i = 0; i < 25;++i) {
  45. aiMesh* mesh = scene->mMeshes[i] = new aiMesh();
  46. mesh->mPrimitiveTypes = aiPrimitiveType_POINT;
  47. mesh->mFaces = new aiFace[ mesh->mNumFaces = 10+i ];
  48. mesh->mVertices = new aiVector3D[mesh->mNumVertices = mesh->mNumFaces];
  49. for (unsigned int a = 0; a < mesh->mNumFaces; ++a ) {
  50. aiFace& f = mesh->mFaces[a];
  51. f.mIndices = new unsigned int [f.mNumIndices = 1];
  52. f.mIndices[0] = a*3;
  53. mesh->mVertices[a] = aiVector3D((float)i,(float)a,0.f);
  54. }
  55. mesh->mMaterialIndex = i%5;
  56. if (i % 2)
  57. mesh->mNormals = new aiVector3D[mesh->mNumVertices];
  58. }
  59. // construct some nodes (1+25)
  60. scene->mRootNode = new aiNode();
  61. scene->mRootNode->mName.Set("Root");
  62. AddNodes(0,scene->mRootNode,2);
  63. process = new PretransformVertices();
  64. }
  65. // ------------------------------------------------------------------------------------------------
  66. void PretransformVerticesTest::TearDown()
  67. {
  68. delete scene;
  69. delete process;
  70. }
  71. // ------------------------------------------------------------------------------------------------
  72. TEST_F(PretransformVerticesTest, testProcessCollapseHierarchy)
  73. {
  74. process->KeepHierarchy(false);
  75. process->Execute(scene);
  76. EXPECT_EQ(5U, scene->mNumMaterials);
  77. EXPECT_EQ(10U, scene->mNumMeshes); // every second mesh has normals
  78. }
  79. // ------------------------------------------------------------------------------------------------
  80. TEST_F(PretransformVerticesTest, testProcessKeepHierarchy)
  81. {
  82. process->KeepHierarchy(true);
  83. process->Execute(scene);
  84. EXPECT_EQ(5U, scene->mNumMaterials);
  85. EXPECT_EQ(49U, scene->mNumMeshes); // see note on mesh 12 above
  86. }