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 fbxwriter.h |
13 | #ifndef _FBXSDK_FILEIO_WRITER_H_ |
14 | #define _FBXSDK_FILEIO_WRITER_H_ |
15 | |
16 | #include <fbxsdk/fbxsdk_def.h> |
17 | |
18 | #include <fbxsdk/utils/fbxrenamingstrategy.h> |
19 | |
20 | #include <fbxsdk/fbxsdk_nsbegin.h> |
21 | |
22 | class FbxStatus; |
23 | class FbxManager; |
24 | class FbxFile; |
25 | class FbxStream; |
26 | class FbxObject; |
27 | class FbxDocument; |
28 | class FbxScene; |
29 | class FbxExporter; |
30 | class FbxIO; |
31 | class FbxIOSettings; |
32 | class FbxProgress; |
33 | |
34 | #define IOSP GetIOSettings() |
35 | |
36 | /** Base class of other writers used internally. |
37 | * This class provides the interfaces for writing files. |
38 | * |
39 | * The role of the writer is to effectively "write" specific file data |
40 | * vs the role of the exporter is to select a specific writer |
41 | * and launch the writing of a file through that writer. |
42 | * \see FbxExporter |
43 | * |
44 | * ex: |
45 | * - FbxWriterFbx5 can write FBX 5 format files |
46 | * - FbxWriterFbx6 can write FBX 6 format files |
47 | * - FbxWriterFbx7 can write FBX 7 format files |
48 | * - FbxWriterCollada can write Collada files |
49 | * - FbxWriterDxf can write Dxf files |
50 | * - ... etc. |
51 | * |
52 | * A SDK user should - normally - not use this class, |
53 | * except if a custom writer must be created for plug-in extension, |
54 | * then FbxWriter must be the base class for |
55 | * the new custom writer in that particular situation. |
56 | * \nosubgrouping |
57 | */ |
58 | class FBXSDK_DLL FbxWriter |
59 | { |
60 | public: |
61 | /** Constructor. |
62 | * \param pManager The FbxManager Object. |
63 | * \param pID Id for current writer. |
64 | * \param pStatus The FbxStatus object to hold error codes. |
65 | */ |
66 | FbxWriter(FbxManager& pManager, int pID, FbxStatus& pStatus); |
67 | |
68 | /** Destructor. */ |
69 | virtual ~FbxWriter(); |
70 | |
71 | /** Information type to request. |
72 | * \remarks Used internally to get writer file information. |
73 | */ |
74 | enum EInfoRequest |
75 | { |
76 | eInfoExtension, //!< To get the file ext for a writer ex: "FBX". |
77 | eInfoDescriptions, //!< To get the file description for a writer ex:"Autodesk FBX (*.fbx)". |
78 | eInfoVersions, //!< To get the file version for a writer ex: 7100. |
79 | eInfoCompatibleDesc, //!< To get the file compatible description for a writer. |
80 | eInfoUILabel, //!< To get the file UI label to show for a writer ex: file labels shown in "Open file dialog". |
81 | eReserved1 = 0xFBFB, |
82 | }; |
83 | |
84 | //! Helper typedef for passing FbxWriter creator function as argument (used internally). |
85 | typedef FbxWriter* (*CreateFuncType)(FbxManager& pManager, FbxExporter& pExporter, int pSubID, int pPluginID); |
86 | |
87 | //! Helper typedef for passing FbxIOSettings creator function as argument (used internally). |
88 | typedef void (*IOSettingsFillerFuncType)(FbxIOSettings& pIOS); |
89 | |
90 | //! Helper typedef for passing EInfoRequest function as argument (used internally). |
91 | typedef void* (*GetInfoFuncType)(EInfoRequest pRequest, int pWriterTypeId); |
92 | |
93 | /** Creates a new file. |
94 | * \param pFileName The name of the newly created file. |
95 | */ |
96 | virtual bool FileCreate(char* pFileName) = 0; |
97 | |
98 | /** Creates a new file via a stream. |
99 | * \param pStream The stream to write to. |
100 | * \param pStreamData the user-defined stream data to be written. |
101 | */ |
102 | virtual bool FileCreate(FbxStream* pStream, void* pStreamData); |
103 | |
104 | /** Closes the file. |
105 | */ |
106 | virtual bool FileClose() = 0; |
107 | |
108 | /** Test if the file is open. |
109 | */ |
110 | virtual bool IsFileOpen() = 0; |
111 | |
112 | /** Setup write options. |
113 | */ |
114 | virtual void GetWriteOptions() = 0; |
115 | |
116 | /** Writes content to the specified file with given stream options |
117 | * \param pDocument FbxDocument to write file data to. |
118 | */ |
119 | virtual bool Write(FbxDocument* pDocument) = 0; |
120 | |
121 | /** Pre-processes the scene. |
122 | * \param pScene The scene needs to be pre-processed. |
123 | */ |
124 | virtual bool PreprocessScene(FbxScene &pScene) = 0; |
125 | |
126 | /** Post-processes the scene. |
127 | * \param pScene The scene needs to be post-processed. |
128 | */ |
129 | virtual bool PostprocessScene(FbxScene &pScene) = 0; |
130 | |
131 | #ifndef FBXSDK_ENV_WINSTORE |
132 | /** Writes extension plug-ins name, version and parameters, so that we can remember if a plug-in was used during export. |
133 | * This is especially useful for extension plug-ins that modify the scene and also to warn users during import if an |
134 | * extension plug-in was used that could be missing. |
135 | * \param pParams The parameters of the extension plug-in. The properties of the objects are used |
136 | * as the parameters of the extension plug-in. |
137 | * \remark This function has no implementation in this class. Only sub-class should implement it as needed. For example, |
138 | * FBX 6 and FBX 7 does implement it. |
139 | */ |
140 | virtual void PluginWriteParameters(FbxObject& pParams); |
141 | #endif /* !FBXSDK_ENV_WINSTORE */ |
142 | |
143 | /** Finds the selected root node in the specified scene. |
144 | * \param pScene The scene in which the selected root node is found. |
145 | * \return The located root node.\c NULL if the selected root node cannot be found. |
146 | */ |
147 | virtual FbxNode* FindRootNode(FbxScene& pScene); |
148 | |
149 | /** Checks if there are spaces in the names of specified node (and its children nodes), |
150 | * and writes the returned node's name in the specified string list. |
151 | * \param pNode Specifies the node to check. |
152 | * \param pNodeNameList Specifies the string list where the node name that has spaces in it is recorded. |
153 | * \return \c true If there are no spaces in the name of specified node (and its children nodes), |
154 | * \c false If spaces are found. |
155 | */ |
156 | virtual bool CheckSpaceInNodeNameRecursive(FbxNode* pNode, FbxString& pNodeNameList); |
157 | |
158 | /** Sets the file export version as specified. |
159 | * \param pVersion The specified file export version. |
160 | */ |
161 | bool SetFileExportVersion(FbxString pVersion); |
162 | |
163 | /** Sets the renaming mode as specified. |
164 | * \param pRenamingMode The specified renaming mode. |
165 | */ |
166 | void SetRenamingMode(FbxSceneRenamer::ERenamingMode pRenamingMode){mRenamingMode = pRenamingMode;} |
167 | |
168 | /** Sets the resampling rate as specified. |
169 | * \param pResamplingRate The specified resampling rate. |
170 | */ |
171 | inline void SetResamplingRate(double pResamplingRate){mResamplingRate = pResamplingRate;} |
172 | |
173 | /** Test if file format is an internal plug-in . |
174 | * A non genuine plug-in is a plug-in made by someone external to Autodesk FBX SDK group. |
175 | * \return \c true If the file format is an internal plug-in ,\c false Otherwise . |
176 | */ |
177 | bool IsGenuine(); |
178 | |
179 | /** Access to a IOSettings object. |
180 | * \return The pointer to IOSettings or \c NULL \c if the object |
181 | * has not been allocated. |
182 | */ |
183 | virtual FbxIOSettings * GetIOSettings(); |
184 | |
185 | /** Set the IOSettings pointer to be used for this writer instance. |
186 | * \param pIOSettings |
187 | */ |
188 | virtual void SetIOSettings(FbxIOSettings * pIOSettings); |
189 | |
190 | /** Pass a progress handler to the writer. |
191 | * \param pProgress FbxProgress to store the progress information. |
192 | */ |
193 | virtual void SetProgressHandler(FbxProgress* /*pProgress*/){} |
194 | |
195 | /** Returns true if this writer supports FbxStream I/O. Default value is false. */ |
196 | virtual bool SupportsStreams() const; |
197 | |
198 | protected: |
199 | #ifndef FBXSDK_ENV_WINSTORE |
200 | //! Function called by FBX before writing out the scene (FbxScene). |
201 | void PluginsWriteBegin(FbxScene& pScene); |
202 | /** |
203 | * Function called by FBX before writing out any FBX object. |
204 | * \param pFbx File object. |
205 | * \param pWriteObjectId Flag to write out object id. |
206 | */ |
207 | void PluginsWrite(FbxIO& pFbx, bool pWriteObjectId); |
208 | //! Function called by FBX after writing out the scene (FbxScene). |
209 | void PluginsWriteEnd(FbxScene& pScene); |
210 | #endif /* !FBXSDK_ENV_WINSTORE */ |
211 | |
212 | /***************************************************************************************************************************** |
213 | ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! ** |
214 | *****************************************************************************************************************************/ |
215 | public: |
216 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
217 | FbxStatus& GetStatus() { return mStatus; } |
218 | |
219 | protected: |
220 | |
221 | FbxWriter& operator=(FbxWriter const&) { return *this; } |
222 | |
223 | FbxStatus& mStatus; |
224 | FbxManager& mManager; |
225 | FbxString mFileVersion; |
226 | //! Resample rate for animation. |
227 | double mResamplingRate; |
228 | //! The mode describing from which format to which format when write FBX file. |
229 | FbxSceneRenamer::ERenamingMode mRenamingMode; |
230 | |
231 | private: |
232 | int mInternalID; |
233 | FbxIOSettings * mIOSettings; |
234 | |
235 | friend struct FbxWriterFbx7_Impl; |
236 | #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/ |
237 | }; |
238 | |
239 | //! Helper to access the IOSetting object pointer as a ref ex: IOS_REF.GetBoolProp( ... ); |
240 | #define IOS_REF (*GetIOSettings()) |
241 | |
242 | #include <fbxsdk/fbxsdk_nsend.h> |
243 | |
244 | #endif /* _FBXSDK_FILEIO_WRITER_H_ */ |
245 | |