public int Add(FbxNode pNode, FbxMatrix pMatrix, bool pLocalMatrix, bool pMultipleBindPose) { int ret = NativeMethods.FbxPose_Add__SWIG_0(swigCPtr, FbxNode.getCPtr(pNode), FbxMatrix.getCPtr(pMatrix), pLocalMatrix, pMultipleBindPose); if (NativeMethods.SWIGPendingException.Pending) { throw NativeMethods.SWIGPendingException.Retrieve(); } return(ret); }
public int Add(FbxNode pNode, FbxMatrix pMatrix) { int ret = NativeMethods.FbxPose_Add__SWIG_2(swigCPtr, FbxNode.getCPtr(pNode), FbxMatrix.getCPtr(pMatrix)); if (NativeMethods.SWIGPendingException.Pending) { throw NativeMethods.SWIGPendingException.Retrieve(); } return(ret); }
/// <summary> /// Export bones of skinned mesh /// </summary> protected bool ExportSkeleton(MeshInfo meshInfo, FbxScene fbxScene, FbxNode fbxParentNode, ref Dictionary <Transform, FbxNode> boneNodes) { SkinnedMeshRenderer unitySkinnedMeshRenderer = meshInfo.renderer as SkinnedMeshRenderer; if (unitySkinnedMeshRenderer.bones.Length <= 0) { return(false); } Dictionary <Transform, Matrix4x4> boneBindPose = new Dictionary <Transform, Matrix4x4>(); for (int boneIndex = 0; boneIndex < unitySkinnedMeshRenderer.bones.Length; boneIndex++) { Transform unityBoneTransform = unitySkinnedMeshRenderer.bones [boneIndex]; FbxNode fbxBoneNode = FbxNode.Create(fbxScene, unityBoneTransform.name); // Create the node's attributes FbxSkeleton fbxSkeleton = FbxSkeleton.Create(fbxScene, unityBoneTransform.name + "_Skel"); var fbxSkeletonType = FbxSkeleton.EType.eLimbNode; if (unityBoneTransform == unityBoneTransform.root || fbxParentNode.GetName().Equals(unityBoneTransform.parent.name)) { fbxSkeletonType = FbxSkeleton.EType.eRoot; } fbxSkeleton.SetSkeletonType(fbxSkeletonType); fbxSkeleton.Size.Set(1.0f); // Set the node's attribute fbxBoneNode.SetNodeAttribute(fbxSkeleton); boneBindPose.Add(unityBoneTransform, meshInfo.BindPoses [boneIndex]); // save relatation between unity transform and fbx bone node for skinning boneNodes [unityBoneTransform] = fbxBoneNode; } // set the hierarchy for the FbxNodes foreach (KeyValuePair <Transform, FbxNode> t in boneNodes) { Matrix4x4 pose; // if this is a root node then don't need to do anything if (t.Key == t.Key.root || !boneNodes.ContainsKey(t.Key.parent)) { fbxParentNode.AddChild(t.Value); pose = boneBindPose[t.Key].inverse; // assuming parent is identity matrix } else { boneNodes [t.Key.parent].AddChild(t.Value); // inverse of my bind pose times parent bind pose pose = boneBindPose[t.Key.parent] * boneBindPose[t.Key].inverse; } // use FbxMatrix to get translation and rotation relative to parent FbxMatrix matrix = new FbxMatrix(); matrix.SetColumn(0, new FbxVector4(pose.GetRow(0).x, pose.GetRow(0).y, pose.GetRow(0).z, pose.GetRow(0).w)); matrix.SetColumn(1, new FbxVector4(pose.GetRow(1).x, pose.GetRow(1).y, pose.GetRow(1).z, pose.GetRow(1).w)); matrix.SetColumn(2, new FbxVector4(pose.GetRow(2).x, pose.GetRow(2).y, pose.GetRow(2).z, pose.GetRow(2).w)); matrix.SetColumn(3, new FbxVector4(pose.GetRow(3).x, pose.GetRow(3).y, pose.GetRow(3).z, pose.GetRow(3).w)); FbxVector4 translation, rotation, shear, scale; double sign; matrix.GetElements(out translation, out rotation, out shear, out scale, out sign); // Negating the x value of the translation, and the y and z values of the prerotation // to convert from Unity to Maya coordinates (left to righthanded) t.Value.LclTranslation.Set(new FbxDouble3(-translation.X, translation.Y, translation.Z)); t.Value.LclRotation.Set(new FbxDouble3(0, 0, 0)); t.Value.LclScaling.Set(new FbxDouble3(scale.X, scale.Y, scale.Z)); t.Value.SetRotationActive(true); t.Value.SetPivotState(FbxNode.EPivotSet.eSourcePivot, FbxNode.EPivotState.ePivotReference); t.Value.SetPreRotation(FbxNode.EPivotSet.eSourcePivot, new FbxVector4(rotation.X, -rotation.Y, -rotation.Z)); } return(true); }