Example #1
0
        public void CreateInputUpdateAction(IInputSlot inputSlot)
        {
            if (inputSlot is Slot <float> floatInputSlot)
            {
                var newCurve = new Curve();
                newCurve.AddOrUpdateV(Playback.Current.TimeInBars, new VDefinition()
                {
                    Value   = floatInputSlot.Value,
                    InType  = VDefinition.Interpolation.Spline,
                    OutType = VDefinition.Interpolation.Spline,
                });
                _animatedInputCurves.Add(new CurveId(inputSlot), newCurve);

                floatInputSlot.UpdateAction       = context => { floatInputSlot.Value = (float)newCurve.GetSampledValue(context.LocalTime); };
                floatInputSlot.DirtyFlag.Trigger |= DirtyFlagTrigger.Animated;
            }
            else if (inputSlot is Slot <Vector2> vector2InputSlot)
            {
                var newCurveX = new Curve();
                newCurveX.AddOrUpdateV(Playback.Current.TimeInBars, new VDefinition()
                {
                    Value   = vector2InputSlot.Value.X,
                    InType  = VDefinition.Interpolation.Spline,
                    OutType = VDefinition.Interpolation.Spline,
                });
                _animatedInputCurves.Add(new CurveId(inputSlot, 0), newCurveX);

                var newCurveY = new Curve();
                newCurveY.AddOrUpdateV(Playback.Current.TimeInBars, new VDefinition()
                {
                    Value   = vector2InputSlot.Value.Y,
                    InType  = VDefinition.Interpolation.Spline,
                    OutType = VDefinition.Interpolation.Spline,
                });
                _animatedInputCurves.Add(new CurveId(inputSlot, 1), newCurveY);

                vector2InputSlot.UpdateAction = context =>
                {
                    vector2InputSlot.Value.X = (float)newCurveX.GetSampledValue(context.LocalTime);
                    vector2InputSlot.Value.Y = (float)newCurveY.GetSampledValue(context.LocalTime);
                };
                vector2InputSlot.DirtyFlag.Trigger |= DirtyFlagTrigger.Animated;
            }
            else if (inputSlot is Slot <Vector3> vector3InputSlot)
            {
                var newCurveX = new Curve();
                newCurveX.AddOrUpdateV(Playback.Current.TimeInBars, new VDefinition()
                {
                    Value   = vector3InputSlot.Value.X,
                    InType  = VDefinition.Interpolation.Spline,
                    OutType = VDefinition.Interpolation.Spline,
                });
                _animatedInputCurves.Add(new CurveId(inputSlot, 0), newCurveX);

                var newCurveY = new Curve();
                newCurveY.AddOrUpdateV(Playback.Current.TimeInBars, new VDefinition()
                {
                    Value   = vector3InputSlot.Value.Y,
                    InType  = VDefinition.Interpolation.Spline,
                    OutType = VDefinition.Interpolation.Spline,
                });
                _animatedInputCurves.Add(new CurveId(inputSlot, 1), newCurveY);

                var newCurveZ = new Curve();
                newCurveZ.AddOrUpdateV(Playback.Current.TimeInBars, new VDefinition()
                {
                    Value   = vector3InputSlot.Value.Z,
                    InType  = VDefinition.Interpolation.Spline,
                    OutType = VDefinition.Interpolation.Spline,
                });
                _animatedInputCurves.Add(new CurveId(inputSlot, 2), newCurveZ);

                vector3InputSlot.UpdateAction = context =>
                {
                    vector3InputSlot.Value.X = (float)newCurveX.GetSampledValue(context.LocalTime);
                    vector3InputSlot.Value.Y = (float)newCurveY.GetSampledValue(context.LocalTime);
                    vector3InputSlot.Value.Z = (float)newCurveZ.GetSampledValue(context.LocalTime);
                };
                vector3InputSlot.DirtyFlag.Trigger |= DirtyFlagTrigger.Animated;
            }
            else if (inputSlot is Slot <Vector4> vector4InputSlot)
            {
                var newCurveX = new Curve();
                newCurveX.AddOrUpdateV(Playback.Current.TimeInBars, new VDefinition()
                {
                    Value   = vector4InputSlot.Value.X,
                    InType  = VDefinition.Interpolation.Spline,
                    OutType = VDefinition.Interpolation.Spline,
                });
                _animatedInputCurves.Add(new CurveId(inputSlot, 0), newCurveX);

                var newCurveY = new Curve();
                newCurveY.AddOrUpdateV(Playback.Current.TimeInBars, new VDefinition()
                {
                    Value   = vector4InputSlot.Value.Y,
                    InType  = VDefinition.Interpolation.Spline,
                    OutType = VDefinition.Interpolation.Spline,
                });
                _animatedInputCurves.Add(new CurveId(inputSlot, 1), newCurveY);

                var newCurveZ = new Curve();
                newCurveZ.AddOrUpdateV(Playback.Current.TimeInBars, new VDefinition()
                {
                    Value   = vector4InputSlot.Value.Z,
                    InType  = VDefinition.Interpolation.Spline,
                    OutType = VDefinition.Interpolation.Spline,
                });
                _animatedInputCurves.Add(new CurveId(inputSlot, 2), newCurveZ);

                var newCurveW = new Curve();
                newCurveW.AddOrUpdateV(Playback.Current.TimeInBars, new VDefinition()
                {
                    Value   = vector4InputSlot.Value.W,
                    InType  = VDefinition.Interpolation.Spline,
                    OutType = VDefinition.Interpolation.Spline,
                });
                _animatedInputCurves.Add(new CurveId(inputSlot, 3), newCurveW);

                vector4InputSlot.UpdateAction = context =>
                {
                    vector4InputSlot.Value.X = (float)newCurveX.GetSampledValue(context.LocalTime);
                    vector4InputSlot.Value.Y = (float)newCurveY.GetSampledValue(context.LocalTime);
                    vector4InputSlot.Value.Z = (float)newCurveZ.GetSampledValue(context.LocalTime);
                    vector4InputSlot.Value.W = (float)newCurveW.GetSampledValue(context.LocalTime);
                };
                vector4InputSlot.DirtyFlag.Trigger |= DirtyFlagTrigger.Animated;
            }
            else if (inputSlot is Slot <int> intInputSlot)
            {
                var newCurve = new Curve();
                newCurve.AddOrUpdateV(Playback.Current.TimeInBars, new VDefinition()
                {
                    Value       = intInputSlot.Value,
                    InType      = VDefinition.Interpolation.Constant,
                    OutType     = VDefinition.Interpolation.Constant,
                    InEditMode  = VDefinition.EditMode.Constant,
                    OutEditMode = VDefinition.EditMode.Constant,
                });
                _animatedInputCurves.Add(new CurveId(inputSlot), newCurve);

                intInputSlot.UpdateAction       = context => { intInputSlot.Value = (int)newCurve.GetSampledValue(context.LocalTime); };
                intInputSlot.DirtyFlag.Trigger |= DirtyFlagTrigger.Animated;
            }
            else if (inputSlot is Slot <Size2> size2InputSlot)
            {
                var newCurveX = new Curve();
                newCurveX.AddOrUpdateV(Playback.Current.TimeInBars, new VDefinition()
                {
                    Value       = size2InputSlot.Value.Width,
                    InType      = VDefinition.Interpolation.Constant,
                    OutType     = VDefinition.Interpolation.Constant,
                    InEditMode  = VDefinition.EditMode.Constant,
                    OutEditMode = VDefinition.EditMode.Constant,
                });
                _animatedInputCurves.Add(new CurveId(inputSlot, 0), newCurveX);

                var newCurveY = new Curve();
                newCurveY.AddOrUpdateV(Playback.Current.TimeInBars, new VDefinition()
                {
                    Value       = size2InputSlot.Value.Height,
                    InType      = VDefinition.Interpolation.Constant,
                    OutType     = VDefinition.Interpolation.Constant,
                    InEditMode  = VDefinition.EditMode.Constant,
                    OutEditMode = VDefinition.EditMode.Constant,
                });
                _animatedInputCurves.Add(new CurveId(inputSlot, 1), newCurveY);

                size2InputSlot.UpdateAction = context =>
                {
                    size2InputSlot.Value.Width  = (int)newCurveX.GetSampledValue(context.LocalTime);
                    size2InputSlot.Value.Height = (int)newCurveY.GetSampledValue(context.LocalTime);
                };
                size2InputSlot.DirtyFlag.Trigger |= DirtyFlagTrigger.Animated;
            }
            else if (inputSlot is Slot <bool> boolInputSlot)
            {
                var newCurve = new Curve();
                newCurve.AddOrUpdateV(Playback.Current.TimeInBars, new VDefinition()
                {
                    Value       = boolInputSlot.Value ? 1 :0,
                    InType      = VDefinition.Interpolation.Constant,
                    OutType     = VDefinition.Interpolation.Constant,
                    InEditMode  = VDefinition.EditMode.Constant,
                    OutEditMode = VDefinition.EditMode.Constant,
                });
                _animatedInputCurves.Add(new CurveId(inputSlot), newCurve);

                boolInputSlot.UpdateAction       = context => { boolInputSlot.Value = newCurve.GetSampledValue(context.LocalTime) > 0.5f; };
                boolInputSlot.DirtyFlag.Trigger |= DirtyFlagTrigger.Animated;
            }
            else
            {
                Log.Error("Could not create update action.");
            }
        }