示例#1
0
            /// <summary>
            /// Unconditionally export components on this game object
            /// </summary>
            protected void ExportComponents(GameObject unityGo, FbxScene fbxScene, FbxNode fbxNodeParent)
            {
                // create an FbxNode and add it as a child of parent
                FbxNode fbxNode = FbxNode.Create(fbxScene, unityGo.name);

                NumNodes++;

                ExportTransform(unityGo.transform, fbxNode);
                ExportMesh(GetMeshInfo(unityGo), fbxNode, fbxScene);

                if (Verbose)
                {
                    Debug.Log(string.Format("exporting {0}", fbxNode.GetName()));
                }

                fbxNodeParent.AddChild(fbxNode);

                // now  unityGo  through our children and recurse
                foreach (Transform childT in unityGo.transform)
                {
                    ExportComponents(childT.gameObject, fbxScene, fbxNode);
                }

                return;
            }
        protected override void CheckScene(FbxScene scene)
        {
            FbxScene origScene = CreateScene(FbxManager);

            FbxNode origAnimNode   = origScene.GetRootNode().GetChild(0);
            FbxNode importAnimNode = scene.GetRootNode().GetChild(0);

            Assert.AreEqual(origScene.GetRootNode().GetChildCount(), scene.GetRootNode().GetChildCount());
            Assert.IsNotNull(origAnimNode);
            Assert.IsNotNull(importAnimNode);
            Assert.AreEqual(origAnimNode.GetName(), importAnimNode.GetName());

            FbxAnimStack origStack   = origScene.GetCurrentAnimationStack();
            FbxAnimStack importStack = scene.GetCurrentAnimationStack();

            CheckAnimStack(origStack, importStack);

            FbxAnimLayer origLayer   = origStack.GetAnimLayerMember();
            FbxAnimLayer importLayer = importStack.GetAnimLayerMember();

            Assert.IsNotNull(origLayer);
            Assert.IsNotNull(importLayer);

            Assert.AreEqual(FbxTime.EMode.eFrames30, scene.GetGlobalSettings().GetTimeMode());

            CheckAnimCurve(origAnimNode, importAnimNode, origLayer, importLayer, PropertyComponentList);
        }
示例#3
0
            /// <summary>
            /// Export bind pose of mesh to skeleton
            /// </summary>
            protected void ExportBindPose(FbxNode fbxRootNode, FbxNode meshNode, FbxScene fbxScene, Dictionary <Transform, FbxNode> boneNodes)
            {
                FbxPose fbxPose = FbxPose.Create(fbxScene, fbxRootNode.GetName());

                // set as bind pose
                fbxPose.SetIsBindPose(true);

                // assume each bone node has one weighted vertex cluster
                foreach (FbxNode fbxNode in boneNodes.Values)
                {
                    // EvaluateGlobalTransform returns an FbxAMatrix (affine matrix)
                    // which has to be converted to an FbxMatrix so that it can be passed to fbxPose.Add().
                    // The hierarchy for FbxMatrix and FbxAMatrix is as follows:
                    //
                    //      FbxDouble4x4
                    //      /           \
                    // FbxMatrix     FbxAMatrix
                    //
                    // Therefore we can't convert directly from FbxAMatrix to FbxMatrix,
                    // however FbxMatrix has a constructor that takes an FbxAMatrix.
                    FbxMatrix fbxBindMatrix = new FbxMatrix(fbxNode.EvaluateGlobalTransform());

                    fbxPose.Add(fbxNode, fbxBindMatrix);
                }

                FbxMatrix bindMatrix = new FbxMatrix(meshNode.EvaluateGlobalTransform());

                fbxPose.Add(meshNode, bindMatrix);

                // add the pose to the scene
                fbxScene.AddPose(fbxPose);
            }
