public static Vector3[] Edge1DHandle(int id, Axis axis, Vector3[] points, Vector3 from, Vector3 to, Vector3 direction, float snappingStep, float handleSize, CapFunction capFunction, bool selectLockingAxisOnClick = false)
        {
            var evt = Event.current;

            switch (evt.GetTypeForControl(id))
            {
            case EventType.Layout:
            {
                if (SceneHandles.InCameraOrbitMode)
                {
                    break;
                }
                UnityEditor.HandleUtility.AddControl(id, UnityEditor.HandleUtility.DistanceToLine(from, to) * 2.0f);
                break;
            }

            case EventType.Repaint:
            {
                DrawLine(from, to);
                break;
            }
            }

            var position = (from + to) * 0.5f;
            var result   = Slider1D.Do(id, axis, points, position, direction, snappingStep, handleSize, capFunction, selectLockingAxisOnClick);

            return(result);
        }
Example #2
0
        private Vector3 MidpointHandle(int id, Vector3 localPos, Vector3 localTangent, Vector3 localBinormal, bool isCameraInsideBox)
        {
            Color color = Handles.color;

            this.AdjustMidpointHandleColor(localPos, localTangent, localBinormal, isCameraInsideBox);
            if (Handles.color.a > 0f)
            {
                Vector3             normalized = Vector3.Cross(localTangent, localBinormal).normalized;
                Handles.CapFunction arg_66_0;
                if ((arg_66_0 = this.midpointHandleDrawFunction) == null)
                {
                    if (PrimitiveBoundsHandle.< > f__mg$cache0 == null)
                    {
                        PrimitiveBoundsHandle.< > f__mg$cache0 = new Handles.CapFunction(Handles.DotHandleCap);
                    }
                    arg_66_0 = PrimitiveBoundsHandle.< > f__mg$cache0;
                }
                Handles.CapFunction  capFunction = arg_66_0;
                Handles.SizeFunction arg_92_0;
                if ((arg_92_0 = this.midpointHandleSizeFunction) == null)
                {
                    if (PrimitiveBoundsHandle.< > f__mg$cache1 == null)
                    {
                        PrimitiveBoundsHandle.< > f__mg$cache1 = new Handles.SizeFunction(PrimitiveBoundsHandle.DefaultMidpointHandleSizeFunction);
                    }
                    arg_92_0 = PrimitiveBoundsHandle.< > f__mg$cache1;
                }
                Handles.SizeFunction sizeFunction = arg_92_0;
                localPos = Slider1D.Do(id, localPos, normalized, sizeFunction(localPos), capFunction, SnapSettings.scale);
            }
            Handles.color = color;
            return(localPos);
        }
Example #3
0
        private Vector3 MidpointHandle(Vector3 localPos, Vector3 localTangent, Vector3 localBinormal, Matrix4x4 transform, bool isCameraInsideBox)
        {
            Color color       = Handles.color;
            float alphaFactor = 1f;

            this.AdjustMidpointHandleColor(localPos, localTangent, localBinormal, transform, alphaFactor, isCameraInsideBox);
            int controlID = GUIUtility.GetControlID(this.m_ControlIdHint, FocusType.Keyboard);

            if (alphaFactor > 0f)
            {
                Handles.DrawCapFunction drawMethodForHandles;
                Func <Vector3, float>   getHandleSizeMethod;
                Vector3 normalized = Vector3.Cross(localTangent, localBinormal).normalized;
                if (this.drawMethodForHandles != null)
                {
                    drawMethodForHandles = this.drawMethodForHandles;
                }
                else
                {
                    drawMethodForHandles = new Handles.DrawCapFunction(BoxEditor.DefaultMidPointDrawFunc);
                }
                if (this.getHandleSizeMethod != null)
                {
                    getHandleSizeMethod = this.getHandleSizeMethod;
                }
                else
                {
                    getHandleSizeMethod = new Func <Vector3, float>(BoxEditor.DefaultMidpointGetSizeFunc);
                }
                localPos = Slider1D.Do(controlID, localPos, normalized, getHandleSizeMethod(localPos), drawMethodForHandles, SnapSettings.scale);
            }
            Handles.color = color;
            return(localPos);
        }
Example #4
0
        public static Vector3 Slider1DHandleAlignedOffset(int id, Vector3 from, Vector3 to, float snappingStep = 0, float handleSize = 0, CapFunction capFunction = null, bool selectLockingAxisOnClick = false)
        {
            var snapPoints      = new[] { from, to };
            var handleDirection = (from - to).normalized;
            var grid            = Grid.ActiveGrid;
            var axis            = grid.GetClosestAxis(handleDirection);

            return(Slider1D.Do(id, axis, snapPoints, from, handleDirection, snappingStep, handleSize, capFunction, selectLockingAxisOnClick)[0] - from);
        }
