Jump to content
  • Advertisement
Sign in to follow this  
VitaliBR

Study of Model 3D

This topic is 2986 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I decided to study a more current format (such as Doom 3 MD5) and try to make a code that carries the format (also texture and animation).
I searched a lot about but have not had much success. i found a library (ASSIMP) that helps loading the model...But I do not know what to do and how.

I found the documentation for md5 format. But still I do not know how to write code, what steps should I follow...Is there any tutorial teaching how to load a logic model? and book?

ASSIMP: http://assimp.sourceforge.net/main_features_formats.html
Specification of MD5: http://tfc.duke.free.fr/coding/md5-specs-en.html
http://www.modwiki.net/wiki/MD5MESH_%28file_format%29

Thanks

[Edited by - VitaliBR on July 14, 2010 3:17:37 PM]

Share this post


Link to post
Share on other sites
Advertisement
I'm having a progress in my MD5 loader.

In .md5mesh (we can find the following part):
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 ...
}


Quote:
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.
s and t (float) are the texture coordinates (also called UV coords)


Quote:
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).


If someone can give a hint to help me see the solution, I thank


Edit:

In http://www.modwiki.net/wiki/MD5MESH_%28file_format%29
Quote:
numverts <integer>
vert [vertIndex] ( [texU] [texV] ) [weightIndex] [weightElem]

* numverts - The number of vertices. Coorisponds to the number of elements to follow in the list.
* vertIndex - The index of this vertex.
* texU - The U component of the UV texture coordinates.
* texV - The V component of the UV texture coordinates.
* weightIndex - The index into the weight array where this vertex's first weight is located.
* weightElem - The number of elements in the weight array that apply to this vertex.

Share this post


Link to post
Share on other sites
Sorry, what is the question again? ;)

The basic steps loading and displaying a md5 model are:

1. load all vertexdata
2. load all weightingdata
3. create indices for the triangles (using the 'tri' properties)
4. skin the model (bind the vertices to the (a) skeleton)
5. render all triangles

Code examples you'll find in the links you already posted. :)

Share this post


Link to post
Share on other sites
I'm in doubt of the model with texturing.

* UV in .md5mesh:

vert [vertIndex] ( [texU] [texV] ) [weightIndex] [weightElem]




Being texU and texV the UV texture coordinates.

* ABOUT UV Coordinates:

UV coordinates are a texture’s x and y coordinates and always range from 0 to 1.
Let’s take for example a 800×600 image.
When we use a UV coordinate with u=0.5 and v=0.5 then the pixel at
x=400 and y=300 is targeted.

Texture with UV coordinates:


Box with vertex coordinates:


Therefore, the. Md5mesh of the box looks like this:

mesh {
numverts 12
vert 0 ( 0.0 0.0 )
vert 1 ( 0.33 0.0 )
vert 2 ( 0.66 0.0 )
vert 3 ( 1.0 0.0 )
vert 4 ( 0.0 0.5 )
vert 5 ( 0.33 0.5 )
vert 6 ( 0.66 0.5 )
vert 7 ( 1.0 0.5 )
vert 8 ( 0.0 1.0 )
vert 9 ( 0.33 1.0 )
vert 10 ( 0.66 1.0 )
vert 11 ( 1.0 1.0 )
}






Right?
What should I do? get the UV coordinates and connects them with the vertex of the models?

Thanks guy :)

[Edited by - VitaliBR on July 15, 2010 1:10:58 PM]

Share this post


Link to post
Share on other sites
Quote:

Right?
What should I do? get the UV coordinates and connects them with the vertices of the models?


Well, it looks something like that. But yeah, essentially you do connect the uv coordinates to each vertex, as it stands in the file.

Share this post


Link to post
Share on other sites
That's where I'm getting confused.

The file .md5mesh consist of:
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 ...
}



There are how to make a command that recognizes each mesh texture and apply according to the UV coordinates passed?
I will calculate the position of the vertex by using 'weight'? ( pos.x pos.y pos.z )

Sorry =/ may be a stupid question, but I'm confused

EDIT:
I did some testing with .Md5mesh opening the model in 3D Studio Max.
I'm using MD5 Import ( http://www.doom3world.org/phpbb2/viewtopic.php?t=3229 )
The 3DS Max loaded the textures correctly.

The .md5mesh file is storing textures as follows:
MD5Version 10
commandline ""

numJoints 33
numMeshes 6