示例#4
0
            /// <summary>
            /// Unconditionally export components on this game object
            /// </summary>
            protected void ExportComponents(GameObject unityGo, FbxScene fbxScene, FbxNode fbxParentNode)
            {
                // create an FbxNode and add it as a child of fbxParentNode
                FbxNode fbxNode = FbxNode.Create(fbxScene, unityGo.name);

                NumNodes++;

                ExportTransform(unityGo.transform, fbxNode);

                var fbxNodeAttr = ExportNull(fbxScene);

                // set the fbxNode's node attribute
                fbxNode.SetNodeAttribute(fbxNodeAttr);
                fbxNode.SetShadingMode(FbxNode.EShadingMode.eWireFrame);

                if (Verbose)
                {
                    Debug.Log(string.Format("exporting {0}", fbxNode.GetName()));
                }

                fbxParentNode.AddChild(fbxNode);

                // now  unityGo  through our children and recurse
                foreach (Transform uniChildT in  unityGo.transform)
                {
                    ExportComponents(uniChildT.gameObject, fbxScene, fbxNode);
                }

                return;
            }
        public void Animate(Transform unityTransform, FbxNode fbxNode, FbxAnimLayer fbxAnimLayer, bool Verbose)
        {
            if (!unityTransform || fbxNode == null)
            {
                return;
            }

            /* Find or create the three curves. */
            var fbxAnimCurveX = fbxNode.LclRotation.GetCurve(fbxAnimLayer, Globals.FBXSDK_CURVENODE_COMPONENT_X, true);
            var fbxAnimCurveY = fbxNode.LclRotation.GetCurve(fbxAnimLayer, Globals.FBXSDK_CURVENODE_COMPONENT_Y, true);
            var fbxAnimCurveZ = fbxNode.LclRotation.GetCurve(fbxAnimLayer, Globals.FBXSDK_CURVENODE_COMPONENT_Z, true);

            /* set the keys */
            using (new FbxAnimCurveModifyHelper(new List <FbxAnimCurve> {
                fbxAnimCurveX, fbxAnimCurveY, fbxAnimCurveZ
            }))
            {
                foreach (var key in ComputeKeys(unityTransform.localRotation, fbxNode))
                {
                    int i = fbxAnimCurveX.KeyAdd(key.time);
                    fbxAnimCurveX.KeySet(i, key.time, (float)key.euler.X);

                    i = fbxAnimCurveY.KeyAdd(key.time);
                    fbxAnimCurveY.KeySet(i, key.time, (float)key.euler.Y);

                    i = fbxAnimCurveZ.KeyAdd(key.time);
                    fbxAnimCurveZ.KeySet(i, key.time, (float)key.euler.Z);
                }
            }

            if (Verbose)
            {
                Debug.Log("Exported rotation animation for " + fbxNode.GetName());
            }
        }
示例#6
0
            /// <summary>
            /// Unconditionally export components on this game object
            /// </summary>
            protected void ExportComponents(GameObject unityGo, FbxScene fbxScene, FbxNode fbxParentNode)
            {
                // create an FbxNode and add it as a child of fbxParentNode
                FbxNode fbxNode = FbxNode.Create(fbxScene, unityGo.name);

                NumNodes++;

                ExportTransform(unityGo.transform, fbxNode);
                var fbxProperty = ExportCustomData(unityGo.transform, fbxNode);

                if (Verbose)
                {
                    Debug.Log(string.Format("exporting {0} ({1} components)", fbxNode.GetName(), (int)fbxProperty.GetFloat()));
                }

                fbxParentNode.AddChild(fbxNode);

                // now go through our children and recurse
                foreach (Transform uniChildT in unityGo.transform)
                {
                    ExportComponents(uniChildT.gameObject, fbxScene, fbxNode);
                }

                return;
            }
示例#7
0
        static void PrintFbxNode(FbxNode node, string prefix = "")
        {
            Console.WriteLine(prefix + node.GetName());

            for (int childIndex = 0; childIndex < node.GetChildCount(); ++childIndex)
            {
                PrintFbxNode(node.GetChild(childIndex), prefix + "--");
            }
        }