Example #5
0
        private Vector3 MidpointHandle(Vector3 localPos, Vector3 localTangent, Vector3 localBinormal, Matrix4x4 transform, bool isCameraInsideBox)
        {
            Color color = Handles.color;
            float num   = 1f;

            this.AdjustMidpointHandleColor(localPos, localTangent, localBinormal, transform, num, isCameraInsideBox);
            int controlID = GUIUtility.GetControlID(this.m_ControlIdHint, FocusType.Keyboard);

            if (num > 0f)
            {
                Vector3 normalized = Vector3.Cross(localTangent, localBinormal).normalized;
                Handles.DrawCapFunction drawFunc = this.drawMethodForHandles ?? new Handles.DrawCapFunction(BoxEditor.DefaultMidPointDrawFunc);
                Func <Vector3, float>   func     = this.getHandleSizeMethod ?? new Func <Vector3, float>(BoxEditor.DefaultMidpointGetSizeFunc);
                localPos = Slider1D.Do(controlID, localPos, normalized, func(localPos), drawFunc, SnapSettings.scale);
            }
            Handles.color = color;
            return(localPos);
        }
Example #6
0
        private Vector3 MidpointHandle(Vector3 localPos, Vector3 localTangent, Vector3 localBinormal, Matrix4x4 transform)
        {
            Color color       = Handles.color;
            float alphaFactor = 1f;

            AdjustMidpointHandleColor(localPos, localTangent, localBinormal, transform, alphaFactor);
            int controlID = GUIUtility.GetControlID(m_ControlIdHint, FocusType.Keyboard);

            if (alphaFactor > 0f)
            {
                Vector3 normalized = Vector3.Cross(localTangent, localBinormal).normalized;
                localPos = Slider1D.Do(controlID, localPos, normalized, HandleUtility.GetHandleSize(localPos) * 0.03f,
#if !UNITY_5_6_OR_NEWER
                                       Handles.DotCap,
#else
                                       Handles.DotHandleCap,
#endif
                                       SnapSettingsScale);
            }
            Handles.color = color;
            return(localPos);
        }
        internal static float DoRadiusHandle(Quaternion rotation, Vector3 position, float radius, bool handlesOnly)
        {
            Vector3 planeNormal;
            float   frontAngle = 90;

            Vector3[] dirs = new[]
            {
                rotation *Vector3.right,
                rotation *Vector3.up,
                rotation *Vector3.forward,
                rotation * -Vector3.right,
                      rotation * -Vector3.up,
                      rotation * -Vector3.forward
            };

            if (Camera.current.orthographic)
            {
                planeNormal = Camera.current.transform.forward;

                if (!handlesOnly)
                {
                    // Draw periphery circle
                    DrawWireDisc(position, planeNormal, radius);

                    // Draw two-shaded axis-aligned circles
                    for (int i = 0; i < 3; i++)
                    {
                        Vector3 from = Vector3.Cross(dirs[i], planeNormal).normalized;
                        DrawTwoShadedWireDisc(position, dirs[i], from, 180, radius);
                    }
                }
            }
            else
            {
                // Since the geometry is transfromed by Handles.matrix during rendering, we transform the camera position
                // by the inverse matrix so that the two-shaded wireframe will have the proper orientation.
                Matrix4x4 invMatrix = Matrix4x4.Inverse(Handles.matrix);

                planeNormal = position - invMatrix.MultiplyPoint(Camera.current.transform.position); // vector from camera to center
                float sqrDist      = planeNormal.sqrMagnitude;                                       // squared distance from camera to center
                float sqrRadius    = radius * radius;                                                // squared radius
                float sqrOffset    = sqrRadius * sqrRadius / sqrDist;                                // squared distance from actual center to drawn disc center
                float insideAmount = sqrOffset / sqrRadius;

                // If we are not inside the sphere, calculate where to draw the periphery
                if (insideAmount < 1)
                {
                    float drawnRadius = Mathf.Sqrt(sqrRadius - sqrOffset); // the radius of the drawn disc
                    frontAngle = Mathf.Atan2(drawnRadius, Mathf.Sqrt(sqrOffset)) * Mathf.Rad2Deg;

                    // Draw periphery circle
                    if (!handlesOnly)
                    {
                        DrawWireDisc(position - sqrRadius * planeNormal / sqrDist, planeNormal, drawnRadius);
                    }
                }
                else
                {
                    frontAngle = -1000;
                }

                if (!handlesOnly)
                {
                    // Draw two-shaded axis-aligned circles
                    for (int i = 0; i < 3; i++)
                    {
                        if (insideAmount < 1)
                        {
                            float Q = Vector3.Angle(planeNormal, dirs[i]);
                            Q = 90 - Mathf.Min(Q, 180 - Q);
                            float f = Mathf.Tan(Q * Mathf.Deg2Rad);
                            float g = Mathf.Sqrt(sqrOffset + f * f * sqrOffset) / radius;
                            if (g < 1)
                            {
                                float   e    = Mathf.Asin(g) * Mathf.Rad2Deg;
                                Vector3 from = Vector3.Cross(dirs[i], planeNormal).normalized;
                                from = Quaternion.AngleAxis(e, dirs[i]) * from;
                                DrawTwoShadedWireDisc(position, dirs[i], from, (90 - e) * 2, radius);
                            }
                            else
                            {
                                DrawTwoShadedWireDisc(position, dirs[i], radius);
                            }
                        }
                        else
                        {
                            DrawTwoShadedWireDisc(position, dirs[i], radius);
                        }
                    }
                }
            }

            Color origCol = color;

            // Draw handles
            for (int i = 0; i < 6; i++)
            {
                // Get the id no matter if we're drawing the slider or not,
                // in order to not corrupt the id order when slider handles pop in and out.
                int id = GUIUtility.GetControlID(s_RadiusHandleHash, FocusType.Passive);

                // The angle between the axis and the center-camera vector
                float angle = Vector3.Angle(dirs[i], -planeNormal);

                // Don't make the slider if the axis is pointing almost towards or away from the camera,
                // but always draw it if the user is already dragging it.
                if ((angle > 5 && angle < 175) || GUIUtility.hotControl == id)
                {
                    // Give handles twice the alpha of the lines.
                    // If handle is not on front side of sphere, make it dimmer.
                    Color col = origCol;
                    if (angle > frontAngle + 5f)
                    {
                        col.a = Mathf.Clamp01(backfaceAlphaMultiplier * origCol.a * 2);
                    }
                    else
                    {
                        col.a = Mathf.Clamp01(origCol.a * 2);
                    }
                    color = ToActiveColorSpace(col);

                    Vector3 pos  = position + radius * dirs[i];
                    bool    temp = GUI.changed;
                    GUI.changed = false;
                    pos         = Slider1D.Do(id, pos, dirs[i], HandleUtility.GetHandleSize(pos) * 0.03f, DotHandleCap, 0);


                    if (GUI.changed)
                    {
                        radius = Vector3.Distance(pos, position);
                    }
                    GUI.changed |= temp;
                }
            }

            color = origCol;

            return(radius);
        }
Example #8
0
        public static Vector3 Slider1DHandleOffset(int id, Vector3[] snapPoints, Vector3 handleDirection, float snappingStep = 0, float handleSize = 0, CapFunction capFunction = null, bool selectLockingAxisOnClick = false)
        {
            Axis axis = Grid.ActiveGrid.GetClosestAxis(Handles.matrix.MultiplyVector(handleDirection));

            return(Slider1D.Do(id, axis, snapPoints, snapPoints[0], handleDirection, snappingStep, handleSize, capFunction, selectLockingAxisOnClick)[0] - snapPoints[0]);
        }
Example #9
0
 public static Vector3 Slider1DHandleOffset(int id, Axis axis, Vector3[] snapPoints, Vector3 handleDirection, float snappingStep = 0, float handleSize = 0, CapFunction capFunction = null, bool selectLockingAxisOnClick = false)
 {
     return(Slider1D.Do(id, axis, snapPoints, snapPoints[0], handleDirection, snappingStep, handleSize, capFunction, selectLockingAxisOnClick)[0] - snapPoints[0]);
 }
Example #10
0
 public static Vector3[] Slider1DHandle(int id, Axis axis, Vector3[] snapPoints, Vector3 handleOrigin, Vector3 handleDirection, float snappingStep, float handleSize, CapFunction capFunction, bool selectLockingAxisOnClick = false)
 {
     return(Slider1D.Do(id, axis, snapPoints, handleOrigin, handleDirection, snappingStep, handleSize, capFunction, selectLockingAxisOnClick));
 }
 public static Vector3 Slider1DHandle(int id, Axis axis, Vector3 handleOrigin, Vector3 handleDirection, float snappingStep, float handleSize, CapFunction capFunction, bool selectLockingAxisOnClick = false)
 {
     pointArray[0] = handleOrigin;
     return(Slider1D.Do(id, axis, pointArray, handleOrigin, handleDirection, snappingStep, handleSize, capFunction, selectLockingAxisOnClick)[0]);
 }