Esempio n. 1
0
        public List <FOBJKey> GetKeys(float FrameCount = -1)
        {
            List <FOBJKey> Keys  = new List <FOBJKey>();
            int            clock = 0;

            Reader.Seek(0);
            while (Reader.Position < Reader.BaseStream.Length)
            {
                int type = Reader.ReadPacked();
                GXInterpolationType interpolation = (GXInterpolationType)((type) & 0x0F);
                int numOfKey = ((type >> 4)) + 1;
                if (interpolation == 0)
                {
                    break;
                }

                for (int i = 0; i < numOfKey; i++)
                {
                    double value = 0;
                    double tan   = 0;
                    int    time  = 0;
                    switch (interpolation)
                    {
                    case GXInterpolationType.HSD_A_OP_CON:
                        value = ParseFloat(Reader, FOBJ.ValueFormat, FOBJ.ValueScale);
                        time  = Reader.ReadPacked();
                        break;

                    case GXInterpolationType.HSD_A_OP_LIN:
                        value = ParseFloat(Reader, FOBJ.ValueFormat, FOBJ.ValueScale);
                        time  = Reader.ReadPacked();
                        break;

                    case GXInterpolationType.HSD_A_OP_SPL0:
                        value = ParseFloat(Reader, FOBJ.ValueFormat, FOBJ.ValueScale);
                        time  = Reader.ReadPacked();
                        break;

                    case GXInterpolationType.HSD_A_OP_SPL:
                        value = ParseFloat(Reader, FOBJ.ValueFormat, FOBJ.ValueScale);
                        tan   = ParseFloat(Reader, FOBJ.TanFormat, FOBJ.TanScale);
                        time  = Reader.ReadPacked();
                        break;

                    case GXInterpolationType.HSD_A_OP_SLP:
                        tan = ParseFloat(Reader, FOBJ.TanFormat, FOBJ.TanScale);
                        break;

                    case GXInterpolationType.HSD_A_OP_KEY:
                        value = ParseFloat(Reader, FOBJ.ValueFormat, FOBJ.ValueScale);
                        break;

                    default:
                        throw new Exception("Unknown Interpolation Type " + interpolation.ToString("X"));
                    }

                    FOBJKey kf = new FOBJKey();
                    kf.InterpolationType = interpolation;
                    kf.Value             = (float)value;
                    kf.Frame             = clock;
                    kf.Tan = (float)tan;
                    Keys.Add(kf);
                    clock += time;
                }
            }
            return(Keys);
        }
Esempio n. 2
0
        public List <FOBJKey> GetKeys(float startframe, float frame_count = -1)
        {
            List <FOBJKey> Keys = new List <FOBJKey>();

            if (FOBJ.JointTrackType == JointTrackType.HSD_A_J_PTCL)
            {
                return(Keys);
            }

            float clock = startframe;

            Reader.Seek(0);
            while (Reader.Position < Reader.BaseStream.Length)
            {
                int type = Reader.ReadPacked();
                GXInterpolationType interpolation = (GXInterpolationType)((type) & 0x0F);
                int numOfKey = ((type >> 4)) + 1;
                if (interpolation == 0)
                {
                    break;
                }

                for (int i = 0; i < numOfKey; i++)
                {
                    double value = 0;
                    double tan   = 0;
                    int    time  = 0;
                    switch (interpolation)
                    {
                    case GXInterpolationType.HSD_A_OP_CON:
                        value = ParseFloat(Reader, FOBJ.ValueFormat, FOBJ.ValueScale);
                        time  = Reader.ReadPacked();
                        break;

                    case GXInterpolationType.HSD_A_OP_LIN:
                        value = ParseFloat(Reader, FOBJ.ValueFormat, FOBJ.ValueScale);
                        time  = Reader.ReadPacked();
                        break;

                    case GXInterpolationType.HSD_A_OP_SPL0:
                        value = ParseFloat(Reader, FOBJ.ValueFormat, FOBJ.ValueScale);
                        time  = Reader.ReadPacked();
                        break;

                    case GXInterpolationType.HSD_A_OP_SPL:
                        value = ParseFloat(Reader, FOBJ.ValueFormat, FOBJ.ValueScale);
                        tan   = ParseFloat(Reader, FOBJ.TanFormat, FOBJ.TanScale);
                        time  = Reader.ReadPacked();
                        break;

                    case GXInterpolationType.HSD_A_OP_SLP:
                        tan = ParseFloat(Reader, FOBJ.TanFormat, FOBJ.TanScale);
                        break;

                    case GXInterpolationType.HSD_A_OP_KEY:
                        value = ParseFloat(Reader, FOBJ.ValueFormat, FOBJ.ValueScale);
                        break;

                    default:
                        throw new Exception("Unknown Interpolation Type " + interpolation.ToString("X"));
                    }

                    FOBJKey kf = new FOBJKey();
                    kf.InterpolationType = interpolation;
                    kf.Value             = (float)value;
                    kf.Frame             = clock;
                    kf.Tan = (float)tan;
                    Keys.Add(kf);
                    clock += time;
                }
            }

            // hack for animations that don't start on frame 0
            if (Keys.Count > 0 && Keys[0].Frame != 0)
            {
                Keys.Insert(0, new FOBJKey()
                {
                    Frame = 0, Value = Keys[0].Value, InterpolationType = GXInterpolationType.HSD_A_OP_CON
                });
            }

            return(Keys);
        }
