mesh.h 36 KB

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