#pragma once #include "d3dx9.h" #ifndef OBJMESH_HEADER #define OBJMESH_HEADER struct BinMesh; class ObjMesh { private: struct Vertex { D3DXVECTOR3 position; D3DXVECTOR3 normal; }; struct VertexInfo { int m_iPos; int m_iNormal; int m_iUV; bool operator<( const VertexInfo& v )const { if( m_iPos == v.m_iPos ) { if( m_iNormal == v.m_iNormal ) { return m_iUV < v.m_iUV; } return m_iNormal < v.m_iNormal; } return m_iPos < v.m_iPos; } }; int m_VertexCount; int m_IndexCount; int m_FaceCount; static const int MaxVertexBuffer= 65536; static const int MaxIndexBuffer= 65536 * 9 / 2; Vertex m_VertexBuffer[ MaxVertexBuffer ]; unsigned short int m_IndexBuffer[ MaxIndexBuffer ]; struct OpInfo { void Reset(); Vertex m_NextVB[ ObjMesh::MaxVertexBuffer ]; unsigned short int m_NextIB[ ObjMesh::MaxIndexBuffer ]; int m_NextVertexCount; int m_NextIndexCount; int m_NextFaceCount; int m_iEdgeCount; unsigned int m_EdgeConfiguration[ ObjMesh::MaxIndexBuffer ]; unsigned char m_EdgeUsage[ ObjMesh::MaxIndexBuffer ]; int MakeEdgeID( unsigned short VertexA, unsigned short VertexB ); unsigned short int m_EdgeID[ ObjMesh::MaxIndexBuffer ]; }; OpInfo m_OP; public: #ifdef EXTRACODE bool LoadMesh( const char* pcFileName, int FloatBits, bool bFlatten, BinMesh& BM, int& IndexBytes, int& VertexBytes ); static float ObjMesh::RoundFloat( float f, int iBits ); static float m_fMaxRoundError; #endif bool LoadMesh( BinMesh* pBinMesh ); void GenerateNormals(); void CatmullClarkSubdivide(); void Extrude( float fExtend ); void SuperEllip( float fStrength ); void Bevel( float fExtend, float fMinAngle ); void UnIndex(); inline unsigned int GetVertexCount() const { return m_VertexCount; }; inline unsigned int GetIndexCount() const { return m_IndexCount; }; inline unsigned int GetFaceCount() const { return m_FaceCount; }; Vertex* GetVertexBuffer() { return m_VertexBuffer; } unsigned short int* GetIndexBuffer() { return m_IndexBuffer; } }; extern ObjMesh g_objMesh; #endif