平民程序 - linghuye's blog

天下风云出我辈,一入江湖岁月催。皇图霸业谈笑中,不胜人生一场醉。提剑跨骑挥鬼雨,白骨如山鸟惊飞。尘事如潮人如水,只笑江湖几人回。

随笔 - 221, 文章 - 0, 评论 - 680, 引用 - 0
数据加载中……

WoW's M2 格式研究

基本设计格式
1.定义字符串长度为: strlen(szText) + 1
2.所有偏移位置均指以文件头为起点.
3.文件存储各段数据实际以16字节对齐占用,即若strlen为16,加尾部\0字符,长度为17,但实际要占用32字节. 即,除非该段Offset为0(无数据),则该段至少占用16字节的整数倍空间.
4.vec3_type: 3D向量点   vec2_type:2D向量点

 

// M2文件头部信息结构
struct M2_HEADER // 336 bytes, 84 DWORDs.
{
DWORD dwIdent; // M2 File Identity
DWORD dwVersion; // version: 256

DWORD nModelNameSize; // strlen(szModelName) + 1
DWORD nModelNameOffset; // always 336(header size), points to ModelName.

DWORD dwUnk1; // All 0s, occasionally 1,3(World\SkillActivated\Containers\TreasureChest01: 3)

DWORD nGlobalSequences;
DWORD nGlobalSequencesOffset; // points to array of DWORD
    
DWORD nNumAnimations;
DWORD nAnimationsOffset; // points to M2_ANIMATION_INFO

DWORD nUnkIndices;
DWORD nUnkIndicesOffset; // points to array of unsigned short

DWORD nUnkLongs;
DWORD nUnkLongsOffset; // points to array of longs

DWORD nBonesCount;
DWORD nBonesOffset; // points to M2_BONE_DATA

DWORD nUnkIndices2;
DWORD nUnkIndicesOffset2; // points to array of unsigned short

DWORD nNumVertices;
DWORD nVerticesOffset; // points to M2_Vertex!!!

DWORD nNumGeoMeshs;  
DWORD nGeoMeshsOffset; // Points to M2_GEOMETRY_MESH!!!

DWORD dwMagic[2]; // 0s

DWORD nNumTextures;
DWORD nTexturesOffset; // points to M2_TEXTURE_INFO.

DWORD dwUnk6[10]; // Other chunks

DWORD nGroupBoneIDs; // Bone groups data
DWORD nGroupBoneIDsOffset; // points to array of unsigned short which is bone id.

DWORD nNumMaterials;
DWORD nMaterialsOffset;

DWORD nStruct1Count; // 16 bytes, only 1. 
DWORD nStruct1Offset;

DWORD nStruct2Count; // 16 bytes, only 1.
DWORD nStruct2Offset;

DWORD nStruct3Count; // 16 bytes, only 1.
DWORD nStruct3Offset;

vec3_type vMinBox; // Bounding box
vec3_type vMaxBox;

float fUnk4; // Unknown but it's right before min box when former mdx format.

float fUnk[5];
DWORD dwUnk8; // Unknown 0
float fUnk9;

DWORD dwUnk10;   // Always 36
DWORD dwUnk11[5];

DWORD nAttachments;
DWORD nAttachmentsOffset;

DWORD dwUnk12;
DWORD dwUnkOffset12;

DWORD nNumEvents;
DWORD nEventsOffset; 

DWORD dwUnk13;
DWORD dwUnkOffset13;

DWORD nCameras1;
DWORD nCameras1Offset;

DWORD nCameras2;
DWORD nCameras2Offset;
DWORD dwUnk14;

DWORD dwUnk15[6];
};       

// 纹理信息结构
struct M2_TEXTURE_INFO
{
DWORD nReplaceableId; // 非0时,表示换装(Creature/Character部分全部为换装类型).
DWORD dwUnk2; // 换装参数?
DWORD nNameSize; // 字符串长度,为1则空.
DWORD nNameOffset; // 字符串偏移位置
};

// 顶点信息结构 
struct M2_VERTEX // 48 bytes
{
vec3_type      v;
unsigned long  bwgt; // ?
unsigned short bidx; // ? 
unsigned short gndx; // ?
vec3_type    n;
vec2_type    u;
unsigned long  unk[2]; // Reserved 0 until now 1.12
};

// 几何 Mesh 信息结构
struct M2_GEOMETRY_MESH // 44 bytes
{
DWORD nNumIndexedVertices; // Indexed vertices count
DWORD nIndicesOffset; // Vertices indices array, points to unsigned shorts.
DWORD nPrimitivesCount; // Primitives count, Triangle's count * 3
DWORD nPrimitivesOffset; // Points to primitive vertex indices, MDL_TRIANGLEs. 
DWORD nNumGroupIndices; // Group indices count
DWORD nGroupIndicesOffset; // M2_4GROUP_INDICES array correlative with vertex.
DWORD nNumGeoParts; // per 32 bytes
DWORD nGeoPartsOffset; // points to M2_GEOMESH_GROUP_DATA
DWORD nUnk; // per 24 bypes
DWORD nUnkOffset; // points to M2_GROUP_BONE_DATA
DWORD dwUnk3; // one of 256, 75, 53, 21 
};

struct M2_ANIMATION_INFO // 68 bytes
{
DWORD   nAnimationClass; // Refer to AnimationData.dbc's first field.
DWORD nFrameBegin;
DWORD nFrameEnd;
float fMoveSpeed;
int bNonLooping;
int nUnk1;
DWORD   nUnk2;
DWORD   nUnk3;
DWORD   nUnk4;   
vec3_type vMins; // Unsure?
vec3_type vMaxs;
float   fBoundsRadius;
DWORD   nUnk5;
};  

struct M2_ANIM_FRAME_SEQUENCE // Animation Frame Sequence
{
short wType;
short wFlags;
DWORD dwLineTypeCount; // Interpolate type?
DWORD dwLineTypeOffset;
DWORD nFramesCount; // num of frame indices
DWORD nFramesOffset; // points to frame indices array 
DWORD nMtDataCount; // num of frame matrix transform data(translate/rotate/scale)
DWORD nMtDataOffset; // frame matrix transform data offset 
};

struct M2_BONE_DATA
{
int   nParentID;
short wObjTag;
short wUnk;
short nGeosetAnimID;
short nGeosetID;
M2_ANIM_FRAME_SEQUENCE infoTranslate;
M2_ANIM_FRAME_SEQUENCE infoRotate;
M2_ANIM_FRAME_SEQUENCE infoScale;
vec3_type vPivotPoint;
};

struct M2_TRANSLATE_DATA
{
vec3_type vTrans;
};

struct M2_ROTATE_DATA
{
quaternion_type qRotate;
};

struct M2_SCALE_DATA
{
vec3_type vScale;
};

struct M2_GEOMESH_GROUP_DATA
{
DWORD dwUnk;
unsigned short nUnk0;
unsigned short nNumVertices;
unsigned short nUnk2;
unsigned short nPrimitivesCount;
unsigned short nGroupCount;
unsigned short nUnk4;
unsigned short nUnk5;
unsigned short nUnk6;
vec3_type vUnk;
};

struct M2_GROUP_BONE_DATA
{
short dwUnk[12];
};

struct M2_4GROUP_INDICES
{
unsigned char idx[4];
};

posted on 2005-08-13 17:42 linghuye 阅读(2138) 评论(0)  编辑 收藏 引用 所属分类: MyWarCraftStudio

只有注册用户登录后才能发表评论。