mesh.h 29 KB

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