private void StoreBindPose(FBXScene pScene, FBXNode pMesh) { List <FBXNode> lClusteredFbxNodes = new List <FBXNode>(); int i, j; FBXNodeAttribute att = pMesh.GetNodeAttribute(); if (pMesh != null && att != null) { int lSkinCount = 0; int lClusterCount = 0; switch (pMesh.GetNodeAttribute().GetAttributeType()) { default: break; case NodeAttribType.eMesh: case NodeAttribType.eNurbs: case NodeAttribType.ePatch: FBXGeometry geo = (FBXGeometry)att.ToGeometry(); lSkinCount = geo.GetDeformerCount(EDeformerType.eSkin); for (i = 0; i < lSkinCount; ++i) { FBXSkin lSkin = geo.GetSkinDeformer(i); lClusterCount += lSkin.GetClusterCount(); } break; } if (lClusterCount != 0) { for (i = 0; i < lSkinCount; ++i) { FBXGeometry geo = (FBXGeometry)att.ToGeometry(); FBXSkin lSkin = geo.GetSkinDeformer(i); lClusterCount = lSkin.GetClusterCount(); for (j = 0; j < lClusterCount; ++j) { FBXNode lClusterNode = lSkin.GetClusterLink(j); AddNodeRecursively(lClusteredFbxNodes, lClusterNode); } } lClusteredFbxNodes.Add(pMesh); } } if (lClusteredFbxNodes.Count != 0) { FBXPose lPose = FBXPose.Create(pScene, "pose"); lPose.SetIsBindPose(true); for (i = 0; i < lClusteredFbxNodes.Count; i++) { FBXNode lKFbxNode = lClusteredFbxNodes[i]; FBXAMatrix lBindMatrix = lKFbxNode.EvaluateGlobalTransform(); lPose.Add(lKFbxNode, lBindMatrix); } pScene.AddPose(lPose); } }
// skinning private void CreateMeshSkinning(Dictionary <string, List <VertexWeight> > vg, FBXNode pFbxMesh, FBXNode pSkeletonRoot, FBXScene pScene) { FBXSkin lFbxSkin = FBXSkin.Create(pScene, ""); FBXAMatrix lMeshMatTransform = pFbxMesh.EvaluateGlobalTransform(); foreach (string key in vg.Keys) { List <VertexWeight> bvg = vg[key]; FBXCluster lCluster = FBXCluster.Create(pScene, key); FBXNode lFbxBone = pSkeletonRoot.FindChild(key); if (lFbxBone != null) { lCluster.SetLink(lFbxBone); foreach (VertexWeight v in bvg) { lCluster.AddControlPointIndex(v.vertexIndex, v.weight); } lFbxSkin.AddCluster(lCluster); lCluster.SetTransformMatrix(lMeshMatTransform); FBXAMatrix lBoneMatTransform = lFbxBone.EvaluateGlobalTransform(); lCluster.SetTransformLinkMatrix(lBoneMatTransform); } } FBXGeometry lFbxMeshAtt = (FBXGeometry)pFbxMesh.GetNodeAttribute().ToGeometry(); if (lFbxMeshAtt != null) { lFbxMeshAtt.AddDeformer(lFbxSkin); } }
/// <summary> /// The display content method /// </summary> /// <param name="sceneInstance">The scene that we are running on.</param> private static void DisplayContent(FBXScene sceneInstance) { FBXNode rootNode = sceneInstance.GetRootNode(); if (rootNode != null) { // Iterate over the children in this node. for (int index = 0; index < rootNode.GetChildCount(); index++) { var attributeType = rootNode.GetChild(index).GetNodeAttribute().GetAttributeType(); FBXNode nodeInstance = rootNode.GetChild(index); FBXNodeAttribute attributeInstance = nodeInstance.GetNodeAttribute(); // Cast out the node object based on the type of the attribute. switch (attributeType) { case EAttributeType.eMesh: DisplayMesh((FBXMesh)attributeInstance); break; case EAttributeType.eCamera: DisplayCamera((FBXCamera)attributeInstance); break; case EAttributeType.eLight: DisplayLight((FBXLight)attributeInstance); break; case EAttributeType.eSkeleton: DisplaySkeleton((FBXSkeleton)attributeInstance); break; } } } }