📄 m2header.h
字号:
//--------------------------------------------------
// Desc: M2 header
// Date: 2007.3.30 /update
// Author: Artsylee
//
// From: WOW Model Viewer
// I just coding in my own ways!
//
//--------------------------------------------------
#ifndef _M2HEADER_
#define _M2HEADER_
#include <d3dx9.h>
typedef __int8 int8;
typedef __int16 int16;
typedef __int32 int32;
typedef unsigned __int8 uint8;
typedef unsigned __int16 uint16;
typedef unsigned __int32 uint32;
#pragma pack(push, 1)
struct ModelHeader
{
uint8 id[4]; // ID (MD20)
uint8 version[4]; // 版本(00 01 00 00)
uint32 nameLength; // 模型名长度(strlen(x)+1), 实际占用最小16字节
uint32 nameOfs; // 模型名偏移
uint32 type; // 类型Model type always 0, 1 or 3 (mostly 0)
uint32 nGlobalSequences; // 全局时间序列数量
uint32 ofsGlobalSequences; // 时间序列偏移, 指向uint32类型
uint32 nAnimations; // 动画组数
uint32 ofsAnimations; // 动画偏移, 指向ModelAnimation
uint32 nC;
uint32 ofsC;
uint32 nD; // always 201 or 203 depending on WoW client version
uint32 ofsD;
uint32 nBones; // 骨骼数量
uint32 ofsBones; // 骨骼偏移, 指向ModelBoneDef
uint32 nF; // 骨骼查找表(一般为27)
uint32 ofsF; // 指向int16
uint32 nVertices; // 顶点
uint32 ofsVertices; // 顶点偏移, 指向ModelVertex
uint32 nViews; // number of LOD views 4 for every model (4个)
uint32 ofsViews; // 指向ModelView
uint32 nColors; // 用于颜色动画
uint32 ofsColors; // 指向ModelColorDef
uint32 nTextures; // 纹理
uint32 ofsTextures; // 指向ModelTextureDef
uint32 nTransparency; // 透明度动画
uint32 ofsTransparency; // 指向ModelTransDef
uint32 nI; // always unused ?
uint32 ofsI;
uint32 nTexAnims; // 纹理动画
uint32 ofsTexAnims; // 指向ModelTexAnimDef
uint32 nTexReplace;
uint32 ofsTexReplace;
uint32 nTexFlags; // renderFlags
uint32 ofsTexFlags; // 指向ModelRenderFlags
uint32 nY;
uint32 ofsY;
uint32 nTexLookup; // 全局纹理数组的查询表
uint32 ofsTexLookup; // 指向uint16
uint32 nTexUnitLookup; // 纹理单元查找表
uint32 ofsTexUnitLookup; // 指向int16
uint32 nTransparencyLookup; // 透明度查找表
uint32 ofsTransparencyLookup; // 指向int16
uint32 nTexAnimLookup; // 纹理动画查找表
uint32 ofsTexAnimLookup; // 指向 uint16
float floats[14];
uint32 nBoundingTriangles; // 包围体三角形顶点索引(一般为36)
uint32 ofsBoundingTriangles; // 指向 uint16
uint32 nBoundingVertices; // 包围体顶点(一般为8)
uint32 ofsBoundingVertices; // 指向Vec3D
uint32 nBoundingNormals; // 包围体法线(一般为12)
uint32 ofsBoundingNormals;
uint32 nAttachments; // 可以换装放装备等部位
uint32 ofsAttachments; // 指向ModelAttachmentDef
uint32 nAttachLookup; // 附属装备查找表
uint32 ofsAttachLookup; // 指向int16
uint32 nQ;
uint32 ofsQ;
uint32 nLights; // 光源
uint32 ofsLights; // 指向ModelLightDef
uint32 nCameras; // 模型摄像机
uint32 ofsCameras; // 指向ModelCameraDef
uint32 nT; // nCameraLookup ?
uint32 ofsT;
uint32 nRibbonEmitters; // RIBBON
uint32 ofsRibbonEmitters; // 指向ModelRibbonEmitterDef
uint32 nParticleEmitters; // 粒子系统
uint32 ofsParticleEmitters; // 指向ModelParticleEmitterDef
};
// vertex
struct ModelVertex { D3DXVECTOR3 pos; // 位置 uint8 weights[4]; // 权重 uint8 bones[4]; // 骨骼INDEX, 每个顶点最多受四个骨骼影响 D3DXVECTOR3 normal; // 法线 D3DXVECTOR2 texcoords; // UV坐标 int unk1; // always 0,0 so this is probably unused
int unk2; // always 0,0 so this is probably unused
};
// texturestruct ModelTextureDef { uint32 type; // 类型(为0时代表使用M2文件中指定的纹理,非0时代表换装的部位) uint32 flags; // 标志(是否Wrap UV显示) uint32 nameLen; // 文件名长度 uint32 nameOfs; // 文件名偏移};
// LOD view
struct ModelView
{
uint32 nIndex; // Index数量
uint32 ofsIndex; // (index into vertices[])指向uint16(一般指向的值为0至(nIndex-1)顺序增加)
uint32 nTris; // 三角形顶点索引数量
uint32 ofsTris; // indices(指向uint16)
uint32 nProps; // additional vertex
uint32 ofsProps; // additional vertex properties
uint32 nSub; // Sub mesh数量
uint32 ofsSub; // materials/renderops/submeshes(指向SUBMESH---ModelGeoset)
uint32 nTex; // material properties/textures
uint32 ofsTex; // (指向ModelTexUnit)
int32 lod; // LOD bias?
};
// One material + render operation
struct ModelGeoset
{
uint16 id; // mesh part id?
uint16 d2; // ?
uint16 vstart; // first vertex
uint16 vcount; // number vertices
uint16 istart; // first index
uint16 icount; // number indices
uint16 d3; // number of bone indices
uint16 d4; // ? always 1 to 4
uint16 d5; // ?
uint16 d6; // root bone?
D3DXVECTOR3 v;
};
// A texture unit (sub of material)
struct ModelTexUnit
{
// probably the texture units
// size always >=number of materials it seems
uint16 flags; // Flags
uint16 order; // ?
uint16 op; // 该纹理单元对应的子MESH索引, 索引可基本确定子MESH部位
uint16 op2; // Always same as above?
int16 colorIndex; // color index or -1
uint16 flagsIndex; // ModelRenderFlags index
uint16 texunit; // Texture unit (0 or 1)
uint16 d4; // ? (seems to be always 1)
uint16 textureid; // Texture id (index into global texture list)
uint16 texunit2; // copy of texture unit value?
uint16 transid; // transparency id (index into transparency list)
uint16 texanimid; // texture animation id
};
// animations
struct ModelAnimation
{
uint32 animID; // 动画组ID(相当于该动画怎么用的)
uint32 timeStart; // 开始时间
uint32 timeEnd; // 结束时间
float moveSpeed; // 速度
uint32 loopType; // LOOP类型
uint32 flags;
uint32 d1;
uint32 d2;
uint32 playSpeed; // note: this can't be play speed because it's 0 for some models
D3DXVECTOR3 boxA, boxB; //
float rad; // 区域
int16 s[2];
};
// animation data
struct AnimationBlock
{
int16 type; // interpolation type (0=none, 1=linear, 2=hermite)
int16 seq; // global sequence id or -1
uint32 nRanges;
uint32 ofsRanges; // 指向uint32
uint32 nTimes; // nTimes == nKeys
uint32 ofsTimes; // 指向uint32
uint32 nKeys;
uint32 ofsKeys; // 指向类型不定(Vec3D, 四无数, float, uint8)
};
// bones
struct ModelBoneDef
{
int32 animid; // ID, 暂时没用到,有时为-1
int32 flags; // unknown(有时00 20 00 00)
int16 parent; // parent bone index or -1
int16 geoid; // unknown
AnimationBlock translation;
AnimationBlock rotation;
AnimationBlock scaling;
D3DXVECTOR3 pivot;
};
// texture animation
struct ModelTexAnimDef
{
AnimationBlock trans;
AnimationBlock rot;
AnimationBlock scale;
};// render flagsstruct ModelRenderFlags { uint16 flags; uint16 blend; // blend mode};// color animationstruct ModelColorDef { AnimationBlock color; // 颜色 AnimationBlock opacity; // 不透明度};// Transparency animationstruct ModelTransDef { AnimationBlock trans; // 透明度};// model lightstruct ModelLightDef { int16 type; int16 bone; D3DXVECTOR3 pos; AnimationBlock ambColor; AnimationBlock ambIntensity; AnimationBlock color; AnimationBlock intensity; AnimationBlock attStart; AnimationBlock attEnd; AnimationBlock unk1;};// model camerastruct ModelCameraDef { int32 id; float fov; float farclip; float nearclip; AnimationBlock transPos; D3DXVECTOR3 pos; AnimationBlock transTarget; D3DXVECTOR3 target; AnimationBlock rot;};// attachmentstruct ModelAttachmentDef { int32 id; int32 bone; D3DXVECTOR3 pos; AnimationBlock unk;};// particlestruct ModelParticleParams { float mid; uint32 colors[3]; float sizes[3]; int16 d[10]; float unk[3]; float scales[3]; float slowdown; float rotation; float f2[16];};// particle emitterstruct ModelParticleEmitterDef { int32 id; int32 flags; // 标记(与billboard有关) D3DXVECTOR3 pos; // 位置 int16 bone; // 模型骨骼索引 int16 texture; // 纹理 int32 nZero1; int32 ofsZero1; int32 nZero2; int32 ofsZero2; int16 blend; // 混合方式 int16 type; // 发射器类型 int16 s1; // 面向摄像机方式 int16 s2; // Texture tile rotation (-1,0,1) int16 cols; // 使用的纹理包含纹理动画时,一列包含的动画帧数目 int16 rows; // 一行 AnimationBlock params[10]; // 10个属性的关键帧数据 ModelParticleParams p; AnimationBlock en;};// ribbon emitterstruct ModelRibbonEmitterDef { int32 id; int32 bone; D3DXVECTOR3 pos; // 位置 int32 nTextures; int32 ofsTextures; int32 nUnknown; int32 ofsUnknown; AnimationBlock color; AnimationBlock opacity; AnimationBlock above; AnimationBlock below; float res, length, unk; int16 s1, s2; AnimationBlock unk1; AnimationBlock unk2;};// block Qstruct ModelBlockQ { char id[4]; int32 dbid; int32 bone; D3DXVECTOR3 pos; int16 type;
int16 seq;
uint32 nRanges;
uint32 ofsRanges;
uint32 nTimes;
uint32 ofsTimes;
};// character detailstruct CharModelDetails
{
bool closeRHand;
bool closeLHand;
bool isChar;
bool isMounted;
void Reset()
{
closeRHand = false;
closeLHand = false;
isChar = false;
isMounted = false;
}
};#pragma pack(pop)
#endif // _M2HEADER_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -