Exemple #1
0
        /// <summary>
        /// helper function for filling a float bitmap
        /// with a gradient from positions and colors
        /// colors and positions must be the same length
        /// as they should be 1 to 1 reference
        /// </summary>
        /// <param name="dst"></param>
        /// <param name="positions"></param>
        /// <param name="colors"></param>
        public static void CreateGradient(FloatBitmap dst, float[] positions, MVector[] colors)
        {
            if (positions.Length != colors.Length)
            {
                return;
            }


            //sort from least to greater
            Array.Sort(positions);

            List <float>   pos  = new List <float>(positions);
            List <MVector> cols = new List <MVector>(colors);

            if (positions[0] > 0)
            {
                pos.Insert(0, 0);
                MVector c = colors[0];
                cols.Insert(0, c);
            }

            if (positions[positions.Length - 1] < 1)
            {
                pos.Add(1);
                MVector c = colors[colors.Length - 1];
                cols.Add(c);
            }

            for (int i = 0; i < pos.Count - 1; i++)
            {
                float p1 = pos[i];
                float p2 = pos[i + 1];

                MVector c1 = cols[i];
                MVector c2 = cols[i + 1];

                ConvertToLAB(ref c1);
                ConvertToLAB(ref c2);

                int imin = (int)(p1 * dst.Width);
                int imax = (int)(p2 * dst.Width);

                for (int x = imin; x < imax; x++)
                {
                    //minus 1 on imax otherwise we won't reach 1 for t
                    float t = (float)(x - imin) / (float)(imax - 1 - imin);

                    MVector n = MVector.Lerp(c1, c2, t);

                    ConvertLABToRGB(ref n);

                    for (int y = 0; y < dst.Height; y++)
                    {
                        dst.SetPixel(x, y, n.X, n.Y, n.Z, n.W);
                    }
                }
            }
        }
Exemple #2
0
        void Process()
        {
            if (input.Input.Data == null || input2.Input.Data == null || input3.Input.Data == null)
            {
                return;
            }

            object from  = input.Input.Data;
            object to    = input.Input.Data;
            float  delta = (float)input.Input.Data;


            if (from is float && to is MVector)
            {
                MVector f = new MVector((float)from, (float)from, (float)from, (float)from);
                MVector r = MVector.Lerp(f, (MVector)to, delta);
                output.Data = r;
                output.Changed();
            }
            else if (from is float && to is float)
            {
                float r = Utils.Lerp((float)from, (float)to, delta);
                output.Data = r;
                output.Changed();
            }
            else if (from is MVector && to is float)
            {
                MVector f = new MVector((float)from, (float)from, (float)from, (float)from);
                MVector r = MVector.Lerp((MVector)from, f, delta);
                output.Data = r;
                output.Changed();
            }
            else if (from is MVector && to is MVector)
            {
                output.Data = MVector.Lerp((MVector)from, (MVector)to, delta);
                output.Changed();
            }
            else
            {
                output.Data = 0;
                output.Changed();
            }

            if (ParentGraph != null)
            {
                FunctionGraph g = (FunctionGraph)ParentGraph;

                if (g != null && g.OutputNode == this)
                {
                    g.Result = output.Data;
                }
            }
        }
Exemple #3
0
        void Process()
        {
            if (input.Input.Data == null || input2.Input.Data == null || input3.Input.Data == null)
            {
                return;
            }

            object from  = input.Input.Data;
            object to    = input2.Input.Data;
            float  delta = Convert.ToSingle(input3.Input.Data);


            if ((from is float || from is double || from is int || from is long) && to is MVector)
            {
                float   vt = Convert.ToSingle(from);
                MVector f  = new MVector(vt, vt, vt, vt);
                MVector r  = MVector.Lerp(f, (MVector)to, delta);
                output.Data = r;
            }
            else if ((from is float || from is double || from is int || from is long) && (to is float || to is double || to is int || to is long))
            {
                float r = Utils.Lerp(Convert.ToSingle(from), Convert.ToSingle(to), delta);
                output.Data = r;
            }
            else if (from is MVector && (to is float || to is double || to is int || to is long))
            {
                float   vt = Convert.ToSingle(to);
                MVector f  = new MVector(vt, vt, vt, vt);
                MVector r  = MVector.Lerp((MVector)from, f, delta);
                output.Data = r;
            }
            else if (from is MVector && to is MVector)
            {
                output.Data = MVector.Lerp((MVector)from, (MVector)to, delta);
            }
            else
            {
                output.Data = 0;
            }

            result = output.Data.ToString();

            if (ParentGraph != null)
            {
                FunctionGraph g = (FunctionGraph)ParentGraph;

                if (g != null && g.OutputNode == this)
                {
                    g.Result = output.Data;
                }
            }
        }
Exemple #4
0
        public override void TryAndProcess()
        {
            if (!input.IsValid || !input2.IsValid || !input3.IsValid)
            {
                return;
            }

            NodeType t  = input.Reference.Type;
            NodeType t2 = input2.Reference.Type;

            float delta = input3.Data.ToFloat();

            try
            {
                if (t == NodeType.Float && t2 == NodeType.Float)
                {
                    float v1 = input.Data.ToFloat();
                    float v2 = input2.Data.ToFloat();
                    output.Data = Utils.Lerp(v1, v2, delta);
                }
                else if ((t == NodeType.Float2 || t == NodeType.Float3 || t == NodeType.Float4) &&
                         (t2 == NodeType.Float2 || t2 == NodeType.Float3 || t2 == NodeType.Float4))
                {
                    MVector v1 = (MVector)input.Data;
                    MVector v2 = (MVector)input2.Data;

                    output.Data = MVector.Lerp(v1, v2, delta);
                }
                else if (t == NodeType.Float && (t2 == NodeType.Float2 || t2 == NodeType.Float3 || t2 == NodeType.Float4))
                {
                    float   f  = input.Data.ToFloat();
                    MVector v1 = new MVector(f, f, f, f);
                    MVector v2 = (MVector)input2.Data;
                    output.Data = MVector.Lerp(v1, v2, delta);
                }
                else if ((t == NodeType.Float2 || t == NodeType.Float3 || t == NodeType.Float4) && t2 == NodeType.Float)
                {
                    float   f  = input2.Data.ToFloat();
                    MVector v2 = new MVector(f, f, f, f);
                    MVector v1 = (MVector)input.Data;
                    output.Data = MVector.Lerp(v1, v2, delta);
                }

                result = output.Data?.ToString();
            }
            catch (Exception e)
            {
            }

            UpdateOutputType();
        }