FBXMeshGeometry.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2016, assimp team
  5. All rights reserved.
  6. Redistribution and use of this software in source and binary forms,
  7. with or without modification, are permitted provided that the
  8. following conditions are met:
  9. * Redistributions of source code must retain the above
  10. copyright notice, this list of conditions and the
  11. following disclaimer.
  12. * Redistributions in binary form must reproduce the above
  13. copyright notice, this list of conditions and the
  14. following disclaimer in the documentation and/or other
  15. materials provided with the distribution.
  16. * Neither the name of the assimp team, nor the names of its
  17. contributors may be used to endorse or promote products
  18. derived from this software without specific prior
  19. written permission of the assimp team.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. ----------------------------------------------------------------------
  32. */
  33. /** @file FBXImporter.h
  34. * @brief Declaration of the FBX main importer class
  35. */
  36. #ifndef INCLUDED_AI_FBX_MESHGEOMETRY_H
  37. #define INCLUDED_AI_FBX_MESHGEOMETRY_H
  38. #include "FBXParser.h"
  39. #include "FBXDocument.h"
  40. namespace Assimp {
  41. namespace FBX {
  42. /**
  43. * DOM base class for all kinds of FBX geometry
  44. */
  45. class Geometry : public Object
  46. {
  47. public:
  48. Geometry( uint64_t id, const Element& element, const std::string& name, const Document& doc );
  49. virtual ~Geometry();
  50. /** Get the Skin attached to this geometry or NULL */
  51. const Skin* DeformerSkin() const;
  52. private:
  53. const Skin* skin;
  54. };
  55. typedef std::vector<int> MatIndexArray;
  56. /**
  57. * DOM class for FBX geometry of type "Mesh"
  58. */
  59. class MeshGeometry : public Geometry
  60. {
  61. public:
  62. /** The class constructor */
  63. MeshGeometry( uint64_t id, const Element& element, const std::string& name, const Document& doc );
  64. /** The class destructor */
  65. virtual ~MeshGeometry();
  66. /** Get a list of all vertex points, non-unique*/
  67. const std::vector<aiVector3D>& GetVertices() const;
  68. /** Get a list of all vertex normals or an empty array if
  69. * no normals are specified. */
  70. const std::vector<aiVector3D>& GetNormals() const;
  71. /** Get a list of all vertex tangents or an empty array
  72. * if no tangents are specified */
  73. const std::vector<aiVector3D>& GetTangents() const;
  74. /** Get a list of all vertex binormals or an empty array
  75. * if no binormals are specified */
  76. const std::vector<aiVector3D>& GetBinormals() const;
  77. /** Return list of faces - each entry denotes a face and specifies
  78. * how many vertices it has. Vertices are taken from the
  79. * vertex data arrays in sequential order. */
  80. const std::vector<unsigned int>& GetFaceIndexCounts() const;
  81. /** Get a UV coordinate slot, returns an empty array if
  82. * the requested slot does not exist. */
  83. const std::vector<aiVector2D>& GetTextureCoords( unsigned int index ) const;
  84. /** Get a UV coordinate slot, returns an empty array if
  85. * the requested slot does not exist. */
  86. std::string GetTextureCoordChannelName( unsigned int index ) const;
  87. /** Get a vertex color coordinate slot, returns an empty array if
  88. * the requested slot does not exist. */
  89. const std::vector<aiColor4D>& GetVertexColors( unsigned int index ) const;
  90. /** Get per-face-vertex material assignments */
  91. const MatIndexArray& GetMaterialIndices() const;
  92. /** Convert from a fbx file vertex index (for example from a #Cluster weight) or NULL
  93. * if the vertex index is not valid. */
  94. const unsigned int* ToOutputVertexIndex( unsigned int in_index, unsigned int& count ) const;
  95. /** Determine the face to which a particular output vertex index belongs.
  96. * This mapping is always unique. */
  97. unsigned int FaceForVertexIndex( unsigned int in_index ) const;
  98. private:
  99. void ReadLayer( const Scope& layer );
  100. void ReadLayerElement( const Scope& layerElement );
  101. void ReadVertexData( const std::string& type, int index, const Scope& source );
  102. void ReadVertexDataUV( std::vector<aiVector2D>& uv_out, const Scope& source,
  103. const std::string& MappingInformationType,
  104. const std::string& ReferenceInformationType );
  105. void ReadVertexDataNormals( std::vector<aiVector3D>& normals_out, const Scope& source,
  106. const std::string& MappingInformationType,
  107. const std::string& ReferenceInformationType );
  108. void ReadVertexDataColors( std::vector<aiColor4D>& colors_out, const Scope& source,
  109. const std::string& MappingInformationType,
  110. const std::string& ReferenceInformationType );
  111. void ReadVertexDataTangents( std::vector<aiVector3D>& tangents_out, const Scope& source,
  112. const std::string& MappingInformationType,
  113. const std::string& ReferenceInformationType );
  114. void ReadVertexDataBinormals( std::vector<aiVector3D>& binormals_out, const Scope& source,
  115. const std::string& MappingInformationType,
  116. const std::string& ReferenceInformationType );
  117. void ReadVertexDataMaterials( MatIndexArray& materials_out, const Scope& source,
  118. const std::string& MappingInformationType,
  119. const std::string& ReferenceInformationType );
  120. private:
  121. // cached data arrays
  122. MatIndexArray m_materials;
  123. std::vector<aiVector3D> m_vertices;
  124. std::vector<unsigned int> m_faces;
  125. mutable std::vector<unsigned int> m_facesVertexStartIndices;
  126. std::vector<aiVector3D> m_tangents;
  127. std::vector<aiVector3D> m_binormals;
  128. std::vector<aiVector3D> m_normals;
  129. std::string m_uvNames[ AI_MAX_NUMBER_OF_TEXTURECOORDS ];
  130. std::vector<aiVector2D> m_uvs[ AI_MAX_NUMBER_OF_TEXTURECOORDS ];
  131. std::vector<aiColor4D> m_colors[ AI_MAX_NUMBER_OF_COLOR_SETS ];
  132. std::vector<unsigned int> m_mapping_counts;
  133. std::vector<unsigned int> m_mapping_offsets;
  134. std::vector<unsigned int> m_mappings;
  135. };
  136. }
  137. }
  138. #endif // INCLUDED_AI_FBX_MESHGEOMETRY_H