public void AddAnimationCurve(string inputId, float[] curveData)
    {
        // prepare some data
        string keyValueFloatDataStr = "";
        string timeArrayDataStr     = "";

        for (int i = 0; i < curveData.Length; i++)
        {
            if (i == 0)
            {
                keyValueFloatDataStr += curveData [i].ToString();
                timeArrayDataStr     += FbxHelper.GetFbxSeconds(i, 60);
            }
            else
            {
                keyValueFloatDataStr += "," + curveData [i].ToString();
                timeArrayDataStr     += "," + FbxHelper.GetFbxSeconds(i, 60);
            }
        }

        //AnimationCurve: 106102887970656, "AnimCurve::", ""
        string      nodeData  = inputId + ", \"AnimCurve::\", \"\"";
        FbxDataNode curveNode = new FbxDataNode("AnimationCurve", nodeData, 1);

        string dataLengthStr = curveData.Length.ToString();

        curveNode.addSubNode("Default", "0");
        curveNode.addSubNode("KeyVer", "4008");

        FbxDataNode keyTimeNode = new FbxDataNode("KeyTime", "*" + dataLengthStr, 2);

        keyTimeNode.addSubNode("a", timeArrayDataStr);
        curveNode.addSubNode(keyTimeNode);

        FbxDataNode keyValuesNode = new FbxDataNode("KeyValueFloat", "*" + dataLengthStr, 2);

        keyValuesNode.addSubNode("a", keyValueFloatDataStr);
        curveNode.addSubNode(keyValuesNode);

        curveNode.addSubNode(";KeyAttrFlags", "Cubic|TangeantAuto|GenericTimeIndependent|GenericClampProgressive");

        FbxDataNode keyAttrFlagsNode = new FbxDataNode("KeyAttrFlags", "*1", 2);

        keyAttrFlagsNode.addSubNode("a", "24840");
        curveNode.addSubNode(keyAttrFlagsNode);

        FbxDataNode keyRefCountNode = new FbxDataNode("KeyAttrRefCount", "*1", 2);

        keyRefCountNode.addSubNode("a", dataLengthStr);
        curveNode.addSubNode(keyRefCountNode);

        // release memory
        curveNode.saveDataOnDisk(saveFileFolder);

        objMainNode.addSubNode(curveNode);
    }
示例#2
0
        static FbxObject CreateAnimStackObject(AnimStack Anim, FbxObjectManager ObjectManager)
        {
            var Name   = "AnimStack::" + Anim.Name;
            var Object = ObjectManager.CreateObject("AnimationStack", Name);
            var Def    = Object.Definition;

            Def.AddValue(Object.Ident);
            Def.AddValue(Name);
            Def.AddValue("");
            var Properties = Def.AddProperty("Properties70");

            var LocalStart = Properties.AddProperty("P");

            LocalStart.AddValue("LocalStart");
            LocalStart.AddValue("KTime");
            LocalStart.AddValue("Time");
            LocalStart.AddValue("");
            LocalStart.AddValue(FbxHelper.GetFbxSeconds(Anim.LocalStartTime));

            var LocalStop = Properties.AddProperty("P");

            LocalStop.AddValue("LocalStop");
            LocalStop.AddValue("KTime");
            LocalStop.AddValue("Time");
            LocalStop.AddValue("");
            LocalStop.AddValue(FbxHelper.GetFbxSeconds(Anim.LocalEndTime));

            var ReferenceStart = Properties.AddProperty("P");

            ReferenceStart.AddValue("ReferenceStart");
            ReferenceStart.AddValue("KTime");
            ReferenceStart.AddValue("Time");
            ReferenceStart.AddValue("");
            ReferenceStart.AddValue(FbxHelper.GetFbxSeconds(Anim.ReferenceStartTime));

            var ReferenceStop = Properties.AddProperty("P");

            ReferenceStop.AddValue("ReferenceStop");
            ReferenceStop.AddValue("KTime");
            ReferenceStop.AddValue("Time");
            ReferenceStop.AddValue("");
            ReferenceStop.AddValue(FbxHelper.GetFbxSeconds(Anim.ReferenceEndTime));

            /*
             * AnimationStack: 362632224, "AnimStack::Take 001", "" {
             * Properties70:
             *      {
             *      P: "LocalStart", "KTime", "Time", "",0
             *      P: "LocalStop", "KTime", "Time", "", 46186158000
             *      P: "ReferenceStart", "KTime", "Time", "",0
             *      P: "ReferenceStop", "KTime", "Time", "", 46186158000
             * }
             */
            return(Object);
        }
