miniassimp

annotate 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
rev   line source
nuclear@0 1 /*
nuclear@0 2 ---------------------------------------------------------------------------
nuclear@0 3 Open Asset Import Library (assimp)
nuclear@0 4 ---------------------------------------------------------------------------
nuclear@0 5
nuclear@0 6 Copyright (c) 2006-2018, assimp team
nuclear@0 7
nuclear@0 8
nuclear@0 9 All rights reserved.
nuclear@0 10
nuclear@0 11 Redistribution and use of this software in source and binary forms,
nuclear@0 12 with or without modification, are permitted provided that the following
nuclear@0 13 conditions are met:
nuclear@0 14
nuclear@0 15 * Redistributions of source code must retain the above
nuclear@0 16 copyright notice, this list of conditions and the
nuclear@0 17 following disclaimer.
nuclear@0 18
nuclear@0 19 * Redistributions in binary form must reproduce the above
nuclear@0 20 copyright notice, this list of conditions and the
nuclear@0 21 following disclaimer in the documentation and/or other
nuclear@0 22 materials provided with the distribution.
nuclear@0 23
nuclear@0 24 * Neither the name of the assimp team, nor the names of its
nuclear@0 25 contributors may be used to endorse or promote products
nuclear@0 26 derived from this software without specific prior
nuclear@0 27 written permission of the assimp team.
nuclear@0 28
nuclear@0 29 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
nuclear@0 30 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
nuclear@0 31 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
nuclear@0 32 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
nuclear@0 33 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
nuclear@0 34 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
nuclear@0 35 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
nuclear@0 36 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
nuclear@0 37 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
nuclear@0 38 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
nuclear@0 39 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
nuclear@0 40 ---------------------------------------------------------------------------
nuclear@0 41 */
nuclear@0 42
nuclear@0 43 /** @file mesh.h
nuclear@0 44 * @brief Declares the data structures in which the imported geometry is
nuclear@0 45 returned by ASSIMP: aiMesh, aiFace and aiBone data structures.
nuclear@0 46 */
nuclear@0 47 #pragma once
nuclear@0 48 #ifndef AI_MESH_H_INC
nuclear@0 49 #define AI_MESH_H_INC
nuclear@0 50
nuclear@0 51 #include "types.h"
nuclear@0 52
nuclear@0 53 #ifdef __cplusplus
nuclear@0 54 extern "C" {
nuclear@0 55 #endif
nuclear@0 56
nuclear@0 57 // ---------------------------------------------------------------------------
nuclear@0 58 // Limits. These values are required to match the settings Assimp was
nuclear@0 59 // compiled against. Therefore, do not redefine them unless you build the
nuclear@0 60 // library from source using the same definitions.
nuclear@0 61 // ---------------------------------------------------------------------------
nuclear@0 62
nuclear@0 63 /** @def AI_MAX_FACE_INDICES
nuclear@0 64 * Maximum number of indices per face (polygon). */
nuclear@0 65
nuclear@0 66 #ifndef AI_MAX_FACE_INDICES
nuclear@0 67 # define AI_MAX_FACE_INDICES 0x7fff
nuclear@0 68 #endif
nuclear@0 69
nuclear@0 70 /** @def AI_MAX_BONE_WEIGHTS
nuclear@0 71 * Maximum number of indices per face (polygon). */
nuclear@0 72
nuclear@0 73 #ifndef AI_MAX_BONE_WEIGHTS
nuclear@0 74 # define AI_MAX_BONE_WEIGHTS 0x7fffffff
nuclear@0 75 #endif
nuclear@0 76
nuclear@0 77 /** @def AI_MAX_VERTICES
nuclear@0 78 * Maximum number of vertices per mesh. */
nuclear@0 79
nuclear@0 80 #ifndef AI_MAX_VERTICES
nuclear@0 81 # define AI_MAX_VERTICES 0x7fffffff
nuclear@0 82 #endif
nuclear@0 83
nuclear@0 84 /** @def AI_MAX_FACES
nuclear@0 85 * Maximum number of faces per mesh. */
nuclear@0 86
nuclear@0 87 #ifndef AI_MAX_FACES
nuclear@0 88 # define AI_MAX_FACES 0x7fffffff
nuclear@0 89 #endif
nuclear@0 90
nuclear@0 91 /** @def AI_MAX_NUMBER_OF_COLOR_SETS
nuclear@0 92 * Supported number of vertex color sets per mesh. */
nuclear@0 93
nuclear@0 94 #ifndef AI_MAX_NUMBER_OF_COLOR_SETS
nuclear@0 95 # define AI_MAX_NUMBER_OF_COLOR_SETS 0x8
nuclear@0 96 #endif // !! AI_MAX_NUMBER_OF_COLOR_SETS
nuclear@0 97
nuclear@0 98 /** @def AI_MAX_NUMBER_OF_TEXTURECOORDS
nuclear@0 99 * Supported number of texture coord sets (UV(W) channels) per mesh */
nuclear@0 100
nuclear@0 101 #ifndef AI_MAX_NUMBER_OF_TEXTURECOORDS
nuclear@0 102 # define AI_MAX_NUMBER_OF_TEXTURECOORDS 0x8
nuclear@0 103 #endif // !! AI_MAX_NUMBER_OF_TEXTURECOORDS
nuclear@0 104
nuclear@0 105 // ---------------------------------------------------------------------------
nuclear@0 106 /** @brief A single face in a mesh, referring to multiple vertices.
nuclear@0 107 *
nuclear@0 108 * If mNumIndices is 3, we call the face 'triangle', for mNumIndices > 3
nuclear@0 109 * it's called 'polygon' (hey, that's just a definition!).
nuclear@0 110 * <br>
nuclear@0 111 * aiMesh::mPrimitiveTypes can be queried to quickly examine which types of
nuclear@0 112 * primitive are actually present in a mesh. The #aiProcess_SortByPType flag
nuclear@0 113 * executes a special post-processing algorithm which splits meshes with
nuclear@0 114 * *different* primitive types mixed up (e.g. lines and triangles) in several
nuclear@0 115 * 'clean' submeshes. Furthermore there is a configuration option (
nuclear@0 116 * #AI_CONFIG_PP_SBP_REMOVE) to force #aiProcess_SortByPType to remove
nuclear@0 117 * specific kinds of primitives from the imported scene, completely and forever.
nuclear@0 118 * In many cases you'll probably want to set this setting to
nuclear@0 119 * @code
nuclear@0 120 * aiPrimitiveType_LINE|aiPrimitiveType_POINT
nuclear@0 121 * @endcode
nuclear@0 122 * Together with the #aiProcess_Triangulate flag you can then be sure that
nuclear@0 123 * #aiFace::mNumIndices is always 3.
nuclear@0 124 * @note Take a look at the @link data Data Structures page @endlink for
nuclear@0 125 * more information on the layout and winding order of a face.
nuclear@0 126 */
nuclear@0 127 struct aiFace
nuclear@0 128 {
nuclear@0 129 //! Number of indices defining this face.
nuclear@0 130 //! The maximum value for this member is #AI_MAX_FACE_INDICES.
nuclear@0 131 unsigned int mNumIndices;
nuclear@0 132
nuclear@0 133 //! Pointer to the indices array. Size of the array is given in numIndices.
nuclear@0 134 unsigned int* mIndices;
nuclear@0 135
nuclear@0 136 #ifdef __cplusplus
nuclear@0 137
nuclear@0 138 //! Default constructor
nuclear@0 139 aiFace() AI_NO_EXCEPT
nuclear@0 140 : mNumIndices( 0 )
nuclear@0 141 , mIndices( 0 ) {
nuclear@0 142 // empty
nuclear@0 143 }
nuclear@0 144
nuclear@0 145 //! Default destructor. Delete the index array
nuclear@0 146 ~aiFace()
nuclear@0 147 {
nuclear@0 148 delete [] mIndices;
nuclear@0 149 }
nuclear@0 150
nuclear@0 151 //! Copy constructor. Copy the index array
nuclear@0 152 aiFace( const aiFace& o)
nuclear@0 153 : mNumIndices(0)
nuclear@0 154 , mIndices( 0 ) {
nuclear@0 155 *this = o;
nuclear@0 156 }
nuclear@0 157
nuclear@0 158 //! Assignment operator. Copy the index array
nuclear@0 159 aiFace& operator = ( const aiFace& o) {
nuclear@0 160 if (&o == this) {
nuclear@0 161 return *this;
nuclear@0 162 }
nuclear@0 163
nuclear@0 164 delete[] mIndices;
nuclear@0 165 mNumIndices = o.mNumIndices;
nuclear@0 166 if (mNumIndices) {
nuclear@0 167 mIndices = new unsigned int[mNumIndices];
nuclear@0 168 ::memcpy( mIndices, o.mIndices, mNumIndices * sizeof( unsigned int));
nuclear@0 169 } else {
nuclear@0 170 mIndices = 0;
nuclear@0 171 }
nuclear@0 172
nuclear@0 173 return *this;
nuclear@0 174 }
nuclear@0 175
nuclear@0 176 //! Comparison operator. Checks whether the index array
nuclear@0 177 //! of two faces is identical
nuclear@0 178 bool operator== (const aiFace& o) const {
nuclear@0 179 if (mIndices == o.mIndices) {
nuclear@0 180 return true;
nuclear@0 181 }
nuclear@0 182
nuclear@0 183 if (0 != mIndices && mNumIndices != o.mNumIndices) {
nuclear@0 184 return false;
nuclear@0 185 }
nuclear@0 186
nuclear@0 187 if (0 == mIndices) {
nuclear@0 188 return false;
nuclear@0 189 }
nuclear@0 190
nuclear@0 191 for (unsigned int i = 0; i < this->mNumIndices; ++i) {
nuclear@0 192 if (mIndices[i] != o.mIndices[i]) {
nuclear@0 193 return false;
nuclear@0 194 }
nuclear@0 195 }
nuclear@0 196
nuclear@0 197 return true;
nuclear@0 198 }
nuclear@0 199
nuclear@0 200 //! Inverse comparison operator. Checks whether the index
nuclear@0 201 //! array of two faces is NOT identical
nuclear@0 202 bool operator != (const aiFace& o) const {
nuclear@0 203 return !(*this == o);
nuclear@0 204 }
nuclear@0 205 #endif // __cplusplus
nuclear@0 206 }; // struct aiFace
nuclear@0 207
nuclear@0 208
nuclear@0 209 // ---------------------------------------------------------------------------
nuclear@0 210 /** @brief A single influence of a bone on a vertex.
nuclear@0 211 */
nuclear@0 212 struct aiVertexWeight {
nuclear@0 213 //! Index of the vertex which is influenced by the bone.
nuclear@0 214 unsigned int mVertexId;
nuclear@0 215
nuclear@0 216 //! The strength of the influence in the range (0...1).
nuclear@0 217 //! The influence from all bones at one vertex amounts to 1.
nuclear@0 218 float mWeight;
nuclear@0 219
nuclear@0 220 #ifdef __cplusplus
nuclear@0 221
nuclear@0 222 //! Default constructor
nuclear@0 223 aiVertexWeight() AI_NO_EXCEPT
nuclear@0 224 : mVertexId(0)
nuclear@0 225 , mWeight(0.0f) {
nuclear@0 226 // empty
nuclear@0 227 }
nuclear@0 228
nuclear@0 229 //! Initialization from a given index and vertex weight factor
nuclear@0 230 //! \param pID ID
nuclear@0 231 //! \param pWeight Vertex weight factor
nuclear@0 232 aiVertexWeight( unsigned int pID, float pWeight )
nuclear@0 233 : mVertexId( pID )
nuclear@0 234 , mWeight( pWeight ) {
nuclear@0 235 // empty
nuclear@0 236 }
nuclear@0 237
nuclear@0 238 bool operator == ( const aiVertexWeight &rhs ) const {
nuclear@0 239 return ( mVertexId == rhs.mVertexId && mWeight == rhs.mWeight );
nuclear@0 240 }
nuclear@0 241
nuclear@0 242 bool operator != ( const aiVertexWeight &rhs ) const {
nuclear@0 243 return ( *this == rhs );
nuclear@0 244 }
nuclear@0 245
nuclear@0 246 #endif // __cplusplus
nuclear@0 247 };
nuclear@0 248
nuclear@0 249
nuclear@0 250 // ---------------------------------------------------------------------------
nuclear@0 251 /** @brief A single bone of a mesh.
nuclear@0 252 *
nuclear@0 253 * A bone has a name by which it can be found in the frame hierarchy and by
nuclear@0 254 * which it can be addressed by animations. In addition it has a number of
nuclear@0 255 * influences on vertices, and a matrix relating the mesh position to the
nuclear@0 256 * position of the bone at the time of binding.
nuclear@0 257 */
nuclear@0 258 struct aiBone {
nuclear@0 259 //! The name of the bone.
nuclear@0 260 C_STRUCT aiString mName;
nuclear@0 261
nuclear@0 262 //! The number of vertices affected by this bone.
nuclear@0 263 //! The maximum value for this member is #AI_MAX_BONE_WEIGHTS.
nuclear@0 264 unsigned int mNumWeights;
nuclear@0 265
nuclear@0 266 //! The influence weights of this bone, by vertex index.
nuclear@0 267 C_STRUCT aiVertexWeight* mWeights;
nuclear@0 268
nuclear@0 269 /** Matrix that transforms from bone space to mesh space in bind pose.
nuclear@0 270 *
nuclear@0 271 * This matrix describes the position of the mesh
nuclear@0 272 * in the local space of this bone when the skeleton was bound.
nuclear@0 273 * Thus it can be used directly to determine a desired vertex position,
nuclear@0 274 * given the world-space transform of the bone when animated,
nuclear@0 275 * and the position of the vertex in mesh space.
nuclear@0 276 *
nuclear@0 277 * It is sometimes called an inverse-bind matrix,
nuclear@0 278 * or inverse bind pose matrix.
nuclear@0 279 */
nuclear@0 280 C_STRUCT aiMatrix4x4 mOffsetMatrix;
nuclear@0 281
nuclear@0 282 #ifdef __cplusplus
nuclear@0 283
nuclear@0 284 //! Default constructor
nuclear@0 285 aiBone() AI_NO_EXCEPT
nuclear@0 286 : mName()
nuclear@0 287 , mNumWeights( 0 )
nuclear@0 288 , mWeights( 0 )
nuclear@0 289 , mOffsetMatrix() {
nuclear@0 290 // empty
nuclear@0 291 }
nuclear@0 292
nuclear@0 293 //! Copy constructor
nuclear@0 294 aiBone(const aiBone& other)
nuclear@0 295 : mName( other.mName )
nuclear@0 296 , mNumWeights( other.mNumWeights )
nuclear@0 297 , mWeights(0)
nuclear@0 298 , mOffsetMatrix( other.mOffsetMatrix ) {
nuclear@0 299 if (other.mWeights && other.mNumWeights) {
nuclear@0 300 mWeights = new aiVertexWeight[mNumWeights];
nuclear@0 301 ::memcpy(mWeights,other.mWeights,mNumWeights * sizeof(aiVertexWeight));
nuclear@0 302 }
nuclear@0 303 }
nuclear@0 304
nuclear@0 305
nuclear@0 306 //! Assignment operator
nuclear@0 307 aiBone &operator=(const aiBone& other) {
nuclear@0 308 if (this == &other) {
nuclear@0 309 return *this;
nuclear@0 310 }
nuclear@0 311
nuclear@0 312 mName = other.mName;
nuclear@0 313 mNumWeights = other.mNumWeights;
nuclear@0 314 mOffsetMatrix = other.mOffsetMatrix;
nuclear@0 315
nuclear@0 316 if (other.mWeights && other.mNumWeights)
nuclear@0 317 {
nuclear@0 318 if (mWeights) {
nuclear@0 319 delete[] mWeights;
nuclear@0 320 }
nuclear@0 321
nuclear@0 322 mWeights = new aiVertexWeight[mNumWeights];
nuclear@0 323 ::memcpy(mWeights,other.mWeights,mNumWeights * sizeof(aiVertexWeight));
nuclear@0 324 }
nuclear@0 325
nuclear@0 326 return *this;
nuclear@0 327 }
nuclear@0 328
nuclear@0 329 bool operator == ( const aiBone &rhs ) const {
nuclear@0 330 if ( mName != rhs.mName || mNumWeights != rhs.mNumWeights ) {
nuclear@0 331 return false;
nuclear@0 332 }
nuclear@0 333
nuclear@0 334 for ( size_t i = 0; i < mNumWeights; ++i ) {
nuclear@0 335 if ( mWeights[ i ] != rhs.mWeights[ i ] ) {
nuclear@0 336 return false;
nuclear@0 337 }
nuclear@0 338 }
nuclear@0 339
nuclear@0 340 return true;
nuclear@0 341 }
nuclear@0 342 //! Destructor - deletes the array of vertex weights
nuclear@0 343 ~aiBone() {
nuclear@0 344 delete [] mWeights;
nuclear@0 345 }
nuclear@0 346 #endif // __cplusplus
nuclear@0 347 };
nuclear@0 348
nuclear@0 349
nuclear@0 350 // ---------------------------------------------------------------------------
nuclear@0 351 /** @brief Enumerates the types of geometric primitives supported by Assimp.
nuclear@0 352 *
nuclear@0 353 * @see aiFace Face data structure
nuclear@0 354 * @see aiProcess_SortByPType Per-primitive sorting of meshes
nuclear@0 355 * @see aiProcess_Triangulate Automatic triangulation
nuclear@0 356 * @see AI_CONFIG_PP_SBP_REMOVE Removal of specific primitive types.
nuclear@0 357 */
nuclear@0 358 enum aiPrimitiveType
nuclear@0 359 {
nuclear@0 360 /** A point primitive.
nuclear@0 361 *
nuclear@0 362 * This is just a single vertex in the virtual world,
nuclear@0 363 * #aiFace contains just one index for such a primitive.
nuclear@0 364 */
nuclear@0 365 aiPrimitiveType_POINT = 0x1,
nuclear@0 366
nuclear@0 367 /** A line primitive.
nuclear@0 368 *
nuclear@0 369 * This is a line defined through a start and an end position.
nuclear@0 370 * #aiFace contains exactly two indices for such a primitive.
nuclear@0 371 */
nuclear@0 372 aiPrimitiveType_LINE = 0x2,
nuclear@0 373
nuclear@0 374 /** A triangular primitive.
nuclear@0 375 *
nuclear@0 376 * A triangle consists of three indices.
nuclear@0 377 */
nuclear@0 378 aiPrimitiveType_TRIANGLE = 0x4,
nuclear@0 379
nuclear@0 380 /** A higher-level polygon with more than 3 edges.
nuclear@0 381 *
nuclear@0 382 * A triangle is a polygon, but polygon in this context means
nuclear@0 383 * "all polygons that are not triangles". The "Triangulate"-Step
nuclear@0 384 * is provided for your convenience, it splits all polygons in
nuclear@0 385 * triangles (which are much easier to handle).
nuclear@0 386 */
nuclear@0 387 aiPrimitiveType_POLYGON = 0x8,
nuclear@0 388
nuclear@0 389
nuclear@0 390 /** This value is not used. It is just here to force the
nuclear@0 391 * compiler to map this enum to a 32 Bit integer.
nuclear@0 392 */
nuclear@0 393 #ifndef SWIG
nuclear@0 394 _aiPrimitiveType_Force32Bit = INT_MAX
nuclear@0 395 #endif
nuclear@0 396 }; //! enum aiPrimitiveType
nuclear@0 397
nuclear@0 398 // Get the #aiPrimitiveType flag for a specific number of face indices
nuclear@0 399 #define AI_PRIMITIVE_TYPE_FOR_N_INDICES(n) \
nuclear@0 400 ((n) > 3 ? aiPrimitiveType_POLYGON : (aiPrimitiveType)(1u << ((n)-1)))
nuclear@0 401
nuclear@0 402
nuclear@0 403
nuclear@0 404 // ---------------------------------------------------------------------------
nuclear@0 405 /** @brief An AnimMesh is an attachment to an #aiMesh stores per-vertex
nuclear@0 406 * animations for a particular frame.
nuclear@0 407 *
nuclear@0 408 * You may think of an #aiAnimMesh as a `patch` for the host mesh, which
nuclear@0 409 * replaces only certain vertex data streams at a particular time.
nuclear@0 410 * Each mesh stores n attached attached meshes (#aiMesh::mAnimMeshes).
nuclear@0 411 * The actual relationship between the time line and anim meshes is
nuclear@0 412 * established by #aiMeshAnim, which references singular mesh attachments
nuclear@0 413 * by their ID and binds them to a time offset.
nuclear@0 414 */
nuclear@0 415 struct aiAnimMesh
nuclear@0 416 {
nuclear@0 417 /**Anim Mesh name */
nuclear@0 418 C_STRUCT aiString mName;
nuclear@0 419
nuclear@0 420 /** Replacement for aiMesh::mVertices. If this array is non-NULL,
nuclear@0 421 * it *must* contain mNumVertices entries. The corresponding
nuclear@0 422 * array in the host mesh must be non-NULL as well - animation
nuclear@0 423 * meshes may neither add or nor remove vertex components (if
nuclear@0 424 * a replacement array is NULL and the corresponding source
nuclear@0 425 * array is not, the source data is taken instead)*/
nuclear@0 426 C_STRUCT aiVector3D* mVertices;
nuclear@0 427
nuclear@0 428 /** Replacement for aiMesh::mNormals. */
nuclear@0 429 C_STRUCT aiVector3D* mNormals;
nuclear@0 430
nuclear@0 431 /** Replacement for aiMesh::mTangents. */
nuclear@0 432 C_STRUCT aiVector3D* mTangents;
nuclear@0 433
nuclear@0 434 /** Replacement for aiMesh::mBitangents. */
nuclear@0 435 C_STRUCT aiVector3D* mBitangents;
nuclear@0 436
nuclear@0 437 /** Replacement for aiMesh::mColors */
nuclear@0 438 C_STRUCT aiColor4D* mColors[AI_MAX_NUMBER_OF_COLOR_SETS];
nuclear@0 439
nuclear@0 440 /** Replacement for aiMesh::mTextureCoords */
nuclear@0 441 C_STRUCT aiVector3D* mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS];
nuclear@0 442
nuclear@0 443 /** The number of vertices in the aiAnimMesh, and thus the length of all
nuclear@0 444 * the member arrays.
nuclear@0 445 *
nuclear@0 446 * This has always the same value as the mNumVertices property in the
nuclear@0 447 * corresponding aiMesh. It is duplicated here merely to make the length
nuclear@0 448 * of the member arrays accessible even if the aiMesh is not known, e.g.
nuclear@0 449 * from language bindings.
nuclear@0 450 */
nuclear@0 451 unsigned int mNumVertices;
nuclear@0 452
nuclear@0 453 /**
nuclear@0 454 * Weight of the AnimMesh.
nuclear@0 455 */
nuclear@0 456 float mWeight;
nuclear@0 457
nuclear@0 458 #ifdef __cplusplus
nuclear@0 459
nuclear@0 460 aiAnimMesh() AI_NO_EXCEPT
nuclear@0 461 : mVertices( 0 )
nuclear@0 462 , mNormals(0)
nuclear@0 463 , mTangents(0)
nuclear@0 464 , mBitangents(0)
nuclear@0 465 , mColors()
nuclear@0 466 , mTextureCoords()
nuclear@0 467 , mNumVertices( 0 )
nuclear@0 468 , mWeight( 0.0f )
nuclear@0 469 {
nuclear@0 470 // fixme consider moving this to the ctor initializer list as well
nuclear@0 471 for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++){
nuclear@0 472 mTextureCoords[a] = NULL;
nuclear@0 473 }
nuclear@0 474 for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
nuclear@0 475 mColors[a] = NULL;
nuclear@0 476 }
nuclear@0 477 }
nuclear@0 478
nuclear@0 479 ~aiAnimMesh()
nuclear@0 480 {
nuclear@0 481 delete [] mVertices;
nuclear@0 482 delete [] mNormals;
nuclear@0 483 delete [] mTangents;
nuclear@0 484 delete [] mBitangents;
nuclear@0 485 for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) {
nuclear@0 486 delete [] mTextureCoords[a];
nuclear@0 487 }
nuclear@0 488 for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
nuclear@0 489 delete [] mColors[a];
nuclear@0 490 }
nuclear@0 491 }
nuclear@0 492
nuclear@0 493 /** Check whether the anim mesh overrides the vertex positions
nuclear@0 494 * of its host mesh*/
nuclear@0 495 bool HasPositions() const {
nuclear@0 496 return mVertices != NULL;
nuclear@0 497 }
nuclear@0 498
nuclear@0 499 /** Check whether the anim mesh overrides the vertex normals
nuclear@0 500 * of its host mesh*/
nuclear@0 501 bool HasNormals() const {
nuclear@0 502 return mNormals != NULL;
nuclear@0 503 }
nuclear@0 504
nuclear@0 505 /** Check whether the anim mesh overrides the vertex tangents
nuclear@0 506 * and bitangents of its host mesh. As for aiMesh,
nuclear@0 507 * tangents and bitangents always go together. */
nuclear@0 508 bool HasTangentsAndBitangents() const {
nuclear@0 509 return mTangents != NULL;
nuclear@0 510 }
nuclear@0 511
nuclear@0 512 /** Check whether the anim mesh overrides a particular
nuclear@0 513 * set of vertex colors on his host mesh.
nuclear@0 514 * @param pIndex 0<index<AI_MAX_NUMBER_OF_COLOR_SETS */
nuclear@0 515 bool HasVertexColors( unsigned int pIndex) const {
nuclear@0 516 return pIndex >= AI_MAX_NUMBER_OF_COLOR_SETS ? false : mColors[pIndex] != NULL;
nuclear@0 517 }
nuclear@0 518
nuclear@0 519 /** Check whether the anim mesh overrides a particular
nuclear@0 520 * set of texture coordinates on his host mesh.
nuclear@0 521 * @param pIndex 0<index<AI_MAX_NUMBER_OF_TEXTURECOORDS */
nuclear@0 522 bool HasTextureCoords( unsigned int pIndex) const {
nuclear@0 523 return pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS ? false : mTextureCoords[pIndex] != NULL;
nuclear@0 524 }
nuclear@0 525
nuclear@0 526 #endif
nuclear@0 527 };
nuclear@0 528
nuclear@0 529 // ---------------------------------------------------------------------------
nuclear@0 530 /** @brief Enumerates the methods of mesh morphing supported by Assimp.
nuclear@0 531 */
nuclear@0 532 enum aiMorphingMethod
nuclear@0 533 {
nuclear@0 534 /** Interpolation between morph targets */
nuclear@0 535 aiMorphingMethod_VERTEX_BLEND = 0x1,
nuclear@0 536
nuclear@0 537 /** Normalized morphing between morph targets */
nuclear@0 538 aiMorphingMethod_MORPH_NORMALIZED = 0x2,
nuclear@0 539
nuclear@0 540 /** Relative morphing between morph targets */
nuclear@0 541 aiMorphingMethod_MORPH_RELATIVE = 0x3,
nuclear@0 542
nuclear@0 543 /** This value is not used. It is just here to force the
nuclear@0 544 * compiler to map this enum to a 32 Bit integer.
nuclear@0 545 */
nuclear@0 546 #ifndef SWIG
nuclear@0 547 _aiMorphingMethod_Force32Bit = INT_MAX
nuclear@0 548 #endif
nuclear@0 549 }; //! enum aiMorphingMethod
nuclear@0 550
nuclear@0 551 // ---------------------------------------------------------------------------
nuclear@0 552 /** @brief A mesh represents a geometry or model with a single material.
nuclear@0 553 *
nuclear@0 554 * It usually consists of a number of vertices and a series of primitives/faces
nuclear@0 555 * referencing the vertices. In addition there might be a series of bones, each
nuclear@0 556 * of them addressing a number of vertices with a certain weight. Vertex data
nuclear@0 557 * is presented in channels with each channel containing a single per-vertex
nuclear@0 558 * information such as a set of texture coords or a normal vector.
nuclear@0 559 * If a data pointer is non-null, the corresponding data stream is present.
nuclear@0 560 * From C++-programs you can also use the comfort functions Has*() to
nuclear@0 561 * test for the presence of various data streams.
nuclear@0 562 *
nuclear@0 563 * A Mesh uses only a single material which is referenced by a material ID.
nuclear@0 564 * @note The mPositions member is usually not optional. However, vertex positions
nuclear@0 565 * *could* be missing if the #AI_SCENE_FLAGS_INCOMPLETE flag is set in
nuclear@0 566 * @code
nuclear@0 567 * aiScene::mFlags
nuclear@0 568 * @endcode
nuclear@0 569 */
nuclear@0 570 struct aiMesh
nuclear@0 571 {
nuclear@0 572 /** Bitwise combination of the members of the #aiPrimitiveType enum.
nuclear@0 573 * This specifies which types of primitives are present in the mesh.
nuclear@0 574 * The "SortByPrimitiveType"-Step can be used to make sure the
nuclear@0 575 * output meshes consist of one primitive type each.
nuclear@0 576 */
nuclear@0 577 unsigned int mPrimitiveTypes;
nuclear@0 578
nuclear@0 579 /** The number of vertices in this mesh.
nuclear@0 580 * This is also the size of all of the per-vertex data arrays.
nuclear@0 581 * The maximum value for this member is #AI_MAX_VERTICES.
nuclear@0 582 */
nuclear@0 583 unsigned int mNumVertices;
nuclear@0 584
nuclear@0 585 /** The number of primitives (triangles, polygons, lines) in this mesh.
nuclear@0 586 * This is also the size of the mFaces array.
nuclear@0 587 * The maximum value for this member is #AI_MAX_FACES.
nuclear@0 588 */
nuclear@0 589 unsigned int mNumFaces;
nuclear@0 590
nuclear@0 591 /** Vertex positions.
nuclear@0 592 * This array is always present in a mesh. The array is
nuclear@0 593 * mNumVertices in size.
nuclear@0 594 */
nuclear@0 595 C_STRUCT aiVector3D* mVertices;
nuclear@0 596
nuclear@0 597 /** Vertex normals.
nuclear@0 598 * The array contains normalized vectors, NULL if not present.
nuclear@0 599 * The array is mNumVertices in size. Normals are undefined for
nuclear@0 600 * point and line primitives. A mesh consisting of points and
nuclear@0 601 * lines only may not have normal vectors. Meshes with mixed
nuclear@0 602 * primitive types (i.e. lines and triangles) may have normals,
nuclear@0 603 * but the normals for vertices that are only referenced by
nuclear@0 604 * point or line primitives are undefined and set to QNaN (WARN:
nuclear@0 605 * qNaN compares to inequal to *everything*, even to qNaN itself.
nuclear@0 606 * Using code like this to check whether a field is qnan is:
nuclear@0 607 * @code
nuclear@0 608 * #define IS_QNAN(f) (f != f)
nuclear@0 609 * @endcode
nuclear@0 610 * still dangerous because even 1.f == 1.f could evaluate to false! (
nuclear@0 611 * remember the subtleties of IEEE754 artithmetics). Use stuff like
nuclear@0 612 * @c fpclassify instead.
nuclear@0 613 * @note Normal vectors computed by Assimp are always unit-length.
nuclear@0 614 * However, this needn't apply for normals that have been taken
nuclear@0 615 * directly from the model file.
nuclear@0 616 */
nuclear@0 617 C_STRUCT aiVector3D* mNormals;
nuclear@0 618
nuclear@0 619 /** Vertex tangents.
nuclear@0 620 * The tangent of a vertex points in the direction of the positive
nuclear@0 621 * X texture axis. The array contains normalized vectors, NULL if
nuclear@0 622 * not present. The array is mNumVertices in size. A mesh consisting
nuclear@0 623 * of points and lines only may not have normal vectors. Meshes with
nuclear@0 624 * mixed primitive types (i.e. lines and triangles) may have
nuclear@0 625 * normals, but the normals for vertices that are only referenced by
nuclear@0 626 * point or line primitives are undefined and set to qNaN. See
nuclear@0 627 * the #mNormals member for a detailed discussion of qNaNs.
nuclear@0 628 * @note If the mesh contains tangents, it automatically also
nuclear@0 629 * contains bitangents.
nuclear@0 630 */
nuclear@0 631 C_STRUCT aiVector3D* mTangents;
nuclear@0 632
nuclear@0 633 /** Vertex bitangents.
nuclear@0 634 * The bitangent of a vertex points in the direction of the positive
nuclear@0 635 * Y texture axis. The array contains normalized vectors, NULL if not
nuclear@0 636 * present. The array is mNumVertices in size.
nuclear@0 637 * @note If the mesh contains tangents, it automatically also contains
nuclear@0 638 * bitangents.
nuclear@0 639 */
nuclear@0 640 C_STRUCT aiVector3D* mBitangents;
nuclear@0 641
nuclear@0 642 /** Vertex color sets.
nuclear@0 643 * A mesh may contain 0 to #AI_MAX_NUMBER_OF_COLOR_SETS vertex
nuclear@0 644 * colors per vertex. NULL if not present. Each array is
nuclear@0 645 * mNumVertices in size if present.
nuclear@0 646 */
nuclear@0 647 C_STRUCT aiColor4D* mColors[AI_MAX_NUMBER_OF_COLOR_SETS];
nuclear@0 648
nuclear@0 649 /** Vertex texture coords, also known as UV channels.
nuclear@0 650 * A mesh may contain 0 to AI_MAX_NUMBER_OF_TEXTURECOORDS per
nuclear@0 651 * vertex. NULL if not present. The array is mNumVertices in size.
nuclear@0 652 */
nuclear@0 653 C_STRUCT aiVector3D* mTextureCoords[AI_MAX_NUMBER_OF_TEXTURECOORDS];
nuclear@0 654
nuclear@0 655 /** Specifies the number of components for a given UV channel.
nuclear@0 656 * Up to three channels are supported (UVW, for accessing volume
nuclear@0 657 * or cube maps). If the value is 2 for a given channel n, the
nuclear@0 658 * component p.z of mTextureCoords[n][p] is set to 0.0f.
nuclear@0 659 * If the value is 1 for a given channel, p.y is set to 0.0f, too.
nuclear@0 660 * @note 4D coords are not supported
nuclear@0 661 */
nuclear@0 662 unsigned int mNumUVComponents[AI_MAX_NUMBER_OF_TEXTURECOORDS];
nuclear@0 663
nuclear@0 664 /** The faces the mesh is constructed from.
nuclear@0 665 * Each face refers to a number of vertices by their indices.
nuclear@0 666 * This array is always present in a mesh, its size is given
nuclear@0 667 * in mNumFaces. If the #AI_SCENE_FLAGS_NON_VERBOSE_FORMAT
nuclear@0 668 * is NOT set each face references an unique set of vertices.
nuclear@0 669 */
nuclear@0 670 C_STRUCT aiFace* mFaces;
nuclear@0 671
nuclear@0 672 /** The number of bones this mesh contains.
nuclear@0 673 * Can be 0, in which case the mBones array is NULL.
nuclear@0 674 */
nuclear@0 675 unsigned int mNumBones;
nuclear@0 676
nuclear@0 677 /** The bones of this mesh.
nuclear@0 678 * A bone consists of a name by which it can be found in the
nuclear@0 679 * frame hierarchy and a set of vertex weights.
nuclear@0 680 */
nuclear@0 681 C_STRUCT aiBone** mBones;
nuclear@0 682
nuclear@0 683 /** The material used by this mesh.
nuclear@0 684 * A mesh uses only a single material. If an imported model uses
nuclear@0 685 * multiple materials, the import splits up the mesh. Use this value
nuclear@0 686 * as index into the scene's material list.
nuclear@0 687 */
nuclear@0 688 unsigned int mMaterialIndex;
nuclear@0 689
nuclear@0 690 /** Name of the mesh. Meshes can be named, but this is not a
nuclear@0 691 * requirement and leaving this field empty is totally fine.
nuclear@0 692 * There are mainly three uses for mesh names:
nuclear@0 693 * - some formats name nodes and meshes independently.
nuclear@0 694 * - importers tend to split meshes up to meet the
nuclear@0 695 * one-material-per-mesh requirement. Assigning
nuclear@0 696 * the same (dummy) name to each of the result meshes
nuclear@0 697 * aids the caller at recovering the original mesh
nuclear@0 698 * partitioning.
nuclear@0 699 * - Vertex animations refer to meshes by their names.
nuclear@0 700 **/
nuclear@0 701 C_STRUCT aiString mName;
nuclear@0 702
nuclear@0 703
nuclear@0 704 /** The number of attachment meshes. Note! Currently only works with Collada loader. */
nuclear@0 705 unsigned int mNumAnimMeshes;
nuclear@0 706
nuclear@0 707 /** Attachment meshes for this mesh, for vertex-based animation.
nuclear@0 708 * Attachment meshes carry replacement data for some of the
nuclear@0 709 * mesh'es vertex components (usually positions, normals).
nuclear@0 710 * Note! Currently only works with Collada loader.*/
nuclear@0 711 C_STRUCT aiAnimMesh** mAnimMeshes;
nuclear@0 712
nuclear@0 713 /**
nuclear@0 714 * Method of morphing when animeshes are specified.
nuclear@0 715 */
nuclear@0 716 unsigned int mMethod;
nuclear@0 717
nuclear@0 718 #ifdef __cplusplus
nuclear@0 719
nuclear@0 720 //! Default constructor. Initializes all members to 0
nuclear@0 721 aiMesh() AI_NO_EXCEPT
nuclear@0 722 : mPrimitiveTypes( 0 )
nuclear@0 723 , mNumVertices( 0 )
nuclear@0 724 , mNumFaces( 0 )
nuclear@0 725 , mVertices( 0 )
nuclear@0 726 , mNormals(0)
nuclear@0 727 , mTangents(0)
nuclear@0 728 , mBitangents(0)
nuclear@0 729 , mColors()
nuclear@0 730 , mTextureCoords()
nuclear@0 731 , mNumUVComponents()
nuclear@0 732 , mFaces(0)
nuclear@0 733 , mNumBones( 0 )
nuclear@0 734 , mBones(0)
nuclear@0 735 , mMaterialIndex( 0 )
nuclear@0 736 , mNumAnimMeshes( 0 )
nuclear@0 737 , mAnimMeshes(0)
nuclear@0 738 , mMethod( 0 ) {
nuclear@0 739 for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; ++a ) {
nuclear@0 740 mNumUVComponents[a] = 0;
nuclear@0 741 mTextureCoords[a] = 0;
nuclear@0 742 }
nuclear@0 743
nuclear@0 744 for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; ++a) {
nuclear@0 745 mColors[a] = 0;
nuclear@0 746 }
nuclear@0 747 }
nuclear@0 748
nuclear@0 749 //! Deletes all storage allocated for the mesh
nuclear@0 750 ~aiMesh() {
nuclear@0 751 delete [] mVertices;
nuclear@0 752 delete [] mNormals;
nuclear@0 753 delete [] mTangents;
nuclear@0 754 delete [] mBitangents;
nuclear@0 755 for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS; a++) {
nuclear@0 756 delete [] mTextureCoords[a];
nuclear@0 757 }
nuclear@0 758 for( unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS; a++) {
nuclear@0 759 delete [] mColors[a];
nuclear@0 760 }
nuclear@0 761
nuclear@0 762 // DO NOT REMOVE THIS ADDITIONAL CHECK
nuclear@0 763 if (mNumBones && mBones) {
nuclear@0 764 for( unsigned int a = 0; a < mNumBones; a++) {
nuclear@0 765 delete mBones[a];
nuclear@0 766 }
nuclear@0 767 delete [] mBones;
nuclear@0 768 }
nuclear@0 769
nuclear@0 770 if (mNumAnimMeshes && mAnimMeshes) {
nuclear@0 771 for( unsigned int a = 0; a < mNumAnimMeshes; a++) {
nuclear@0 772 delete mAnimMeshes[a];
nuclear@0 773 }
nuclear@0 774 delete [] mAnimMeshes;
nuclear@0 775 }
nuclear@0 776
nuclear@0 777 delete [] mFaces;
nuclear@0 778 }
nuclear@0 779
nuclear@0 780 //! Check whether the mesh contains positions. Provided no special
nuclear@0 781 //! scene flags are set, this will always be true
nuclear@0 782 bool HasPositions() const
nuclear@0 783 { return mVertices != 0 && mNumVertices > 0; }
nuclear@0 784
nuclear@0 785 //! Check whether the mesh contains faces. If no special scene flags
nuclear@0 786 //! are set this should always return true
nuclear@0 787 bool HasFaces() const
nuclear@0 788 { return mFaces != 0 && mNumFaces > 0; }
nuclear@0 789
nuclear@0 790 //! Check whether the mesh contains normal vectors
nuclear@0 791 bool HasNormals() const
nuclear@0 792 { return mNormals != 0 && mNumVertices > 0; }
nuclear@0 793
nuclear@0 794 //! Check whether the mesh contains tangent and bitangent vectors
nuclear@0 795 //! It is not possible that it contains tangents and no bitangents
nuclear@0 796 //! (or the other way round). The existence of one of them
nuclear@0 797 //! implies that the second is there, too.
nuclear@0 798 bool HasTangentsAndBitangents() const
nuclear@0 799 { return mTangents != 0 && mBitangents != 0 && mNumVertices > 0; }
nuclear@0 800
nuclear@0 801 //! Check whether the mesh contains a vertex color set
nuclear@0 802 //! \param pIndex Index of the vertex color set
nuclear@0 803 bool HasVertexColors( unsigned int pIndex) const {
nuclear@0 804 if (pIndex >= AI_MAX_NUMBER_OF_COLOR_SETS) {
nuclear@0 805 return false;
nuclear@0 806 } else {
nuclear@0 807 return mColors[pIndex] != 0 && mNumVertices > 0;
nuclear@0 808 }
nuclear@0 809 }
nuclear@0 810
nuclear@0 811 //! Check whether the mesh contains a texture coordinate set
nuclear@0 812 //! \param pIndex Index of the texture coordinates set
nuclear@0 813 bool HasTextureCoords( unsigned int pIndex) const {
nuclear@0 814 if (pIndex >= AI_MAX_NUMBER_OF_TEXTURECOORDS) {
nuclear@0 815 return false;
nuclear@0 816 } else {
nuclear@0 817 return mTextureCoords[pIndex] != 0 && mNumVertices > 0;
nuclear@0 818 }
nuclear@0 819 }
nuclear@0 820
nuclear@0 821 //! Get the number of UV channels the mesh contains
nuclear@0 822 unsigned int GetNumUVChannels() const {
nuclear@0 823 unsigned int n( 0 );
nuclear@0 824 while (n < AI_MAX_NUMBER_OF_TEXTURECOORDS && mTextureCoords[n]) {
nuclear@0 825 ++n;
nuclear@0 826 }
nuclear@0 827
nuclear@0 828 return n;
nuclear@0 829 }
nuclear@0 830
nuclear@0 831 //! Get the number of vertex color channels the mesh contains
nuclear@0 832 unsigned int GetNumColorChannels() const {
nuclear@0 833 unsigned int n(0);
nuclear@0 834 while (n < AI_MAX_NUMBER_OF_COLOR_SETS && mColors[n]) {
nuclear@0 835 ++n;
nuclear@0 836 }
nuclear@0 837 return n;
nuclear@0 838 }
nuclear@0 839
nuclear@0 840 //! Check whether the mesh contains bones
nuclear@0 841 bool HasBones() const {
nuclear@0 842 return mBones != 0 && mNumBones > 0;
nuclear@0 843 }
nuclear@0 844
nuclear@0 845 #endif // __cplusplus
nuclear@0 846 };
nuclear@0 847
nuclear@0 848 #ifdef __cplusplus
nuclear@0 849 }
nuclear@0 850 #endif //! extern "C"
nuclear@0 851 #endif // AI_MESH_H_INC
nuclear@0 852