fbxprocessorshaderdependency.h

Go to the documentation of this file.
00001 /****************************************************************************************
00002  
00003    Copyright (C) 2012 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/fbxpair.h>
00019 #include <fbxsdk/core/base/fbxdynamicarray.h>
00020 #include <fbxsdk/core/base/fbxhashmap.h>
00021 #include <fbxsdk/core/fbxxref.h>
00022 #include <fbxsdk/scene/shading/fbxbindingtable.h>
00023 #include <fbxsdk/utils/fbxprocessor.h>
00024 
00025 #include <fbxsdk/fbxsdk_nsbegin.h>
00026 
00030 class FBXSDK_DLL FbxProcessorShaderDependency : public FbxProcessor
00031 {
00032     FBXSDK_OBJECT_DECLARE(FbxProcessorShaderDependency,FbxProcessor);
00033 
00034 public:
00035 
00036     FbxPropertyT<FbxString> RootProcessPath;
00037 
00038     FbxPropertyT<FbxBool> CleanupOnDestroy;
00039 
00040     FbxPropertyT<FbxString> AdditionalIncludePaths;
00041 
00042     void ClearProcessedFiles();
00043 
00047     protected:
00048         virtual bool                internal_ProcessObject          (FbxObject*     pObject);
00049 
00050 
00052 
00054     //  WARNING!
00055     //    Anything beyond these lines may not be documented accurately and is 
00056     //     subject to change without notice.
00058 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00059     // Constructor / Destructor
00060     protected:
00061         FbxProcessorShaderDependency(FbxManager& pManager, char const* pName);
00062         bool                ConstructProperties(bool pForceSet);
00063         void                Destruct(bool pRecursive, bool pDependents);
00064 
00065     public:
00066 
00067         class StringHash
00068         {
00069         public:
00070             unsigned int operator()( const FbxString& pValue ) const
00071             {
00072                 // from wikipedia.org
00073                 // Jenkins One-at-a-time hash
00074 
00075                 size_t lLen = pValue.GetLen();
00076                 unsigned int lHashValue = 0;
00077                 const char* lData = pValue.Buffer();
00078                 for( size_t i = 0; i < lLen; ++i )
00079                 {
00080                     lHashValue += lData[i];
00081                     lHashValue += (lHashValue << 10);
00082                     lHashValue ^= (lHashValue >> 16);
00083                 }
00084                 lHashValue += (lHashValue << 3);
00085                 lHashValue ^= (lHashValue >> 11);
00086                 lHashValue += (lHashValue << 15);
00087 
00088                 return lHashValue;
00089             }
00090         };
00091 
00092     protected:
00093 
00094         class FileDeleter
00095         {
00096         public: 
00097             FileDeleter( const char* pFileUrl ) : mFileUrl( pFileUrl) {};
00098             ~FileDeleter()
00099             {
00100                 if( !mFileUrl.IsEmpty() )
00101                 {
00102                     remove( mFileUrl );
00103                 }
00104             };
00105 
00106             void Release() { mFileUrl = ""; }
00107 
00108         private: FbxString mFileUrl;
00109         };
00110 
00111         // first == string as it appears in the file
00112         // second == string URL
00113         struct FilePathData
00114         {
00115             FbxString mOriginalStr;
00116             FbxString mOriginalAbsUrl;
00117 
00118             FbxString mNewStr;
00119         };
00120 
00121         typedef FbxDynamicArray< FilePathData > FilePathList;
00122 
00123         virtual bool GetIncludePaths( FbxString& pFile, FilePathList& pPaths, FbxXRefManager& pManager ) const;
00124         virtual bool ReplaceUrls( const FbxString& pFileUrl, const FbxString& pNewFileUrl, 
00125                         const FilePathList& pPaths ) const;
00126 
00127     private:
00128         struct Dependency
00129         {
00130             FbxString mNewUrl;
00131             FbxString mOriginalUrl;
00132         };
00133 
00134         typedef FbxHashMap< FbxString, Dependency, StringHash > DependMap;
00135 
00136         DependMap mDependMap;
00137 
00138         FbxString mRootPath;
00139 
00140         FbxXRefManager mResolver;
00141         int mSystemIndex;
00142 
00143         // magic number to limit the size of files we can parse =(
00144         static const int sMaxFileSize;
00145 
00146         bool ParseDependencies( const FbxBindingTable& pTable );
00147         bool AddDependency( FbxString& pFileUrl );
00148         bool AddSystemPaths();
00149 
00150     #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS 
00151 };
00152 
00153 #include <fbxsdk/fbxsdk_nsend.h>
00154 
00155 #endif /* _FBXSDK_UTILS_PROCESSOR_SHADER_DEPENDENCY_H_ */