00001 /**************************************************************************************** 00002 00003 Copyright (C) 2013 Autodesk, Inc. 00004 All rights reserved. 00005 00006 Use of this software is subject to the terms of the Autodesk license agreement 00007 provided at the time of installation or download, or which otherwise accompanies 00008 this software in either electronic or hard copy form. 00009 00010 ****************************************************************************************/ 00011 00013 #ifndef _FBXSDK_UTILS_PROCESSOR_SHADER_DEPENDENCY_H_ 00014 #define _FBXSDK_UTILS_PROCESSOR_SHADER_DEPENDENCY_H_ 00015 00016 #include <fbxsdk/fbxsdk_def.h> 00017 00018 #include <fbxsdk/core/base/fbxhashmap.h> 00019 #include <fbxsdk/core/base/fbxdynamicarray.h> 00020 #include <fbxsdk/scene/shading/fbxbindingtable.h> 00021 00022 #include <fbxsdk/fbxsdk_nsbegin.h> 00023 00027 class FBXSDK_DLL FbxProcessorShaderDependency : public FbxProcessor 00028 { 00029 FBXSDK_OBJECT_DECLARE(FbxProcessorShaderDependency, FbxProcessor); 00030 00031 public: 00032 FbxPropertyT<FbxString> RootProcessPath; 00033 00034 FbxPropertyT<FbxBool> CleanupOnDestroy; 00035 00036 FbxPropertyT<FbxString> AdditionalIncludePaths; 00037 00038 void ClearProcessedFiles(); 00039 00043 protected: 00044 virtual bool internal_ProcessObject(FbxObject* pObject); 00046 00047 /***************************************************************************************************************************** 00048 ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! ** 00049 *****************************************************************************************************************************/ 00050 #ifndef DOXYGEN_SHOULD_SKIP_THIS 00051 // Constructor / Destructor 00052 protected: 00053 virtual void ConstructProperties(bool pForceSet); 00054 virtual void Destruct(bool pRecursive); 00055 00056 public: 00057 00058 class StringHash 00059 { 00060 public: 00061 unsigned int operator()( const FbxString& pValue ) const 00062 { 00063 // from wikipedia.org 00064 // Jenkins One-at-a-time hash 00065 00066 size_t lLen = pValue.GetLen(); 00067 unsigned int lHashValue = 0; 00068 const char* lData = pValue.Buffer(); 00069 for( size_t i = 0; i < lLen; ++i ) 00070 { 00071 lHashValue += lData[i]; 00072 lHashValue += (lHashValue << 10); 00073 lHashValue ^= (lHashValue >> 16); 00074 } 00075 lHashValue += (lHashValue << 3); 00076 lHashValue ^= (lHashValue >> 11); 00077 lHashValue += (lHashValue << 15); 00078 00079 return lHashValue; 00080 } 00081 }; 00082 00083 protected: 00084 00085 class FileDeleter 00086 { 00087 public: 00088 FileDeleter( const char* pFileUrl ) : mFileUrl( pFileUrl) {}; 00089 ~FileDeleter() 00090 { 00091 if( !mFileUrl.IsEmpty() ) 00092 { 00093 remove( mFileUrl ); 00094 } 00095 }; 00096 00097 void Release() { mFileUrl = ""; } 00098 00099 private: FbxString mFileUrl; 00100 }; 00101 00102 // first == string as it appears in the file 00103 // second == string URL 00104 struct FilePathData 00105 { 00106 FbxString mOriginalStr; 00107 FbxString mOriginalAbsUrl; 00108 00109 FbxString mNewStr; 00110 }; 00111 00112 typedef FbxDynamicArray< FilePathData > FilePathList; 00113 00114 virtual bool GetIncludePaths( FbxString& pFile, FilePathList& pPaths, FbxXRefManager& pManager ) const; 00115 virtual bool ReplaceUrls( const FbxString& pFileUrl, const FbxString& pNewFileUrl, 00116 const FilePathList& pPaths ) const; 00117 00118 private: 00119 struct Dependency 00120 { 00121 FbxString mNewUrl; 00122 FbxString mOriginalUrl; 00123 }; 00124 00125 typedef FbxHashMap< FbxString, Dependency, StringHash > DependMap; 00126 00127 DependMap mDependMap; 00128 00129 FbxString mRootPath; 00130 00131 FbxXRefManager mResolver; 00132 int mSystemIndex; 00133 00134 // magic number to limit the size of files we can parse =( 00135 static const int sMaxFileSize; 00136 00137 bool ParseDependencies( const FbxBindingTable& pTable ); 00138 bool AddDependency( FbxString& pFileUrl ); 00139 bool AddSystemPaths(); 00140 #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/ 00141 }; 00142 00143 #include <fbxsdk/fbxsdk_nsend.h> 00144 00145 #endif /* _FBXSDK_UTILS_PROCESSOR_SHADER_DEPENDENCY_H_ */