/* =========================================================================== maya2q3 - export .md3 files from maya Copyright (C) 2005 HermitWorks Entertainment Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. =========================================================================== */ #ifndef INC__q3util_h_ #define INC__q3util_h_ namespace q3 { class ResourceLoader { public: //empty the directory tree out static void ClearDirectories( void ); static void AddDirectory( const char *dirName ); static bool ResourceExists( const char *resName ); //a single null byte will follow the data, this byte is not counted in dataSize static bool GetData( const char *resName, void *&data, size_t &dataSize ); static void FreeData( void *data ); //ext includes the '.' static const char** FindFiles( const char *dirName, const char *ext = null ); static const char** FindDirectories( const char *dirName ); static void FindClose( const char **findData ); private: ResourceLoader() { }; static void AddDirectories( void ); static bool CDECL PakSort( const ospath &p0, const ospath &p1 ); }; int ComparePaths( const char *s0, const char *s1 ); qname MangleMayaShaderName( const char *s ); qname GetShaderName( const MObject &shaderObj ); qname GetShaderSetName( const MObject &setNode ); inline vec3 MayaVecToQ3( const MVector &a ) { return vec3c( -(float)a.x, (float)a.z, (float)a.y ); } inline vec3 MayaVecToQ3( const MFloatVector &a ) { return vec3c( -a.x, a.z, a.y ); } inline vec3 MayaVecToQ3( const MPoint &a ) { return vec3c( -(float)a.x, (float)a.z, (float)a.y ); } inline vec3 MayaVecToQ3( const MFloatPoint &a ) { return vec3c( -a.x, a.z, a.y ); } inline vec3 MayaVecToQ3( const vec3 &a ) { return vec3c( -a[0], a[2], a[1] ); } inline vec3 Q3VecToMaya( const vec3 &a ) { return vec3c( -a[0], a[2], a[1] ); } affine_t MayaMatrixToQ3( const MMatrix &mat ); bool DagIsTag( const MDagPath &path ); MString GetTagName( const MDagPath &path ); struct Patch { vec3 lodOrigin; float lodRadius; int lodFixed; bool lodStitched; int width; int height; std::vector< float > widthLodError; std::vector< float > heightLodError; std::vector< q3::drawVert_t > verts; uint meshIdx; }; void StitchAllPatches( std::vector< Patch > &patches ); void FixSharedVertexLodError( std::vector< Patch > &patches ); Patch SubdividePatchToGrid( int width, int height, const drawVert_t points[] ); void PatchToMesh( const Patch &patch, std::vector< q3::drawVert_t > &out_verts, std::vector< int > &out_indices ); class KeyNotFound : public std::exception { }; struct Entity { public: const std::string& AsString( const std::string &key ) const; const std::string& AsString( const std::string &key, const std::string &def ) const; bool AsBool( const std::string &key ) const; bool AsBool( const std::string &key, bool def ) const; float AsFloat( const std::string &key ) const; float AsFloat( const std::string &key, float def ) const; vec3 AsVec3( const std::string &key ) const; vec3 AsVec3( const std::string &key, const vec3 &def ) const; static std::vector< Entity > ParseEntities( const char *str ); private: typedef std::map< std::string, std::string > EntMap; EntMap pairs; friend std::vector< Entity > ParseEntityString( const char *str ); }; }; #endif