Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualsimpler

Posted 19 October 2012 - 01:28 PM

I recently got my skinned model importer working. To load the models I used the Assimp library which have been working great. It can load many different formats both for static models and animated ones and the only job you have to do for yourself is to extract the data you need from the aiScene object. To extract the skeleton and animation data I used this. I first tried extracting the skeletion hierarchy myself but that was above my head so I was really happy finding that animation extractor. Even if you won't use Assimp you can take a look at the source code for the animation extractor to see how it works.

To do the animation you send the array of bone transforms to the shader. You should have a vertex structure containing indexes to which bone the vertex gets affected by and also weights deciding how much it's affected.

struct SkinnedVertexIn
{
	 float3 PosL	   : POSITION;
	 float3 NormalL	: NORMAL;
	 float2 Tex		: TEXCOORD;
	 float3 Weights	: WEIGHTS;	
	 uint4 BoneIndices : BONEINDICES;	 // Indices into the bone transform array
};

And then you do something like this to calculate the position for a vertex after applying the bone transforms:

cbuffer cbSkinned
{
	 float4x4 gBoneTransforms[96];
};

...

for(int i = 0; i < 4; ++i)
{
   posL	 += weights[i]*mul(float4(vin.PosL, 1.0f), gBoneTransforms[vin.BoneIndices[i]]).xyz;
   normalL  += weights[i]*mul(vin.NormalL, (float3x3)gBoneTransforms[vin.BoneIndices[i]]);
}

Good luck!

#1simpler

Posted 19 October 2012 - 01:25 PM

I recently got my skinned model importer working. To load the models I used the Assimp library which have been working great. It can load many different formats both for static models and animated ones and the only job you have to do for yourself is to extract the data you need from the aiScene object. To extract the skeleton and animation data I used this.

To do the animation you send the array of bone transforms to the shader. You should have a vertex structure containing indexes to which bone the vertex gets affected by and also weights deciding how much it's affected.

struct SkinnedVertexIn
{
	 float3 PosL	   : POSITION;
	 float3 NormalL	: NORMAL;
	 float2 Tex		: TEXCOORD;
	 float3 Weights	: WEIGHTS;	
	 uint4 BoneIndices : BONEINDICES;	 // Indices into the bone transform array
};

And then you do something like this to calculate the position for a vertex after applying the bone transforms:

cbuffer cbSkinned
{
	 float4x4 gBoneTransforms[96];
};

...

for(int i = 0; i < 4; ++i)
{
   posL	 += weights[i]*mul(float4(vin.PosL, 1.0f), gBoneTransforms[vin.BoneIndices[i]]).xyz;
   normalL  += weights[i]*mul(vin.NormalL, (float3x3)gBoneTransforms[vin.BoneIndices[i]]);
}

Good luck!

PARTNERS