示例#8
0
            /// <summary>
            /// Exports the game object has a camera component
            /// </summary>
            protected void ExportComponents(GameObject unityGo, FbxScene fbxScene, FbxNode fbxNodeParent)
            {
                Camera unityCamera = unityGo.GetComponent <Camera> ();

                if (unityCamera == null)
                {
                    return;
                }

                // create an node and add it as a child of parent
                FbxNode fbxNode = FbxNode.Create(fbxScene, unityGo.name);

                NumNodes++;

                FbxNodeAttribute fbxNodeAttr = ExportCamera(unityCamera, fbxScene, fbxNode);

                if (fbxNodeAttr != null)
                {
                    fbxNode.SetNodeAttribute(fbxNodeAttr);

                    // make the last camera exported the default camera
                    DefaultCamera = fbxNode.GetName();
                }

                if (Verbose)
                {
                    Debug.Log(string.Format("exporting {0}", fbxNode.GetName()));
                }

                fbxNodeParent.AddChild(fbxNode);

                // add mapping between fbxnode for light
                // and unity game object for animation export
                MapUnityObjectToFbxNode [unityGo] = fbxNode;

                // now  unityGo  through our children and recurse
                foreach (Transform childT in  unityGo.transform)
                {
                    ExportComponents(childT.gameObject, fbxScene, fbxNode);
                }

                return;
            }
示例#9
0
        protected override void CheckScene(FbxScene scene)
        {
            FbxScene origScene = CreateScene(FbxManager);

            Assert.That(origScene.GetRootNode().GetChildCount(), Is.EqualTo(scene.GetRootNode().GetChildCount()));

            // check nodes match
            FbxNode origSourceNode      = origScene.GetRootNode().GetChild(0);
            FbxNode origConstrainedNode = origScene.GetRootNode().GetChild(1);

            FbxNode importSourceNode      = scene.GetRootNode().GetChild(0);
            FbxNode importConstrainedNode = scene.GetRootNode().GetChild(1);

            Assert.That(origSourceNode, Is.Not.Null);
            Assert.That(importSourceNode, Is.Not.Null);
            Assert.That(origConstrainedNode, Is.Not.Null);
            Assert.That(importConstrainedNode, Is.Not.Null);
            Assert.That(importSourceNode.GetName(), Is.EqualTo(origSourceNode.GetName()));
            Assert.That(importConstrainedNode.GetName(), Is.EqualTo(origConstrainedNode.GetName()));

            // check constraints match
            // TODO: find a way to cast to FbxConstraint
            Assert.That(scene.GetSrcObjectCount(), Is.EqualTo(origScene.GetSrcObjectCount()));
            FbxObject origPosConstraint   = origScene.FindSrcObject(ConstraintName);
            FbxObject importPosConstraint = scene.FindSrcObject(ConstraintName);

            Assert.That(origPosConstraint, Is.Not.Null);
            Assert.That(importPosConstraint, Is.Not.Null);
            Assert.That(importPosConstraint.GetName(), Is.EqualTo(origPosConstraint.GetName()));

            // check animation matches
            FbxAnimStack origStack   = origScene.GetCurrentAnimationStack();
            FbxAnimStack importStack = scene.GetCurrentAnimationStack();

            CheckAnimStack(origStack, importStack);

            FbxAnimLayer origLayer   = origStack.GetAnimLayerMember();
            FbxAnimLayer importLayer = importStack.GetAnimLayerMember();

            Assert.That(origLayer, Is.Not.Null);
            Assert.That(importLayer, Is.Not.Null);

            Assert.That(scene.GetGlobalSettings().GetTimeMode(), Is.EqualTo(FbxTime.EMode.eFrames30));

            CheckAnimCurve(origPosConstraint, importPosConstraint, origLayer, importLayer, PropertyComponentList);
        }