Esempio n. 3
0
        public List <FOBJKey> GetKeys(float startframe, float frame_count = -1)
        {
            List <FOBJKey> Keys = new List <FOBJKey>();

            if (FOBJ.JointTrackType == JointTrackType.HSD_A_J_PTCL)
            {
                return(Keys);
            }

            float clock = 0;// startframe;

            Reader.Seek(0);
            while (Reader.Position < Reader.BaseStream.Length)
            {
                int type = Reader.ReadPacked();
                GXInterpolationType interpolation = (GXInterpolationType)((type) & 0x0F);
                int numOfKey = ((type >> 4)) + 1;
                if (interpolation == 0)
                {
                    break;
                }

                for (int i = 0; i < numOfKey; i++)
                {
                    double value = 0;
                    double tan   = 0;
                    int    time  = 0;
                    switch (interpolation)
                    {
                    case GXInterpolationType.HSD_A_OP_CON:
                        value = ParseFloat(Reader, FOBJ.ValueFormat, FOBJ.ValueScale);
                        time  = Reader.ReadPacked();
                        break;

                    case GXInterpolationType.HSD_A_OP_LIN:
                        value = ParseFloat(Reader, FOBJ.ValueFormat, FOBJ.ValueScale);
                        time  = Reader.ReadPacked();
                        break;

                    case GXInterpolationType.HSD_A_OP_SPL0:
                        value = ParseFloat(Reader, FOBJ.ValueFormat, FOBJ.ValueScale);
                        time  = Reader.ReadPacked();
                        break;

                    case GXInterpolationType.HSD_A_OP_SPL:
                        value = ParseFloat(Reader, FOBJ.ValueFormat, FOBJ.ValueScale);
                        tan   = ParseFloat(Reader, FOBJ.TanFormat, FOBJ.TanScale);
                        time  = Reader.ReadPacked();
                        break;

                    case GXInterpolationType.HSD_A_OP_SLP:
                        tan = ParseFloat(Reader, FOBJ.TanFormat, FOBJ.TanScale);
                        break;

                    case GXInterpolationType.HSD_A_OP_KEY:
                        value = ParseFloat(Reader, FOBJ.ValueFormat, FOBJ.ValueScale);
                        break;

                    default:
                        throw new Exception("Unknown Interpolation Type " + interpolation.ToString("X"));
                    }

                    FOBJKey kf = new FOBJKey();
                    kf.InterpolationType = interpolation;
                    kf.Value             = (float)value;
                    kf.Frame             = clock;
                    kf.Tan = (float)tan;
                    Keys.Add(kf);
                    clock += time;
                }
            }

            // hack for animations that don't start on frame 0
            if (startframe != 0)
            {
                // create a player in order to bake keys
                FOBJ_Player player = new FOBJ_Player(0, Keys);

                // move starting frame
                foreach (var k in Keys)
                {
                    k.Frame -= startframe;
                }

                // remove all keys out of bounds
                Keys.RemoveAll(e => e.Frame < 0);

                // bake the keys from frame 0 to first key frame
                if (Keys.Count > 0 && Keys[0].Frame != 0)
                {
                    var firstFrame = Keys[0].Frame;
                    for (int i = 0; i < firstFrame; i++)
                    {
                        Keys.Insert(i, new FOBJKey()
                        {
                            Frame             = i,
                            Value             = player.GetValue(i - startframe),
                            InterpolationType = GXInterpolationType.HSD_A_OP_LIN
                        });
                    }
                }
            }

            return(Keys);
        }