終于決定,還是通過(guò)wow model viewer起手,研究一下WOW的數(shù)據(jù)類(lèi)型,從另一個(gè)角度,體驗(yàn)一把這個(gè)唯一讓我充過(guò)值的游戲。
這將是一系列隨筆,即在讀代碼的時(shí)候,順便記錄,以理清思路和加深映象。 其中會(huì)有很多讓人費(fèi)解的地方,如果有幸被某位兄弟看見(jiàn)
,請(qǐng)勿見(jiàn)笑。
這都是第四篇關(guān)于M2文件格式的文章了,但是,對(duì)MD2文件格式的理解卻還是九牛一毛,冰山一角。 仔細(xì)思考了一下,發(fā)現(xiàn)是不是自己一
開(kāi)始走的路不對(duì),因?yàn)槭菑陌胙戏治龅摹?今天決定把文件頭補(bǔ)上。 因?yàn)槲募^可以大概看出一個(gè)文件是如何組織數(shù)據(jù),以及包含哪些
數(shù)據(jù)的。
在此,給出WotLK的頭文件定義
char id[4];
uint8 version[4];
uint32 nameLength;
uint32 nameOfs;
uint32 GlobalModelFlags; // 1: tilt x, 2: tilt y, 4:, 8: add another field in header, 16: ; (no other flags as
of 3.1.1);
uint32 nGlobalSequences; // AnimationRelated
uint32 ofsGlobalSequences; // A list of timestamps.
uint32 nAnimations; // AnimationRelated
uint32 ofsAnimations; // Information about the animations in the model.
uint32 nAnimationLookup; // AnimationRelated
uint32 ofsAnimationLookup; // Mapping of global IDs to the entries in the Animation sequences block.
//uint32 nD;
//uint32 ofsD;
uint32 nBones; // BonesAndLookups
uint32 ofsBones; // Information about the bones in this model.
uint32 nKeyBoneLookup; // BonesAndLookups
uint32 ofsKeyBoneLookup; // Lookup table for key skeletal bones.
uint32 nVertices; // GeometryAndRendering
uint32 ofsVertices; // Vertices of the model.
uint32 nViews; // GeometryAndRendering
//uint32 ofsViews; // Views (LOD) are now in .skins.
uint32 nColors; // ColorsAndTransparency
uint32 ofsColors; // Color definitions.
uint32 nTextures; // TextureAndTheifAnimation
uint32 ofsTextures; // Textures of this model.
uint32 nTransparency; // H, ColorsAndTransparency
uint32 ofsTransparency; // Transparency of textures.
//uint32 nI; // always unused ?
//uint32 ofsI;
uint32 nTexAnims; // J, TextureAndTheifAnimation
uint32 ofsTexAnims;
uint32 nTexReplace; // TextureAndTheifAnimation
uint32 ofsTexReplace; // Replaceable Textures.
uint32 nTexFlags; // Render Flags
uint32 ofsTexFlags; // Blending modes / render flags.
uint32 nBoneLookup; // BonesAndLookups
uint32 ofsBoneLookup; // A bone lookup table.
uint32 nTexLookup; // TextureAndTheifAnimation
uint32 ofsTexLookup; // The same for textures.
uint32 nTexUnitLookup; // L, TextureAndTheifAnimation, seems gone after Cataclysm
uint32 ofsTexUnitLookup; // And texture units. Somewhere they have to be too.
uint32 nTransparencyLookup; // M, ColorsAndTransparency
uint32 ofsTransparencyLookup; // Everything needs its lookup. Here are the transparencies.
uint32 nTexAnimLookup; // TextureAndTheifAnimation
uint32 ofsTexAnimLookup; // Wait. Do we have animated Textures? Wasn't ofsTexAnims deleted? oO
Sphere collisionSphere;
Sphere boundSphere;
uint32 nBoundingTriangles; // Miscellaneous
uint32 ofsBoundingTriangles;
uint32 nBoundingVertices; // Miscellaneous
uint32 ofsBoundingVertices;
uint32 nBoundingNormals; // Miscellaneous
uint32 ofsBoundingNormals;
uint32 nAttachments; // O, Miscellaneous
uint32 ofsAttachments; // Attachments are for weapons etc.
uint32 nAttachLookup; // P, Miscellaneous
uint32 ofsAttachLookup; // Of course with a lookup.
uint32 nEvents; //
uint32 ofsEvents; // Used for playing sounds when dying and a lot else.
uint32 nLights; // R
uint32 ofsLights; // Lights are mainly used in loginscreens but in wands and some doodads too.
uint32 nCameras; // S, Miscellaneous
uint32 ofsCameras; // The cameras are present in most models for having a model in the Character-Tab.
uint32 nCameraLookup; // Miscellaneous
uint32 ofsCameraLookup; // And lookup-time again, unit16
uint32 nRibbonEmitters; // U, Effects
uint32 ofsRibbonEmitters; // Things swirling around. See the CoT-entrance for light-trails.
uint32 nParticleEmitters; // V, Effects
uint32 ofsParticleEmitters; // Spells and weapons, doodads and loginscreens use them. Blood dripping of a blade?
Particles.
};
在說(shuō)明之前,有幾個(gè)約定需要講解一下,以便簡(jiǎn)單。 結(jié)構(gòu)體中的 nXXXXX表示,有多少個(gè)這樣的數(shù)據(jù)單元
而ofsXXXXXX表示,在哪里讀取這個(gè)數(shù)據(jù)。 而每一個(gè)數(shù)據(jù)單元具體的大小和信息,則需要由額外的地方來(lái)定義。
在解釋的時(shí)候,就不對(duì)nXXXXX和ofsXXXX多作解釋了。
下面逐一說(shuō)明各變量的作用的含意
id: 必然是 'M' 'D' '2' '0'
version: 用來(lái)檢查文件版本的。 可以是以下值
// 10 1 0 0 = WoW 5.0 models (as of 15464)
// 10 1 0 0 = WoW 4.0.0.12319 models
// 9 1 0 0 = WoW 4.0 models
// 8 1 0 0 = WoW 3.0 models
// 4 1 0 0 = WoW 2.0 models
// 0 1 0 0 = WoW 1.0 models
nameLength和nameOfs 在WMV中,除了看到拿來(lái)檢測(cè)數(shù)據(jù)合法性外,沒(méi)有看到拿來(lái)讀取數(shù)據(jù)的地方
GlobalModelFlags 模型的全局標(biāo)志位,在WMV中除了看到用于輸出外,沒(méi)有看到有其它地方使用
nGlobalSequences和ofsGlobalSequences 一個(gè)全局?jǐn)?shù)據(jù)序列,數(shù)據(jù)單元類(lèi)型為UINT32
nAnimations和ofsAnimations 動(dòng)畫(huà)數(shù)據(jù)信息,數(shù)據(jù)單元類(lèi)型由ModelAnimation定義,此定義在WMV中如下。
struct ModelAnimation
{
uint32 animID; // AnimationDataDB.ID
uint32 timeStart;
uint32 timeEnd;
float moveSpeed;
uint32 flags;
uint16 probability;
uint16 unused;
uint32 d1;
uint32 d2;
uint32 playSpeed; // note: this can't be play speed because it's 0 for some models
Sphere boundSphere;
int16 NextAnimation;
int16 Index;
};
它主要是定義一個(gè)動(dòng)畫(huà)的相關(guān)參數(shù),比如ID,開(kāi)始結(jié)束時(shí)間等等。
nAnimationLookup,動(dòng)畫(huà)數(shù)據(jù)查看表,主要是給外部提供一個(gè)查詢(xún)的便利性,數(shù)據(jù)單元類(lèi)型為UINT16
nBones,ofsBones 骨骼數(shù)據(jù),數(shù)據(jù)單元類(lèi)型為ModelBoneDef 其定義大致如下
struct ModelBoneDef {
int32 keyboneid; // Back-reference to the key bone lookup table. -1 if this is no key bone.
int32 flags; // Only known flags: 8 - billboarded and 512 - transformed
int16 parent; // parent bone index
int16 geoid; // A geoset for this bone.
int32 unknown; // new int added to the bone definitions. Added in WoW 2.0
AnimationBlock translation; // (Vec3D)
AnimationBlock rotation; // (QuatS)
AnimationBlock scaling; // (Vec3D)
Vec3D pivot;
};
可以看出,每個(gè)骨頭都有一個(gè)ID,以及一些標(biāo)志位,同時(shí)記錄了其父骨骼的索引。 而骨骼本身,則有平移,旋轉(zhuǎn),縮放和錨點(diǎn)等數(shù)據(jù)。
nKeyBoneLookup也是一個(gè)提供快速查詢(xún)的數(shù)據(jù)。 M2中很多對(duì)應(yīng)的信息,都提供了這樣的LOOK UP TABLE。 典型的以空間換時(shí)間的做法。
nVertices,ofsVertices 頂點(diǎn)信息,其數(shù)據(jù)單元定義如下
struct ModelVertex
{
Vec3D pos;
uint8 weights[4];
uint8 bones[4];
Vec3D normal;
Vec2D texcoords;
int unk1, unk2; // always 0,0 so this is probably unused
};
每一個(gè)頂點(diǎn)數(shù)據(jù),有一個(gè)位置信息,4個(gè)骨骼索引和對(duì)應(yīng)的權(quán)重 (其實(shí)貌似權(quán)重存3個(gè)就可以了。) 法線(xiàn)(法線(xiàn)貌似也只存兩個(gè)FLOAT就
可以了。) 紋理坐標(biāo) 以及兩個(gè)沒(méi)有摸索出用途的INT。 值得注意的是,WOW中的坐標(biāo)用的是Z向上,Y向里的坐標(biāo)。 如果要將WOW中的坐
標(biāo)轉(zhuǎn)換到左手坐標(biāo)系(D3D默認(rèn))中。 則 X0,Y0,Z0 = X,Z,Y 若轉(zhuǎn)換成右手坐標(biāo)系(OPENGL默認(rèn)) 則 X0,Y0,Z0 = X,Z,-Y. 這個(gè)在
前面分析數(shù)據(jù)的時(shí)候有說(shuō)過(guò)。 因?yàn)樵赪MV中,就有轉(zhuǎn)換坐標(biāo)系相關(guān)的操作。
nViews, 此值表示模型有多少個(gè)LOD數(shù)據(jù)。 在WotLK版本以后,LOD數(shù)據(jù)全部被放入了 *.skin文件中。 不再在M2文件中讀取。
假設(shè)一個(gè)模型為 ooxx.m2 那其對(duì)應(yīng)的LOD文件信息可以為 ooxx00.skin ooxx01.skin ooxx02.skin ooxx03.skin,而此M2模型的具體子
模型劃分等細(xì)節(jié),都在skin文件中了。
nColors,ofsColors 此模型用到的顏色序列,用于實(shí)現(xiàn)模型動(dòng)態(tài)變色效果 其數(shù)據(jù)單元定義為
struct ModelColorDef {
AnimationBlock color; // (Vec3D) Three floats. One for each color.
AnimationBlock opacity; // (UInt16) 0 - transparent, 0x7FFF - opaque.
};
struct AnimationBlock {
int16 type; // interpolation type (0=none, 1=linear, 2=hermite)
int16 seq; // global sequence id or -1
uint32 nRanges;
uint32 ofsRanges;
uint32 nTimes;
uint32 ofsTimes;
uint32 nKeys;
uint32 ofsKeys;
};
nTextures,ofsTextures定義了此模型用到的紋理序列,其結(jié)構(gòu)定義如下
#define TEXTURE_MAX 32
struct ModelTextureDef
{
uint32 type;
uint32 flags;
uint32 nameLen;
uint32 nameOfs;
};
關(guān)于紋理相關(guān)的內(nèi)容,得專(zhuān)門(mén)有一篇文章講解一下才行。這個(gè)內(nèi)容有點(diǎn)多,但是思路卻很清楚清晰
nTransparency,ofsTransparency用于實(shí)現(xiàn)透明變化效果,其讀取結(jié)構(gòu)定義如下
struct ModelTransDef
{
AnimationBlock trans; // (UInt16)
};
AnimationBlock的定義上面已經(jīng)給出
nTexAnims 紋理動(dòng)畫(huà),結(jié)構(gòu)體定義如下
struct ModelTexAnimDef {
AnimationBlock trans; // (Vec3D)
AnimationBlock rot; // (QuatS)
AnimationBlock scale; // (Vec3D)
};
這個(gè)表示在不同的情況下,紋理矩陣作用的效果,一些爆布,火盆上的火焰或者流動(dòng)的巖漿就是通過(guò)這個(gè)實(shí)現(xiàn)的。
nTexReplace 字面上是可替換的紋理,在WMV中沒(méi)有發(fā)現(xiàn)具體的用法。
nTexFlags 紋理標(biāo)記位,在WMV中沒(méi)有發(fā)現(xiàn)具體用法
nBoneLookup 骨骼查詢(xún)表,在WMV中,除了拿來(lái)顯示以外,沒(méi)有看到特別的作用。
nTexLookup 紋理查詢(xún)表,用于快速定位一個(gè)nTextures中讀出來(lái)的紋理。
nTexUnitLookup 紋理單元查詢(xún)表,和上面的功能類(lèi)似,貌似CTM版本就沒(méi)有使用到了。
nTransparencyLookup 透明信息查詢(xún)表
nTexAnimLookup 紋理信息查詢(xún)表
collisionSphere 碰撞球
boundSphere 包圍球
nBoundingTriangles 構(gòu)成包圍網(wǎng)格的三角形數(shù)據(jù) 每個(gè)數(shù)據(jù)單元是UINT16
nBoundingVertices 構(gòu)成包圍網(wǎng)格的頂點(diǎn)數(shù)據(jù) 每個(gè)數(shù)據(jù)單元是Vec3D,即三個(gè)FLOAT
nBoundingNormals 構(gòu)成包圍網(wǎng)格的法線(xiàn)數(shù)據(jù) 數(shù)據(jù)同上
nAttachments掛接點(diǎn)的信息 每個(gè)掛接點(diǎn)的信息定義如下
struct ModelAttachmentDef
{
uint32 id; // Just an id. Is referenced in the enum POSITION_SLOTS.
uint32 bone; // Somewhere it has to be attached.
Vec3D pos; // Relative to that bone of course.
AnimationBlock unk; // (Int32) Its an integer in the data. It has been 1 on all models I saw. Whatever.
};
nAttachLookup 掛接點(diǎn)查詢(xún)表,用于快速定位某個(gè)掛接點(diǎn)
nEvents 動(dòng)畫(huà)播放時(shí)的事件觸發(fā),用于完成一些特殊的,比如音效的播放,攻擊方與受擊方的動(dòng)畫(huà)吻合等。 定義如下
struct ModelEventDef
{
char id[4]; // This is a (actually 3 character) name for the event with a $ in front.
int32 dbid; // This data is passed when the event is fired.
int32 bone; // Somewhere it has to be attached.
Vec3D pos; // Relative to that bone of course.
int16 type; // This is some fake-AnimationBlock.
int16 seq; // Built up like a real one but without timestamps(?). What the fuck?
uint32 nTimes; // See the documentation on AnimationBlocks at this topic.
uint32 ofsTimes; // This points to a list of timestamps for each animation given.
};
關(guān)于ID的值,WMV中列出了一些摸索到的。
/*
There are a lot more of them. I did not list all up to now.
ID Data Description
DEST exploding ballista, that one has a really fucked up block. Oo
POIN unk something alliance gunship related (flying in icecrown)
WHEE 601+ Used on wheels at vehicles.
$tsp p is {0 to 3} (position); t is {W, S, B, F (feet) or R} (type); s is {R or L} (right or left); this is
used when running through snow for example.
$AHx UnitCombat_C, x is {0 to 3}
$BRT Plays some sound.
$BTH Used for bubbles or breath. ("In front of head")
$BWP UnitCombat_C
$BWR Something with bow and rifle. Used in AttackRifle, AttackBow etc. "shoot now"?
$CAH UnitCombat_C
$Cxx UnitCombat_C, x is {P or S}
$CSD SoundEntries.dbc Emote sounds?
$CVS SoundEntriesAdvanced.dbc Sound
$DSE
$DSL SoundEntries.dbc Sound with something special. Use another one if you always want to have it playing..
$DSO SoundEntries.dbc Sound
$DTH UnitCombat_C, death, this plays death sounds and more.
$EMV MapLoad.cpp
$ESD Plays some emote sound.
$EWT MapLoad.cpp
$FDx x is {1 to 5}. Calls some function in the Object VMT. Also plays some sound.
$FDx x is {6 to 9}. Calls some function in the Object VMT.
$FDX Should do nothing. But is existant.
$FSD Plays some sound.
$GCx Play gameobject custom sound referenced in GameObjectDisplayInfo.dbc. x can be from {0 to 3}: {Custom0,
Custom1, Custom2, Custom3}
$GOx Play gameobject sound referenced in GameObjectDisplayInfo.dbc. x can be from {0 to 5}: {Stand, Open,
Loop, Close, Destroy, Opened}
$HIT Get hit?
$KVS MapLoad.cpp
$SCD Plays some sound.
$SHK SpellEffectCameraShakes.dbc Add a camera shake
$SHx x is {L or R}, fired on Sheath and SheathHip. "Left/right shoulder" was in the old list.
$SMD Plays some sound.
$SMG Plays some sound.
$SND SoundEntries.dbc Sound
$TRD Does something with a spell, a sound and a spellvisual.
$VGx UnitVehicle_C, x is {0 to 8}
$VTx UnitVehicle_C, x is {0 to 8}
$WxG x is {W or N}. Calls some function in the Object VMT.
------- ---------------------------------- - Old documentation (?) ----------------------------------------------
$CSx x is {L or R} ("Left/right hand") (?)
$CFM
$CHD ("Head") (?)
$CCH ("Bust") (?)
$TRD ("Crotch") (?)
$CCH ("Bust") (?)
$BWR ("Right hand") (?)
$CAH
$CST
*/
nLights 光照信息,標(biāo)記了,模型的哪個(gè)骨骼上,掛接了燈光。 結(jié)構(gòu)定義如下
struct ModelLightDef {
int16 type; // 0: Directional, 1: Point light
int16 bone; // If its attached to a bone, this is the bone. Else here is a nice -1.
Vec3D pos; // Position, Where is this light?
AnimationBlock ambientColor; // (Vec3D) The ambient color. Three floats for RGB.
AnimationBlock ambientIntensity; // (Float) A float for the intensity.
AnimationBlock diffuseColor; // (Vec3D) The diffuse color. Three floats for RGB.
AnimationBlock diffuseIntensity; // (Float) A float for the intensity again.
AnimationBlock attenuationStart; // (Float) This defines, where the light starts to be.
AnimationBlock attenuationEnd; // (Float) And where it stops.
AnimationBlock useAttenuation; // (Uint32) Its an integer and usually 1.
};
nCameras 真的不是太懂這個(gè)。 結(jié)構(gòu)體定義如下
struct ModelCameraDef {
int32 id; // 0 is potrait camera, 1 characterinfo camera; -1 if none; referenced in CamLookup_Table
float fov; // No radians, no degrees. Multiply by 35 to get degrees.
float farclip; // Where it stops to be drawn.
float nearclip; // Far and near. Both of them.
AnimationBlock transPos; // (Vec3D) How the cameras position moves. Should be 3*3 floats. (? WoW parses 36 bytes
= 3*3*sizeof(float))
Vec3D pos; // float, Where the camera is located.
AnimationBlock transTarget; // (Vec3D) How the target moves. Should be 3*3 floats. (?)
Vec3D target; // float, Where the camera points to.
AnimationBlock rot; // (Quat) The camera can have some roll-effect. Its 0 to 2*Pi.
};
nCameraLookup 攝相機(jī)信息查詢(xún)表
nRibbonEmitters 此模型身上的多邊形軌跡(緞帶)效果數(shù)目。 結(jié)構(gòu)體定義如下
struct ModelRibbonEmitterDef {
int32 id;
int32 bone;
Vec3D pos;
int32 nTextures;
int32 ofsTextures;
int32 nUnknown;
int32 ofsUnknown;
AnimationBlock color; // (Vec3D)
AnimationBlock opacity; // (UInt16) And an alpha value in a short, where: 0 - transparent, 0x7FFF - opaque.
AnimationBlock above; // (Float) The height above.
AnimationBlock below; // (Float) The height below. Do not set these to the same!
float res; // This defines how smooth the ribbon is. A low value may produce a lot of edges.
float length; // The length aka Lifespan.
float Emissionangle; // use arcsin(val) to get the angle in degree
int16 s1, s2;
AnimationBlock unk1; // (short)
AnimationBlock unk2; // (boolean)
int32 unknown; // This looks much like just some Padding to the fill up the 0x10 Bytes, always 0
};
最后一個(gè)值unknown是WotLK版本后新增的,不知道拿來(lái)干什么。 但可以肯定,WLK版本,加強(qiáng)了這個(gè)效果類(lèi)型的表現(xiàn)力。
nParticleEmitters 粒子系統(tǒng),結(jié)構(gòu)體定義如下。
struct ModelParticleEmitterDefV10
{
int32 id;
int32 flags;
Vec3D pos; // The position. Relative to the following bone.
int16 bone; // The bone its attached to.
int16 texture; // And the texture that is used.
int32 nModelFileName;
int32 ofsModelFileName;
int32 nParticleFileName;
int32 ofsParticleFileName; // TODO
int8 blend;
int8 EmitterType; // EmitterType 1 - Plane (rectangle), 2 - Sphere, 3 - Spline? (can't be bothered to find one)
int16 ParticleColor; // This one is used so you can assign a color to specific particles. They loop over all
// particles and compare +0x2A to 11, 12 and 13. If that matches, the colors from the dbc get applied.
int8 ParticleType; // 0 "normal" particle,
// 1 large quad from the particle's origin to its position (used in Moonwell water effects)
// 2 seems to be the same as 0 (found some in the Deeprun Tram blinky-lights-sign thing)
int8 HeaderTail; // 0 - Head, 1 - Tail, 2 - Both
int16 TextureTileRotation; // TODO, Rotation for the texture tile. (Values: -1,0,1)
int16 cols; // How many different frames are on that texture? People should learn what rows and cols are.
int16 rows; // (2, 2) means slice texture to 2*2 pieces
AnimationBlock EmissionSpeed; // (Float) All of the following blocks should be floats.
AnimationBlock SpeedVariation; // (Float) Variation in the flying-speed. (range: 0 to 1)
AnimationBlock VerticalRange; // (Float) Drifting away vertically. (range: 0 to pi)
AnimationBlock HorizontalRange; // (Float) They can do it horizontally too! (range: 0 to 2*pi)
AnimationBlock Gravity; // (Float) Fall down, apple!
AnimationBlock Lifespan; // (Float) Everyone has to die.
int32 unknown;
AnimationBlock EmissionRate; // (Float) Stread your particles, emitter.
int32 unknown2;
AnimationBlock EmissionAreaLength; // (Float) Well, you can do that in this area.
AnimationBlock EmissionAreaWidth; // (Float)
AnimationBlock Gravity2; // (Float) A second gravity? Its strong.
ModelParticleParams p;
AnimationBlock en; // (UInt16), seems unused in cataclysm
int32 unknown3; // 12319, cataclysm
int32 unknown4; // 12319, cataclysm
int32 unknown5; // 12319, cataclysm
int32 unknown6; // 12319, cataclysm
};
可見(jiàn)WOW在粒子這塊的處理還是比較用心的,畢竟很多裝備上都是這種效果,特別是武器,肩膀,頭盔,盾牌等裝備上的效果。
后面CTM中新增的4個(gè)INT,可能是為了加強(qiáng)效果用的。 說(shuō)明WOW還在繼續(xù)增強(qiáng)粒子系統(tǒng)的表現(xiàn)力。 也就是說(shuō),WOW中裝備的表現(xiàn)力還是將會(huì)通過(guò)粒子系統(tǒng)來(lái)實(shí)現(xiàn)。
哇靠,又一點(diǎn)了。 發(fā)貼睡覺(jué)。。。。。