Example #1
0
 public AnimationCurveTpl(KeyframeTpl <T> keyframe1, KeyframeTpl <T> keyframe2) :
     this(false)
 {
     m_curve    = new KeyframeTpl <T> [2];
     m_curve[0] = keyframe1;
     m_curve[1] = keyframe2;
 }
Example #2
0
 public AnimationCurveTpl(T value1, T inSlope1, T outSlope1, T value2, T inSlope2, T outSlope2, T defaultWeight) :
     this(false)
 {
     m_curve    = new KeyframeTpl <T> [2];
     m_curve[0] = new KeyframeTpl <T>(0.0f, value1, inSlope1, outSlope1, defaultWeight);
     m_curve[1] = new KeyframeTpl <T>(1.0f, value2, inSlope2, outSlope2, defaultWeight);
 }
Example #3
0
 public AnimationCurveTpl(T defaultValue, T defaultWeight) :
     this(false)
 {
     m_curve    = new KeyframeTpl <T> [2];
     m_curve[0] = new KeyframeTpl <T>(0.0f, defaultValue, defaultWeight);
     m_curve[1] = new KeyframeTpl <T>(1.0f, defaultValue, defaultWeight);
 }
Example #4
0
        public static StreamedCurveKey CalculateStreamedFrame(AnimationCurveTpl <Float> curve, int lhsIndex, int rhsIndex, float timeOffset)
        {
            IReadOnlyList <KeyframeTpl <Float> > keyframes = curve.Curve;
            KeyframeTpl <Float> lhs = keyframes[lhsIndex];
            int curveKeyIndex       = lhsIndex;
            KeyframeTpl <Float> rhs = keyframes[rhsIndex];
            float frameTime         = lhs.Time + timeOffset;
            //TimeEnd = rhs.Time + timeOffset;
            float deltaTime = rhs.Time - lhs.Time;

            if (deltaTime < 0.00009999999747378752)
            {
                deltaTime = 0.000099999997f;
            }
            float deltaValue    = rhs.Value.Value - lhs.Value.Value;
            float inverseTime   = 1.0f / (deltaTime * deltaTime);
            float outTangent    = lhs.OutSlope.Value * deltaTime;
            float inTangent     = rhs.InSlope.Value * deltaTime;
            float curveKeyCoefX = (inTangent + outTangent - deltaValue - deltaValue) * inverseTime / deltaTime;
            float curveKeyCoefY = inverseTime * (deltaValue + deltaValue + deltaValue - outTangent - outTangent - inTangent);
            float curveKeyCoefZ = lhs.OutSlope.Value;
            float curveKeyValue = lhs.Value.Value;

            if (lhs.OutSlope.Value == float.PositiveInfinity || rhs.InSlope.Value == float.PositiveInfinity)
            {
                curveKeyCoefX = 0.0f;
                curveKeyCoefY = 0.0f;
                curveKeyCoefZ = 0.0f;
                curveKeyValue = lhs.Value.Value;
            }
            Vector3f         curveKeyCoef = new Vector3f(curveKeyCoefX, curveKeyCoefY, curveKeyCoefZ);
            StreamedCurveKey curveKey     = new StreamedCurveKey(curveKeyIndex, curveKeyValue, curveKeyCoef);

            return(curveKey);
        }
Example #5
0
 public AnimationCurveTpl(IReadOnlyList <KeyframeTpl <T> > keyframes) :
     this(false)
 {
     m_curve = new KeyframeTpl <T> [keyframes.Count];
     for (int i = 0; i < keyframes.Count; i++)
     {
         m_curve[i] = keyframes[i];
     }
 }
