fbxexporter.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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 fbxexporter.h
  9. #ifndef _FBXSDK_FILEIO_EXPORTER_H_
  10. #define _FBXSDK_FILEIO_EXPORTER_H_
  11. #include <fbxsdk/fbxsdk_def.h>
  12. #include <fbxsdk/core/fbxevent.h>
  13. #include <fbxsdk/core/base/fbxstring.h>
  14. #include <fbxsdk/fileio/fbxiobase.h>
  15. #include <fbxsdk/fileio/fbxiosettings.h>
  16. #include <fbxsdk/fileio/fbxprogress.h>
  17. #include <fbxsdk/utils/fbxrenamingstrategy.h>
  18. #include <fbxsdk/fbxsdk_nsbegin.h>
  19. class FbxIO;
  20. class FbxIOFileHeaderInfo;
  21. class FbxThread;
  22. class FbxWriter;
  23. struct FbxExportThreadArg;
  24. /** Class to export SDK objects into an FBX file.
  25. * Normally this class is used as is. But for very special needs
  26. * a user can override Initialize() for special purpose.
  27. *
  28. * An exporter will select the appropriate writer to a particular file.
  29. * Ex: When an exporter must export an FBX 7 file,
  30. * the exporter will ask for all registered writers if an FBX 7 file writer is available,
  31. * then if a writer is found, the exporter will create
  32. * the specialized FBX 7 writer and write the file.
  33. * This way, an exporter can "write" many different type of files like FBX 5/6/7, 3DS, Obj, Dxf, Collada, etc.
  34. * \see FbxWriter
  35. *
  36. * Typical workflow for using the FbxExporter class:
  37. * -# create a SDKManager
  38. * -# create an IOSettings object
  39. * -# create an empty scene
  40. * -# create an exporter
  41. * -# initialize it with a file name
  42. * -# set numerous options to control how the exporter will behave.\n
  43. * ex: set IOSettings values to export Materials or Textures.
  44. * -# call FbxExporter::Export() with the entity to export.
  45. *
  46. * \code
  47. * // ex:
  48. * // create a SdkManager
  49. * FbxManager* lSdkManager = FbxManager::Create();
  50. *
  51. * // create an IOSettings object
  52. * FbxIOSettings* ios = FbxIOSettings::Create(lSdkManager, IOSROOT);
  53. *
  54. * // set some IOSettings options
  55. * ios->SetBoolProp(EXP_FBX_MATERIAL, true);
  56. * ios->SetBoolProp(EXP_FBX_TEXTURE, true);
  57. *
  58. * // create an empty scene
  59. * FbxScene* lScene = FbxScene::Create(lSdkManager, "");
  60. *
  61. * // create an exporter.
  62. * FbxExporter* lExporter = FbxExporter::Create(lSdkManager, "");
  63. *
  64. * // initialize the exporter by providing a filename and the IOSettings to use
  65. * lExporter->Initialize("C:\\myfile.fbx", -1, ios);
  66. *
  67. * // export the scene.
  68. * lExporter->Export(lScene);
  69. *
  70. * // destroy the exporter
  71. * lExporter->Destroy();
  72. * \endcode
  73. *
  74. * \remarks According to the file suffix, a specialized writer will be created internally.\n
  75. * Ex: for .fbx files a FBX Writer, for .3ds files, a 3ds writer, etc.\n
  76. * Supported files formats: FBX 5/6/7 Binary & ASCII, Collada, DXF, OBJ, 3DS
  77. * \nosubgrouping
  78. */
  79. class FBXSDK_DLL FbxExporter : public FbxIOBase
  80. {
  81. FBXSDK_OBJECT_DECLARE(FbxExporter, FbxIOBase);
  82. public:
  83. /**
  84. * \name Export Functions
  85. */
  86. //@{
  87. /** Initialize object.
  88. * \param pFileName Name of file to access.
  89. * \param pFileFormat file format identifier User does not need to specify it by default.
  90. if not specified, plugin will detect the file format according to file suffix automatically.
  91. * \param pIOSettings client IOSettings, if not specified, a default IOSettings will be created
  92. * \return \c true on success, \c false otherwise.
  93. * \remarks To identify the error that occurred, inspect the status object accessed
  94. * using the GetStatus() function.
  95. */
  96. virtual bool Initialize(const char* pFileName, int pFileFormat = -1, FbxIOSettings* pIOSettings = NULL);
  97. /** Initialize object.
  98. * \param pStream stream to access.
  99. * \param pStreamData user-defined stream data.
  100. * \param pFileFormat file format identifier User does not need to specify it by default.
  101. if not specified, plugin will request the file format from the stream.
  102. * \param pIOSettings client IOSettings, if not specified, a default IOSettings will be created
  103. * \return \c true on success, \c false otherwise.
  104. * \remarks To identify the error that occurred, inspect the status object accessed
  105. * using the GetStatus() function.
  106. */
  107. virtual bool Initialize(FbxStream* pStream, void* pStreamData=NULL, int pFileFormat = -1, FbxIOSettings * pIOSettings = NULL);
  108. /** Setup file export options settings.
  109. * \return \c true on success, \c false otherwise.
  110. */
  111. bool GetExportOptions();
  112. /** Access to a IOSettings object.
  113. * \return The pointer to IOSettings or \c NULL \c if the object has not been allocated.
  114. */
  115. FbxIOSettings* GetIOSettings();
  116. /** Set the IOSettings pointer
  117. * \param pIOSettings Pointer on a FbxIOSettings object.
  118. */
  119. void SetIOSettings(FbxIOSettings* pIOSettings);
  120. /** Export the document to the currently created file.
  121. * \param pDocument Document to export.
  122. * \param pNonBlocking If true, the export process will be executed in a new thread, allowing it to be non-blocking.
  123. To determine if the export finished, refer to the function IsExporting().
  124. * \return \c true on success, \c false otherwise.
  125. * \remarks To identify the error that occurred, inspect the status object accessed
  126. * using the GetStatus() function.
  127. */
  128. bool Export(FbxDocument* pDocument, bool pNonBlocking=false);
  129. #if !defined(FBXSDK_ENV_WINSTORE) && !defined(FBXSDK_ENV_EMSCRIPTEN)
  130. /** Check if the exporter is currently exporting.
  131. * \param pExportResult This parameter, after the export finished, will contain the result of the export success or failure.
  132. * \return Return true if the exporter is currently exporting.
  133. * \remarks This function will always return false if Export() was called with pNonBlocking set to false.
  134. * This function should be used only in the context of pNonBlocking set to true.
  135. * It is very important to periodically check if the export finished using this function,
  136. * since it will also free up the thread's allocations when its done.
  137. */
  138. bool IsExporting(bool& pExportResult);
  139. #endif /* !FBXSDK_ENV_WINSTORE && ! FBXSDK_ENV_EMSCRIPTEN */
  140. /** Get the progress status in non-blocking mode.
  141. * \param pStatus Optional current status string.
  142. * \return Percentage of the finished workload.
  143. */
  144. float GetProgress(FbxString* pStatus=NULL);
  145. /** Register a callback function for progress reporting in single thread mode.
  146. * \param pCallback Pointer of the callback function.
  147. * \param pArgs Pointer to the arguments passed to the callback function.
  148. */
  149. void SetProgressCallback(FbxProgressCallback pCallback, void* pArgs=NULL);
  150. //@}
  151. /**
  152. * \name File Format
  153. */
  154. //@{
  155. /** Get the format of the exported file.
  156. * \return File format identifier.
  157. */
  158. int GetFileFormat();
  159. /** Return \c true if the file format is a recognized FBX format.
  160. */
  161. bool IsFBX();
  162. /** Get the list of writable versions for the current file format.
  163. * \return \c NULL or a null terminated array of strings.
  164. * \remarks the strings returned match the writers registered for the current format.
  165. * The array items can be retrieved with the following code:
  166. * \code
  167. * char const* const* lWV = lExporter->GetCurrentWritableVersions();
  168. * if (lWV)
  169. * {
  170. * int i = 0;
  171. * while (lWV[i] != NULL)
  172. * {
  173. * printf("fmt = %s\n", lWV[i]);
  174. * i++;
  175. * }
  176. * }
  177. * \endcode
  178. *
  179. */
  180. char const* const* GetCurrentWritableVersions();
  181. /** Set file version for a given file format.
  182. * \param pVersion String description of the file format.
  183. * \param pRenamingMode Renaming mode.
  184. * \return \c true if mode is set correctly
  185. */
  186. bool SetFileExportVersion(FbxString pVersion, FbxSceneRenamer::ERenamingMode pRenamingMode=FbxSceneRenamer::eNone);
  187. /** Set the resampling rate (only used when exporting to FBX 5.3 and lower)
  188. * \param pResamplingRate resampling rate
  189. */
  190. inline void SetResamplingRate(double pResamplingRate){ mResamplingRate = pResamplingRate; }
  191. /** Set the default rendering resolution.
  192. * \param pCamName name of the camera.
  193. * \param pResolutionMode resolution mode.
  194. * \param pW width.
  195. * \param pH height.
  196. * \remark These values are ignored when exporting to FBX 7.x and higher. With FBX version 6.x and lower,
  197. * the HeaderInfo is still accessible for legacy reasons and any other custom writers. For FBX filles,
  198. * these values are used by the FBX QuickTime plug-in (obsolete now) to help it get the window size
  199. * without loading the whole file. The information contained in the FbxIOFileHeaderInfo is a duplicate
  200. * of AspectRatioMode, AspectWidth and AspectHeight properties defined in the FbxCamera class.
  201. * Retrieveing the FileHeaderInfo starting from FBX 7.x will always return the uninitialized structure.
  202. */
  203. void SetDefaultRenderResolution(FbxString pCamName, FbxString pResolutionMode, double pW, double pH);
  204. /** Get the complete file header information.
  205. * \return valid pointer to the complete header information
  206. */
  207. FbxIOFileHeaderInfo* GetFileHeaderInfo();
  208. //@}
  209. /*****************************************************************************************************************************
  210. ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
  211. *****************************************************************************************************************************/
  212. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  213. bool GetExportOptions(FbxIO* pFbxObject);
  214. bool Export(FbxDocument* pDocument, FbxIO* pFbxObject);
  215. protected:
  216. virtual void Construct(const FbxObject* pFrom);
  217. virtual void Destruct(bool pRecursive);
  218. virtual void SetOrCreateIOSettings(FbxIOSettings* pIOSettings, bool pAllowNULL);
  219. void Reset();
  220. bool FileCreate();
  221. void FileClose();
  222. private:
  223. bool ExportProcess(FbxDocument* pDocument);
  224. int mFileFormat;
  225. FbxWriter* mWriter;
  226. #if !defined(FBXSDK_ENV_WINSTORE) && !defined(FBXSDK_ENV_EMSCRIPTEN)
  227. FbxThread* mExportThread;
  228. FbxExportThreadArg* mExportThreadArg;
  229. bool mExportThreadResult;
  230. bool mIsThreadExporting;
  231. #endif /* !FBXSDK_ENV_WINSTORE && !FBXSDK_ENV_EMSCRIPTEN */
  232. FbxProgress mProgress;
  233. FbxStream* mStream;
  234. void* mStreamData;
  235. FbxString mStrFileVersion;
  236. double mResamplingRate;
  237. FbxSceneRenamer::ERenamingMode mRenamingMode;
  238. FbxIOFileHeaderInfo* mHeaderInfo;
  239. FbxIOSettings* mIOSettings;
  240. bool mClientIOSettings;
  241. friend void ExportThread(void*);
  242. #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
  243. };
  244. //! Event that is emitted to plugins before a file is exported to the FBX format.
  245. class FBXSDK_DLL FbxEventPreExport : public FbxEvent<FbxEventPreExport>
  246. {
  247. FBXSDK_EVENT_DECLARE(FbxEventPreExport);
  248. public:
  249. FbxEventPreExport(FbxDocument* pDocument) : mDocument(pDocument) {};
  250. //! The document to be exported
  251. FbxDocument* mDocument;
  252. };
  253. //! Event that is emitted to plugins after a file is exported to the FBX format.
  254. class FBXSDK_DLL FbxEventPostExport : public FbxEvent<FbxEventPostExport>
  255. {
  256. FBXSDK_EVENT_DECLARE(FbxEventPostExport);
  257. public:
  258. FbxEventPostExport(FbxDocument* pDocument) : mDocument(pDocument) {};
  259. //! The document to be exported
  260. FbxDocument* mDocument;
  261. };
  262. #include <fbxsdk/fbxsdk_nsend.h>
  263. #endif /* _FBXSDK_FILEIO_EXPORTER_H_ */