Path Tracer
mesh.h
Go to the documentation of this file.
1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
5 
6 Copyright (c) 2006-2020, assimp team
7 
8 
9 All rights reserved.
10 
11 Redistribution and use of this software in source and binary forms,
12 with or without modification, are permitted provided that the following
13 conditions are met:
14 
15 * Redistributions of source code must retain the above
16  copyright notice, this list of conditions and the
17  following disclaimer.
18 
19 * Redistributions in binary form must reproduce the above
20  copyright notice, this list of conditions and the
21  following disclaimer in the documentation and/or other
22  materials provided with the distribution.
23 
24 * Neither the name of the assimp team, nor the names of its
25  contributors may be used to endorse or promote products
26  derived from this software without specific prior
27  written permission of the assimp team.
28 
29 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 ---------------------------------------------------------------------------
41 */
42 
47 #pragma once
48 #ifndef AI_MESH_H_INC
49 #define AI_MESH_H_INC
50 
51 #ifdef __GNUC__
52 #pragma GCC system_header
53 #endif
54 
55 #ifdef _WIN32
56 #pragma warning(disable : 4351)
57 #endif // _WIN32
58 
59 #include <assimp/aabb.h>
60 #include <assimp/types.h>
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
66 // ---------------------------------------------------------------------------
67 // Limits. These values are required to match the settings Assimp was
68 // compiled against. Therefore, do not redefine them unless you build the
69 // library from source using the same definitions.
70 // ---------------------------------------------------------------------------
71 
75 #ifndef AI_MAX_FACE_INDICES
76 #define AI_MAX_FACE_INDICES 0x7fff
77 #endif
78 
82 #ifndef AI_MAX_BONE_WEIGHTS
83 #define AI_MAX_BONE_WEIGHTS 0x7fffffff
84 #endif
85 
89 #ifndef AI_MAX_VERTICES
90 #define AI_MAX_VERTICES 0x7fffffff
91 #endif
92 
96 #ifndef AI_MAX_FACES
97 #define AI_MAX_FACES 0x7fffffff
98 #endif
99 
103 #ifndef AI_MAX_NUMBER_OF_COLOR_SETS
104 #define AI_MAX_NUMBER_OF_COLOR_SETS 0x8
105 #endif // !! AI_MAX_NUMBER_OF_COLOR_SETS
106 
110 #ifndef AI_MAX_NUMBER_OF_TEXTURECOORDS
111 #define AI_MAX_NUMBER_OF_TEXTURECOORDS 0x8
112 #endif // !! AI_MAX_NUMBER_OF_TEXTURECOORDS
113 
114 // ---------------------------------------------------------------------------
136 struct aiFace {
139  unsigned int mNumIndices;
140 
142  unsigned int *mIndices;
143 
144 #ifdef __cplusplus
145 
147  aiFace() AI_NO_EXCEPT
148  : mNumIndices(0),
149  mIndices(nullptr) {
150  // empty
151  }
152 
154  ~aiFace() {
155  delete[] mIndices;
156  }
157 
159  aiFace(const aiFace &o) :
160  mNumIndices(0), mIndices(nullptr) {
161  *this = o;
162  }
163 
165  aiFace &operator=(const aiFace &o) {
166  if (&o == this) {
167  return *this;
168  }
169 
170  delete[] mIndices;
172  if (mNumIndices) {
173  mIndices = new unsigned int[mNumIndices];
174  ::memcpy(mIndices, o.mIndices, mNumIndices * sizeof(unsigned int));
175  } else {
176  mIndices = nullptr;
177  }
178 
179  return *this;
180  }
181 
184  bool operator==(const aiFace &o) const {
185  if (mIndices == o.mIndices) {
186  return true;
187  }
188 
189  if (nullptr != mIndices && mNumIndices != o.mNumIndices) {
190  return false;
191  }
192 
193  if (nullptr == mIndices) {
194  return false;
195  }
196 
197  for (unsigned int i = 0; i < this->mNumIndices; ++i) {
198  if (mIndices[i] != o.mIndices[i]) {
199  return false;
200  }
201  }
202 
203  return true;
204  }
205 
208  bool operator!=(const aiFace &o) const {
209  return !(*this == o);
210  }
211 #endif // __cplusplus
212 }; // struct aiFace
213 
214 // ---------------------------------------------------------------------------
219  unsigned int mVertexId;
220 
223  ai_real mWeight;
224 
225 #ifdef __cplusplus
226 
228  aiVertexWeight() AI_NO_EXCEPT
229  : mVertexId(0),
230  mWeight(0.0f) {
231  // empty
232  }
233 
237  aiVertexWeight(unsigned int pID, float pWeight) :
238  mVertexId(pID), mWeight(pWeight) {
239  // empty
240  }
241 
242  bool operator==(const aiVertexWeight &rhs) const {
243  return (mVertexId == rhs.mVertexId && mWeight == rhs.mWeight);
244  }
245 
246  bool operator!=(const aiVertexWeight &rhs) const {
247  return (*this == rhs);
248  }
249 
250 #endif // __cplusplus
251 };
252 
253 // Forward declare aiNode (pointer use only)
254 struct aiNode;
255 
256 // ---------------------------------------------------------------------------
264 struct aiBone {
266  C_STRUCT aiString mName;
267 
270  unsigned int mNumWeights;
271 
272 #ifndef ASSIMP_BUILD_NO_ARMATUREPOPULATE_PROCESS
273  // The bone armature node - used for skeleton conversion
274  // you must enable aiProcess_PopulateArmatureData to populate this
275  C_STRUCT aiNode *mArmature;
276 
277  // The bone node in the scene - used for skeleton conversion
278  // you must enable aiProcess_PopulateArmatureData to populate this
279  C_STRUCT aiNode *mNode;
280 
281 #endif
282  C_STRUCT aiVertexWeight *mWeights;
284 
297 
298 #ifdef __cplusplus
299 
301  aiBone() AI_NO_EXCEPT
302  : mName(),
303  mNumWeights(0),
304  mWeights(nullptr),
305  mOffsetMatrix() {
306  // empty
307  }
308 
310  aiBone(const aiBone &other) :
311  mName(other.mName),
312  mNumWeights(other.mNumWeights),
313  mWeights(nullptr),
315  if (other.mWeights && other.mNumWeights) {
317  ::memcpy(mWeights, other.mWeights, mNumWeights * sizeof(aiVertexWeight));
318  }
319  }
320 
322  aiBone &operator=(const aiBone &other) {
323  if (this == &other) {
324  return *this;
325  }
326 
327  mName = other.mName;
328  mNumWeights = other.mNumWeights;
330 
331  if (other.mWeights && other.mNumWeights) {
332  if (mWeights) {
333  delete[] mWeights;
334  }
335 
337  ::memcpy(mWeights, other.mWeights, mNumWeights * sizeof(aiVertexWeight));
338  }
339 
340  return *this;
341  }
342 
343  bool operator==(const aiBone &rhs) const {
344  if (mName != rhs.mName || mNumWeights != rhs.mNumWeights) {
345  return false;
346  }
347 
348  for (size_t i = 0; i < mNumWeights; ++i) {
349  if (mWeights[i] != rhs.mWeights[i]) {
350  return false;
351  }
352  }
353 
354  return true;
355  }
357  ~aiBone() {
358  delete[] mWeights;
359  }
360 #endif // __cplusplus
361 };
362 
363 // ---------------------------------------------------------------------------
378 
385 
391 
400 
404 #ifndef SWIG
406 #endif
407 };
408 
409 // Get the #aiPrimitiveType flag for a specific number of face indices
410 #define AI_PRIMITIVE_TYPE_FOR_N_INDICES(n) \
411  ((n) > 3 ? aiPrimitiveType_POLYGON : (aiPrimitiveType)(1u << ((n)-1)))
412 
413 // ---------------------------------------------------------------------------
424 struct aiAnimMesh {
426  C_STRUCT aiString mName;
427 
435 
437  C_STRUCT aiVector3D *mNormals;
438 
441 
444 
447 
450 
459  unsigned int mNumVertices;
460 
464  float mWeight;
465 
466 #ifdef __cplusplus
467 
468  aiAnimMesh() AI_NO_EXCEPT
469  : mVertices(nullptr),
470  mNormals(nullptr),
471  mTangents(nullptr),
472  mBitangents(nullptr),
473  mColors(),
474  mTextureCoords(),
475  mNumVertices(0),
476  mWeight(0.0f) {
477  // fixme consider moving this to the ctor initializer list as well
478  for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) {
479  mTextureCoords[a] = nullptr;
480  }
481  for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
482  mColors[a] = nullptr;
483  }
484  }
485 
486  ~aiAnimMesh() {
487  delete[] mVertices;
488  delete[] mNormals;
489  delete[] mTangents;
490  delete[] mBitangents;
491  for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) {
492  delete[] mTextureCoords[a];
493  }
494  for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
495  delete[] mColors[a];
496  }
497  }
498 
501  bool HasPositions() const {
502  return mVertices != nullptr;
503  }
504 
507  bool HasNormals() const {
508  return mNormals != nullptr;
509  }
510 
514  bool HasTangentsAndBitangents() const {
515  return mTangents != nullptr;
516  }
517 
521  bool HasVertexColors(unsigned int pIndex) const {
522  return pIndex >= AI_MAX_NUMBER_OF_COLOR_SETS ? false : mColors[pIndex] != nullptr;
523  }
524 
528  bool HasTextureCoords(unsigned int pIndex) const {
529  return pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS ? false : mTextureCoords[pIndex] != nullptr;
530  }
531 
532 #endif
533 };
534 
535 // ---------------------------------------------------------------------------
541 
544 
547 
551 #ifndef SWIG
553 #endif
554 };
555 
556 // ---------------------------------------------------------------------------
575 struct aiMesh {
581  unsigned int mPrimitiveTypes;
582 
587  unsigned int mNumVertices;
588 
593  unsigned int mNumFaces;
594 
600 
621  C_STRUCT aiVector3D *mNormals;
622 
636 
645 
652 
658 
667 
674  C_STRUCT aiFace *mFaces;
675 
679  unsigned int mNumBones;
680 
685  C_STRUCT aiBone **mBones;
686 
692  unsigned int mMaterialIndex;
693 
705  C_STRUCT aiString mName;
706 
708  unsigned int mNumAnimMeshes;
709 
715 
719  unsigned int mMethod;
720 
724  C_STRUCT aiAABB mAABB;
725 
726 #ifdef __cplusplus
727 
729  aiMesh() AI_NO_EXCEPT
730  : mPrimitiveTypes(0),
731  mNumVertices(0),
732  mNumFaces(0),
733  mVertices(nullptr),
734  mNormals(nullptr),
735  mTangents(nullptr),
736  mBitangents(nullptr),
737  mColors(),
738  mTextureCoords(),
740  mFaces(nullptr),
741  mNumBones(0),
742  mBones(nullptr),
743  mMaterialIndex(0),
744  mNumAnimMeshes(0),
745  mAnimMeshes(nullptr),
746  mMethod(0),
747  mAABB() {
748  for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a) {
749  mNumUVComponents[a] = 0;
750  mTextureCoords[a] = nullptr;
751  }
752 
753  for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; ++a) {
754  mColors[a] = nullptr;
755  }
756  }
757 
759  ~aiMesh() {
760  delete[] mVertices;
761  delete[] mNormals;
762  delete[] mTangents;
763  delete[] mBitangents;
764  for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) {
765  delete[] mTextureCoords[a];
766  }
767  for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
768  delete[] mColors[a];
769  }
770 
771  // DO NOT REMOVE THIS ADDITIONAL CHECK
772  if (mNumBones && mBones) {
773  for (unsigned int a = 0; a < mNumBones; a++) {
774  if (mBones[a]) {
775  delete mBones[a];
776  }
777  }
778  delete[] mBones;
779  }
780 
781  if (mNumAnimMeshes && mAnimMeshes) {
782  for (unsigned int a = 0; a < mNumAnimMeshes; a++) {
783  delete mAnimMeshes[a];
784  }
785  delete[] mAnimMeshes;
786  }
787 
788  delete[] mFaces;
789  }
790 
793  bool HasPositions() const { return mVertices != nullptr && mNumVertices > 0; }
794 
797  bool HasFaces() const { return mFaces != nullptr && mNumFaces > 0; }
798 
800  bool HasNormals() const { return mNormals != nullptr && mNumVertices > 0; }
801 
806  bool HasTangentsAndBitangents() const { return mTangents != nullptr && mBitangents != nullptr && mNumVertices > 0; }
807 
810  bool HasVertexColors(unsigned int pIndex) const {
811  if (pIndex >= AI_MAX_NUMBER_OF_COLOR_SETS) {
812  return false;
813  } else {
814  return mColors[pIndex] != nullptr && mNumVertices > 0;
815  }
816  }
817 
820  bool HasTextureCoords(unsigned int pIndex) const {
821  if (pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS) {
822  return false;
823  } else {
824  return mTextureCoords[pIndex] != nullptr && mNumVertices > 0;
825  }
826  }
827 
829  unsigned int GetNumUVChannels() const {
830  unsigned int n(0);
832  ++n;
833  }
834 
835  return n;
836  }
837 
839  unsigned int GetNumColorChannels() const {
840  unsigned int n(0);
841  while (n < AI_MAX_NUMBER_OF_COLOR_SETS && mColors[n]) {
842  ++n;
843  }
844  return n;
845  }
846 
848  bool HasBones() const {
849  return mBones != nullptr && mNumBones > 0;
850  }
851 
852 #endif // __cplusplus
853 };
854 
855 #ifdef __cplusplus
856 }
857 #endif
858 #endif // AI_MESH_H_INC
aiMesh::mNormals
C_STRUCT aiVector3D * mNormals
Definition: mesh.h:621
aiMorphingMethod
aiMorphingMethod
Enumerates the methods of mesh morphing supported by Assimp.
Definition: mesh.h:538
aiAnimMesh::mTangents
C_STRUCT aiVector3D * mTangents
Definition: mesh.h:440
aiBone::mOffsetMatrix
C_STRUCT aiMatrix4x4 mOffsetMatrix
Definition: mesh.h:296
aiFace::mNumIndices
unsigned int mNumIndices
Definition: mesh.h:139
aiPrimitiveType_POINT
@ aiPrimitiveType_POINT
Definition: mesh.h:377
aiMesh::mVertices
C_STRUCT aiVector3D * mVertices
Definition: mesh.h:599
aiVector3D
Definition: vector3.h:136
aiMesh::mAnimMeshes
C_STRUCT aiAnimMesh ** mAnimMeshes
Definition: mesh.h:714
aiMesh::mNumVertices
unsigned int mNumVertices
Definition: mesh.h:587
_aiPrimitiveType_Force32Bit
@ _aiPrimitiveType_Force32Bit
Definition: mesh.h:405
aiAnimMesh::mWeight
float mWeight
Definition: mesh.h:464
aiBone::mWeights
C_STRUCT aiVertexWeight * mWeights
The influence weights of this bone, by vertex index.
Definition: mesh.h:283
types.h
aiAnimMesh::mColors
C_STRUCT aiColor4D * mColors[AI_MAX_NUMBER_OF_COLOR_SETS]
Definition: mesh.h:446
aiAnimMesh::mVertices
C_STRUCT aiVector3D * mVertices
Definition: mesh.h:434
aiMesh::mMethod
unsigned int mMethod
Definition: mesh.h:719
aiNode
Definition: scene.h:85
aiMesh::mPrimitiveTypes
unsigned int mPrimitiveTypes
Definition: mesh.h:581
_aiMorphingMethod_Force32Bit
@ _aiMorphingMethod_Force32Bit
Definition: mesh.h:552
aiAnimMesh::mNumVertices
unsigned int mNumVertices
Definition: mesh.h:459
aiAnimMesh::mNormals
C_STRUCT aiVector3D * mNormals
Definition: mesh.h:437
aiFace
A single face in a mesh, referring to multiple vertices.
Definition: mesh.h:136
aiAnimMesh::mName
C_STRUCT aiString mName
Definition: mesh.h:426
aiMesh::mTextureCoords
C_STRUCT aiVector3D * mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS]
Definition: mesh.h:657
aiBone::mNumWeights
unsigned int mNumWeights
Definition: mesh.h:270
aiVertexWeight::mVertexId
unsigned int mVertexId
Index of the vertex which is influenced by the bone.
Definition: mesh.h:219
aiMesh::mNumUVComponents
unsigned int mNumUVComponents[AI_MAX_NUMBER_OF_TEXTURECOORDS]
Definition: mesh.h:666
aiMesh::mNumFaces
unsigned int mNumFaces
Definition: mesh.h:593
aiAABB
Definition: aabb.h:52
aiMesh::mBitangents
C_STRUCT aiVector3D * mBitangents
Definition: mesh.h:644
aiPrimitiveType_POLYGON
@ aiPrimitiveType_POLYGON
Definition: mesh.h:399
aiAnimMesh::mTextureCoords
C_STRUCT aiVector3D * mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS]
Definition: mesh.h:449
aiMorphingMethod_MORPH_RELATIVE
@ aiMorphingMethod_MORPH_RELATIVE
Definition: mesh.h:546
aiMesh::mColors
C_STRUCT aiColor4D * mColors[AI_MAX_NUMBER_OF_COLOR_SETS]
Definition: mesh.h:651
aiString
Definition: types.h:266
aiColor4D
Definition: color4.h:97
aiVertexWeight
A single influence of a bone on a vertex.
Definition: mesh.h:217
aiMesh::mMaterialIndex
unsigned int mMaterialIndex
Definition: mesh.h:692
AI_MAX_NUMBER_OF_COLOR_SETS
#define AI_MAX_NUMBER_OF_COLOR_SETS
Definition: mesh.h:104
aiFace::mIndices
unsigned int * mIndices
Pointer to the indices array. Size of the array is given in numIndices.
Definition: mesh.h:142
aiMorphingMethod_VERTEX_BLEND
@ aiMorphingMethod_VERTEX_BLEND
Definition: mesh.h:540
aiVertexWeight::mWeight
ai_real mWeight
Definition: mesh.h:223
aiBone
A single bone of a mesh.
Definition: mesh.h:264
aiPrimitiveType_TRIANGLE
@ aiPrimitiveType_TRIANGLE
Definition: mesh.h:390
aiMesh::mBones
C_STRUCT aiBone ** mBones
Definition: mesh.h:685
aiPrimitiveType_LINE
@ aiPrimitiveType_LINE
Definition: mesh.h:384
aiMesh::mName
C_STRUCT aiString mName
Definition: mesh.h:705
aiAnimMesh
An AnimMesh is an attachment to an aiMesh stores per-vertex animations for a particular frame.
Definition: mesh.h:424
aiMatrix4x4
Definition: matrix4x4.h:266
aiAnimMesh::mBitangents
C_STRUCT aiVector3D * mBitangents
Definition: mesh.h:443
aiMesh::mNumBones
unsigned int mNumBones
Definition: mesh.h:679
aiMesh::mNumAnimMeshes
unsigned int mNumAnimMeshes
Definition: mesh.h:708
aiMesh::mFaces
C_STRUCT aiFace * mFaces
Definition: mesh.h:674
aiBone::mName
C_STRUCT aiString mName
The name of the bone.
Definition: mesh.h:266
aiMesh::mTangents
C_STRUCT aiVector3D * mTangents
Definition: mesh.h:635
aiMorphingMethod_MORPH_NORMALIZED
@ aiMorphingMethod_MORPH_NORMALIZED
Definition: mesh.h:543
AI_MAX_NUMBER_OF_TEXTURECOORDS
#define AI_MAX_NUMBER_OF_TEXTURECOORDS
Definition: mesh.h:111
aiPrimitiveType
aiPrimitiveType
Enumerates the types of geometric primitives supported by Assimp.
Definition: mesh.h:371
aiMesh
enum aiMorphingMethod
Definition: mesh.h:575