FBXMeshGeometry.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /*
  2. Open Asset Import Library (assimp)
  3. ----------------------------------------------------------------------
  4. Copyright (c) 2006-2025, 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. * @brief DOM base class for all kinds of FBX geometry
  44. */
  45. class Geometry : public Object {
  46. public:
  47. /// @brief The class constructor with all parameters.
  48. /// @param id The id.
  49. /// @param element The element instance
  50. /// @param name The name instance
  51. /// @param doc The document instance
  52. Geometry( uint64_t id, const Element& element, const std::string& name, const Document& doc );
  53. /// @brief The class destructor, default.
  54. virtual ~Geometry() = default;
  55. /// @brief Get the Skin attached to this geometry or nullptr.
  56. /// @return The deformer skip instance as a pointer, nullptr if none.
  57. const Skin* DeformerSkin() const;
  58. /// @brief Get the BlendShape attached to this geometry or nullptr
  59. /// @return The blendshape arrays.
  60. const std::unordered_set<const BlendShape*>& GetBlendShapes() const;
  61. private:
  62. const Skin* skin;
  63. std::unordered_set<const BlendShape*> blendShapes;
  64. };
  65. typedef std::vector<int> MatIndexArray;
  66. /**
  67. * @brief DOM class for FBX geometry of type "Mesh"
  68. */
  69. class MeshGeometry : public Geometry {
  70. public:
  71. /// @brief The class constructor
  72. /// @param id The id.
  73. /// @param element The element instance
  74. /// @param name The name instance
  75. /// @param doc The document instance
  76. MeshGeometry( uint64_t id, const Element& element, const std::string& name, const Document& doc );
  77. /// @brief The class destructor, default.
  78. virtual ~MeshGeometry() = default;
  79. /// brief Get a vector of all vertex points, non-unique.
  80. /// @return The vertices vector.
  81. const std::vector<aiVector3D>& GetVertices() const;
  82. /// @brief Get a vector of all vertex normals or an empty array if no normals are specified.
  83. /// @return The normal vector.
  84. const std::vector<aiVector3D>& GetNormals() const;
  85. /// @brief Get a vector of all vertex tangents or an empty array if no tangents are specified.
  86. /// @return The vertex tangents vector.
  87. const std::vector<aiVector3D>& GetTangents() const;
  88. /// @brief Get a vector of all vertex bi-normals or an empty array if no bi-normals are specified.
  89. /// @return The binomal vector.
  90. const std::vector<aiVector3D>& GetBinormals() const;
  91. /// @brief Return list of faces - each entry denotes a face and specifies how many vertices it has.
  92. /// Vertices are taken from the vertex data arrays in sequential order.
  93. /// @return The face indices vector.
  94. const std::vector<unsigned int>& GetFaceIndexCounts() const;
  95. /// @brief Get a UV coordinate slot, returns an empty array if the requested slot does not exist.
  96. /// @param index The requested texture coordinate slot.
  97. /// @return The texture coordinates.
  98. const std::vector<aiVector2D>& GetTextureCoords( unsigned int index ) const;
  99. /// @brief Get a UV coordinate slot, returns an empty array if the requested slot does not exist.
  100. /// @param index The requested texture coordinate slot.
  101. /// @return The texture coordinate channel name.
  102. std::string GetTextureCoordChannelName( unsigned int index ) const;
  103. /// @brief Get a vertex color coordinate slot, returns an empty array if the requested slot does not exist.
  104. /// @param index The requested texture coordinate slot.
  105. /// @return The vertex color vector.
  106. const std::vector<aiColor4D>& GetVertexColors( unsigned int index ) const;
  107. /// @brief Get per-face-vertex material assignments.
  108. /// @return The Material indices Array.
  109. const MatIndexArray& GetMaterialIndices() const;
  110. /// @brief Convert from a fbx file vertex index (for example from a #Cluster weight) or nullptr if the vertex index is not valid.
  111. /// @param in_index The requested input index.
  112. /// @param count The number of indices.
  113. /// @return The indices.
  114. const unsigned int* ToOutputVertexIndex( unsigned int in_index, unsigned int& count ) const;
  115. /// @brief Determine the face to which a particular output vertex index belongs.
  116. /// This mapping is always unique.
  117. /// @param in_index The requested input index.
  118. /// @return The face-to-vertex index.
  119. unsigned int FaceForVertexIndex( unsigned int in_index ) const;
  120. private:
  121. void ReadLayer( const Scope& layer );
  122. void ReadLayerElement( const Scope& layerElement );
  123. void ReadVertexData( const std::string& type, int index, const Scope& source );
  124. void ReadVertexDataUV( std::vector<aiVector2D>& uv_out, const Scope& source,
  125. const std::string& MappingInformationType,
  126. const std::string& ReferenceInformationType );
  127. void ReadVertexDataNormals( std::vector<aiVector3D>& normals_out, const Scope& source,
  128. const std::string& MappingInformationType,
  129. const std::string& ReferenceInformationType );
  130. void ReadVertexDataColors( std::vector<aiColor4D>& colors_out, const Scope& source,
  131. const std::string& MappingInformationType,
  132. const std::string& ReferenceInformationType );
  133. void ReadVertexDataTangents( std::vector<aiVector3D>& tangents_out, const Scope& source,
  134. const std::string& MappingInformationType,
  135. const std::string& ReferenceInformationType );
  136. void ReadVertexDataBinormals( std::vector<aiVector3D>& binormals_out, const Scope& source,
  137. const std::string& MappingInformationType,
  138. const std::string& ReferenceInformationType );
  139. void ReadVertexDataMaterials( MatIndexArray& materials_out, const Scope& source,
  140. const std::string& MappingInformationType,
  141. const std::string& ReferenceInformationType );
  142. private:
  143. // cached data arrays
  144. MatIndexArray m_materials;
  145. std::vector<aiVector3D> m_vertices;
  146. std::vector<unsigned int> m_faces;
  147. mutable std::vector<unsigned int> m_facesVertexStartIndices;
  148. std::vector<aiVector3D> m_tangents;
  149. std::vector<aiVector3D> m_binormals;
  150. std::vector<aiVector3D> m_normals;
  151. std::string m_uvNames[ AI_MAX_NUMBER_OF_TEXTURECOORDS ];
  152. std::vector<aiVector2D> m_uvs[ AI_MAX_NUMBER_OF_TEXTURECOORDS ];
  153. std::vector<aiColor4D> m_colors[ AI_MAX_NUMBER_OF_COLOR_SETS ];
  154. std::vector<unsigned int> m_mapping_counts;
  155. std::vector<unsigned int> m_mapping_offsets;
  156. std::vector<unsigned int> m_mappings;
  157. };
  158. /**
  159. * DOM class for FBX geometry of type "Shape"
  160. */
  161. class ShapeGeometry : public Geometry
  162. {
  163. public:
  164. /** The class constructor */
  165. ShapeGeometry(uint64_t id, const Element& element, const std::string& name, const Document& doc);
  166. /** The class destructor */
  167. virtual ~ShapeGeometry();
  168. /** Get a list of all vertex points, non-unique*/
  169. const std::vector<aiVector3D>& GetVertices() const;
  170. /** Get a list of all vertex normals or an empty array if
  171. * no normals are specified. */
  172. const std::vector<aiVector3D>& GetNormals() const;
  173. /** Return list of vertex indices. */
  174. const std::vector<unsigned int>& GetIndices() const;
  175. private:
  176. std::vector<aiVector3D> m_vertices;
  177. std::vector<aiVector3D> m_normals;
  178. std::vector<unsigned int> m_indices;
  179. };
  180. /**
  181. * DOM class for FBX geometry of type "Line"
  182. */
  183. class LineGeometry : public Geometry
  184. {
  185. public:
  186. /** The class constructor */
  187. LineGeometry(uint64_t id, const Element& element, const std::string& name, const Document& doc);
  188. /** The class destructor */
  189. virtual ~LineGeometry();
  190. /** Get a list of all vertex points, non-unique*/
  191. const std::vector<aiVector3D>& GetVertices() const;
  192. /** Return list of vertex indices. */
  193. const std::vector<int>& GetIndices() const;
  194. private:
  195. std::vector<aiVector3D> m_vertices;
  196. std::vector<int> m_indices;
  197. };
  198. }
  199. }
  200. #endif // INCLUDED_AI_FBX_MESHGEOMETRY_H