mesh.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  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. : mNumIndices( 0 )
  112. , mIndices( NULL )
  113. {
  114. }
  115. //! Default destructor. Delete the index array
  116. ~aiFace()
  117. {
  118. delete [] mIndices;
  119. }
  120. //! Copy constructor. Copy the index array
  121. aiFace( const aiFace& o)
  122. : mIndices( NULL )
  123. {
  124. *this = o;
  125. }
  126. //! Assignment operator. Copy the index array
  127. aiFace& operator = ( const aiFace& o)
  128. {
  129. if (&o == this)
  130. return *this;
  131. delete[] mIndices;
  132. mNumIndices = o.mNumIndices;
  133. if (mNumIndices) {
  134. mIndices = new unsigned int[mNumIndices];
  135. ::memcpy( mIndices, o.mIndices, mNumIndices * sizeof( unsigned int));
  136. }
  137. else {
  138. mIndices = NULL;
  139. }
  140. return *this;
  141. }
  142. //! Comparison operator. Checks whether the index array
  143. //! of two faces is identical
  144. bool operator== (const aiFace& o) const
  145. {
  146. if (mIndices == o.mIndices)return true;
  147. else if (mIndices && mNumIndices == o.mNumIndices)
  148. {
  149. for (unsigned int i = 0;i < this->mNumIndices;++i)
  150. if (mIndices[i] != o.mIndices[i])return false;
  151. return true;
  152. }
  153. return false;
  154. }
  155. //! Inverse comparison operator. Checks whether the index
  156. //! array of two faces is NOT identical
  157. bool operator != (const aiFace& o) const
  158. {
  159. return !(*this == o);
  160. }
  161. #endif // __cplusplus
  162. }; // struct aiFace
  163. // ---------------------------------------------------------------------------
  164. /** @brief A single influence of a bone on a vertex.
  165. */
  166. struct aiVertexWeight
  167. {
  168. //! Index of the vertex which is influenced by the bone.
  169. unsigned int mVertexId;
  170. //! The strength of the influence in the range (0...1).
  171. //! The influence from all bones at one vertex amounts to 1.
  172. float mWeight;
  173. #ifdef __cplusplus
  174. //! Default constructor
  175. aiVertexWeight() { }
  176. //! Initialisation from a given index and vertex weight factor
  177. //! \param pID ID
  178. //! \param pWeight Vertex weight factor
  179. aiVertexWeight( unsigned int pID, float pWeight)
  180. : mVertexId( pID), mWeight( pWeight)
  181. { /* nothing to do here */ }
  182. #endif // __cplusplus
  183. };
  184. // ---------------------------------------------------------------------------
  185. /** @brief A single bone of a mesh.
  186. *
  187. * A bone has a name by which it can be found in the frame hierarchy and by
  188. * which it can be addressed by animations. In addition it has a number of
  189. * influences on vertices.
  190. */
  191. struct aiBone
  192. {
  193. //! The name of the bone.
  194. C_STRUCT aiString mName;
  195. //! The number of vertices affected by this bone
  196. //! The maximum value for this member is #AI_MAX_BONE_WEIGHTS.
  197. unsigned int mNumWeights;
  198. //! The vertices affected by this bone
  199. C_STRUCT aiVertexWeight* mWeights;
  200. //! Matrix that transforms from mesh space to bone space in bind pose
  201. C_STRUCT aiMatrix4x4 mOffsetMatrix;
  202. #ifdef __cplusplus
  203. //! Default constructor
  204. aiBone()
  205. : mNumWeights( 0 )
  206. , mWeights( NULL )
  207. {
  208. }
  209. //! Copy constructor
  210. aiBone(const aiBone& other)
  211. : mName( other.mName )
  212. , mNumWeights( other.mNumWeights )
  213. , mOffsetMatrix( other.mOffsetMatrix )
  214. {
  215. if (other.mWeights && other.mNumWeights)
  216. {
  217. mWeights = new aiVertexWeight[mNumWeights];
  218. ::memcpy(mWeights,other.mWeights,mNumWeights * sizeof(aiVertexWeight));
  219. }
  220. }
  221. //! Destructor - deletes the array of vertex weights
  222. ~aiBone()
  223. {
  224. delete [] mWeights;
  225. }
  226. #endif // __cplusplus
  227. };
  228. // ---------------------------------------------------------------------------
  229. /** @brief Enumerates the types of geometric primitives supported by Assimp.
  230. *
  231. * @see aiFace Face data structure
  232. * @see aiProcess_SortByPType Per-primitive sorting of meshes
  233. * @see aiProcess_Triangulate Automatic triangulation
  234. * @see AI_CONFIG_PP_SBP_REMOVE Removal of specific primitive types.
  235. */
  236. enum aiPrimitiveType
  237. {
  238. /** A point primitive.
  239. *
  240. * This is just a single vertex in the virtual world,
  241. * #aiFace contains just one index for such a primitive.
  242. */
  243. aiPrimitiveType_POINT = 0x1,
  244. /** A line primitive.
  245. *
  246. * This is a line defined through a start and an end position.
  247. * #aiFace contains exactly two indices for such a primitive.
  248. */
  249. aiPrimitiveType_LINE = 0x2,
  250. /** A triangular primitive.
  251. *
  252. * A triangle consists of three indices.
  253. */
  254. aiPrimitiveType_TRIANGLE = 0x4,
  255. /** A higher-level polygon with more than 3 edges.
  256. *
  257. * A triangle is a polygon, but polygon in this context means
  258. * "all polygons that are not triangles". The "Triangulate"-Step
  259. * is provided for your convenience, it splits all polygons in
  260. * triangles (which are much easier to handle).
  261. */
  262. aiPrimitiveType_POLYGON = 0x8,
  263. /** This value is not used. It is just here to force the
  264. * compiler to map this enum to a 32 Bit integer.
  265. */
  266. #ifndef SWIG
  267. _aiPrimitiveType_Force32Bit = INT_MAX
  268. #endif
  269. }; //! enum aiPrimitiveType
  270. // Get the #aiPrimitiveType flag for a specific number of face indices
  271. #define AI_PRIMITIVE_TYPE_FOR_N_INDICES(n) \
  272. ((n) > 3 ? aiPrimitiveType_POLYGON : (aiPrimitiveType)(1u << ((n)-1)))
  273. // ---------------------------------------------------------------------------
  274. /** @brief NOT CURRENTLY IN USE. An AnimMesh is an attachment to an #aiMesh stores per-vertex
  275. * animations for a particular frame.
  276. *
  277. * You may think of an #aiAnimMesh as a `patch` for the host mesh, which
  278. * replaces only certain vertex data streams at a particular time.
  279. * Each mesh stores n attached attached meshes (#aiMesh::mAnimMeshes).
  280. * The actual relationship between the time line and anim meshes is
  281. * established by #aiMeshAnim, which references singular mesh attachments
  282. * by their ID and binds them to a time offset.
  283. */
  284. struct aiAnimMesh
  285. {
  286. /** Replacement for aiMesh::mVertices. If this array is non-NULL,
  287. * it *must* contain mNumVertices entries. The corresponding
  288. * array in the host mesh must be non-NULL as well - animation
  289. * meshes may neither add or nor remove vertex components (if
  290. * a replacement array is NULL and the corresponding source
  291. * array is not, the source data is taken instead)*/
  292. C_STRUCT aiVector3D* mVertices;
  293. /** Replacement for aiMesh::mNormals. */
  294. C_STRUCT aiVector3D* mNormals;
  295. /** Replacement for aiMesh::mTangents. */
  296. C_STRUCT aiVector3D* mTangents;
  297. /** Replacement for aiMesh::mBitangents. */
  298. C_STRUCT aiVector3D* mBitangents;
  299. /** Replacement for aiMesh::mColors */
  300. C_STRUCT aiColor4D* mColors[AI_MAX_NUMBER_OF_COLOR_SETS];
  301. /** Replacement for aiMesh::mTextureCoords */
  302. C_STRUCT aiVector3D* mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS];
  303. /** The number of vertices in the aiAnimMesh, and thus the length of all
  304. * the member arrays.
  305. *
  306. * This has always the same value as the mNumVertices property in the
  307. * corresponding aiMesh. It is duplicated here merely to make the length
  308. * of the member arrays accessible even if the aiMesh is not known, e.g.
  309. * from language bindings.
  310. */
  311. unsigned int mNumVertices;
  312. #ifdef __cplusplus
  313. aiAnimMesh()
  314. : mVertices( NULL )
  315. , mNormals( NULL )
  316. , mTangents( NULL )
  317. , mBitangents( NULL )
  318. , mNumVertices( 0 )
  319. {
  320. // fixme consider moving this to the ctor initializer list as well
  321. for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++){
  322. mTextureCoords[a] = NULL;
  323. }
  324. for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
  325. mColors[a] = NULL;
  326. }
  327. }
  328. ~aiAnimMesh()
  329. {
  330. delete [] mVertices;
  331. delete [] mNormals;
  332. delete [] mTangents;
  333. delete [] mBitangents;
  334. for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) {
  335. delete [] mTextureCoords[a];
  336. }
  337. for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
  338. delete [] mColors[a];
  339. }
  340. }
  341. /** Check whether the anim mesh overrides the vertex positions
  342. * of its host mesh*/
  343. bool HasPositions() const {
  344. return mVertices != NULL;
  345. }
  346. /** Check whether the anim mesh overrides the vertex normals
  347. * of its host mesh*/
  348. bool HasNormals() const {
  349. return mNormals != NULL;
  350. }
  351. /** Check whether the anim mesh overrides the vertex tangents
  352. * and bitangents of its host mesh. As for aiMesh,
  353. * tangents and bitangents always go together. */
  354. bool HasTangentsAndBitangents() const {
  355. return mTangents != NULL;
  356. }
  357. /** Check whether the anim mesh overrides a particular
  358. * set of vertex colors on his host mesh.
  359. * @param pIndex 0<index<AI_MAX_NUMBER_OF_COLOR_SETS */
  360. bool HasVertexColors( unsigned int pIndex) const {
  361. return pIndex >= AI_MAX_NUMBER_OF_COLOR_SETS ? false : mColors[pIndex] != NULL;
  362. }
  363. /** Check whether the anim mesh overrides a particular
  364. * set of texture coordinates on his host mesh.
  365. * @param pIndex 0<index<AI_MAX_NUMBER_OF_TEXTURECOORDS */
  366. bool HasTextureCoords( unsigned int pIndex) const {
  367. return pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS ? false : mTextureCoords[pIndex] != NULL;
  368. }
  369. #endif
  370. };
  371. // ---------------------------------------------------------------------------
  372. /** @brief A mesh represents a geometry or model with a single material.
  373. *
  374. * It usually consists of a number of vertices and a series of primitives/faces
  375. * referencing the vertices. In addition there might be a series of bones, each
  376. * of them addressing a number of vertices with a certain weight. Vertex data
  377. * is presented in channels with each channel containing a single per-vertex
  378. * information such as a set of texture coords or a normal vector.
  379. * If a data pointer is non-null, the corresponding data stream is present.
  380. * From C++-programs you can also use the comfort functions Has*() to
  381. * test for the presence of various data streams.
  382. *
  383. * A Mesh uses only a single material which is referenced by a material ID.
  384. * @note The mPositions member is usually not optional. However, vertex positions
  385. * *could* be missing if the #AI_SCENE_FLAGS_INCOMPLETE flag is set in
  386. * @code
  387. * aiScene::mFlags
  388. * @endcode
  389. */
  390. struct aiMesh
  391. {
  392. /** Bitwise combination of the members of the #aiPrimitiveType enum.
  393. * This specifies which types of primitives are present in the mesh.
  394. * The "SortByPrimitiveType"-Step can be used to make sure the
  395. * output meshes consist of one primitive type each.
  396. */
  397. unsigned int mPrimitiveTypes;
  398. /** The number of vertices in this mesh.
  399. * This is also the size of all of the per-vertex data arrays.
  400. * The maximum value for this member is #AI_MAX_VERTICES.
  401. */
  402. unsigned int mNumVertices;
  403. /** The number of primitives (triangles, polygons, lines) in this mesh.
  404. * This is also the size of the mFaces array.
  405. * The maximum value for this member is #AI_MAX_FACES.
  406. */
  407. unsigned int mNumFaces;
  408. /** Vertex positions.
  409. * This array is always present in a mesh. The array is
  410. * mNumVertices in size.
  411. */
  412. C_STRUCT aiVector3D* mVertices;
  413. /** Vertex normals.
  414. * The array contains normalized vectors, NULL if not present.
  415. * The array is mNumVertices in size. Normals are undefined for
  416. * point and line primitives. A mesh consisting of points and
  417. * lines only may not have normal vectors. Meshes with mixed
  418. * primitive types (i.e. lines and triangles) may have normals,
  419. * but the normals for vertices that are only referenced by
  420. * point or line primitives are undefined and set to QNaN (WARN:
  421. * qNaN compares to inequal to *everything*, even to qNaN itself.
  422. * Using code like this to check whether a field is qnan is:
  423. * @code
  424. * #define IS_QNAN(f) (f != f)
  425. * @endcode
  426. * still dangerous because even 1.f == 1.f could evaluate to false! (
  427. * remember the subtleties of IEEE754 artithmetics). Use stuff like
  428. * @c fpclassify instead.
  429. * @note Normal vectors computed by Assimp are always unit-length.
  430. * However, this needn't apply for normals that have been taken
  431. * directly from the model file.
  432. */
  433. C_STRUCT aiVector3D* mNormals;
  434. /** Vertex tangents.
  435. * The tangent of a vertex points in the direction of the positive
  436. * X texture axis. The array contains normalized vectors, NULL if
  437. * not present. The array is mNumVertices in size. A mesh consisting
  438. * of points and lines only may not have normal vectors. Meshes with
  439. * mixed primitive types (i.e. lines and triangles) may have
  440. * normals, but the normals for vertices that are only referenced by
  441. * point or line primitives are undefined and set to qNaN. See
  442. * the #mNormals member for a detailled discussion of qNaNs.
  443. * @note If the mesh contains tangents, it automatically also
  444. * contains bitangents.
  445. */
  446. C_STRUCT aiVector3D* mTangents;
  447. /** Vertex bitangents.
  448. * The bitangent of a vertex points in the direction of the positive
  449. * Y texture axis. The array contains normalized vectors, NULL if not
  450. * present. The array is mNumVertices in size.
  451. * @note If the mesh contains tangents, it automatically also contains
  452. * bitangents.
  453. */
  454. C_STRUCT aiVector3D* mBitangents;
  455. /** Vertex color sets.
  456. * A mesh may contain 0 to #AI_MAX_NUMBER_OF_COLOR_SETS vertex
  457. * colors per vertex. NULL if not present. Each array is
  458. * mNumVertices in size if present.
  459. */
  460. C_STRUCT aiColor4D* mColors[AI_MAX_NUMBER_OF_COLOR_SETS];
  461. /** Vertex texture coords, also known as UV channels.
  462. * A mesh may contain 0 to AI_MAX_NUMBER_OF_TEXTURECOORDS per
  463. * vertex. NULL if not present. The array is mNumVertices in size.
  464. */
  465. C_STRUCT aiVector3D* mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS];
  466. /** Specifies the number of components for a given UV channel.
  467. * Up to three channels are supported (UVW, for accessing volume
  468. * or cube maps). If the value is 2 for a given channel n, the
  469. * component p.z of mTextureCoords[n][p] is set to 0.0f.
  470. * If the value is 1 for a given channel, p.y is set to 0.0f, too.
  471. * @note 4D coords are not supported
  472. */
  473. unsigned int mNumUVComponents[AI_MAX_NUMBER_OF_TEXTURECOORDS];
  474. /** The faces the mesh is constructed from.
  475. * Each face refers to a number of vertices by their indices.
  476. * This array is always present in a mesh, its size is given
  477. * in mNumFaces. If the #AI_SCENE_FLAGS_NON_VERBOSE_FORMAT
  478. * is NOT set each face references an unique set of vertices.
  479. */
  480. C_STRUCT aiFace* mFaces;
  481. /** The number of bones this mesh contains.
  482. * Can be 0, in which case the mBones array is NULL.
  483. */
  484. unsigned int mNumBones;
  485. /** The bones of this mesh.
  486. * A bone consists of a name by which it can be found in the
  487. * frame hierarchy and a set of vertex weights.
  488. */
  489. C_STRUCT aiBone** mBones;
  490. /** The material used by this mesh.
  491. * A mesh does use only a single material. If an imported model uses
  492. * multiple materials, the import splits up the mesh. Use this value
  493. * as index into the scene's material list.
  494. */
  495. unsigned int mMaterialIndex;
  496. /** Name of the mesh. Meshes can be named, but this is not a
  497. * requirement and leaving this field empty is totally fine.
  498. * There are mainly three uses for mesh names:
  499. * - some formats name nodes and meshes independently.
  500. * - importers tend to split meshes up to meet the
  501. * one-material-per-mesh requirement. Assigning
  502. * the same (dummy) name to each of the result meshes
  503. * aids the caller at recovering the original mesh
  504. * partitioning.
  505. * - Vertex animations refer to meshes by their names.
  506. **/
  507. C_STRUCT aiString mName;
  508. /** NOT CURRENTLY IN USE. The number of attachment meshes */
  509. unsigned int mNumAnimMeshes;
  510. /** NOT CURRENTLY IN USE. Attachment meshes for this mesh, for vertex-based animation.
  511. * Attachment meshes carry replacement data for some of the
  512. * mesh'es vertex components (usually positions, normals). */
  513. C_STRUCT aiAnimMesh** mAnimMeshes;
  514. #ifdef __cplusplus
  515. //! Default constructor. Initializes all members to 0
  516. aiMesh()
  517. : mPrimitiveTypes( 0 )
  518. , mNumVertices( 0 )
  519. , mNumFaces( 0 )
  520. , mVertices( NULL )
  521. , mNormals( NULL )
  522. , mTangents( NULL )
  523. , mBitangents( NULL )
  524. , mFaces( NULL )
  525. , mNumBones( 0 )
  526. , mBones( NULL )
  527. , mMaterialIndex( 0 )
  528. , mNumAnimMeshes( 0 )
  529. , mAnimMeshes( NULL )
  530. {
  531. for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++)
  532. {
  533. mNumUVComponents[a] = 0;
  534. mTextureCoords[a] = NULL;
  535. }
  536. for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++)
  537. mColors[a] = NULL;
  538. }
  539. //! Deletes all storage allocated for the mesh
  540. ~aiMesh()
  541. {
  542. delete [] mVertices;
  543. delete [] mNormals;
  544. delete [] mTangents;
  545. delete [] mBitangents;
  546. for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) {
  547. delete [] mTextureCoords[a];
  548. }
  549. for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
  550. delete [] mColors[a];
  551. }
  552. // DO NOT REMOVE THIS ADDITIONAL CHECK
  553. if (mNumBones && mBones) {
  554. for( unsigned int a = 0; a < mNumBones; a++) {
  555. delete mBones[a];
  556. }
  557. delete [] mBones;
  558. }
  559. if (mNumAnimMeshes && mAnimMeshes) {
  560. for( unsigned int a = 0; a < mNumAnimMeshes; a++) {
  561. delete mAnimMeshes[a];
  562. }
  563. delete [] mAnimMeshes;
  564. }
  565. delete [] mFaces;
  566. }
  567. //! Check whether the mesh contains positions. Provided no special
  568. //! scene flags are set (such as #AI_SCENE_FLAGS_ANIM_SKELETON_ONLY),
  569. //! this will always be true
  570. bool HasPositions() const
  571. { return mVertices != NULL && mNumVertices > 0; }
  572. //! Check whether the mesh contains faces. If no special scene flags
  573. //! are set this should always return true
  574. bool HasFaces() const
  575. { return mFaces != NULL && mNumFaces > 0; }
  576. //! Check whether the mesh contains normal vectors
  577. bool HasNormals() const
  578. { return mNormals != NULL && mNumVertices > 0; }
  579. //! Check whether the mesh contains tangent and bitangent vectors
  580. //! It is not possible that it contains tangents and no bitangents
  581. //! (or the other way round). The existence of one of them
  582. //! implies that the second is there, too.
  583. bool HasTangentsAndBitangents() const
  584. { return mTangents != NULL && mBitangents != NULL && mNumVertices > 0; }
  585. //! Check whether the mesh contains a vertex color set
  586. //! \param pIndex Index of the vertex color set
  587. bool HasVertexColors( unsigned int pIndex) const
  588. {
  589. if( pIndex >= AI_MAX_NUMBER_OF_COLOR_SETS)
  590. return false;
  591. else
  592. return mColors[pIndex] != NULL && mNumVertices > 0;
  593. }
  594. //! Check whether the mesh contains a texture coordinate set
  595. //! \param pIndex Index of the texture coordinates set
  596. bool HasTextureCoords( unsigned int pIndex) const
  597. {
  598. if( pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS)
  599. return false;
  600. else
  601. return mTextureCoords[pIndex] != NULL && mNumVertices > 0;
  602. }
  603. //! Get the number of UV channels the mesh contains
  604. unsigned int GetNumUVChannels() const
  605. {
  606. unsigned int n = 0;
  607. while (n < AI_MAX_NUMBER_OF_TEXTURECOORDS && mTextureCoords[n])++n;
  608. return n;
  609. }
  610. //! Get the number of vertex color channels the mesh contains
  611. unsigned int GetNumColorChannels() const
  612. {
  613. unsigned int n = 0;
  614. while (n < AI_MAX_NUMBER_OF_COLOR_SETS && mColors[n])++n;
  615. return n;
  616. }
  617. //! Check whether the mesh contains bones
  618. inline bool HasBones() const
  619. { return mBones != NULL && mNumBones > 0; }
  620. #endif // __cplusplus
  621. };
  622. #ifdef __cplusplus
  623. }
  624. #endif //! extern "C"
  625. #endif // __AI_MESH_H_INC