Vertex.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #ifndef VERTEX_H_
  2. #define VERTEX_H_
  3. #include "FileIO.h"
  4. #include "Vector2.h"
  5. #include "Vector3.h"
  6. #include "Vector4.h"
  7. // Maximum number of supported UV sets
  8. #define MAX_UV_SETS 8
  9. namespace gameplay
  10. {
  11. class Vertex
  12. {
  13. public:
  14. static const unsigned int POSITION_COUNT = 3;
  15. static const unsigned int NORMAL_COUNT = 3;
  16. static const unsigned int TANGENT_COUNT = 3;
  17. static const unsigned int BINORMAL_COUNT = 3;
  18. static const unsigned int TEXCOORD_COUNT = 2;
  19. static const unsigned int DIFFUSE_COUNT = 4;
  20. static const unsigned int BLEND_WEIGHTS_COUNT = 4;
  21. static const unsigned int BLEND_INDICES_COUNT = 4;
  22. /**
  23. * Constructor.
  24. */
  25. Vertex(void);
  26. /**
  27. * Destructor.
  28. */
  29. ~Vertex(void);
  30. Vector3 position;
  31. Vector3 normal;
  32. Vector3 tangent;
  33. Vector3 binormal;
  34. Vector2 texCoord[MAX_UV_SETS];
  35. Vector4 diffuse;
  36. Vector4 blendWeights;
  37. Vector4 blendIndices;
  38. bool hasNormal, hasTangent, hasBinormal, hasTexCoord[MAX_UV_SETS], hasDiffuse, hasWeights;
  39. inline bool operator<(const Vertex& v) const
  40. {
  41. if (position == v.position)
  42. {
  43. if (normal == v.normal)
  44. {
  45. if (tangent == v.tangent)
  46. {
  47. if (binormal == v.binormal)
  48. {
  49. if (diffuse == v.diffuse)
  50. {
  51. if (blendWeights == v.blendWeights)
  52. {
  53. if (blendIndices == v.blendIndices)
  54. {
  55. for (unsigned int i = 0; i < MAX_UV_SETS; ++i)
  56. {
  57. if (!(texCoord[i] == v.texCoord[i]))
  58. return texCoord[i] < v.texCoord[i];
  59. }
  60. return false;
  61. }
  62. return blendIndices < v.blendIndices;
  63. }
  64. return blendWeights < v.blendWeights;
  65. }
  66. return diffuse < v.diffuse;
  67. }
  68. return binormal < v.binormal;
  69. }
  70. return tangent < v.tangent;
  71. }
  72. return normal < v.normal;
  73. }
  74. return position < v.position;
  75. }
  76. inline bool operator==(const Vertex& v) const
  77. {
  78. for (unsigned int i = 0; i < MAX_UV_SETS; ++i)
  79. {
  80. if (!(texCoord[i] == v.texCoord[i]))
  81. return false;
  82. }
  83. return position==v.position && normal==v.normal && tangent==v.tangent && binormal==v.binormal &&
  84. diffuse==v.diffuse && blendWeights==v.blendWeights && blendIndices==v.blendIndices;
  85. }
  86. /**
  87. * Returns the size of this vertex in bytes.
  88. */
  89. unsigned int byteSize() const;
  90. /**
  91. * Writes this vertex to the binary file stream.
  92. */
  93. void writeBinary(FILE* file) const;
  94. /**
  95. * Writes this vertex to a text file stream.
  96. */
  97. void writeText(FILE* file) const;
  98. /**
  99. * Normalizes the blend weights of this vertex so that they add up to 1.0.
  100. */
  101. void normalizeBlendWeight();
  102. };
  103. }
  104. #endif