mesh.h 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2021, 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 _MSC_VER
  45. #pragma warning(disable : 4351)
  46. #endif // _MSC_VER
  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. #ifndef ASSIMP_BUILD_NO_ARMATUREPOPULATE_PROCESS
  247. mArmature(nullptr),
  248. mNode(nullptr),
  249. #endif
  250. mWeights(nullptr),
  251. mOffsetMatrix() {
  252. // empty
  253. }
  254. //! Copy constructor
  255. aiBone(const aiBone &other) :
  256. mName(other.mName),
  257. mNumWeights(other.mNumWeights),
  258. #ifndef ASSIMP_BUILD_NO_ARMATUREPOPULATE_PROCESS
  259. mArmature(nullptr),
  260. mNode(nullptr),
  261. #endif
  262. mWeights(nullptr),
  263. mOffsetMatrix(other.mOffsetMatrix) {
  264. if (other.mWeights && other.mNumWeights) {
  265. mWeights = new aiVertexWeight[mNumWeights];
  266. ::memcpy(mWeights, other.mWeights, mNumWeights * sizeof(aiVertexWeight));
  267. }
  268. }
  269. //! Assignment operator
  270. aiBone &operator=(const aiBone &other) {
  271. if (this == &other) {
  272. return *this;
  273. }
  274. mName = other.mName;
  275. mNumWeights = other.mNumWeights;
  276. mOffsetMatrix = other.mOffsetMatrix;
  277. if (other.mWeights && other.mNumWeights) {
  278. if (mWeights) {
  279. delete[] mWeights;
  280. }
  281. mWeights = new aiVertexWeight[mNumWeights];
  282. ::memcpy(mWeights, other.mWeights, mNumWeights * sizeof(aiVertexWeight));
  283. }
  284. return *this;
  285. }
  286. bool operator==(const aiBone &rhs) const {
  287. if (mName != rhs.mName || mNumWeights != rhs.mNumWeights) {
  288. return false;
  289. }
  290. for (size_t i = 0; i < mNumWeights; ++i) {
  291. if (mWeights[i] != rhs.mWeights[i]) {
  292. return false;
  293. }
  294. }
  295. return true;
  296. }
  297. //! Destructor - deletes the array of vertex weights
  298. ~aiBone() {
  299. delete[] mWeights;
  300. }
  301. #endif // __cplusplus
  302. };
  303. // ---------------------------------------------------------------------------
  304. /** @brief Enumerates the types of geometric primitives supported by Assimp.
  305. *
  306. * @see aiFace Face data structure
  307. * @see aiProcess_SortByPType Per-primitive sorting of meshes
  308. * @see aiProcess_Triangulate Automatic triangulation
  309. * @see AI_CONFIG_PP_SBP_REMOVE Removal of specific primitive types.
  310. */
  311. enum aiPrimitiveType {
  312. /** A point primitive.
  313. *
  314. * This is just a single vertex in the virtual world,
  315. * #aiFace contains just one index for such a primitive.
  316. */
  317. aiPrimitiveType_POINT = 0x1,
  318. /** A line primitive.
  319. *
  320. * This is a line defined through a start and an end position.
  321. * #aiFace contains exactly two indices for such a primitive.
  322. */
  323. aiPrimitiveType_LINE = 0x2,
  324. /** A triangular primitive.
  325. *
  326. * A triangle consists of three indices.
  327. */
  328. aiPrimitiveType_TRIANGLE = 0x4,
  329. /** A higher-level polygon with more than 3 edges.
  330. *
  331. * A triangle is a polygon, but polygon in this context means
  332. * "all polygons that are not triangles". The "Triangulate"-Step
  333. * is provided for your convenience, it splits all polygons in
  334. * triangles (which are much easier to handle).
  335. */
  336. aiPrimitiveType_POLYGON = 0x8,
  337. /**
  338. * A flag to determine whether this triangles only mesh is NGON encoded.
  339. *
  340. * NGON encoding is a special encoding that tells whether 2 or more consecutive triangles
  341. * should be considered as a triangle fan. This is identified by looking at the first vertex index.
  342. * 2 consecutive triangles with the same 1st vertex index are part of the same
  343. * NGON.
  344. *
  345. * At the moment, only quads (concave or convex) are supported, meaning that polygons are 'seen' as
  346. * triangles, as usual after a triangulation pass.
  347. *
  348. * To get an NGON encoded mesh, please use the aiProcess_Triangulate post process.
  349. *
  350. * @see aiProcess_Triangulate
  351. * @link https://github.com/KhronosGroup/glTF/pull/1620
  352. */
  353. aiPrimitiveType_NGONEncodingFlag = 0x10,
  354. /** This value is not used. It is just here to force the
  355. * compiler to map this enum to a 32 Bit integer.
  356. */
  357. #ifndef SWIG
  358. _aiPrimitiveType_Force32Bit = INT_MAX
  359. #endif
  360. }; //! enum aiPrimitiveType
  361. // Get the #aiPrimitiveType flag for a specific number of face indices
  362. #define AI_PRIMITIVE_TYPE_FOR_N_INDICES(n) \
  363. ((n) > 3 ? aiPrimitiveType_POLYGON : (aiPrimitiveType)(1u << ((n)-1)))
  364. // ---------------------------------------------------------------------------
  365. /** @brief An AnimMesh is an attachment to an #aiMesh stores per-vertex
  366. * animations for a particular frame.
  367. *
  368. * You may think of an #aiAnimMesh as a `patch` for the host mesh, which
  369. * replaces only certain vertex data streams at a particular time.
  370. * Each mesh stores n attached attached meshes (#aiMesh::mAnimMeshes).
  371. * The actual relationship between the time line and anim meshes is
  372. * established by #aiMeshAnim, which references singular mesh attachments
  373. * by their ID and binds them to a time offset.
  374. */
  375. struct aiAnimMesh {
  376. /**Anim Mesh name */
  377. C_STRUCT aiString mName;
  378. /** Replacement for aiMesh::mVertices. If this array is non-nullptr,
  379. * it *must* contain mNumVertices entries. The corresponding
  380. * array in the host mesh must be non-nullptr as well - animation
  381. * meshes may neither add or nor remove vertex components (if
  382. * a replacement array is nullptr and the corresponding source
  383. * array is not, the source data is taken instead)*/
  384. C_STRUCT aiVector3D *mVertices;
  385. /** Replacement for aiMesh::mNormals. */
  386. C_STRUCT aiVector3D *mNormals;
  387. /** Replacement for aiMesh::mTangents. */
  388. C_STRUCT aiVector3D *mTangents;
  389. /** Replacement for aiMesh::mBitangents. */
  390. C_STRUCT aiVector3D *mBitangents;
  391. /** Replacement for aiMesh::mColors */
  392. C_STRUCT aiColor4D *mColors[AI_MAX_NUMBER_OF_COLOR_SETS];
  393. /** Replacement for aiMesh::mTextureCoords */
  394. C_STRUCT aiVector3D *mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS];
  395. /** The number of vertices in the aiAnimMesh, and thus the length of all
  396. * the member arrays.
  397. *
  398. * This has always the same value as the mNumVertices property in the
  399. * corresponding aiMesh. It is duplicated here merely to make the length
  400. * of the member arrays accessible even if the aiMesh is not known, e.g.
  401. * from language bindings.
  402. */
  403. unsigned int mNumVertices;
  404. /**
  405. * Weight of the AnimMesh.
  406. */
  407. float mWeight;
  408. #ifdef __cplusplus
  409. aiAnimMesh() AI_NO_EXCEPT
  410. : mVertices(nullptr),
  411. mNormals(nullptr),
  412. mTangents(nullptr),
  413. mBitangents(nullptr),
  414. mColors(),
  415. mTextureCoords(),
  416. mNumVertices(0),
  417. mWeight(0.0f) {
  418. // fixme consider moving this to the ctor initializer list as well
  419. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) {
  420. mTextureCoords[a] = nullptr;
  421. }
  422. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
  423. mColors[a] = nullptr;
  424. }
  425. }
  426. ~aiAnimMesh() {
  427. delete[] mVertices;
  428. delete[] mNormals;
  429. delete[] mTangents;
  430. delete[] mBitangents;
  431. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) {
  432. delete[] mTextureCoords[a];
  433. }
  434. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
  435. delete[] mColors[a];
  436. }
  437. }
  438. /** Check whether the anim mesh overrides the vertex positions
  439. * of its host mesh*/
  440. bool HasPositions() const {
  441. return mVertices != nullptr;
  442. }
  443. /** Check whether the anim mesh overrides the vertex normals
  444. * of its host mesh*/
  445. bool HasNormals() const {
  446. return mNormals != nullptr;
  447. }
  448. /** Check whether the anim mesh overrides the vertex tangents
  449. * and bitangents of its host mesh. As for aiMesh,
  450. * tangents and bitangents always go together. */
  451. bool HasTangentsAndBitangents() const {
  452. return mTangents != nullptr;
  453. }
  454. /** Check whether the anim mesh overrides a particular
  455. * set of vertex colors on his host mesh.
  456. * @param pIndex 0<index<AI_MAX_NUMBER_OF_COLOR_SETS */
  457. bool HasVertexColors(unsigned int pIndex) const {
  458. return pIndex >= AI_MAX_NUMBER_OF_COLOR_SETS ? false : mColors[pIndex] != nullptr;
  459. }
  460. /** Check whether the anim mesh overrides a particular
  461. * set of texture coordinates on his host mesh.
  462. * @param pIndex 0<index<AI_MAX_NUMBER_OF_TEXTURECOORDS */
  463. bool HasTextureCoords(unsigned int pIndex) const {
  464. return pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS ? false : mTextureCoords[pIndex] != nullptr;
  465. }
  466. #endif
  467. };
  468. // ---------------------------------------------------------------------------
  469. /** @brief Enumerates the methods of mesh morphing supported by Assimp.
  470. */
  471. enum aiMorphingMethod {
  472. /** Interpolation between morph targets */
  473. aiMorphingMethod_VERTEX_BLEND = 0x1,
  474. /** Normalized morphing between morph targets */
  475. aiMorphingMethod_MORPH_NORMALIZED = 0x2,
  476. /** Relative morphing between morph targets */
  477. aiMorphingMethod_MORPH_RELATIVE = 0x3,
  478. /** This value is not used. It is just here to force the
  479. * compiler to map this enum to a 32 Bit integer.
  480. */
  481. #ifndef SWIG
  482. _aiMorphingMethod_Force32Bit = INT_MAX
  483. #endif
  484. }; //! enum aiMorphingMethod
  485. // ---------------------------------------------------------------------------
  486. /** @brief A mesh represents a geometry or model with a single material.
  487. *
  488. * It usually consists of a number of vertices and a series of primitives/faces
  489. * referencing the vertices. In addition there might be a series of bones, each
  490. * of them addressing a number of vertices with a certain weight. Vertex data
  491. * is presented in channels with each channel containing a single per-vertex
  492. * information such as a set of texture coordinates or a normal vector.
  493. * If a data pointer is non-null, the corresponding data stream is present.
  494. * From C++-programs you can also use the comfort functions Has*() to
  495. * test for the presence of various data streams.
  496. *
  497. * A Mesh uses only a single material which is referenced by a material ID.
  498. * @note The mPositions member is usually not optional. However, vertex positions
  499. * *could* be missing if the #AI_SCENE_FLAGS_INCOMPLETE flag is set in
  500. * @code
  501. * aiScene::mFlags
  502. * @endcode
  503. */
  504. struct aiMesh {
  505. /** Bitwise combination of the members of the #aiPrimitiveType enum.
  506. * This specifies which types of primitives are present in the mesh.
  507. * The "SortByPrimitiveType"-Step can be used to make sure the
  508. * output meshes consist of one primitive type each.
  509. */
  510. unsigned int mPrimitiveTypes;
  511. /** The number of vertices in this mesh.
  512. * This is also the size of all of the per-vertex data arrays.
  513. * The maximum value for this member is #AI_MAX_VERTICES.
  514. */
  515. unsigned int mNumVertices;
  516. /** The number of primitives (triangles, polygons, lines) in this mesh.
  517. * This is also the size of the mFaces array.
  518. * The maximum value for this member is #AI_MAX_FACES.
  519. */
  520. unsigned int mNumFaces;
  521. /** Vertex positions.
  522. * This array is always present in a mesh. The array is
  523. * mNumVertices in size.
  524. */
  525. C_STRUCT aiVector3D *mVertices;
  526. /** Vertex normals.
  527. * The array contains normalized vectors, nullptr if not present.
  528. * The array is mNumVertices in size. Normals are undefined for
  529. * point and line primitives. A mesh consisting of points and
  530. * lines only may not have normal vectors. Meshes with mixed
  531. * primitive types (i.e. lines and triangles) may have normals,
  532. * but the normals for vertices that are only referenced by
  533. * point or line primitives are undefined and set to QNaN (WARN:
  534. * qNaN compares to inequal to *everything*, even to qNaN itself.
  535. * Using code like this to check whether a field is qnan is:
  536. * @code
  537. * #define IS_QNAN(f) (f != f)
  538. * @endcode
  539. * still dangerous because even 1.f == 1.f could evaluate to false! (
  540. * remember the subtleties of IEEE754 artithmetics). Use stuff like
  541. * @c fpclassify instead.
  542. * @note Normal vectors computed by Assimp are always unit-length.
  543. * However, this needn't apply for normals that have been taken
  544. * directly from the model file.
  545. */
  546. C_STRUCT aiVector3D *mNormals;
  547. /** Vertex tangents.
  548. * The tangent of a vertex points in the direction of the positive
  549. * X texture axis. The array contains normalized vectors, nullptr if
  550. * not present. The array is mNumVertices in size. A mesh consisting
  551. * of points and lines only may not have normal vectors. Meshes with
  552. * mixed primitive types (i.e. lines and triangles) may have
  553. * normals, but the normals for vertices that are only referenced by
  554. * point or line primitives are undefined and set to qNaN. See
  555. * the #mNormals member for a detailed discussion of qNaNs.
  556. * @note If the mesh contains tangents, it automatically also
  557. * contains bitangents.
  558. */
  559. C_STRUCT aiVector3D *mTangents;
  560. /** Vertex bitangents.
  561. * The bitangent of a vertex points in the direction of the positive
  562. * Y texture axis. The array contains normalized vectors, nullptr if not
  563. * present. The array is mNumVertices in size.
  564. * @note If the mesh contains tangents, it automatically also contains
  565. * bitangents.
  566. */
  567. C_STRUCT aiVector3D *mBitangents;
  568. /** Vertex color sets.
  569. * A mesh may contain 0 to #AI_MAX_NUMBER_OF_COLOR_SETS vertex
  570. * colors per vertex. nullptr if not present. Each array is
  571. * mNumVertices in size if present.
  572. */
  573. C_STRUCT aiColor4D *mColors[AI_MAX_NUMBER_OF_COLOR_SETS];
  574. /** Vertex texture coordinates, also known as UV channels.
  575. * A mesh may contain 0 to AI_MAX_NUMBER_OF_TEXTURECOORDS per
  576. * vertex. nullptr if not present. The array is mNumVertices in size.
  577. */
  578. C_STRUCT aiVector3D *mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS];
  579. /** Specifies the number of components for a given UV channel.
  580. * Up to three channels are supported (UVW, for accessing volume
  581. * or cube maps). If the value is 2 for a given channel n, the
  582. * component p.z of mTextureCoords[n][p] is set to 0.0f.
  583. * If the value is 1 for a given channel, p.y is set to 0.0f, too.
  584. * @note 4D coordinates are not supported
  585. */
  586. unsigned int mNumUVComponents[AI_MAX_NUMBER_OF_TEXTURECOORDS];
  587. /** The faces the mesh is constructed from.
  588. * Each face refers to a number of vertices by their indices.
  589. * This array is always present in a mesh, its size is given
  590. * in mNumFaces. If the #AI_SCENE_FLAGS_NON_VERBOSE_FORMAT
  591. * is NOT set each face references an unique set of vertices.
  592. */
  593. C_STRUCT aiFace *mFaces;
  594. /** The number of bones this mesh contains.
  595. * Can be 0, in which case the mBones array is nullptr.
  596. */
  597. unsigned int mNumBones;
  598. /** The bones of this mesh.
  599. * A bone consists of a name by which it can be found in the
  600. * frame hierarchy and a set of vertex weights.
  601. */
  602. C_STRUCT aiBone **mBones;
  603. /** The material used by this mesh.
  604. * A mesh uses only a single material. If an imported model uses
  605. * multiple materials, the import splits up the mesh. Use this value
  606. * as index into the scene's material list.
  607. */
  608. unsigned int mMaterialIndex;
  609. /** Name of the mesh. Meshes can be named, but this is not a
  610. * requirement and leaving this field empty is totally fine.
  611. * There are mainly three uses for mesh names:
  612. * - some formats name nodes and meshes independently.
  613. * - importers tend to split meshes up to meet the
  614. * one-material-per-mesh requirement. Assigning
  615. * the same (dummy) name to each of the result meshes
  616. * aids the caller at recovering the original mesh
  617. * partitioning.
  618. * - Vertex animations refer to meshes by their names.
  619. **/
  620. C_STRUCT aiString mName;
  621. /** The number of attachment meshes. Note! Currently only works with Collada loader. */
  622. unsigned int mNumAnimMeshes;
  623. /** Attachment meshes for this mesh, for vertex-based animation.
  624. * Attachment meshes carry replacement data for some of the
  625. * mesh'es vertex components (usually positions, normals).
  626. * Note! Currently only works with Collada loader.*/
  627. C_STRUCT aiAnimMesh **mAnimMeshes;
  628. /**
  629. * Method of morphing when anim-meshes are specified.
  630. */
  631. unsigned int mMethod;
  632. /**
  633. * The bounding box.
  634. */
  635. C_STRUCT aiAABB mAABB;
  636. /** Vertex UV stream names. Pointer to array of size AI_MAX_NUMBER_OF_TEXTURECOORDS
  637. */
  638. C_STRUCT aiString **mTextureCoordsNames;
  639. #ifdef __cplusplus
  640. //! Default constructor. Initializes all members to 0
  641. aiMesh() AI_NO_EXCEPT
  642. : mPrimitiveTypes(0),
  643. mNumVertices(0),
  644. mNumFaces(0),
  645. mVertices(nullptr),
  646. mNormals(nullptr),
  647. mTangents(nullptr),
  648. mBitangents(nullptr),
  649. mColors(),
  650. mTextureCoords(),
  651. mNumUVComponents(),
  652. mFaces(nullptr),
  653. mNumBones(0),
  654. mBones(nullptr),
  655. mMaterialIndex(0),
  656. mNumAnimMeshes(0),
  657. mAnimMeshes(nullptr),
  658. mMethod(0),
  659. mAABB(),
  660. mTextureCoordsNames(nullptr) {
  661. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a) {
  662. mNumUVComponents[a] = 0;
  663. mTextureCoords[a] = nullptr;
  664. }
  665. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; ++a) {
  666. mColors[a] = nullptr;
  667. }
  668. }
  669. //! Deletes all storage allocated for the mesh
  670. ~aiMesh() {
  671. delete[] mVertices;
  672. delete[] mNormals;
  673. delete[] mTangents;
  674. delete[] mBitangents;
  675. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) {
  676. delete[] mTextureCoords[a];
  677. }
  678. if (mTextureCoordsNames) {
  679. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) {
  680. delete mTextureCoordsNames[a];
  681. }
  682. delete[] mTextureCoordsNames;
  683. }
  684. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
  685. delete[] mColors[a];
  686. }
  687. // DO NOT REMOVE THIS ADDITIONAL CHECK
  688. if (mNumBones && mBones) {
  689. for (unsigned int a = 0; a < mNumBones; a++) {
  690. if (mBones[a]) {
  691. delete mBones[a];
  692. }
  693. }
  694. delete[] mBones;
  695. }
  696. if (mNumAnimMeshes && mAnimMeshes) {
  697. for (unsigned int a = 0; a < mNumAnimMeshes; a++) {
  698. delete mAnimMeshes[a];
  699. }
  700. delete[] mAnimMeshes;
  701. }
  702. delete[] mFaces;
  703. }
  704. //! Check whether the mesh contains positions. Provided no special
  705. //! scene flags are set, this will always be true
  706. bool HasPositions() const { return mVertices != nullptr && mNumVertices > 0; }
  707. //! Check whether the mesh contains faces. If no special scene flags
  708. //! are set this should always return true
  709. bool HasFaces() const { return mFaces != nullptr && mNumFaces > 0; }
  710. //! Check whether the mesh contains normal vectors
  711. bool HasNormals() const { return mNormals != nullptr && mNumVertices > 0; }
  712. //! Check whether the mesh contains tangent and bitangent vectors
  713. //! It is not possible that it contains tangents and no bitangents
  714. //! (or the other way round). The existence of one of them
  715. //! implies that the second is there, too.
  716. bool HasTangentsAndBitangents() const { return mTangents != nullptr && mBitangents != nullptr && mNumVertices > 0; }
  717. //! Check whether the mesh contains a vertex color set
  718. //! \param pIndex Index of the vertex color set
  719. bool HasVertexColors(unsigned int pIndex) const {
  720. if (pIndex >= AI_MAX_NUMBER_OF_COLOR_SETS) {
  721. return false;
  722. } else {
  723. return mColors[pIndex] != nullptr && mNumVertices > 0;
  724. }
  725. }
  726. //! Check whether the mesh contains a texture coordinate set
  727. //! \param pIndex Index of the texture coordinates set
  728. bool HasTextureCoords(unsigned int pIndex) const {
  729. if (pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS) {
  730. return false;
  731. } else {
  732. return mTextureCoords[pIndex] != nullptr && mNumVertices > 0;
  733. }
  734. }
  735. //! Get the number of UV channels the mesh contains
  736. unsigned int GetNumUVChannels() const {
  737. unsigned int n(0);
  738. while (n < AI_MAX_NUMBER_OF_TEXTURECOORDS && mTextureCoords[n]) {
  739. ++n;
  740. }
  741. return n;
  742. }
  743. //! Get the number of vertex color channels the mesh contains
  744. unsigned int GetNumColorChannels() const {
  745. unsigned int n(0);
  746. while (n < AI_MAX_NUMBER_OF_COLOR_SETS && mColors[n]) {
  747. ++n;
  748. }
  749. return n;
  750. }
  751. //! Check whether the mesh contains bones
  752. bool HasBones() const {
  753. return mBones != nullptr && mNumBones > 0;
  754. }
  755. //! Check whether the mesh contains a texture coordinate set name
  756. //! \param pIndex Index of the texture coordinates set
  757. bool HasTextureCoordsName(unsigned int pIndex) const {
  758. if (mTextureCoordsNames == nullptr || pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS) {
  759. return false;
  760. }
  761. return mTextureCoordsNames[pIndex] != nullptr;
  762. }
  763. //! Set a texture coordinate set name
  764. //! \param pIndex Index of the texture coordinates set
  765. //! \param texCoordsName name of the texture coordinate set
  766. void SetTextureCoordsName(unsigned int pIndex, const aiString &texCoordsName) {
  767. if (pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS) {
  768. return;
  769. }
  770. if (mTextureCoordsNames == nullptr) {
  771. // Construct and null-init array
  772. mTextureCoordsNames = new aiString *[AI_MAX_NUMBER_OF_TEXTURECOORDS] {};
  773. }
  774. if (texCoordsName.length == 0) {
  775. delete mTextureCoordsNames[pIndex];
  776. mTextureCoordsNames[pIndex] = nullptr;
  777. return;
  778. }
  779. if (mTextureCoordsNames[pIndex] == nullptr) {
  780. mTextureCoordsNames[pIndex] = new aiString(texCoordsName);
  781. return;
  782. }
  783. *mTextureCoordsNames[pIndex] = texCoordsName;
  784. }
  785. //! Get a texture coordinate set name
  786. //! \param pIndex Index of the texture coordinates set
  787. const aiString *GetTextureCoordsName(unsigned int pIndex) const {
  788. if (mTextureCoordsNames == nullptr || pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS) {
  789. return nullptr;
  790. }
  791. return mTextureCoordsNames[pIndex];
  792. }
  793. #endif // __cplusplus
  794. };
  795. #ifdef __cplusplus
  796. }
  797. #endif //! extern "C"
  798. #endif // AI_MESH_H_INC