Exemplo n.º 1
0
        /// <summary>
        /// Creates a new curve drawing GUI element.
        /// </summary>
        /// <param name="layout">Layout into which to add the GUI element.</param>
        /// <param name="width">Width of the element in pixels.</param>
        /// <param name="height">Height of the element in pixels.</param>
        /// <param name="curveInfos">Initial set of curves to display. </param>
        public GUICurveDrawing(GUILayout layout, int width, int height, CurveDrawInfo[] curveInfos)
            : base(layout, width, height)
        {
            tickHandler = new GUIGraphTicks(GUITickStepType.Time);
            this.curveInfos = curveInfos;

            ClearSelectedKeyframes(); // Makes sure the array is initialized
        }
Exemplo n.º 2
0
        /// <summary>Initializes the struct with default values.</summary>
        public static CurveDrawInfo Default()
        {
            CurveDrawInfo value = new CurveDrawInfo();

            value.curve = null;
            value.color = new Color();

            return(value);
        }
Exemplo n.º 3
0
        private bool TryGetCurve(string path, out CurveDrawInfo[] curveInfos)
        {
            int    index = path.LastIndexOf(".");
            string parentPath;
            string subPathSuffix = null;

            if (index == -1)
            {
                parentPath = path;
            }
            else
            {
                parentPath    = path.Substring(0, index);
                subPathSuffix = path.Substring(index, path.Length - index);
            }

            FieldAnimCurves fieldCurves;

            if (clipInfo.curves.TryGetValue(parentPath, out fieldCurves))
            {
                if (!string.IsNullOrEmpty(subPathSuffix))
                {
                    if (subPathSuffix == ".x" || subPathSuffix == ".r")
                    {
                        curveInfos = new [] { fieldCurves.curveInfos[0] };
                        return(true);
                    }
                    else if (subPathSuffix == ".y" || subPathSuffix == ".g")
                    {
                        curveInfos = new[] { fieldCurves.curveInfos[1] };
                        return(true);
                    }
                    else if (subPathSuffix == ".z" || subPathSuffix == ".b")
                    {
                        curveInfos = new[] { fieldCurves.curveInfos[2] };
                        return(true);
                    }
                    else if (subPathSuffix == ".w" || subPathSuffix == ".a")
                    {
                        curveInfos = new[] { fieldCurves.curveInfos[3] };
                        return(true);
                    }
                }
                else
                {
                    curveInfos = fieldCurves.curveInfos;
                    return(true);
                }
            }

            curveInfos = new CurveDrawInfo[0];
            return(false);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Calculates the total range covered by a set of curves.
        /// </summary>
        /// <param name="curveInfos">Curves to calculate range for.</param>
        /// <param name="xRange">Maximum time value present in the curves.</param>
        /// <param name="yRange">Maximum absolute curve value present in the curves.</param>
        private static void CalculateRange(CurveDrawInfo[] curveInfos, out float xRange, out float yRange)
        {
            // Note: This only evaluates at keyframes, we should also evaluate in-between in order to account for steep
            // tangents
            xRange = 0.0f;
            yRange = 0.0f;

            foreach (var curveInfo in curveInfos)
            {
                KeyFrame[] keyframes = curveInfo.curve.KeyFrames;

                foreach (var key in keyframes)
                {
                    xRange = Math.Max(xRange, key.time);
                    yRange = Math.Max(yRange, Math.Abs(key.value));
                }
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Attempts to find a curve field at the specified path.
        /// </summary>
        /// <param name="path">Path of the curve field to look for.</param>
        /// <param name="curveInfos">One or multiple curves found for the specific path (one field can have multiple curves
        ///                          if it is a complex type, like a vector).</param>
        /// <returns>True if the curve field was found, false otherwise.</returns>
        private bool TryGetCurve(string path, out CurveDrawInfo[] curveInfos)
        {
            int index = path.LastIndexOf(".");
            string parentPath;
            string subPathSuffix = null;
            if (index == -1)
            {
                parentPath = path;
            }
            else
            {
                parentPath = path.Substring(0, index);
                subPathSuffix = path.Substring(index, path.Length - index);
            }

            FieldAnimCurves fieldCurves;
            if (clipInfo.curves.TryGetValue(parentPath, out fieldCurves))
            {
                if (!string.IsNullOrEmpty(subPathSuffix))
                {
                    if (subPathSuffix == ".x" || subPathSuffix == ".r")
                    {
                        curveInfos = new [] { fieldCurves.curveInfos[0] };
                        return true;
                    }
                    else if (subPathSuffix == ".y" || subPathSuffix == ".g")
                    {
                        curveInfos = new[] { fieldCurves.curveInfos[1] };
                        return true;
                    }
                    else if (subPathSuffix == ".z" || subPathSuffix == ".b")
                    {
                        curveInfos = new[] { fieldCurves.curveInfos[2] };
                        return true;
                    }
                    else if (subPathSuffix == ".w" || subPathSuffix == ".a")
                    {
                        curveInfos = new[] { fieldCurves.curveInfos[3] };
                        return true;
                    }
                }
                else
                {
                    curveInfos = fieldCurves.curveInfos;
                    return true;
                }
            }

            curveInfos = new CurveDrawInfo[0];
            return false;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Change the set of curves to display.
        /// </summary>
        /// <param name="curveInfos">New set of curves to draw on the GUI element.</param>
        public void SetCurves(CurveDrawInfo[] curveInfos)
        {
            this.curveInfos = curveInfos;
            guiCurveDrawing.SetCurves(curveInfos);

            Redraw();
        }
Exemplo n.º 7
0
 /// <summary>
 /// Change the set of curves to display.
 /// </summary>
 /// <param name="curveInfos">New set of curves to draw on the GUI element.</param>
 public void SetCurves(CurveDrawInfo[] curveInfos)
 {
     this.curveInfos = curveInfos;
 }