Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

86 рядки
2.4 KiB

  1. #include "UnitTestPCH.h"
  2. #include "utLimitBoneWeights.h"
  3. CPPUNIT_TEST_SUITE_REGISTRATION (LimitBoneWeightsTest);
  4. // ------------------------------------------------------------------------------------------------
  5. void LimitBoneWeightsTest :: setUp (void)
  6. {
  7. // construct the process
  8. this->piProcess = new LimitBoneWeightsProcess();
  9. // now need to create a nice mesh for testing purposes
  10. this->pcMesh = new aiMesh();
  11. pcMesh->mNumVertices = 500;
  12. pcMesh->mVertices = new aiVector3D[500]; // uninit.
  13. pcMesh->mNumBones = 30;
  14. pcMesh->mBones = new aiBone*[30];
  15. unsigned int iCur = 0;
  16. for (unsigned int i = 0; i < 30;++i)
  17. {
  18. aiBone* pc = pcMesh->mBones[i] = new aiBone();
  19. pc->mNumWeights = 250;
  20. pc->mWeights = new aiVertexWeight[pc->mNumWeights];
  21. for (unsigned int qq = 0; qq < pc->mNumWeights;++qq)
  22. {
  23. aiVertexWeight& v = pc->mWeights[qq];
  24. v.mVertexId = iCur++;
  25. if (500 == iCur)iCur = 0;
  26. v.mWeight = 1.0f / 15; // each vertex should occur once in two bones
  27. }
  28. }
  29. }
  30. // ------------------------------------------------------------------------------------------------
  31. void LimitBoneWeightsTest :: tearDown (void)
  32. {
  33. delete pcMesh;
  34. delete piProcess;
  35. }
  36. // ------------------------------------------------------------------------------------------------
  37. void LimitBoneWeightsTest :: testProcess(void)
  38. {
  39. // execute the step on the given data
  40. piProcess->ProcessMesh(pcMesh);
  41. // check whether everything is ok ...
  42. typedef std::vector<LimitBoneWeightsProcess::Weight> VertexWeightList;
  43. VertexWeightList* asWeights = new VertexWeightList[pcMesh->mNumVertices];
  44. for (unsigned int i = 0; i < pcMesh->mNumVertices;++i)
  45. asWeights[i].reserve(4);
  46. // sort back as per-vertex lists
  47. for (unsigned int i = 0; i < pcMesh->mNumBones;++i)
  48. {
  49. aiBone& pcBone = **(pcMesh->mBones+i);
  50. for (unsigned int q = 0; q < pcBone.mNumWeights;++q)
  51. {
  52. aiVertexWeight weight = pcBone.mWeights[q];
  53. asWeights[weight.mVertexId].push_back(LimitBoneWeightsProcess::Weight (i,weight.mWeight));
  54. }
  55. }
  56. // now validate the size of the lists and check whether all weights sum to 1.0f
  57. for (unsigned int i = 0; i < pcMesh->mNumVertices;++i)
  58. {
  59. CPPUNIT_ASSERT( asWeights[i].size() <= 4 );
  60. float fSum = 0.0f;
  61. for (VertexWeightList::const_iterator
  62. iter = asWeights[i].begin();
  63. iter != asWeights[i].end();++iter)
  64. {
  65. fSum += (*iter).mWeight;
  66. }
  67. CPPUNIT_ASSERT( fSum >= 0.95 && fSum <= 1.04);
  68. }
  69. // delete allocated storage
  70. delete[] asWeights;
  71. // everything seems to be OK
  72. }