Esempio n. 1
0
        public UICurves()
        {
            InitializeComponent();
            mode      = CurveMode.RGB;
            Points    = new Dictionary <int, List <CurvePoint> >();
            Points[0] = new List <CurvePoint>();
            Points[1] = new List <CurvePoint>();
            Points[2] = new List <CurvePoint>();
            Points[3] = new List <CurvePoint>();

            Normalized    = new Dictionary <int, List <MathHelpers.Point> >();
            Normalized[0] = new List <MathHelpers.Point>();
            Normalized[1] = new List <MathHelpers.Point>();
            Normalized[2] = new List <MathHelpers.Point>();
            Normalized[3] = new List <MathHelpers.Point>();

            inited = false;

            Input    = new Dictionary <int, List <MathHelpers.Point> >();
            Input[0] = new List <MathHelpers.Point>();
            Input[1] = new List <MathHelpers.Point>();
            Input[2] = new List <MathHelpers.Point>();
            Input[3] = new List <MathHelpers.Point>();

            ValueRange.Set(0, 1);
        }
Esempio n. 2
0
 public CurvePoint(float inVal, float outVal, float arriveTangent, float leaveTangent, CurveMode interpMode)
 {
     InVal = inVal;
     OutVal = outVal;
     ArriveTangent = arriveTangent;
     LeaveTangent = leaveTangent;
     InterpMode = interpMode;
 }
Esempio n. 3
0
 public CurvePoint(float inVal, float outVal, float arriveTangent, float leaveTangent, CurveMode interpMode)
 {
     InVal         = inVal;
     OutVal        = outVal;
     ArriveTangent = arriveTangent;
     LeaveTangent  = leaveTangent;
     InterpMode    = interpMode;
 }
Esempio n. 4
0
 public ImmutableEdge(uint a, uint b, CurveMode mode, IReadOnlyList <string> bones, Vector3?ctl0, Vector3?ctl1)
 {
     From     = a;
     To       = b;
     Mode     = mode;
     Bones    = bones != null ? new ReadOnlyList <string>(bones) : null;
     Control0 = ctl0;
     Control1 = ctl1;
 }
Esempio n. 5
0
        public void ResetValue()
        {
            Type       = TweenType.None;
            Identifier = "";

            FromFloat      = 0f;
            ToFloat        = 1f;
            FromVector2    = Vector2.zero;
            ToVector2      = Vector2.one;
            FromVector3    = Vector3.zero;
            ToVector3      = Vector3.one;
            FromVector4    = Vector4.zero;
            ToVector4      = Vector4.one;
            FromColor      = Color.black;
            ToColor        = Color.white;
            FromQuaternion = Quaternion.identity;
            ToQuaternion   = Quaternion.identity;
            FromRect       = Rect.zero;
            ToRect         = Rect.zero;
            FromTransform  = null;
            ToTransform    = null;

            QueueVector3.Clear();
            QueueColor.Clear();

            CurveMode   = CurveMode.Single;
            CurveTarget = CurveTargetType.Factor;
            Curve       = TweenSetting.Ins.DefaultCurve;
            CurveX      = TweenSetting.Ins.DefaultCurve;
            CurveY      = TweenSetting.Ins.DefaultCurve;
            CurveZ      = TweenSetting.Ins.DefaultCurve;
            CurveW      = TweenSetting.Ins.DefaultCurve;

            PlayType   = PlayType.Once;
            EaseType   = TweenSetting.Ins.DefaultEaseType;
            LoopCount  = 0;
            Duration   = 1f;
            Interval   = 0f;
            SpeedBased = false;
            StartDelay = 0f;
            AutoPlay   = TweenSetting.Ins.DefaultAutoPlayType;
            UpdateType = TweenSetting.Ins.DefaultUpdateType;
            TimeScale  = TweenSetting.Ins.DefaultTimeScale;
            TimeSmooth = TweenSetting.Ins.DefaultTimeSmooth;
            SelfScale  = 1f;
            AutoKill   = false;

            WorldSpace     = true;
            ColorLerpMode  = ColorLerpMode.RGB;
            ColorBlockType = ColorBlockType.NormalColor;
            PathMode       = PathMode.PointToPoint;
            ShakeArgs      = new TweenShakeArgs();

            ResourcesIndex = 0;
            ResourcesKey   = "";
        }