joints {
"origin" -1 ( -0.000000 0.016430 -0.006044 ) ( 0.707107 0.000000 0.707107 ) //
"sheath" 0 ( 11.004813 -3.177138 31.702473 ) ( 0.307041 -0.578614 0.354181 ) // origin
.
.
.
}
mesh {
shader "C:\Users\Vitali\Desktop\bob\guard1_body.tga"

numverts 494
vert 0 ( 0.394531 0.513672 ) 0 1
.
.
.
}

mesh {
shader "C:\Users\Vitali\Desktop\bob\guard1_face.tga"

numverts 110
vert 0 ( 0.455078 0.386719 ) 0 2
.
.
.
}
.
.
.




[Edited by - VitaliBR on July 15, 2010 4:39:55 PM]

Share this post


Link to post
Share on other sites
Well, each Vertex has a bunch of properties attached to it (position, uv, ..). The uv-coords are not affected by the weights, just the position is.

If you need some sample code for the mesh-skinning: have a look at http://tfc.duke.free.fr/coding/md5-specs-en.html.

Share this post


Link to post
Share on other sites
Is this correct?

void MD5Model::render() {
glPushAttrib(GL_CURRENT_BIT);
glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);

for( size_t i=0; i < meshes.size(); i++ ) {
const Mesh *mesh = meshes;

glVertexPointer(3, GL_FLOAT, GLsizei(sizeof(Vertex)), mesh->verts[0].pos);
glNormalPointer(GL_FLOAT, GLsizei(sizeof(Vertex)), mesh->verts[0].n);
glTexCoordPointer(2, GL_FLOAT, GLsizei(sizeof(Vertex)), mesh->verts[0].tc);

glDrawElements(GL_TRIANGLES, GLsizei(mesh->tris.size()*3), GL_UNSIGNED_INT, &mesh->tris[0]);
}

glPopClientAttrib();
glPopAttrib();
}




Read the vertices:
    if ( str == "vert" ) {
// syntax: vert (vertex index) '(' [texU] [texV] ')' (weight index) (weight count)
Vertex vert;

int index = readInt(fin); // Vertex index
readVec(fin, vert.tc, 2); // texU , texV
vert.weightIndex = readInt(fin); // weight index
vert.weightCount = readInt(fin); // weight count

// make sure index is within bounds of vector of vertices
if ( size_t(index) >= mesh->verts.size() )
throw Exception("MD5Model::readMeshEl(): vertex index >= numverts");

mesh->verts[index] = vert;
}


Class of Vertex (used in the previous code):
  class Vertex {
public:
int weightIndex;
int weightCount;
float pos[3]; //Position
float tc[2]; //UV coordinates
float n[3]; //Normal
};


How do I do that every texture is applied to their particular mesh?
Example: The first mesh has the line 'shader': "C:\md5model\head.tga", so I apply the texture (head.tga) on the first Mesh?

[Edited by - VitaliBR on July 16, 2010 10:22:57 AM]

Share this post


Link to post
Share on other sites
I was thinking something like:

1step- Read the 'shader' (where is located the texture) and store in an array that will have the size indicated by 'numMeshes' (if numMeshes = 10, the array has size 10, and store 10 strings)

2step - Create a function that reads a string and load the textures (texture, bump map, specular map) and return an ID of the texture equal to your Mesh.
* Example: Shader = Texture / Texture_bump_map / Texture_specular_map to be used for Mesh

3step - In the Render function, determine which mesh will be drawn and apply the texture coordinates and textures loaded.
* Example: If you draw the 2nd mesh, we will apply the textures ID 2 (Shader [2] = Texture [2] / Texture_bump_map [2] / Texture_specular_map [2])

My thinking is right? I'm having some difficulty to implement my idea in the code

Share this post


Link to post
Share on other sites
Doom3 uses a bit more complicated shadingsystem. But as a lightweight version you could do something like that:

-> for each submesh in XYZ.md5mesh
-> read mesh's base skeleton
-> read vertexdata
-> read tris
-> read weights
-> read shader string and look for matching textures (the correct way would be to parse the actual shader)


after you've loaded all data you could move to rendering the model:


-> for each submesh
-> setup shader (simple case: bind the texture used by the submesh)
-> build skin using the skeleton
-> setup vertexbuffer (weighted positions, uv, ...)
-> draw all tris


skinning the model is done that way:


-> for each vertex in submesh
-> new vertex position = (0, 0, 0)
-> for i = 0 to number_of_weights
-> weight = weights[first_weight + i]
-> joint = joints[weight->joint]
-> transform weight position by joint's quaternion
-> new vertex position += (transformed weight position
-> + joint's position) * weight->bias

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!