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 fbxmanager.h
13#ifndef _FBXSDK_CORE_MANAGER_H_
14#define _FBXSDK_CORE_MANAGER_H_
15
16#include <fbxsdk/fbxsdk_def.h>
17
18#include <fbxsdk/core/fbxobject.h>
19
20#include <fbxsdk/fbxsdk_nsbegin.h>
21
22class FbxIOSettings;
23class FbxIOPluginRegistry;
24class FbxAnimEvaluator;
25class FbxSceneReference;
26class FbxUserNotification;
27class FbxMessageEmitter;
28class FbxLocalizationManager;
29class FbxXRefManager;
30class FbxManager_internal;
31
32#ifndef FBXSDK_ENV_WINSTORE
33 class FbxPlugin;
34#endif
35
36/** SDK object manager.
37 * The SDK manager is in charge of:
38 * \li scene element allocation, for example, FbxScene::Create(pSdkManager, "").
39 * \li scene element deallocation, call FbxManager::Destroy() to deallocates all object created by the SDK manager.
40 * \li scene element search and access, please see \ref GlobalObjectManagement section.
41 *
42 * It is possible to override memory allocation functions throughout the FBX SDK by
43 * providing system memory allocation functions using the handler set functions below.
44 * It must be done before the first FbxManager creation.
45 *
46 * FbxSetMallocHandler();
47 * FbxSetCallocHandler();
48 * FbxSetReallocHandler();
49 * FbxSetFreeHandler();
50 *
51 * Upon destruction, all objects allocated by the SDK manager and not explicitly destroyed are destroyed as well.
52 * A derived class can be defined to allocate and deallocate specialized scene elements.
53 * \remarks You could create more than one SDK manager. However, it's better to NOT share the same object among different managers.
54 * \nosubgrouping
55 */
56class FBXSDK_DLL FbxManager
57{
58public:
59 /**
60 * \name FBX SDK Manager Creation/Destruction
61 */
62 //@{
63 /** SDK manager allocation method.
64 * \return A pointer to the SDK manager or \c NULL if this is an
65 * evaluation copy of the FBX SDK and it is expired.
66 */
67 static FbxManager* Create();
68
69 /** Destructor.
70 * Deallocates all object previously created by the SDK manager.
71 */
72 virtual void Destroy();
73 //@}
74
75 /**
76 * \name Versions Queries
77 */
78 //@{
79 /** Get FBX SDK version string.
80 * \param pFull If true, the complete version string including revision number and release date will be returned,
81 * otherwise only the version numbering is returned.
82 */
83 static const char* GetVersion(bool pFull=true);
84
85 /** Get the current default FBX file format version number for this version of the FBX SDK.
86 * \param pMajor Version major number.
87 * \param pMinor Version minor number.
88 * \param pRevision Version revision number.
89 */
90 static void GetFileFormatVersion(int& pMajor, int& pMinor, int& pRevision);
91 //@}
92
93
94 /**
95 * \name Object Registration, Definition and Management
96 */
97 //@{
98 /** Class registration.
99 * \param pName The class name. For example, "FbxMesh" for FbxMesh class.
100 * \param T1 FBX type of the specified class.
101 * \param T2 FBX type of parent class.
102 * \param pFbxFileTypeName The type name of the class in FBX file.
103 * \param pFbxFileSubTypeName The sub type name of the class in FBX file.
104 * \return The class Id of the newly register class.
105 * Such as:
106 * \code RegisterFbxClass("FbxCamera", FBX_TYPE(FbxCamera), FBX_TYPE(FbxNodeAttribute)); \endcode
107 */
108 template <typename T1, typename T2> inline FbxClassId RegisterFbxClass(const char* pName, const T1* /*T1*/, const T2* /*T2*/, const char* pFbxFileTypeName=0, const char* pFbxFileSubTypeName=0)
109 {
110 T1::ClassId = Internal_RegisterFbxClass(pName, T2::ClassId, (FbxObjectCreateProc)T1::Allocate, pFbxFileTypeName, pFbxFileSubTypeName);
111 return T1::ClassId;
112 }
113
114 /** Runtime class registration.
115 * \param pName The class name. For example, "FbxUIWidgetBoolean".
116 * \param T FBX type of parent class.
117 * \param pFbxFileTypeName The type name of the class in FBX file.
118 * \param pFbxFileSubTypeName The sub type name of the class in FBX file.
119 * \return The class Id of the newly register class.
120 * Such as:
121 * \code RegisterRuntimeFbxClass( "FbxUIWidgetBoolean", FBX_TYPE(FbxUIWidgetDefinition), NULL, "FbxUIWidgetBoolean"); \endcode
122 */
123 template <typename T> inline FbxClassId RegisterRuntimeFbxClass(const char* pName, const T* /*T*/, const char* pFbxFileTypeName=0,const char* pFbxFileSubTypeName=0)
124 {
125 return Internal_RegisterFbxClass(pName, T::ClassId, (FbxObjectCreateProc)T::Allocate, pFbxFileTypeName, pFbxFileSubTypeName);
126 }
127
128 /** Runtime class unregistration.
129 * \param pName The class name.
130 */
131 inline void UnregisterRuntimeFbxClass(const char* pName)
132 {
133 FbxClassId lClassId = FindClass(pName);
134 if( !(lClassId == FbxClassId()) )
135 {
136 Internal_UnregisterFbxClass(lClassId);
137 }
138 }
139
140 /** Override class.
141 * \param pFBX_TYPE_Class FBX type of class.
142 * \param pFBX_TYPE_OverridenClass FBX type of overridden class.
143 * \return The class Id
144 */
145 template <typename T1,typename T2> inline FbxClassId OverrideFbxClass(const T1* pFBX_TYPE_Class, const T2* pFBX_TYPE_OverridenClass)
146 {
147 T1::ClassId = Internal_OverrideFbxClass(T2::ClassId,(FbxObjectCreateProc)T1::Allocate );
148 return T1::ClassId;
149 }
150
151 /** Create a new object of the specified ClassId.
152 * \param pClassId The ClassId of the object to be created.
153 * \param pName The name given to the newly created object.
154 * \param pContainer An optional parameter to specify which object will "contain" the new object. By contain, we mean
155 * the new object will become a source to the container, connection-wise.
156 * \param pCloneFrom A valid object pointer to use as the reference for cloning the object upon construction.
157 * \return If not null, a new instance of the specified class.
158 * \remark This function will return NULL if the ClassId used is invalid. New ClassId can be registered using
159 * the function RegisterFbxClass().
160 */
161 FbxObject* CreateNewObjectFromClassId(FbxClassId pClassId, const char* pName, FbxObject* pContainer=NULL, const FbxObject* pCloneFrom=NULL);
162
163 /** Find class by the specified name.
164 * \param pClassName Class Name to find.
165 */
166 FbxClassId FindClass(const char* pClassName) const;
167
168 /** Find file class.
169 * \param pFbxFileTypeName Specify the type name in FBX file to find.
170 * \param pFbxFileSubTypeName Specify by The sub type name in FBX file to find.
171 */
172 FbxClassId FindFbxFileClass(const char* pFbxFileTypeName, const char* pFbxFileSubTypeName) const;
173
174 /** Class unregistration.
175 * \param pFBX_TYPE_Class FBX type of unregistered class.
176 */
177 template <typename T> inline void UnregisterFbxClass(const T* pFBX_TYPE_Class)
178 {
179 Internal_UnregisterFbxClass(T::ClassId);
180 T::ClassId = FbxClassId();
181 }
182 //@}
183
184 /**
185 * \name Data Type Management
186 */
187 //@{
188 /** Register a new data type to the manager
189 * \param pName The type name.
190 * \param pType The data type.
191 * \return The newly created FbxDataType
192 */
193 FbxDataType CreateDataType(const char* pName, const EFbxType pType);
194
195 /** List the data types
196 * \return the number of registered datatypes
197 */
198 int GetDataTypeCount() const;
199
200 /** Find a data types at pIndex.
201 * \param pIndex The data type index.
202 * \return the found datatype. return null if not found
203 */
204 FbxDataType& GetDataType(const int pIndex) const;
205
206 /** Find a data type from the type name.
207 * \param pDataType The type name.
208 * \return the found datatype. return null if not found
209 */
210 FbxDataType& GetDataTypeFromName(const char* pDataType) const;
211 //@}
212
213 /**
214 * \name User Notification Object
215 */
216 //@{
217 /** Access to the unique UserNotification object.
218 * \return The pointer to the user notification or \c NULL \c if the object
219 * has not been allocated.
220 */
221 FbxUserNotification* GetUserNotification() const;
222
223 /** Set the user notification
224 * \param pUN
225 */
226 void SetUserNotification(FbxUserNotification* pUN);
227 //@}
228
229 /**
230 * \name IOSettings Object
231 */
232 //@{
233 /** Access to a IOSettings object.
234 * \return The pointer to IOSettings or \c NULL \c if the object
235 * has not been allocated.
236 */
237 virtual FbxIOSettings* GetIOSettings() const;
238
239 /** Set the IOSettings pointer
240 * \param pIOSettings
241 */
242 virtual void SetIOSettings(FbxIOSettings* pIOSettings);
243 //@}
244
245
246 /**
247 * \name Message Emitter (for Message Logging)
248 */
249 //@{
250 /** Access to the unique FbxMessageEmitter object.
251 * \return The pointer to the message emitter.
252 */
253 FbxMessageEmitter& GetMessageEmitter();
254 /** Sets to the unique FbxMessageEmitter object.
255 * \param pMessageEmitter the emitter to use, passing NULL will reset to the default emitter.
256 * The object will be deleted when the SDK manager is destroyed, thus ownership is transfered.
257 */
258 bool SetMessageEmitter(FbxMessageEmitter* pMessageEmitter);
259 //@}
260
261
262 /**
263 * \name Localization Hierarchy
264 */
265 //@{
266 /** Add a localization object to the known localization providers.
267 * \param pLocManager the localization object to register.
268 */
269 void AddLocalization(FbxLocalizationManager* pLocManager);
270
271 /** Remove a localization object from the known localization providers.
272 * \param pLocManager the localization object to remove.
273 */
274 void RemoveLocalization(FbxLocalizationManager* pLocManager);
275
276 /** Select the current locale for localization.
277 * \param pLocale the locale name, for example "fr" or "en-US".
278 */
279 bool SetLocale(const char* pLocale);
280
281 /** Localization helper function. Calls each registered localization manager
282 * until one can localizes the text.
283 * \param pID the identifier for the text to localize.
284 * \param pDefault the default text. Uses pID if NULL.
285 * \return the potentially localized text. May return the parameter passed in.
286 */
287 const char* Localize(const char* pID, const char* pDefault=NULL) const;
288 //@}
289
290 /**
291 * \name XRef Manager
292 */
293 //@{
294 /** Retrieve the manager responsible for managing object XRef resolution.
295 * \return The XRef manager for this SDK manager.
296 */
297 FbxXRefManager& GetXRefManager();
298 //@}
299
300 /**
301 * \name Library Management
302 */
303 //@{
304 /** Retrieve the main object Libraries
305 * \return The Root library
306 */
307 FbxLibrary* GetRootLibrary() const;
308 FbxLibrary* GetSystemLibraries() const;
309 FbxLibrary* GetUserLibraries() const;
310 //@}
311
312 /**
313 * \name Plug-in Registry Object
314 */
315 //@{
316 /** Access to the unique FbxIOPluginRegistry object.
317 * \return The pointer to the user FbxIOPluginRegistry
318 */
319 FbxIOPluginRegistry* GetIOPluginRegistry() const;
320 //@}
321
322 /**
323 * \name Fbx Generic Plugins Management
324 */
325 //@{
326 #ifndef FBXSDK_ENV_WINSTORE
327 /** Load plug-ins directory
328 * \param pFilename The directory path.
329 * \param pExtensions The plug in extension.
330 * \return \c True
331 */
332 bool LoadPluginsDirectory(const char* pFilename, const char* pExtensions=NULL);
333
334 /** Load plug-in
335 * \param pFilename The file name
336 * \return \c True
337 */
338 bool LoadPlugin(const char* pFilename);
339
340 /** Unload all plug-ins
341 */
342 bool UnloadPlugins();
343
344 /** Emit plugins event.
345 * \param pEvent The event to be emitted.
346 */
347 bool EmitPluginsEvent(const FbxEventBase& pEvent);
348
349 //!Get plugins.
350 FbxArray<const FbxPlugin*> GetPlugins() const;
351
352 /** get plugins count
353 * \return The number of plugins.
354 */
355 int GetPluginCount() const;
356
357 /** Find plug in.
358 * \param pName The plug in name.
359 * \param pVersion The plug in version.
360 * \return The plugin, \c null if not found.
361 */
362 FbxPlugin* FindPlugin(const char* pName, const char* pVersion) const;
363 #endif /* !FBXSDK_ENV_WINSTORE */
364 //@}
365
366
367 /**
368 * \name IO Settings
369 */
370 //@{
371 // Add IOSettings in hierarchy from different modules
372
373 /** Fill IO Settings for registered readers.
374 * \param pIOS The properties hierarchies to fill.
375 */
376 void FillIOSettingsForReadersRegistered(FbxIOSettings& pIOS);
377
378 /** Fill IO Settings for registered writers.
379 * \param pIOS The properties hierarchies to fill.
380 */
381 void FillIOSettingsForWritersRegistered(FbxIOSettings& pIOS);
382
383 /** Fill common IO Settings
384 * \param pIOS The properties hierarchies to fill.
385 * \param pImport If \c true, import properties are set, otherwise export properties are set.
386 */
387 void FillCommonIOSettings(FbxIOSettings& pIOS, bool pImport);
388 //@}
389
390 /**
391 * \name Global Object Management
392 */
393 //@{
394 /** Register object with the manager.
395 * \internal
396 * \param pObject The object to be registered.
397 * \anchor GlobalObjectManagement
398 */
399 void RegisterObject(FbxObject* pObject);
400
401 /** Unregister object with the manager.
402 * \internal
403 * \param pObject The object to be unregistered.
404 */
405 void UnregisterObject(FbxObject* pObject);
406
407 /** Register a list of objects with the manager.
408 * \internal
409 * \param pArray The list of object to be registered.
410 */
411 void RegisterObjects(const FbxArray<FbxObject*>& pArray);
412
413 /** Unregister a list of objects with the manager.
414 * \internal
415 * \param pArray The list of object to be unregistered.
416 */
417 void UnregisterObjects(const FbxArray<FbxObject*>& pArray);
418
419 /** Increment the scene destroying counter.
420 * \remarks Call this function before the destroying list is changed.
421 */
422 void IncreaseDestroyingSceneFlag();
423 /** Shrink the object list and decrements the scene destroying counter.
424 * \remarks Call this function after the destroying is changed.
425 * Use IncreasDestroyingSceneFlag() and DecreaseDestroyingSceneFlag() in pairs.
426 */
427 void DecreaseDestroyingSceneFlag();
428 /**
429 * \name Reference Management
430 */
431 //@{
432 /** Get number of references.
433 * \return Number of references.
434 */
435 int GetReferenceCount() const;
436
437 /** Get reference at given index.
438 * \param pIndex Position in the list of references.
439 * \return Pointer to the reference or \c NULL if index is out of bounds.
440 */
441 FbxSceneReference* GetReference(int pIndex) const;
442
443 /** Add a reference.
444 * \param pReference The reference to be added.
445 * \return If the reference is correctly added to the scene, return \c true otherwise, if the reference is
446 * already there, returns \c false.
447 */
448 int AddReference(FbxSceneReference* pReference);
449
450 /** Remove the specified reference from reference list.
451 * \param pReference The reference to be removed.
452 * \return If the reference was successfully removed, return \c true otherwise, if the
453 * reference could not be found returns \c false.
454 */
455 bool RemoveReference(FbxSceneReference* pReference);
456
457 /** Clear the specified reference from the SDK manager.
458 * \param pReference The reference to be removed.
459 * \return If the reference was successfully cleared from the SDK manager, return \c true otherwise, if the
460 * reference could not be found returns \c false.
461 */
462 bool ClearReference(FbxSceneReference* pReference);
463 //@}
464
465 /** Add a prefix to a name.
466 * \param pPrefix The prefix to be added to the \c pName. This
467 * string must contain the "::" characters in order to be considered
468 * as a prefix.
469 * \param pName The name to be prefix.
470 * \return The prefixed string
471 * \remarks If a prefix already exists, it is removed before
472 * adding \c pPrefix.
473 */
474 static FbxString PrefixName(const char* pPrefix, const char* pName);
475
476 /** Get the count of document available in this manager
477 * \return The count of document owned by this manager.
478 */
479 int GetDocumentCount();
480
481 /** Get the document at pIndex in the manager's list.
482 * \param pIndex The index of the document to retrieve.
483 * \return The document at the specified index. Will return NULL if index is invalid.
484 */
485 FbxDocument* GetDocument(int pIndex);
486
487/*****************************************************************************************************************************
488** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
489*****************************************************************************************************************************/
490#ifndef DOXYGEN_SHOULD_SKIP_THIS
491 static FbxManager* GetDefaultManager();
492 void CreateMissingBindPoses(FbxScene* pScene);
493 int GetBindPoseCount(FbxScene *pScene) const;
494 int GetFbxClassCount() const;
495 FbxClassId GetNextFbxClass(FbxClassId pClassId /* invalid id: first one */) const;
496
497protected:
498 FbxManager();
499 virtual ~FbxManager();
500
501 void Clear();
502 void ClassInit();
503 void ClassRelease();
504 void DataTypeInit();
505 void DataTypeRelease();
506
507private:
508 bool CanAutoDestroySrcObject(FbxObject* pObject, FbxObject* pSrcObject, bool pRecursive) const;
509
510 void Create_Common_Import_IOSettings_Groups(FbxIOSettings& pIOS);
511 void Create_Common_Export_IOSettings_Groups(FbxIOSettings& pIOS);
512 void Add_Common_Import_IOSettings(FbxIOSettings& pIOS);
513 void Add_Common_Export_IOSettings(FbxIOSettings& pIOS);
514 void Add_Common_RW_Import_IOSettings(FbxIOSettings& pIOS);
515 void Add_Common_RW_Export_IOSettings(FbxIOSettings& pIOS);
516
517 FbxClassId Internal_RegisterFbxClass(const char* pClassName, FbxClassId pParentClassId, FbxObjectCreateProc=0, const char* pFbxFileTypeName=0, const char* pFbxFileSubTypeName=0);
518 bool Internal_RegisterFbxClass(FbxClassId pClassId);
519 FbxClassId Internal_OverrideFbxClass(FbxClassId pClassId, FbxObjectCreateProc=0);
520 void Internal_UnregisterFbxClass(FbxClassId pClassId);
521
522 void RemoveObjectsOfType(const FbxClassId& pClassId);
523
524 FbxAnimEvaluator* GetDefaultAnimationEvaluator();
525
526 FbxArray<FbxObject*> mObjects;
527 FbxArray<FbxDocument*> mDocuments;
528
529 FbxIOSettings* mIOSettings;
530 FbxIOPluginRegistry* mRegistry;
531 FbxUserNotification* mUserNotification;
532 FbxMessageEmitter* mMessageEmitter;
533 FbxArray<FbxLocalizationManager*> mLocalizationManagerArray;
534 FbxArray<FbxSceneReference*> mSceneReferenceArray;
535 FbxAnimEvaluator* mDefaultAnimationEvaluator;
536
537 FbxArray<FbxObject*> mDestroyingObjects;
538 FbxArray<FbxDocument*> mDestroyingDocuments;
539 int mIsDestroyingScene;
540
541 FbxManager_internal* mInternal;
542 static FbxManager* smDefaultManager;
543
544 FBXSDK_FRIEND_NEW();
545 friend class FbxObject;
546 friend class FbxProperty; //For GetDefaultAnimationEvaluator()
547 friend class FbxNode; //For GetDefaultAnimationEvaluator()
548 friend class FbxScene; //For GetDefaultAnimationEvaluator()
549 friend class FbxAnimEvaluator; //For GetDefaultAnimationEvaluator()
550#endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
551};
552
553#include <fbxsdk/fbxsdk_nsend.h>
554
555#endif /* _FBXSDK_CORE_MANAGER_H_ */
556