fbxmanager.h 19 KB

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