Esempio n. 6
0
        public UICurves(PropertyInfo p, object owner)
        {
            InitializeComponent();
            mode          = CurveMode.RGB;
            property      = p;
            propertyOwner = owner;

            try
            {
                minProperty = propertyOwner.GetType().GetProperty("MinValue");
            }
            catch { }

            try
            {
                maxProperty = propertyOwner.GetType().GetProperty("MaxValue");
            }
            catch { }

            Normalized    = new Dictionary <int, List <MathHelpers.Point> >();
            Normalized[0] = new List <MathHelpers.Point>();
            Normalized[1] = new List <MathHelpers.Point>();
            Normalized[2] = new List <MathHelpers.Point>();
            Normalized[3] = new List <MathHelpers.Point>();

            Points    = new Dictionary <int, List <CurvePoint> >();
            Points[0] = new List <CurvePoint>();
            Points[1] = new List <CurvePoint>();
            Points[2] = new List <CurvePoint>();
            Points[3] = new List <CurvePoint>();

            inited = false;

            Input = (Dictionary <int, List <MathHelpers.Point> >)p.GetValue(owner);

            Sort(Input[0]);
            Sort(Input[1]);
            Sort(Input[2]);
            Sort(Input[3]);

            float min = 0;
            float max = 1;

            if (minProperty != null)
            {
                min = Convert.ToSingle(minProperty.GetValue(propertyOwner));
            }
            if (maxProperty != null)
            {
                max = Convert.ToSingle(maxProperty.GetValue(propertyOwner));
            }

            ValueRange.Set(min, max);
        }
Esempio n. 7
0
        void ShowPoints(CurveMode m)
        {
            int idx = (int)m;

            var pts = Points[idx];

            foreach (CurvePoint p in pts)
            {
                CurveView.Children.Add(p);
            }
        }
Esempio n. 8
0
        void HidePoints(CurveMode m)
        {
            int idx = (int)m;

            var pts = Points[idx];

            foreach (CurvePoint p in pts)
            {
                CurveView.Children.Remove(p);
            }
        }
Esempio n. 9
0
        private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            CurveMode prev = mode;

            HidePoints(prev);

            mode = (CurveMode)Channels.SelectedIndex;

            ShowPoints(mode);

            UpdatePath();
        }
Esempio n. 10
0
        internal Edge(BendyComponent owner, Node from, Node to, CurveMode mode, Vector3?ctl0 = null, Vector3?ctl1 = null)
        {
            Owner = owner;
            Graph = from.Graph;
            From  = from;
            To    = to;
            Mode  = mode;
            _ctl0 = ctl0;
            _ctl1 = ctl1;

            EnsureInScene();
        }
Esempio n. 11
0
        private void PathBetween(Anchor a1, Anchor a2, CurveMode interpMode = CurveMode.CIM_Linear)
        {
            Line          line;
            BezierSegment bez;

            switch (interpMode)
            {
            case CurveMode.CIM_Linear:
                line = new Line();
                line.bind(Line.X1Property, a1, "X");
                line.bind(Line.Y1Property, a1, "Y", new YConverter(), ActualHeight);
                line.bind(Line.X2Property, a2, "X");
                line.bind(Line.Y2Property, a2, "Y", new YConverter(), ActualHeight);
                graph.Children.Add(line);
                break;

            case CurveMode.CIM_Constant:
                line = new Line();
                line.bind(Line.X1Property, a1, "X");
                line.bind(Line.Y1Property, a1, "Y", new YConverter(), ActualHeight);
                line.bind(Line.X2Property, a2, "X");
                line.bind(Line.Y2Property, a1, "Y", new YConverter(), ActualHeight);
                graph.Children.Add(line);
                line = new Line();
                line.bind(Line.X1Property, a2, "X");
                line.bind(Line.Y1Property, a1, "Y", new YConverter(), ActualHeight);
                line.bind(Line.X2Property, a2, "X");
                line.bind(Line.Y2Property, a2, "Y", new YConverter(), ActualHeight);
                graph.Children.Add(line);
                break;

            case CurveMode.CIM_CurveAuto:
            case CurveMode.CIM_CurveUser:
            case CurveMode.CIM_CurveBreak:
            case CurveMode.CIM_CurveAutoClamped:
                bez        = new BezierSegment(this);
                bez.Slope1 = a1.point.Value.LeaveTangent;
                bez.Slope2 = a2.point.Value.ArriveTangent;
                bez.bind(BezierSegment.X1Property, a1, "X");
                bez.bind(BezierSegment.Y1Property, a1, "Y");
                bez.bind(BezierSegment.X2Property, a2, "X");
                bez.bind(BezierSegment.Y2Property, a2, "Y");
                graph.Children.Add(bez);
                a1.rightBez = bez;
                a2.leftBez  = bez;
                break;

            default:
                break;
            }
        }