示例#10
0
            /// <summary>
            /// Exports the game object has a light component
            /// </summary>
            protected void ExportComponents(GameObject unityGo, FbxScene fbxScene, FbxNode fbxNodeParent)
            {
                // create an node and add it as a child of parent
                FbxNode fbxNode = FbxNode.Create(fbxScene, unityGo.name);

                NumNodes++;

                ExportTransform(unityGo.transform, fbxNode);

                var fbxMesh = ExportMesh(unityGo, fbxScene);

                if (fbxMesh != null)
                {
                    // set the fbxNode containing the mesh
                    fbxNode.SetNodeAttribute(fbxMesh);
                    fbxNode.SetShadingMode(FbxNode.EShadingMode.eWireFrame);
                }

                FbxLight fbxLight = ExportLight(unityGo, fbxScene, fbxNode);

                if (fbxLight != null)
                {
                    fbxNode.SetNodeAttribute(fbxLight);
                }

                if (Verbose)
                {
                    Debug.Log(string.Format("exporting {0}", fbxNode.GetName()));
                }

                fbxNodeParent.AddChild(fbxNode);

                // add mapping between fbxnode for light
                // and unity game object for animation export
                MapUnityObjectToFbxNode [unityGo] = fbxNode;

                // now  unityGo  through our children and recurse
                foreach (Transform childT in  unityGo.transform)
                {
                    ExportComponents(childT.gameObject, fbxScene, fbxNode);
                }

                return;
            }
        // 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));
            }
        }
        // compare the hierarchy 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());
            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));
            }
        }
        public void Animate(Transform unityTransform, FbxNode fbxNode, FbxAnimLayer fbxAnimLayer, bool Verbose)
        {
            if (!unityTransform || fbxNode == null)
            {
                return;
            }

            /* Find or create the three curves. */
            var fbxAnimCurveX = fbxNode.LclRotation.GetCurve(fbxAnimLayer, Globals.FBXSDK_CURVENODE_COMPONENT_X, true);
            var fbxAnimCurveY = fbxNode.LclRotation.GetCurve(fbxAnimLayer, Globals.FBXSDK_CURVENODE_COMPONENT_Y, true);
            var fbxAnimCurveZ = fbxNode.LclRotation.GetCurve(fbxAnimLayer, Globals.FBXSDK_CURVENODE_COMPONENT_Z, true);

            /* set the keys */
            using (new FbxAnimCurveModifyHelper(new List <FbxAnimCurve> {
                fbxAnimCurveX, fbxAnimCurveY, fbxAnimCurveZ
            }))
            {
                foreach (var key in ComputeKeys(unityTransform.localRotation, fbxNode))
                {
                    int i = fbxAnimCurveX.KeyAdd(key.time);
                    fbxAnimCurveX.KeySet(i, key.time, (float)key.euler.X);

                    i = fbxAnimCurveY.KeyAdd(key.time);
                    fbxAnimCurveY.KeySet(i, key.time, (float)key.euler.Y);

                    i = fbxAnimCurveZ.KeyAdd(key.time);
                    fbxAnimCurveZ.KeySet(i, key.time, (float)key.euler.Z);
                }
            }

            // Uni-35616 unroll curves to preserve continuous rotations
            var fbxCurveNode = fbxNode.LclRotation.GetCurveNode(fbxAnimLayer, false /*should already exist*/);

            FbxAnimCurveFilterUnroll fbxAnimUnrollFilter = new FbxAnimCurveFilterUnroll();

            fbxAnimUnrollFilter.Apply(fbxCurveNode);

            if (Verbose)
            {
                Debug.Log("Exported rotation animation for " + fbxNode.GetName());
            }
        }
示例#14
0
            /// <summary>
            /// Process fbxNode, configure the transform and construct mesh
            /// </summary>
            public void ProcessNode(FbxNode fbxNode, GameObject unityParentObj = null)
            {
                string name = fbxNode.GetName();

                GameObject unityGo = new GameObject(name);

                NumNodes++;

                if (unityParentObj != null)
                {
                    unityGo.transform.parent = unityParentObj.transform;
                }

                ProcessTransform(fbxNode, unityGo);
                ProcessMesh(fbxNode, unityGo);

                for (int i = 0; i < fbxNode.GetChildCount(); ++i)
                {
                    ProcessNode(fbxNode.GetChild(i), unityGo);
                }
            }
