md3文件:MD3文件格式



Char 是8位整型变量类型 
Short 是16位整型变量类型 
Int 是32位整型变量类型 
Float 是32位浮点变量类型 
Vec2 是float[2] 
Vec3 是float[3] 
Mat3x3 是float[3][3] 2维 
TexVec 是纹理U/V坐标向量 

文件头 
MD3_HEADER 
char ID[4]; //文件标志"IDP3" 
 Version; //文件版本0x0f 
char FileName[68]; //文件名 
 BoneFrame_num; //BoneFrames数 
 Tag_num; //每个BoneFrameTag数 
 Mesh_num; //Mesh(几何网格)数 
 MaxSkin_num; //最大可用Skin(材质)数 
 HeaderLength; //文件头长度. 
 Tag_Start; //Tag(标签)结构开始位置. 
 Tag_End; //标签Tag结束位置也就是几何网格结构起始位置 
 FileSize; //文件大小 
注释: 
Tag开始位置和结束位置相同则表示没有Tag 
Tag_Num有时为零,当然表示没有Tag. 
我不能确定Tag有什么作用,也许对骨骼动画系统有用吧. 
文件头后是Tag列表,如果有效那么tags总和等于Tag_num个BoneFrame_num. 
注意: 我们称的为'Tags',是在MD3文件中它为'Tag_'
TAG: 
char Name[64]; //name of 'tag' as it's usually 
//called in the md3 files try to 
//see it as a sub-mesh/seperate 
//mesh-part. 
//sometimes this 64  may 
//contain some garbage, but 
//i've been told this is because 
//some tools leave garbage in 
//those s, but they ARE 
//s... 
Vec3 Postition; //relative position of tag 
Vec3x3 Rotation; //the direction the tag is facing relative to the rest of the model 
注释: 
fairly obvious i think, the name is the name of the tag. 
"position" is the relative position and "rotation" is the relative rotation to the rest of the model. 

在tags的后是,'boneframe'骨架帧.几何网格帧个数通常 
After the tags come the 'boneframes', frames in the bone animation. 
The number of meshframes is usually identical to this number or simply 1. 
The header variable BoneFrame_num holds the ammount of BoneFrame.. 
BONEFRAME: 
没有完全证实: 
float Mins[3]; 
float Maxs[3]; 
float Position[3]; 
float scale; 
char Creator[16]; //我想这应该是制作者名字,但仅仅是猜测. 
注释: 
Mins,Maxs,和Position可能是正确,scale则是猜测. 
If you divide the maximum and minimum xyz values of all the vertices from each meshframe you get 
the exact values as mins and maxs.. 
Position is the exact center of mins and maxs, most of the time anyway. 
Creator 非常可能是制作模型生成文件名通常为(from ASE)"或 .3ds. 

在的后为几何网格头:mesh-headers; 
几何网格总数为Mesh_num所指明. 
注意:个Mesh包含Mesh-header,表皮, 3角形,纹理坐标和顶点. 
Each mesh contains that data, and the next mesh will only start after the triangles, meshes etc. of the previous mesh. 
让我惊讶是Md3文件并不包含很多个Mesh,这是我们需要深入了解
MESH: 
char ID[4]; //id, must be IDP3 
char Name[68]; //name of mesh 65 chars, 32 bit aligned  68 chars 
 MeshFrame_num; //number of meshframes in mesh 
 Skin_num; //number of skins in mesh 
 Vertex_num; //number of vertices 
 Triangle_num; //number of Triangles 
 Triangle_Start; // 3角形数据开始位置,相对于Mesh_Header 
 HeaderSize; //头长度 
 TexVec_Start; //纹理坐标数据开始位置,相对于Mesh_Header 
 Vertex_Start; //顶点开始位置,相对于Mesh_Header 
 MeshSize; //Mesh大小 
注释: 
Meshframe_num 类似于quake1/quake2总帧数. 
(these frames work on a morph like way, the vertices are moved from one position to another instead of rotated around eachother like in bone-based-animations) 


Skin_num 是Skins个数. 
些Skin是动画. 
Triangle_Start, TexVec_Start 和 Vertex_Start 是以字节为单位从Mesh Header指出相应位置. 
Mesh header 的后是Skin(纹理) 
个数由上面Mesh_header中Skin_num决定. 
SKIN: 
char Name[68]; //name of skin used by mesh 65 chars,32 bit aligned  68 chars 
注释: 
Name 纹理名字, 在baseq3路径下. 
Q3 通过特殊思路方法取得纹理. 
脚本放置在baseq3/script路径下,保存了那些表面采用动画及多重纹理映射. 
Now the strange thing is,  you remove the ".tga" at the end of the skin, and that name is used in the script files, than that scripted surface is used. 
If it isn't mentioned in the script files then the filename is used to load the tga file. 

纹理的后接着是 3角形数据,个数由Triangle_num指出. 
TRIANGLE 
 Triangle[3]; //vertex 1,2,3 of triangle 
注释: 
3角形结构是很简单结构.个 3角形由 3个顶点构成,如果你有个顶点列表,比如你有28个顶点列表,个 3角形由顶点1,14,7构成,那么 3角形结构就是整形1,14,7 7. 
3角形列表的后是纹理UV坐标个数由顶点决定: 
TEXTURE U/V COORDINATES: 
Vec2 TexVec; //Texture U/V coordinates of vertex 
注释: 
它使 3角形知道如何给自己贴上纹理. 
纹理坐标的后是顶点坐标,由Vertex_num指出个数. 
VERTICES: 
//!!!注意变量类型!!! signed! 
signed  Vec[3]; //顶点 X/Y/Z 坐标 
unsigned char EnvTex[2]; //环境贴图坐标 
注释: 
Vec 包含 3d xyz 顶点坐标. 
EnvTex 包含环境贴图纹理坐标.
Tags:  文件格式 md3文件

延伸阅读

最新评论

发表评论