BRE12
mesh.h
Go to the documentation of this file.
1 /*
2 ---------------------------------------------------------------------------
3 Open Asset Import Library (assimp)
4 ---------------------------------------------------------------------------
5 
6 Copyright (c) 2006-2012, 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 #ifndef INCLUDED_AI_MESH_H
47 #define INCLUDED_AI_MESH_H
48 
49 #include "types.h"
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 // ---------------------------------------------------------------------------
56 // Limits. These values are required to match the settings Assimp was
57 // compiled against. Therfore, do not redefine them unless you build the
58 // library from source using the same definitions.
59 // ---------------------------------------------------------------------------
60 
64 #ifndef AI_MAX_FACE_INDICES
65 # define AI_MAX_FACE_INDICES 0x7fff
66 #endif
67 
71 #ifndef AI_MAX_BONE_WEIGHTS
72 # define AI_MAX_BONE_WEIGHTS 0x7fffffff
73 #endif
74 
78 #ifndef AI_MAX_VERTICES
79 # define AI_MAX_VERTICES 0x7fffffff
80 #endif
81 
85 #ifndef AI_MAX_FACES
86 # define AI_MAX_FACES 0x7fffffff
87 #endif
88 
92 #ifndef AI_MAX_NUMBER_OF_COLOR_SETS
93 # define AI_MAX_NUMBER_OF_COLOR_SETS 0x8
94 #endif // !! AI_MAX_NUMBER_OF_COLOR_SETS
95 
99 #ifndef AI_MAX_NUMBER_OF_TEXTURECOORDS
100 # define AI_MAX_NUMBER_OF_TEXTURECOORDS 0x8
101 #endif // !! AI_MAX_NUMBER_OF_TEXTURECOORDS
102 
103 // ---------------------------------------------------------------------------
125 struct aiFace
126 {
129  unsigned int mNumIndices;
130 
132  unsigned int* mIndices;
133 
134 #ifdef __cplusplus
135 
137  aiFace()
138  : mNumIndices( 0 )
139  , mIndices( NULL )
140  {
141  }
142 
144  ~aiFace()
145  {
146  delete [] mIndices;
147  }
148 
150  aiFace( const aiFace& o)
151  : mIndices( NULL )
152  {
153  *this = o;
154  }
155 
157  aiFace& operator = ( const aiFace& o)
158  {
159  if (&o == this)
160  return *this;
161 
162  delete[] mIndices;
163  mNumIndices = o.mNumIndices;
164  if (mNumIndices) {
165  mIndices = new unsigned int[mNumIndices];
166  ::memcpy( mIndices, o.mIndices, mNumIndices * sizeof( unsigned int));
167  }
168  else {
169  mIndices = NULL;
170  }
171  return *this;
172  }
173 
176  bool operator== (const aiFace& o) const
177  {
178  if (mIndices == o.mIndices)return true;
179  else if (mIndices && mNumIndices == o.mNumIndices)
180  {
181  for (unsigned int i = 0;i < this->mNumIndices;++i)
182  if (mIndices[i] != o.mIndices[i])return false;
183  return true;
184  }
185  return false;
186  }
187 
190  bool operator != (const aiFace& o) const
191  {
192  return !(*this == o);
193  }
194 #endif // __cplusplus
195 }; // struct aiFace
196 
197 
198 // ---------------------------------------------------------------------------
202 {
204  unsigned int mVertexId;
205 
208  float mWeight;
209 
210 #ifdef __cplusplus
211 
213  aiVertexWeight() { }
214 
218  aiVertexWeight( unsigned int pID, float pWeight)
219  : mVertexId( pID), mWeight( pWeight)
220  { /* nothing to do here */ }
221 
222 #endif // __cplusplus
223 };
224 
225 
226 // ---------------------------------------------------------------------------
233 struct aiBone
234 {
236  C_STRUCT aiString mName;
237 
240  unsigned int mNumWeights;
241 
244 
247 
248 #ifdef __cplusplus
249 
251  aiBone()
252  : mNumWeights( 0 )
253  , mWeights( NULL )
254  {
255  }
256 
258  aiBone(const aiBone& other)
259  : mName( other.mName )
260  , mNumWeights( other.mNumWeights )
261  , mOffsetMatrix( other.mOffsetMatrix )
262  {
263  if (other.mWeights && other.mNumWeights)
264  {
265  mWeights = new aiVertexWeight[mNumWeights];
266  ::memcpy(mWeights,other.mWeights,mNumWeights * sizeof(aiVertexWeight));
267  }
268  }
269 
271  ~aiBone()
272  {
273  delete [] mWeights;
274  }
275 #endif // __cplusplus
276 };
277 
278 
279 // ---------------------------------------------------------------------------
288 {
295 
302 
308 
317 
318 
322 #ifndef SWIG
324 #endif
325 };
326 
327 // Get the #aiPrimitiveType flag for a specific number of face indices
328 #define AI_PRIMITIVE_TYPE_FOR_N_INDICES(n) \
329  ((n) > 3 ? aiPrimitiveType_POLYGON : (aiPrimitiveType)(1u << ((n)-1)))
330 
331 
332 
333 // ---------------------------------------------------------------------------
345 {
353 
355  C_STRUCT aiVector3D* mNormals;
356 
359 
362 
365 
367  C_STRUCT aiVector3D* mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS];
368 
377  unsigned int mNumVertices;
378 
379 #ifdef __cplusplus
380 
381  aiAnimMesh()
382  : mVertices( NULL )
383  , mNormals( NULL )
384  , mTangents( NULL )
385  , mBitangents( NULL )
386  , mNumVertices( 0 )
387  {
388  // fixme consider moving this to the ctor initializer list as well
389  for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++){
390  mTextureCoords[a] = NULL;
391  }
392  for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
393  mColors[a] = NULL;
394  }
395  }
396 
397  ~aiAnimMesh()
398  {
399  delete [] mVertices;
400  delete [] mNormals;
401  delete [] mTangents;
402  delete [] mBitangents;
403  for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) {
404  delete [] mTextureCoords[a];
405  }
406  for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
407  delete [] mColors[a];
408  }
409  }
410 
413  bool HasPositions() const {
414  return mVertices != NULL;
415  }
416 
419  bool HasNormals() const {
420  return mNormals != NULL;
421  }
422 
426  bool HasTangentsAndBitangents() const {
427  return mTangents != NULL;
428  }
429 
433  bool HasVertexColors( unsigned int pIndex) const {
434  return pIndex >= AI_MAX_NUMBER_OF_COLOR_SETS ? false : mColors[pIndex] != NULL;
435  }
436 
440  bool HasTextureCoords( unsigned int pIndex) const {
441  return pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS ? false : mTextureCoords[pIndex] != NULL;
442  }
443 
444 #endif
445 };
446 
447 
448 // ---------------------------------------------------------------------------
467 struct aiMesh
468 {
474  unsigned int mPrimitiveTypes;
475 
480  unsigned int mNumVertices;
481 
486  unsigned int mNumFaces;
487 
493 
514  C_STRUCT aiVector3D* mNormals;
515 
529 
538 
545 
550  C_STRUCT aiVector3D* mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS];
551 
559  unsigned int mNumUVComponents[AI_MAX_NUMBER_OF_TEXTURECOORDS];
560 
567  C_STRUCT aiFace* mFaces;
568 
572  unsigned int mNumBones;
573 
578  C_STRUCT aiBone** mBones;
579 
585  unsigned int mMaterialIndex;
586 
598  C_STRUCT aiString mName;
599 
600 
602  unsigned int mNumAnimMeshes;
603 
608 
609 
610 #ifdef __cplusplus
611 
613  aiMesh()
614  : mPrimitiveTypes( 0 )
615  , mNumVertices( 0 )
616  , mNumFaces( 0 )
617  , mVertices( NULL )
618  , mNormals( NULL )
619  , mTangents( NULL )
620  , mBitangents( NULL )
621  , mFaces( NULL )
622  , mNumBones( 0 )
623  , mBones( NULL )
624  , mMaterialIndex( 0 )
625  , mNumAnimMeshes( 0 )
626  , mAnimMeshes( NULL )
627  {
628  for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++)
629  {
630  mNumUVComponents[a] = 0;
631  mTextureCoords[a] = NULL;
632  }
633 
634  for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++)
635  mColors[a] = NULL;
636  }
637 
639  ~aiMesh()
640  {
641  delete [] mVertices;
642  delete [] mNormals;
643  delete [] mTangents;
644  delete [] mBitangents;
645  for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) {
646  delete [] mTextureCoords[a];
647  }
648  for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
649  delete [] mColors[a];
650  }
651 
652  // DO NOT REMOVE THIS ADDITIONAL CHECK
653  if (mNumBones && mBones) {
654  for( unsigned int a = 0; a < mNumBones; a++) {
655  delete mBones[a];
656  }
657  delete [] mBones;
658  }
659 
660  if (mNumAnimMeshes && mAnimMeshes) {
661  for( unsigned int a = 0; a < mNumAnimMeshes; a++) {
662  delete mAnimMeshes[a];
663  }
664  delete [] mAnimMeshes;
665  }
666 
667  delete [] mFaces;
668  }
669 
673  bool HasPositions() const
674  { return mVertices != NULL && mNumVertices > 0; }
675 
678  bool HasFaces() const
679  { return mFaces != NULL && mNumFaces > 0; }
680 
682  bool HasNormals() const
683  { return mNormals != NULL && mNumVertices > 0; }
684 
689  bool HasTangentsAndBitangents() const
690  { return mTangents != NULL && mBitangents != NULL && mNumVertices > 0; }
691 
694  bool HasVertexColors( unsigned int pIndex) const
695  {
696  if( pIndex >= AI_MAX_NUMBER_OF_COLOR_SETS)
697  return false;
698  else
699  return mColors[pIndex] != NULL && mNumVertices > 0;
700  }
701 
704  bool HasTextureCoords( unsigned int pIndex) const
705  {
706  if( pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS)
707  return false;
708  else
709  return mTextureCoords[pIndex] != NULL && mNumVertices > 0;
710  }
711 
713  unsigned int GetNumUVChannels() const
714  {
715  unsigned int n = 0;
716  while (n < AI_MAX_NUMBER_OF_TEXTURECOORDS && mTextureCoords[n])++n;
717  return n;
718  }
719 
721  unsigned int GetNumColorChannels() const
722  {
723  unsigned int n = 0;
724  while (n < AI_MAX_NUMBER_OF_COLOR_SETS && mColors[n])++n;
725  return n;
726  }
727 
729  inline bool HasBones() const
730  { return mBones != NULL && mNumBones > 0; }
731 
732 #endif // __cplusplus
733 };
734 
735 
736 #ifdef __cplusplus
737 }
738 #endif
739 #endif // __AI_MESH_H_INC
740 
unsigned int mPrimitiveTypes
Bitwise combination of the members of the aiPrimitiveType enum.
Definition: mesh.h:474
float mWeight
The strength of the influence in the range (0...1).
Definition: mesh.h:208
A triangular primitive.
Definition: mesh.h:307
C_STRUCT aiString mName
The name of the bone.
Definition: mesh.h:236
Basic data types and primitives, such as vectors or colors.
C_STRUCT aiVector3D * mTangents
Replacement for aiMesh::mTangents.
Definition: mesh.h:358
Definition: matrix4x4.h:236
#define AI_MAX_NUMBER_OF_COLOR_SETS
Supported number of vertex color sets per mesh.
Definition: mesh.h:93
A mesh represents a geometry or model with a single material.
Definition: mesh.h:467
C_STRUCT aiFace * mFaces
The faces the mesh is constructed from.
Definition: mesh.h:567
unsigned int mNumVertices
The number of vertices in the aiAnimMesh, and thus the length of all the member arrays.
Definition: mesh.h:377
C_STRUCT aiVector3D * mVertices
Replacement for aiMesh::mVertices.
Definition: mesh.h:352
NOT CURRENTLY IN USE.
Definition: mesh.h:344
#define AI_MAX_NUMBER_OF_TEXTURECOORDS
Supported number of texture coord sets (UV(W) channels) per mesh.
Definition: mesh.h:100
A single bone of a mesh.
Definition: mesh.h:233
unsigned int mMaterialIndex
The material used by this mesh.
Definition: mesh.h:585
unsigned int mNumBones
The number of bones this mesh contains.
Definition: mesh.h:572
C_STRUCT aiString mName
Name of the mesh.
Definition: mesh.h:598
C_STRUCT aiVector3D * mNormals
Replacement for aiMesh::mNormals.
Definition: mesh.h:355
This value is not used.
Definition: mesh.h:323
A higher-level polygon with more than 3 edges.
Definition: mesh.h:316
unsigned int * mIndices
Pointer to the indices array. Size of the array is given in numIndices.
Definition: mesh.h:132
A single face in a mesh, referring to multiple vertices.
Definition: mesh.h:125
C_STRUCT aiBone ** mBones
The bones of this mesh.
Definition: mesh.h:578
Represents an UTF-8 string, zero byte terminated.
Definition: types.h:251
C_STRUCT aiVector3D * mVertices
Vertex positions.
Definition: mesh.h:492
C_STRUCT aiVector3D * mTangents
Vertex tangents.
Definition: mesh.h:528
C_STRUCT aiAnimMesh ** mAnimMeshes
NOT CURRENTLY IN USE.
Definition: mesh.h:607
unsigned int mNumAnimMeshes
NOT CURRENTLY IN USE.
Definition: mesh.h:602
A line primitive.
Definition: mesh.h:301
Definition: vector3.h:134
C_STRUCT aiVertexWeight * mWeights
The vertices affected by this bone.
Definition: mesh.h:243
C_STRUCT aiVector3D * mNormals
Vertex normals.
Definition: mesh.h:514
aiPrimitiveType
Enumerates the types of geometric primitives supported by Assimp.
Definition: mesh.h:287
Definition: color4.h:96
unsigned int mNumIndices
Number of indices defining this face.
Definition: mesh.h:129
A single influence of a bone on a vertex.
Definition: mesh.h:201
C_STRUCT aiVector3D * mBitangents
Replacement for aiMesh::mBitangents.
Definition: mesh.h:361
unsigned int mNumVertices
The number of vertices in this mesh.
Definition: mesh.h:480
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:240
unsigned int mNumFaces
The number of primitives (triangles, polygons, lines) in this mesh.
Definition: mesh.h:486
unsigned int mVertexId
Index of the vertex which is influenced by the bone.
Definition: mesh.h:204
C_STRUCT aiMatrix4x4 mOffsetMatrix
Matrix that transforms from mesh space to bone space in bind pose.
Definition: mesh.h:246
A point primitive.
Definition: mesh.h:294
C_STRUCT aiVector3D * mBitangents
Vertex bitangents.
Definition: mesh.h:537