| 1 | /* |
| 2 | Open Asset Import Library (assimp) |
| 3 | ---------------------------------------------------------------------- |
| 4 | |
| 5 | Copyright (c) 2006-2025, assimp team |
| 6 | |
| 7 | All rights reserved. |
| 8 | |
| 9 | Redistribution and use of this software in source and binary forms, |
| 10 | with or without modification, are permitted provided that the |
| 11 | following conditions are met: |
| 12 | |
| 13 | * Redistributions of source code must retain the above |
| 14 | copyright notice, this list of conditions and the |
| 15 | following disclaimer. |
| 16 | |
| 17 | * Redistributions in binary form must reproduce the above |
| 18 | copyright notice, this list of conditions and the |
| 19 | following disclaimer in the documentation and/or other |
| 20 | materials provided with the distribution. |
| 21 | |
| 22 | * Neither the name of the assimp team, nor the names of its |
| 23 | contributors may be used to endorse or promote products |
| 24 | derived from this software without specific prior |
| 25 | written permission of the assimp team. |
| 26 | |
| 27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 28 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 29 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 30 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 31 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 32 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 33 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 34 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 35 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 36 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 37 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 38 | |
| 39 | ---------------------------------------------------------------------- |
| 40 | */ |
| 41 | |
| 42 | /** @file FBXImporter.h |
| 43 | * @brief Declaration of the FBX main importer class |
| 44 | */ |
| 45 | #ifndef INCLUDED_AI_FBX_MESHGEOMETRY_H |
| 46 | #define INCLUDED_AI_FBX_MESHGEOMETRY_H |
| 47 | |
| 48 | #include "FBXParser.h" |
| 49 | #include "FBXDocument.h" |
| 50 | |
| 51 | namespace Assimp { |
| 52 | namespace FBX { |
| 53 | |
| 54 | /** |
| 55 | * @brief DOM base class for all kinds of FBX geometry |
| 56 | */ |
| 57 | class Geometry : public Object { |
| 58 | public: |
| 59 | /// @brief The class constructor with all parameters. |
| 60 | /// @param id The id. |
| 61 | /// @param element The element instance |
| 62 | /// @param name The name instance |
| 63 | /// @param doc The document instance |
| 64 | Geometry( uint64_t id, const Element& element, const std::string& name, const Document& doc ); |
| 65 | |
| 66 | /// @brief The class destructor, default. |
| 67 | virtual ~Geometry() = default; |
| 68 | |
| 69 | /// @brief Get the Skin attached to this geometry or nullptr. |
| 70 | /// @return The deformer skip instance as a pointer, nullptr if none. |
| 71 | const Skin* DeformerSkin() const; |
| 72 | |
| 73 | /// @brief Get the BlendShape attached to this geometry or nullptr |
| 74 | /// @return The blendshape arrays. |
| 75 | const std::unordered_set<const BlendShape*>& GetBlendShapes() const; |
| 76 | |
| 77 | private: |
| 78 | const Skin* skin; |
| 79 | std::unordered_set<const BlendShape*> blendShapes; |
| 80 | |
| 81 | }; |
| 82 | |
| 83 | typedef std::vector<int> MatIndexArray; |
| 84 | |
| 85 | /** |
| 86 | * @brief DOM class for FBX geometry of type "Mesh" |
| 87 | */ |
| 88 | class MeshGeometry : public Geometry { |
| 89 | public: |
| 90 | /// @brief The class constructor |
| 91 | /// @param id The id. |
| 92 | /// @param element The element instance |
| 93 | /// @param name The name instance |
| 94 | /// @param doc The document instance |
| 95 | MeshGeometry( uint64_t id, const Element& element, const std::string& name, const Document& doc ); |
| 96 | |
| 97 | /// @brief The class destructor, default. |
| 98 | virtual ~MeshGeometry() = default; |
| 99 | |
| 100 | /// brief Get a vector of all vertex points, non-unique. |
| 101 | /// @return The vertices vector. |
| 102 | const std::vector<aiVector3D>& GetVertices() const; |
| 103 | |
| 104 | /// @brief Get a vector of all vertex normals or an empty array if no normals are specified. |
| 105 | /// @return The normal vector. |
| 106 | const std::vector<aiVector3D>& GetNormals() const; |
| 107 | |
| 108 | /// @brief Get a vector of all vertex tangents or an empty array if no tangents are specified. |
| 109 | /// @return The vertex tangents vector. |
| 110 | const std::vector<aiVector3D>& GetTangents() const; |
| 111 | |
| 112 | /// @brief Get a vector of all vertex bi-normals or an empty array if no bi-normals are specified. |
| 113 | /// @return The binomal vector. |
| 114 | const std::vector<aiVector3D>& GetBinormals() const; |
| 115 | |
| 116 | /// @brief Return list of faces - each entry denotes a face and specifies how many vertices it has. |
| 117 | /// Vertices are taken from the vertex data arrays in sequential order. |
| 118 | /// @return The face indices vector. |
| 119 | const std::vector<unsigned int>& GetFaceIndexCounts() const; |
| 120 | |
| 121 | /// @brief Get a UV coordinate slot, returns an empty array if the requested slot does not exist. |
| 122 | /// @param index The requested texture coordinate slot. |
| 123 | /// @return The texture coordinates. |
| 124 | const std::vector<aiVector2D>& GetTextureCoords( unsigned int index ) const; |
| 125 | |
| 126 | /// @brief Get a UV coordinate slot, returns an empty array if the requested slot does not exist. |
| 127 | /// @param index The requested texture coordinate slot. |
| 128 | /// @return The texture coordinate channel name. |
| 129 | std::string GetTextureCoordChannelName( unsigned int index ) const; |
| 130 | |
| 131 | /// @brief Get a vertex color coordinate slot, returns an empty array if the requested slot does not exist. |
| 132 | /// @param index The requested texture coordinate slot. |
| 133 | /// @return The vertex color vector. |
| 134 | const std::vector<aiColor4D>& GetVertexColors( unsigned int index ) const; |
| 135 | |
| 136 | /// @brief Get per-face-vertex material assignments. |
| 137 | /// @return The Material indices Array. |
| 138 | const MatIndexArray& GetMaterialIndices() const; |
| 139 | |
| 140 | /// @brief Convert from a fbx file vertex index (for example from a #Cluster weight) or nullptr if the vertex index is not valid. |
| 141 | /// @param in_index The requested input index. |
| 142 | /// @param count The number of indices. |
| 143 | /// @return The indices. |
| 144 | const unsigned int* ToOutputVertexIndex( unsigned int in_index, unsigned int& count ) const; |
| 145 | |
| 146 | /// @brief Determine the face to which a particular output vertex index belongs. |
| 147 | /// This mapping is always unique. |
| 148 | /// @param in_index The requested input index. |
| 149 | /// @return The face-to-vertex index. |
| 150 | unsigned int FaceForVertexIndex( unsigned int in_index ) const; |
| 151 | |
| 152 | private: |
| 153 | void ReadLayer( const Scope& layer ); |
| 154 | void ReadLayerElement( const Scope& layerElement ); |
| 155 | void ReadVertexData( const std::string& type, int index, const Scope& source ); |
| 156 | |
| 157 | void ReadVertexDataUV( std::vector<aiVector2D>& uv_out, const Scope& source, |
| 158 | const std::string& MappingInformationType, |
| 159 | const std::string& ReferenceInformationType ); |
| 160 | |
| 161 | void ReadVertexDataNormals( std::vector<aiVector3D>& normals_out, const Scope& source, |
| 162 | const std::string& MappingInformationType, |
| 163 | const std::string& ReferenceInformationType ); |
| 164 | |
| 165 | void ReadVertexDataColors( std::vector<aiColor4D>& colors_out, const Scope& source, |
| 166 | const std::string& MappingInformationType, |
| 167 | const std::string& ReferenceInformationType ); |
| 168 | |
| 169 | void ReadVertexDataTangents( std::vector<aiVector3D>& tangents_out, const Scope& source, |
| 170 | const std::string& MappingInformationType, |
| 171 | const std::string& ReferenceInformationType ); |
| 172 | |
| 173 | void ReadVertexDataBinormals( std::vector<aiVector3D>& binormals_out, const Scope& source, |
| 174 | const std::string& MappingInformationType, |
| 175 | const std::string& ReferenceInformationType ); |
| 176 | |
| 177 | void ReadVertexDataMaterials( MatIndexArray& materials_out, const Scope& source, |
| 178 | const std::string& MappingInformationType, |
| 179 | const std::string& ReferenceInformationType ); |
| 180 | |
| 181 | private: |
| 182 | // cached data arrays |
| 183 | MatIndexArray m_materials; |
| 184 | std::vector<aiVector3D> m_vertices; |
| 185 | std::vector<unsigned int> m_faces; |
| 186 | mutable std::vector<unsigned int> m_facesVertexStartIndices; |
| 187 | std::vector<aiVector3D> m_tangents; |
| 188 | std::vector<aiVector3D> m_binormals; |
| 189 | std::vector<aiVector3D> m_normals; |
| 190 | |
| 191 | std::string m_uvNames[ AI_MAX_NUMBER_OF_TEXTURECOORDS ]; |
| 192 | std::vector<aiVector2D> m_uvs[ AI_MAX_NUMBER_OF_TEXTURECOORDS ]; |
| 193 | std::vector<aiColor4D> m_colors[ AI_MAX_NUMBER_OF_COLOR_SETS ]; |
| 194 | |
| 195 | std::vector<unsigned int> m_mapping_counts; |
| 196 | std::vector<unsigned int> m_mapping_offsets; |
| 197 | std::vector<unsigned int> m_mappings; |
| 198 | }; |
| 199 | |
| 200 | /** |
| 201 | * DOM class for FBX geometry of type "Shape" |
| 202 | */ |
| 203 | class ShapeGeometry : public Geometry |
| 204 | { |
| 205 | public: |
| 206 | /** The class constructor */ |
| 207 | ShapeGeometry(uint64_t id, const Element& element, const std::string& name, const Document& doc); |
| 208 | |
| 209 | /** The class destructor */ |
| 210 | virtual ~ShapeGeometry(); |
| 211 | |
| 212 | /** Get a list of all vertex points, non-unique*/ |
| 213 | const std::vector<aiVector3D>& GetVertices() const; |
| 214 | |
| 215 | /** Get a list of all vertex normals or an empty array if |
| 216 | * no normals are specified. */ |
| 217 | const std::vector<aiVector3D>& GetNormals() const; |
| 218 | |
| 219 | /** Return list of vertex indices. */ |
| 220 | const std::vector<unsigned int>& GetIndices() const; |
| 221 | |
| 222 | private: |
| 223 | std::vector<aiVector3D> m_vertices; |
| 224 | std::vector<aiVector3D> m_normals; |
| 225 | std::vector<unsigned int> m_indices; |
| 226 | }; |
| 227 | /** |
| 228 | * DOM class for FBX geometry of type "Line" |
| 229 | */ |
| 230 | class LineGeometry : public Geometry |
| 231 | { |
| 232 | public: |
| 233 | /** The class constructor */ |
| 234 | LineGeometry(uint64_t id, const Element& element, const std::string& name, const Document& doc); |
| 235 | |
| 236 | /** The class destructor */ |
| 237 | virtual ~LineGeometry(); |
| 238 | |
| 239 | /** Get a list of all vertex points, non-unique*/ |
| 240 | const std::vector<aiVector3D>& GetVertices() const; |
| 241 | |
| 242 | /** Return list of vertex indices. */ |
| 243 | const std::vector<int>& GetIndices() const; |
| 244 | |
| 245 | private: |
| 246 | std::vector<aiVector3D> m_vertices; |
| 247 | std::vector<int> m_indices; |
| 248 | }; |
| 249 | |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | #endif // INCLUDED_AI_FBX_MESHGEOMETRY_H |
| 254 | |
| 255 | |