示例#15
0
    Transform CreateNode(Transform parent, FbxNode fbxNode)
    {
        var       unityNode      = new GameObject(fbxNode.GetName());
        Transform unityTransform = unityNode.transform;

        unityTransform.parent = parent;

        // If there's a mesh attached, create it
        var fbxMesh = fbxNode.GetMesh();

        if (fbxMesh != null)
        {
            var mesh       = GetOrCreateInstance(fbxMesh);
            var meshFilter = unityNode.AddComponent <MeshFilter>();
            var meshRender = unityNode.AddComponent <MeshRenderer>();
            meshFilter.sharedMesh = mesh;
            meshRender.material   = DefaultMaterial;
        }

        return(unityTransform);
    }
示例#16
0
            /// <summary>
            /// Unconditionally export components on this game object
            /// </summary>
            protected void ExportComponents(GameObject unityGo, FbxScene fbxScene, FbxNode fbxParentNode)
            {
                // create an FbxNode and add it as a child of fbxParentNode
                FbxNode fbxNode = FbxNode.Create(fbxScene, unityGo.name);

                NumNodes++;

                ExportTransform(unityGo.transform, fbxNode);
                ExportMesh(GetMeshInfo(unityGo), fbxNode, fbxScene);
#if UNI_16194
                // if this GameObject is at the root of the scene,
                // make it invisible, but leave all its children as is

                // set the node visibility
                fbxNode.SetVisibility(unityGo.transform.parent ? unityGo.activeSelf : false);

                // don't inherit visibility of invisible root node
                if (unityGo.transform.parent == null)
                {
                    fbxNode.VisibilityInheritance.Set(false);
                }
#endif
                if (Verbose)
                {
                    Debug.Log(string.Format("exporting {0}", fbxNode.GetName()));
                }

                fbxParentNode.AddChild(fbxNode);

                // now  unityGo  through our children and recurse
                foreach (Transform uniChildT in  unityGo.transform)
                {
                    ExportComponents(uniChildT.gameObject, fbxScene, fbxNode);
                }

                return;
            }
示例#17
0
                public void Animate(Transform unityTransform, FbxNode fbxNode, FbxAnimLayer fbxAnimLayer, bool Verbose)
                {
                    /* Find or create the three curves. */
                    var x = fbxNode.LclRotation.GetCurve(fbxAnimLayer, Globals.FBXSDK_CURVENODE_COMPONENT_X, true);
                    var y = fbxNode.LclRotation.GetCurve(fbxAnimLayer, Globals.FBXSDK_CURVENODE_COMPONENT_Y, true);
                    var z = fbxNode.LclRotation.GetCurve(fbxAnimLayer, Globals.FBXSDK_CURVENODE_COMPONENT_Z, true);

                    /* set the keys */
                    x.KeyModifyBegin();
                    y.KeyModifyBegin();
                    z.KeyModifyBegin();

                    var keys = ComputeKeys(unityTransform.localRotation, fbxNode);

                    for (int i = 0, n = keys.Length; i < n; ++i)
                    {
                        var key = keys[i];
                        x.KeyAdd(key.time);
                        x.KeySet(i, key.time, (float)key.euler.X);

                        y.KeyAdd(key.time);
                        y.KeySet(i, key.time, (float)key.euler.Y);

                        z.KeyAdd(key.time);
                        z.KeySet(i, key.time, (float)key.euler.Z);
                    }

                    z.KeyModifyEnd();
                    y.KeyModifyEnd();
                    x.KeyModifyEnd();

                    if (Verbose)
                    {
                        Debug.Log("Exported rotation animation for " + fbxNode.GetName());
                    }
                }
