fbxlibrary.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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 fbxlibrary.h
  9. #ifndef _FBXSDK_SCENE_LIBRARY_H_
  10. #define _FBXSDK_SCENE_LIBRARY_H_
  11. #include <fbxsdk/fbxsdk_def.h>
  12. #include <fbxsdk/scene/fbxdocument.h>
  13. #include <fbxsdk/scene/fbxobjectfilter.h>
  14. #include <fbxsdk/fbxsdk_nsbegin.h>
  15. class FbxLocalizationManager;
  16. class FbxCriteria;
  17. /** This library class represents libraries that store sub-libraries and shading objects.
  18. * Shading objects are objects of class FbxTexture, FbxSurfaceMaterial, and FbxLight.
  19. * \nosubgrouping
  20. */
  21. class FBXSDK_DLL FbxLibrary : public FbxDocument
  22. {
  23. FBXSDK_OBJECT_DECLARE(FbxLibrary, FbxDocument);
  24. public:
  25. //! Returns a pointer to the parent library if one exists.
  26. FbxLibrary* GetParentLibrary(void) const;
  27. /** Sets whether not this library is a system library.
  28. * \param pSystemLibrary A flag which indicates whether or not this library is a system library.
  29. */
  30. void SystemLibrary(bool pSystemLibrary);
  31. //! Returns whether or not this library is a system library.
  32. bool IsSystemLibrary() const;
  33. /** The prefix must not include the dash and language code, nor
  34. * can it contain the extension. But if you want, it can contain
  35. * a folder or sub-folder, such as: locales/mydocloc.
  36. * This is resolved using the XRef Manager, with priority
  37. * given to the library's ".fbm" folder, if one exists.
  38. * \param pPrefix New prefix to be set.
  39. */
  40. void LocalizationBaseNamePrefix(const char* pPrefix);
  41. //! Retrieves the localization prefix.
  42. FbxString LocalizationBaseNamePrefix() const;
  43. // =======================================================================
  44. //
  45. // sub-library
  46. //
  47. // =======================================================================
  48. /** Adds a sub-library
  49. * \param pSubLibrary The sub-library to be added.
  50. * \return \c True if adding the sub-library is successful, returns \c false if not.
  51. */
  52. bool AddSubLibrary(FbxLibrary* pSubLibrary);
  53. /** Removes a sub-library
  54. * \param pSubLibrary The sub-library to be removed.
  55. * \return \c True if the sub-library is removed, \c false if not.
  56. */
  57. bool RemoveSubLibrary(FbxLibrary* pSubLibrary);
  58. //! Returns the total number of sub-libraries
  59. int GetSubLibraryCount(void) const;
  60. /** Returns the sub-library at the specified index.
  61. * \param pIndex The sub-library index.
  62. */
  63. FbxLibrary* GetSubLibrary(int pIndex) const;
  64. /** Clones the specified asset.
  65. * \param pToClone The asset to be cloned.
  66. * \param pOptionalDestinationContainer The container for the asset copy.
  67. * \remarks The asset and all its dependents are cloned.
  68. */
  69. FbxObject* CloneAsset( FbxObject* pToClone, FbxObject* pOptionalDestinationContainer = NULL) const;
  70. /** Returns a criteria filter which you can use to filter objects
  71. * when iterating items in the library. Only real 'assets' are returned,
  72. * rather than FBX support objects. This currently includes
  73. * lights, environments, materials and textures (maps).
  74. * This is typically used to IMPORT from a library.
  75. */
  76. static FbxCriteria GetAssetCriteriaFilter();
  77. /** Returns a filter which you should use when you clone / export objects.
  78. * This filters out objects that should remain in the asset library.
  79. *
  80. * Use this to EXPORT from a library (or CLONE from a library).
  81. */
  82. static FbxCriteria GetAssetDependentsFilter();
  83. /** Transfers ownership from the source library to this library for any assets passing through the filter.
  84. * It is assumed that name conflicts and other details have been resolved beforehand.
  85. *
  86. * External asset files required by the assets are copied (not moved). It's
  87. * up to the owner of the source library to clean up the files if the files are
  88. * not on a read-only transport. If this document hasn't been committed yet,
  89. * the assets will not be copied.
  90. *
  91. * Returns true if no filtered assets were skipped. If no assets pass through
  92. * the filter, it returns true, because nothing has been skipped.
  93. *
  94. * This may leave the source library in an invalid state. For example, the source library
  95. * would be in an invalid state if you had decided to transfer texture objects to the library,
  96. * but materials were kept in the source library.
  97. *
  98. * To safeguard against this, the transfer disconnects objects, and thus materials
  99. * are left without textures.
  100. *
  101. * When you transfer an object, all its dependents come with it. If you move
  102. * a material, it takes the associated textures as well. Although if you moved a texture,
  103. * the material would not be transferred with it.
  104. * \param pSrcLibrary The source library to be imported.
  105. * \return \c True if no filtered assets are skipped.
  106. **/
  107. bool ImportAssets(FbxLibrary* pSrcLibrary);
  108. /** Transfers ownership from the source library to this library for any assets passing through the filter.
  109. * It is assumed that name conflicts and other details have been resolved beforehand.
  110. *
  111. * External asset files required by the assets are copied (not moved). It's
  112. * up to the owner of the source library to clean up the files if the files are
  113. * not on a read-only transport. If this document hasn't been committed yet,
  114. * the assets will not be copied.
  115. *
  116. * Returns true if no filtered assets were skipped. If no assets pass through
  117. * the filter, it returns true, because nothing has been skipped.
  118. *
  119. * This may leave the source library in an invalid state. For example, the source library
  120. * would be in an invalid state if you had decided to transfer texture objects to the library,
  121. * but materials were kept in the source library.
  122. *
  123. * To safeguard against this, the transfer disconnects objects, and thus materials
  124. * are left without textures.
  125. *
  126. * When you transfer an object, all its dependents come with it. If you move
  127. * a material, it takes the associated textures as well. Although if you moved a texture,
  128. * the material would not be transferred with it.
  129. * \param pSrcLibrary The source library to be imported.
  130. * \param pAssetFilter The asset filter.
  131. * \return \c True if no filtered assets are skipped.
  132. **/
  133. bool ImportAssets(FbxLibrary* pSrcLibrary, const FbxCriteria& pAssetFilter);
  134. /** Returns a new instance of a library member.
  135. * This instantiates the first object found that matches the filter.
  136. * \param pFBX_TYPE The type of member
  137. * \param pFilter A user specified filter
  138. * \param pRecurse A flag that indicates whether to check sub-libraries
  139. * \param pOptContainer Optional container for the cloned asset
  140. * \return A new instance of the member. Note that the new member is not included with this library.
  141. */
  142. template < class T > T* InstantiateMember( const T* pFBX_TYPE, const FbxObjectFilter& pFilter, bool pRecurse = true, FbxObject* pOptContainer = NULL);
  143. // =======================================================================
  144. //
  145. // Localization
  146. //
  147. // =======================================================================
  148. /** Returns the localization manager for the library.
  149. */
  150. FbxLocalizationManager& GetLocalizationManager() const;
  151. /** Localization helper function. Calls the FBX SDK manager implementation.
  152. * Sub-classes that manage their own localization can over-ride this function.
  153. * \param pID The identifier for the text to localize.
  154. * \param pDefault The default text. Uses pID if NULL.
  155. * \return The potentially localized text. May return the parameter passed in.
  156. */
  157. virtual const char* Localize( const char* pID, const char* pDefault = NULL ) const;
  158. // =======================================================================
  159. //
  160. // Shading Object
  161. //
  162. // =======================================================================
  163. /** Adds a shading object.
  164. * \param pShadingObject The shading object to be added.
  165. */
  166. bool AddShadingObject(FbxObject* pShadingObject);
  167. /** Removes a shading object.
  168. * \param pShadingObject The shading object to be removed.
  169. */
  170. bool RemoveShadingObject(FbxObject* pShadingObject);
  171. //! Returns the total number of shading objects
  172. int GetShadingObjectCount(void) const;
  173. /** Returns the shading object at the specified index.
  174. * \param pIndex Shading object index.
  175. * \return The shading object located at the specified index.
  176. */
  177. FbxObject* GetShadingObject(int pIndex) const;
  178. /** Returns the number of shading objects according to their implementations.
  179. * \param pCriteria Filtering criteria that identifies what kind of
  180. * implementations to consider.
  181. * \returns The number of shading objects corresponding to the filtering parameters
  182. */
  183. int GetShadingObjectCount(const FbxImplementationFilter& pCriteria) const;
  184. /** Returns a handle on the shading object at the specified index that corresponds to the given filtering parameters.
  185. * \param pIndex Shading object index.
  186. * \param pCriteria Filtering criteria that identifies what kind of
  187. * implementations to consider.
  188. * \returns A handle on the shading object at the specified index that corresponds to the given filtering parameters.
  189. */
  190. FbxObject* GetShadingObject(int pIndex, const FbxImplementationFilter& pCriteria) const;
  191. /*****************************************************************************************************************************
  192. ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
  193. *****************************************************************************************************************************/
  194. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  195. protected:
  196. virtual void Construct(const FbxObject* pFrom);
  197. virtual void Destruct(bool pRecursive);
  198. mutable FbxLocalizationManager* mLocalizationManager;
  199. #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
  200. };
  201. /*****************************************************************************************************************************
  202. ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
  203. *****************************************************************************************************************************/
  204. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  205. template <class T> T* FbxLibrary::InstantiateMember(const T* pFBX_TYPE, const FbxObjectFilter& pFilter, bool pRecurse, FbxObject* pOptContainer)
  206. {
  207. //First check all materials in the library.
  208. for( int i = 0; i < GetMemberCount<T>(); ++i )
  209. {
  210. T* lObject = GetMember<T>(i);
  211. if( pFilter.Match(lObject) )
  212. return FbxCast<T>(CloneAsset(lObject,pOptContainer));
  213. }
  214. if( pRecurse )
  215. {
  216. // then check all materials in each sub-library.
  217. for( int i = 0; i < GetMemberCount<FbxLibrary>(); ++i )
  218. {
  219. FbxLibrary* lLibrary = GetMember<FbxLibrary>(i);
  220. T* lClonedObject = lLibrary->InstantiateMember(pFBX_TYPE, pFilter, pRecurse, pOptContainer);
  221. if( lClonedObject )
  222. return lClonedObject;
  223. }
  224. }
  225. return NULL;
  226. }
  227. class FBXSDK_DLL FbxEventPopulateSystemLibrary : public FbxEvent<FbxEventPopulateSystemLibrary>
  228. {
  229. FBXSDK_EVENT_DECLARE(FbxEventPopulateSystemLibrary)
  230. public:
  231. FbxEventPopulateSystemLibrary(FbxLibrary* pLibrary) { mLibrary = pLibrary; }
  232. inline FbxLibrary* GetLibrary() const { return mLibrary; }
  233. private:
  234. FbxLibrary* mLibrary;
  235. };
  236. class FBXSDK_DLL FbxEventUpdateSystemLibrary : public FbxEvent<FbxEventUpdateSystemLibrary>
  237. {
  238. FBXSDK_EVENT_DECLARE(FbxEventUpdateSystemLibrary)
  239. public:
  240. FbxEventUpdateSystemLibrary(FbxLibrary *pLibrary) { mLibrary = pLibrary; }
  241. inline FbxLibrary* GetLibrary() const { return mLibrary; }
  242. private:
  243. FbxLibrary* mLibrary;
  244. };
  245. class FBXSDK_DLL FbxEventWriteLocalization : public FbxEvent<FbxEventWriteLocalization>
  246. {
  247. FBXSDK_EVENT_DECLARE(FbxEventWriteLocalization)
  248. public:
  249. FbxEventWriteLocalization(FbxLibrary* pAssetLibrary) { mAssetLibrary = pAssetLibrary; }
  250. inline FbxLibrary* GetLibrary() const { return mAssetLibrary; }
  251. private:
  252. FbxLibrary* mAssetLibrary;
  253. };
  254. class FBXSDK_DLL FbxEventMapAssetFileToAssetObject : public FbxEvent<FbxEventMapAssetFileToAssetObject>
  255. {
  256. FBXSDK_EVENT_DECLARE(FbxEventMapAssetFileToAssetObject)
  257. public:
  258. FbxEventMapAssetFileToAssetObject(const char* pFile) :
  259. mAsset(NULL),
  260. mFilePath( pFile )
  261. {
  262. }
  263. inline const char* GetFilePath() const { return mFilePath; }
  264. mutable FbxObject* mAsset;
  265. private:
  266. FbxString mFilePath;
  267. };
  268. #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
  269. #include <fbxsdk/fbxsdk_nsend.h>
  270. #endif /* _FBXSDK_SCENE_LIBRARY_H_ */