to implement basic vertex skinning. I use Ogre's mesh and skeleton (xml)
files and have assured that they are properly parsed, yet all I get when
trying to animate the model is polygon soup.
I use this working code for debug rendering the animated skeleton:
void Bone::render ( const D3DXMATRIX& top ){ D3DXMATRIX temp = animatedMatrix *bindMatrix *top; D3DXVECTOR3 a; a.x = top._41; a.y = top._42; a.z = top._43; D3DXVECTOR3 b; b.x = temp._41; b.y = temp._42; b.z = temp._43; Debug::instance->addLine ( a, b ); std::vector<Bone*>::iterator it; for ( it = children.begin (); it != children.end (); ++it ) (*it)->render ( temp );}
... and this is the part that I assume is wrong(?). This is where I
compute the skinMatrix that will be sent to the shader. I've tried
countless of variations but without luck and now my brain is beginning
to hurt :(
void Bone::update ( const D3DXMATRIX& top ){ skinMatrix = inverseBindMatrix *animatedMatrix *bindMatrix *top; D3DXMATRIX newTop = animatedMatrix *bindMatrix *top; std::vector<Bone*>::iterator it; for ( it = children.begin (); it != children.end (); ++it ) (*it)->update ( newTop );}
My vertex shader
PS_INPUT vertexShader ( VS_INPUT input ){ PS_INPUT output = (PS_INPUT)0; // skinning float3 pos = float4 ( input.Pos, 1 ); float3 nor = float4 ( input.Nor, 0 ); float3 P = 0.0f; float3 N = 0.0f; [unroll] for ( int i = 0; i < 4; ++i ) { // InverseBind [ input.BoneI [0] ] P += input.BoneW *mul ( pos, SkinMatrices[input.BoneI] ); N += input.BoneW *mul ( nor, SkinMatrices[input.BoneI] ); } N = normalize ( N ); // standard stuff output.Pos = mul ( float4 ( P, 1 ), Combined ); output.PosW= mul ( float4 ( P, 1 ), World ).xyz; output.Nor = mul ( float4 ( N, 0 ), World ).xyz; output.Tex = input.Tex; return output;}
[Edited by - MZP on November 11, 2010 4:37:30 PM]