GraphicsAPI_2020C
mesh.h
Go to the documentation of this file.
1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
5 
6 Copyright (c) 2006-2017, assimp team
7 
8 All rights reserved.
9 
10 Redistribution and use of this software in source and binary forms,
11 with or without modification, are permitted provided that the following
12 conditions are met:
13 
14 * Redistributions of source code must retain the above
15  copyright notice, this list of conditions and the
16  following disclaimer.
17 
18 * Redistributions in binary form must reproduce the above
19  copyright notice, this list of conditions and the
20  following disclaimer in the documentation and/or other
21  materials provided with the distribution.
22 
23 * Neither the name of the assimp team, nor the names of its
24  contributors may be used to endorse or promote products
25  derived from this software without specific prior
26  written permission of the assimp team.
27 
28 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 ---------------------------------------------------------------------------
40 */
41 
46 #pragma once
47 #ifndef AI_MESH_H_INC
48 #define AI_MESH_H_INC
49 
50 #include "types.h"
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 // ---------------------------------------------------------------------------
57 // Limits. These values are required to match the settings Assimp was
58 // compiled against. Therefore, do not redefine them unless you build the
59 // library from source using the same definitions.
60 // ---------------------------------------------------------------------------
61 
65 #ifndef AI_MAX_FACE_INDICES
66 # define AI_MAX_FACE_INDICES 0x7fff
67 #endif
68 
72 #ifndef AI_MAX_BONE_WEIGHTS
73 # define AI_MAX_BONE_WEIGHTS 0x7fffffff
74 #endif
75 
79 #ifndef AI_MAX_VERTICES
80 # define AI_MAX_VERTICES 0x7fffffff
81 #endif
82 
86 #ifndef AI_MAX_FACES
87 # define AI_MAX_FACES 0x7fffffff
88 #endif
89 
93 #ifndef AI_MAX_NUMBER_OF_COLOR_SETS
94 # define AI_MAX_NUMBER_OF_COLOR_SETS 0x8
95 #endif // !! AI_MAX_NUMBER_OF_COLOR_SETS
96 
100 #ifndef AI_MAX_NUMBER_OF_TEXTURECOORDS
101 # define AI_MAX_NUMBER_OF_TEXTURECOORDS 0x8
102 #endif // !! AI_MAX_NUMBER_OF_TEXTURECOORDS
103 
104 // ---------------------------------------------------------------------------
126 struct aiFace
127 {
130  unsigned int mNumIndices;
131 
133  unsigned int* mIndices;
134 
135 #ifdef __cplusplus
136 
138  aiFace()
139  : mNumIndices( 0 )
140  , mIndices( NULL )
141  {
142  }
143 
145  ~aiFace()
146  {
147  delete [] mIndices;
148  }
149 
151  aiFace( const aiFace& o)
152  : mIndices( NULL )
153  {
154  *this = o;
155  }
156 
158  aiFace& operator = ( const aiFace& o)
159  {
160  if (&o == this)
161  return *this;
162 
163  delete[] mIndices;
164  mNumIndices = o.mNumIndices;
165  if (mNumIndices) {
166  mIndices = new unsigned int[mNumIndices];
167  ::memcpy( mIndices, o.mIndices, mNumIndices * sizeof( unsigned int));
168  }
169  else {
170  mIndices = NULL;
171  }
172  return *this;
173  }
174 
177  bool operator== (const aiFace& o) const
178  {
179  if (mIndices == o.mIndices)return true;
180  else if (mIndices && mNumIndices == o.mNumIndices)
181  {
182  for (unsigned int i = 0;i < this->mNumIndices;++i)
183  if (mIndices[i] != o.mIndices[i])return false;
184  return true;
185  }
186  return false;
187  }
188 
191  bool operator != (const aiFace& o) const
192  {
193  return !(*this == o);
194  }
195 #endif // __cplusplus
196 }; // struct aiFace
197 
198 
199 // ---------------------------------------------------------------------------
203 {
205  unsigned int mVertexId;
206 
209  float mWeight;
210 
211 #ifdef __cplusplus
212 
214  aiVertexWeight() { }
215 
219  aiVertexWeight( unsigned int pID, float pWeight)
220  : mVertexId( pID), mWeight( pWeight)
221  { /* nothing to do here */ }
222 
223 #endif // __cplusplus
224 };
225 
226 
227 // ---------------------------------------------------------------------------
234 struct aiBone
235 {
237  C_STRUCT aiString mName;
238 
241  unsigned int mNumWeights;
242 
244  C_STRUCT aiVertexWeight* mWeights;
245 
247  C_STRUCT aiMatrix4x4 mOffsetMatrix;
248 
249 #ifdef __cplusplus
250 
252  aiBone()
253  : mName()
254  , mNumWeights( 0 )
255  , mWeights( NULL )
256  {
257  }
258 
260  aiBone(const aiBone& other)
261  : mName( other.mName )
262  , mNumWeights( other.mNumWeights )
263  , mOffsetMatrix( other.mOffsetMatrix )
264  {
265  if (other.mWeights && other.mNumWeights)
266  {
267  mWeights = new aiVertexWeight[mNumWeights];
268  ::memcpy(mWeights,other.mWeights,mNumWeights * sizeof(aiVertexWeight));
269  }
270  }
271 
273  ~aiBone()
274  {
275  delete [] mWeights;
276  }
277 #endif // __cplusplus
278 };
279 
280 
281 // ---------------------------------------------------------------------------
290 {
297 
304 
310 
319 
320 
324 #ifndef SWIG
326 #endif
327 };
328 
329 // Get the #aiPrimitiveType flag for a specific number of face indices
330 #define AI_PRIMITIVE_TYPE_FOR_N_INDICES(n) \
331  ((n) > 3 ? aiPrimitiveType_POLYGON : (aiPrimitiveType)(1u << ((n)-1)))
332 
333 
334 
335 // ---------------------------------------------------------------------------
347 {
354  C_STRUCT aiVector3D* mVertices;
355 
357  C_STRUCT aiVector3D* mNormals;
358 
360  C_STRUCT aiVector3D* mTangents;
361 
363  C_STRUCT aiVector3D* mBitangents;
364 
367 
369  C_STRUCT aiVector3D* mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS];
370 
379  unsigned int mNumVertices;
380 
384  float mWeight;
385 
386 #ifdef __cplusplus
387 
388  aiAnimMesh()
389  : mVertices( NULL )
390  , mNormals( NULL )
391  , mTangents( NULL )
392  , mBitangents( NULL )
393  , mNumVertices( 0 )
394  , mWeight( 0.0f )
395  {
396  // fixme consider moving this to the ctor initializer list as well
397  for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++){
398  mTextureCoords[a] = NULL;
399  }
400  for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
401  mColors[a] = NULL;
402  }
403  }
404 
405  ~aiAnimMesh()
406  {
407  delete [] mVertices;
408  delete [] mNormals;
409  delete [] mTangents;
410  delete [] mBitangents;
411  for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) {
412  delete [] mTextureCoords[a];
413  }
414  for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
415  delete [] mColors[a];
416  }
417  }
418 
421  bool HasPositions() const {
422  return mVertices != NULL;
423  }
424 
427  bool HasNormals() const {
428  return mNormals != NULL;
429  }
430 
434  bool HasTangentsAndBitangents() const {
435  return mTangents != NULL;
436  }
437 
441  bool HasVertexColors( unsigned int pIndex) const {
442  return pIndex >= AI_MAX_NUMBER_OF_COLOR_SETS ? false : mColors[pIndex] != NULL;
443  }
444 
448  bool HasTextureCoords( unsigned int pIndex) const {
449  return pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS ? false : mTextureCoords[pIndex] != NULL;
450  }
451 
452 #endif
453 };
454 
455 // ---------------------------------------------------------------------------
459 {
462 
465 
468 
472 #ifndef SWIG
474 #endif
475 };
476 
477 // ---------------------------------------------------------------------------
496 struct aiMesh
497 {
503  unsigned int mPrimitiveTypes;
504 
509  unsigned int mNumVertices;
510 
515  unsigned int mNumFaces;
516 
521  C_STRUCT aiVector3D* mVertices;
522 
543  C_STRUCT aiVector3D* mNormals;
544 
557  C_STRUCT aiVector3D* mTangents;
558 
566  C_STRUCT aiVector3D* mBitangents;
567 
574 
579  C_STRUCT aiVector3D* mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS];
580 
588  unsigned int mNumUVComponents[AI_MAX_NUMBER_OF_TEXTURECOORDS];
589 
596  C_STRUCT aiFace* mFaces;
597 
601  unsigned int mNumBones;
602 
607  C_STRUCT aiBone** mBones;
608 
614  unsigned int mMaterialIndex;
615 
627  C_STRUCT aiString mName;
628 
629 
631  unsigned int mNumAnimMeshes;
632 
637  C_STRUCT aiAnimMesh** mAnimMeshes;
638 
642  unsigned int mMethod;
643 
644 #ifdef __cplusplus
645 
647  aiMesh()
648  : mPrimitiveTypes( 0 )
649  , mNumVertices( 0 )
650  , mNumFaces( 0 )
651  , mVertices( NULL )
652  , mNormals( NULL )
653  , mTangents( NULL )
654  , mBitangents( NULL )
655  , mFaces( NULL )
656  , mNumBones( 0 )
657  , mBones( NULL )
658  , mMaterialIndex( 0 )
659  , mNumAnimMeshes( 0 )
660  , mAnimMeshes( NULL )
661  , mMethod( 0 )
662  {
663  for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++)
664  {
665  mNumUVComponents[a] = 0;
666  mTextureCoords[a] = NULL;
667  }
668 
669  for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++)
670  mColors[a] = NULL;
671  }
672 
674  ~aiMesh()
675  {
676  delete [] mVertices;
677  delete [] mNormals;
678  delete [] mTangents;
679  delete [] mBitangents;
680  for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) {
681  delete [] mTextureCoords[a];
682  }
683  for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
684  delete [] mColors[a];
685  }
686 
687  // DO NOT REMOVE THIS ADDITIONAL CHECK
688  if (mNumBones && mBones) {
689  for( unsigned int a = 0; a < mNumBones; a++) {
690  delete mBones[a];
691  }
692  delete [] mBones;
693  }
694 
695  if (mNumAnimMeshes && mAnimMeshes) {
696  for( unsigned int a = 0; a < mNumAnimMeshes; a++) {
697  delete mAnimMeshes[a];
698  }
699  delete [] mAnimMeshes;
700  }
701 
702  delete [] mFaces;
703  }
704 
707  bool HasPositions() const
708  { return mVertices != NULL && mNumVertices > 0; }
709 
712  bool HasFaces() const
713  { return mFaces != NULL && mNumFaces > 0; }
714 
716  bool HasNormals() const
717  { return mNormals != NULL && mNumVertices > 0; }
718 
723  bool HasTangentsAndBitangents() const
724  { return mTangents != NULL && mBitangents != NULL && mNumVertices > 0; }
725 
728  bool HasVertexColors( unsigned int pIndex) const
729  {
730  if( pIndex >= AI_MAX_NUMBER_OF_COLOR_SETS)
731  return false;
732  else
733  return mColors[pIndex] != NULL && mNumVertices > 0;
734  }
735 
738  bool HasTextureCoords( unsigned int pIndex) const
739  {
740  if( pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS)
741  return false;
742  else
743  return mTextureCoords[pIndex] != NULL && mNumVertices > 0;
744  }
745 
747  unsigned int GetNumUVChannels() const
748  {
749  unsigned int n = 0;
750  while (n < AI_MAX_NUMBER_OF_TEXTURECOORDS && mTextureCoords[n])++n;
751  return n;
752  }
753 
755  unsigned int GetNumColorChannels() const
756  {
757  unsigned int n = 0;
758  while (n < AI_MAX_NUMBER_OF_COLOR_SETS && mColors[n])++n;
759  return n;
760  }
761 
763  inline bool HasBones() const
764  { return mBones != NULL && mNumBones > 0; }
765 
766 #endif // __cplusplus
767 };
768 
769 #ifdef __cplusplus
770 }
771 #endif
772 #endif // AI_MESH_H_INC
773 
Interpolation between morph targets.
Definition: mesh.h:461
unsigned int mPrimitiveTypes
Bitwise combination of the members of the aiPrimitiveType enum.
Definition: mesh.h:503
float mWeight
The strength of the influence in the range (0...1).
Definition: mesh.h:209
A triangular primitive.
Definition: mesh.h:309
C_STRUCT aiString mName
The name of the bone.
Definition: mesh.h:237
Basic data types and primitives, such as vectors or colors.
Normalized morphing between morph targets.
Definition: mesh.h:464
Definition: matrix4x4.h:269
#define AI_MAX_NUMBER_OF_COLOR_SETS
Supported number of vertex color sets per mesh.
Definition: mesh.h:94
enum aiMorphingMethod
Definition: mesh.h:496
float mWeight
Weight of the AnimMesh.
Definition: mesh.h:384
unsigned int mNumVertices
The number of vertices in the aiAnimMesh, and thus the length of all the member arrays.
Definition: mesh.h:379
NOT CURRENTLY IN USE.
Definition: mesh.h:346
#define AI_MAX_NUMBER_OF_TEXTURECOORDS
Supported number of texture coord sets (UV(W) channels) per mesh.
Definition: mesh.h:101
A single bone of a mesh.
Definition: mesh.h:234
unsigned int mMaterialIndex
The material used by this mesh.
Definition: mesh.h:614
aiMorphingMethod
Enumerates the methods of mesh morphing supported by Assimp.
Definition: mesh.h:458
unsigned int mNumBones
The number of bones this mesh contains.
Definition: mesh.h:601
Relative morphing between morph targets.
Definition: mesh.h:467
This value is not used.
Definition: mesh.h:325
A higher-level polygon with more than 3 edges.
Definition: mesh.h:318
unsigned int * mIndices
Pointer to the indices array. Size of the array is given in numIndices.
Definition: mesh.h:133
A single face in a mesh, referring to multiple vertices.
Definition: mesh.h:126
Represents an UTF-8 string, zero byte terminated.
Definition: types.h:252
unsigned int mMethod
Method of morphing when animeshes are specified.
Definition: mesh.h:642
unsigned int mNumAnimMeshes
The number of attachment meshes.
Definition: mesh.h:631
A line primitive.
Definition: mesh.h:303
Definition: vector3.h:135
C_STRUCT aiVertexWeight * mWeights
The vertices affected by this bone.
Definition: mesh.h:244
aiPrimitiveType
Enumerates the types of geometric primitives supported by Assimp.
Definition: mesh.h:289
Definition: color4.h:98
unsigned int mNumIndices
Number of indices defining this face.
Definition: mesh.h:130
A single influence of a bone on a vertex.
Definition: mesh.h:202
unsigned int mNumVertices
The number of vertices in this mesh.
Definition: mesh.h:509
unsigned int mNumWeights
The number of vertices affected by this bone The maximum value for this member is AI_MAX_BONE_WEIGHTS...
Definition: mesh.h:241
unsigned int mNumFaces
The number of primitives (triangles, polygons, lines) in this mesh.
Definition: mesh.h:515
unsigned int mVertexId
Index of the vertex which is influenced by the bone.
Definition: mesh.h:205
C_STRUCT aiMatrix4x4 mOffsetMatrix
Matrix that transforms from mesh space to bone space in bind pose.
Definition: mesh.h:247
A point primitive.
Definition: mesh.h:296
This value is not used.
Definition: mesh.h:473