示例#3
0
            public FbxObject AddAnimationCurve(float[] CurveDatas, float[] CurveTimes)
            {
                //	todo: use proper time!
                var TimeDatas = new List <long>();

                for (int i = 0; i < CurveDatas.Length; i++)
                {
                    TimeDatas.Add(FbxHelper.GetFbxSeconds(CurveTimes[i]));
                }

                //	add a new object
                var CurveNodeObj = new FbxObject(AllocIdent(), "AnimationCurve");

                Objects.Add(CurveNodeObj);
                var CurveNode = CurveNodeObj.Definition;

                CurveNode.AddValue(CurveNodeObj.Ident);
                CurveNode.AddValue("AnimCurve::");                      //	name
                CurveNode.AddValue("");

                //AnimationCurve: 106102887970656, "AnimCurve::", ""
                //string nodeData = inputId + ", \"AnimCurve::\", \"\"";
                //FbxDataNode curveNode = new FbxDataNode("AnimationCurve", nodeData, 1);


                CurveNode.AddProperty("Default", 0);
                CurveNode.AddProperty("KeyVer", 4008);

                var keyTimeNode = CurveNode.AddProperty("KeyTime");

                keyTimeNode.AddValue("*" + CurveDatas.Length);
                keyTimeNode.AddProperty("a", new FbxValue_Ints(TimeDatas));
                //FbxDataNode keyTimeNode = new FbxDataNode("KeyTime", "*" + dataLengthStr, 2);
                //keyTimeNode.addSubNode("a", timeArrayDataStr);
                //curveNode.addSubNode(keyTimeNode);

                var keyValuesNode = CurveNode.AddProperty("KeyValueFloat");

                keyValuesNode.AddValue("*" + CurveDatas.Length);
                keyValuesNode.AddProperty("a", new FbxValue_Floats(CurveDatas));
                //var keyValuesNode = new FbxDataNode("KeyValueFloat", "*" + dataLengthStr, 2);
                //keyValuesNode.addSubNode("a", keyValueFloatDataStr);
                //curveNode.addSubNode(keyValuesNode);

                //curveNode.addSubNode(";KeyAttrFlags", "Cubic|TangeantAuto|GenericTimeIndependent|GenericClampProgressive");
                var keyAttrFlagsNode = CurveNode.AddProperty("KeyAttrFlags");

                keyAttrFlagsNode.AddComment("KeyAttrFlags = Cubic | TangeantAuto | GenericTimeIndependent | GenericClampProgressive");
                //FbxDataNode keyAttrFlagsNode = new FbxDataNode("KeyAttrFlags", "*1", 2);
                keyAttrFlagsNode.AddValue("*1");
                keyAttrFlagsNode.AddProperty("a", "24840");
                //curveNode.addSubNode(keyAttrFlagsNode);

                var keyRefCountNode = CurveNode.AddProperty("KeyAttrRefCount");

                keyRefCountNode.AddValue("*1");
                //FbxDataNode keyRefCountNode = new FbxDataNode("KeyAttrRefCount", "*1", 2);
                keyRefCountNode.AddProperty("a", CurveDatas.Length);
                //keyRefCountNode.addSubNode("a", dataLengthStr);
                //curveNode.addSubNode(keyRefCountNode);

                //	objects.add curvenode
                //return curveNode;

                return(CurveNodeObj);
            }