Esempio n. 1
0
        static AnimationFile.Frame SeekFrame(AnimationFile.Bone bone, float time, int mode = 0)
        {
            foreach (AnimationFile.Frame frame in bone.Frames)
            {
                if (frame.Delay > time)
                {
                    bool ok = false;
                    switch (mode)
                    {
                    case 1:
                        ok = frame.HasTransition;
                        break;

                    case 2:
                        ok = frame.HasScale;
                        break;


                    default:
                        ok = true;
                        break;
                    }
                    if (ok)
                    {
                        return(frame);
                    }
                }
            }
            return(null);
        }
Esempio n. 2
0
        static AnimationFile.Frame SeekFrameReverse(AnimationFile.Bone bone, float time, int mode = 0)
        {
            AnimationFile.Frame[] frames = (AnimationFile.Frame[])bone.Frames.Clone();
            Array.Reverse(frames);
            foreach (AnimationFile.Frame frame in frames)
            {
                if (frame.Delay <= time)
                {
                    bool ok = false;
                    switch (mode)
                    {
                    case 1:
                        ok = frame.HasTransition;
                        break;

                    case 2:
                        ok = frame.HasScale;
                        break;


                    default:
                        ok = true;
                        break;
                    }
                    if (ok)
                    {
                        return(frame);
                    }
                }
            }
            return(null);
        }
Esempio n. 3
0
        static void ApplyAnimationFrame(Model.Branch[] branches, AnimationFile.Animation animation, float time = 0)
        {
            foreach (Model.Branch b in branches)
            {
                AnimationFile.Bone boneDef = animation[b.Name];
                if (b.Parent != null)
                {
                    if (boneDef != null)
                    {
                        Vector3             transition = Vector3.Zero;
                        Quaternion          rotation = b.OriginalAngles;
                        float               scale = b.OriginalScale;
                        AnimationFile.Frame frameFrom, frameTo;
                        float               delta = 0;

                        frameFrom = SeekFrameReverse(boneDef, time, 0);
                        frameTo   = SeekFrame(boneDef, time, 0);
                        if (frameFrom != null && frameTo != null)
                        {
                            delta    = (time - frameFrom.Delay) / (frameTo.Delay - frameFrom.Delay);
                            rotation = Quaternion.Slerp(frameFrom.Rotation, frameTo.Rotation, delta);                            //Vector3.Lerp(frameFrom.Transition, frameTo.Transition, delta);
                        }

                        frameFrom = SeekFrameReverse(boneDef, time, 1);
                        frameTo   = SeekFrame(boneDef, time, 1);
                        if (frameFrom != null && frameTo != null)
                        {
                            delta      = (time - frameFrom.Delay) / (frameTo.Delay - frameFrom.Delay);
                            transition = Vector3.Lerp(frameFrom.Transition, frameTo.Transition, delta);
                        }
                        if (b.Name == "Root")
                        {
                            transition.Z = 0;
                        }


                        b.Position = b.OriginalPosition + transition;
                        b.Angles   = rotation;
                        b.Scale    = scale;
                    }
                }
                if (b.Children != null)
                {
                    ApplyAnimationFrame(b.Children, animation, time);
                }
            }
        }