Esempio n. 12
0
        private byte MapJoystickPosInRange(int joystickValue, CurveMode curveMode, byte rangeMin, byte rangeMax, int offset, bool reverse = false)
        {
            byte mappedValue = (byte)ChannelCurves.DoChannelCurve(
                joystickValue, Joystick.JOYSTICK_MAXVALUE, curveMode, rangeMin, rangeMax);

            //byte mappedValue = (byte)(((float)(joystickValue * (rangeMax - rangeMin)) / ) + rangeMin);

            mappedValue = (byte)(mappedValue + offset);
            if (reverse)
            {
                mappedValue = (byte)(rangeMax - (mappedValue - rangeMin));
            }
            return(mappedValue);
        }
    public void EnforceMode(int index)
    {
        int       modeIndex = (index + 1) / 3;
        CurveMode mode      = modes[modeIndex];

        if (mode == CurveMode.Free || !loop && (modeIndex == 0 || modeIndex == modes.Count - 1))
        {
            return;
        }

        int middleIndex = modeIndex * 3;
        int fixedIndex, enforcedIndex;

        if (index <= middleIndex)
        {
            fixedIndex = middleIndex - 1;
            if (fixedIndex < 0)
            {
                fixedIndex = PointCount - 2;
            }
            enforcedIndex = middleIndex + 1;
            if (enforcedIndex >= PointCount)
            {
                enforcedIndex = 1;
            }
        }
        else
        {
            fixedIndex = middleIndex + 1;
            if (fixedIndex >= PointCount)
            {
                fixedIndex = 1;
            }
            enforcedIndex = middleIndex - 1;
            if (enforcedIndex < 0)
            {
                enforcedIndex = PointCount - 2;
            }
        }

        Vector3 middle  = points[middleIndex];
        Vector3 tangent = middle - points[fixedIndex];

        if (mode == CurveMode.Align)
        {
            tangent = tangent.normalized * Vector3.Distance(middle, points[enforcedIndex]);
        }
        points[enforcedIndex] = points[middleIndex] + tangent;
    }
Esempio n. 14
0
    public Vector3[] GenerateCurve(CurveMode mode)
    {
        switch (mode)
        {
        case CurveMode.LINEAR:
            return(GenerateLinearCurve());

        case CurveMode.QUADRATIC:
            return(GenerateQuadraticCurve());

        case CurveMode.CUBIC:
            return(GenerateCubicCurve());
        }

        return(null);
    }
Esempio n. 15
0
 public CurvePoint(float _inVal, float _outVal, float _arriveTangent, float _leaveTangent)
 {
     InVal = _inVal;
     OutVal = _outVal;
     ArriveTangent = _arriveTangent;
     LeaveTangent = _leaveTangent;
     //accurate float comparison ( == )
     if (Math.Abs(_arriveTangent - _leaveTangent) < float.Epsilon)
     {
         interpMode = CurveMode.CIM_CurveUser;
     }
     else
     {
         interpMode = CurveMode.CIM_CurveBreak;
     }
 }
Esempio n. 16
0
 public CurvePoint(float _inVal, float _outVal, float _arriveTangent, float _leaveTangent)
 {
     InVal         = _inVal;
     OutVal        = _outVal;
     ArriveTangent = _arriveTangent;
     LeaveTangent  = _leaveTangent;
     //accurate float comparison ( == )
     if (Math.Abs(_arriveTangent - _leaveTangent) < float.Epsilon)
     {
         interpMode = CurveMode.CIM_CurveUser;
     }
     else
     {
         interpMode = CurveMode.CIM_CurveBreak;
     }
 }
Esempio n. 17
0
 public SketchCurvePoint(
     SketchPoint point,
     SketchPoint curveFrom,
     SketchPoint curveTo,
     double cornerRadius,
     CurveMode mode,
     bool hasCurveFrom,
     bool hasCurveTo)
 {
     Point        = point;
     CurveFrom    = curveFrom;
     CurveTo      = curveTo;
     CornerRadius = cornerRadius;
     Mode         = mode;
     HasCurveFrom = hasCurveFrom;
     HasCurveTo   = hasCurveTo;
 }
