3D Model Skeletons

Started by
3 comments, last by drsixstring 22 years, 1 month ago
I just downloaded Milkshape 3D and I''m playing around with making humanoid models. Soon I want to learn how to set up a skelton so I can easily animate the model when I put it into my under-construction 3-D engine. I''m using D3D 8.0 w/ VC++. Is implemententing skeltons pretty easy, or will I have to write the entire thing myself?
Advertisement
Skeletonanimation is hard, especially the math...

I took the time to encapsule the skinned mesh example in the dsk8.1, rewriting it line by line. Took about two days writing the 1800 lines of code. The example is hard becouse it supports alot of different "meshtypes"...

Philip Taylors (MS) next article on msdn will be in the area of this. Check it out... Should be out in a couple of weeks.

If there''s anything I can help you with, (beginner to though) dont hesitate to ask me!

/Johan
Is the implementation of the actual skelton the hard part, or is the majority of the work done with loading and rendering the mesh?
All of it is hard, I don''t have a 100% grip on this yet so, but I''ll get back to you later on...
Agree with all previous comments.

My suggestions:
1) Learn how to use D3D vertex buffers and index buffers with normal (non-skeletal, single matrix per mesh) objects first.
2) Once you understand #1 really well, take the time to learn how skeletal meshes work, completely independent of D3D8.1. I suggest looking at brett porter's stuff: rsn.gamedev.net. Unfortunately, his sample code is designed for OpenGL -- fortunately, his sample code uses milkshape3d file formats (additional ms3d file format stuff can be found on milkshape's home page.) I suggest using the ms3d ascii format -- its a bit unweildly but you can read the files using notepad and figure out what's going on.
2a) Also learn how ms3d file format works within the conceptual framework of skinned meshes in general.
3) Once you understand skinned meshes conceptually and understand how the ms3d file format works, you can try to implement them in directx -- this is where things get tricky. As johanK points out, there are many different mesh types and differing ways of rendering skinned meshes in d3d. The sample (skinnedmesh) is very confusing because of this. After much expirementation, i discovered that the easiest method of doing skinned meshes in d3d is:
a) Using Matrix Palette. this feature is documented in directx help.
b) Software vertex computation (cause most graphics cards, including geForce3 don't support matrix palettes in hardware)
c) the following state settings before rendering (if you don't understand this code yet, do step #1 again. =) ):

if (FAILED(m_pD3DDevice->SetRenderState(D3DRS_SOFTWAREVERTEXPROCESSING, TRUE)))
{success=false;} //this maximizes compatability at expense of speed
if (FAILED(m_pD3DDevice->SetRenderState(D3DRS_VERTEXBLEND, D3DVBF_0WEIGHTS))) //this says each vertex is only influenced by its own bone matrix (two matrices cannot affect the same bone which is fine cause ms3d doesn't allow it anyway)
{success=false;}
if (FAILED(m_pD3DDevice->SetRenderState(D3DRS_INDEXEDVERTEXBLENDENABLE, TRUE)))
{success=false;} //says we are using a matrix palette.
if (FAILED (m_pD3DDevice->SetVertexShader( D3DFVF_SKINVERTEX ) ) ) //use the fvf we define
{success=false;}

And this as your FVF:
struct SSkinVertex
{
D3DXVECTOR3 v; //vertex
DWORD matrixIndices; //low byte is the only one used. says which bone in the matrix palette to use
D3DXVECTOR3 n; //normal
float tu, tv; //tex coordinates
} PACK_STRUCT;

With this as the FVF declaration:
#define D3DFVF_SKINVERTEX (D3DFVF_XYZB1 | D3DFVF_LASTBETA_UBYTE4 | D3DFVF_NORMAL | D3DFVF_TEX1)

This will allow you to have a matrix palette of 255 bones/matrices. If you need more matrices (doubt that you will) you can swap the palette halfway through.

4) What you might want to do is write something that loads the milkshape file in native form, then converts the data into D3D vertex and index buffers (this is quite easy if you understand what's going on -- it is a little tricky cause you have to deal with the different vertex and index formats). Once loaded render everything with identity matrices to make sure your IB and VB are right -- all of the meshes for each bone will render on top of each other (like a sick pile of limbs). However, each distinct bone should look correct (ie the arm will look like an arm, but it will look like the arms are all stacked on top of each other.) Then, you can start to try to get the matrices right.

Good luck, it's no easy task!

DmGoober

[edited by - DmGoober on March 19, 2002 2:02:13 PM]

[edited by - DmGoober on March 19, 2002 2:03:10 PM]
Alexander "DmGoober" Jhinalexjh@online.microsoft.com[Warning! This email account is not attended. All comments are the opinions of an individual employee and are not representative of Microsoft Corporation.]

This topic is closed to new replies.

Advertisement