mesh.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2012, assimp team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the assimp team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the assimp team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. /** @file mesh.h
  35. * @brief Declares the data structures in which the imported geometry is
  36. returned by ASSIMP: aiMesh, aiFace and aiBone data structures.
  37. */
  38. #ifndef INCLUDED_AI_MESH_H
  39. #define INCLUDED_AI_MESH_H
  40. #include "types.h"
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. // ---------------------------------------------------------------------------
  45. // Limits. These values are required to match the settings Assimp was
  46. // compiled against. Therfore, do not redefine them unless you build the
  47. // library from source using the same definitions.
  48. // ---------------------------------------------------------------------------
  49. /** @def AI_MAX_FACE_INDICES
  50. * Maximum number of indices per face (polygon). */
  51. #ifndef AI_MAX_FACE_INDICES
  52. # define AI_MAX_FACE_INDICES 0x7fff
  53. #endif
  54. /** @def AI_MAX_BONE_WEIGHTS
  55. * Maximum number of indices per face (polygon). */
  56. #ifndef AI_MAX_BONE_WEIGHTS
  57. # define AI_MAX_BONE_WEIGHTS 0x7fffffff
  58. #endif
  59. /** @def AI_MAX_VERTICES
  60. * Maximum number of vertices per mesh. */
  61. #ifndef AI_MAX_VERTICES
  62. # define AI_MAX_VERTICES 0x7fffffff
  63. #endif
  64. /** @def AI_MAX_FACES
  65. * Maximum number of faces per mesh. */
  66. #ifndef AI_MAX_FACES
  67. # define AI_MAX_FACES 0x7fffffff
  68. #endif
  69. /** @def AI_MAX_NUMBER_OF_COLOR_SETS
  70. * Supported number of vertex color sets per mesh. */
  71. #ifndef AI_MAX_NUMBER_OF_COLOR_SETS
  72. # define AI_MAX_NUMBER_OF_COLOR_SETS 0x8
  73. #endif // !! AI_MAX_NUMBER_OF_COLOR_SETS
  74. /** @def AI_MAX_NUMBER_OF_TEXTURECOORDS
  75. * Supported number of texture coord sets (UV(W) channels) per mesh */
  76. #ifndef AI_MAX_NUMBER_OF_TEXTURECOORDS
  77. # define AI_MAX_NUMBER_OF_TEXTURECOORDS 0x8
  78. #endif // !! AI_MAX_NUMBER_OF_TEXTURECOORDS
  79. // ---------------------------------------------------------------------------
  80. /** @brief A single face in a mesh, referring to multiple vertices.
  81. *
  82. * If mNumIndices is 3, we call the face 'triangle', for mNumIndices > 3
  83. * it's called 'polygon' (hey, that's just a definition!).
  84. * <br>
  85. * aiMesh::mPrimitiveTypes can be queried to quickly examine which types of
  86. * primitive are actually present in a mesh. The #aiProcess_SortByPType flag
  87. * executes a special post-processing algorithm which splits meshes with
  88. * *different* primitive types mixed up (e.g. lines and triangles) in several
  89. * 'clean' submeshes. Furthermore there is a configuration option (
  90. * #AI_CONFIG_PP_SBP_REMOVE) to force #aiProcess_SortByPType to remove
  91. * specific kinds of primitives from the imported scene, completely and forever.
  92. * In many cases you'll probably want to set this setting to
  93. * @code
  94. * aiPrimitiveType_LINE|aiPrimitiveType_POINT
  95. * @endcode
  96. * Together with the #aiProcess_Triangulate flag you can then be sure that
  97. * #aiFace::mNumIndices is always 3.
  98. * @note Take a look at the @link data Data Structures page @endlink for
  99. * more information on the layout and winding order of a face.
  100. */
  101. struct aiFace
  102. {
  103. //! Number of indices defining this face.
  104. //! The maximum value for this member is #AI_MAX_FACE_INDICES.
  105. unsigned int mNumIndices;
  106. //! Pointer to the indices array. Size of the array is given in numIndices.
  107. unsigned int* mIndices;
  108. #ifdef __cplusplus
  109. //! Default constructor
  110. aiFace()
  111. {
  112. mNumIndices = 0; mIndices = NULL;
  113. }
  114. //! Default destructor. Delete the index array
  115. ~aiFace()
  116. {
  117. delete [] mIndices;
  118. }
  119. //! Copy constructor. Copy the index array
  120. aiFace( const aiFace& o)
  121. {
  122. mIndices = NULL;
  123. *this = o;
  124. }
  125. //! Assignment operator. Copy the index array
  126. const aiFace& operator = ( const aiFace& o)
  127. {
  128. if (&o == this)
  129. return *this;
  130. delete[] mIndices;
  131. mNumIndices = o.mNumIndices;
  132. mIndices = new unsigned int[mNumIndices];
  133. ::memcpy( mIndices, o.mIndices, mNumIndices * sizeof( unsigned int));
  134. return *this;
  135. }
  136. //! Comparison operator. Checks whether the index array
  137. //! of two faces is identical
  138. bool operator== (const aiFace& o) const
  139. {
  140. if (mIndices == o.mIndices)return true;
  141. else if (mIndices && mNumIndices == o.mNumIndices)
  142. {
  143. for (unsigned int i = 0;i < this->mNumIndices;++i)
  144. if (mIndices[i] != o.mIndices[i])return false;
  145. return true;
  146. }
  147. return false;
  148. }
  149. //! Inverse comparison operator. Checks whether the index
  150. //! array of two faces is NOT identical
  151. bool operator != (const aiFace& o) const
  152. {
  153. return !(*this == o);
  154. }
  155. #endif // __cplusplus
  156. }; // struct aiFace
  157. // ---------------------------------------------------------------------------
  158. /** @brief A single influence of a bone on a vertex.
  159. */
  160. struct aiVertexWeight
  161. {
  162. //! Index of the vertex which is influenced by the bone.
  163. unsigned int mVertexId;
  164. //! The strength of the influence in the range (0...1).
  165. //! The influence from all bones at one vertex amounts to 1.
  166. float mWeight;
  167. #ifdef __cplusplus
  168. //! Default constructor
  169. aiVertexWeight() { }
  170. //! Initialisation from a given index and vertex weight factor
  171. //! \param pID ID
  172. //! \param pWeight Vertex weight factor
  173. aiVertexWeight( unsigned int pID, float pWeight)
  174. : mVertexId( pID), mWeight( pWeight)
  175. { /* nothing to do here */ }
  176. #endif // __cplusplus
  177. };
  178. // ---------------------------------------------------------------------------
  179. /** @brief A single bone of a mesh.
  180. *
  181. * A bone has a name by which it can be found in the frame hierarchy and by
  182. * which it can be addressed by animations. In addition it has a number of
  183. * influences on vertices.
  184. */
  185. struct aiBone
  186. {
  187. //! The name of the bone.
  188. C_STRUCT aiString mName;
  189. //! The number of vertices affected by this bone
  190. //! The maximum value for this member is #AI_MAX_BONE_WEIGHTS.
  191. unsigned int mNumWeights;
  192. //! The vertices affected by this bone
  193. C_STRUCT aiVertexWeight* mWeights;
  194. //! Matrix that transforms from mesh space to bone space in bind pose
  195. C_STRUCT aiMatrix4x4 mOffsetMatrix;
  196. #ifdef __cplusplus
  197. //! Default constructor
  198. aiBone()
  199. {
  200. mNumWeights = 0; mWeights = NULL;
  201. }
  202. //! Copy constructor
  203. aiBone(const aiBone& other)
  204. {
  205. mNumWeights = other.mNumWeights;
  206. mOffsetMatrix = other.mOffsetMatrix;
  207. mName = other.mName;
  208. if (other.mWeights && other.mNumWeights)
  209. {
  210. mWeights = new aiVertexWeight[mNumWeights];
  211. ::memcpy(mWeights,other.mWeights,mNumWeights * sizeof(aiVertexWeight));
  212. }
  213. }
  214. //! Destructor - deletes the array of vertex weights
  215. ~aiBone()
  216. {
  217. delete [] mWeights;
  218. }
  219. #endif // __cplusplus
  220. };
  221. // ---------------------------------------------------------------------------
  222. /** @brief Enumerates the types of geometric primitives supported by Assimp.
  223. *
  224. * @see aiFace Face data structure
  225. * @see aiProcess_SortByPType Per-primitive sorting of meshes
  226. * @see aiProcess_Triangulate Automatic triangulation
  227. * @see AI_CONFIG_PP_SBP_REMOVE Removal of specific primitive types.
  228. */
  229. enum aiPrimitiveType
  230. {
  231. /** A point primitive.
  232. *
  233. * This is just a single vertex in the virtual world,
  234. * #aiFace contains just one index for such a primitive.
  235. */
  236. aiPrimitiveType_POINT = 0x1,
  237. /** A line primitive.
  238. *
  239. * This is a line defined through a start and an end position.
  240. * #aiFace contains exactly two indices for such a primitive.
  241. */
  242. aiPrimitiveType_LINE = 0x2,
  243. /** A triangular primitive.
  244. *
  245. * A triangle consists of three indices.
  246. */
  247. aiPrimitiveType_TRIANGLE = 0x4,
  248. /** A higher-level polygon with more than 3 edges.
  249. *
  250. * A triangle is a polygon, but polygon in this context means
  251. * "all polygons that are not triangles". The "Triangulate"-Step
  252. * is provided for your convenience, it splits all polygons in
  253. * triangles (which are much easier to handle).
  254. */
  255. aiPrimitiveType_POLYGON = 0x8,
  256. /** This value is not used. It is just here to force the
  257. * compiler to map this enum to a 32 Bit integer.
  258. */
  259. #ifndef SWIG
  260. _aiPrimitiveType_Force32Bit = 0x9fffffff
  261. #endif
  262. }; //! enum aiPrimitiveType
  263. // Get the #aiPrimitiveType flag for a specific number of face indices
  264. #define AI_PRIMITIVE_TYPE_FOR_N_INDICES(n) \
  265. ((n) > 3 ? aiPrimitiveType_POLYGON : (aiPrimitiveType)(1u << ((n)-1)))
  266. // ---------------------------------------------------------------------------
  267. /** @brief NOT CURRENTLY IN USE. An AnimMesh is an attachment to an #aiMesh stores per-vertex
  268. * animations for a particular frame.
  269. *
  270. * You may think of an #aiAnimMesh as a `patch` for the host mesh, which
  271. * replaces only certain vertex data streams at a particular time.
  272. * Each mesh stores n attached attached meshes (#aiMesh::mAnimMeshes).
  273. * The actual relationship between the time line and anim meshes is
  274. * established by #aiMeshAnim, which references singular mesh attachments
  275. * by their ID and binds them to a time offset.
  276. */
  277. struct aiAnimMesh
  278. {
  279. /** Replacement for aiMesh::mVertices. If this array is non-NULL,
  280. * it *must* contain mNumVertices entries. The corresponding
  281. * array in the host mesh must be non-NULL as well - animation
  282. * meshes may neither add or nor remove vertex components (if
  283. * a replacement array is NULL and the corresponding source
  284. * array is not, the source data is taken instead)*/
  285. C_STRUCT aiVector3D* mVertices;
  286. /** Replacement for aiMesh::mNormals. */
  287. C_STRUCT aiVector3D* mNormals;
  288. /** Replacement for aiMesh::mTangents. */
  289. C_STRUCT aiVector3D* mTangents;
  290. /** Replacement for aiMesh::mBitangents. */
  291. C_STRUCT aiVector3D* mBitangents;
  292. /** Replacement for aiMesh::mColors */
  293. C_STRUCT aiColor4D* mColors[AI_MAX_NUMBER_OF_COLOR_SETS];
  294. /** Replacement for aiMesh::mTextureCoords */
  295. C_STRUCT aiVector3D* mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS];
  296. /** The number of vertices in the aiAnimMesh, and thus the length of all
  297. * the member arrays.
  298. *
  299. * This has always the same value as the mNumVertices property in the
  300. * corresponding aiMesh. It is duplicated here merely to make the length
  301. * of the member arrays accessible even if the aiMesh is not known, e.g.
  302. * from language bindings.
  303. */
  304. unsigned int mNumVertices;
  305. #ifdef __cplusplus
  306. aiAnimMesh()
  307. : mVertices()
  308. , mNormals()
  309. , mTangents()
  310. , mBitangents()
  311. {
  312. // fixme consider moving this to the ctor initializer list as well
  313. for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++){
  314. mTextureCoords[a] = NULL;
  315. }
  316. for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
  317. mColors[a] = NULL;
  318. }
  319. }
  320. ~aiAnimMesh()
  321. {
  322. delete [] mVertices;
  323. delete [] mNormals;
  324. delete [] mTangents;
  325. delete [] mBitangents;
  326. for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) {
  327. delete [] mTextureCoords[a];
  328. }
  329. for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
  330. delete [] mColors[a];
  331. }
  332. }
  333. /** Check whether the anim mesh overrides the vertex positions
  334. * of its host mesh*/
  335. bool HasPositions() const {
  336. return mVertices != NULL;
  337. }
  338. /** Check whether the anim mesh overrides the vertex normals
  339. * of its host mesh*/
  340. bool HasNormals() const {
  341. return mNormals != NULL;
  342. }
  343. /** Check whether the anim mesh overrides the vertex tangents
  344. * and bitangents of its host mesh. As for aiMesh,
  345. * tangents and bitangents always go together. */
  346. bool HasTangentsAndBitangents() const {
  347. return mTangents != NULL;
  348. }
  349. /** Check whether the anim mesh overrides a particular
  350. * set of vertex colors on his host mesh.
  351. * @param pIndex 0<index<AI_MAX_NUMBER_OF_COLOR_SETS */
  352. bool HasVertexColors( unsigned int pIndex) const {
  353. return pIndex >= AI_MAX_NUMBER_OF_COLOR_SETS ? false : mColors[pIndex] != NULL;
  354. }
  355. /** Check whether the anim mesh overrides a particular
  356. * set of texture coordinates on his host mesh.
  357. * @param pIndex 0<index<AI_MAX_NUMBER_OF_TEXTURECOORDS */
  358. bool HasTextureCoords( unsigned int pIndex) const {
  359. return pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS ? false : mTextureCoords[pIndex] != NULL;
  360. }
  361. #endif
  362. };
  363. // ---------------------------------------------------------------------------
  364. /** @brief A mesh represents a geometry or model with a single material.
  365. *
  366. * It usually consists of a number of vertices and a series of primitives/faces
  367. * referencing the vertices. In addition there might be a series of bones, each
  368. * of them addressing a number of vertices with a certain weight. Vertex data
  369. * is presented in channels with each channel containing a single per-vertex
  370. * information such as a set of texture coords or a normal vector.
  371. * If a data pointer is non-null, the corresponding data stream is present.
  372. * From C++-programs you can also use the comfort functions Has*() to
  373. * test for the presence of various data streams.
  374. *
  375. * A Mesh uses only a single material which is referenced by a material ID.
  376. * @note The mPositions member is usually not optional. However, vertex positions
  377. * *could* be missing if the #AI_SCENE_FLAGS_INCOMPLETE flag is set in
  378. * @code
  379. * aiScene::mFlags
  380. * @endcode
  381. */
  382. struct aiMesh
  383. {
  384. /** Bitwise combination of the members of the #aiPrimitiveType enum.
  385. * This specifies which types of primitives are present in the mesh.
  386. * The "SortByPrimitiveType"-Step can be used to make sure the
  387. * output meshes consist of one primitive type each.
  388. */
  389. unsigned int mPrimitiveTypes;
  390. /** The number of vertices in this mesh.
  391. * This is also the size of all of the per-vertex data arrays.
  392. * The maximum value for this member is #AI_MAX_VERTICES.
  393. */
  394. unsigned int mNumVertices;
  395. /** The number of primitives (triangles, polygons, lines) in this mesh.
  396. * This is also the size of the mFaces array.
  397. * The maximum value for this member is #AI_MAX_FACES.
  398. */
  399. unsigned int mNumFaces;
  400. /** Vertex positions.
  401. * This array is always present in a mesh. The array is
  402. * mNumVertices in size.
  403. */
  404. C_STRUCT aiVector3D* mVertices;
  405. /** Vertex normals.
  406. * The array contains normalized vectors, NULL if not present.
  407. * The array is mNumVertices in size. Normals are undefined for
  408. * point and line primitives. A mesh consisting of points and
  409. * lines only may not have normal vectors. Meshes with mixed
  410. * primitive types (i.e. lines and triangles) may have normals,
  411. * but the normals for vertices that are only referenced by
  412. * point or line primitives are undefined and set to QNaN (WARN:
  413. * qNaN compares to inequal to *everything*, even to qNaN itself.
  414. * Using code like this to check whether a field is qnan is:
  415. * @code
  416. * #define IS_QNAN(f) (f != f)
  417. * @endcode
  418. * still dangerous because even 1.f == 1.f could evaluate to false! (
  419. * remember the subtleties of IEEE754 artithmetics). Use stuff like
  420. * @c fpclassify instead.
  421. * @note Normal vectors computed by Assimp are always unit-length.
  422. * However, this needn't apply for normals that have been taken
  423. * directly from the model file.
  424. */
  425. C_STRUCT aiVector3D* mNormals;
  426. /** Vertex tangents.
  427. * The tangent of a vertex points in the direction of the positive
  428. * X texture axis. The array contains normalized vectors, NULL if
  429. * not present. The array is mNumVertices in size. A mesh consisting
  430. * of points and lines only may not have normal vectors. Meshes with
  431. * mixed primitive types (i.e. lines and triangles) may have
  432. * normals, but the normals for vertices that are only referenced by
  433. * point or line primitives are undefined and set to qNaN. See
  434. * the #mNormals member for a detailled discussion of qNaNs.
  435. * @note If the mesh contains tangents, it automatically also
  436. * contains bitangents.
  437. */
  438. C_STRUCT aiVector3D* mTangents;
  439. /** Vertex bitangents.
  440. * The bitangent of a vertex points in the direction of the positive
  441. * Y texture axis. The array contains normalized vectors, NULL if not
  442. * present. The array is mNumVertices in size.
  443. * @note If the mesh contains tangents, it automatically also contains
  444. * bitangents.
  445. */
  446. C_STRUCT aiVector3D* mBitangents;
  447. /** Vertex color sets.
  448. * A mesh may contain 0 to #AI_MAX_NUMBER_OF_COLOR_SETS vertex
  449. * colors per vertex. NULL if not present. Each array is
  450. * mNumVertices in size if present.
  451. */
  452. C_STRUCT aiColor4D* mColors[AI_MAX_NUMBER_OF_COLOR_SETS];
  453. /** Vertex texture coords, also known as UV channels.
  454. * A mesh may contain 0 to AI_MAX_NUMBER_OF_TEXTURECOORDS per
  455. * vertex. NULL if not present. The array is mNumVertices in size.
  456. */
  457. C_STRUCT aiVector3D* mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS];
  458. /** Specifies the number of components for a given UV channel.
  459. * Up to three channels are supported (UVW, for accessing volume
  460. * or cube maps). If the value is 2 for a given channel n, the
  461. * component p.z of mTextureCoords[n][p] is set to 0.0f.
  462. * If the value is 1 for a given channel, p.y is set to 0.0f, too.
  463. * @note 4D coords are not supported
  464. */
  465. unsigned int mNumUVComponents[AI_MAX_NUMBER_OF_TEXTURECOORDS];
  466. /** The faces the mesh is constructed from.
  467. * Each face refers to a number of vertices by their indices.
  468. * This array is always present in a mesh, its size is given
  469. * in mNumFaces. If the #AI_SCENE_FLAGS_NON_VERBOSE_FORMAT
  470. * is NOT set each face references an unique set of vertices.
  471. */
  472. C_STRUCT aiFace* mFaces;
  473. /** The number of bones this mesh contains.
  474. * Can be 0, in which case the mBones array is NULL.
  475. */
  476. unsigned int mNumBones;
  477. /** The bones of this mesh.
  478. * A bone consists of a name by which it can be found in the
  479. * frame hierarchy and a set of vertex weights.
  480. */
  481. C_STRUCT aiBone** mBones;
  482. /** The material used by this mesh.
  483. * A mesh does use only a single material. If an imported model uses
  484. * multiple materials, the import splits up the mesh. Use this value
  485. * as index into the scene's material list.
  486. */
  487. unsigned int mMaterialIndex;
  488. /** Name of the mesh. Meshes can be named, but this is not a
  489. * requirement and leaving this field empty is totally fine.
  490. * There are mainly three uses for mesh names:
  491. * - some formats name nodes and meshes independently.
  492. * - importers tend to split meshes up to meet the
  493. * one-material-per-mesh requirement. Assigning
  494. * the same (dummy) name to each of the result meshes
  495. * aids the caller at recovering the original mesh
  496. * partitioning.
  497. * - Vertex animations refer to meshes by their names.
  498. **/
  499. C_STRUCT aiString mName;
  500. /** NOT CURRENTLY IN USE. The number of attachment meshes */
  501. unsigned int mNumAnimMeshes;
  502. /** NOT CURRENTLY IN USE. Attachment meshes for this mesh, for vertex-based animation.
  503. * Attachment meshes carry replacement data for some of the
  504. * mesh'es vertex components (usually positions, normals). */
  505. C_STRUCT aiAnimMesh** mAnimMeshes;
  506. #ifdef __cplusplus
  507. //! Default constructor. Initializes all members to 0
  508. aiMesh()
  509. {
  510. mNumVertices = 0;
  511. mNumFaces = 0;
  512. mNumAnimMeshes = 0;
  513. mPrimitiveTypes = 0;
  514. mVertices = NULL; mFaces = NULL;
  515. mNormals = NULL; mTangents = NULL;
  516. mBitangents = NULL;
  517. mAnimMeshes = NULL;
  518. for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++)
  519. {
  520. mNumUVComponents[a] = 0;
  521. mTextureCoords[a] = NULL;
  522. }
  523. for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++)
  524. mColors[a] = NULL;
  525. mNumBones = 0; mBones = NULL;
  526. mMaterialIndex = 0;
  527. mNumAnimMeshes = 0;
  528. mAnimMeshes = NULL;
  529. }
  530. //! Deletes all storage allocated for the mesh
  531. ~aiMesh()
  532. {
  533. delete [] mVertices;
  534. delete [] mNormals;
  535. delete [] mTangents;
  536. delete [] mBitangents;
  537. for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) {
  538. delete [] mTextureCoords[a];
  539. }
  540. for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
  541. delete [] mColors[a];
  542. }
  543. // DO NOT REMOVE THIS ADDITIONAL CHECK
  544. if (mNumBones && mBones) {
  545. for( unsigned int a = 0; a < mNumBones; a++) {
  546. delete mBones[a];
  547. }
  548. delete [] mBones;
  549. }
  550. if (mNumAnimMeshes && mAnimMeshes) {
  551. for( unsigned int a = 0; a < mNumAnimMeshes; a++) {
  552. delete mAnimMeshes[a];
  553. }
  554. delete [] mAnimMeshes;
  555. }
  556. delete [] mFaces;
  557. }
  558. //! Check whether the mesh contains positions. Provided no special
  559. //! scene flags are set (such as #AI_SCENE_FLAGS_ANIM_SKELETON_ONLY),
  560. //! this will always be true
  561. bool HasPositions() const
  562. { return mVertices != NULL && mNumVertices > 0; }
  563. //! Check whether the mesh contains faces. If no special scene flags
  564. //! are set this should always return true
  565. bool HasFaces() const
  566. { return mFaces != NULL && mNumFaces > 0; }
  567. //! Check whether the mesh contains normal vectors
  568. bool HasNormals() const
  569. { return mNormals != NULL && mNumVertices > 0; }
  570. //! Check whether the mesh contains tangent and bitangent vectors
  571. //! It is not possible that it contains tangents and no bitangents
  572. //! (or the other way round). The existence of one of them
  573. //! implies that the second is there, too.
  574. bool HasTangentsAndBitangents() const
  575. { return mTangents != NULL && mBitangents != NULL && mNumVertices > 0; }
  576. //! Check whether the mesh contains a vertex color set
  577. //! \param pIndex Index of the vertex color set
  578. bool HasVertexColors( unsigned int pIndex) const
  579. {
  580. if( pIndex >= AI_MAX_NUMBER_OF_COLOR_SETS)
  581. return false;
  582. else
  583. return mColors[pIndex] != NULL && mNumVertices > 0;
  584. }
  585. //! Check whether the mesh contains a texture coordinate set
  586. //! \param pIndex Index of the texture coordinates set
  587. bool HasTextureCoords( unsigned int pIndex) const
  588. {
  589. if( pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS)
  590. return false;
  591. else
  592. return mTextureCoords[pIndex] != NULL && mNumVertices > 0;
  593. }
  594. //! Get the number of UV channels the mesh contains
  595. unsigned int GetNumUVChannels() const
  596. {
  597. unsigned int n = 0;
  598. while (n < AI_MAX_NUMBER_OF_TEXTURECOORDS && mTextureCoords[n])++n;
  599. return n;
  600. }
  601. //! Get the number of vertex color channels the mesh contains
  602. unsigned int GetNumColorChannels() const
  603. {
  604. unsigned int n = 0;
  605. while (n < AI_MAX_NUMBER_OF_COLOR_SETS && mColors[n])++n;
  606. return n;
  607. }
  608. //! Check whether the mesh contains bones
  609. inline bool HasBones() const
  610. { return mBones != NULL && mNumBones > 0; }
  611. #endif // __cplusplus
  612. };
  613. #ifdef __cplusplus
  614. }
  615. #endif //! extern "C"
  616. #endif // __AI_MESH_H_INC