///////////////////////////////////////////////////////////////////////////////////////////////////// // // Crytek Character Animation source code // // History: // Created by Sergiy Migdalskiy // ///////////////////////////////////////////////////////////////////////////////////////////////////// #ifndef _CGF_UTILS_HDR_ #define _CGF_UTILS_HDR_ // prerequisities //#include //#include #ifndef M_PI #define M_PI 3.1415926535897932384626433832795 #endif // given the chunk, parses it and returns the array of pointers to the strings with the bone names // in the supplied array. Returns true when successful extern bool LoadBoneNameList (const CHUNK_HEADER& chunkHeader, const void* pChunk, unsigned nChunkSize, std::vector& arrNames); enum MatChunkLoadErrorEnum { MCLE_Success, MCLE_Truncated, MCLE_UnknownVersion, MCLE_IgnoredType // this material type should be ignored (multimaterial) }; // Attempts to load the material from the given material chunk to the "me" structure extern MatChunkLoadErrorEnum LoadMatEntity (const CHUNK_HEADER& chunkHeader, const void* pChunkData, unsigned nChunkSize, MAT_ENTITY& me); // material name parser. // In the CGF, the material has to have a complex name: // name_spec template_spec phys_mat_spec render_index_spec // // name_spec: // $s_* -- * means the template name; in this case, material name remains $s_* // * -- * means just the material name // // template_spec: -- not necessary // (*) -- * means the template; closing bracket may be absent // // phys_mat_spec: -- not necessary // /name // // render_index_spec: -- not necessary // [id] class CMatEntityNameTokenizer { public: CMatEntityNameTokenizer (); ~CMatEntityNameTokenizer (); void tokenize(const char* szName); // material name const char *szName; // template name (NULL if no template) const char *szTemplate; // physic material name const char *szPhysMtl; // render index (0 if not specified) int nSortValue; // true, if the template is to be inverted.. (# before the template name bool bInvert; // operator that sorts the materials for rendering bool operator < (const CMatEntityNameTokenizer& right)const; protected: char* m_szMtlName; }; // this is sorting predicate that helps form a mapping of old-new mat ids // it's given an array of tokenizers to index into class CMatEntityIndexSort { public: // accepts the array of initialized tokenizers and their number CMatEntityIndexSort (const CMatEntityNameTokenizer* pTokenizers, unsigned numSize): m_pTokenizers (pTokenizers), m_numSize (numSize) { } bool operator () (unsigned nLeft, unsigned nRight) const { assert (nLeft >= 0 && nLeft < m_numSize); assert (nRight >= 0 && nRight < m_numSize); return m_pTokenizers[nLeft ]