Esempio n. 18
0
        public void CopyFrom(TweenParam param)
        {
            Type       = param.Type;
            Identifier = param.Identifier;

            CopyFromToValueFrom(param);

            CurveMode   = param.CurveMode;
            CurveTarget = param.CurveTarget;
            Curve       = param.Curve;
            CurveX      = param.CurveX;
            CurveY      = param.CurveY;
            CurveZ      = param.CurveZ;
            CurveW      = param.CurveW;

            PlayType   = param.PlayType;
            EaseType   = param.EaseType;
            LoopCount  = param.LoopCount;
            Duration   = param.Duration;
            Interval   = param.Interval;
            SpeedBased = param.SpeedBased;
            StartDelay = param.StartDelay;
            AutoPlay   = param.AutoPlay;
            UpdateType = param.UpdateType;
            TimeScale  = param.TimeScale;
            TimeSmooth = param.TimeSmooth;
            SelfScale  = param.SelfScale;
            AutoKill   = param.AutoKill;

            WorldSpace     = param.WorldSpace;
            ColorLerpMode  = param.ColorLerpMode;
            ColorBlockType = param.ColorBlockType;
            PathMode       = param.PathMode;
            ShakeArgs      = param.ShakeArgs;

            ResourcesIndex = param.ResourcesIndex;
            ResourcesKey   = param.ResourcesKey;

            OnPlay         = param.OnPlay;
            OnStop         = param.OnStop;
            OnValueFloat   = param.OnValueFloat;
            OnValueVector2 = param.OnValueVector2;
            OnValueVector3 = param.OnValueVector3;
            OnValueColor   = param.OnValueColor;
        }
    public void SetControlPointMode(int index, CurveMode m)
    {
        int modeIndex = (index + 1) / 3;

        modes[modeIndex] = m;
        // need to make sure if loop is on, the first and last point agrees on the mode
        if (loop)
        {
            if (modeIndex == 0)
            {
                modes[modes.Count - 1] = m;
            }
            else if (modeIndex == modes.Count - 1)
            {
                modes[0] = m;
            }
        }
        EnforceMode(index);
    }
Esempio n. 20
0
        public static Color GetTangentColor(this CurveMode curveMode)
        {
            switch (curveMode)
            {
            case CurveMode.Free:
                return(Color.green);

            case CurveMode.StraightLine:
                return(Color.red);

            case CurveMode.Aligned:
                return(Color.yellow);

            case CurveMode.Mirrored:
                return(Color.blue);

            default:
                throw new ArgumentOutOfRangeException(nameof(curveMode), curveMode, null);
            }
        }
