Jump to content
  • Advertisement
Sign in to follow this  
Alundra

Vertex's struct from .x skinned mesh

This topic is 2537 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

Hi,
I have done a converter from .x to custom format since a long time but now I would add animation on it.
I need to get weight and boneIndice for each vertex to send it in the custom file format.

I get vertices like that :


D3DVERTEXELEMENT9 Decl[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
{ 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
D3DDECL_END()
};

ID3DXMesh* pMesh = NULL;
pRawMesh->CloneMesh( D3DXMESH_32BIT | D3DXMESH_DYNAMIC, Decl, pDev9, &pMesh );

struct Vertex
{
float px, py, pz;
float nx, ny, nz;
float tu, tv;
};

void* VertexData = NULL;
pMesh->LockVertexBuffer( D3DLOCK_READONLY, &VertexData );
Vertex* pVertices = (Vertex*)VertexData;
pMesh->UnlockVertexBuffer();


Can you say to me how can I get weight / boneIndice ?
Thanks for your help

Share this post


Link to post
Share on other sites
Advertisement
The easiest way to get bones and indices is to use a 3d modeler, because in code, it will be a little difficult finding the joints based on all the vertices positions. Also, vertices are usually created from the weights instead of the other way around. you could come up with some sort of technique to create weights for each of the vertices, which binds the vertices to one or more bones, after you have a skeleton (bones) to bind them to.

My suggestion is to just use a format the supports skeletal animation. one i like is the md5 format. I wrote a little lesson on loading md5 models and animation here:

http://www.braynzarsoft.net/index.php?p=DX11Lessons

Share this post


Link to post
Share on other sites
Thanks for the link, your article is very good !
But, there is really no way to get it to complete my converter ?
I have done this converter to avoid to do an exporter but if it's not possible...

Share this post


Link to post
Share on other sites
well, i don't think .x files support skeletal animation (using bones or joints), so they also do not contain bones or weights. bones are much much easier to create in a 3d modeler, so you can actually see how they are placed and their orientation, and control which vertices are affected by them. in code, this is going to be a little more difficult to do, since you can't actually see which vertices will be effected by the bones. of course, you could set up some sort of technique to bind vertices to a bone depending on how close to the bone they are. This is what you would need to do:

First you'll have to create a bone structure (extremely hard to do in code since you might not know the exact positions of the joints of your mesh, such as knees, hip, neck arms)

After the bone structure, create weights depending on which vertices are effected by each bone. each vertex will have one or more weights, and each weight will be bound to one bone. weights are described in bone space, so you will have to subtract the bones position from the weight. you can check which bones a vertex is affected by, using a type of bounding sphere for the bone (just a radius, or distance). if the vertex is within the distance to the bone, a weight will be created for it. since a vertex might be bound to more than one bone, each of the weights must have a bias factor that adds up to one. the bias factor will say how much of an affect a bone has on the vertex's position. You could find the bias factor by how close the vertex is to each bone. if it's closer to one bone than another, then the weight bound to the first bone will have a larger bias factor (eg. 0.75)

After you create the weights, you will have to turn them back into vertices for each frame of animation. To me, it would just make sense to use a format that already has a skeletal system and weights included, it will be much easier and faster

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!