Exemple #1
0
        public static ValueTimeCurveInterpolator Read(BinaryReader reader, KeyFrame.InterpolationTypes type)
        {
            ValueTimeCurveInterpolator vtci = new ValueTimeCurveInterpolator();

            switch (type)
            {
            case KeyFrame.InterpolationTypes.Mirrored:
            case KeyFrame.InterpolationTypes.Asymmetric:
            case KeyFrame.InterpolationTypes.Disconnected:
                vtci.m_InFactor  = reader.ReadDouble();
                vtci.m_InValue   = reader.ReadSingle();
                vtci.m_OutFactor = reader.ReadDouble();
                vtci.m_OutValue  = reader.ReadSingle();
                return(vtci);

            case KeyFrame.InterpolationTypes.Hold:
                vtci.m_InFactor  = reader.ReadDouble();
                vtci.m_InValue   = reader.ReadSingle();
                vtci.m_OutFactor = 0.0f;
                vtci.m_OutValue  = 0.0f;
                return(vtci);
            }

            return(null);
        }
Exemple #2
0
        public static bool Read(BinaryReader reader, KeyFrameWithInterpolation frame)
        {
            if (!KeyFrame.Read(reader, frame))
            {
                return(false);
            }
            int type = reader.ReadByte();

            if (!Enum.IsDefined(typeof(InterpolationTypes), type))
            {
                return(false);
            }

            frame.m_InterpolationType = (InterpolationTypes)type;
            switch (frame.m_InterpolationType)
            {
            case KeyFrame.InterpolationTypes.Mirrored:
            case KeyFrame.InterpolationTypes.Asymmetric:
            case KeyFrame.InterpolationTypes.Disconnected:
            case KeyFrame.InterpolationTypes.Hold:
                frame.m_Interpolator = ValueTimeCurveInterpolator.Read(reader, frame.m_InterpolationType);
                break;

            default:
                frame.m_Interpolator = null;
                break;
            }
            return(true);
        }
Exemple #3
0
        public override void ApplyInterpolation(ActorComponent component, float time, KeyFrame toFrame, float mix)
        {
            switch (m_InterpolationType)
            {
            case KeyFrame.InterpolationTypes.Mirrored:
            case KeyFrame.InterpolationTypes.Asymmetric:
            case KeyFrame.InterpolationTypes.Disconnected:
            {
                ValueTimeCurveInterpolator interpolator = m_Interpolator as ValueTimeCurveInterpolator;
                if (interpolator != null)
                {
                    float v = (float)interpolator.Get((double)time);
                    SetValue(component, v, mix);
                }
                break;
            }

            case KeyFrame.InterpolationTypes.Hold:
            {
                SetValue(component, m_Value, mix);
                break;
            }

            case KeyFrame.InterpolationTypes.Linear:
            {
                KeyFrameInt to = toFrame as KeyFrameInt;

                float f = (time - m_Time) / (to.m_Time - m_Time);
                SetValue(component, m_Value * (1.0f - f) + to.m_Value * f, mix);
                break;
            }
            }
        }
Exemple #4
0
        public override bool SetNextFrame(KeyFrameWithInterpolation frame, KeyFrame nextFrame)
        {
            // This frame is a hold, return false to remove the interpolator.
            // We store it in the first place as when it gets called as the nextFrame parameter (in a previous call)
            // we still read out the in factor and in value (see below where nextInValue and nextInFactor are defined).
            if (frame.InterpolationType == KeyFrame.InterpolationTypes.Hold)
            {
                return(false);
            }

            // Just a sanity check really, both keyframes need to be numeric.
            KeyFrameNumeric ourFrame = frame as KeyFrameNumeric;
            KeyFrameNumeric next     = nextFrame as KeyFrameNumeric;

            if (ourFrame == null || next == null)
            {
                return(false);
            }

            // We are not gauranteed to have a next interpolator (usually when the next keyframe is linear).
            ValueTimeCurveInterpolator nextInterpolator = null;

            float timeRange = next.Time - ourFrame.Time;
            float outTime   = (float)(ourFrame.Time + timeRange * m_OutFactor);

            float  nextInValue  = 0.0f;
            double nextInFactor = 0.0f;

            // Get the invalue and infactor from the next interpolator (this is where hold keyframes get their interpolator values processed too).
            if ((nextInterpolator = next.Interpolator as ValueTimeCurveInterpolator) != null)
            {
                nextInValue  = nextInterpolator.m_InValue;
                nextInFactor = nextInterpolator.m_InFactor;
                //this._Curve = new BezierAnimationCurve([this._Time, this._Value], [outTime, this._OutValue], [inTime, nxt._InValue], [nxt._Time, nxt._Value]);
            }
            else
            {
                // Happens when next is linear.
                nextInValue = next.Value;
            }

            float inTime = (float)(next.Time - timeRange * nextInFactor);

            // Finally we can generate the curve.
            InitializeCurve(ourFrame.Time, ourFrame.Value, outTime, m_OutValue, inTime, nextInValue, next.Time, next.Value);
            //this._Curve = new BezierAnimationCurve([ourFrame.Time, ourFrame.Value], [outTime, m_OutValue], [inTime, nextInValue], [next.Time, next.Value]);
            return(true);
        }