天行健 君子当自强而不息

加载MD2文件播放角色动画

MD2文件由两个主要部分组成:文件头和数据。

文件头部分: 包含模型描述,多边形数,顶点数和动画细节等。
数据部分:  组成模型的多边形网格的数据,包括所有的多边形,顶点和纹理数据。

在MD2文件中,所有的多边形都为三角形,且没有其他的实体。
顶点数据定义的不是单帧而是多帧动画。事实上,每个MD2文件包含198帧动画,编号为0-197。

MD2文件头数据结构定义:
// This is the header structure for a Quake II .MD2 file by id Software
typedef struct MD2_HEADER_TYPE
{
    
int identifier;          // identifies the file type, should be "IDP2"
    int version;             // version number, should be 8.
    int skin_width;        // width of texture map used for skinning
    int skin_height;       // height of texture map used for skinning
    int framesize;          // number of bytes in a single frame of animation

    
int num_skins;        // total number of skins,
                                 
// listed by ASCII filename and are available for loading if files are found in full path.

    
int num_verts;        // number of vertices in each model frame, 
                                 
// the number of vertices in each frame is always the same.

    
int num_textcoords; // total number of texture coordinates in entire file,
                                  
// may be larger than the number of vertices.

    
int num_polys;        // number of polygons per model, or per frame of animation if you will.

    
int num_openGLcmds; // number of openGL commands which can help with rendering optimization,
                                       
// however, we won't be using them.

    
int num_frames;     // total number of animation frames

    
// memory byte offsets to actual data for each item

    
int offset_skins;       // offset in bytes from beginning of file to the skin array that holds the file name
                                  
// for each skin, each file name record is 64 bytes.

    
int offset_textcoords;  // offset in bytes from the beginning of file to the texture coordinate array
    int offset_polys;          // offset in bytes from the beginning of file to the polygon mesh
    int offset_frames;       // offset in bytes from the beginning of file to the vertex data for each frame
    int offset_openGLcmds;  // offset in bytes from the beginning of file to the openGL commands
    int offset_end;         // offset in bytes from the beginning of file to end of file
} MD2_HEADER, *MD2_HEADER_PTR;


线框模式


实体模式

其他模型






posted on 2007-04-24 02:15 lovedday 阅读(1020) 评论(2)  编辑 收藏 引用

评论

# re: 加载MD2文件播放角色动画 2008-03-18 14:24 阿飞

谢谢! 感悟...  回复  更多评论   

# re: 加载MD2文件播放角色动画 2012-03-09 10:13 preboy

可以弄个源代码吗、详细讲解下在游戏中怎样运用以显示一个MESH,  回复  更多评论   


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


公告

导航

统计

常用链接

随笔分类(178)

3D游戏编程相关链接

搜索

最新评论