miniassimp

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