青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

永遠也不完美的程序

不斷學習,不斷實踐,不斷的重構……

常用鏈接

統計

積分與排名

好友鏈接

最新評論

MD5Mesh and MD5Anim files formats(Doom 3's models)

Written by David Henry, 21th august of 2005

NOTE: this has nothing to do with the cryptographic hash function also called “MD5”.

Introduction

The MD5 model format comes from id Software's Doom 3 first person shooter, released in august 2004. The mesh data and animation data are separated in distinct files. These are ASCII files and are human readable. Here are some generalities about the MD5 format:

  • Model's geometric data are stored in *.md5mesh files;
  • Animations are stored in *.md5anim files;
  • Supports Skeletal Animation;
  • Supports Vertex Skinning;
  • Uses quaternions for orientation.

Textures are in separate files (TGA, DDS, or whatever you want). In Doom 3, they are controlled by the *.mtr files in the /materials directory from the game's *.pk4 files. The MTR files are not covered here.

Working with quaternions

The MD5 Mesh and MD5 Anim formats work with quaternions. Quaternions are magic mathematical objects which can represent an orientation. Quaternions are an extension of the complex numbers. If you just discover them now, or don't know how to use them, take a look at a computer graphics math book or at an online FAQ about them.

Quaternions are an alternative to matrices for representing a rotation. Quaternions can't hold information about position (like 4x4 matrices), just the orientation. They can hold the same information as 3x3 rotation matrices.

There is not a lot of things to know about quaternions here, just some formulas:

  • Quaternion multiplication (Quat × Quat);
  • Rotation of a point by a quaternion;
  • Quaternion inverse;
  • Quaternion normalization;
  • Quaternion interpolation (SLERP), for smooth animation.

Quaternions are represented by four components: w, x, y and z. Orientation quaternions are unit quaternions.

In the MD5 Mesh and MD5 Anim files, only the x, y and z components are stored. You'll have to compute the w-component yourself, given the three others.

Computing the w-component

Since we deal with only unit quaternions (their length is 1.0), we can obtain the last component with this formula:

float t = 1.0f - (q.x * q.x) - (q.y * q.y) - (q.z * q.z);
if (t < 0.0f)
{
q.w = 0.0f;
}
else
{
q.w = -sqrt (t);
}

Others quaternion operations

A realy quick overview of needed quaternion operations and formulas. For more about them, refer to a 3D Math book, an online FAQ or Wikipedia.

The quaternion multiplication allows to concatenate two rotations. The product of two quaternions Qa and Qb is given by the following formula :

Qa.Qb = (wa, va)(wb, vb) = (wawb - va·vb, wavb + wbva + wa×wb)

After expanding and making simplifications, we have the following result :

r.w = (qa.w * qb.w) - (qa.x * qb.x) - (qa.y * qb.y) - (qa.z * qb.z);
r.x = (qa.x * qb.w) + (qa.w * qb.x) + (qa.y * qb.z) - (qa.z * qb.y);
r.y = (qa.y * qb.w) + (qa.w * qb.y) + (qa.z * qb.x) - (qa.x * qb.z);
r.z = (qa.z * qb.w) + (qa.w * qb.z) + (qa.x * qb.y) - (qa.y * qb.x);

Be careful! Quaternions are non-commutative, i.e. Qa × Qb ≠ Qb × Qa.

The rotation of a point by a quaternion is given by the formula:

R = Q.P.Q*

Where R is the resultant quaternion, Q is the orientation quaternion by which you want to perform a rotation, Q* the conjugate of Q and P is the point converted to a quaternion. To convert a 3D vector to a quaternion, copy the x, y and z components and set the w component to 0. This is the same for quaternion to vector conversion: take the x, y and z components and forget the w.

Note: here the “.” is the multiplication operator.

Quaternion inverse can be obtained, for unit quaternions, by negating the x, y and z components (this is equal to the conjugate quaternion):

inverse(<w, x, y, z>) = conjugate(<w, x, y, z>) = <w, -x, -y, -z>

Quaternion normalization is exactly the same as for vectors, but with four components.

I will not cover the quaternions spherical linear interpolation (SLERP) here, but you can look at the sample code (at the end of this document), or in books, or in the web for the formula. Spherical linear interpolation is used to interpolate two orientations. It is usefull for skeletal animation.

MD5 Mesh

The MD5 Mesh files have the “md5mesh” extension. They contain the geometric data of the models:

  • Model's bind-pose skeleton;
  • One or multiple meshes. Each mesh have its proper data:
    • Vertices;
    • Triangles;
    • Vertex weights;
    • A shader name.

Reading a md5mesh file

When parsing the MD5 Mesh file, you can find comments. They start with the “//” string and goes to the end of the line. They are here just for humans who want to take a look at the file with a text editor, they don't affect model's data. You can ignore them.

Before loading the geometric data, you will find some precious variables needed to check if this is a valid md5mesh file and for allocating memory:

MD5Version 10
commandline "<string>"
numJoints <int>
numMeshes <int>

The first line tell you the version of the format. This is an integer. Doom 3's MD5 version is 10. This document covers the version 10 of the format. Olders (or newers) may differ in some points in the structure of the format.

Then comes the commmandline string used by Doom 3 with the exportmodels console command. I have nothing to tell you about it.

numJoints is the number of joints of the model's skeleton. numMeshes is the number of meshes of the model contained in the md5mesh file.

After that you have the bind-pose skeleton's joints:

joints {
"name" parent ( pos.x pos.y pos.z ) ( orient.x orient.y orient.z )
...
}

name (string) is the joint's name. parent (int) is the joint's parent index. If it is equal to -1, then the joint has no parent joint and is what we call a root joint. pos.x, pos.y and pos.z (float) are the joint's position in space. orient.x, orient.y and orient.z (float) are the joint's orientation quaternion x, y and z components. After reading a joint, you must calculate the w component.

After the skeleton, there are the meshes. Each mesh is in the form:

mesh {
shader "<string>"
numverts <int>
vert vertIndex ( s t ) startWeight countWeight
vert ...
numtris <int>
tri triIndex vertIndex[0] vertIndex[1] vertIndex[2]
tri ...
numweights <int>
weight weightIndex joint bias ( pos.x pos.y pos.z )
weight ...
}

The shader string is defined in the MTR files (/materials directory) of Doom 3 and tell you what are the textures to apply to the mesh and how to combine them.

numverts (int) is the number of vertices of the mesh. After this variable, you have the vertex list. vertIndex (int) is the vertex index. s and t (float) are the texture coordinates (also called UV coords). In the MD5 Mesh format, a vertex hasn't a proper position. Instead, its position is computed from vertex weights (this is explained later in this document). countWeight (int) is the number of weights, starting from the startWeight (int) index, which are used to calculate the final vertex position.

numtris is the number of triangles of the mesh. triIndex (int) is the index of the triangle. Each is defined by three vertex indices composing it: vertIndex[0], vertIndex[1] and vertIndex[2] (int).

numweights (int) is the number of weights of the mesh. weightIndex (int) is the weight index. joint (int) is the joint it depends of. bias (float) is a factor in the ]0.0, 1.0] range which defines the contribution of this weight when computing a vertex position. pos.x, pos.y and pos.z (float) are the weight's position in space.