示例#18
0
            /// <summary>
            /// Process transformation data and setup Transform component
            /// </summary>
            private void ProcessTransform(FbxNode fbxNode, GameObject unityGo)
            {
                FbxVector4    lclTrs = new FbxVector4();
                FbxQuaternion lclRot = new FbxQuaternion();
                FbxVector4    lclScl = new FbxVector4(1.0f, 1.0f, 1.0f);

#if UNI_18844
                // Construct rotation matrices
                FbxVector4 fbxRotation  = new FbxVector4(fbxNode.LclRotation.Get());
                FbxAMatrix fbxRotationM = new FbxAMatrix();
                fbxRotationM.SetR(fbxRotation);

                FbxVector4 fbxPreRotation  = new FbxVector4(fbxNode.PreRotation.Get());
                FbxAMatrix fbxPreRotationM = new FbxAMatrix();
                fbxPreRotationM.SetR(fbxPreRotation);

                FbxVector4 fbxPostRotation  = new FbxVector4(fbxNode.PostRotation.Get());
                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.RotationOffset.Get();
                fbxRotationOffsetM.SetT(fbxRotationOffset);

                FbxAMatrix fbxRotationPivotM = new FbxAMatrix();
                FbxVector4 fbxRotationPivot  = fbxNode.RotationPivot.Get();
                fbxRotationPivotM.SetT(fbxRotationPivot);

                FbxAMatrix fbxScalingOffsetM = new FbxAMatrix();
                FbxVector4 fbxScalingOffset  = fbxNode.ScalingOffset.Get();
                fbxScalingOffsetM.SetT(fbxScalingOffset);

                FbxAMatrix fbxScalingPivotM = new FbxAMatrix();
                FbxVector4 fbxScalingPivot  = fbxNode.ScalingPivot.Get();
                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();
#endif

                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]);
            }
示例#19
0
        public static void LogError(FbxNode node, string message)
        {
            //!!!!пока так

            Log.Info("Import3D: Error: " + node.GetName() + " : " + message);
        }
        protected override FbxScene CreateScene(FbxManager manager)
        {
            FbxScene  scene      = base.CreateScene(manager);
            FbxNode   cameraNode = scene.GetRootNode().GetChild(0);
            FbxCamera camera     = FbxCamera.Create(scene, "camera");

            camera.ProjectionType.Set(FbxCamera.EProjectionType.ePerspective);
            camera.SetAspect(FbxCamera.EAspectRatioMode.eFixedRatio, 300, 400);
            camera.FilmAspectRatio.Set(240);
            camera.SetApertureWidth(4);
            camera.SetApertureHeight(2);
            camera.SetApertureMode(FbxCamera.EApertureMode.eFocalLength);
            camera.FocalLength.Set(32);
            camera.SetNearPlane(1);
            camera.SetFarPlane(100);

            // create custom property (background color)
            var bgColorProperty = FbxProperty.Create(cameraNode, Globals.FbxColor4DT, "backgroundColor");

            Assert.IsTrue(bgColorProperty.IsValid());

            bgColorProperty.Set(new FbxColor(0.5, 0.4, 0.1, 1));

            // Must be marked user-defined or it won't be shown in most DCCs
            bgColorProperty.ModifyFlag(FbxPropertyFlags.EFlags.eUserDefined, true);
            bgColorProperty.ModifyFlag(FbxPropertyFlags.EFlags.eAnimatable, true);

            Assert.IsTrue(bgColorProperty.GetFlag(FbxPropertyFlags.EFlags.eUserDefined));
            Assert.IsTrue(bgColorProperty.GetFlag(FbxPropertyFlags.EFlags.eAnimatable));

            // create custom property (clear flags)
            var clearFlagsProperty = FbxProperty.Create(cameraNode, Globals.FbxIntDT, "clearFlags");

            Assert.IsTrue(clearFlagsProperty.IsValid());

            clearFlagsProperty.Set(4);

            // Must be marked user-defined or it won't be shown in most DCCs
            clearFlagsProperty.ModifyFlag(FbxPropertyFlags.EFlags.eUserDefined, true);
            clearFlagsProperty.ModifyFlag(FbxPropertyFlags.EFlags.eAnimatable, true);

            Assert.IsTrue(clearFlagsProperty.GetFlag(FbxPropertyFlags.EFlags.eUserDefined));
            Assert.IsTrue(clearFlagsProperty.GetFlag(FbxPropertyFlags.EFlags.eAnimatable));

            // Add camera properties to animation clip
            FbxAnimStack animStack = scene.GetCurrentAnimationStack();
            FbxAnimLayer animLayer = animStack.GetAnimLayerMember();

            // TODO: (UNI-19438) Figure out why trying to do GetCurve for NearPlane always returns null
            CreateAnimCurves(cameraNode, animLayer, new List <PropertyComponentPair> ()
            {
                new PropertyComponentPair("backgroundColor", new string[] {
                    Globals.FBXSDK_CURVENODE_COLOR_RED,
                    Globals.FBXSDK_CURVENODE_COLOR_GREEN,
                    Globals.FBXSDK_CURVENODE_COLOR_BLUE, "W"
                }),
                new PropertyComponentPair("FocalLength", new string[] { null }),
                new PropertyComponentPair("clearFlags", new string[] { null })
            }, (index) => { return(index); }, (index) => { return(index / 5.0f); }, camera);

            cameraNode.SetNodeAttribute(camera);

            // set the default camera
            scene.GetGlobalSettings().SetDefaultCamera(cameraNode.GetName());

            return(scene);
        }
