mesh.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2019, 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. #pragma once
  39. #ifndef AI_MESH_H_INC
  40. #define AI_MESH_H_INC
  41. #include "types.h"
  42. #ifdef __cplusplus
  43. extern "C" {
  44. #endif
  45. // ---------------------------------------------------------------------------
  46. // Limits. These values are required to match the settings Assimp was
  47. // compiled against. Therefore, do not redefine them unless you build the
  48. // library from source using the same definitions.
  49. // ---------------------------------------------------------------------------
  50. /** @def AI_MAX_FACE_INDICES
  51. * Maximum number of indices per face (polygon). */
  52. #ifndef AI_MAX_FACE_INDICES
  53. # define AI_MAX_FACE_INDICES 0x7fff
  54. #endif
  55. /** @def AI_MAX_BONE_WEIGHTS
  56. * Maximum number of indices per face (polygon). */
  57. #ifndef AI_MAX_BONE_WEIGHTS
  58. # define AI_MAX_BONE_WEIGHTS 0x7fffffff
  59. #endif
  60. /** @def AI_MAX_VERTICES
  61. * Maximum number of vertices per mesh. */
  62. #ifndef AI_MAX_VERTICES
  63. # define AI_MAX_VERTICES 0x7fffffff
  64. #endif
  65. /** @def AI_MAX_FACES
  66. * Maximum number of faces per mesh. */
  67. #ifndef AI_MAX_FACES
  68. # define AI_MAX_FACES 0x7fffffff
  69. #endif
  70. /** @def AI_MAX_NUMBER_OF_COLOR_SETS
  71. * Supported number of vertex color sets per mesh. */
  72. #ifndef AI_MAX_NUMBER_OF_COLOR_SETS
  73. # define AI_MAX_NUMBER_OF_COLOR_SETS 0x8
  74. #endif // !! AI_MAX_NUMBER_OF_COLOR_SETS
  75. /** @def AI_MAX_NUMBER_OF_TEXTURECOORDS
  76. * Supported number of texture coord sets (UV(W) channels) per mesh */
  77. #ifndef AI_MAX_NUMBER_OF_TEXTURECOORDS
  78. # define AI_MAX_NUMBER_OF_TEXTURECOORDS 0x8
  79. #endif // !! AI_MAX_NUMBER_OF_TEXTURECOORDS
  80. // ---------------------------------------------------------------------------
  81. /** @brief A single face in a mesh, referring to multiple vertices.
  82. *
  83. * If mNumIndices is 3, we call the face 'triangle', for mNumIndices > 3
  84. * it's called 'polygon' (hey, that's just a definition!).
  85. * <br>
  86. * aiMesh::mPrimitiveTypes can be queried to quickly examine which types of
  87. * primitive are actually present in a mesh. The #aiProcess_SortByPType flag
  88. * executes a special post-processing algorithm which splits meshes with
  89. * *different* primitive types mixed up (e.g. lines and triangles) in several
  90. * 'clean' submeshes. Furthermore there is a configuration option (
  91. * #AI_CONFIG_PP_SBP_REMOVE) to force #aiProcess_SortByPType to remove
  92. * specific kinds of primitives from the imported scene, completely and forever.
  93. * In many cases you'll probably want to set this setting to
  94. * @code
  95. * aiPrimitiveType_LINE|aiPrimitiveType_POINT
  96. * @endcode
  97. * Together with the #aiProcess_Triangulate flag you can then be sure that
  98. * #aiFace::mNumIndices is always 3.
  99. * @note Take a look at the @link data Data Structures page @endlink for
  100. * more information on the layout and winding order of a face.
  101. */
  102. struct aiFace
  103. {
  104. //! Number of indices defining this face.
  105. //! The maximum value for this member is #AI_MAX_FACE_INDICES.
  106. unsigned int mNumIndices;
  107. //! Pointer to the indices array. Size of the array is given in numIndices.
  108. unsigned int* mIndices;
  109. #ifdef __cplusplus
  110. //! Default constructor
  111. aiFace() AI_NO_EXCEPT
  112. : mNumIndices( 0 )
  113. , mIndices( nullptr ) {
  114. // empty
  115. }
  116. //! Default destructor. Delete the index array
  117. ~aiFace()
  118. {
  119. delete [] mIndices;
  120. }
  121. //! Copy constructor. Copy the index array
  122. aiFace( const aiFace& o)
  123. : mNumIndices(0)
  124. , mIndices( nullptr ) {
  125. *this = o;
  126. }
  127. //! Assignment operator. Copy the index array
  128. aiFace& operator = ( const aiFace& o) {
  129. if (&o == this) {
  130. return *this;
  131. }
  132. delete[] mIndices;
  133. mNumIndices = o.mNumIndices;
  134. if (mNumIndices) {
  135. mIndices = new unsigned int[mNumIndices];
  136. ::memcpy( mIndices, o.mIndices, mNumIndices * sizeof( unsigned int));
  137. } else {
  138. mIndices = nullptr;
  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. if (mIndices == o.mIndices) {
  146. return true;
  147. }
  148. if (nullptr != mIndices && mNumIndices != o.mNumIndices) {
  149. return false;
  150. }
  151. if (nullptr == mIndices) {
  152. return false;
  153. }
  154. for (unsigned int i = 0; i < this->mNumIndices; ++i) {
  155. if (mIndices[i] != o.mIndices[i]) {
  156. return false;
  157. }
  158. }
  159. return true;
  160. }
  161. //! Inverse comparison operator. Checks whether the index
  162. //! array of two faces is NOT identical
  163. bool operator != (const aiFace& o) const {
  164. return !(*this == o);
  165. }
  166. #endif // __cplusplus
  167. }; // struct aiFace
  168. // ---------------------------------------------------------------------------
  169. /** @brief A single influence of a bone on a vertex.
  170. */
  171. struct aiVertexWeight {
  172. //! Index of the vertex which is influenced by the bone.
  173. unsigned int mVertexId;
  174. //! The strength of the influence in the range (0...1).
  175. //! The influence from all bones at one vertex amounts to 1.
  176. float mWeight;
  177. #ifdef __cplusplus
  178. //! Default constructor
  179. aiVertexWeight() AI_NO_EXCEPT
  180. : mVertexId(0)
  181. , mWeight(0.0f) {
  182. // empty
  183. }
  184. //! Initialization from a given index and vertex weight factor
  185. //! \param pID ID
  186. //! \param pWeight Vertex weight factor
  187. aiVertexWeight( unsigned int pID, float pWeight )
  188. : mVertexId( pID )
  189. , mWeight( pWeight ) {
  190. // empty
  191. }
  192. bool operator == ( const aiVertexWeight &rhs ) const {
  193. return ( mVertexId == rhs.mVertexId && mWeight == rhs.mWeight );
  194. }
  195. bool operator != ( const aiVertexWeight &rhs ) const {
  196. return ( *this == rhs );
  197. }
  198. #endif // __cplusplus
  199. };
  200. // ---------------------------------------------------------------------------
  201. /** @brief A single bone of a mesh.
  202. *
  203. * A bone has a name by which it can be found in the frame hierarchy and by
  204. * which it can be addressed by animations. In addition it has a number of
  205. * influences on vertices, and a matrix relating the mesh position to the
  206. * position of the bone at the time of binding.
  207. */
  208. struct aiBone {
  209. //! The name of the bone.
  210. C_STRUCT aiString mName;
  211. //! The number of vertices affected by this bone.
  212. //! The maximum value for this member is #AI_MAX_BONE_WEIGHTS.
  213. unsigned int mNumWeights;
  214. //! The influence weights of this bone, by vertex index.
  215. C_STRUCT aiVertexWeight* mWeights;
  216. /** Matrix that transforms from bone space to mesh space in bind pose.
  217. *
  218. * This matrix describes the position of the mesh
  219. * in the local space of this bone when the skeleton was bound.
  220. * Thus it can be used directly to determine a desired vertex position,
  221. * given the world-space transform of the bone when animated,
  222. * and the position of the vertex in mesh space.
  223. *
  224. * It is sometimes called an inverse-bind matrix,
  225. * or inverse bind pose matrix.
  226. */
  227. C_STRUCT aiMatrix4x4 mOffsetMatrix;
  228. #ifdef __cplusplus
  229. //! Default constructor
  230. aiBone() AI_NO_EXCEPT
  231. : mName()
  232. , mNumWeights( 0 )
  233. , mWeights( nullptr )
  234. , mOffsetMatrix() {
  235. // empty
  236. }
  237. //! Copy constructor
  238. aiBone(const aiBone& other)
  239. : mName( other.mName )
  240. , mNumWeights( other.mNumWeights )
  241. , mWeights(nullptr)
  242. , mOffsetMatrix( other.mOffsetMatrix ) {
  243. if (other.mWeights && other.mNumWeights) {
  244. mWeights = new aiVertexWeight[mNumWeights];
  245. ::memcpy(mWeights,other.mWeights,mNumWeights * sizeof(aiVertexWeight));
  246. }
  247. }
  248. //! Assignment operator
  249. aiBone &operator=(const aiBone& other) {
  250. if (this == &other) {
  251. return *this;
  252. }
  253. mName = other.mName;
  254. mNumWeights = other.mNumWeights;
  255. mOffsetMatrix = other.mOffsetMatrix;
  256. if (other.mWeights && other.mNumWeights)
  257. {
  258. if (mWeights) {
  259. delete[] mWeights;
  260. }
  261. mWeights = new aiVertexWeight[mNumWeights];
  262. ::memcpy(mWeights,other.mWeights,mNumWeights * sizeof(aiVertexWeight));
  263. }
  264. return *this;
  265. }
  266. bool operator == ( const aiBone &rhs ) const {
  267. if ( mName != rhs.mName || mNumWeights != rhs.mNumWeights ) {
  268. return false;
  269. }
  270. for ( size_t i = 0; i < mNumWeights; ++i ) {
  271. if ( mWeights[ i ] != rhs.mWeights[ i ] ) {
  272. return false;
  273. }
  274. }
  275. return true;
  276. }
  277. //! Destructor - deletes the array of vertex weights
  278. ~aiBone() {
  279. delete [] mWeights;
  280. }
  281. #endif // __cplusplus
  282. };
  283. // ---------------------------------------------------------------------------
  284. /** @brief Enumerates the types of geometric primitives supported by Assimp.
  285. *
  286. * @see aiFace Face data structure
  287. * @see aiProcess_SortByPType Per-primitive sorting of meshes
  288. * @see aiProcess_Triangulate Automatic triangulation
  289. * @see AI_CONFIG_PP_SBP_REMOVE Removal of specific primitive types.
  290. */
  291. enum aiPrimitiveType
  292. {
  293. /** A point primitive.
  294. *
  295. * This is just a single vertex in the virtual world,
  296. * #aiFace contains just one index for such a primitive.
  297. */
  298. aiPrimitiveType_POINT = 0x1,
  299. /** A line primitive.
  300. *
  301. * This is a line defined through a start and an end position.
  302. * #aiFace contains exactly two indices for such a primitive.
  303. */
  304. aiPrimitiveType_LINE = 0x2,
  305. /** A triangular primitive.
  306. *
  307. * A triangle consists of three indices.
  308. */
  309. aiPrimitiveType_TRIANGLE = 0x4,
  310. /** A higher-level polygon with more than 3 edges.
  311. *
  312. * A triangle is a polygon, but polygon in this context means
  313. * "all polygons that are not triangles". The "Triangulate"-Step
  314. * is provided for your convenience, it splits all polygons in
  315. * triangles (which are much easier to handle).
  316. */
  317. aiPrimitiveType_POLYGON = 0x8,
  318. /** This value is not used. It is just here to force the
  319. * compiler to map this enum to a 32 Bit integer.
  320. */
  321. #ifndef SWIG
  322. _aiPrimitiveType_Force32Bit = INT_MAX
  323. #endif
  324. }; //! enum aiPrimitiveType
  325. // Get the #aiPrimitiveType flag for a specific number of face indices
  326. #define AI_PRIMITIVE_TYPE_FOR_N_INDICES(n) \
  327. ((n) > 3 ? aiPrimitiveType_POLYGON : (aiPrimitiveType)(1u << ((n)-1)))
  328. // ---------------------------------------------------------------------------
  329. /** @brief An AnimMesh is an attachment to an #aiMesh stores per-vertex
  330. * animations for a particular frame.
  331. *
  332. * You may think of an #aiAnimMesh as a `patch` for the host mesh, which
  333. * replaces only certain vertex data streams at a particular time.
  334. * Each mesh stores n attached attached meshes (#aiMesh::mAnimMeshes).
  335. * The actual relationship between the time line and anim meshes is
  336. * established by #aiMeshAnim, which references singular mesh attachments
  337. * by their ID and binds them to a time offset.
  338. */
  339. struct aiAnimMesh
  340. {
  341. /**Anim Mesh name */
  342. C_STRUCT aiString mName;
  343. /** Replacement for aiMesh::mVertices. If this array is non-NULL,
  344. * it *must* contain mNumVertices entries. The corresponding
  345. * array in the host mesh must be non-NULL as well - animation
  346. * meshes may neither add or nor remove vertex components (if
  347. * a replacement array is NULL and the corresponding source
  348. * array is not, the source data is taken instead)*/
  349. C_STRUCT aiVector3D* mVertices;
  350. /** Replacement for aiMesh::mNormals. */
  351. C_STRUCT aiVector3D* mNormals;
  352. /** Replacement for aiMesh::mTangents. */
  353. C_STRUCT aiVector3D* mTangents;
  354. /** Replacement for aiMesh::mBitangents. */
  355. C_STRUCT aiVector3D* mBitangents;
  356. /** Replacement for aiMesh::mColors */
  357. C_STRUCT aiColor4D* mColors[AI_MAX_NUMBER_OF_COLOR_SETS];
  358. /** Replacement for aiMesh::mTextureCoords */
  359. C_STRUCT aiVector3D* mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS];
  360. /** The number of vertices in the aiAnimMesh, and thus the length of all
  361. * the member arrays.
  362. *
  363. * This has always the same value as the mNumVertices property in the
  364. * corresponding aiMesh. It is duplicated here merely to make the length
  365. * of the member arrays accessible even if the aiMesh is not known, e.g.
  366. * from language bindings.
  367. */
  368. unsigned int mNumVertices;
  369. /**
  370. * Weight of the AnimMesh.
  371. */
  372. float mWeight;
  373. #ifdef __cplusplus
  374. aiAnimMesh() AI_NO_EXCEPT
  375. : mVertices( nullptr )
  376. , mNormals(nullptr)
  377. , mTangents(nullptr)
  378. , mBitangents(nullptr)
  379. , mColors()
  380. , mTextureCoords()
  381. , mNumVertices( 0 )
  382. , mWeight( 0.0f )
  383. {
  384. // fixme consider moving this to the ctor initializer list as well
  385. for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++){
  386. mTextureCoords[a] = nullptr;
  387. }
  388. for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
  389. mColors[a] = nullptr;
  390. }
  391. }
  392. ~aiAnimMesh()
  393. {
  394. delete [] mVertices;
  395. delete [] mNormals;
  396. delete [] mTangents;
  397. delete [] mBitangents;
  398. for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) {
  399. delete [] mTextureCoords[a];
  400. }
  401. for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
  402. delete [] mColors[a];
  403. }
  404. }
  405. /** Check whether the anim mesh overrides the vertex positions
  406. * of its host mesh*/
  407. bool HasPositions() const {
  408. return mVertices != nullptr;
  409. }
  410. /** Check whether the anim mesh overrides the vertex normals
  411. * of its host mesh*/
  412. bool HasNormals() const {
  413. return mNormals != nullptr;
  414. }
  415. /** Check whether the anim mesh overrides the vertex tangents
  416. * and bitangents of its host mesh. As for aiMesh,
  417. * tangents and bitangents always go together. */
  418. bool HasTangentsAndBitangents() const {
  419. return mTangents != nullptr;
  420. }
  421. /** Check whether the anim mesh overrides a particular
  422. * set of vertex colors on his host mesh.
  423. * @param pIndex 0<index<AI_MAX_NUMBER_OF_COLOR_SETS */
  424. bool HasVertexColors( unsigned int pIndex) const {
  425. return pIndex >= AI_MAX_NUMBER_OF_COLOR_SETS ? false : mColors[pIndex] != nullptr;
  426. }
  427. /** Check whether the anim mesh overrides a particular
  428. * set of texture coordinates on his host mesh.
  429. * @param pIndex 0<index<AI_MAX_NUMBER_OF_TEXTURECOORDS */
  430. bool HasTextureCoords( unsigned int pIndex) const {
  431. return pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS ? false : mTextureCoords[pIndex] != nullptr;
  432. }
  433. #endif
  434. };
  435. // ---------------------------------------------------------------------------
  436. /** @brief Enumerates the methods of mesh morphing supported by Assimp.
  437. */
  438. enum aiMorphingMethod
  439. {
  440. /** Interpolation between morph targets */
  441. aiMorphingMethod_VERTEX_BLEND = 0x1,
  442. /** Normalized morphing between morph targets */
  443. aiMorphingMethod_MORPH_NORMALIZED = 0x2,
  444. /** Relative morphing between morph targets */
  445. aiMorphingMethod_MORPH_RELATIVE = 0x3,
  446. /** This value is not used. It is just here to force the
  447. * compiler to map this enum to a 32 Bit integer.
  448. */
  449. #ifndef SWIG
  450. _aiMorphingMethod_Force32Bit = INT_MAX
  451. #endif
  452. }; //! enum aiMorphingMethod
  453. // ---------------------------------------------------------------------------
  454. /** @brief A mesh represents a geometry or model with a single material.
  455. *
  456. * It usually consists of a number of vertices and a series of primitives/faces
  457. * referencing the vertices. In addition there might be a series of bones, each
  458. * of them addressing a number of vertices with a certain weight. Vertex data
  459. * is presented in channels with each channel containing a single per-vertex
  460. * information such as a set of texture coords or a normal vector.
  461. * If a data pointer is non-null, the corresponding data stream is present.
  462. * From C++-programs you can also use the comfort functions Has*() to
  463. * test for the presence of various data streams.
  464. *
  465. * A Mesh uses only a single material which is referenced by a material ID.
  466. * @note The mPositions member is usually not optional. However, vertex positions
  467. * *could* be missing if the #AI_SCENE_FLAGS_INCOMPLETE flag is set in
  468. * @code
  469. * aiScene::mFlags
  470. * @endcode
  471. */
  472. struct aiMesh
  473. {
  474. /** Bitwise combination of the members of the #aiPrimitiveType enum.
  475. * This specifies which types of primitives are present in the mesh.
  476. * The "SortByPrimitiveType"-Step can be used to make sure the
  477. * output meshes consist of one primitive type each.
  478. */
  479. unsigned int mPrimitiveTypes;
  480. /** The number of vertices in this mesh.
  481. * This is also the size of all of the per-vertex data arrays.
  482. * The maximum value for this member is #AI_MAX_VERTICES.
  483. */
  484. unsigned int mNumVertices;
  485. /** The number of primitives (triangles, polygons, lines) in this mesh.
  486. * This is also the size of the mFaces array.
  487. * The maximum value for this member is #AI_MAX_FACES.
  488. */
  489. unsigned int mNumFaces;
  490. /** Vertex positions.
  491. * This array is always present in a mesh. The array is
  492. * mNumVertices in size.
  493. */
  494. C_STRUCT aiVector3D* mVertices;
  495. /** Vertex normals.
  496. * The array contains normalized vectors, NULL if not present.
  497. * The array is mNumVertices in size. Normals are undefined for
  498. * point and line primitives. A mesh consisting of points and
  499. * lines only may not have normal vectors. Meshes with mixed
  500. * primitive types (i.e. lines and triangles) may have normals,
  501. * but the normals for vertices that are only referenced by
  502. * point or line primitives are undefined and set to QNaN (WARN:
  503. * qNaN compares to inequal to *everything*, even to qNaN itself.
  504. * Using code like this to check whether a field is qnan is:
  505. * @code
  506. * #define IS_QNAN(f) (f != f)
  507. * @endcode
  508. * still dangerous because even 1.f == 1.f could evaluate to false! (
  509. * remember the subtleties of IEEE754 artithmetics). Use stuff like
  510. * @c fpclassify instead.
  511. * @note Normal vectors computed by Assimp are always unit-length.
  512. * However, this needn't apply for normals that have been taken
  513. * directly from the model file.
  514. */
  515. C_STRUCT aiVector3D* mNormals;
  516. /** Vertex tangents.
  517. * The tangent of a vertex points in the direction of the positive
  518. * X texture axis. The array contains normalized vectors, NULL if
  519. * not present. The array is mNumVertices in size. A mesh consisting
  520. * of points and lines only may not have normal vectors. Meshes with
  521. * mixed primitive types (i.e. lines and triangles) may have
  522. * normals, but the normals for vertices that are only referenced by
  523. * point or line primitives are undefined and set to qNaN. See
  524. * the #mNormals member for a detailed discussion of qNaNs.
  525. * @note If the mesh contains tangents, it automatically also
  526. * contains bitangents.
  527. */
  528. C_STRUCT aiVector3D* mTangents;
  529. /** Vertex bitangents.
  530. * The bitangent of a vertex points in the direction of the positive
  531. * Y texture axis. The array contains normalized vectors, NULL if not
  532. * present. The array is mNumVertices in size.
  533. * @note If the mesh contains tangents, it automatically also contains
  534. * bitangents.
  535. */
  536. C_STRUCT aiVector3D* mBitangents;
  537. /** Vertex color sets.
  538. * A mesh may contain 0 to #AI_MAX_NUMBER_OF_COLOR_SETS vertex
  539. * colors per vertex. NULL if not present. Each array is
  540. * mNumVertices in size if present.
  541. */
  542. C_STRUCT aiColor4D* mColors[AI_MAX_NUMBER_OF_COLOR_SETS];
  543. /** Vertex texture coords, also known as UV channels.
  544. * A mesh may contain 0 to AI_MAX_NUMBER_OF_TEXTURECOORDS per
  545. * vertex. NULL if not present. The array is mNumVertices in size.
  546. */
  547. C_STRUCT aiVector3D* mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS];
  548. /** Specifies the number of components for a given UV channel.
  549. * Up to three channels are supported (UVW, for accessing volume
  550. * or cube maps). If the value is 2 for a given channel n, the
  551. * component p.z of mTextureCoords[n][p] is set to 0.0f.
  552. * If the value is 1 for a given channel, p.y is set to 0.0f, too.
  553. * @note 4D coords are not supported
  554. */
  555. unsigned int mNumUVComponents[AI_MAX_NUMBER_OF_TEXTURECOORDS];
  556. /** The faces the mesh is constructed from.
  557. * Each face refers to a number of vertices by their indices.
  558. * This array is always present in a mesh, its size is given
  559. * in mNumFaces. If the #AI_SCENE_FLAGS_NON_VERBOSE_FORMAT
  560. * is NOT set each face references an unique set of vertices.
  561. */
  562. C_STRUCT aiFace* mFaces;
  563. /** The number of bones this mesh contains.
  564. * Can be 0, in which case the mBones array is NULL.
  565. */
  566. unsigned int mNumBones;
  567. /** The bones of this mesh.
  568. * A bone consists of a name by which it can be found in the
  569. * frame hierarchy and a set of vertex weights.
  570. */
  571. C_STRUCT aiBone** mBones;
  572. /** The material used by this mesh.
  573. * A mesh uses only a single material. If an imported model uses
  574. * multiple materials, the import splits up the mesh. Use this value
  575. * as index into the scene's material list.
  576. */
  577. unsigned int mMaterialIndex;
  578. /** Name of the mesh. Meshes can be named, but this is not a
  579. * requirement and leaving this field empty is totally fine.
  580. * There are mainly three uses for mesh names:
  581. * - some formats name nodes and meshes independently.
  582. * - importers tend to split meshes up to meet the
  583. * one-material-per-mesh requirement. Assigning
  584. * the same (dummy) name to each of the result meshes
  585. * aids the caller at recovering the original mesh
  586. * partitioning.
  587. * - Vertex animations refer to meshes by their names.
  588. **/
  589. C_STRUCT aiString mName;
  590. /** The number of attachment meshes. Note! Currently only works with Collada loader. */
  591. unsigned int mNumAnimMeshes;
  592. /** Attachment meshes for this mesh, for vertex-based animation.
  593. * Attachment meshes carry replacement data for some of the
  594. * mesh'es vertex components (usually positions, normals).
  595. * Note! Currently only works with Collada loader.*/
  596. C_STRUCT aiAnimMesh** mAnimMeshes;
  597. /**
  598. * Method of morphing when animeshes are specified.
  599. */
  600. unsigned int mMethod;
  601. #ifdef __cplusplus
  602. //! Default constructor. Initializes all members to 0
  603. aiMesh() AI_NO_EXCEPT
  604. : mPrimitiveTypes( 0 )
  605. , mNumVertices( 0 )
  606. , mNumFaces( 0 )
  607. , mVertices( nullptr )
  608. , mNormals(nullptr)
  609. , mTangents(nullptr)
  610. , mBitangents(nullptr)
  611. , mColors()
  612. , mTextureCoords()
  613. , mNumUVComponents()
  614. , mFaces(nullptr)
  615. , mNumBones( 0 )
  616. , mBones(nullptr)
  617. , mMaterialIndex( 0 )
  618. , mNumAnimMeshes( 0 )
  619. , mAnimMeshes(nullptr)
  620. , mMethod( 0 ) {
  621. for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a ) {
  622. mNumUVComponents[a] = 0;
  623. mTextureCoords[a] = nullptr;
  624. }
  625. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; ++a) {
  626. mColors[a] = nullptr;
  627. }
  628. }
  629. //! Deletes all storage allocated for the mesh
  630. ~aiMesh() {
  631. delete [] mVertices;
  632. delete [] mNormals;
  633. delete [] mTangents;
  634. delete [] mBitangents;
  635. for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) {
  636. delete [] mTextureCoords[a];
  637. }
  638. for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
  639. delete [] mColors[a];
  640. }
  641. // DO NOT REMOVE THIS ADDITIONAL CHECK
  642. if (mNumBones && mBones) {
  643. for( unsigned int a = 0; a < mNumBones; a++) {
  644. delete mBones[a];
  645. }
  646. delete [] mBones;
  647. }
  648. if (mNumAnimMeshes && mAnimMeshes) {
  649. for( unsigned int a = 0; a < mNumAnimMeshes; a++) {
  650. delete mAnimMeshes[a];
  651. }
  652. delete [] mAnimMeshes;
  653. }
  654. delete [] mFaces;
  655. }
  656. //! Check whether the mesh contains positions. Provided no special
  657. //! scene flags are set, this will always be true
  658. bool HasPositions() const
  659. { return mVertices != nullptr && mNumVertices > 0; }
  660. //! Check whether the mesh contains faces. If no special scene flags
  661. //! are set this should always return true
  662. bool HasFaces() const
  663. { return mFaces != nullptr && mNumFaces > 0; }
  664. //! Check whether the mesh contains normal vectors
  665. bool HasNormals() const
  666. { return mNormals != nullptr && mNumVertices > 0; }
  667. //! Check whether the mesh contains tangent and bitangent vectors
  668. //! It is not possible that it contains tangents and no bitangents
  669. //! (or the other way round). The existence of one of them
  670. //! implies that the second is there, too.
  671. bool HasTangentsAndBitangents() const
  672. { return mTangents != nullptr && mBitangents != nullptr && mNumVertices > 0; }
  673. //! Check whether the mesh contains a vertex color set
  674. //! \param pIndex Index of the vertex color set
  675. bool HasVertexColors( unsigned int pIndex) const {
  676. if (pIndex >= AI_MAX_NUMBER_OF_COLOR_SETS) {
  677. return false;
  678. } else {
  679. return mColors[pIndex] != nullptr && mNumVertices > 0;
  680. }
  681. }
  682. //! Check whether the mesh contains a texture coordinate set
  683. //! \param pIndex Index of the texture coordinates set
  684. bool HasTextureCoords( unsigned int pIndex) const {
  685. if (pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS) {
  686. return false;
  687. } else {
  688. return mTextureCoords[pIndex] != nullptr && mNumVertices > 0;
  689. }
  690. }
  691. //! Get the number of UV channels the mesh contains
  692. unsigned int GetNumUVChannels() const {
  693. unsigned int n( 0 );
  694. while (n < AI_MAX_NUMBER_OF_TEXTURECOORDS && mTextureCoords[n]) {
  695. ++n;
  696. }
  697. return n;
  698. }
  699. //! Get the number of vertex color channels the mesh contains
  700. unsigned int GetNumColorChannels() const {
  701. unsigned int n(0);
  702. while (n < AI_MAX_NUMBER_OF_COLOR_SETS && mColors[n]) {
  703. ++n;
  704. }
  705. return n;
  706. }
  707. //! Check whether the mesh contains bones
  708. bool HasBones() const {
  709. return mBones != nullptr && mNumBones > 0;
  710. }
  711. #endif // __cplusplus
  712. };
  713. #ifdef __cplusplus
  714. }
  715. #endif //! extern "C"
  716. #endif // AI_MESH_H_INC