Example #6
0
 public AnimationCurveTpl(IReadOnlyList <KeyframeTpl <T> > keyframes, CurveLoopTypes preInfinity, CurveLoopTypes postInfinity)
 {
     PreInfinity   = preInfinity;
     PostInfinity  = postInfinity;
     RotationOrder = RotationOrder.OrderZXY;
     m_curve       = new KeyframeTpl <T> [keyframes.Count];
     for (int i = 0; i < keyframes.Count; i++)
     {
         m_curve[i] = keyframes[i];
     }
 }
        private void AddFloatKeyframe(FloatCurve curve, float time, float value)
        {
            if (!m_floats.TryGetValue(curve, out List <KeyframeTpl <Float> > floatCurve))
            {
                floatCurve = new List <KeyframeTpl <Float> >();
                m_floats.Add(curve, floatCurve);
            }

            KeyframeTpl <Float> floatKey = new KeyframeTpl <Float>(time, value, Float.DefaultWeight);

            floatCurve.Add(floatKey);
        }
        public QuaternionCurve Unpack()
        {
            int[]   timesValues = Times.Unpack();
            float[] times       = new float[timesValues.Length];
            for (int i = 0; i < times.Length; i++)
            {
                times[i] = timesValues[i] * 0.01f;
            }
            Quaternionf[] rotations = Values.Unpack();
            float[]       slopes    = Slopes.Unpack();

            KeyframeTpl <Quaternionf>[] keyframes = new KeyframeTpl <Quaternionf> [rotations.Length];
            for (int i = 0, j = 4; i < rotations.Length; i++, j += 4)
            {
                float       time     = times[i];
                Quaternionf rotation = rotations[i];
                Quaternionf inSlope  = new Quaternionf(slopes[j - 4], slopes[j - 3], slopes[j - 2], slopes[j - 1]);
                Quaternionf outSlope = new Quaternionf(slopes[j + 0], slopes[j + 1], slopes[j + 2], slopes[j + 3]);
                keyframes[i] = new KeyframeTpl <Quaternionf>(time, rotation, inSlope, outSlope, KeyframeTpl <Quaternionf> .DefaultQuaternionWeight);
            }
            AnimationCurveTpl <Quaternionf> curve = new AnimationCurveTpl <Quaternionf>(keyframes, PreInfinity, PostInfinity);

            return(new QuaternionCurve(Path, curve));
        }
        private void AddTransformCurve(float time, TransformType transType, IReadOnlyList <float> curveValues,
                                       IReadOnlyList <float> inSlopeValues, IReadOnlyList <float> outSlopeValues, int offset, string path)
        {
            switch (transType)
            {
            case TransformType.Translation:
            {
                Vector3Curve curve = new Vector3Curve(path);
                if (!m_translations.TryGetValue(curve, out List <KeyframeTpl <Vector3f> > transCurve))
                {
                    transCurve = new List <KeyframeTpl <Vector3f> >();
                    m_translations.Add(curve, transCurve);
                }

                float x = curveValues[offset + 0];
                float y = curveValues[offset + 1];
                float z = curveValues[offset + 2];

                float inX = inSlopeValues[0];
                float inY = inSlopeValues[1];
                float inZ = inSlopeValues[2];

                float outX = outSlopeValues[0];
                float outY = outSlopeValues[1];
                float outZ = outSlopeValues[2];

                Vector3f value    = new Vector3f(x, y, z);
                Vector3f inSlope  = new Vector3f(inX, inY, inZ);
                Vector3f outSlope = new Vector3f(outX, outY, outZ);
                KeyframeTpl <Vector3f> transKey = new KeyframeTpl <Vector3f>(time, value, inSlope, outSlope, Vector3f.DefaultWeight);
                transCurve.Add(transKey);
            }
            break;

            case TransformType.Rotation:
            {
                QuaternionCurve curve = new QuaternionCurve(path);
                if (!m_rotations.TryGetValue(curve, out List <KeyframeTpl <Quaternionf> > rotCurve))
                {
                    rotCurve = new List <KeyframeTpl <Quaternionf> >();
                    m_rotations.Add(curve, rotCurve);
                }

                float x = curveValues[offset + 0];
                float y = curveValues[offset + 1];
                float z = curveValues[offset + 2];
                float w = curveValues[offset + 3];

                float inX = inSlopeValues[0];
                float inY = inSlopeValues[1];
                float inZ = inSlopeValues[2];
                float inW = inSlopeValues[3];

                float outX = outSlopeValues[0];
                float outY = outSlopeValues[1];
                float outZ = outSlopeValues[2];
                float outW = outSlopeValues[3];

                Quaternionf value                = new Quaternionf(x, y, z, w);
                Quaternionf inSlope              = new Quaternionf(inX, inY, inZ, inW);
                Quaternionf outSlope             = new Quaternionf(outX, outY, outZ, outW);
                KeyframeTpl <Quaternionf> rotKey = new KeyframeTpl <Quaternionf>(time, value, inSlope, outSlope, Quaternionf.DefaultWeight);
                rotCurve.Add(rotKey);
            }
            break;

            case TransformType.Scaling:
            {
                Vector3Curve curve = new Vector3Curve(path);
                if (!m_scales.TryGetValue(curve, out List <KeyframeTpl <Vector3f> > scaleCurve))
                {
                    scaleCurve = new List <KeyframeTpl <Vector3f> >();
                    m_scales.Add(curve, scaleCurve);
                }

                float x = curveValues[offset + 0];
                float y = curveValues[offset + 1];
                float z = curveValues[offset + 2];

                float inX = inSlopeValues[0];
                float inY = inSlopeValues[1];
                float inZ = inSlopeValues[2];

                float outX = outSlopeValues[0];
                float outY = outSlopeValues[1];
                float outZ = outSlopeValues[2];

                Vector3f value    = new Vector3f(x, y, z);
                Vector3f inSlope  = new Vector3f(inX, inY, inZ);
                Vector3f outSlope = new Vector3f(outX, outY, outZ);
                KeyframeTpl <Vector3f> scaleKey = new KeyframeTpl <Vector3f>(time, value, inSlope, outSlope, Vector3f.DefaultWeight);
                scaleCurve.Add(scaleKey);
            }
            break;

            case TransformType.EulerRotation:
            {
                Vector3Curve curve = new Vector3Curve(path);
                if (!m_eulers.TryGetValue(curve, out List <KeyframeTpl <Vector3f> > eulerCurve))
                {
                    eulerCurve = new List <KeyframeTpl <Vector3f> >();
                    m_eulers.Add(curve, eulerCurve);
                }

                float x = curveValues[offset + 0];
                float y = curveValues[offset + 1];
                float z = curveValues[offset + 2];

                float inX = inSlopeValues[0];
                float inY = inSlopeValues[1];
                float inZ = inSlopeValues[2];

                float outX = outSlopeValues[0];
                float outY = outSlopeValues[1];
                float outZ = outSlopeValues[2];

                Vector3f value    = new Vector3f(x, y, z);
                Vector3f inSlope  = new Vector3f(inX, inY, inZ);
                Vector3f outSlope = new Vector3f(outX, outY, outZ);
                KeyframeTpl <Vector3f> eulerKey = new KeyframeTpl <Vector3f>(time, value, inSlope, outSlope, Vector3f.DefaultWeight);
                eulerCurve.Add(eulerKey);
            }
            break;

            default:
                throw new NotImplementedException(transType.ToString());
            }
        }
        private void AddComplexCurve(float time, BindingType bindType, IReadOnlyList <float> curveValues,
                                     IReadOnlyList <float> inSlopeValues, IReadOnlyList <float> outSlopeValues, int offset, string path)
        {
            switch (bindType)
            {
            case BindingType.Translation:
            {
                if (!m_translations.TryGetValue(path, out List <KeyframeTpl <Vector3f> > transCurve))
                {
                    transCurve = new List <KeyframeTpl <Vector3f> >();
                    m_translations.Add(path, transCurve);
                }

                float x = curveValues[offset + 0];
                float y = curveValues[offset + 1];
                float z = curveValues[offset + 2];

                float inX = inSlopeValues[0];
                float inY = inSlopeValues[1];
                float inZ = inSlopeValues[2];

                float outX = outSlopeValues[0];
                float outY = outSlopeValues[1];
                float outZ = outSlopeValues[2];

                Vector3f value     = new Vector3f(x, y, z);
                Vector3f inSlope   = new Vector3f(inX, inY, inZ);
                Vector3f outSlope  = new Vector3f(outX, outY, outZ);
                Vector3f defWeight = new Vector3f(1.0f / 3.0f);
                KeyframeTpl <Vector3f> transKey = new KeyframeTpl <Vector3f>(time, value, inSlope, outSlope, defWeight);
                transCurve.Add(transKey);
                m_translations[path] = transCurve;
            }
            break;

            case BindingType.Rotation:
            {
                if (!m_rotations.TryGetValue(path, out List <KeyframeTpl <Quaternionf> > rotCurve))
                {
                    rotCurve = new List <KeyframeTpl <Quaternionf> >();
                    m_rotations.Add(path, rotCurve);
                }

                float x = curveValues[offset + 0];
                float y = curveValues[offset + 1];
                float z = curveValues[offset + 2];
                float w = curveValues[offset + 3];

                float inX = 0;                                //inSlopeValues[0];
                float inY = 0;                                //inSlopeValues[1];
                float inZ = 0;                                //inSlopeValues[2];
                float inW = 0;                                //inSlopeValues[3];

                float outX = 0;                               //outSlopeValues[0];
                float outY = 0;                               //outSlopeValues[1];
                float outZ = 0;                               //outSlopeValues[2];
                float outW = 0;                               //outSlopeValues[3];

                Quaternionf value                = new Quaternionf(x, y, z, w);
                Quaternionf inSlope              = new Quaternionf(inX, inY, inZ, inW);
                Quaternionf outSlope             = new Quaternionf(outX, outY, outZ, outW);
                Quaternionf defWeight            = new Quaternionf(1.0f / 3.0f);
                KeyframeTpl <Quaternionf> rotKey = new KeyframeTpl <Quaternionf>(time, value, inSlope, outSlope, defWeight);
                rotCurve.Add(rotKey);
                m_rotations[path] = rotCurve;
            }
            break;

            case BindingType.Scaling:
            {
                if (!m_scales.TryGetValue(path, out List <KeyframeTpl <Vector3f> > scaleCurve))
                {
                    scaleCurve = new List <KeyframeTpl <Vector3f> >();
                    m_scales.Add(path, scaleCurve);
                }

                float x = curveValues[offset + 0];
                float y = curveValues[offset + 1];
                float z = curveValues[offset + 2];

                float inX = inSlopeValues[0];
                float inY = inSlopeValues[1];
                float inZ = inSlopeValues[2];

                float outX = outSlopeValues[0];
                float outY = outSlopeValues[1];
                float outZ = outSlopeValues[2];

                Vector3f value     = new Vector3f(x, y, z);
                Vector3f inSlope   = new Vector3f(inX, inY, inZ);
                Vector3f outSlope  = new Vector3f(outX, outY, outZ);
                Vector3f defWeight = new Vector3f(1.0f / 3.0f);
                KeyframeTpl <Vector3f> scaleKey = new KeyframeTpl <Vector3f>(time, value, inSlope, outSlope, defWeight);
                scaleCurve.Add(scaleKey);
                m_scales[path] = scaleCurve;
            }
            break;

            case BindingType.EulerRotation:
            {
                if (!m_eulers.TryGetValue(path, out List <KeyframeTpl <Vector3f> > eulerCurve))
                {
                    eulerCurve = new List <KeyframeTpl <Vector3f> >();
                    m_eulers.Add(path, eulerCurve);
                }

                float x = curveValues[offset + 0];
                float y = curveValues[offset + 1];
                float z = curveValues[offset + 2];

                float inX = inSlopeValues[0];
                float inY = inSlopeValues[1];
                float inZ = inSlopeValues[2];

                float outX = outSlopeValues[0];
                float outY = outSlopeValues[1];
                float outZ = outSlopeValues[2];

                Vector3f value     = new Vector3f(x, y, z);
                Vector3f inSlope   = new Vector3f(inX, inY, inZ);
                Vector3f outSlope  = new Vector3f(outX, outY, outZ);
                Vector3f defWeight = new Vector3f(1.0f / 3.0f);
                KeyframeTpl <Vector3f> eulerKey = new KeyframeTpl <Vector3f>(time, value, inSlope, outSlope, defWeight);
                eulerCurve.Add(eulerKey);
                m_eulers[path] = eulerCurve;
            }
            break;

            case BindingType.Floats:
            {
                if (!m_floats.TryGetValue(path, out List <KeyframeTpl <Float> > floatCurve))
                {
                    floatCurve = new List <KeyframeTpl <Float> >();
                    m_floats.Add(path, floatCurve);
                }

                float x    = curveValues[offset];
                float inX  = inSlopeValues[0];
                float outX = outSlopeValues[0];

                Float value     = new Float(x);
                Float inSlope   = new Float(inX);
                Float outSlope  = new Float(outX);
                Float defWeight = new Float(1.0f / 3.0f);
                KeyframeTpl <Float> floatKey = new KeyframeTpl <Float>(time, value, inSlope, outSlope, defWeight);
                floatCurve.Add(floatKey);
                m_floats[path] = floatCurve;
            }
            break;

            default:
                throw new NotImplementedException(bindType.ToString());
            }
        }
Example #11
0
 public AnimationCurveTpl(KeyframeTpl <T> keyframe) :
     this(false)
 {
     m_curve    = new KeyframeTpl <T> [1];
     m_curve[0] = keyframe;
 }