# 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.

## 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 ?

##### Share on other sites
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 on other sites
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 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

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633769
• Total Posts
3013759
×