// 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));
            }
        }
예제 #2
0
        void Run()
        {
            FbxManager    manager = FbxManager.Create();
            FbxIOSettings setting = FbxIOSettings.Create(manager, "IOSRoot");

            manager.SetIOSettings(setting);

            FbxImporter impoter = FbxImporter.Create(manager, "");

            bool status = impoter.Initialize(@"D:\develop\FbxWrapper\1.fbx", -1, setting);

            Log.Info(status);

            if (!status)
            {
                return;
            }

            FbxScene scene = FbxScene.Create(manager, "scene1");

            status = impoter.Import(scene);
            Log.Info(status);


            int numTrack = scene.GetSrcObjectCount(FbxAnimStack.ClassId);

            Log.Info("num stack " + numTrack);

            FbxObject obj = scene.GetSrcObject(FbxAnimStack.ClassId, 0);

            FbxAnimStack stack = FbxAnimStack.Cast(obj);

            if (stack == null)
            {
                Log.Error("can not get anim stack!");
                return;
            }

            FbxCriteria cri      = FbxCriteria.ObjectTypeStrict(FbxAnimLayer.ClassId);
            int         numLayer = stack.GetMemberCount(cri);

            Log.Info("anim layer count : " + numLayer);

            FbxAnimLayer layer = null;

            if (numLayer > 0)
            {
                FbxObject layerobj = stack.GetMember(cri, 0);
                layer = FbxAnimLayer.Cast(layerobj);
                if (layer == null)
                {
                    Log.Error("anim layer is null!");
                    return;
                }

                Log.Info("anim layer name " + layer.GetName());
            }


            Log.Info("node count " + scene.GetNodeCount());
            for (int i = 0; i < scene.GetNodeCount(); i++)
            {
                FbxNode node = scene.GetNode(i);
                Log.Info("node " + i + " " + node.GetName());

                if (node.LclTranslation.IsAnimated(layer))
                {
                    FbxAnimCurveNode curveNode = node.LclTranslation.GetCurveNode(layer);
                    if (curveNode == null)
                    {
                        Log.Error("curve node is null");
                    }
                    else
                    {
                        for (int c = 0; c < curveNode.GetCurveCount(0); c++)
                        {
                            FbxAnimCurve curve = curveNode.GetCurve(0, (uint)c);
                            if (curve != null)
                            {
                                Log.Info("curve " + curve.GetName());
                                Log.Info("key count " + curve.KeyGetCount());
                                FbxAnimCurveKey key = curve.KeyGet(0);
                                FbxTime         t   = key.GetTime();
                                Log.Info("key " + t.GetTimeString() + " value " + key.GetValue());
                            }
                        }
                    }
                }



                if (node.GetNodeAttribute() != null)
                {
                    Log.Info("got attribu");
                    FbxNodeAttribute att = node.GetNodeAttribute();
                    PrintAttribute(att);
                }
                else
                {
                    Log.Info("att count " + node.GetNodeAttributeCount());
                    for (int j = 0; j < node.GetNodeAttributeCount(); j++)
                    {
                        FbxNodeAttribute att = node.GetNodeAttributeByIndex(j);
                        PrintAttribute(att);
                    }
                }

                FbxVector4    rot = node.GetPostRotation(FbxNode.EPivotSet.eSourcePivot);
                FbxQuaternion q;
            }
        }
예제 #3
0
            /// <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]);
            }
예제 #4
0
        void Run()
        {
            FbxManager    manager = FbxManager.Create();
            FbxIOSettings setting = FbxIOSettings.Create(manager, "IOSRoot");

            //fbxiosettingspath.h
            //PostProcessSteps.CalculateTangentSpace = #define EXP_TANGENTSPACE				EXP_GEOMETRY "|" IOSN_TANGENTS_BINORMALS
            //PostProcessSteps.JoinIdenticalVertices = #define IOSN_DXF_WELD_VERTICES           "WeldVertices"
            //PostProcessSteps.Triangulate = #define IOSN_TRIANGULATE                "Triangulate"
            //PostProcessSteps.RemoveComponent =
            //PostProcessSteps.GenerateSmoothNormals =
            //setting.AddProperty()
            setting.SetBoolProp("Import|AdvOptGrp|Dxf|WeldVertices", true);
            setting.SetBoolProp("Triangulate", true);

            manager.SetIOSettings(setting);

            FbxImporter impoter = FbxImporter.Create(manager, "");

            bool status = impoter.Initialize(@"1.fbx", -1, setting);

            Log.Info(status);

            if (!status)
            {
                return;
            }

            FbxScene scene = FbxScene.Create(manager, "scene1");

            status = impoter.Import(scene);
            Log.Info(status);


            int numTrack = scene.GetSrcObjectCount(FbxCriteria.ObjectType(FbxAnimStack.ClassId));

            Log.Info("num stack " + numTrack);

            FbxObject obj = scene.GetSrcObject(FbxCriteria.ObjectType(FbxAnimStack.ClassId), 0);

            FbxAnimStack stack = FbxAnimStack.Cast(obj);

            if (stack == null)
            {
                Log.Error("can not get anim stack!");
                return;
            }

            FbxCriteria cri      = FbxCriteria.ObjectTypeStrict(FbxAnimLayer.ClassId);
            int         numLayer = stack.GetMemberCount(cri);

            Log.Info("anim layer count : " + numLayer);

            FbxAnimLayer layer = null;

            if (numLayer > 0)
            {
                FbxObject layerobj = stack.GetMember(cri, 0);
                layer = FbxAnimLayer.Cast(layerobj);
                if (layer == null)
                {
                    Log.Error("anim layer is null!");
                    return;
                }

                Log.Info("anim layer name " + layer.GetName());
            }


            Log.Info("node count " + scene.GetNodeCount());
            for (int i = 0; i < scene.GetNodeCount(); i++)
            {
                FbxNode node = scene.GetNode(i);
                Log.Info("node " + i + " " + node.GetName() + " ChildCount:" + node.GetChildCount());

                //----------------
                //node.LclTranslation.IsAnimated
                //----------------
                //ToDo :

                if (node.LclTranslation.IsAnimated(layer))
                {
                    FbxAnimCurveNode curveNode = node.LclTranslation.GetCurveNode(layer);
                    if (curveNode == null)
                    {
                        Log.Error("curve node is null");
                    }
                    else
                    {
                        for (int c = 0; c < curveNode.GetCurveCount(0); c++)
                        {
                            FbxAnimCurve curve = curveNode.GetCurve(0, (uint)c);
                            if (curve != null)
                            {
                                Log.Info("curve " + curve.GetName());
                                Log.Info("key count " + curve.KeyGetCount());
                                FbxAnimCurveKey key = curve.KeyGet(0);
                                FbxTime         t   = key.GetTime();
                                Log.Info("key " + t.GetTimeString() + " value " + key.GetValue());
                            }
                        }
                    }
                }



                if (node.GetNodeAttribute() != null)
                {
                    Log.Info("got attribu");
                    FbxNodeAttribute att = node.GetNodeAttribute();
                    PrintAttribute(manager, att);
                }
                else
                {
                    Log.Info("att count " + node.GetNodeAttributeCount());
                    for (int j = 0; j < node.GetNodeAttributeCount(); j++)
                    {
                        FbxNodeAttribute att = node.GetNodeAttributeByIndex(j);
                        PrintAttribute(manager, att);
                    }
                }

                FbxVector4    rot = node.GetPostRotation(FbxNode.EPivotSet.eSourcePivot);
                FbxQuaternion q;
            }
        }