No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 
 
 

97 líneas
2.9 KiB

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