// compare the hierarchy and transform of two nodes private void CheckSceneHelper(FbxNode node1, FbxNode node2) { if (node1 == null && node2 == null) { return; } Assert.IsNotNull(node1); Assert.IsNotNull(node2); Assert.AreEqual(node1.GetChildCount(), node2.GetChildCount()); // compare the transforms Assert.AreEqual(node1.LclTranslation.Get(), node2.LclTranslation.Get()); Assert.AreEqual(node1.LclRotation.Get(), node2.LclRotation.Get()); Assert.AreEqual(node1.LclScaling.Get(), node2.LclScaling.Get()); Assert.AreEqual(node1.GetPreRotation(FbxNode.EPivotSet.eSourcePivot), node2.GetPreRotation(FbxNode.EPivotSet.eSourcePivot)); Assert.AreEqual(node1.GetPostRotation(FbxNode.EPivotSet.eSourcePivot), node2.GetPostRotation(FbxNode.EPivotSet.eSourcePivot)); Assert.AreEqual(node1.GetRotationPivot(FbxNode.EPivotSet.eSourcePivot), node2.GetRotationPivot(FbxNode.EPivotSet.eSourcePivot)); Assert.AreEqual(node1.GetScalingPivot(FbxNode.EPivotSet.eSourcePivot), node2.GetScalingPivot(FbxNode.EPivotSet.eSourcePivot)); Assert.AreEqual(node1.GetRotationOffset(FbxNode.EPivotSet.eSourcePivot), node2.GetRotationOffset(FbxNode.EPivotSet.eSourcePivot)); Assert.AreEqual(node1.GetScalingOffset(FbxNode.EPivotSet.eSourcePivot), node2.GetScalingOffset(FbxNode.EPivotSet.eSourcePivot)); Assert.AreEqual(node1.GetName(), node2.GetName()); for (int i = 0; i < node1.GetChildCount(); i++) { // recurse through the hierarchy CheckSceneHelper(node1.GetChild(i), node2.GetChild(i)); } }
/// <summary> /// Process transformation data and setup Transform component /// </summary> private void ProcessTransform(FbxNode fbxNode, GameObject unityGo) { // Construct rotation matrices FbxVector4 fbxRotation = new FbxVector4(fbxNode.LclRotation.Get()); FbxAMatrix fbxRotationM = new FbxAMatrix(); fbxRotationM.SetR(fbxRotation); FbxVector4 fbxPreRotation = new FbxVector4(fbxNode.GetPreRotation(FbxNode.EPivotSet.eSourcePivot)); FbxAMatrix fbxPreRotationM = new FbxAMatrix(); fbxPreRotationM.SetR(fbxPreRotation); FbxVector4 fbxPostRotation = new FbxVector4(fbxNode.GetPostRotation(FbxNode.EPivotSet.eSourcePivot)); FbxAMatrix fbxPostRotationM = new FbxAMatrix(); fbxPostRotationM.SetR(fbxPostRotation); // Construct translation matrix FbxAMatrix fbxTranslationM = new FbxAMatrix(); FbxVector4 fbxTranslation = new FbxVector4(fbxNode.LclTranslation.Get()); fbxTranslationM.SetT(fbxTranslation); // Construct scaling matrix FbxAMatrix fbxScalingM = new FbxAMatrix(); FbxVector4 fbxScaling = new FbxVector4(fbxNode.LclScaling.Get()); fbxScalingM.SetS(fbxScaling); // Construct offset and pivot matrices FbxAMatrix fbxRotationOffsetM = new FbxAMatrix(); FbxVector4 fbxRotationOffset = fbxNode.GetRotationOffset(FbxNode.EPivotSet.eSourcePivot); fbxRotationOffsetM.SetT(fbxRotationOffset); FbxAMatrix fbxRotationPivotM = new FbxAMatrix(); FbxVector4 fbxRotationPivot = fbxNode.GetRotationPivot(FbxNode.EPivotSet.eSourcePivot); fbxRotationPivotM.SetT(fbxRotationPivot); FbxAMatrix fbxScalingOffsetM = new FbxAMatrix(); FbxVector4 fbxScalingOffset = fbxNode.GetScalingOffset(FbxNode.EPivotSet.eSourcePivot); fbxScalingOffsetM.SetT(fbxScalingOffset); FbxAMatrix fbxScalingPivotM = new FbxAMatrix(); FbxVector4 fbxScalingPivot = fbxNode.GetScalingPivot(FbxNode.EPivotSet.eSourcePivot); fbxScalingPivotM.SetT(fbxScalingPivot); FbxAMatrix fbxTransform = fbxTranslationM * fbxRotationOffsetM * fbxRotationPivotM * fbxPreRotationM * fbxRotationM * fbxPostRotationM * fbxRotationPivotM.Inverse() * fbxScalingOffsetM * fbxScalingPivotM * fbxScalingM * fbxScalingPivotM.Inverse(); FbxVector4 lclTrs = fbxTransform.GetT(); FbxQuaternion lclRot = fbxTransform.GetQ(); FbxVector4 lclScl = fbxTransform.GetS(); Debug.Log(string.Format("processing {3} Lcl : T({0}) R({1}) S({2})", lclTrs.ToString(), lclRot.ToString(), lclScl.ToString(), fbxNode.GetName())); unityGo.transform.localPosition = new Vector3((float)lclTrs[0], (float)lclTrs[1], (float)lclTrs[2]); unityGo.transform.localRotation = new Quaternion((float)lclRot[0], (float)lclRot[1], (float)lclRot[2], (float)lclRot[3]); unityGo.transform.localScale = new Vector3((float)lclScl[0], (float)lclScl[1], (float)lclScl[2]); }