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