miniassimp
diff include/miniassimp/mesh.h @ 0:879c81d94345
initial commit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Mon, 28 Jan 2019 18:19:26 +0200 |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/include/miniassimp/mesh.h Mon Jan 28 18:19:26 2019 +0200 1.3 @@ -0,0 +1,852 @@ 1.4 +/* 1.5 +--------------------------------------------------------------------------- 1.6 +Open Asset Import Library (assimp) 1.7 +--------------------------------------------------------------------------- 1.8 + 1.9 +Copyright (c) 2006-2018, assimp team 1.10 + 1.11 + 1.12 +All rights reserved. 1.13 + 1.14 +Redistribution and use of this software in source and binary forms, 1.15 +with or without modification, are permitted provided that the following 1.16 +conditions are met: 1.17 + 1.18 +* Redistributions of source code must retain the above 1.19 + copyright notice, this list of conditions and the 1.20 + following disclaimer. 1.21 + 1.22 +* Redistributions in binary form must reproduce the above 1.23 + copyright notice, this list of conditions and the 1.24 + following disclaimer in the documentation and/or other 1.25 + materials provided with the distribution. 1.26 + 1.27 +* Neither the name of the assimp team, nor the names of its 1.28 + contributors may be used to endorse or promote products 1.29 + derived from this software without specific prior 1.30 + written permission of the assimp team. 1.31 + 1.32 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.33 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.34 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.35 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.36 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.37 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.38 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.39 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.40 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.41 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.42 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.43 +--------------------------------------------------------------------------- 1.44 +*/ 1.45 + 1.46 +/** @file mesh.h 1.47 + * @brief Declares the data structures in which the imported geometry is 1.48 + returned by ASSIMP: aiMesh, aiFace and aiBone data structures. 1.49 + */ 1.50 +#pragma once 1.51 +#ifndef AI_MESH_H_INC 1.52 +#define AI_MESH_H_INC 1.53 + 1.54 +#include "types.h" 1.55 + 1.56 +#ifdef __cplusplus 1.57 +extern "C" { 1.58 +#endif 1.59 + 1.60 +// --------------------------------------------------------------------------- 1.61 +// Limits. These values are required to match the settings Assimp was 1.62 +// compiled against. Therefore, do not redefine them unless you build the 1.63 +// library from source using the same definitions. 1.64 +// --------------------------------------------------------------------------- 1.65 + 1.66 +/** @def AI_MAX_FACE_INDICES 1.67 + * Maximum number of indices per face (polygon). */ 1.68 + 1.69 +#ifndef AI_MAX_FACE_INDICES 1.70 +# define AI_MAX_FACE_INDICES 0x7fff 1.71 +#endif 1.72 + 1.73 +/** @def AI_MAX_BONE_WEIGHTS 1.74 + * Maximum number of indices per face (polygon). */ 1.75 + 1.76 +#ifndef AI_MAX_BONE_WEIGHTS 1.77 +# define AI_MAX_BONE_WEIGHTS 0x7fffffff 1.78 +#endif 1.79 + 1.80 +/** @def AI_MAX_VERTICES 1.81 + * Maximum number of vertices per mesh. */ 1.82 + 1.83 +#ifndef AI_MAX_VERTICES 1.84 +# define AI_MAX_VERTICES 0x7fffffff 1.85 +#endif 1.86 + 1.87 +/** @def AI_MAX_FACES 1.88 + * Maximum number of faces per mesh. */ 1.89 + 1.90 +#ifndef AI_MAX_FACES 1.91 +# define AI_MAX_FACES 0x7fffffff 1.92 +#endif 1.93 + 1.94 +/** @def AI_MAX_NUMBER_OF_COLOR_SETS 1.95 + * Supported number of vertex color sets per mesh. */ 1.96 + 1.97 +#ifndef AI_MAX_NUMBER_OF_COLOR_SETS 1.98 +# define AI_MAX_NUMBER_OF_COLOR_SETS 0x8 1.99 +#endif // !! AI_MAX_NUMBER_OF_COLOR_SETS 1.100 + 1.101 +/** @def AI_MAX_NUMBER_OF_TEXTURECOORDS 1.102 + * Supported number of texture coord sets (UV(W) channels) per mesh */ 1.103 + 1.104 +#ifndef AI_MAX_NUMBER_OF_TEXTURECOORDS 1.105 +# define AI_MAX_NUMBER_OF_TEXTURECOORDS 0x8 1.106 +#endif // !! AI_MAX_NUMBER_OF_TEXTURECOORDS 1.107 + 1.108 +// --------------------------------------------------------------------------- 1.109 +/** @brief A single face in a mesh, referring to multiple vertices. 1.110 + * 1.111 + * If mNumIndices is 3, we call the face 'triangle', for mNumIndices > 3 1.112 + * it's called 'polygon' (hey, that's just a definition!). 1.113 + * <br> 1.114 + * aiMesh::mPrimitiveTypes can be queried to quickly examine which types of 1.115 + * primitive are actually present in a mesh. The #aiProcess_SortByPType flag 1.116 + * executes a special post-processing algorithm which splits meshes with 1.117 + * *different* primitive types mixed up (e.g. lines and triangles) in several 1.118 + * 'clean' submeshes. Furthermore there is a configuration option ( 1.119 + * #AI_CONFIG_PP_SBP_REMOVE) to force #aiProcess_SortByPType to remove 1.120 + * specific kinds of primitives from the imported scene, completely and forever. 1.121 + * In many cases you'll probably want to set this setting to 1.122 + * @code 1.123 + * aiPrimitiveType_LINE|aiPrimitiveType_POINT 1.124 + * @endcode 1.125 + * Together with the #aiProcess_Triangulate flag you can then be sure that 1.126 + * #aiFace::mNumIndices is always 3. 1.127 + * @note Take a look at the @link data Data Structures page @endlink for 1.128 + * more information on the layout and winding order of a face. 1.129 + */ 1.130 +struct aiFace 1.131 +{ 1.132 + //! Number of indices defining this face. 1.133 + //! The maximum value for this member is #AI_MAX_FACE_INDICES. 1.134 + unsigned int mNumIndices; 1.135 + 1.136 + //! Pointer to the indices array. Size of the array is given in numIndices. 1.137 + unsigned int* mIndices; 1.138 + 1.139 +#ifdef __cplusplus 1.140 + 1.141 + //! Default constructor 1.142 + aiFace() AI_NO_EXCEPT 1.143 + : mNumIndices( 0 ) 1.144 + , mIndices( 0 ) { 1.145 + // empty 1.146 + } 1.147 + 1.148 + //! Default destructor. Delete the index array 1.149 + ~aiFace() 1.150 + { 1.151 + delete [] mIndices; 1.152 + } 1.153 + 1.154 + //! Copy constructor. Copy the index array 1.155 + aiFace( const aiFace& o) 1.156 + : mNumIndices(0) 1.157 + , mIndices( 0 ) { 1.158 + *this = o; 1.159 + } 1.160 + 1.161 + //! Assignment operator. Copy the index array 1.162 + aiFace& operator = ( const aiFace& o) { 1.163 + if (&o == this) { 1.164 + return *this; 1.165 + } 1.166 + 1.167 + delete[] mIndices; 1.168 + mNumIndices = o.mNumIndices; 1.169 + if (mNumIndices) { 1.170 + mIndices = new unsigned int[mNumIndices]; 1.171 + ::memcpy( mIndices, o.mIndices, mNumIndices * sizeof( unsigned int)); 1.172 + } else { 1.173 + mIndices = 0; 1.174 + } 1.175 + 1.176 + return *this; 1.177 + } 1.178 + 1.179 + //! Comparison operator. Checks whether the index array 1.180 + //! of two faces is identical 1.181 + bool operator== (const aiFace& o) const { 1.182 + if (mIndices == o.mIndices) { 1.183 + return true; 1.184 + } 1.185 + 1.186 + if (0 != mIndices && mNumIndices != o.mNumIndices) { 1.187 + return false; 1.188 + } 1.189 + 1.190 + if (0 == mIndices) { 1.191 + return false; 1.192 + } 1.193 + 1.194 + for (unsigned int i = 0; i < this->mNumIndices; ++i) { 1.195 + if (mIndices[i] != o.mIndices[i]) { 1.196 + return false; 1.197 + } 1.198 + } 1.199 + 1.200 + return true; 1.201 + } 1.202 + 1.203 + //! Inverse comparison operator. Checks whether the index 1.204 + //! array of two faces is NOT identical 1.205 + bool operator != (const aiFace& o) const { 1.206 + return !(*this == o); 1.207 + } 1.208 +#endif // __cplusplus 1.209 +}; // struct aiFace 1.210 + 1.211 + 1.212 +// --------------------------------------------------------------------------- 1.213 +/** @brief A single influence of a bone on a vertex. 1.214 + */ 1.215 +struct aiVertexWeight { 1.216 + //! Index of the vertex which is influenced by the bone. 1.217 + unsigned int mVertexId; 1.218 + 1.219 + //! The strength of the influence in the range (0...1). 1.220 + //! The influence from all bones at one vertex amounts to 1. 1.221 + float mWeight; 1.222 + 1.223 +#ifdef __cplusplus 1.224 + 1.225 + //! Default constructor 1.226 + aiVertexWeight() AI_NO_EXCEPT 1.227 + : mVertexId(0) 1.228 + , mWeight(0.0f) { 1.229 + // empty 1.230 + } 1.231 + 1.232 + //! Initialization from a given index and vertex weight factor 1.233 + //! \param pID ID 1.234 + //! \param pWeight Vertex weight factor 1.235 + aiVertexWeight( unsigned int pID, float pWeight ) 1.236 + : mVertexId( pID ) 1.237 + , mWeight( pWeight ) { 1.238 + // empty 1.239 + } 1.240 + 1.241 + bool operator == ( const aiVertexWeight &rhs ) const { 1.242 + return ( mVertexId == rhs.mVertexId && mWeight == rhs.mWeight ); 1.243 + } 1.244 + 1.245 + bool operator != ( const aiVertexWeight &rhs ) const { 1.246 + return ( *this == rhs ); 1.247 + } 1.248 + 1.249 +#endif // __cplusplus 1.250 +}; 1.251 + 1.252 + 1.253 +// --------------------------------------------------------------------------- 1.254 +/** @brief A single bone of a mesh. 1.255 + * 1.256 + * A bone has a name by which it can be found in the frame hierarchy and by 1.257 + * which it can be addressed by animations. In addition it has a number of 1.258 + * influences on vertices, and a matrix relating the mesh position to the 1.259 + * position of the bone at the time of binding. 1.260 + */ 1.261 +struct aiBone { 1.262 + //! The name of the bone. 1.263 + C_STRUCT aiString mName; 1.264 + 1.265 + //! The number of vertices affected by this bone. 1.266 + //! The maximum value for this member is #AI_MAX_BONE_WEIGHTS. 1.267 + unsigned int mNumWeights; 1.268 + 1.269 + //! The influence weights of this bone, by vertex index. 1.270 + C_STRUCT aiVertexWeight* mWeights; 1.271 + 1.272 + /** Matrix that transforms from bone space to mesh space in bind pose. 1.273 + * 1.274 + * This matrix describes the position of the mesh 1.275 + * in the local space of this bone when the skeleton was bound. 1.276 + * Thus it can be used directly to determine a desired vertex position, 1.277 + * given the world-space transform of the bone when animated, 1.278 + * and the position of the vertex in mesh space. 1.279 + * 1.280 + * It is sometimes called an inverse-bind matrix, 1.281 + * or inverse bind pose matrix. 1.282 + */ 1.283 + C_STRUCT aiMatrix4x4 mOffsetMatrix; 1.284 + 1.285 +#ifdef __cplusplus 1.286 + 1.287 + //! Default constructor 1.288 + aiBone() AI_NO_EXCEPT 1.289 + : mName() 1.290 + , mNumWeights( 0 ) 1.291 + , mWeights( 0 ) 1.292 + , mOffsetMatrix() { 1.293 + // empty 1.294 + } 1.295 + 1.296 + //! Copy constructor 1.297 + aiBone(const aiBone& other) 1.298 + : mName( other.mName ) 1.299 + , mNumWeights( other.mNumWeights ) 1.300 + , mWeights(0) 1.301 + , mOffsetMatrix( other.mOffsetMatrix ) { 1.302 + if (other.mWeights && other.mNumWeights) { 1.303 + mWeights = new aiVertexWeight[mNumWeights]; 1.304 + ::memcpy(mWeights,other.mWeights,mNumWeights * sizeof(aiVertexWeight)); 1.305 + } 1.306 + } 1.307 + 1.308 + 1.309 + //! Assignment operator 1.310 + aiBone &operator=(const aiBone& other) { 1.311 + if (this == &other) { 1.312 + return *this; 1.313 + } 1.314 + 1.315 + mName = other.mName; 1.316 + mNumWeights = other.mNumWeights; 1.317 + mOffsetMatrix = other.mOffsetMatrix; 1.318 + 1.319 + if (other.mWeights && other.mNumWeights) 1.320 + { 1.321 + if (mWeights) { 1.322 + delete[] mWeights; 1.323 + } 1.324 + 1.325 + mWeights = new aiVertexWeight[mNumWeights]; 1.326 + ::memcpy(mWeights,other.mWeights,mNumWeights * sizeof(aiVertexWeight)); 1.327 + } 1.328 + 1.329 + return *this; 1.330 + } 1.331 + 1.332 + bool operator == ( const aiBone &rhs ) const { 1.333 + if ( mName != rhs.mName || mNumWeights != rhs.mNumWeights ) { 1.334 + return false; 1.335 + } 1.336 + 1.337 + for ( size_t i = 0; i < mNumWeights; ++i ) { 1.338 + if ( mWeights[ i ] != rhs.mWeights[ i ] ) { 1.339 + return false; 1.340 + } 1.341 + } 1.342 + 1.343 + return true; 1.344 + } 1.345 + //! Destructor - deletes the array of vertex weights 1.346 + ~aiBone() { 1.347 + delete [] mWeights; 1.348 + } 1.349 +#endif // __cplusplus 1.350 +}; 1.351 + 1.352 + 1.353 +// --------------------------------------------------------------------------- 1.354 +/** @brief Enumerates the types of geometric primitives supported by Assimp. 1.355 + * 1.356 + * @see aiFace Face data structure 1.357 + * @see aiProcess_SortByPType Per-primitive sorting of meshes 1.358 + * @see aiProcess_Triangulate Automatic triangulation 1.359 + * @see AI_CONFIG_PP_SBP_REMOVE Removal of specific primitive types. 1.360 + */ 1.361 +enum aiPrimitiveType 1.362 +{ 1.363 + /** A point primitive. 1.364 + * 1.365 + * This is just a single vertex in the virtual world, 1.366 + * #aiFace contains just one index for such a primitive. 1.367 + */ 1.368 + aiPrimitiveType_POINT = 0x1, 1.369 + 1.370 + /** A line primitive. 1.371 + * 1.372 + * This is a line defined through a start and an end position. 1.373 + * #aiFace contains exactly two indices for such a primitive. 1.374 + */ 1.375 + aiPrimitiveType_LINE = 0x2, 1.376 + 1.377 + /** A triangular primitive. 1.378 + * 1.379 + * A triangle consists of three indices. 1.380 + */ 1.381 + aiPrimitiveType_TRIANGLE = 0x4, 1.382 + 1.383 + /** A higher-level polygon with more than 3 edges. 1.384 + * 1.385 + * A triangle is a polygon, but polygon in this context means 1.386 + * "all polygons that are not triangles". The "Triangulate"-Step 1.387 + * is provided for your convenience, it splits all polygons in 1.388 + * triangles (which are much easier to handle). 1.389 + */ 1.390 + aiPrimitiveType_POLYGON = 0x8, 1.391 + 1.392 + 1.393 + /** This value is not used. It is just here to force the 1.394 + * compiler to map this enum to a 32 Bit integer. 1.395 + */ 1.396 +#ifndef SWIG 1.397 + _aiPrimitiveType_Force32Bit = INT_MAX 1.398 +#endif 1.399 +}; //! enum aiPrimitiveType 1.400 + 1.401 +// Get the #aiPrimitiveType flag for a specific number of face indices 1.402 +#define AI_PRIMITIVE_TYPE_FOR_N_INDICES(n) \ 1.403 + ((n) > 3 ? aiPrimitiveType_POLYGON : (aiPrimitiveType)(1u << ((n)-1))) 1.404 + 1.405 + 1.406 + 1.407 +// --------------------------------------------------------------------------- 1.408 +/** @brief An AnimMesh is an attachment to an #aiMesh stores per-vertex 1.409 + * animations for a particular frame. 1.410 + * 1.411 + * You may think of an #aiAnimMesh as a `patch` for the host mesh, which 1.412 + * replaces only certain vertex data streams at a particular time. 1.413 + * Each mesh stores n attached attached meshes (#aiMesh::mAnimMeshes). 1.414 + * The actual relationship between the time line and anim meshes is 1.415 + * established by #aiMeshAnim, which references singular mesh attachments 1.416 + * by their ID and binds them to a time offset. 1.417 +*/ 1.418 +struct aiAnimMesh 1.419 +{ 1.420 + /**Anim Mesh name */ 1.421 + C_STRUCT aiString mName; 1.422 + 1.423 + /** Replacement for aiMesh::mVertices. If this array is non-NULL, 1.424 + * it *must* contain mNumVertices entries. The corresponding 1.425 + * array in the host mesh must be non-NULL as well - animation 1.426 + * meshes may neither add or nor remove vertex components (if 1.427 + * a replacement array is NULL and the corresponding source 1.428 + * array is not, the source data is taken instead)*/ 1.429 + C_STRUCT aiVector3D* mVertices; 1.430 + 1.431 + /** Replacement for aiMesh::mNormals. */ 1.432 + C_STRUCT aiVector3D* mNormals; 1.433 + 1.434 + /** Replacement for aiMesh::mTangents. */ 1.435 + C_STRUCT aiVector3D* mTangents; 1.436 + 1.437 + /** Replacement for aiMesh::mBitangents. */ 1.438 + C_STRUCT aiVector3D* mBitangents; 1.439 + 1.440 + /** Replacement for aiMesh::mColors */ 1.441 + C_STRUCT aiColor4D* mColors[AI_MAX_NUMBER_OF_COLOR_SETS]; 1.442 + 1.443 + /** Replacement for aiMesh::mTextureCoords */ 1.444 + C_STRUCT aiVector3D* mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS]; 1.445 + 1.446 + /** The number of vertices in the aiAnimMesh, and thus the length of all 1.447 + * the member arrays. 1.448 + * 1.449 + * This has always the same value as the mNumVertices property in the 1.450 + * corresponding aiMesh. It is duplicated here merely to make the length 1.451 + * of the member arrays accessible even if the aiMesh is not known, e.g. 1.452 + * from language bindings. 1.453 + */ 1.454 + unsigned int mNumVertices; 1.455 + 1.456 + /** 1.457 + * Weight of the AnimMesh. 1.458 + */ 1.459 + float mWeight; 1.460 + 1.461 +#ifdef __cplusplus 1.462 + 1.463 + aiAnimMesh() AI_NO_EXCEPT 1.464 + : mVertices( 0 ) 1.465 + , mNormals(0) 1.466 + , mTangents(0) 1.467 + , mBitangents(0) 1.468 + , mColors() 1.469 + , mTextureCoords() 1.470 + , mNumVertices( 0 ) 1.471 + , mWeight( 0.0f ) 1.472 + { 1.473 + // fixme consider moving this to the ctor initializer list as well 1.474 + for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++){ 1.475 + mTextureCoords[a] = NULL; 1.476 + } 1.477 + for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) { 1.478 + mColors[a] = NULL; 1.479 + } 1.480 + } 1.481 + 1.482 + ~aiAnimMesh() 1.483 + { 1.484 + delete [] mVertices; 1.485 + delete [] mNormals; 1.486 + delete [] mTangents; 1.487 + delete [] mBitangents; 1.488 + for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) { 1.489 + delete [] mTextureCoords[a]; 1.490 + } 1.491 + for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) { 1.492 + delete [] mColors[a]; 1.493 + } 1.494 + } 1.495 + 1.496 + /** Check whether the anim mesh overrides the vertex positions 1.497 + * of its host mesh*/ 1.498 + bool HasPositions() const { 1.499 + return mVertices != NULL; 1.500 + } 1.501 + 1.502 + /** Check whether the anim mesh overrides the vertex normals 1.503 + * of its host mesh*/ 1.504 + bool HasNormals() const { 1.505 + return mNormals != NULL; 1.506 + } 1.507 + 1.508 + /** Check whether the anim mesh overrides the vertex tangents 1.509 + * and bitangents of its host mesh. As for aiMesh, 1.510 + * tangents and bitangents always go together. */ 1.511 + bool HasTangentsAndBitangents() const { 1.512 + return mTangents != NULL; 1.513 + } 1.514 + 1.515 + /** Check whether the anim mesh overrides a particular 1.516 + * set of vertex colors on his host mesh. 1.517 + * @param pIndex 0<index<AI_MAX_NUMBER_OF_COLOR_SETS */ 1.518 + bool HasVertexColors( unsigned int pIndex) const { 1.519 + return pIndex >= AI_MAX_NUMBER_OF_COLOR_SETS ? false : mColors[pIndex] != NULL; 1.520 + } 1.521 + 1.522 + /** Check whether the anim mesh overrides a particular 1.523 + * set of texture coordinates on his host mesh. 1.524 + * @param pIndex 0<index<AI_MAX_NUMBER_OF_TEXTURECOORDS */ 1.525 + bool HasTextureCoords( unsigned int pIndex) const { 1.526 + return pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS ? false : mTextureCoords[pIndex] != NULL; 1.527 + } 1.528 + 1.529 +#endif 1.530 +}; 1.531 + 1.532 +// --------------------------------------------------------------------------- 1.533 +/** @brief Enumerates the methods of mesh morphing supported by Assimp. 1.534 + */ 1.535 +enum aiMorphingMethod 1.536 +{ 1.537 + /** Interpolation between morph targets */ 1.538 + aiMorphingMethod_VERTEX_BLEND = 0x1, 1.539 + 1.540 + /** Normalized morphing between morph targets */ 1.541 + aiMorphingMethod_MORPH_NORMALIZED = 0x2, 1.542 + 1.543 + /** Relative morphing between morph targets */ 1.544 + aiMorphingMethod_MORPH_RELATIVE = 0x3, 1.545 + 1.546 + /** This value is not used. It is just here to force the 1.547 + * compiler to map this enum to a 32 Bit integer. 1.548 + */ 1.549 +#ifndef SWIG 1.550 + _aiMorphingMethod_Force32Bit = INT_MAX 1.551 +#endif 1.552 +}; //! enum aiMorphingMethod 1.553 + 1.554 +// --------------------------------------------------------------------------- 1.555 +/** @brief A mesh represents a geometry or model with a single material. 1.556 +* 1.557 +* It usually consists of a number of vertices and a series of primitives/faces 1.558 +* referencing the vertices. In addition there might be a series of bones, each 1.559 +* of them addressing a number of vertices with a certain weight. Vertex data 1.560 +* is presented in channels with each channel containing a single per-vertex 1.561 +* information such as a set of texture coords or a normal vector. 1.562 +* If a data pointer is non-null, the corresponding data stream is present. 1.563 +* From C++-programs you can also use the comfort functions Has*() to 1.564 +* test for the presence of various data streams. 1.565 +* 1.566 +* A Mesh uses only a single material which is referenced by a material ID. 1.567 +* @note The mPositions member is usually not optional. However, vertex positions 1.568 +* *could* be missing if the #AI_SCENE_FLAGS_INCOMPLETE flag is set in 1.569 +* @code 1.570 +* aiScene::mFlags 1.571 +* @endcode 1.572 +*/ 1.573 +struct aiMesh 1.574 +{ 1.575 + /** Bitwise combination of the members of the #aiPrimitiveType enum. 1.576 + * This specifies which types of primitives are present in the mesh. 1.577 + * The "SortByPrimitiveType"-Step can be used to make sure the 1.578 + * output meshes consist of one primitive type each. 1.579 + */ 1.580 + unsigned int mPrimitiveTypes; 1.581 + 1.582 + /** The number of vertices in this mesh. 1.583 + * This is also the size of all of the per-vertex data arrays. 1.584 + * The maximum value for this member is #AI_MAX_VERTICES. 1.585 + */ 1.586 + unsigned int mNumVertices; 1.587 + 1.588 + /** The number of primitives (triangles, polygons, lines) in this mesh. 1.589 + * This is also the size of the mFaces array. 1.590 + * The maximum value for this member is #AI_MAX_FACES. 1.591 + */ 1.592 + unsigned int mNumFaces; 1.593 + 1.594 + /** Vertex positions. 1.595 + * This array is always present in a mesh. The array is 1.596 + * mNumVertices in size. 1.597 + */ 1.598 + C_STRUCT aiVector3D* mVertices; 1.599 + 1.600 + /** Vertex normals. 1.601 + * The array contains normalized vectors, NULL if not present. 1.602 + * The array is mNumVertices in size. Normals are undefined for 1.603 + * point and line primitives. A mesh consisting of points and 1.604 + * lines only may not have normal vectors. Meshes with mixed 1.605 + * primitive types (i.e. lines and triangles) may have normals, 1.606 + * but the normals for vertices that are only referenced by 1.607 + * point or line primitives are undefined and set to QNaN (WARN: 1.608 + * qNaN compares to inequal to *everything*, even to qNaN itself. 1.609 + * Using code like this to check whether a field is qnan is: 1.610 + * @code 1.611 + * #define IS_QNAN(f) (f != f) 1.612 + * @endcode 1.613 + * still dangerous because even 1.f == 1.f could evaluate to false! ( 1.614 + * remember the subtleties of IEEE754 artithmetics). Use stuff like 1.615 + * @c fpclassify instead. 1.616 + * @note Normal vectors computed by Assimp are always unit-length. 1.617 + * However, this needn't apply for normals that have been taken 1.618 + * directly from the model file. 1.619 + */ 1.620 + C_STRUCT aiVector3D* mNormals; 1.621 + 1.622 + /** Vertex tangents. 1.623 + * The tangent of a vertex points in the direction of the positive 1.624 + * X texture axis. The array contains normalized vectors, NULL if 1.625 + * not present. The array is mNumVertices in size. A mesh consisting 1.626 + * of points and lines only may not have normal vectors. Meshes with 1.627 + * mixed primitive types (i.e. lines and triangles) may have 1.628 + * normals, but the normals for vertices that are only referenced by 1.629 + * point or line primitives are undefined and set to qNaN. See 1.630 + * the #mNormals member for a detailed discussion of qNaNs. 1.631 + * @note If the mesh contains tangents, it automatically also 1.632 + * contains bitangents. 1.633 + */ 1.634 + C_STRUCT aiVector3D* mTangents; 1.635 + 1.636 + /** Vertex bitangents. 1.637 + * The bitangent of a vertex points in the direction of the positive 1.638 + * Y texture axis. The array contains normalized vectors, NULL if not 1.639 + * present. The array is mNumVertices in size. 1.640 + * @note If the mesh contains tangents, it automatically also contains 1.641 + * bitangents. 1.642 + */ 1.643 + C_STRUCT aiVector3D* mBitangents; 1.644 + 1.645 + /** Vertex color sets. 1.646 + * A mesh may contain 0 to #AI_MAX_NUMBER_OF_COLOR_SETS vertex 1.647 + * colors per vertex. NULL if not present. Each array is 1.648 + * mNumVertices in size if present. 1.649 + */ 1.650 + C_STRUCT aiColor4D* mColors[AI_MAX_NUMBER_OF_COLOR_SETS]; 1.651 + 1.652 + /** Vertex texture coords, also known as UV channels. 1.653 + * A mesh may contain 0 to AI_MAX_NUMBER_OF_TEXTURECOORDS per 1.654 + * vertex. NULL if not present. The array is mNumVertices in size. 1.655 + */ 1.656 + C_STRUCT aiVector3D* mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS]; 1.657 + 1.658 + /** Specifies the number of components for a given UV channel. 1.659 + * Up to three channels are supported (UVW, for accessing volume 1.660 + * or cube maps). If the value is 2 for a given channel n, the 1.661 + * component p.z of mTextureCoords[n][p] is set to 0.0f. 1.662 + * If the value is 1 for a given channel, p.y is set to 0.0f, too. 1.663 + * @note 4D coords are not supported 1.664 + */ 1.665 + unsigned int mNumUVComponents[AI_MAX_NUMBER_OF_TEXTURECOORDS]; 1.666 + 1.667 + /** The faces the mesh is constructed from. 1.668 + * Each face refers to a number of vertices by their indices. 1.669 + * This array is always present in a mesh, its size is given 1.670 + * in mNumFaces. If the #AI_SCENE_FLAGS_NON_VERBOSE_FORMAT 1.671 + * is NOT set each face references an unique set of vertices. 1.672 + */ 1.673 + C_STRUCT aiFace* mFaces; 1.674 + 1.675 + /** The number of bones this mesh contains. 1.676 + * Can be 0, in which case the mBones array is NULL. 1.677 + */ 1.678 + unsigned int mNumBones; 1.679 + 1.680 + /** The bones of this mesh. 1.681 + * A bone consists of a name by which it can be found in the 1.682 + * frame hierarchy and a set of vertex weights. 1.683 + */ 1.684 + C_STRUCT aiBone** mBones; 1.685 + 1.686 + /** The material used by this mesh. 1.687 + * A mesh uses only a single material. If an imported model uses 1.688 + * multiple materials, the import splits up the mesh. Use this value 1.689 + * as index into the scene's material list. 1.690 + */ 1.691 + unsigned int mMaterialIndex; 1.692 + 1.693 + /** Name of the mesh. Meshes can be named, but this is not a 1.694 + * requirement and leaving this field empty is totally fine. 1.695 + * There are mainly three uses for mesh names: 1.696 + * - some formats name nodes and meshes independently. 1.697 + * - importers tend to split meshes up to meet the 1.698 + * one-material-per-mesh requirement. Assigning 1.699 + * the same (dummy) name to each of the result meshes 1.700 + * aids the caller at recovering the original mesh 1.701 + * partitioning. 1.702 + * - Vertex animations refer to meshes by their names. 1.703 + **/ 1.704 + C_STRUCT aiString mName; 1.705 + 1.706 + 1.707 + /** The number of attachment meshes. Note! Currently only works with Collada loader. */ 1.708 + unsigned int mNumAnimMeshes; 1.709 + 1.710 + /** Attachment meshes for this mesh, for vertex-based animation. 1.711 + * Attachment meshes carry replacement data for some of the 1.712 + * mesh'es vertex components (usually positions, normals). 1.713 + * Note! Currently only works with Collada loader.*/ 1.714 + C_STRUCT aiAnimMesh** mAnimMeshes; 1.715 + 1.716 + /** 1.717 + * Method of morphing when animeshes are specified. 1.718 + */ 1.719 + unsigned int mMethod; 1.720 + 1.721 +#ifdef __cplusplus 1.722 + 1.723 + //! Default constructor. Initializes all members to 0 1.724 + aiMesh() AI_NO_EXCEPT 1.725 + : mPrimitiveTypes( 0 ) 1.726 + , mNumVertices( 0 ) 1.727 + , mNumFaces( 0 ) 1.728 + , mVertices( 0 ) 1.729 + , mNormals(0) 1.730 + , mTangents(0) 1.731 + , mBitangents(0) 1.732 + , mColors() 1.733 + , mTextureCoords() 1.734 + , mNumUVComponents() 1.735 + , mFaces(0) 1.736 + , mNumBones( 0 ) 1.737 + , mBones(0) 1.738 + , mMaterialIndex( 0 ) 1.739 + , mNumAnimMeshes( 0 ) 1.740 + , mAnimMeshes(0) 1.741 + , mMethod( 0 ) { 1.742 + for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a ) { 1.743 + mNumUVComponents[a] = 0; 1.744 + mTextureCoords[a] = 0; 1.745 + } 1.746 + 1.747 + for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; ++a) { 1.748 + mColors[a] = 0; 1.749 + } 1.750 + } 1.751 + 1.752 + //! Deletes all storage allocated for the mesh 1.753 + ~aiMesh() { 1.754 + delete [] mVertices; 1.755 + delete [] mNormals; 1.756 + delete [] mTangents; 1.757 + delete [] mBitangents; 1.758 + for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) { 1.759 + delete [] mTextureCoords[a]; 1.760 + } 1.761 + for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) { 1.762 + delete [] mColors[a]; 1.763 + } 1.764 + 1.765 + // DO NOT REMOVE THIS ADDITIONAL CHECK 1.766 + if (mNumBones && mBones) { 1.767 + for( unsigned int a = 0; a < mNumBones; a++) { 1.768 + delete mBones[a]; 1.769 + } 1.770 + delete [] mBones; 1.771 + } 1.772 + 1.773 + if (mNumAnimMeshes && mAnimMeshes) { 1.774 + for( unsigned int a = 0; a < mNumAnimMeshes; a++) { 1.775 + delete mAnimMeshes[a]; 1.776 + } 1.777 + delete [] mAnimMeshes; 1.778 + } 1.779 + 1.780 + delete [] mFaces; 1.781 + } 1.782 + 1.783 + //! Check whether the mesh contains positions. Provided no special 1.784 + //! scene flags are set, this will always be true 1.785 + bool HasPositions() const 1.786 + { return mVertices != 0 && mNumVertices > 0; } 1.787 + 1.788 + //! Check whether the mesh contains faces. If no special scene flags 1.789 + //! are set this should always return true 1.790 + bool HasFaces() const 1.791 + { return mFaces != 0 && mNumFaces > 0; } 1.792 + 1.793 + //! Check whether the mesh contains normal vectors 1.794 + bool HasNormals() const 1.795 + { return mNormals != 0 && mNumVertices > 0; } 1.796 + 1.797 + //! Check whether the mesh contains tangent and bitangent vectors 1.798 + //! It is not possible that it contains tangents and no bitangents 1.799 + //! (or the other way round). The existence of one of them 1.800 + //! implies that the second is there, too. 1.801 + bool HasTangentsAndBitangents() const 1.802 + { return mTangents != 0 && mBitangents != 0 && mNumVertices > 0; } 1.803 + 1.804 + //! Check whether the mesh contains a vertex color set 1.805 + //! \param pIndex Index of the vertex color set 1.806 + bool HasVertexColors( unsigned int pIndex) const { 1.807 + if (pIndex >= AI_MAX_NUMBER_OF_COLOR_SETS) { 1.808 + return false; 1.809 + } else { 1.810 + return mColors[pIndex] != 0 && mNumVertices > 0; 1.811 + } 1.812 + } 1.813 + 1.814 + //! Check whether the mesh contains a texture coordinate set 1.815 + //! \param pIndex Index of the texture coordinates set 1.816 + bool HasTextureCoords( unsigned int pIndex) const { 1.817 + if (pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS) { 1.818 + return false; 1.819 + } else { 1.820 + return mTextureCoords[pIndex] != 0 && mNumVertices > 0; 1.821 + } 1.822 + } 1.823 + 1.824 + //! Get the number of UV channels the mesh contains 1.825 + unsigned int GetNumUVChannels() const { 1.826 + unsigned int n( 0 ); 1.827 + while (n < AI_MAX_NUMBER_OF_TEXTURECOORDS && mTextureCoords[n]) { 1.828 + ++n; 1.829 + } 1.830 + 1.831 + return n; 1.832 + } 1.833 + 1.834 + //! Get the number of vertex color channels the mesh contains 1.835 + unsigned int GetNumColorChannels() const { 1.836 + unsigned int n(0); 1.837 + while (n < AI_MAX_NUMBER_OF_COLOR_SETS && mColors[n]) { 1.838 + ++n; 1.839 + } 1.840 + return n; 1.841 + } 1.842 + 1.843 + //! Check whether the mesh contains bones 1.844 + bool HasBones() const { 1.845 + return mBones != 0 && mNumBones > 0; 1.846 + } 1.847 + 1.848 +#endif // __cplusplus 1.849 +}; 1.850 + 1.851 +#ifdef __cplusplus 1.852 +} 1.853 +#endif //! extern "C" 1.854 +#endif // AI_MESH_H_INC 1.855 +