原来的我还是很认真的啊。。。

原来的我还是很认真的啊。。。

    开始分析M2文件,发现和BC前的版本差异不多,虽然现在已是WLK了。想着以前写过一些,于是打开看看是否有啥好用的,么想,打开吓一跳,原来的我还是很认真的啊,M2Object,M2FileObject,XFileObject,甚至还封装了FileBuffer,Toolkit.... 源码这里。

  1  #ifndef __M2OBJECT_H__
  2  #define  __M2OBJECT_H__
  3 
  4  // base on  http://wowdev.org/wiki/index.php/M2  and  http://squishythoughts.com/archives/category/projects/3d/
  5 
  6  #include  < fstream >
  7  #include  < iostream >
  8  #include  < string >
  9  #include  < vector >
 10 
 11  #include  " FileBuffer.h "
 12 
 13  namespace  M2
 14  {
 15 
 16  enum  StructType {ST_BASE  =   0 , ST_HEADER, ST_NAME, ST_VERTEX, ST_VIEW, ST_BONE, ST_TEXTUREUNIT, ST_TEXTURE, ST_TEXTURENAME };
 17 
 18  class  CBase
 19  {
 20  public :
 21      CBase(StructType type  =  ST_BASE)
 22          : m_eType(type)
 23      {
 24      }
 25       virtual   ~ CBase() {}
 26 
 27       virtual   int  Read(CFileBuffer &  fb)  =   0 ;
 28       virtual  size_t BlockSize()  const  {  return   0 ; }
 29       virtual   void  Show(std::ostream &  os)  const ;
 30  public :
 31      StructType m_eType;
 32  };
 33 
 34  extern   int   operator   >>  (CFileBuffer &  fb, CBase &   base );
 35  extern  std::ostream &   operator   <<  (std::ostream &  os,  const  CBase &   base );
 36 
 37  class  CHeader :  public  CBase
 38  {
 39  public :
 40       struct  DataBlock_t
 41      {
 42          unsigned  int  m_uiCount;
 43          unsigned  int  m_uiOffset;
 44 
 45           int  Read(CFileBuffer &  fb);
 46           virtual  size_t BlockSize()  const  {  return   324 ; }
 47           void  Show(std::ostream &  os)  const ;
 48      };
 49  public :
 50      CHeader()
 51          : CBase(ST_HEADER)
 52      {
 53      }
 54 
 55       virtual   int  Read(CFileBuffer &  fb);
 56       virtual   void  Show(std::ostream &  os)  const ;
 57  public :
 58      .
 59  };
 60 
 61  class  CName :  public  CBase
 62  {
 63  public :
 64      CName()
 65          : CBase(ST_NAME)
 66      {
 67      }
 68       virtual   int  Read(CFileBuffer &  fb);
 69       virtual   void  Show(std::ostream &  os)  const ;
 70  public :
 71      std:: string  m_strName;
 72  };
 73 
 74  class  CVertex :  public  CBase
 75  {
 76  public :
 77       struct  Vector3Data_t
 78      {
 79           float  m_fX;
 80           float  m_fY;
 81           float  m_fZ;
 82 
 83           int  Read(CFileBuffer &  fb);
 84           void  Show(std::ostream &  os)  const ;
 85      };
 86       struct  Vector2Data_t
 87      {
 88           float  m_fX;
 89           float  m_fY;
 90 
 91           int  Read(CFileBuffer &  fb);
 92           void  Show(std::ostream &  os)  const ;
 93      };
 94  public :
 95      CVertex()
 96          : CBase(ST_VERTEX)
 97      {
 98      }
 99 
100       virtual   int  Read(CFileBuffer &  fb);
101       virtual  size_t BlockSize()  const  {  return   48 ; }
102       virtual   void  Show(std::ostream &  os)  const ;
103  public :
104      
105  };
106  typedef std::vector < CVertex >  TVertexVector;
107 
108  class  CView :  public  CBase
109  {
110    
111  };
112  typedef std::vector < CView >  TViewVector;
113 
114  class  CBone :  public  CBase
115  {
116     
117  };
118  typedef std::vector < CBone >  TBoneVector;
119 
120  class  CTextureUnit :  public  CBase
121  {
122    
123  };
124  typedef std::vector < CTextureUnit >  TTextureUnitVector;
125 
126  typedef CTextureUnit TTextureTableItem;
127  typedef std::vector < TTextureTableItem >  TTextureTableItemVector;
128 
129  class  CTexture :  public  CBase
130  {
131    
132  };
133  typedef std::vector < CTexture >  TTextureVector;
134 
135 
136  }
137 
138 
139  #endif
140 

    上次在展现模型的地方被卡住了,不知道这次会如何。。。毕竟DirectX还么真正写过什么程序呢。

你可能感兴趣的:(原来的我还是很认真的啊。。。)