Esempio n. 21
0
    private void DrawInspector()
    {
        GUILayout.Label("Selected point");

        EditorGUI.BeginChangeCheck();
        Vector3 p = EditorGUILayout.Vector3Field("Position", spline.GetControlPoint(selectedIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Move Point");
            EditorUtility.SetDirty(spline);
            spline.SetControlPoint(selectedIndex, handleTransform.InverseTransformPoint(p));
        }

        EditorGUI.BeginChangeCheck();
        CurveMode m = (CurveMode)EditorGUILayout.EnumPopup("Mode", spline.GetControlPointMode(selectedIndex));

        if (EditorGUI.EndChangeCheck())
        {
            Undo.RecordObject(spline, "Change Mode");
            EditorUtility.SetDirty(spline);
            spline.SetControlPointMode(selectedIndex, m);
        }
    }
Esempio n. 22
0
        private static double GetHeightByCurveMode(double ratio, CurveMode mode)
        {
            double ret = 1;

            //All the curves should start from point (0,1) and ends with point (1,0).
            switch (mode)
            {
            case CurveMode.Flat:
                return(1);

            case CurveMode.ReverseLinear:                     //normally, Linear starts from point(0,0) and ends with point (1,1),so we reverse it.
                ret = 1 - ratio;
                break;

            case CurveMode.ReverseSineQuarter:                      //normally, SineQuater starts from point(0,0) and ends with point (1,1),so we reverse it.
                ret = 1 - System.Math.Sin(ratio * System.Math.PI / 2);
                break;

            case CurveMode.CosineHalf:                      //normally, ConsineHalf starts from point (0,1) and ends with point (1,-1), so we scale it.
                ret = System.Math.Cos(ratio * System.Math.PI) / 2 + 0.5f;
                break;

            case CurveMode.CosineQuarter:                    //Consine Quarter perfectly starts from point(0,1) and ends with point(1,0). just get the origin value.
                ret = System.Math.Cos(ratio * System.Math.PI / 2);
                break;
            }
            if (ret > 1)
            {
                return(1);
            }
            if (ret < 0)
            {
                return(0);
            }
            return(ret);
        }
Esempio n. 23
0
        public UICurves(PropertyInfo p, PropertyInfo output, object owner)
        {
            InitializeComponent();
            mode           = CurveMode.RGB;
            outputProperty = output;
            property       = p;
            propertyOwner  = owner;

            Points    = new Dictionary <int, List <CurvePoint> >();
            Points[0] = new List <CurvePoint>();
            Points[1] = new List <CurvePoint>();
            Points[2] = new List <CurvePoint>();
            Points[3] = new List <CurvePoint>();

            inited = false;

            Input      = (Dictionary <int, List <Point> >)p.GetValue(owner);
            Normalized = (Dictionary <int, List <Point> >)output.GetValue(owner);

            Sort(Input[0]);
            Sort(Input[1]);
            Sort(Input[2]);
            Sort(Input[3]);
        }
Esempio n. 24
0
        public InterpCurve(IMEPackage _pcc, StructProperty prop)
        {
            pcc = _pcc;

            Curves    = new ObservableCollectionExtended <Curve>();
            Name      = prop.Name;
            curveType = Enums.Parse <CurveType>(prop.StructType);

            float     InVal      = 0f;
            CurveMode InterpMode = CurveMode.CIM_Linear;
            var       points     = prop.Properties.GetProp <ArrayProperty <StructProperty> >("Points");

            switch (curveType)
            {
            case CurveType.InterpCurveQuat:
                throw new NotImplementedException($"InterpCurveQuat has not been implemented yet.");

            case CurveType.InterpCurveFloat:
                float OutVal        = 0f;
                float ArriveTangent = 0f;
                float LeaveTangent  = 0f;
                var   vals          = new LinkedList <CurvePoint>();
                foreach (var point in points)
                {
                    foreach (var p in point.Properties)
                    {
                        switch (p)
                        {
                        case FloatProperty floatProp when floatProp.Name == "InVal":
                            InVal = floatProp.Value;
                            break;

                        case FloatProperty floatProp when floatProp.Name == "OutVal":
                            OutVal = floatProp.Value;
                            break;

                        case FloatProperty floatProp when floatProp.Name == "ArriveTangent":
                            ArriveTangent = floatProp.Value;
                            break;

                        case FloatProperty floatProp when floatProp.Name == "LeaveTangent":
                            LeaveTangent = floatProp.Value;
                            break;

                        case EnumProperty enumProp when enumProp.Name == "InterpMode" && Enum.TryParse(enumProp.Value, out CurveMode enumVal):
                            InterpMode = enumVal;
                            break;
                        }
                    }
                    vals.AddLast(new CurvePoint(InVal, OutVal, ArriveTangent, LeaveTangent, InterpMode));
                }
                Curves.Add(new Curve("X", vals));
                break;

            case CurveType.InterpCurveVector:
                Vector OutValVec        = new Vector(0, 0, 0);
                Vector ArriveTangentVec = new Vector(0, 0, 0);
                Vector LeaveTangentVec  = new Vector(0, 0, 0);
                var    x = new LinkedList <CurvePoint>();
                var    y = new LinkedList <CurvePoint>();
                var    z = new LinkedList <CurvePoint>();
                foreach (var point in points)
                {
                    foreach (var p in point.Properties)
                    {
                        switch (p)
                        {
                        case FloatProperty floatProp when floatProp.Name == "InVal":
                            InVal = floatProp.Value;
                            break;

                        case StructProperty structProp when structProp.Name == "OutVal":
                            OutValVec = GetVector(structProp);
                            break;

                        case StructProperty structProp when structProp.Name == "ArriveTangent":
                            ArriveTangentVec = GetVector(structProp);
                            break;

                        case StructProperty structProp when structProp.Name == "LeaveTangent":
                            LeaveTangentVec = GetVector(structProp);
                            break;

                        case EnumProperty enumProp when enumProp.Name == "InterpMode" && Enum.TryParse(enumProp.Value, out CurveMode enumVal):
                            InterpMode = enumVal;
                            break;
                        }
                    }
                    x.AddLast(new CurvePoint(InVal, OutValVec.X, ArriveTangentVec.X, LeaveTangentVec.X, InterpMode));
                    y.AddLast(new CurvePoint(InVal, OutValVec.Y, ArriveTangentVec.Y, LeaveTangentVec.Y, InterpMode));
                    z.AddLast(new CurvePoint(InVal, OutValVec.Z, ArriveTangentVec.Z, LeaveTangentVec.Z, InterpMode));
                }
                if (Name == "EulerTrack")
                {
                    Curves.Add(new Curve("Roll", x));
                    Curves.Add(new Curve("Pitch", y));
                    Curves.Add(new Curve("Yaw", z));
                }
                else
                {
                    Curves.Add(new Curve("X", x));
                    Curves.Add(new Curve("Y", y));
                    Curves.Add(new Curve("Z", z));
                }
                break;

            case CurveType.InterpCurveVector2D:
                throw new NotImplementedException($"InterpCurveVector2D has not been implemented yet.");

            case CurveType.InterpCurveTwoVectors:
                throw new NotImplementedException($"InterpCurveTwoVectors has not been implemented yet.");

            case CurveType.InterpCurveLinearColor:
                throw new NotImplementedException($"InterpCurveLinearColor has not been implemented yet.");
            }
            foreach (var curve in Curves)
            {
                curve.SharedValueChanged += Curve_SharedValueChanged;
                curve.ListModified       += Curve_ListModified;
            }
        }
Esempio n. 25
0
        public static void DistanceToLine(double height, Vector2d lineStart, Vector2d lineEnd, double radius, List <EPMPoint> pointList, CurveMode curveMode = CurveMode.ReverseLinear, CombineMode combineMode = CombineMode.Add, double limitation = 0)
        {
            Vector2d dir        = lineEnd - lineStart;
            double   lineLength = dir.Length();

            dir.Normalize();
            Vector2d normal = new Vector2d(-dir.y, dir.x);

            for (int i = 0; i < pointList.Count; i++)
            {
                EPMPoint p        = pointList[i];
                Vector2d v2       = p.pos2d - lineStart;
                double   dot      = v2 * dir;
                double   distance = 0;
                if (dot < 0 || dot > lineLength)
                {
                    //Check the distance to LineStart point and LineEndPoint
                    distance = System.Math.Min(v2.Length(), (p.pos2d - lineEnd).Length());
                }
                else
                {
                    //check the distance to line
                    distance = System.Math.Abs(v2 * normal);
                }

                if (distance < radius)
                {
                    double y = GetHeightByCurveMode(distance / radius, curveMode) * height;
                    SetHeightByCombineMode(p, y, combineMode, limitation);
                }
            }
        }
Esempio n. 26
0
 public static void DistanceWithinCircle(double height, Vector2d center, double radius, double influenceDistance, List <EPMPoint> pointList, CurveMode curveMode = CurveMode.ReverseLinear, CombineMode combineMode = CombineMode.Add, double limitation = 0)
 {
     for (int i = 0; i < pointList.Count; i++)
     {
         EPMPoint p        = pointList[i];
         double   distance = radius - center * p.pos2d;
         if (distance >= 0 && distance < influenceDistance)
         {
             double y = GetHeightByCurveMode(distance / influenceDistance, curveMode) * height;
             SetHeightByCombineMode(p, y, combineMode, limitation);
         }
     }
 }
 public static T SetCurveMode <T>(this T tween, CurveMode curveMode) where T : Tweener
 {
     tween.CurveMode = curveMode;
     return(tween);
 }
Esempio n. 28
0
        public static void DistanceToBorderOfRectangle(double height, Vector2d rectangleCenterLineStart, Vector2d rectangleCenterLineEnd, double rectangleHalfWitdth, double influenceDistance, List <EPMPoint> pointList, CurveMode curveMode = CurveMode.ReverseLinear, CombineMode combineMode = CombineMode.Add, double limitation = 0)
        {
            Vector2d dir        = rectangleCenterLineEnd - rectangleCenterLineStart;
            double   lineLength = dir.Length();

            dir.Normalize();
            Vector2d normal = new Vector2d(-dir.y, dir.x);
            Vector2d corner1, corner2, corner3, corner4;

            corner1 = rectangleCenterLineStart + normal * rectangleHalfWitdth;
            corner2 = rectangleCenterLineStart - normal * rectangleHalfWitdth;
            corner3 = rectangleCenterLineEnd + normal * rectangleHalfWitdth;
            corner4 = rectangleCenterLineEnd - normal * rectangleHalfWitdth;

            for (int i = 0; i < pointList.Count; i++)
            {
                EPMPoint p        = pointList[i];
                Vector2d v2       = p.pos2d - rectangleCenterLineStart;
                double   hlength  = v2 * dir;
                double   vlength  = v2 * normal;
                double   distance = 0;
                if (hlength >= 0 && hlength <= lineLength && System.Math.Abs(vlength) <= rectangleHalfWitdth)
                {
                    //The point is in the rectangle, ignore it.
                    continue;
                }
                else
                {
                    if (hlength >= 0 && hlength <= lineLength)
                    {
                        distance = System.Math.Abs(vlength - rectangleHalfWitdth);
                    }
                    else if (System.Math.Abs(vlength) <= rectangleHalfWitdth)
                    {
                        if (hlength > 0)
                        {
                            distance = hlength - lineLength;
                        }
                        else
                        {
                            distance = -hlength;
                        }
                    }
                    else
                    {
                        v2       = p.pos2d;
                        distance = EPMGlobal.Min((v2 - corner1).Length(), (v2 - corner2).Length(), (v2 - corner3).Length(), (v2 - corner4).Length());
                    }

                    if (distance <= influenceDistance)
                    {
                        double y = GetHeightByCurveMode(distance / influenceDistance, curveMode) * height;
                        SetHeightByCombineMode(p, y, combineMode, limitation);
                    }
                }
            }
        }
Esempio n. 29
0
        public static void DistanceWithinRectangle(double height, Vector2d rectangleCenterLineStart, Vector2d rectangleCenterLineEnd, double rectangleHalfWitdth, double influenceDistance, List <EPMPoint> pointList, CurveMode curveMode = CurveMode.ReverseLinear, CombineMode combineMode = CombineMode.Add, double limitation = 0)
        {
            Vector2d dir        = rectangleCenterLineEnd - rectangleCenterLineStart;
            double   lineLength = dir.Length();

            dir.Normalize();
            Vector2d normal = new Vector2d(-dir.y, dir.x);

            for (int i = 0; i < pointList.Count; i++)
            {
                EPMPoint p        = pointList[i];
                Vector2d v2       = p.pos2d - rectangleCenterLineStart;
                double   hlength  = v2 * dir;
                double   vlength  = v2 * normal;
                double   distance = 0;
                if (hlength >= 0 && hlength <= lineLength && System.Math.Abs(vlength) <= rectangleHalfWitdth)
                {
                    //The point is in the rectangle
                    distance = EPMGlobal.Min(rectangleHalfWitdth - System.Math.Abs(vlength), hlength, lineLength - hlength);
                    if (distance <= influenceDistance)
                    {
                        double y = GetHeightByCurveMode(distance / influenceDistance, curveMode) * height;
                        SetHeightByCombineMode(p, y, combineMode, limitation);
                    }
                }
                else
                {
                    //The point is outside the rectangle, ignore it.
                    continue;
                }
            }
        }
Esempio n. 30
0
 private void PathBetween(Anchor a1, Anchor a2, CurveMode interpMode = CurveMode.CIM_Linear)
 {
     Line line;
     BezierSegment bez;
     switch (interpMode)
     {
         case CurveMode.CIM_Linear:
             line = new Line();
             line.bind(Line.X1Property, a1, "X");
             line.bind(Line.Y1Property, a1, "Y", new YConverter(), ActualHeight);
             line.bind(Line.X2Property, a2, "X");
             line.bind(Line.Y2Property, a2, "Y", new YConverter(), ActualHeight);
             graph.Children.Add(line);
             break;
         case CurveMode.CIM_Constant:
             line = new Line();
             line.bind(Line.X1Property, a1, "X");
             line.bind(Line.Y1Property, a1, "Y", new YConverter(), ActualHeight);
             line.bind(Line.X2Property, a2, "X");
             line.bind(Line.Y2Property, a1, "Y", new YConverter(), ActualHeight);
             graph.Children.Add(line);
             line = new Line();
             line.bind(Line.X1Property, a2, "X");
             line.bind(Line.Y1Property, a1, "Y", new YConverter(), ActualHeight);
             line.bind(Line.X2Property, a2, "X");
             line.bind(Line.Y2Property, a2, "Y", new YConverter(), ActualHeight);
             graph.Children.Add(line);
             break;
         case CurveMode.CIM_CurveAuto:
         case CurveMode.CIM_CurveUser:
         case CurveMode.CIM_CurveBreak:
         case CurveMode.CIM_CurveAutoClamped:
             bez = new BezierSegment(this);
             bez.Slope1 = a1.point.Value.LeaveTangent;
             bez.Slope2 = a2.point.Value.ArriveTangent;
             bez.bind(BezierSegment.X1Property, a1, "X");
             bez.bind(BezierSegment.Y1Property, a1, "Y");
             bez.bind(BezierSegment.X2Property, a2, "X");
             bez.bind(BezierSegment.Y2Property, a2, "Y");
             graph.Children.Add(bez);
             a1.rightBez = bez;
             a2.leftBez = bez;
             break;
         default:
             break;
     }
 }
Esempio n. 31
0
        public InterpCurve(IMEPackage _pcc, PropertyReader.Property p)
        {
            pcc = _pcc;

            Curves    = new ObservableCollection <Curve>();
            Name      = pcc.getNameEntry(p.Name);
            curveType = (CurveType)Enum.Parse(typeof(CurveType), pcc.getNameEntry(p.Value.IntValue));

            float     InVal      = 0f;
            CurveMode InterpMode = CurveMode.CIM_Linear;
            var       points     = PropertyReader.ReadStructArrayProp(pcc, PropertyReader.getPropOrNull(pcc, p.raw, 32, "Points"));

            switch (curveType)
            {
            case CurveType.InterpCurveQuat:
                throw new NotImplementedException($"InterpCurveQuat has not been implemented yet.");

            case CurveType.InterpCurveFloat:
                float OutVal                 = 0f;
                float ArriveTangent          = 0f;
                float LeaveTangent           = 0f;
                LinkedList <CurvePoint> vals = new LinkedList <CurvePoint>();
                foreach (var point in points)
                {
                    foreach (var prop in point)
                    {
                        switch (pcc.getNameEntry(prop.Name))
                        {
                        case "InVal":
                            InVal = BitConverter.ToSingle(prop.raw, 24);
                            break;

                        case "OutVal":
                            OutVal = BitConverter.ToSingle(prop.raw, 24);
                            break;

                        case "ArriveTangent":
                            ArriveTangent = BitConverter.ToSingle(prop.raw, 24);
                            break;

                        case "LeaveTangent":
                            LeaveTangent = BitConverter.ToSingle(prop.raw, 24);
                            break;

                        case "InterpMode":
                            InterpMode = (CurveMode)Enum.Parse(typeof(CurveMode), pcc.getNameEntry(prop.Value.IntValue));
                            break;

                        default:
                            break;
                        }
                    }
                    vals.AddLast(new CurvePoint(InVal, OutVal, ArriveTangent, LeaveTangent, InterpMode));
                }
                Curves.Add(new Curve("X", vals));
                break;

            case CurveType.InterpCurveVector:
                Vector OutValVec          = new Vector(0, 0, 0);
                Vector ArriveTangentVec   = new Vector(0, 0, 0);
                Vector LeaveTangentVec    = new Vector(0, 0, 0);
                LinkedList <CurvePoint> x = new LinkedList <CurvePoint>();
                LinkedList <CurvePoint> y = new LinkedList <CurvePoint>();
                LinkedList <CurvePoint> z = new LinkedList <CurvePoint>();
                foreach (var point in points)
                {
                    foreach (var prop in point)
                    {
                        switch (pcc.getNameEntry(prop.Name))
                        {
                        case "InVal":
                            InVal = BitConverter.ToSingle(prop.raw, 24);
                            break;

                        case "OutVal":
                            OutValVec = GetVector(prop);
                            break;

                        case "ArriveTangent":
                            ArriveTangentVec = GetVector(prop);
                            break;

                        case "LeaveTangent":
                            LeaveTangentVec = GetVector(prop);
                            break;

                        case "InterpMode":
                            InterpMode = (CurveMode)Enum.Parse(typeof(CurveMode), pcc.getNameEntry(prop.Value.IntValue));
                            break;

                        default:
                            break;
                        }
                    }
                    x.AddLast(new CurvePoint(InVal, OutValVec.X, ArriveTangentVec.X, LeaveTangentVec.X, InterpMode));
                    y.AddLast(new CurvePoint(InVal, OutValVec.Y, ArriveTangentVec.Y, LeaveTangentVec.Y, InterpMode));
                    z.AddLast(new CurvePoint(InVal, OutValVec.Z, ArriveTangentVec.Z, LeaveTangentVec.Z, InterpMode));
                }
                if (Name == "EulerTrack")
                {
                    Curves.Add(new Curve("Roll", x));
                    Curves.Add(new Curve("Pitch", y));
                    Curves.Add(new Curve("Yaw", z));
                }
                else
                {
                    Curves.Add(new Curve("X", x));
                    Curves.Add(new Curve("Y", y));
                    Curves.Add(new Curve("Z", z));
                }
                break;

            case CurveType.InterpCurveVector2D:
                throw new NotImplementedException($"InterpCurveVector2D has not been implemented yet.");

            case CurveType.InterpCurveTwoVectors:
                throw new NotImplementedException($"InterpCurveTwoVectors has not been implemented yet.");

            case CurveType.InterpCurveLinearColor:
                throw new NotImplementedException($"InterpCurveLinearColor has not been implemented yet.");

            default:
                break;
            }
            foreach (var curve in Curves)
            {
                curve.SharedValueChanged += Curve_SharedValueChanged;
                curve.ListModified       += Curve_ListModified;
            }
        }
Esempio n. 32
0
        public static double DoChannelCurve(double positiveInputValue, double maxInputValue, CurveMode curveMode, double rangeMin, double rangeMax)
        {
            double mappedValue;

            switch (curveMode)
            {
            case CurveMode.Linear:
                mappedValue = LinearWithRange(positiveInputValue, maxInputValue, rangeMin, rangeMax);
                break;

            case CurveMode.SymmetricDegree3:

                double mppositiveInputValue = LinearWithRange(positiveInputValue, maxInputValue, 0, 2000);
                double mpmaxInputValue      = 2000;

                double diagVal = SymmetricDegree3(mppositiveInputValue - mpmaxInputValue / 2);
                double diagMax = SymmetricDegree3(mpmaxInputValue / 2);

                //mappedValue = LinearWithRange(diagVal, diagMax, rangeMin, rangeMax);

                mappedValue = LinearWithRange(diagVal, -diagMax, diagMax, 0, maxInputValue);
                //mappedValue += maxInputValue / 2;
                mappedValue = LinearWithRange(mappedValue, maxInputValue, rangeMin, rangeMax);
                break;

            default:
                throw new Exception();
            }
            return(mappedValue);
        }
Esempio n. 33
0
 public Edge CreateEdge(BendyComponent owner, Node from, Node to, CurveMode mode, Vector3?ctl0 = null, Vector3?ctl1 = null)
 {
     return(new Edge(owner, from, to, mode, ctl0, ctl1));
 }