I know how to read BoneIndices and BoneWeights from a fbx file. What I can't understand is filling vertex structure with BoneIndices and Bone weights. Can anyone help me?
for (unsigned int deformerIndex = 0; deformerIndex < (UINT)mesh->GetDeformerCount(); ++deformerIndex)
{
FbxSkin* skin = reinterpret_cast<FbxSkin*>(mesh->GetDeformer(deformerIndex, FbxDeformer::eSkin));
if (!skin)
continue;
for (unsigned int clusterIndex = 0; clusterIndex < (UINT)skin->GetClusterCount(); ++clusterIndex)
{
FbxCluster* cluster = skin->GetCluster(clusterIndex);
std::string jointname = cluster->GetLink()->GetName();
unsigned int jointIndex = FindJointIndex(jointname);
FbxAMatrix transformMatrix;
FbxAMatrix transformLinkMatrix;
FbxAMatrix globalBindposeInverseMatrix;
cluster->GetTransformMatrix(transformMatrix);
cluster->GetTransformLinkMatrix(transformLinkMatrix);
globalBindposeInverseMatrix = transformLinkMatrix.Inverse() * transformMatrix * geometryTransform;
skeleton.mJoints[jointIndex].mGlobalBindposeInverse = globalBindposeInverseMatrix;
skeleton.mJoints[jointIndex].mNode = cluster->GetLink();
int *boneVertexIndices = cluster->GetControlPointIndices();
double *boneVertexWeights = cluster->GetControlPointWeights();
int numBoneVertexIndices = cluster->GetControlPointIndicesCount();
//vertex strcuture filling code
for (int boneVertexIndex = 0; boneVertexIndex < numBoneVertexIndices; boneVertexIndex++)
{
int vertexid = controlpoints[boneVertexIndices[boneVertexIndex]];
meshvertices[vertexid].boneids.x = jointIndex;
meshvertices[vertexid].boneids.y = jointIndex;
meshvertices[vertexid].boneids.z = jointIndex;
meshvertices[vertexid].boneids.w = jointIndex;
meshvertices[vertexid].weights.x = (float)boneVertexWeights[boneVertexIndex];
meshvertices[vertexid].weights.y = (float)boneVertexWeights[boneVertexIndex];
meshvertices[vertexid].weights.z = (float)boneVertexWeights[boneVertexIndex];
meshvertices[vertexid].weights.w = (float)boneVertexWeights[boneVertexIndex];
}
}
}