1/****************************************************************************************
2
3 Copyright (C) 2015 Autodesk, Inc.
4 All rights reserved.
5
6 Use of this software is subject to the terms of the Autodesk license agreement
7 provided at the time of installation or download, or which otherwise accompanies
8 this software in either electronic or hard copy form.
9
10****************************************************************************************/
11
12//! \file fbxreader.h
13#ifndef _FBXSDK_FILEIO_READER_H_
14#define _FBXSDK_FILEIO_READER_H_
15
16#include <fbxsdk/fbxsdk_def.h>
17
18#include <fbxsdk/core/base/fbxarray.h>
19#include <fbxsdk/core/base/fbxstring.h>
20#include <fbxsdk/core/base/fbxtime.h>
21#include <fbxsdk/fileio/fbx/fbxio.h>
22
23#include <fbxsdk/fbxsdk_nsbegin.h>
24
25class FbxManager;
26class FbxFile;
27class FbxStream;
28class FbxObject;
29class FbxDocument;
30class FbxDocumentInfo;
31class FbxScene;
32class FbxImporter;
33class FbxIOSettings;
34class FbxAxisSystem;
35class FbxStatistics;
36class FbxSystemUnit;
37class FbxNode;
38class FbxProgress;
39class FbxTakeInfo;
40
41 /** Base class of other readers used internally.
42 * This class provides the interfaces for reading files.
43 *
44 * The role of the reader is to effectively "read" specific file data
45 * vs the role of the importer is to select a specific reader
46 * and launch the reading of a file through that reader.
47 * \see FbxImporter
48 *
49 * ex:
50 * - FbxReaderFbx5 can read FBX 5 format files
51 * - FbxReaderFbx6 can read FBX 6 format files
52 * - FbxReaderFbx7 can read FBX 7 format files
53 * - FbxReaderCollada can read Collada files
54 * - FbxReaderDxf can read Dxf files
55 * - ... etc.
56 *
57 * A SDK user should - normally - not use this class,
58 * except if a custom reader must be created for plug-in extension,
59 * then FbxReader must be the base class for
60 * the new custom reader in that particular situation.
61 * \nosubgrouping
62 */
63
64class FBXSDK_DLL FbxReader
65{
66public:
67 /** Constructor.
68 * \param pManager The FbxManager Object.
69 * \param pID Id for current reader.
70 * \param pStatus The FbxStatus object to hold error codes.
71 */
72 FbxReader(FbxManager& pManager, int pID, FbxStatus& pStatus);
73
74 /** Destructor.
75 */
76 virtual ~FbxReader();
77
78 /** Information type to request.
79 * \remarks Used internally to get reader file information.
80 */
81 enum EInfoRequest
82 {
83 eInfoExtension, //!< To get the file ext for a reader ex: "FBX".
84 eInfoDescriptions, //!< To get the file description for a reader ex: "Autodesk FBX (*.fbx)".
85 eReserved1 = 0xFBFB,
86 };
87
88 /** Flags for reading parts of file.
89 * \remarks Used internally when an importer is initialized to get some information very fast.
90 */
91 enum EFileOpenSpecialFlags
92 {
93 eParseForGlobalSettings = 1, //!< Used for reading the Global settings section when an importer is initialized.
94 eParseForStatistics = 2 //!< Used for reading a group of statistics when an importer is initialized.
95 };
96
97 /** \internal Helper typedef for passing FbxReader creator function as argument (used internally) */
98 typedef FbxReader* (*CreateFuncType)(FbxManager& pManager, FbxImporter& pImporter, int pSubID, int pPluginID);
99
100 /** \internal Helper typedef for passing FbxIOSettings creator function as argument (used internally) */
101 typedef void (*IOSettingsFillerFuncType)(FbxIOSettings& pIOS);
102
103 /** \internal Helper typedef for passing EInfoRequest function as argument (used internally) */
104 typedef void* (*GetInfoFuncType)(EInfoRequest pRequest, int pReaderTypeId);
105
106 /** Returns the file version.
107 * \param pMajor Major version.
108 * \param pMinor Minor version.
109 * \param pRevision Revision version.
110 */
111 virtual void GetVersion(int& pMajor, int& pMinor, int& pRevision){ pMajor = pMinor = pRevision = 0; }
112
113 /** Opens the file with default flag
114 * \param pFileName Name of the File to open
115 * \return If the file opens successfully return \c true, otherwise return \c false.
116 */
117 virtual bool FileOpen(char* pFileName) = 0;
118
119 /** Opens the stream with default flag
120 * \param pStream stream to open
121 * \param pStreamData user-defined stream data
122 * \return If the stream opens successfully return \c true, otherwise return \c false.
123 */
124 virtual bool FileOpen(FbxStream* pStream, void* pStreamData);
125
126 /** Closes the file stream
127 * \return \c false
128 */
129 virtual bool FileClose() = 0;
130
131 /** Checks if the file stream is open.
132 * \return \c false.
133 */
134 virtual bool IsFileOpen() = 0;
135
136 /** Returns file stream options
137 * \param pParseFileAsNeeded Sets whether to parse file as read options
138 * \return true on success, otherwise return false.
139 */
140 virtual bool GetReadOptions(bool pParseFileAsNeeded = true) = 0;
141
142 /** Reads file with stream options
143 * \param pDocument FbxDocument to store the file data
144 * \return \c false.
145 */
146 virtual bool Read(FbxDocument* pDocument) = 0;
147
148#ifndef FBXSDK_ENV_WINSTORE
149 /** Reads extension plug-ins name, version and parameters, so that we can remember if a plug-in was used during export.
150 * This is especially useful for extension plug-ins that modify the scene and also to warn users during import if an
151 * extension plug-in was used that could be missing.
152 * \param pParams The parameters of the extension plug-in. The properties of the objects are used
153 * as the parameters of the extension plug-in.
154 * \remark This function has no implementation in this class. Only sub-class should implement it as needed. For example,
155 * FBX 6 and FBX 7 does implement it.
156 */
157 virtual void PluginReadParameters(FbxObject& pParams);
158#endif /* !FBXSDK_ENV_WINSTORE */
159
160 /** Opens the file with specific EFileOpenSpecialFlags
161 * \param pFileName Name of the File to open.
162 * \param pFlags The EFileOpenSpecialFlags to open with
163 * \return If the file opens successfully return true, otherwise return false.
164 */
165 virtual bool FileOpen(char* pFileName, EFileOpenSpecialFlags /*pFlags*/){ return FileOpen(pFileName); }
166
167 /** Returns the system axis information and file system units from the file
168 * \param pAxisSystem Axis system in file
169 * \param pSystemUnits System unit in file
170 * \return \c false.
171 */
172 virtual bool GetAxisInfo(FbxAxisSystem* /*pAxisSystem*/, FbxSystemUnit* /*pSystemUnits*/){ return false; }
173
174 /** Returns statistics from the file
175 * \param pStats Statistics in the file.
176 * \return \c false.
177 */
178 virtual bool GetStatistics(FbxStatistics* /*pStats*/){ return false; }
179
180 /** Get FBX file time mode read from GlobalSettings in FBX 6.n and FBX 7.n
181 * \param pTimeMode ref to a FbxTime::EMode enum
182 * \return \c true on success, \c false otherwise.
183 * \remarks This function must be called after FbxImporter::Initialize().
184 * Can be used for statistics (via GlobalSettings) before loading the whole scene from the file.
185 */
186 virtual bool GetFrameRate(FbxTime::EMode& pTimeMode) { pTimeMode = FbxTime::eDefaultMode; return false; }
187
188
189 /** Returns the scene info from the file.
190 * \return NULL.
191 */
192 virtual FbxDocumentInfo* GetSceneInfo(){return NULL;}
193
194 /** Returns the list of take infos from the file.
195 * \return NULL
196 */
197 virtual FbxArray<FbxTakeInfo*>* GetTakeInfo(){return NULL;}
198
199 /** If default camera resolution is OK, returns information about the resolution of the render.
200 * \param pCamName Default camera name.
201 * \param pResolutionMode Default resolution mode.
202 * \param pW Default resolution width.
203 * \param pH Default resolution height.
204 * \return \c true If default camera resolution is OK, \c false Otherwise.
205 */
206 virtual bool GetDefaultRenderResolution(FbxString& pCamName, FbxString& pResolutionMode, double& pW, double& pH);
207
208 /** Judges if the format of the file is was created by an Autodesk plug-in.
209 * An internal (genuine) plug-in is one created by the Autodesk FBX product team.
210 * \return \c true If the file format is internal plug-in , \c false Otherwise.
211 */
212 bool IsGenuine();
213
214 /** Access to a IOSettings object.
215 * \return A pointer to IOSettings used for this reader or NULL if the object
216 * has not been allocated.
217 */
218 virtual FbxIOSettings * GetIOSettings();
219
220 /** Set the IOSettings pointer to be used for this reader instance.
221 * \param pIOSettings
222 */
223 virtual void SetIOSettings(FbxIOSettings * pIOSettings);
224
225 /** Pass a progress handler to the reader.
226 * \param pProgress FbxProgress to store the progress information.
227 */
228 virtual void SetProgressHandler(FbxProgress* /*pProgress*/){}
229
230 virtual void SetEmbeddingExtractionFolder(const char* /*pExtractFolder*/){}
231
232 /** Returns true if this reader supports FbxStream I/O. Default value is false. */
233 virtual bool SupportsStreams() const;
234
235/*****************************************************************************************************************************
236** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
237*****************************************************************************************************************************/
238#ifndef DOXYGEN_SHOULD_SKIP_THIS
239 virtual bool FileOpen(FbxFile * pFile);
240
241 FbxStatus& GetStatus() { return mStatus; }
242
243protected:
244 void SetDefaultRenderResolution(const char* pCamName, const char* pResolutionMode, double pW, double pH);
245#ifndef FBXSDK_ENV_WINSTORE
246 void PluginsReadBegin(FbxScene& pScene);
247 void PluginsRead(const char* pName, const char* pVersion);
248 void PluginsReadEnd(FbxScene& pScene);
249#endif /* !FBXSDK_ENV_WINSTORE */
250 FbxReader& operator=(FbxReader const&) { return *this; }
251 virtual bool CheckDuplicateNodeNames(FbxNode* pRootNode, FbxString& pDuplicateNodeNameList);
252
253 FbxStatus& mStatus;
254 FbxManager& mManager;
255 FbxIODefaultRenderResolution* mData;
256
257private:
258 int mInternalID;
259 FbxIOSettings* mIOSettings;
260
261 friend struct FbxReaderFbx7_Impl;
262#endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
263};
264
265//! Helper to access the IOSetting object pointer as a ref ex: IOS_REF.GetBoolProp( ... );
266#define IOS_REF (*GetIOSettings())
267
268#include <fbxsdk/fbxsdk_nsend.h>
269
270#endif /* _FBXSDK_FILEIO_READER_H_ */
271