utLimitBoneWeights.cpp 2.2 KB

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