/* =========================================================================== 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__util_ext_h_ #define INC__util_ext_h_ #ifdef _MSC_VER #define DLLEXPORT __declspec( dllexport ) #ifdef CDECL #undef CDECL #endif #define CDECL __cdecl #else #define DLLEXPORT #define CDECL #endif class BinaryReader { private: std::istream &stm; BinaryReader& operator = ( const BinaryReader & ) { } public: inline BinaryReader( std::istream &stm ) : stm( stm ) { } inline size_t seek( size_t newPos ) { stm.seekg( newPos, std::ios_base::beg ); return stm.tellg(); } inline size_t read( void *dst, size_t cb ) { size_t pStart = stm.tellg(); stm.read( (char*)dst, cb ); return (size_t)stm.tellg() - pStart; } inline void align( size_t n ) { size_t ptr = stm.tellg(); size_t div = ptr / n; if( div * n < ptr ) for( size_t c = (div + 1) * n - ptr; c--; ) stm.get(); } template< typename T > inline BinaryReader& operator >> ( T& dst ) { read( &dst, sizeof( T ) ); return *this; } }; class BinaryWriter { private: std::ostream &stm; BinaryWriter& operator = ( const BinaryWriter & ) { } public: inline BinaryWriter( std::ostream &stm ) : stm( stm ) { } inline size_t seek( size_t newPos ) { stm.seekp( newPos, std::ios_base::beg ); return stm.tellp(); } inline void write( const void *buff, size_t cb ) { stm.write( (const char*)buff, cb ); } inline void pad( size_t cb ) { while( cb-- ) stm.put( '\0' ); } /* Aligns the stream pointer to a multiple of n. */ inline void align( size_t n ) { size_t ptr = stm.tellp(); size_t div = ptr / n; if( div * n < ptr ) pad( (div + 1) * n - ptr ); } template< typename T > inline BinaryWriter& operator << ( const T& val ) { stm.write( (char*)&val, sizeof( T ) / sizeof( char ) ); return *this; } inline BinaryWriter& operator << ( const char* val ) { stm << val; return *this; } template< int n > inline BinaryWriter& operator << ( const sstr< n > &str ) { write( (const char*)str, n ); return *this; } }; #include inline argb argbc( const MColor &c ) { argb ret; ret.set_value( c.a, c.r, c.g, c.b ); return ret; } #include #include #include #include inline vec3 vec3c( const MPoint &v ) { vec3 ret = { (float)v.x, (float)v.y, (float)v.z }; return ret; } inline vec3 vec3c( const MVector &v ) { vec3 ret = { (float)v.x, (float)v.y, (float)v.z }; return ret; } inline vec3 vec3c( const MFloatPoint &v ) { vec3 ret = { v.x, v.y, v.z }; return ret; } inline vec3 vec3c( const MFloatVector &v ) { vec3 ret = { v.x, v.y, v.z }; return ret; } /* Little class to make sure the time slider gets restored if the exporter happens to throw an exception. */ class MayaAnimIt { private: MTime saveTime; MTime startTime; MTime stepTime; MTime currTime; uint currFrame; uint numFrames; public: MayaAnimIt( void ); MayaAnimIt( MTime startTime, uint numFrames ); MayaAnimIt( MTime startTime, MTime endTime ); MayaAnimIt( MTime startTime, uint numFrames, MTime stepTime ); MayaAnimIt( MTime startTime, MTime endTime, MTime stepTime ); ~MayaAnimIt( void ); bool isDone( void ) const; void next( void ); uint frameNum( void ) const; uint frameCount( void ) const; }; class error; class maya_error : public std::exception { private: MStatus statcode; public: maya_error( MStatus status_code ) : statcode( status_code ) { } virtual const char* what() const { return statcode.errorString().asChar(); } MStatus status_code( void ) const { return statcode; } }; void check_status( MStatus status ); namespace gl { class Context { private: #ifdef _MSC_VER HDC m_gldc; HGLRC m_glrc; #elif __linux__ Display *m_gldc; GLXContext m_glrc; GLXDrawable m_gldr; #else #error ToDo: implement on Mac OSX #endif public: Context( void ); bool operator == ( const Context &other ) const; bool operator != ( const Context &other ) const; operator bool ( void ) const; bool MakeCurrent( void ) const; static Context GetNull( void ); static Context GetCurrent( void ); }; }; #endif