示例#21
0
 public static void LogWarning(FbxNode node, string message)
 {
     Log.Info("Import3D: Warning: " + node.GetName() + " : " + message);
 }
示例#22
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;
            }
        }
示例#23
0
            /// <summary>
            /// Process fbx scene by doing nothing
            /// </summary>
            public void ProcessNode(FbxNode fbxNode, GameObject unityParentObj = null, bool constructTransform = false)
            {
                string name = fbxNode.GetName();

                GameObject unityGo = new GameObject(name);

                NumNodes++;

                if (unityParentObj != null)
                {
                    unityGo.transform.parent = unityParentObj.transform;
                }

                FbxAMatrix fbxTransform = null;

                if (constructTransform)
                {
#if UNI_18844
                    // Construct rotation matrices
                    FbxVector4 fbxRotation  = new FbxVector4(fbxNode.LclRotation.Get());
                    FbxAMatrix fbxRotationM = new FbxAMatrix();
                    fbxRotationM.SetR(fbxRotation);

                    FbxVector4 fbxPreRotation  = new FbxVector4(fbxNode.PreRotation.Get());
                    FbxAMatrix fbxPreRotationM = new FbxAMatrix();
                    fbxPreRotationM.SetR(fbxPreRotation);

                    FbxVector4 fbxPostRotation  = new FbxVector4(fbxNode.PostRotation.Get());
                    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.RotationOffset.Get();
                    fbxRotationOffsetM.SetT(fbxRotationOffset);

                    FbxAMatrix fbxRotationPivotM = new FbxAMatrix();
                    FbxVector4 fbxRotationPivot  = fbxNode.RotationPivot.Get();
                    fbxRotationPivotM.SetT(fbxRotationPivot);

                    FbxAMatrix fbxScalingOffsetM = new FbxAMatrix();
                    FbxVector4 fbxScalingOffset  = fbxNode.ScalingOffset.Get();
                    fbxScalingOffsetM.SetT(fbxScalingOffset);

                    FbxAMatrix fbxScalingPivotM = new FbxAMatrix();
                    FbxVector4 fbxScalingPivot  = fbxNode.ScalingPivot.Get();
                    fbxScalingPivotM.SetT(fbxScalingPivot);

                    fbxTransform =
                        fbxTranslationM *
                        fbxRotationOffsetM *
                        fbxRotationPivotM *
                        fbxPreRotationM *
                        fbxRotationM *
                        fbxPostRotationM *
                        fbxRotationPivotM.Inverse() *
                        fbxScalingOffsetM *
                        fbxScalingPivotM *
                        fbxScalingM *
                        fbxScalingPivotM.Inverse();

                    lclTrs = fbxTransform.GetT();
                    lclRot = fbxTransform.GetQ();
                    lclScl = fbxTransform.GetS();
#endif
                }
                else
                {
                    fbxTransform = fbxNode.EvaluateLocalTransform();
                }

                if (fbxTransform == null)
                {
                    Debug.LogError(string.Format("failed to retrieve transform for node : {0}", fbxNode.GetName()));
                    return;
                }

                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()));

                // check we can handle translation value
                Debug.Assert(lclTrs.X <= float.MaxValue && lclTrs.X >= float.MinValue);
                Debug.Assert(lclTrs.Y <= float.MaxValue && lclTrs.Y >= float.MinValue);
                Debug.Assert(lclTrs.Z <= float.MaxValue && lclTrs.Z >= float.MinValue);

                unityGo.transform.localPosition = new Vector3((float)lclTrs.X, (float)lclTrs.Y, (float)lclTrs.Z);
                unityGo.transform.localRotation = new Quaternion((float)lclRot[0], (float)lclRot[1], (float)lclRot[2], (float)lclRot[3]);
                unityGo.transform.localScale    = new Vector3((float)lclScl.X, (float)lclScl.Y, (float)lclScl.Z);

                for (int i = 0; i < fbxNode.GetChildCount(); ++i)
                {
                    ProcessNode(fbxNode.GetChild(i), unityGo);
                }
            }
