PolyVertex.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. Copyright (C) 2011 by Ivan Safrin
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #pragma once
  20. #include "PolyGlobals.h"
  21. #include "PolyVector3.h"
  22. #include "PolyVector2.h"
  23. #include "PolyColor.h"
  24. #include <vector>
  25. namespace Polycode {
  26. class Bone;
  27. /**
  28. * Bone assignment.
  29. */
  30. class _PolyExport BoneAssignment {
  31. public:
  32. BoneAssignment(){
  33. bone = NULL;
  34. }
  35. /**
  36. * Id of the bone assigned.
  37. */
  38. unsigned int boneID;
  39. /**
  40. * Assignment weight.
  41. */
  42. Number weight;
  43. /**
  44. * Assigned bone.
  45. */
  46. Bone *bone;
  47. };
  48. /**
  49. * A mesh vertex.
  50. */
  51. class _PolyExport Vertex : public Vector3 {
  52. public:
  53. /**
  54. * Default constructor.
  55. */
  56. Vertex();
  57. /**
  58. * Initialize with position.
  59. * @param pos_x Position x.
  60. * @param pos_y Position y.
  61. * @param pos_z Position z.
  62. */
  63. Vertex(Number x, Number y, Number z);
  64. /**
  65. * Initialize with position and normal.
  66. * @param pos_x Position x.
  67. * @param pos_y Position y.
  68. * @param pos_z Position z.
  69. * @param nor_x Normal x.
  70. * @param nor_y Normal y.
  71. * @param nor_z Normal z.
  72. */
  73. Vertex(Number pos_x, Number pos_y, Number pos_z, Number nor_x, Number nor_y, Number nor_z);
  74. /**
  75. * Initialize with position and normal and texture coordinates.
  76. * @param pos_x Position x.
  77. * @param pos_y Position y.
  78. * @param pos_z Position z.
  79. * @param nor_x Normal x.
  80. * @param nor_y Normal y.
  81. * @param nor_z Normal z.
  82. * @param u Horizontal texture coordinate.
  83. * @param v Vertical texture coordinate.
  84. */
  85. Vertex(Number pos_x, Number pos_y, Number pos_z, Number nor_x, Number nor_y, Number nor_z, Number u, Number v);
  86. /**
  87. * Initialize with position and texture coordinates.
  88. * @param pos_x Position x.
  89. * @param pos_y Position y.
  90. * @param pos_z Position z.
  91. * @param u Horizontal texture coordinate.
  92. * @param v Vertical texture coordinate.
  93. */
  94. Vertex(Number x, Number y, Number z, Number u, Number v);
  95. virtual ~Vertex();
  96. /**
  97. * Assign a bone to the vertex by bone id.
  98. * @param boneID The bone id.
  99. * @param boneWeight Normalized weight of the bone assignment.
  100. */
  101. void addBoneAssignment(unsigned int boneID, Number boneWeight);
  102. /**
  103. * Get total number of bone assignments.
  104. * @return Number of bone assignments.
  105. */
  106. int getNumBoneAssignments();
  107. /**
  108. * Get bone assignment at index.
  109. * @param Index of bone assignment.
  110. * @return Bone assignment at index.
  111. */
  112. BoneAssignment *getBoneAssignment(unsigned int index);
  113. /**
  114. * Normalizes all current weight assignments.
  115. */
  116. void normalizeWeights();
  117. /**
  118. * Returns the texture coordinates.
  119. * @return Texture coordinates.
  120. */
  121. Vector2 getTexCoord();
  122. /**
  123. * Sets the texture coordinates.
  124. * @param u New horizontal texture coordinate.
  125. * @param v New vertical texture coordinate.
  126. */
  127. void setTexCoord(Number u, Number v);
  128. Vector2 getSecondaryTexCoord();
  129. void setSecondaryTexCoord(Number u, Number v);
  130. /**
  131. * Sets the normal
  132. * @param x Normal x.
  133. * @param y Normal y.
  134. * @param z Normal z.
  135. */
  136. void setNormal(Number x, Number y, Number z);
  137. /**
  138. * Rest normal.
  139. */
  140. Vector3 restNormal;
  141. /**
  142. * Rest position.
  143. */
  144. Vector3 restPosition;
  145. /**
  146. * Vertex normal.
  147. */
  148. Vector3 normal;
  149. /**
  150. * Vertex tangent.
  151. */
  152. Vector3 tangent;
  153. /**
  154. * Vertex color.
  155. */
  156. Color vertexColor;
  157. /**
  158. * Texture coordinates
  159. */
  160. Vector2 texCoord;
  161. Vector2 secondaryTexCoord;
  162. bool useVertexColor;
  163. protected:
  164. std::vector <BoneAssignment*> boneAssignments;
  165. };
  166. }