fbxprocessorshaderdependency.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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 fbxprocessorshaderdependency.h
  9. #ifndef _FBXSDK_UTILS_PROCESSOR_SHADER_DEPENDENCY_H_
  10. #define _FBXSDK_UTILS_PROCESSOR_SHADER_DEPENDENCY_H_
  11. #include <fbxsdk/fbxsdk_def.h>
  12. #include <fbxsdk/core/base/fbxhashmap.h>
  13. #include <fbxsdk/core/base/fbxdynamicarray.h>
  14. #include <fbxsdk/scene/shading/fbxbindingtable.h>
  15. #include <fbxsdk/fbxsdk_nsbegin.h>
  16. /** Crawls CgFx and HLSL shader files, copies them, and all dependent
  17. * shader files into the location specified by RootProcessPath.
  18. */
  19. class FBXSDK_DLL FbxProcessorShaderDependency : public FbxProcessor
  20. {
  21. FBXSDK_OBJECT_DECLARE(FbxProcessorShaderDependency, FbxProcessor);
  22. public:
  23. FbxPropertyT<FbxString> RootProcessPath;
  24. FbxPropertyT<FbxBool> CleanupOnDestroy;
  25. FbxPropertyT<FbxString> AdditionalIncludePaths;
  26. void ClearProcessedFiles();
  27. /**
  28. * \name Overridable internal function */
  29. //@{
  30. protected:
  31. virtual bool internal_ProcessObject(FbxObject* pObject);
  32. //@}
  33. /*****************************************************************************************************************************
  34. ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
  35. *****************************************************************************************************************************/
  36. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  37. // Constructor / Destructor
  38. protected:
  39. virtual void ConstructProperties(bool pForceSet);
  40. virtual void Destruct(bool pRecursive);
  41. public:
  42. class StringHash
  43. {
  44. public:
  45. unsigned int operator()( const FbxString& pValue ) const
  46. {
  47. // from wikipedia.org
  48. // Jenkins One-at-a-time hash
  49. size_t lLen = pValue.GetLen();
  50. unsigned int lHashValue = 0;
  51. const char* lData = pValue.Buffer();
  52. for( size_t i = 0; i < lLen; ++i )
  53. {
  54. lHashValue += lData[i];
  55. lHashValue += (lHashValue << 10);
  56. lHashValue ^= (lHashValue >> 16);
  57. }
  58. lHashValue += (lHashValue << 3);
  59. lHashValue ^= (lHashValue >> 11);
  60. lHashValue += (lHashValue << 15);
  61. return lHashValue;
  62. }
  63. };
  64. protected:
  65. class FileDeleter
  66. {
  67. public:
  68. FileDeleter( const char* pFileUrl ) : mFileUrl( pFileUrl) {};
  69. ~FileDeleter()
  70. {
  71. if( !mFileUrl.IsEmpty() )
  72. {
  73. remove( mFileUrl );
  74. }
  75. };
  76. void Release() { mFileUrl = ""; }
  77. private: FbxString mFileUrl;
  78. };
  79. // first == string as it appears in the file
  80. // second == string URL
  81. struct FilePathData
  82. {
  83. FbxString mOriginalStr;
  84. FbxString mOriginalAbsUrl;
  85. FbxString mNewStr;
  86. };
  87. typedef FbxDynamicArray< FilePathData > FilePathList;
  88. virtual bool GetIncludePaths( FbxString& pFile, FilePathList& pPaths, FbxXRefManager& pManager ) const;
  89. virtual bool ReplaceUrls( const FbxString& pFileUrl, const FbxString& pNewFileUrl,
  90. const FilePathList& pPaths ) const;
  91. private:
  92. struct Dependency
  93. {
  94. FbxString mNewUrl;
  95. FbxString mOriginalUrl;
  96. };
  97. typedef FbxHashMap< FbxString, Dependency, StringHash > DependMap;
  98. DependMap mDependMap;
  99. FbxString mRootPath;
  100. FbxXRefManager mResolver;
  101. int mSystemIndex;
  102. // magic number to limit the size of files we can parse =(
  103. static const int sMaxFileSize;
  104. bool ParseDependencies( const FbxBindingTable& pTable );
  105. bool AddDependency( FbxString& pFileUrl );
  106. bool AddSystemPaths();
  107. #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
  108. };
  109. #include <fbxsdk/fbxsdk_nsend.h>
  110. #endif /* _FBXSDK_UTILS_PROCESSOR_SHADER_DEPENDENCY_H_ */