// Z3DTYPES.h: interface for the Z3DTYPES class. // ////////////////////////////////////////////////////////////////////// #if !defined(AFX_Z3DTYPES_H__0B082281_CC66_11D4_AD2B_0000E8EB4C69__INCLUDED_) #define AFX_Z3DTYPES_H__0B082281_CC66_11D4_AD2B_0000E8EB4C69__INCLUDED_ #if _MSC_VER > 1000 #pragma once #endif // _MSC_VER > 1000 #include "vector.h" #include "misc.h" #include #include "vertex.h" #pragma pack(push, Z3D_ALIGN4) #pragma pack(4) #define Z3D_LOD_LEVEL 4 struct Z3DBlend2Vertex_ { vector3 pos; float bfactor; BYTE mtrx_id[2]; vector3 normal; float u; float v; BYTE lodLevel; }; struct Z3DBlend2Vertex { vector3 pos; float bfactor; BYTE mtrx_id[2]; vector3 normal; vector3 u; float tu; float tv; BYTE lodLevel; }; struct Z3DMeshIndex { WORD* pIndices; long lIndexCount; Z3DMeshIndex() { pIndices = NULL; lIndexCount = 0; } ~Z3DMeshIndex() { SAFE_DELETEA( pIndices ); } }; struct Z3DLODMesh_ { WORD wId; Z3DBlend2Vertex_* pVertices; long lVertexCount; Z3DMeshIndex aIndex[Z3D_LOD_LEVEL]; Z3DLODMesh_() { wId = 999; pVertices = NULL; lVertexCount = 0; } ~Z3DLODMesh_() { SAFE_DELETEA( pVertices ); } bool Load( const char* szFilename ) { FILE* fp; if((fp = fopen(szFilename, "rb")) == NULL ) { return false; } fread( &wId, sizeof(WORD), 1, fp ); fread( &lVertexCount, sizeof(long), 1, fp ); pVertices = new Z3DBlend2Vertex_[lVertexCount]; if( NULL == pVertices ) { fclose( fp ); return false; } for(int i = 0; i < Z3D_LOD_LEVEL; i++ ) { fread( &(aIndex[i].lIndexCount), sizeof(long), 1, fp ); if( aIndex[i].lIndexCount ) { aIndex[i].pIndices = new WORD[aIndex[i].lIndexCount]; if( NULL == aIndex[i].pIndices ) { fclose( fp ); return false; } } } fread( pVertices, sizeof(Z3DBlend2Vertex_), lVertexCount, fp ); for( i = 0; i < Z3D_LOD_LEVEL; i++ ) { if( aIndex[i].lIndexCount ) { fread( aIndex[i].pIndices, sizeof(WORD), aIndex[i].lIndexCount, fp ); } } fclose( fp ); return true; } int GetId() { return wId; } }; struct Z3DLODMesh { WORD wId; Z3DBlend2Vertex* pVertices; long lVertexCount; Z3DMeshIndex aIndex[Z3D_LOD_LEVEL]; Z3DLODMesh() { wId = 999; pVertices = NULL; lVertexCount = 0; } ~Z3DLODMesh() { SAFE_DELETEA( pVertices ); } bool Load( const char* szFilename ) { FILE* fp; if((fp = fopen(szFilename, "rb")) == NULL ) { return false; } fread( &wId, sizeof(WORD), 1, fp ); fread( &lVertexCount, sizeof(long), 1, fp ); pVertices = new Z3DBlend2Vertex[lVertexCount]; if( NULL == pVertices ) { fclose( fp ); return false; } for(int i = 0; i < Z3D_LOD_LEVEL; i++ ) { fread( &(aIndex[i].lIndexCount), sizeof(long), 1, fp ); if( aIndex[i].lIndexCount ) { aIndex[i].pIndices = new WORD[aIndex[i].lIndexCount]; if( NULL == aIndex[i].pIndices ) { fclose( fp ); return false; } } } fread( pVertices, sizeof(Z3DBlend2Vertex), lVertexCount, fp ); for( i = 0; i < Z3D_LOD_LEVEL; i++ ) { if( aIndex[i].lIndexCount ) { fread( aIndex[i].pIndices, sizeof(WORD), aIndex[i].lIndexCount, fp ); } } fclose( fp ); return true; } bool Save( const char* szFilename ) { FILE* fp; if((fp = fopen(szFilename, "wb")) == NULL ) { return false; } // writing id fwrite( &wId, sizeof(WORD), 1, fp ); // writing vertex count fwrite( &lVertexCount, sizeof(long), 1, fp ); if( NULL == pVertices ) { fclose( fp ); return false; } // writing index count of each LOD level for(int i = 0; i < Z3D_LOD_LEVEL; i++ ) { fwrite( &(aIndex[i].lIndexCount), sizeof(long), 1, fp ); if( aIndex[i].lIndexCount ) { if( NULL == aIndex[i].pIndices ) { fclose( fp ); return false; } } } // writing vertex content fwrite( pVertices, sizeof(Z3DBlend2Vertex), lVertexCount, fp ); // writing index content of each LOD level for( i = 0; i < Z3D_LOD_LEVEL; i++ ) { if( aIndex[i].lIndexCount ) { fwrite( aIndex[i].pIndices, sizeof(WORD), aIndex[i].lIndexCount, fp ); } } fclose( fp ); return true; } int GetId() { return wId; } }; struct Z3DAMesh { WORD m_wVertexCount; BumpVertex* m_pVertices; WORD m_wIndexCount; WORD* m_pIndices; WORD m_wMarker1; WORD m_wMarker2; Z3DAMesh() { m_wVertexCount = 0; m_pVertices = NULL; m_wIndexCount = 0; m_pIndices = NULL; m_wMarker1 = 0; m_wMarker2 = 0; } ~Z3DAMesh() { SAFE_DELETEA(m_pVertices); SAFE_DELETEA(m_pIndices); } bool Load( const char* szFileName ) { FILE* fp; if((fp = fopen(szFileName, "rb")) == NULL ) { return false; } fread( &m_wVertexCount, sizeof(WORD), 1, fp ); fread( &m_wIndexCount, sizeof(WORD), 1, fp ); m_pVertices = new BumpVertex[m_wVertexCount]; if( NULL == m_pVertices ) { fclose( fp ); return false; } m_pIndices = new WORD[m_wIndexCount]; if( NULL == m_pIndices ) { fclose( fp ); return false; } fread( m_pVertices, sizeof(BumpVertex), m_wVertexCount, fp ); fread( m_pIndices, sizeof(WORD), m_wIndexCount, fp ); fread( &m_wMarker1, sizeof(WORD), 1, fp ); fread( &m_wMarker2, sizeof(WORD), 1, fp ); fclose(fp); return true; } bool Save( const char* szFileName ) { FILE* fp; if((fp = fopen(szFileName, "wb")) == NULL ) { return false; } fwrite( &m_wVertexCount, sizeof(WORD), 1, fp ); fwrite( &m_wIndexCount, sizeof(WORD), 1, fp ); if( NULL == m_pVertices ) { fclose( fp ); return false; } if( NULL == m_pIndices ) { fclose( fp ); return false; } fwrite( m_pVertices, sizeof(BumpVertex), m_wVertexCount, fp ); fwrite( m_pIndices, sizeof(WORD), m_wIndexCount, fp ); fwrite( &m_wMarker1, sizeof(WORD), 1, fp ); fwrite( &m_wMarker2, sizeof(WORD), 1, fp ); fclose(fp); return true; } }; /*struct Z3DMesh { Z3DBlend2Vertex* pVertices; long lVertexCount; Z3DMeshIndex index; };*/ #pragma pack(pop, Z3D_ALIGN4) #endif // !defined(AFX_Z3DTYPES_H__0B082281_CC66_11D4_AD2B_0000E8EB4C69__INCLUDED_)