🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Create a vertex structure for DX rendering - Skeletal Animation

Started by
0 comments, last by isu diss 4 years, 5 months ago

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];

            	}
            }
    }        

This topic is closed to new replies.

Advertisement