/COLLADAFramework/include/COLLADAFWMesh.h

https://bitbucket.org/ZhangJingGuo/opencollada · C Header · 347 lines · 81 code · 67 blank · 199 comment · 4 complexity · cf6252d5770f400d2ef38fd153e48a31 MD5 · raw file

  1. /*
  2. Copyright (c) 2008-2009 NetAllied Systems GmbH
  3. This file is part of COLLADAFramework.
  4. Licensed under the MIT Open Source License,
  5. for details please see LICENSE file or the website
  6. http://www.opensource.org/licenses/mit-license.php
  7. */
  8. #ifndef __COLLADAFW_MESH_H__
  9. #define __COLLADAFW_MESH_H__
  10. #include "COLLADAFWPrerequisites.h"
  11. #include "COLLADAFWGeometry.h"
  12. #include "COLLADAFWMeshVertexData.h"
  13. #include "COLLADAFWMeshPrimitive.h"
  14. #include "COLLADABUUtils.h"
  15. namespace COLLADAFW
  16. {
  17. /**
  18. * Describes basic geometric meshes using vertex and primitive information.
  19. * Meshes embody a general form of geometric description that primarily
  20. * includes vertex and primitive information.
  21. * Vertex information is the set of attributes associated with a point on
  22. * the surface of the mesh. Each vertex includes data for attributes such as:
  23. * • Vertex position
  24. * • Vertex color
  25. * • Vertex normal
  26. * • Vertex texture coordinate
  27. * The mesh also includes a description of how the vertices are organized to
  28. * form the geometric shape of the mesh. The mesh vertices are collated into
  29. * geometric primitives such as polygons, triangles, or lines.
  30. */
  31. class Mesh : public Geometry
  32. {
  33. public:
  34. private:
  35. /**
  36. * The positions array. Positions can be stored as float or double values.
  37. * Positions have always a stride of three (XYZ parameters). We don't need to store
  38. * this information.
  39. */
  40. MeshVertexData mPositions;
  41. /**
  42. * The normals array. Normals can be stored as float or double values.
  43. * Normals have always a stride of three (XYZ parameters). We don't need to store this
  44. * information.
  45. */
  46. MeshVertexData mNormals;
  47. /**
  48. * The colors array. Colors can be stored as float or double values.
  49. * Colors can have different strides (RGB or RGBA parameters). We have to store this
  50. * information.
  51. */
  52. MeshVertexData mColors;
  53. /**
  54. * The uv coordinates array. UV coordinates can be stored as float or double values.
  55. * UV corrdinates can have different strides (2d, 3d, 4d). We have to store this
  56. * information.
  57. */
  58. MeshVertexData mUVCoords;
  59. /**
  60. * The Tangent array
  61. */
  62. MeshVertexData mTangents;
  63. /**
  64. * The Binormal array
  65. */
  66. MeshVertexData mBinormals;
  67. /**
  68. * Geometric primitives, which assemble values from the inputs into vertex attribute data.
  69. * Each primitive element holds the index arrays of the used input elements
  70. * Can be any combination of the following in any order:
  71. * <lines>, <linestrips>, <polygons>, <polylist>, <triangles>, <trifans>, and <tristrips>
  72. */
  73. MeshPrimitiveArray mMeshPrimitives;
  74. public:
  75. /** Constructor. */
  76. Mesh ( const UniqueId& uniqueId );
  77. /** Destructor. */
  78. virtual ~Mesh ();
  79. /**
  80. * The positions array.
  81. * Positions can be stored as float or double values.
  82. * Positions have always a stride of three (X, Y and Z parameter). So we don't need to
  83. * store this information.
  84. */
  85. const MeshVertexData& getPositions () const { return mPositions; }
  86. /**
  87. * The positions array.
  88. * Positions can be stored as float or double values.
  89. * Positions have always a stride of three (X, Y and Z parameter). So we don't need to
  90. * store this information.
  91. */
  92. MeshVertexData& getPositions () { return mPositions; }
  93. /**
  94. * The positions array.
  95. * Positions can be stored as float or double values.
  96. * Positions have always a stride of three (X, Y and Z parameter). So we don't need to
  97. * store this information.
  98. */
  99. // void setPositions ( MeshVertexData& positions ) { mPositions = positions; }
  100. /**
  101. * The normals array.
  102. * Normals can be stored as float or double values.
  103. * Normals have always a stride of three (X, Y and Z parameter). We don't need to store
  104. * this information.
  105. */
  106. const MeshVertexData& getNormals () const { return mNormals; }
  107. /**
  108. * The normals array.
  109. * Normals can be stored as float or double values.
  110. * Normals have always a stride of three (X, Y and Z parameter). We don't need to store
  111. * this information.
  112. */
  113. MeshVertexData& getNormals () { return mNormals; }
  114. /**
  115. * The normals array.
  116. * Normals can be stored as float or double values.
  117. * Normals have always a stride of three (X, Y and Z parameter). We don't need to store
  118. * this information.
  119. */
  120. // void setNormals ( MeshVertexData& Normals ) { mNormals = Normals; }
  121. /**
  122. * Checks, if the mesh has normals.
  123. */
  124. bool hasNormals ( )const;
  125. /*
  126. * Counts the number of all normals in the current mesh. This is the sum of the number of
  127. * normals of all primitive elements into the mesh object.
  128. */
  129. const size_t getNormalsCount () const;
  130. /**
  131. * The colors array.
  132. * Colors can be stored as float or double values.
  133. * Colors have always a stride of three (X, Y and Z parameter). We don't need to store
  134. * this information.
  135. */
  136. const MeshVertexData& getColors () const { return mColors; }
  137. /**
  138. * The colors array.
  139. * Colors can be stored as float or double values.
  140. * Colors have always a stride of three (X, Y and Z parameter). We don't need to store
  141. * this information.
  142. */
  143. MeshVertexData& getColors () { return mColors; }
  144. /**
  145. * Returns the color with the name.
  146. */
  147. size_t getColorIndexByName ( const String& name ) const
  148. {
  149. String currentName;
  150. for ( size_t index=0; index<mColors.getValuesCount (); ++index )
  151. {
  152. if ( COLLADABU::Utils::equals ( name, mColors.getName ( index ) ) )
  153. return index;
  154. }
  155. // std::cerr << "No color with name \"" << name << "\"!" << std::endl;
  156. COLLADABU_ASSERT ( COLLADABU::Utils::equals ( name, name ) );
  157. return 0;
  158. }
  159. /**
  160. * The colors array.
  161. * Colors can be stored as float or double values.
  162. * Colors have always a stride of three (X, Y and Z parameter). We don't need to store
  163. * this information.
  164. */
  165. // void setColors ( MeshVertexData& Colors ) { mColors = Colors; }
  166. /**
  167. * The 2 dimensional uv coordinates array.
  168. * UV coordinates can be stored as float or double values.
  169. */
  170. const MeshVertexData& getUVCoords () const { return mUVCoords; }
  171. /**
  172. * The 2 dimensional uv coordinates array.
  173. * UV coordinates can be stored as float or double values.
  174. */
  175. MeshVertexData& getUVCoords () { return mUVCoords; }
  176. /**
  177. * Returns the uv set with the name.
  178. */
  179. size_t getUVSetIndexByName ( const String& name ) const
  180. {
  181. for ( size_t index=0; index<mUVCoords.getValuesCount (); ++index )
  182. {
  183. if ( COLLADABU::Utils::equals ( name, mUVCoords.getName ( index ) ) )
  184. return index;
  185. }
  186. // std::cerr << "No uv set with name \"" << name << "\"!" << std::endl;
  187. COLLADABU_ASSERT ( true );
  188. return 0;
  189. }
  190. /**
  191. * The 3 dimensional tangent coordinates array.
  192. * Tangent coordinates can be stored as float or double values.
  193. */
  194. const MeshVertexData& getTangents () const { return mTangents; }
  195. /**
  196. * The 3 dimensional tangent coordinates array.
  197. * Tangent coordinates can be stored as float or double values.
  198. */
  199. MeshVertexData& getTangents () { return mTangents; }
  200. /**
  201. * The 3 dimensional binormal coordinates array.
  202. * Binormal coordinates can be stored as float or double values.
  203. */
  204. const MeshVertexData& getBinormals () const { return mBinormals; }
  205. /**
  206. * The 3 dimensional binormal coordinates array.
  207. * Binormal coordinates can be stored as float or double values.
  208. */
  209. MeshVertexData& getBinormals () { return mBinormals; }
  210. /**
  211. * Geometric primitives, which assemble values from the inputs into vertex attribute data.
  212. * Can be any combination of the following in any order:
  213. * <lines>, <linestrips>, <polygons>, <polylist>, <triangles>, <trifans>, and <tristrips>
  214. */
  215. MeshPrimitiveArray& getMeshPrimitives () { return mMeshPrimitives; }
  216. /**
  217. * Geometric primitives, which assemble values from the inputs into vertex attribute data.
  218. * Can be any combination of the following in any order:
  219. * <lines>, <linestrips>, <polygons>, <polylist>, <triangles>, <trifans>, and <tristrips>
  220. */
  221. const MeshPrimitiveArray& getMeshPrimitives () const { return mMeshPrimitives; }
  222. /**
  223. * Geometric primitives, which assemble values from the inputs into vertex attribute data.
  224. * Can be any combination of the following in any order:
  225. * <lines>, <linestrips>, <polygons>, <polylist>, <triangles>, <trifans>, and <tristrips>
  226. */
  227. void setMeshPrimitives ( const MeshPrimitiveArray& primitiveElements ) { mMeshPrimitives = primitiveElements; }
  228. /**
  229. * Geometric primitives, which assemble values from the inputs into vertex attribute data.
  230. * Can be any combination of the following in any order:
  231. * <lines>, <linestrips>, <polygons>, <polylist>, <triangles>, <trifans>, and <tristrips>
  232. */
  233. MeshPrimitive* appendPrimitive ( MeshPrimitive* primitiveElement )
  234. { return mMeshPrimitives.append ( primitiveElement ); }
  235. /** Counts the number of all triangles in all Triangle primitives.*/
  236. size_t getTrianglesTriangleCount();
  237. /** Counts the number of all triangles in all Tristrips primitives. This is the number
  238. of triangles one get, if the tristrips are converted to triagles.*/
  239. size_t getTristripsTriangleCount();
  240. /** Counts the number of all triangles in all Trifans primitives. This is the number
  241. of triangles one get, if the tristrips are converted to triagles.*/
  242. size_t getTrifansTriangleCount();
  243. /** Counts the number of all polygons in all polygons primitives.*/
  244. size_t getPolygonsPolygonCount();
  245. size_t getPolylistPolygonCount();
  246. /** Counts the number of all primitives in all primitives of type @a primitiveType.
  247. @note For Triangles, polygons this is the number of faces (The primitives are faces). For
  248. Tristrips and Trisfans this the number of strips and fans (The primitives are not faces).*/
  249. size_t getPrimitiveCount(MeshPrimitive::PrimitiveType primitiveType);
  250. /** Counts the number of all primitives in all primitives of type @a primitiveType.
  251. @note For Triangles, polygons this is the number of primitives (The primitive are faces).
  252. For Tristrips and Trisfans this the number of triangles the strips an fans consist of
  253. (The primitives are not faces, but the triangles they consist of).*/
  254. size_t getFaceCount(MeshPrimitive::PrimitiveType primitiveType);
  255. /** Counts the number of all tristrips in all Tristrip primitives.
  256. TODO not implemented */
  257. size_t getTristripsTristripCount();
  258. /** Counts the number of all trifans in all Trifans primitives.
  259. TODO not implemented */
  260. size_t getTrifansTrifanCount();
  261. /** Counts the number of all Triangle primitives.*/
  262. size_t getTrianglesCount();
  263. /** Counts the number of all Tristrips primitives.*/
  264. size_t getTristripsCount();
  265. /** Counts the number of all Trifans primitives.*/
  266. size_t getTrifansCount();
  267. /** Counts the number of all Polygons primitives.*/
  268. size_t getPolygonsCount();
  269. /** Counts the number of all mesh primitives of type @a primitiveType in the mesh, i.e.
  270. it counts the number of primitives of type @a primitiveType in mMeshPrimitives.*/
  271. size_t getMeshPrimitiveCount(MeshPrimitive::PrimitiveType primitiveType);
  272. /*
  273. * Counts the number of all faces in all primitive elements in the current mesh.
  274. */
  275. const size_t getFacesCount () const;
  276. };
  277. }
  278. #endif // __COLLADA_MESH_H__