fbximporter.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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 fbximporter.h
  9. #ifndef _FBXSDK_FILEIO_IMPORTER_H_
  10. #define _FBXSDK_FILEIO_IMPORTER_H_
  11. #include <fbxsdk/fbxsdk_def.h>
  12. #include <fbxsdk/core/fbxsystemunit.h>
  13. #include <fbxsdk/core/base/fbxtime.h>
  14. #include <fbxsdk/fileio/fbxiobase.h>
  15. #include <fbxsdk/fileio/fbxprogress.h>
  16. #include <fbxsdk/fileio/fbxiosettings.h>
  17. #include <fbxsdk/fileio/fbxstatistics.h>
  18. #include <fbxsdk/scene/fbxaxissystem.h>
  19. #include <fbxsdk/fbxsdk_nsbegin.h>
  20. class FbxIO;
  21. class FbxIOFileHeaderInfo;
  22. class FbxDocumentInfo;
  23. class FbxTakeInfo;
  24. class FbxReader;
  25. class FbxThread;
  26. struct FbxImportThreadArg;
  27. /** Class to import an FBX file into SDK objects.
  28. * Normally this class is used as is. But for very special needs
  29. * a user can override Initialize() for special purpose.
  30. *
  31. * An importer will select the appropriate reader to a particular file.
  32. * Ex: When an importer must import an FBX 7 file,
  33. * the importer will ask for all registered readers if an FBX 7 file reader is available,
  34. * then if a reader is found, the importer will create
  35. * the specialized FBX 7 reader and read the file.
  36. * This way, an importer can "read" many different type of files like FBX 5/6/7, 3DS, Obj, Dxf, Collada, etc.
  37. * \see FbxReader
  38. *
  39. * Typical workflow for using the FbxImporter class:
  40. * -# create a SDKManager
  41. * -# create an IOSettings object
  42. * -# create an empty scene
  43. * -# create an importer
  44. * -# initialize the importer with a file name and IOSettings
  45. * -# set numerous states, take information, defining how the importer will behave
  46. * -# call FbxImporter::Import() with an empty scene
  47. * \code
  48. * ex:
  49. * // create a SdkManager
  50. * FbxManager *lSdkManager = FbxManager::Create();
  51. *
  52. * // create an IOSettings object
  53. * FbxIOSettings * ios = FbxIOSettings::Create(lSdkManager, IOSROOT );
  54. *
  55. * // set some IOSettings options
  56. * ios->SetBoolProp(IMP_FBX_MATERIAL, true);
  57. * ios->SetBoolProp(IMP_FBX_TEXTURE, true);
  58. *
  59. * // create an empty scene
  60. * FbxScene* lScene = FbxScene::Create(lSdkManager,"");
  61. *
  62. * // Create an importer.
  63. * FbxImporter* lImporter = FbxImporter::Create(lSdkManager, "");
  64. *
  65. * // Initialize the importer by providing a filename and the IOSettings to use
  66. * lImporter->Initialize("C:\\myfile.fbx", -1, ios);
  67. *
  68. * // Import the scene.
  69. * lImporter->Import(lScene);
  70. *
  71. * // Destroy the importer.
  72. * lImporter->Destroy();
  73. * \endcode
  74. *
  75. * \remarks According to the file suffix, a specialized reader will be created internally.
  76. * Ex: for .fbx files a FBX Reader, for .3ds files, a 3ds reader, etc.
  77. * Supported files formats: FBX 5/6/7 Binary & ASCII, Collada, DXF, OBJ, 3DS
  78. * \nosubgrouping
  79. */
  80. class FBXSDK_DLL FbxImporter : public FbxIOBase
  81. {
  82. FBXSDK_OBJECT_DECLARE(FbxImporter, FbxIOBase);
  83. public:
  84. /**
  85. * \name Import Functions
  86. */
  87. //@{
  88. /** Initialize object.
  89. * \param pFileName Name of file to access.
  90. * \param pFileFormat file format identifier User does not need to specify it by default.
  91. if not specified, plugin will detect the file format according to file suffix automatically.
  92. * \param pIOSettings client IOSettings, if not specified, a default IOSettings will be created
  93. * \return \c true on success, \c false otherwise.
  94. * \remarks To identify the error that occurred, inspect the status object accessed
  95. * using the GetStatus() function.
  96. * \remarks You do not need to give the pFileFormat if the suffix of pFileName is recognized
  97. */
  98. virtual bool Initialize(const char* pFileName, int pFileFormat=-1, FbxIOSettings * pIOSettings=NULL);
  99. /** Initialize object.
  100. * \param pStream stream to access.
  101. * \param pStreamData user-defined stream data.
  102. * \param pFileFormat file format identifier User does not need to specify it by default.
  103. if not specified, plugin will request the file format from the stream automatically.
  104. * \param pIOSettings client IOSettings, if not specified, a default IOSettings will be created
  105. * \return \c true on success, \c false otherwise.
  106. * \remarks To identify the error that occurred, inspect the status object accessed
  107. * using the GetStatus() function.
  108. * \remarks You do not need to give the pFileFormat if the suffix of pFileName is recognized
  109. */
  110. virtual bool Initialize(FbxStream* pStream, void* pStreamData=NULL, const int pFileFormat=-1, FbxIOSettings* pIOSettings=NULL);
  111. /** Get the FBX version number of the FBX file.
  112. * FBX version numbers start at 5.0.0.
  113. * \param pMajor Version major number.
  114. * \param pMinor Version minor number.
  115. * \param pRevision Version revision number.
  116. * \remarks This function must be called after FbxImporter::Initialize().
  117. */
  118. void GetFileVersion(int& pMajor, int& pMinor, int& pRevision);
  119. /** Get the default rendering resolution if present in the file header.
  120. * \param pCamName Returned name of the camera.
  121. * \param pResolutionMode Returned resolution mode.
  122. * \param pW Returned width.
  123. * \param pH Returned height.
  124. * \return \c true if the default rendering settings are defined in the file, otherwise
  125. * returns \c false with empty parameters.
  126. */
  127. bool GetDefaultRenderResolution(FbxString& pCamName, FbxString& pResolutionMode, double& pW, double& pH);
  128. /** Get the complete file header information.
  129. * \return valid pointer to the complete header information
  130. */
  131. FbxIOFileHeaderInfo* GetFileHeaderInfo();
  132. /** \enum EStreamOptionsGeneration Stream options identifiers.
  133. * - \e eParseFile Parse the file
  134. * - \e eDoNotParseFile Do not parse the file.
  135. */
  136. enum EStreamOptionsGeneration
  137. {
  138. eParseFile, // Parse the file
  139. eDoNotParseFile // Do not parse the file (fast)
  140. };
  141. /** Read the currently opened file header to retrieve information related to takes.
  142. * \param pStreamOptionsGeneration Stream options identifier.
  143. * \return \c true on success, \c false otherwise.
  144. * \remarks Caller gets ownership of the returned structure.
  145. */
  146. bool GetImportOptions(EStreamOptionsGeneration pStreamOptionsGeneration = eParseFile);
  147. /** Read the currently opened file header to retrieve information related to takes.
  148. * \param pFbxObject Target FBX file.
  149. * \return \c true on success, \c false otherwise.
  150. * \remarks Caller gets ownership of the returned structure.
  151. */
  152. bool GetImportOptions(FbxIO* pFbxObject);
  153. /** Import the currently opened file into a scene.
  154. * \param pDocument Document to fill with file content.
  155. * \param pNonBlocking If true, the import process will be executed in a new thread, allowing it to be non-blocking.
  156. To determine if the import finished, refer to the function IsImporting().
  157. * \return \c true on success, \c false otherwise.
  158. * \remarks To identify the error that occurred, inspect the status object accessed
  159. * using the GetStatus() function.
  160. * If the imported file is password protected and the password is not
  161. * set or wrong, the FbxStatus object access with GetStatus() will be set with
  162. * FbxStatus::ePasswordError.
  163. */
  164. bool Import(FbxDocument* pDocument, bool pNonBlocking=false);
  165. #if !defined(FBXSDK_ENV_WINSTORE) && !defined(FBXSDK_ENV_EMSCRIPTEN)
  166. /** Check if the importer is currently importing.
  167. * \param pImportResult This parameter, after the import finished, will contain the result of the import success or failure.
  168. * \return Return true if the importer is currently importing.
  169. * \remarks This function will always return false if Import() was called with pNonBlocking set to false.
  170. * This function should be used only in the context of pNonBlocking set to true.
  171. * It is very important to periodically check if the import finished using this function,
  172. * since it will also free up the thread's allocations when its done.
  173. */
  174. bool IsImporting(bool& pImportResult);
  175. #endif /* !FBXSDK_ENV_WINSTORE && !defined(FBXSDK_ENV_EMSCRIPTEN) */
  176. /** Get the progress status in non-blocking mode.
  177. * \param pStatus Optional current status string.
  178. * \return Percentage of the finished workload
  179. */
  180. float GetProgress(FbxString* pStatus=NULL);
  181. /** Register a callback function for progress reporting in single thread mode.
  182. * \param pCallback Pointer of the callback function.
  183. * \param pArgs pointer to the arguments passed to the callback function.
  184. */
  185. void SetProgressCallback(FbxProgressCallback pCallback, void* pArgs=NULL);
  186. /** Explicitly set the embedding extraction folder. If this is never called, the FBX SDK will determine the best folder to extract embedded files.
  187. * \param pExtractFolder The file path name where the embedded files should be extracted.
  188. */
  189. void SetEmbeddingExtractionFolder(const char* pExtractFolder);
  190. /** Retrieve the current folder destination where the embedded files will be extracted. This might not be initialized until file I/O is performed.
  191. */
  192. const char* GetEmbeddingExtractionFolder();
  193. /** Access to a IOSettings object.
  194. * \return The pointer to IOSettings or \c NULL \c if the object has not been allocated.
  195. */
  196. FbxIOSettings* GetIOSettings();
  197. /** Set the IOSettings pointer
  198. * \param pIOSettings Point to a FbxIOSettings object.
  199. */
  200. void SetIOSettings(FbxIOSettings* pIOSettings);
  201. /** Set the password.
  202. * All subsequently imported files are opened with the given password.
  203. * \param pPassword Password string.
  204. */
  205. void SetPassword(char* pPassword);
  206. /**
  207. * \name Animation Stack Description Access
  208. * \see FbxAnimStack
  209. */
  210. //@{
  211. /** Get the number of available animation stacks in the file.
  212. * \return Number of animation stacks.
  213. * \remarks This function must be called after FbxImporter::Initialize().
  214. */
  215. int GetAnimStackCount();
  216. /** Get the take information about an available take.
  217. * Use the returned reference to a FbxTakeInfo object to set whether the indexed take is imported.
  218. * \param pIndex Index of the requested take.
  219. * \return Take information or \c NULL if function failed.
  220. * \remarks This function must be called after FbxImporter::Initialize().
  221. */
  222. FbxTakeInfo* GetTakeInfo(int pIndex);
  223. /** Return the active animation stack name.
  224. * \return Active animation stack name if there is one, otherwise returns an empty string.
  225. * \remarks This function must be called after FbxImporter::Initialize().
  226. */
  227. FbxString GetActiveAnimStackName();
  228. //@}
  229. /**
  230. * \name Scene Description Access
  231. */
  232. //@{
  233. /** Get the scene info.
  234. * \return Pointer to the scene info or \c NULL if no scene information
  235. * is available in the file.
  236. */
  237. FbxDocumentInfo* GetSceneInfo();
  238. //@}
  239. /**
  240. * \name File Format
  241. */
  242. //@{
  243. /** Returns the index of the reader (FbxReader) associated with the file format.
  244. This index is considered the identifier of the file format.
  245. The array of registered readers can't be retrieved.
  246. \return Index of the registered FbxReader associated with the file format.
  247. If no reader found return -1.
  248. \remarks According to the number of readers registered this value can change
  249. for the same reader between SDK Manager instantiations.
  250. */
  251. int GetFileFormat ();
  252. /** \return \c true if the file format is a recognized FBX format.
  253. */
  254. bool IsFBX();
  255. //@}
  256. /*****************************************************************************************************************************
  257. ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
  258. *****************************************************************************************************************************/
  259. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  260. FbxFile* GetFile();
  261. FbxStream* GetStream();
  262. void* GetStreamData();
  263. void ParseForGlobalSettings(bool pState);
  264. void ParseForStatistics(bool pState);
  265. bool GetAxisInfo(FbxAxisSystem* pAxisSystem, FbxSystemUnit* pSystemUnits);
  266. bool GetStatistics(FbxStatistics* pStatistics);
  267. bool GetFrameRate(FbxTime::EMode &pTimeMode);
  268. protected:
  269. virtual void Construct(const FbxObject* pFrom);
  270. virtual void Destruct(bool pRecursive);
  271. virtual void SetOrCreateIOSettings(FbxIOSettings* pIOSettings, bool pAllowNULL);
  272. void Reset();
  273. bool FileOpen(FbxFile* pFile = NULL);
  274. bool FileOpen(FbxStream* pStream, void* pStreamData);
  275. void FileClose();
  276. void GetImportOptionsInfo();
  277. bool IsNativeExtension ();
  278. //These two internal functions are only used to read old character pose data
  279. bool Initialize(FbxFile* pFile, const int pFileFormat=-1, FbxIOSettings* pIOSettings=NULL);
  280. bool Import(FbxDocument* pDocument, FbxIO* pFbxObject);
  281. private:
  282. bool ImportProcess(FbxDocument* pDocument);
  283. int mFileFormat;
  284. FbxReader* mReader;
  285. FbxString mExtractFolder;
  286. bool mParseForGlobalSettings;
  287. FbxAxisSystem mAxisSystem;
  288. FbxSystemUnit mSystemUnits;
  289. FbxTime::EMode mFrameRate;
  290. bool mParseForStatistics;
  291. FbxStatistics mStatistics;
  292. #if !defined(FBXSDK_ENV_WINSTORE) && !defined(FBXSDK_ENV_EMSCRIPTEN)
  293. FbxThread* mImportThread;
  294. FbxImportThreadArg* mImportThreadArg;
  295. bool mImportThreadResult;
  296. bool mIsThreadImporting;
  297. #endif /* !FBXSDK_ENV_WINSTORE && !defined(FBXSDK_ENV_EMSCRIPTEN) */
  298. FbxProgress mProgress;
  299. FbxFile* mFile;
  300. FbxStream* mStream;
  301. void* mStreamData;
  302. bool mImportOptionsDone;
  303. FbxArray<FbxTakeInfo*> mTakeInfo;
  304. FbxDocumentInfo* mSceneInfo;
  305. FbxString mActiveAnimStackName;
  306. int mMajorVersion;
  307. int mMinorVersion;
  308. int mRevisionVersion;
  309. FbxIOFileHeaderInfo* mHeaderInfo;
  310. FbxIOSettings* mIOSettings;
  311. bool mClientIOSettings;
  312. //For Initialize and Import
  313. friend class FbxReaderFbx5;
  314. friend class FbxReaderFbx6;
  315. friend struct FbxReaderFbx7_Impl;
  316. friend void ImportThread(void*);
  317. #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
  318. };
  319. //! Event that is emitted to plugins before a FBX file has been imported.
  320. class FBXSDK_DLL FbxEventPreImport : public FbxEvent<FbxEventPreImport>
  321. {
  322. FBXSDK_EVENT_DECLARE(FbxEventPreImport);
  323. public:
  324. inline FbxEventPreImport( FbxDocument* pDocument ) : mDocument(pDocument) {};
  325. //! The document the FBX file is to be imported into.
  326. FbxDocument* mDocument;
  327. };
  328. //! Event that is emitted to plugins after a FBX file has been imported.
  329. class FBXSDK_DLL FbxEventPostImport : public FbxEvent<FbxEventPostImport>
  330. {
  331. FBXSDK_EVENT_DECLARE(FbxEventPostImport);
  332. public:
  333. inline FbxEventPostImport( FbxDocument* pDocument ) : mDocument(pDocument) {};
  334. //! The imported document
  335. FbxDocument* mDocument;
  336. };
  337. #include <fbxsdk/fbxsdk_nsend.h>
  338. #endif /* _FBXSDK_FILEIO_IMPORTER_H_ */