The bind-pose skeleton

The model's skeleton stored in the MD5 Mesh files is what we call the “bind-pose skeleton”. It is generally in a position in which the model has been created.

Its joints are already in their final position, you don't have to make any precomputation on it, like adding the parent joint's position and rotating it or anything. Their position are in object space and independent of others joints.

Computing vertex positions

As said before, the vertex positions must be calculated from the weights. Each vertex has one or more weights, each of them having a position dependent of a joint (the position is in joint's local space), and a factor telling us how much it affects the vertex position. The sum of all weight factors of a vertex should be 1.0. This technique is called “vertex skinning” and allows a vertex to depend on more than one joint of the skeleton for better animation rendering.

First, each vertex' weight position must be converted from joint local space to object space. Then, sum all the weights multiplied by their bias value:

finalPos = (weight[0].pos * weight[0].bias) + ... + (weight[N].pos * weight[N].bias)

The vertex data that comes from the MD5 Mesh file has a start index and a count value. The start index is the index to the first weight used by the vertex. Then, all vertex' weight comes just right after this one. The count value indicates the number of weights used from the first weight. Here is the code to compute the final vertex positions (in object space) from their weights:

/* Setup vertices */
for (i = 0; i < mesh->num_verts; ++i)
{
vec3_t finalVertex = { 0.0f, 0.0f, 0.0f };
/* Calculate final vertex to draw with weights */
for (j = 0; j < mesh->vertices[i].count; ++j)
{
const struct md5_weight_t *weight = &mesh->weights[mesh->vertices[i].start + j];
const struct md5_joint_t *joint = &joints[weight->joint];
/* Calculate transformed vertex for this weight */
vec3_t wv;
Quat_rotatePoint (joint->orient, weight->pos, wv);
/* the sum of all weight->bias should be 1.0 */
finalVertex[0] += (joint->pos[0] + wv[0]) * weight->bias;
finalVertex[1] += (joint->pos[1] + wv[1]) * weight->bias;
finalVertex[2] += (joint->pos[2] + wv[2]) * weight->bias;
}
...
}

Texture coordinates

Each vertex has its own texture coordinates. The ST (or UV) texture coordinates for the upper-left corner of the texture are (0.0, 0.0). The ST texture coordinates for the lower-right corner are (1.0, 1.0).

The vertical direction is the inverse of the standard OpenGL direction for the T coordinate. This is like the DirectDraw Surface way. When loading a texture (other than a DDS file), you'll have to flip it vertically or take the oposite of the T texture coordinate for MD5 Mesh vertices (i.e., 1.0 - T).

Precomputing normals

You will probably need to compute normal vectors, for example for lighting. Here is how to compute them in order to get “weight normals”, like the weight positions (this method also works for tangents and bi-tangents):

First, compute all model's vertex positions in bind-pose (using the bind-pose skeleton).

Compute the vertex normals. You now have the normals in object space for the bind-pose skeleton.

For each weight of a vertex, transform the vertex normal by the inverse joint's orientation quaternion of the weight. You now have the normal in joint's local space.

Then when calculating the final vertex positions, you will be able to do the same for the normals, except you won't have to translate from the joint's position when converting from joint's local space to object space.

posted on 2008-11-06 11:54 狂爛球 閱讀(1238) 評論(0)  編輯 收藏 引用 所屬分類: 圖形編程

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            国产精品老女人精品视频| 久久精品综合| 欧美丝袜一区二区| 亚洲图片欧美一区| 亚洲欧美电影在线观看| 国产区欧美区日韩区| 欧美专区18| 久久久亚洲综合| 亚洲精品视频在线观看网站| 亚洲国产裸拍裸体视频在线观看乱了| 久久久高清一区二区三区| 亚洲风情亚aⅴ在线发布| 亚洲欧洲在线看| 国产精品亚洲综合久久| 美女免费视频一区| 欧美性生交xxxxx久久久| 久久国内精品自在自线400部| 久久久久久久91| 一区二区三区欧美在线| 欧美亚洲一区在线| 亚洲免费激情| 久久国产主播| 中文在线资源观看网站视频免费不卡 | 在线亚洲免费| 一色屋精品亚洲香蕉网站| 日韩一级欧洲| 在线播放中文一区| 亚洲无线观看| 日韩午夜在线视频| 久久爱另类一区二区小说| 99精品视频免费全部在线| 久久www成人_看片免费不卡| 一区二区高清视频| 久久综合久久久久88| 午夜精品久久久久久久男人的天堂| 久久综合色88| 久久精品欧美日韩精品| 国产精品大全| 日韩视频在线一区二区三区| 亚洲激情av| 久久精品国产99精品国产亚洲性色 | 免费成人激情视频| 久久久久国产精品人| 欧美视频在线视频| 亚洲精品乱码久久久久久蜜桃麻豆| 韩国久久久久| 欧美一区午夜视频在线观看| 亚洲一区二区三区免费视频| 欧美精品激情blacked18| 美女国内精品自产拍在线播放| 国产欧美日韩视频在线观看| 亚洲视频视频在线| 亚洲欧美日韩一区二区| 欧美日韩国产天堂| 91久久综合| 亚洲精品久久久蜜桃| 美女主播精品视频一二三四| 美女成人午夜| 亚洲黄色一区| 免费成人美女女| 欧美激情在线有限公司| 亚洲激情在线观看视频免费| 巨胸喷奶水www久久久免费动漫| 蜜桃av综合| 亚洲日本aⅴ片在线观看香蕉| 久久婷婷av| 亚洲国产精品成人| 一区二区日韩伦理片| 欧美日韩a区| 一区二区三区国产精品| 亚洲女性喷水在线观看一区| 国产精品免费观看在线| 欧美一级片久久久久久久| 久久久久久久久岛国免费| 狠狠色狠色综合曰曰| 久久久夜夜夜| 亚洲激情综合| 亚洲特级毛片| 国产日韩成人精品| 久久裸体艺术| 亚洲日本成人| 亚洲欧美第一页| 国产一区二区三区久久久| 久久久夜夜夜| 一本大道久久a久久综合婷婷| 午夜精品www| 红杏aⅴ成人免费视频| 免费毛片一区二区三区久久久| 欧美高清免费| 亚洲夜间福利| 在线观看免费视频综合| 欧美激情精品久久久久久蜜臀| 亚洲网站视频| 免播放器亚洲| 亚洲线精品一区二区三区八戒| 国产午夜精品视频| 欧美大片在线看| 亚洲欧美一区二区激情| 欧美国产精品va在线观看| 亚洲一卡久久| 亚洲国产精品第一区二区三区| 欧美日韩一区在线视频| 久久av红桃一区二区小说| 欧美国产日韩二区| 香蕉免费一区二区三区在线观看| 亚洲电影激情视频网站| 国产精品欧美日韩久久| 欧美黑人在线播放| 久久久久久国产精品mv| 亚洲天堂黄色| 亚洲人成网站影音先锋播放| 久久久精品动漫| 亚洲欧美精品在线观看| 最新日韩中文字幕| 一区二区三区亚洲| 国产精品中文字幕欧美| 欧美日韩国产bt| 美女日韩欧美| 久久爱www久久做| 亚洲一区二区三区高清不卡| 亚洲黄一区二区三区| 久久在线视频在线| 久久gogo国模裸体人体| 亚洲一二三四区| 日韩亚洲在线| 亚洲精品一区二区在线| 雨宫琴音一区二区在线| 国产色综合网| 国产精品欧美日韩久久| 欧美日韩美女在线| 欧美1区视频| 麻豆freexxxx性91精品| 久久久久久久久久久成人| 亚洲女ⅴideoshd黑人| 日韩一级片网址| 亚洲第一成人在线| 欧美激情视频免费观看| 美女脱光内衣内裤视频久久影院| 久久久久久九九九九| 欧美在线在线| 久久久久女教师免费一区| 久久手机精品视频| 久久久久国产一区二区| 久久久视频精品| 久久婷婷综合激情| 麻豆乱码国产一区二区三区| 久久综合伊人77777麻豆| 六月婷婷久久| 欧美激情网站在线观看| 亚洲国产1区| 亚洲精品久久久久中文字幕欢迎你| 亚洲国产综合91精品麻豆| 亚洲经典在线| 一区二区三区国产精华| 午夜精品成人在线| 麻豆精品在线视频| 欧美精品18+| 国产精品久久久久永久免费观看| 国产乱人伦精品一区二区| 国产午夜精品一区理论片飘花| 在线看国产一区| 一本色道久久99精品综合| 亚洲欧美一区二区三区久久| 久久久久久网址| 亚洲黄色在线| 亚洲女ⅴideoshd黑人| 久久男人av资源网站| 欧美另类亚洲| 国产色产综合产在线视频| 在线观看日韩av电影| 一区二区三区国产精品| 欧美一二三视频| 欧美国产日本高清在线| 亚洲一区二区三区四区在线观看 | 亚洲一区美女视频在线观看免费| 欧美主播一区二区三区美女 久久精品人| 久久亚洲综合| 国产精品久久亚洲7777| 亚洲国产成人精品女人久久久| 一二三区精品| 久久综合伊人77777尤物| av不卡在线| 美国成人直播| 国产精品一区二区在线观看网站| 亚洲福利一区| 欧美在线日韩| 亚洲人成毛片在线播放| 久久久激情视频| 国产欧美另类| 亚洲一级黄色av| 亚洲黄色免费| 久久9热精品视频| 国产毛片精品国产一区二区三区| 最近看过的日韩成人| 久久久久久**毛片大全| 中文精品99久久国产香蕉| 欧美极品aⅴ影院| 在线日本欧美| 麻豆精品网站| 欧美专区在线观看|