mesh.h 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2023, 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. /**
  89. * @brief A single face in a mesh, referring to multiple vertices.
  90. *
  91. * If mNumIndices is 3, we call the face 'triangle', for mNumIndices > 3
  92. * it's called 'polygon' (hey, that's just a definition!).
  93. * <br>
  94. * aiMesh::mPrimitiveTypes can be queried to quickly examine which types of
  95. * primitive are actually present in a mesh. The #aiProcess_SortByPType flag
  96. * executes a special post-processing algorithm which splits meshes with
  97. * *different* primitive types mixed up (e.g. lines and triangles) in several
  98. * 'clean' sub-meshes. Furthermore there is a configuration option (
  99. * #AI_CONFIG_PP_SBP_REMOVE) to force #aiProcess_SortByPType to remove
  100. * specific kinds of primitives from the imported scene, completely and forever.
  101. * In many cases you'll probably want to set this setting to
  102. * @code
  103. * aiPrimitiveType_LINE|aiPrimitiveType_POINT
  104. * @endcode
  105. * Together with the #aiProcess_Triangulate flag you can then be sure that
  106. * #aiFace::mNumIndices is always 3.
  107. * @note Take a look at the @link data Data Structures page @endlink for
  108. * more information on the layout and winding order of a face.
  109. */
  110. struct aiFace {
  111. //! Number of indices defining this face.
  112. //! The maximum value for this member is #AI_MAX_FACE_INDICES.
  113. unsigned int mNumIndices;
  114. //! Pointer to the indices array. Size of the array is given in numIndices.
  115. unsigned int *mIndices;
  116. #ifdef __cplusplus
  117. //! @brief Default constructor.
  118. aiFace() AI_NO_EXCEPT
  119. : mNumIndices(0),
  120. mIndices(nullptr) {
  121. // empty
  122. }
  123. //! @brief Default destructor. Delete the index array
  124. ~aiFace() {
  125. delete[] mIndices;
  126. }
  127. //! @brief Copy constructor. Copy the index array
  128. aiFace(const aiFace &o) :
  129. mNumIndices(0), mIndices(nullptr) {
  130. *this = o;
  131. }
  132. //! @brief Assignment operator. Copy the index array
  133. aiFace &operator=(const aiFace &o) {
  134. if (&o == this) {
  135. return *this;
  136. }
  137. delete[] mIndices;
  138. mNumIndices = o.mNumIndices;
  139. if (mNumIndices) {
  140. mIndices = new unsigned int[mNumIndices];
  141. ::memcpy(mIndices, o.mIndices, mNumIndices * sizeof(unsigned int));
  142. } else {
  143. mIndices = nullptr;
  144. }
  145. return *this;
  146. }
  147. //! @brief Comparison operator. Checks whether the index array 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. //! @brief 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. //! @brief Default constructor
  183. aiVertexWeight() AI_NO_EXCEPT
  184. : mVertexId(0),
  185. mWeight(0.0f) {
  186. // empty
  187. }
  188. //! @brief 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. /**
  215. * The name of the bone.
  216. */
  217. C_STRUCT aiString mName;
  218. /**
  219. * The number of vertices affected by this bone.
  220. * The maximum value for this member is #AI_MAX_BONE_WEIGHTS.
  221. */
  222. unsigned int mNumWeights;
  223. #ifndef ASSIMP_BUILD_NO_ARMATUREPOPULATE_PROCESS
  224. /**
  225. * The bone armature node - used for skeleton conversion
  226. * you must enable aiProcess_PopulateArmatureData to populate this
  227. */
  228. C_STRUCT aiNode *mArmature;
  229. /**
  230. * The bone node in the scene - used for skeleton conversion
  231. * you must enable aiProcess_PopulateArmatureData to populate this
  232. */
  233. C_STRUCT aiNode *mNode;
  234. #endif
  235. /**
  236. * The influence weights of this bone, by vertex index.
  237. */
  238. C_STRUCT aiVertexWeight *mWeights;
  239. /**
  240. * Matrix that transforms from mesh space to bone space in bind pose.
  241. *
  242. * This matrix describes the position of the mesh
  243. * in the local space of this bone when the skeleton was bound.
  244. * Thus it can be used directly to determine a desired vertex position,
  245. * given the world-space transform of the bone when animated,
  246. * and the position of the vertex in mesh space.
  247. *
  248. * It is sometimes called an inverse-bind matrix,
  249. * or inverse bind pose matrix.
  250. */
  251. C_STRUCT aiMatrix4x4 mOffsetMatrix;
  252. #ifdef __cplusplus
  253. /// @brief Default constructor
  254. aiBone() AI_NO_EXCEPT
  255. : mName(),
  256. mNumWeights(0),
  257. #ifndef ASSIMP_BUILD_NO_ARMATUREPOPULATE_PROCESS
  258. mArmature(nullptr),
  259. mNode(nullptr),
  260. #endif
  261. mWeights(nullptr),
  262. mOffsetMatrix() {
  263. // empty
  264. }
  265. /// @brief Copy constructor
  266. aiBone(const aiBone &other) :
  267. mName(other.mName),
  268. mNumWeights(other.mNumWeights),
  269. #ifndef ASSIMP_BUILD_NO_ARMATUREPOPULATE_PROCESS
  270. mArmature(nullptr),
  271. mNode(nullptr),
  272. #endif
  273. mWeights(nullptr),
  274. mOffsetMatrix(other.mOffsetMatrix) {
  275. copyVertexWeights(other);
  276. }
  277. void copyVertexWeights( const aiBone &other ) {
  278. if (other.mWeights == nullptr || other.mNumWeights == 0) {
  279. mWeights = nullptr;
  280. mNumWeights = 0;
  281. return;
  282. }
  283. mNumWeights = other.mNumWeights;
  284. if (mWeights) {
  285. delete[] mWeights;
  286. }
  287. mWeights = new aiVertexWeight[mNumWeights];
  288. ::memcpy(mWeights, other.mWeights, mNumWeights * sizeof(aiVertexWeight));
  289. }
  290. //! @brief Assignment operator
  291. aiBone &operator = (const aiBone &other) {
  292. if (this == &other) {
  293. return *this;
  294. }
  295. mName = other.mName;
  296. mNumWeights = other.mNumWeights;
  297. mOffsetMatrix = other.mOffsetMatrix;
  298. copyVertexWeights(other);
  299. return *this;
  300. }
  301. /// @brief Compare operator.
  302. bool operator==(const aiBone &rhs) const {
  303. if (mName != rhs.mName || mNumWeights != rhs.mNumWeights ) {
  304. return false;
  305. }
  306. for (size_t i = 0; i < mNumWeights; ++i) {
  307. if (mWeights[i] != rhs.mWeights[i]) {
  308. return false;
  309. }
  310. }
  311. return true;
  312. }
  313. //! @brief Destructor - deletes the array of vertex weights
  314. ~aiBone() {
  315. delete[] mWeights;
  316. }
  317. #endif // __cplusplus
  318. };
  319. // ---------------------------------------------------------------------------
  320. /** @brief Enumerates the types of geometric primitives supported by Assimp.
  321. *
  322. * @see aiFace Face data structure
  323. * @see aiProcess_SortByPType Per-primitive sorting of meshes
  324. * @see aiProcess_Triangulate Automatic triangulation
  325. * @see AI_CONFIG_PP_SBP_REMOVE Removal of specific primitive types.
  326. */
  327. enum aiPrimitiveType {
  328. /**
  329. * @brief A point primitive.
  330. *
  331. * This is just a single vertex in the virtual world,
  332. * #aiFace contains just one index for such a primitive.
  333. */
  334. aiPrimitiveType_POINT = 0x1,
  335. /**
  336. * @brief A line primitive.
  337. *
  338. * This is a line defined through a start and an end position.
  339. * #aiFace contains exactly two indices for such a primitive.
  340. */
  341. aiPrimitiveType_LINE = 0x2,
  342. /**
  343. * @brief A triangular primitive.
  344. *
  345. * A triangle consists of three indices.
  346. */
  347. aiPrimitiveType_TRIANGLE = 0x4,
  348. /**
  349. * @brief A higher-level polygon with more than 3 edges.
  350. *
  351. * A triangle is a polygon, but polygon in this context means
  352. * "all polygons that are not triangles". The "Triangulate"-Step
  353. * is provided for your convenience, it splits all polygons in
  354. * triangles (which are much easier to handle).
  355. */
  356. aiPrimitiveType_POLYGON = 0x8,
  357. /**
  358. * @brief A flag to determine whether this triangles only mesh is NGON encoded.
  359. *
  360. * NGON encoding is a special encoding that tells whether 2 or more consecutive triangles
  361. * should be considered as a triangle fan. This is identified by looking at the first vertex index.
  362. * 2 consecutive triangles with the same 1st vertex index are part of the same
  363. * NGON.
  364. *
  365. * At the moment, only quads (concave or convex) are supported, meaning that polygons are 'seen' as
  366. * triangles, as usual after a triangulation pass.
  367. *
  368. * To get an NGON encoded mesh, please use the aiProcess_Triangulate post process.
  369. *
  370. * @see aiProcess_Triangulate
  371. * @link https://github.com/KhronosGroup/glTF/pull/1620
  372. */
  373. aiPrimitiveType_NGONEncodingFlag = 0x10,
  374. /**
  375. * This value is not used. It is just here to force the
  376. * compiler to map this enum to a 32 Bit integer.
  377. */
  378. #ifndef SWIG
  379. _aiPrimitiveType_Force32Bit = INT_MAX
  380. #endif
  381. }; //! enum aiPrimitiveType
  382. // Get the #aiPrimitiveType flag for a specific number of face indices
  383. #define AI_PRIMITIVE_TYPE_FOR_N_INDICES(n) \
  384. ((n) > 3 ? aiPrimitiveType_POLYGON : (aiPrimitiveType)(1u << ((n)-1)))
  385. // ---------------------------------------------------------------------------
  386. /** @brief An AnimMesh is an attachment to an #aiMesh stores per-vertex
  387. * animations for a particular frame.
  388. *
  389. * You may think of an #aiAnimMesh as a `patch` for the host mesh, which
  390. * replaces only certain vertex data streams at a particular time.
  391. * Each mesh stores n attached attached meshes (#aiMesh::mAnimMeshes).
  392. * The actual relationship between the time line and anim meshes is
  393. * established by #aiMeshAnim, which references singular mesh attachments
  394. * by their ID and binds them to a time offset.
  395. */
  396. struct aiAnimMesh {
  397. /**Anim Mesh name */
  398. C_STRUCT aiString mName;
  399. /** Replacement for aiMesh::mVertices. If this array is non-nullptr,
  400. * it *must* contain mNumVertices entries. The corresponding
  401. * array in the host mesh must be non-nullptr as well - animation
  402. * meshes may neither add or nor remove vertex components (if
  403. * a replacement array is nullptr and the corresponding source
  404. * array is not, the source data is taken instead)*/
  405. C_STRUCT aiVector3D *mVertices;
  406. /** Replacement for aiMesh::mNormals. */
  407. C_STRUCT aiVector3D *mNormals;
  408. /** Replacement for aiMesh::mTangents. */
  409. C_STRUCT aiVector3D *mTangents;
  410. /** Replacement for aiMesh::mBitangents. */
  411. C_STRUCT aiVector3D *mBitangents;
  412. /** Replacement for aiMesh::mColors */
  413. C_STRUCT aiColor4D *mColors[AI_MAX_NUMBER_OF_COLOR_SETS];
  414. /** Replacement for aiMesh::mTextureCoords */
  415. C_STRUCT aiVector3D *mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS];
  416. /** The number of vertices in the aiAnimMesh, and thus the length of all
  417. * the member arrays.
  418. *
  419. * This has always the same value as the mNumVertices property in the
  420. * corresponding aiMesh. It is duplicated here merely to make the length
  421. * of the member arrays accessible even if the aiMesh is not known, e.g.
  422. * from language bindings.
  423. */
  424. unsigned int mNumVertices;
  425. /**
  426. * Weight of the AnimMesh.
  427. */
  428. float mWeight;
  429. #ifdef __cplusplus
  430. /// @brief The class constructor.
  431. aiAnimMesh() AI_NO_EXCEPT :
  432. mVertices(nullptr),
  433. mNormals(nullptr),
  434. mTangents(nullptr),
  435. mBitangents(nullptr),
  436. mColors {nullptr},
  437. mTextureCoords{nullptr},
  438. mNumVertices(0),
  439. mWeight(0.0f) {
  440. // empty
  441. }
  442. /// @brief The class destructor.
  443. ~aiAnimMesh() {
  444. delete[] mVertices;
  445. delete[] mNormals;
  446. delete[] mTangents;
  447. delete[] mBitangents;
  448. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) {
  449. delete[] mTextureCoords[a];
  450. }
  451. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
  452. delete[] mColors[a];
  453. }
  454. }
  455. /**
  456. * @brief Check whether the anim-mesh overrides the vertex positions
  457. * of its host mesh.
  458. * @return true if positions are stored, false if not.
  459. */
  460. bool HasPositions() const {
  461. return mVertices != nullptr;
  462. }
  463. /**
  464. * @brief Check whether the anim-mesh overrides the vertex normals
  465. * of its host mesh
  466. * @return true if normals are stored, false if not.
  467. */
  468. bool HasNormals() const {
  469. return mNormals != nullptr;
  470. }
  471. /**
  472. * @brief Check whether the anim-mesh overrides the vertex tangents
  473. * and bitangents of its host mesh. As for aiMesh,
  474. * tangents and bitangents always go together.
  475. * @return true if tangents and bi-tangents are stored, false if not.
  476. */
  477. bool HasTangentsAndBitangents() const {
  478. return mTangents != nullptr;
  479. }
  480. /**
  481. * @brief Check whether the anim mesh overrides a particular
  482. * set of vertex colors on his host mesh.
  483. * @param pIndex 0<index<AI_MAX_NUMBER_OF_COLOR_SETS
  484. * @return true if vertex colors are stored, false if not.
  485. */
  486. bool HasVertexColors(unsigned int pIndex) const {
  487. return pIndex >= AI_MAX_NUMBER_OF_COLOR_SETS ? false : mColors[pIndex] != nullptr;
  488. }
  489. /**
  490. * @brief Check whether the anim mesh overrides a particular
  491. * set of texture coordinates on his host mesh.
  492. * @param pIndex 0<index<AI_MAX_NUMBER_OF_TEXTURECOORDS
  493. * @return true if texture coordinates are stored, false if not.
  494. */
  495. bool HasTextureCoords(unsigned int pIndex) const {
  496. return pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS ? false : mTextureCoords[pIndex] != nullptr;
  497. }
  498. #endif
  499. };
  500. // ---------------------------------------------------------------------------
  501. /** @brief Enumerates the methods of mesh morphing supported by Assimp.
  502. */
  503. enum aiMorphingMethod {
  504. /** Morphing method to be determined */
  505. aiMorphingMethod_UNKNOWN = 0x0,
  506. /** Interpolation between morph targets */
  507. aiMorphingMethod_VERTEX_BLEND = 0x1,
  508. /** Normalized morphing between morph targets */
  509. aiMorphingMethod_MORPH_NORMALIZED = 0x2,
  510. /** Relative morphing between morph targets */
  511. aiMorphingMethod_MORPH_RELATIVE = 0x3,
  512. /** This value is not used. It is just here to force the
  513. * compiler to map this enum to a 32 Bit integer.
  514. */
  515. #ifndef SWIG
  516. _aiMorphingMethod_Force32Bit = INT_MAX
  517. #endif
  518. }; //! enum aiMorphingMethod
  519. // ---------------------------------------------------------------------------
  520. /** @brief A mesh represents a geometry or model with a single material.
  521. *
  522. * It usually consists of a number of vertices and a series of primitives/faces
  523. * referencing the vertices. In addition there might be a series of bones, each
  524. * of them addressing a number of vertices with a certain weight. Vertex data
  525. * is presented in channels with each channel containing a single per-vertex
  526. * information such as a set of texture coordinates or a normal vector.
  527. * If a data pointer is non-null, the corresponding data stream is present.
  528. * From C++-programs you can also use the comfort functions Has*() to
  529. * test for the presence of various data streams.
  530. *
  531. * A Mesh uses only a single material which is referenced by a material ID.
  532. * @note The mPositions member is usually not optional. However, vertex positions
  533. * *could* be missing if the #AI_SCENE_FLAGS_INCOMPLETE flag is set in
  534. * @code
  535. * aiScene::mFlags
  536. * @endcode
  537. */
  538. struct aiMesh {
  539. /**
  540. * Bitwise combination of the members of the #aiPrimitiveType enum.
  541. * This specifies which types of primitives are present in the mesh.
  542. * The "SortByPrimitiveType"-Step can be used to make sure the
  543. * output meshes consist of one primitive type each.
  544. */
  545. unsigned int mPrimitiveTypes;
  546. /**
  547. * The number of vertices in this mesh.
  548. * This is also the size of all of the per-vertex data arrays.
  549. * The maximum value for this member is #AI_MAX_VERTICES.
  550. */
  551. unsigned int mNumVertices;
  552. /**
  553. * The number of primitives (triangles, polygons, lines) in this mesh.
  554. * This is also the size of the mFaces array.
  555. * The maximum value for this member is #AI_MAX_FACES.
  556. */
  557. unsigned int mNumFaces;
  558. /**
  559. * @brief Vertex positions.
  560. *
  561. * This array is always present in a mesh. The array is
  562. * mNumVertices in size.
  563. */
  564. C_STRUCT aiVector3D *mVertices;
  565. /**
  566. * @brief Vertex normals.
  567. *
  568. * The array contains normalized vectors, nullptr if not present.
  569. * The array is mNumVertices in size. Normals are undefined for
  570. * point and line primitives. A mesh consisting of points and
  571. * lines only may not have normal vectors. Meshes with mixed
  572. * primitive types (i.e. lines and triangles) may have normals,
  573. * but the normals for vertices that are only referenced by
  574. * point or line primitives are undefined and set to QNaN (WARN:
  575. * qNaN compares to inequal to *everything*, even to qNaN itself.
  576. * Using code like this to check whether a field is qnan is:
  577. * @code
  578. * #define IS_QNAN(f) (f != f)
  579. * @endcode
  580. * still dangerous because even 1.f == 1.f could evaluate to false! (
  581. * remember the subtleties of IEEE754 artithmetics). Use stuff like
  582. * @c fpclassify instead.
  583. * @note Normal vectors computed by Assimp are always unit-length.
  584. * However, this needn't apply for normals that have been taken
  585. * directly from the model file.
  586. */
  587. C_STRUCT aiVector3D *mNormals;
  588. /**
  589. * @brief Vertex tangents.
  590. *
  591. * The tangent of a vertex points in the direction of the positive
  592. * X texture axis. The array contains normalized vectors, nullptr if
  593. * not present. The array is mNumVertices in size. A mesh consisting
  594. * of points and lines only may not have normal vectors. Meshes with
  595. * mixed primitive types (i.e. lines and triangles) may have
  596. * normals, but the normals for vertices that are only referenced by
  597. * point or line primitives are undefined and set to qNaN. See
  598. * the #mNormals member for a detailed discussion of qNaNs.
  599. * @note If the mesh contains tangents, it automatically also
  600. * contains bitangents.
  601. */
  602. C_STRUCT aiVector3D *mTangents;
  603. /**
  604. * @brief Vertex bitangents.
  605. *
  606. * The bitangent of a vertex points in the direction of the positive
  607. * Y texture axis. The array contains normalized vectors, nullptr if not
  608. * present. The array is mNumVertices in size.
  609. * @note If the mesh contains tangents, it automatically also contains
  610. * bitangents.
  611. */
  612. C_STRUCT aiVector3D *mBitangents;
  613. /**
  614. * @brief Vertex color sets.
  615. *
  616. * A mesh may contain 0 to #AI_MAX_NUMBER_OF_COLOR_SETS vertex
  617. * colors per vertex. nullptr if not present. Each array is
  618. * mNumVertices in size if present.
  619. */
  620. C_STRUCT aiColor4D *mColors[AI_MAX_NUMBER_OF_COLOR_SETS];
  621. /**
  622. * @brief Vertex texture coordinates, also known as UV channels.
  623. *
  624. * A mesh may contain 0 to AI_MAX_NUMBER_OF_TEXTURECOORDS per
  625. * vertex. nullptr if not present. The array is mNumVertices in size.
  626. */
  627. C_STRUCT aiVector3D *mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS];
  628. /**
  629. * @brief Specifies the number of components for a given UV channel.
  630. *
  631. * Up to three channels are supported (UVW, for accessing volume
  632. * or cube maps). If the value is 2 for a given channel n, the
  633. * component p.z of mTextureCoords[n][p] is set to 0.0f.
  634. * If the value is 1 for a given channel, p.y is set to 0.0f, too.
  635. * @note 4D coordinates are not supported
  636. */
  637. unsigned int mNumUVComponents[AI_MAX_NUMBER_OF_TEXTURECOORDS];
  638. /**
  639. * @brief The faces the mesh is constructed from.
  640. *
  641. * Each face refers to a number of vertices by their indices.
  642. * This array is always present in a mesh, its size is given
  643. * in mNumFaces. If the #AI_SCENE_FLAGS_NON_VERBOSE_FORMAT
  644. * is NOT set each face references an unique set of vertices.
  645. */
  646. C_STRUCT aiFace *mFaces;
  647. /**
  648. * The number of bones this mesh contains. Can be 0, in which case the mBones array is nullptr.
  649. */
  650. unsigned int mNumBones;
  651. /**
  652. * @brief The bones of this mesh.
  653. *
  654. * A bone consists of a name by which it can be found in the
  655. * frame hierarchy and a set of vertex weights.
  656. */
  657. C_STRUCT aiBone **mBones;
  658. /**
  659. * @brief The material used by this mesh.
  660. *
  661. * A mesh uses only a single material. If an imported model uses
  662. * multiple materials, the import splits up the mesh. Use this value
  663. * as index into the scene's material list.
  664. */
  665. unsigned int mMaterialIndex;
  666. /**
  667. * Name of the mesh. Meshes can be named, but this is not a
  668. * requirement and leaving this field empty is totally fine.
  669. * There are mainly three uses for mesh names:
  670. * - some formats name nodes and meshes independently.
  671. * - importers tend to split meshes up to meet the
  672. * one-material-per-mesh requirement. Assigning
  673. * the same (dummy) name to each of the result meshes
  674. * aids the caller at recovering the original mesh
  675. * partitioning.
  676. * - Vertex animations refer to meshes by their names.
  677. */
  678. C_STRUCT aiString mName;
  679. /**
  680. * The number of attachment meshes.
  681. * Currently known to work with loaders:
  682. * - Collada
  683. * - gltf
  684. */
  685. unsigned int mNumAnimMeshes;
  686. /**
  687. * Attachment meshes for this mesh, for vertex-based animation.
  688. * Attachment meshes carry replacement data for some of the
  689. * mesh'es vertex components (usually positions, normals).
  690. * Currently known to work with loaders:
  691. * - Collada
  692. * - gltf
  693. */
  694. C_STRUCT aiAnimMesh **mAnimMeshes;
  695. /**
  696. * Method of morphing when anim-meshes are specified.
  697. * @see aiMorphingMethod to learn more about the provided morphing targets.
  698. */
  699. enum aiMorphingMethod mMethod;
  700. /**
  701. * The bounding box.
  702. */
  703. C_STRUCT aiAABB mAABB;
  704. /**
  705. * Vertex UV stream names. Pointer to array of size AI_MAX_NUMBER_OF_TEXTURECOORDS
  706. */
  707. C_STRUCT aiString **mTextureCoordsNames;
  708. #ifdef __cplusplus
  709. //! The default class constructor.
  710. aiMesh() AI_NO_EXCEPT
  711. : mPrimitiveTypes(0),
  712. mNumVertices(0),
  713. mNumFaces(0),
  714. mVertices(nullptr),
  715. mNormals(nullptr),
  716. mTangents(nullptr),
  717. mBitangents(nullptr),
  718. mColors{nullptr},
  719. mTextureCoords{nullptr},
  720. mNumUVComponents{0},
  721. mFaces(nullptr),
  722. mNumBones(0),
  723. mBones(nullptr),
  724. mMaterialIndex(0),
  725. mNumAnimMeshes(0),
  726. mAnimMeshes(nullptr),
  727. mMethod(aiMorphingMethod_UNKNOWN),
  728. mAABB(),
  729. mTextureCoordsNames(nullptr) {
  730. // empty
  731. }
  732. //! @brief The class destructor.
  733. ~aiMesh() {
  734. delete[] mVertices;
  735. delete[] mNormals;
  736. delete[] mTangents;
  737. delete[] mBitangents;
  738. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) {
  739. delete[] mTextureCoords[a];
  740. }
  741. if (mTextureCoordsNames) {
  742. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) {
  743. delete mTextureCoordsNames[a];
  744. }
  745. delete[] mTextureCoordsNames;
  746. }
  747. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
  748. delete[] mColors[a];
  749. }
  750. // DO NOT REMOVE THIS ADDITIONAL CHECK
  751. if (mNumBones && mBones) {
  752. for (unsigned int a = 0; a < mNumBones; a++) {
  753. if (mBones[a]) {
  754. delete mBones[a];
  755. }
  756. }
  757. delete[] mBones;
  758. }
  759. if (mNumAnimMeshes && mAnimMeshes) {
  760. for (unsigned int a = 0; a < mNumAnimMeshes; a++) {
  761. delete mAnimMeshes[a];
  762. }
  763. delete[] mAnimMeshes;
  764. }
  765. delete[] mFaces;
  766. }
  767. //! @brief Check whether the mesh contains positions. Provided no special
  768. //! scene flags are set, this will always be true
  769. //! @return true, if positions are stored, false if not.
  770. bool HasPositions() const {
  771. return mVertices != nullptr && mNumVertices > 0;
  772. }
  773. //! @brief Check whether the mesh contains faces. If no special scene flags
  774. //! are set this should always return true
  775. //! @return true, if faces are stored, false if not.
  776. bool HasFaces() const {
  777. return mFaces != nullptr && mNumFaces > 0;
  778. }
  779. //! @brief Check whether the mesh contains normal vectors
  780. //! @return true, if normals are stored, false if not.
  781. bool HasNormals() const {
  782. return mNormals != nullptr && mNumVertices > 0;
  783. }
  784. //! @brief Check whether the mesh contains tangent and bitangent vectors.
  785. //!
  786. //! It is not possible that it contains tangents and no bitangents
  787. //! (or the other way round). The existence of one of them
  788. //! implies that the second is there, too.
  789. //! @return true, if tangents and bi-tangents are stored, false if not.
  790. bool HasTangentsAndBitangents() const {
  791. return mTangents != nullptr && mBitangents != nullptr && mNumVertices > 0;
  792. }
  793. //! @brief Check whether the mesh contains a vertex color set
  794. //! @param index Index of the vertex color set
  795. //! @return true, if vertex colors are stored, false if not.
  796. bool HasVertexColors(unsigned int index) const {
  797. if (index >= AI_MAX_NUMBER_OF_COLOR_SETS) {
  798. return false;
  799. }
  800. return mColors[index] != nullptr && mNumVertices > 0;
  801. }
  802. //! @brief Check whether the mesh contains a texture coordinate set
  803. //! @param index Index of the texture coordinates set
  804. //! @return true, if texture coordinates are stored, false if not.
  805. bool HasTextureCoords(unsigned int index) const {
  806. if (index >= AI_MAX_NUMBER_OF_TEXTURECOORDS) {
  807. return false;
  808. }
  809. return (mTextureCoords[index] != nullptr && mNumVertices > 0);
  810. }
  811. //! @brief Get the number of UV channels the mesh contains.
  812. //! @return the number of stored uv-channels.
  813. unsigned int GetNumUVChannels() const {
  814. unsigned int n(0);
  815. while (n < AI_MAX_NUMBER_OF_TEXTURECOORDS && mTextureCoords[n]) {
  816. ++n;
  817. }
  818. return n;
  819. }
  820. //! @brief Get the number of vertex color channels the mesh contains.
  821. //! @return The number of stored color channels.
  822. unsigned int GetNumColorChannels() const {
  823. unsigned int n(0);
  824. while (n < AI_MAX_NUMBER_OF_COLOR_SETS && mColors[n]) {
  825. ++n;
  826. }
  827. return n;
  828. }
  829. //! @brief Check whether the mesh contains bones.
  830. //! @return true, if bones are stored.
  831. bool HasBones() const {
  832. return mBones != nullptr && mNumBones > 0;
  833. }
  834. //! @brief Check whether the mesh contains a texture coordinate set name
  835. //! @param pIndex Index of the texture coordinates set
  836. //! @return true, if texture coordinates for the index exists.
  837. bool HasTextureCoordsName(unsigned int pIndex) const {
  838. if (mTextureCoordsNames == nullptr || pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS) {
  839. return false;
  840. }
  841. return mTextureCoordsNames[pIndex] != nullptr;
  842. }
  843. //! @brief Set a texture coordinate set name
  844. //! @param pIndex Index of the texture coordinates set
  845. //! @param texCoordsName name of the texture coordinate set
  846. void SetTextureCoordsName(unsigned int pIndex, const aiString &texCoordsName) {
  847. if (pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS) {
  848. return;
  849. }
  850. if (mTextureCoordsNames == nullptr) {
  851. // Construct and null-init array
  852. mTextureCoordsNames = new aiString *[AI_MAX_NUMBER_OF_TEXTURECOORDS];
  853. for (size_t i=0; i<AI_MAX_NUMBER_OF_TEXTURECOORDS; ++i) {
  854. mTextureCoordsNames[i] = nullptr;
  855. }
  856. }
  857. if (texCoordsName.length == 0) {
  858. delete mTextureCoordsNames[pIndex];
  859. mTextureCoordsNames[pIndex] = nullptr;
  860. return;
  861. }
  862. if (mTextureCoordsNames[pIndex] == nullptr) {
  863. mTextureCoordsNames[pIndex] = new aiString(texCoordsName);
  864. return;
  865. }
  866. *mTextureCoordsNames[pIndex] = texCoordsName;
  867. }
  868. //! @brief Get a texture coordinate set name
  869. //! @param pIndex Index of the texture coordinates set
  870. //! @return The texture coordinate name.
  871. const aiString *GetTextureCoordsName(unsigned int index) const {
  872. if (mTextureCoordsNames == nullptr || index >= AI_MAX_NUMBER_OF_TEXTURECOORDS) {
  873. return nullptr;
  874. }
  875. return mTextureCoordsNames[index];
  876. }
  877. #endif // __cplusplus
  878. };
  879. /**
  880. * @brief A skeleton bone represents a single bone is a skeleton structure.
  881. *
  882. * Skeleton-Animations can be represented via a skeleton struct, which describes
  883. * a hierarchical tree assembled from skeleton bones. A bone is linked to a mesh.
  884. * The bone knows its parent bone. If there is no parent bone the parent id is
  885. * marked with -1.
  886. * The skeleton-bone stores a pointer to its used armature. If there is no
  887. * armature this value if set to nullptr.
  888. * A skeleton bone stores its offset-matrix, which is the absolute transformation
  889. * for the bone. The bone stores the locale transformation to its parent as well.
  890. * You can compute the offset matrix by multiplying the hierarchy like:
  891. * Tree: s1 -> s2 -> s3
  892. * Offset-Matrix s3 = locale-s3 * locale-s2 * locale-s1
  893. */
  894. struct aiSkeletonBone {
  895. /// The parent bone index, is -1 one if this bone represents the root bone.
  896. int mParent;
  897. #ifndef ASSIMP_BUILD_NO_ARMATUREPOPULATE_PROCESS
  898. /// @brief The bone armature node - used for skeleton conversion
  899. /// you must enable aiProcess_PopulateArmatureData to populate this
  900. C_STRUCT aiNode *mArmature;
  901. /// @brief The bone node in the scene - used for skeleton conversion
  902. /// you must enable aiProcess_PopulateArmatureData to populate this
  903. C_STRUCT aiNode *mNode;
  904. #endif
  905. /// @brief The number of weights
  906. unsigned int mNumnWeights;
  907. /// The mesh index, which will get influenced by the weight.
  908. C_STRUCT aiMesh *mMeshId;
  909. /// The influence weights of this bone, by vertex index.
  910. C_STRUCT aiVertexWeight *mWeights;
  911. /** Matrix that transforms from bone space to mesh space in bind pose.
  912. *
  913. * This matrix describes the position of the mesh
  914. * in the local space of this bone when the skeleton was bound.
  915. * Thus it can be used directly to determine a desired vertex position,
  916. * given the world-space transform of the bone when animated,
  917. * and the position of the vertex in mesh space.
  918. *
  919. * It is sometimes called an inverse-bind matrix,
  920. * or inverse bind pose matrix.
  921. */
  922. C_STRUCT aiMatrix4x4 mOffsetMatrix;
  923. /// Matrix that transforms the locale bone in bind pose.
  924. C_STRUCT aiMatrix4x4 mLocalMatrix;
  925. #ifdef __cplusplus
  926. /// @brief The class constructor.
  927. aiSkeletonBone() :
  928. mParent(-1),
  929. #ifndef ASSIMP_BUILD_NO_ARMATUREPOPULATE_PROCESS
  930. mArmature(nullptr),
  931. mNode(nullptr),
  932. #endif
  933. mNumnWeights(0),
  934. mMeshId(nullptr),
  935. mWeights(nullptr),
  936. mOffsetMatrix(),
  937. mLocalMatrix() {
  938. // empty
  939. }
  940. /// @brief The class constructor with its parent
  941. /// @param parent The parent node index.
  942. aiSkeletonBone(unsigned int parent) :
  943. mParent(parent),
  944. #ifndef ASSIMP_BUILD_NO_ARMATUREPOPULATE_PROCESS
  945. mArmature(nullptr),
  946. mNode(nullptr),
  947. #endif
  948. mNumnWeights(0),
  949. mMeshId(nullptr),
  950. mWeights(nullptr),
  951. mOffsetMatrix(),
  952. mLocalMatrix() {
  953. // empty
  954. }
  955. /// @brief The class destructor.
  956. ~aiSkeletonBone() {
  957. delete[] mWeights;
  958. mWeights = nullptr;
  959. }
  960. #endif // __cplusplus
  961. };
  962. /**
  963. * @brief A skeleton represents the bone hierarchy of an animation.
  964. *
  965. * Skeleton animations can be described as a tree of bones:
  966. * root
  967. * |
  968. * node1
  969. * / \
  970. * node3 node4
  971. * If you want to calculate the transformation of node three you need to compute the
  972. * transformation hierarchy for the transformation chain of node3:
  973. * root->node1->node3
  974. * Each node is represented as a skeleton instance.
  975. */
  976. struct aiSkeleton {
  977. /**
  978. * @brief The name of the skeleton instance.
  979. */
  980. C_STRUCT aiString mName;
  981. /**
  982. * @brief The number of bones in the skeleton.
  983. */
  984. unsigned int mNumBones;
  985. /**
  986. * @brief The bone instance in the skeleton.
  987. */
  988. C_STRUCT aiSkeletonBone **mBones;
  989. #ifdef __cplusplus
  990. /**
  991. * @brief The class constructor.
  992. */
  993. aiSkeleton() AI_NO_EXCEPT : mName(), mNumBones(0), mBones(nullptr) {
  994. // empty
  995. }
  996. /**
  997. * @brief The class destructor.
  998. */
  999. ~aiSkeleton() {
  1000. delete[] mBones;
  1001. }
  1002. #endif // __cplusplus
  1003. };
  1004. #ifdef __cplusplus
  1005. }
  1006. #endif //! extern "C"
  1007. #endif // AI_MESH_H_INC