fbxplugin.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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 fbxplugin.h
  9. #ifndef _FBXSDK_CORE_PLUGIN_H_
  10. #define _FBXSDK_CORE_PLUGIN_H_
  11. #include <fbxsdk/fbxsdk_def.h>
  12. #ifndef FBXSDK_ENV_WINSTORE
  13. #include <fbxsdk/core/fbxobject.h>
  14. #include <fbxsdk/core/fbxmodule.h>
  15. #include <fbxsdk/core/fbxlistener.h>
  16. #include <fbxsdk/fbxsdk_nsbegin.h>
  17. class FbxManager;
  18. class FbxPluginContainer;
  19. //! Plug-in declaration macro that must to be used when defining new FbxPlugin objects.
  20. #define FBXSDK_PLUGIN_DECLARE(Plugin)\
  21. FBXSDK_FRIEND_NEW();\
  22. public:\
  23. static Plugin * Create(const FbxPluginDef& pDefinition, FbxModule pModuleHandle);\
  24. void Destroy();
  25. //! Plug-in implementation macro that must be used when implementing new FbxPlugin objects.
  26. #define FBXSDK_PLUGIN_IMPLEMENT(Plugin)\
  27. Plugin* Plugin::Create(const FbxPluginDef& pDefinition, FbxModule pModuleHandle){ return FbxNew<Plugin>(pDefinition, pModuleHandle); }\
  28. void Plugin::Destroy(){ FbxDelete(this); }
  29. /** Structure used by plug-ins for identification purposes.
  30. * \note To avoid confusions in the system, it is recommended to choose an appropriate unique identifier string name when
  31. * defining your plug-in, as well as incrementing the version string to a correct value whenever something changes in the
  32. * implementation of the plug-in. Both of these string are used when comparing plug-ins for searches, as well as
  33. * identification in FBX files.
  34. */
  35. struct FBXSDK_DLL FbxPluginDef
  36. {
  37. //! Constructor
  38. FbxPluginDef() :
  39. mName("Unknown Name"),
  40. mVersion("Unknown Version")
  41. {
  42. }
  43. FbxString mName; //!< The identifier name string of the plug-in. If the name is already used by another plug-in, the plug-in will still register.
  44. FbxString mVersion; //!< The version string of the plug-in.
  45. };
  46. /** Data used to communicate information between an application and the plug-in.
  47. */
  48. struct FBXSDK_DLL FbxPluginData
  49. {
  50. //! Constructor
  51. FbxPluginData() :
  52. mQueryEmitter(NULL),
  53. mSDKManager(NULL),
  54. mPluginContainer(NULL)
  55. {
  56. }
  57. //! Copy Constructor
  58. explicit FbxPluginData(const FbxPluginData& pOther) :
  59. mQueryEmitter(pOther.mQueryEmitter),
  60. mSDKManager(pOther.mSDKManager),
  61. mPluginContainer(pOther.mPluginContainer)
  62. {
  63. }
  64. FbxEmitter* mQueryEmitter; //!< The emitter on which the plug-in can listen to receive events.
  65. FbxManager* mSDKManager; //!< The FBX SDK Manager on which the plug-in was instanced.
  66. FbxPluginContainer* mPluginContainer; //!< The container which will have the ownership of the plug-in.
  67. };
  68. /** The base class to inherit from when creating new plug-ins for the FBX SDK. Plug-ins for the FBX SDK are extremely flexible
  69. * allowing a wide-range of possibilities. For example, one can write his own plug-in to add new readers/writers to the current list
  70. * of supported I/O formats, or add new dynamic classes to instantiate custom objects that can later be stored in FBX files. We also use the same
  71. * interface for plug-ins written using the FBX Extension SDK, which allow additional callbacks for other various Autodesk products
  72. * enabling greater interoperability with multiple various SDKs.
  73. *
  74. * Here is typical implementation of an FBX SDK plug-in that doesn't do anything else than just registering itself:
  75. * \code
  76. * class MyPlugin : public FbxPlugin
  77. * {
  78. * FBXSDK_PLUGIN_DECLARE(MyPlugin); //This macro is mandatory for any plug-in definition
  79. *
  80. * protected:
  81. * explicit MyPlugin(const FbxPluginDef& pDefinition, FbxModule pModuleHandle) : FbxPlugin(pDefinition, pModuleHandle)
  82. * {
  83. * }
  84. *
  85. * //Abstract functions that *must* be implemented
  86. * virtual bool SpecificInitialize()
  87. * {
  88. * //For example, here we could register as many new I/O readers/writers as we would like, or classes, etc.
  89. * return true;
  90. * }
  91. *
  92. * virtual bool SpecificTerminate()
  93. * {
  94. * //Here we would have to unregister whatever we registered to the FBX SDK
  95. * return true;
  96. * }
  97. * };
  98. *
  99. * FBXSDK_PLUGIN_IMPLEMENT(MyPlugin); //This macro is mandatory for any plug-in implementation
  100. *
  101. * //Standard C export needed for any new FBX SDK plug-in
  102. * extern "C"
  103. * {
  104. * static MyPlugin* sMyPluginInstance = NULL; //The module is owner of the plug-in
  105. *
  106. * //This function will be called when an application will request the plug-in
  107. * #ifdef FBXSDK_ENV_WIN
  108. * __declspec(dllexport) void FBXPluginRegistration(FbxPluginContainer& pContainer, FbxModule pModuleHandle)
  109. * #else
  110. * void FBXPluginRegistration(FbxPluginContainer& pContainer, FbxModule pModuleHandle)
  111. * #endif
  112. * {
  113. * if( sPlugin == NULL )
  114. * {
  115. * //Create the plug-in definition which contains the information about the plug-in
  116. * FbxPluginDef sPluginDef;
  117. * sPluginDef.mName = "My Plugin";
  118. * sPluginDef.mVersion = "1.0";
  119. *
  120. * //Create an instance of the plug-in
  121. * sMyPluginInstance = MyPlugin::Create(sPluginDef, pLibHandle);
  122. *
  123. * //Register the plug-in with the FBX SDK
  124. * pContainer.Register(*sPlugin);
  125. * }
  126. * }
  127. * }
  128. * \endcode
  129. * \see FbxPluginDef, FbxPluginData
  130. */
  131. class FBXSDK_DLL FbxPlugin : public FbxListener
  132. {
  133. FBXSDK_INTRUSIVE_LIST_NODE(FbxPlugin, 1);
  134. public:
  135. /** Abstract function called once at the end of the plug-in construction. At that moment, plug-in data have been properly initialized.
  136. * This function must be implemented by anyone who writes a new plug-in for the FBX SDK.
  137. */
  138. virtual bool SpecificInitialize()=0;
  139. /** Abstract function called once at the beginning of the plug-in destruction. At that moment, plug-in data is fully available.
  140. * This function must be implemented by anyone who writes a new plug-in for the FBX SDK.
  141. */
  142. virtual bool SpecificTerminate()=0;
  143. /** Virtual function called once when the FBX SDK is about to write an FBX file. Users can re-implement it in their plug-in if they need
  144. * to perform tasks at that moment. The scene provided in parameter can be altered. If not re-implemented, this function does nothing.
  145. * \param pScene The scene that is about to be written in the FBX file.
  146. */
  147. virtual void WriteBegin(FbxScene& pScene);
  148. /** Virtual function called once when the FBX SDK is about to write plug-in's parameters. Users can re-implement it in their plug-in if they need
  149. * to store properties in the FBX file for their own usage. The object in parameter is used to store those properties.
  150. * If not re-implemented, this function does nothing.
  151. * \param pParams An abstract object that can be used as a property container, to allow the plug-in to store properties about the plug-in.
  152. */
  153. virtual void WriteParameters(FbxObject& pParams);
  154. /** Virtual function called once after the FBX SDK wrote an FBX file. Users can re-implement it in their plug-in if they need
  155. * to perform tasks at that moment. The scene provided in parameter can be altered, but the changes will not appear in the FBX file.
  156. * If not re-implemented, this function does nothing.
  157. * \param pScene The scene that was written in the FBX file.
  158. */
  159. virtual void WriteEnd(FbxScene& pScene);
  160. /** Virtual function called once when the FBX SDK is about to read an FBX file. Users can re-implement it in their plug-in if they need
  161. * to perform tasks at that moment. The scene provided in parameter can be altered. If not re-implemented, this function does nothing.
  162. * \param pScene The scene that is about to be read in the FBX file.
  163. */
  164. virtual void ReadBegin(FbxScene& pScene);
  165. /** Virtual function called once after the FBX SDK reads the plug-in's parameters. Users can re-implement it in their plug-in if they need
  166. * to retrieve properties for their own usage. The object in parameter is used to retrieve those properties.
  167. * If not re-implemented, this function does nothing.
  168. * \param pParams An abstract object that can be used as a property container, to allow the plug-in to read properties about the plug-in.
  169. */
  170. virtual void ReadParameters(FbxObject& pParams);
  171. /** Virtual function called once after the FBX SDK read an FBX file. Users can re-implement it in their plug-in if they need
  172. * to perform tasks at that moment. The scene provided in parameter can be altered. If not re-implemented, this function does nothing.
  173. * \param pScene The scene that was read in the FBX file.
  174. */
  175. virtual void ReadEnd(FbxScene& pScene);
  176. /** Accessor to the plug-in definition structure that contains basic information on the plug-in like its name or version. This is
  177. * the only method available to differentiate plug-ins.
  178. * \return The definition structure for this plug-in.
  179. */
  180. const FbxPluginDef& GetDefinition() const;
  181. /** Retrieve the module address pointer for this plug-in. With this module instance handle, for example someone can query procedures addresses,
  182. * allowing more complex interactions, as well as other operating system module specific functions.
  183. */
  184. FbxModule GetModuleHdl();
  185. protected:
  186. /** Use the Create() and Destroy() methods declared and implemented in the FBXSDK_PLUGIN_DECLARE and FBXSDK_PLUGIN_IMPLEMENT macros to construct and destroy FbxPlugin objects.
  187. * \param pDefinition The definition associated with this plug-in. Each plug-in must have its own definition to differentiate it with other plug-ins.
  188. * \param pModuleHandle A pointer to the plug-in module address.
  189. */
  190. explicit FbxPlugin(const FbxPluginDef& pDefinition, FbxModule pModuleHandle);
  191. /** Accessor to the plug-in private data.
  192. * \return The data for the current plug-in.
  193. */
  194. FbxPluginData& GetData();
  195. /** Const accessor to the plug-in private data.
  196. * \return The const data for the current plug-in.
  197. */
  198. const FbxPluginData& GetData() const;
  199. /*****************************************************************************************************************************
  200. ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
  201. *****************************************************************************************************************************/
  202. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  203. public:
  204. inline FbxObject& GetPluginSettings() { return *mPluginSettings; }
  205. inline const FbxObject& GetPluginSettings() const { return *mPluginSettings; }
  206. template <typename EventType, typename ListernerType> inline FbxEventHandler* Bind(void (ListernerType::*pFunc)(const EventType*))
  207. {
  208. return FbxListener::Bind<EventType,ListernerType>(*(GetData().mQueryEmitter), pFunc );
  209. }
  210. virtual void Destroy() = 0;
  211. protected:
  212. virtual ~FbxPlugin();
  213. private:
  214. bool Initialize(const FbxPluginData& pData);
  215. bool Terminate();
  216. bool mInitialized;
  217. FbxPluginData mData;
  218. FbxPluginDef mDefinition;
  219. FbxModule mModuleHandle;
  220. FbxObject* mPluginSettings;
  221. friend class FbxLoadingStrategy;
  222. #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
  223. };
  224. #include <fbxsdk/fbxsdk_nsend.h>
  225. #endif /* !FBXSDK_ENV_WINSTORE */
  226. #endif /* _FBXSDK_CORE_PLUGIN_H_ */