fbxreader.h 11 KB

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