示例#24
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;
            }
        }
示例#25
0
            /// <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);
            }
示例#26
0
            /// <summary>
            /// Export GameObject's as a skinned mesh with bones
            /// </summary>
            protected void ExportSkinnedMesh(Animator unityAnimator, FbxScene fbxScene, FbxNode fbxParentNode)
            {
                GameObject unityGo = unityAnimator.gameObject;

                SkinnedMeshRenderer unitySkin
                    = unityGo.GetComponentInChildren <SkinnedMeshRenderer> ();

                if (unitySkin == null)
                {
                    Debug.LogError("could not find skinned mesh");
                    return;
                }

                var meshInfo = GetSkinnedMeshInfo(unityGo);

                if (meshInfo.renderer == null)
                {
                    Debug.LogError("mesh has no renderer");
                    return;
                }

                // create an FbxNode and add it as a child of fbxParentNode
                FbxNode fbxNode = FbxNode.Create(fbxScene, unityAnimator.name);


                Dictionary <Transform, FbxNode> boneNodes
                    = new Dictionary <Transform, FbxNode> ();

                // export skeleton
                if (ExportSkeleton(meshInfo, fbxScene, fbxNode, ref boneNodes))
                {
                    // export skin
                    FbxNode fbxMeshNode = ExportMesh(meshInfo, fbxScene, fbxNode);

                    FbxMesh fbxMesh = fbxMeshNode.GetMesh();

                    if (fbxMesh == null)
                    {
                        Debug.LogError("Could not find mesh");
                        return;
                    }

                    // bind mesh to skeleton
                    ExportSkin(meshInfo, fbxScene, fbxMesh, fbxMeshNode, boneNodes);

                    // add bind pose
                    ExportBindPose(fbxNode, fbxMeshNode, fbxScene, boneNodes);

                    fbxParentNode.AddChild(fbxNode);
                    NumNodes++;

                    if (Verbose)
                    {
                        Debug.Log(string.Format("exporting {0} {1}", "Skin", fbxNode.GetName()));
                    }
                }
                else
                {
                    Debug.LogError("failed to export skeleton");
                }
            }