MeshSkin.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #include "MeshSkin.h"
  2. #include "Node.h"
  3. #include "StringUtil.h"
  4. namespace gameplay
  5. {
  6. MeshSkin::MeshSkin(void) :
  7. _vertexInfluenceCount(0)
  8. {
  9. setIdentityMatrix(_bindShape);
  10. }
  11. MeshSkin::~MeshSkin(void)
  12. {
  13. }
  14. unsigned int MeshSkin::getTypeId(void) const
  15. {
  16. return MESHPART_ID;
  17. }
  18. const char* MeshSkin::getElementName(void) const
  19. {
  20. return "MeshSkin";
  21. }
  22. void MeshSkin::writeBinary(FILE* file)
  23. {
  24. Object::writeBinary(file);
  25. write(_bindShape, 16, file);
  26. write(_joints.size(), file);
  27. for (std::list<Node*>::const_iterator i = _joints.begin(); i != _joints.end(); i++)
  28. {
  29. (*i)->writeBinaryXref(file);
  30. }
  31. write(_bindPoses, file);
  32. }
  33. void MeshSkin::writeText(FILE* file)
  34. {
  35. fprintElementStart(file);
  36. fprintf(file, "<bindShape>");
  37. fprintfMatrix4f(file, _bindShape);
  38. fprintf(file, "</bindShape>");
  39. fprintf(file, "<joints>");
  40. for (std::list<std::string>::const_iterator i = _jointNames.begin(); i != _jointNames.end(); i++)
  41. {
  42. fprintf(file, "%s ", i->c_str());
  43. }
  44. fprintf(file, "</joints>\n");
  45. fprintf(file, "<bindPoses count=\"%lu\">", _bindPoses.size());
  46. for (std::list<float>::const_iterator i = _bindPoses.begin(); i != _bindPoses.end(); i++)
  47. {
  48. fprintf(file, "%f ", *i);
  49. }
  50. fprintf(file, "</bindPoses>\n");
  51. fprintElementEnd(file);
  52. }
  53. void MeshSkin::setBindShape(const float data[])
  54. {
  55. for (int i = 0; i < 16; i++)
  56. {
  57. _bindShape[i] = data[i];
  58. }
  59. }
  60. void MeshSkin::setVertexInfluenceCount(unsigned int count)
  61. {
  62. _vertexInfluenceCount = count;
  63. }
  64. void MeshSkin::setJointNames(const std::list<std::string>& list)
  65. {
  66. _jointNames = list;
  67. }
  68. const std::list<std::string>& MeshSkin::getJointNames()
  69. {
  70. return _jointNames;
  71. }
  72. void MeshSkin::setJoints(const std::list<Node*>& list)
  73. {
  74. _joints = list;
  75. }
  76. void MeshSkin::setBindPoses(std::vector<Matrix>& list)
  77. {
  78. for (std::vector<Matrix>::iterator i = list.begin(); i != list.end(); i++)
  79. {
  80. float* a = i->m;
  81. for (int j = 0; j < 16; j++)
  82. {
  83. _bindPoses.push_back(a[j]);
  84. }
  85. }
  86. }
  87. bool MeshSkin::hasJoint(const char* id)
  88. {
  89. for (std::list<std::string>::iterator i = _jointNames.begin(); i != _jointNames.end(); i++)
  90. {
  91. if (equals(*i, id))
  92. {
  93. return true;
  94. }
  95. }
  96. return false;
  97. }
  98. }