Beispiel #1
0
        public static KAnimInfo LoadPSA(string filename)
        {
            KAnimInfo Info = new KAnimInfo();

            if (File.Exists(filename))
            {
                FileStream   file = File.Open(filename, FileMode.Open);
                VChunkHeader main = KFileHelper.GetChunk(file);

                VBone[]          Bones    = KFileHelper.GetData <VBone>(file);
                AnimInfoBinary[] Animinfo = KFileHelper.GetData <AnimInfoBinary>(file);
                VQuatAnimKey[]   AnimKeys = KFileHelper.GetData <VQuatAnimKey>(file);

                for (int i = 0; i < Bones.Length; i++)
                {
                    if (i == Bones[i].ParentIndex)
                    {
                        Bones[i].ParentIndex = -1;
                    }
                }

                if (Animinfo.Length > 0)
                {
                    Info.AnimRate  = Animinfo[0].AnimRate;
                    Info.BoneCount = Bones.Length;
                    Info.Name      = Animinfo[0].Name;
                    Info.Frames    = new List <KeyFrame>();

                    float StepTime = 1.0f / Animinfo[0].AnimRate;

                    for (int i = 0; i < Animinfo[0].NumRawFrames; i++)
                    {
                        KeyFrame frame = new KeyFrame();
                        frame.Bones = new VBone[Animinfo[0].TotalBones];
                        int x = 0;
                        for (int j = (i * Animinfo[0].TotalBones); j < (i * Animinfo[0].TotalBones) + Animinfo[0].TotalBones; j++)
                        {
                            frame.Bones[x].BonePos.Position    = AnimKeys[j].Position;
                            frame.Bones[x].BonePos.Orientation = AnimKeys[j].Orientation;
                            frame.Bones[x].ParentIndex         = Bones[x].ParentIndex;
                            frame.Bones[x].Name = Bones[x].Name;
                            frame.Time          = StepTime * i;
                            x++;
                        }
                        Info.Frames.Add(frame);
                    }
                }
                file.Close();
            }
            return(Info);
        }
Beispiel #2
0
        // Ładowanie/Zapisywanie animacji
        public void AnimationLoad(string filename)
        {
            ClearAllFrames();
            KAnimInfo info = KFile.LoadPSA(filename);

            AnimationName = info.Name;
            keys          = info.Frames;
            if (keys.Count > 0)
            {
                AnimationTotalTime = (keys.Count - 1) * StepTime;
                ActualFrame        = keys[0];
                if (FrameAmountChanged != null)
                {
                    FrameAmountChanged(this, EventArgs.Empty);
                }
                IsAnimationLoaded = true;
            }
        }