Vertex.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include "Base.h"
  2. #include "Vertex.h"
  3. namespace gameplay
  4. {
  5. Vertex::Vertex(void)
  6. : hasNormal(false), hasTangent(false), hasBinormal(false), hasTexCoord(false), hasDiffuse(false), hasWeights(false)
  7. {
  8. }
  9. Vertex::~Vertex(void)
  10. {
  11. }
  12. unsigned int Vertex::byteSize() const
  13. {
  14. unsigned int count = POSITION_COUNT;
  15. if (hasNormal)
  16. count += NORMAL_COUNT;
  17. if (hasTangent)
  18. count += TANGENT_COUNT;
  19. if (hasBinormal)
  20. count += BINORMAL_COUNT;
  21. if (hasTexCoord)
  22. count += TEXCOORD_COUNT;
  23. if (hasWeights)
  24. count += BLEND_WEIGHTS_COUNT + BLEND_INDICES_COUNT;
  25. if (hasDiffuse)
  26. count += DIFFUSE_COUNT;
  27. return count * sizeof(float);
  28. }
  29. void Vertex::writeBinary(FILE* file) const
  30. {
  31. writeVectorBinary(position, file);
  32. if (hasNormal)
  33. {
  34. writeVectorBinary(normal, file);
  35. }
  36. if (hasTangent)
  37. {
  38. writeVectorBinary(tangent, file);
  39. }
  40. if (hasBinormal)
  41. {
  42. writeVectorBinary(binormal, file);
  43. }
  44. if (hasTexCoord)
  45. {
  46. writeVectorBinary(texCoord, file);
  47. }
  48. if (hasDiffuse)
  49. {
  50. writeVectorBinary(diffuse, file);
  51. }
  52. if (hasWeights)
  53. {
  54. writeVectorBinary(blendWeights, file);
  55. writeVectorBinary(blendIndices, file);
  56. }
  57. }
  58. void Vertex::writeText(FILE* file) const
  59. {
  60. write("// position\n", file);
  61. writeVectorText(position, file);
  62. if (hasNormal)
  63. {
  64. write("// normal\n", file);
  65. writeVectorText(normal, file);
  66. }
  67. if (hasTangent)
  68. {
  69. write("// tanget\n", file);
  70. writeVectorText(tangent, file);
  71. }
  72. if (hasBinormal)
  73. {
  74. write("// binormal\n", file);
  75. writeVectorText(binormal, file);
  76. }
  77. if (hasTexCoord)
  78. {
  79. write("// texCoord\n", file);
  80. writeVectorText(texCoord, file);
  81. }
  82. if (hasDiffuse)
  83. {
  84. write("// diffuse\n", file);
  85. writeVectorText(diffuse, file);
  86. }
  87. if (hasWeights)
  88. {
  89. write("// blendWeights\n", file);
  90. writeVectorText(blendWeights, file);
  91. write("// blendIndices\n", file);
  92. writeVectorText(blendIndices, file);
  93. }
  94. }
  95. void Vertex::normalizeBlendWeight()
  96. {
  97. float total = blendWeights.x + blendWeights.y + blendWeights.z + blendWeights.w;
  98. if (total > 0.0f)
  99. {
  100. blendWeights.x = blendWeights.x / total;
  101. blendWeights.y = blendWeights.y / total;
  102. blendWeights.z = blendWeights.z / total;
  103. blendWeights.w = blendWeights.w / total;
  104. }
  105. }
  106. }