예제 #1
0
        public static Vector3 PositionHandle(Vector3 position, Quaternion rotation, bool snapping, Vector3[] snapVertices = null, InitFunction initFunction = null, InitFunction shutdownFunction = null)
        {
            var xAxisSlider   = GUIUtility.GetControlID(s_SliderHash, FocusType.Keyboard);
            var yAxisSlider   = GUIUtility.GetControlID(s_SliderHash, FocusType.Keyboard);
            var zAxisSlider   = GUIUtility.GetControlID(s_SliderHash, FocusType.Keyboard);
            var xzPlaneSlider = GUIUtility.GetControlID(s_xzAxisMoveHandleHash, FocusType.Keyboard);
            var xyPlaneSlider = GUIUtility.GetControlID(s_xyAxisMoveHandleHash, FocusType.Keyboard);
            var yzPlaneSlider = GUIUtility.GetControlID(s_yzAxisMoveHandleHash, FocusType.Keyboard);


            var size          = HandleUtility.GetHandleSize(position);
            var originalColor = Handles.color;
            var isStatic      = (!Tools.hidden && EditorApplication.isPlaying && ContainsStatic(Selection.gameObjects));

            var prevDisabled = CSGHandles.disabled;

            CSGHandles.disabled = prevDisabled || RealtimeCSG.CSGSettings.LockAxisX;
            {
                Handles.color = isStatic ? Color.Lerp(Handles.xAxisColor, staticColor, staticBlend) : Handles.xAxisColor;
                GUI.SetNextControlName("xAxis");
                position = CSGSlider1D.Do(xAxisSlider, position, rotation * Vector3.right, size, ArrowHandleCap, snapping, snapVertices, initFunction, shutdownFunction);
            }

            CSGHandles.disabled = prevDisabled || RealtimeCSG.CSGSettings.LockAxisY;
            {
                Handles.color = isStatic ? Color.Lerp(Handles.yAxisColor, staticColor, staticBlend) : Handles.yAxisColor;
                GUI.SetNextControlName("yAxis");
                position = CSGSlider1D.Do(yAxisSlider, position, rotation * Vector3.up, size, ArrowHandleCap, snapping, snapVertices, initFunction, shutdownFunction);
            }

            CSGHandles.disabled = prevDisabled || RealtimeCSG.CSGSettings.LockAxisZ;
            {
                Handles.color = isStatic ? Color.Lerp(Handles.zAxisColor, staticColor, staticBlend) : Handles.zAxisColor;
                GUI.SetNextControlName("zAxis");
                position = CSGSlider1D.Do(zAxisSlider, position, rotation * Vector3.forward, size, ArrowHandleCap, snapping, snapVertices, initFunction, shutdownFunction);
            }

            CSGHandles.disabled = prevDisabled || (RealtimeCSG.CSGSettings.LockAxisX || RealtimeCSG.CSGSettings.LockAxisZ);
            if (!CSGHandles.disabled)
            {
                position = DoPlanarHandle(xzPlaneSlider, PrincipleAxis2.XZ, position, rotation, size * 0.25f, snapping, snapVertices, initFunction, shutdownFunction);
            }

            CSGHandles.disabled = prevDisabled || (RealtimeCSG.CSGSettings.LockAxisX || RealtimeCSG.CSGSettings.LockAxisY);
            if (!CSGHandles.disabled)
            {
                position = DoPlanarHandle(xyPlaneSlider, PrincipleAxis2.XY, position, rotation, size * 0.25f, snapping, snapVertices, initFunction, shutdownFunction);
            }

            CSGHandles.disabled = prevDisabled || (RealtimeCSG.CSGSettings.LockAxisY || RealtimeCSG.CSGSettings.LockAxisZ);
            if (!CSGHandles.disabled)
            {
                position = DoPlanarHandle(yzPlaneSlider, PrincipleAxis2.YZ, position, rotation, size * 0.25f, snapping, snapVertices, initFunction, shutdownFunction);
            }

            CSGHandles.disabled = prevDisabled;
            Handles.color       = originalColor;

            return(position);
        }
예제 #2
0
        internal static AABB Do(AABB bounds, Quaternion worldToLocalRotation, bool showEdgePoints = true)
        {
            for (int i = 0; i < sideControlIDs.Length; i++)
            {
                sideControlIDs[i] = GUIUtility.GetControlID(BoundsHash, FocusType.Passive);
            }

            for (int i = 0; i < edgeControlIDs.Length; i++)
            {
                edgeControlIDs[i] = GUIUtility.GetControlID(BoundsHash, FocusType.Passive);
            }

            UpdateColors(bounds, worldToLocalRotation, showEdgePoints);

            var evt = Event.current;

            switch (evt.type)
            {
            case EventType.Repaint:
            {
                Render(bounds, worldToLocalRotation, showEdgePoints);
                break;
            }
            }

            //var isStatic = (!Tools.hidden && EditorApplication.isPlaying && ContainsStatic(Selection.gameObjects));

            //var prevDisabled = CSGHandles.disabled;


            var localToWorldRotation = Quaternion.Inverse(worldToLocalRotation);
            var localToWorld         = Matrix4x4.TRS(Vector3.zero, localToWorldRotation, Vector3.one);

            var origMatrix = Handles.matrix;

            Handles.matrix = localToWorld;

            RealtimeCSG.Helpers.CSGHandles.InitFunction init = delegate
            {
                originalBounds = bounds;
            };
            RealtimeCSG.Helpers.CSGHandles.InitFunction shutdown = delegate
            {
                originalBounds = bounds;
            };

            var toggleSnapping = (Event.current.modifiers & EventModifiers.Control) == EventModifiers.Control;
            var doSnapping     = RealtimeCSG.CSGSettings.SnapToGrid ^ toggleSnapping;

            for (int i = 0; i < sidePoints.Length; i++)
            {
                Handles.color = sideColors[(i * 2) + 1];

                var position = sidePoints[i];
                var normal   = BoundsUtilities.AABBSideNormal[i];
                var size     = sideSizes[i];
                var id       = sideControlIDs[i];
                EditorGUI.BeginChangeCheck();
                position = CSGSlider1D.Do(id, position, normal, size, CSGHandles.HoverArrowHandleCap, doSnapping, null, init, shutdown);
                if (EditorGUI.EndChangeCheck())
                {
                    var originalPoint = BoundsUtilities.GetBoundsSidePoint(originalBounds, i);
                    bounds = originalBounds;

                    var delta = Vector3.Dot(normal, (position - originalPoint));
                    if (normal.x < 0)
                    {
                        bounds.MinX -= delta;
                    }
                    else if (normal.x > 0)
                    {
                        bounds.MaxX += delta;
                    }
                    else if (normal.y < 0)
                    {
                        bounds.MinY -= delta;
                    }
                    else if (normal.y > 0)
                    {
                        bounds.MaxY += delta;
                    }
                    else if (normal.z < 0)
                    {
                        bounds.MinZ -= delta;
                    }
                    else if (normal.z > 0)
                    {
                        bounds.MaxZ += delta;
                    }
                }
            }

            if (showEdgePoints)
            {
                for (int i = 0; i < edgePoints.Length; i++)
                {
                    Handles.color = edgeColors[(i * 2) + 1];

                    var position    = edgePoints[i];
                    var sideIndices = BoundsUtilities.AABBEdgeSides[i];
                    var normal      = BoundsUtilities.AABBEdgeTangents[i];
                    var direction1  = BoundsUtilities.AABBSideNormal[sideIndices[0]];
                    var direction2  = BoundsUtilities.AABBSideNormal[sideIndices[1]];
                    var size        = edgeSizes[i] / 20.0f;
                    var id          = edgeControlIDs[i];
                    EditorGUI.BeginChangeCheck();
                    position = CSGHandles.Slider2D(id, position, Vector3.zero, normal, direction1, direction2, size, null, doSnapping, null, init, shutdown);
                    if (EditorGUI.EndChangeCheck())
                    {
                        var originalPoint = BoundsUtilities.GetBoundsEdgePoint(originalBounds, i);
                        bounds = originalBounds;

                        var delta = (position - originalPoint);
                        var sides = BoundsUtilities.AABBEdgeCubeSides[i];
                        switch (sides[0])
                        {
                        case CubeSide.NegativeX: bounds.MinX += delta.x; break;

                        case CubeSide.PositiveX: bounds.MaxX += delta.x; break;

                        case CubeSide.NegativeY: bounds.MinY += delta.y; break;

                        case CubeSide.PositiveY: bounds.MaxY += delta.y; break;

                        case CubeSide.NegativeZ: bounds.MinZ += delta.z; break;

                        case CubeSide.PositiveZ: bounds.MaxZ += delta.z; break;
                        }

                        switch (sides[1])
                        {
                        case CubeSide.NegativeX: bounds.MinX += delta.x; break;

                        case CubeSide.PositiveX: bounds.MaxX += delta.x; break;

                        case CubeSide.NegativeY: bounds.MinY += delta.y; break;

                        case CubeSide.PositiveY: bounds.MaxY += delta.y; break;

                        case CubeSide.NegativeZ: bounds.MinZ += delta.z; break;

                        case CubeSide.PositiveZ: bounds.MaxZ += delta.z; break;
                        }
                    }
                }
            }

            Handles.matrix = origMatrix;

            if (bounds.MinX > bounds.MaxX)
            {
                float t = bounds.MinX; bounds.MinX = bounds.MaxX; bounds.MaxX = t;
            }
            if (bounds.MinY > bounds.MaxY)
            {
                float t = bounds.MinY; bounds.MinY = bounds.MaxY; bounds.MaxY = t;
            }
            if (bounds.MinZ > bounds.MaxZ)
            {
                float t = bounds.MinZ; bounds.MinZ = bounds.MaxZ; bounds.MaxZ = t;
            }
            return(bounds);
        }
예제 #3
0
        public static Vector3 Slider(Vector3 position, Vector3 direction, float size, CapFunction capFunction, bool snapping, Vector3[] snapVertices, InitFunction initFunction, InitFunction shutdownFunction)
        {
            var id = GUIUtility.GetControlID(s_SliderHash, FocusType.Keyboard);

            return(CSGSlider1D.Do(id, position, direction, size, capFunction, snapping, snapVertices, initFunction, shutdownFunction));
        }
예제 #4
0
        public static Vector3 PositionHandle(Camera camera, Vector3 position, Quaternion rotation, SnapMode snapMode, Vector3[] snapVertices = null, InitFunction initFunction = null, InitFunction shutdownFunction = null)
        {
            GUI.SetNextControlName("xAxis");   var xAxisSlider   = GUIUtility.GetControlID(s_xAxisMoveHandleHash, FocusType.Passive);
            GUI.SetNextControlName("yAxis");   var yAxisSlider   = GUIUtility.GetControlID(s_yAxisMoveHandleHash, FocusType.Passive);
            GUI.SetNextControlName("zAxis");   var zAxisSlider   = GUIUtility.GetControlID(s_zAxisMoveHandleHash, FocusType.Passive);
            GUI.SetNextControlName("xzPlane"); var xzPlaneSlider = GUIUtility.GetControlID(s_xzAxisMoveHandleHash, FocusType.Passive);
            GUI.SetNextControlName("xyPlane"); var xyPlaneSlider = GUIUtility.GetControlID(s_xyAxisMoveHandleHash, FocusType.Passive);
            GUI.SetNextControlName("yzPlane"); var yzPlaneSlider = GUIUtility.GetControlID(s_yzAxisMoveHandleHash, FocusType.Passive);

            var isStatic     = (!Tools.hidden && EditorApplication.isPlaying && ContainsStatic(Selection.gameObjects));
            var prevDisabled = CSGHandles.disabled;

            var hotControl = GUIUtility.hotControl;

            var xAxisIsHot  = (xAxisSlider == hotControl);
            var yAxisIsHot  = (yAxisSlider == hotControl);
            var zAxisIsHot  = (zAxisSlider == hotControl);
            var xzAxisIsHot = (xzPlaneSlider == hotControl);
            var xyAxisIsHot = (xyPlaneSlider == hotControl);
            var yzAxisIsHot = (yzPlaneSlider == hotControl);

            var isControlHot = xAxisIsHot || yAxisIsHot || zAxisIsHot || xzAxisIsHot || xyAxisIsHot || yzAxisIsHot;

            var size          = HandleUtility.GetHandleSize(position);
            var originalColor = Handles.color;

            var lockedAxisX = RealtimeCSG.CSGSettings.LockAxisX;
            var lockedAxisY = RealtimeCSG.CSGSettings.LockAxisY;
            var lockedAxisZ = RealtimeCSG.CSGSettings.LockAxisZ;

            var lockedAxisXY = lockedAxisX || lockedAxisY;
            var lockedAxisXZ = lockedAxisX || lockedAxisZ;
            var lockedAxisYZ = lockedAxisY || lockedAxisZ;


            //,.,.., look at 2018.1 how the position handle works w/ colors

            var xAxisDisabled   = isStatic || prevDisabled || lockedAxisX || (isControlHot && !xAxisIsHot && !xzAxisIsHot && !xyAxisIsHot);
            var yAxisDisabled   = isStatic || prevDisabled || lockedAxisY || (isControlHot && !yAxisIsHot && !xyAxisIsHot && !yzAxisIsHot);
            var zAxisDisabled   = isStatic || prevDisabled || lockedAxisZ || (isControlHot && !zAxisIsHot && !xzAxisIsHot && !yzAxisIsHot);
            var xzPlaneDisabled = isStatic || prevDisabled || lockedAxisXZ || (isControlHot && !xzAxisIsHot);
            var xyPlaneDisabled = isStatic || prevDisabled || lockedAxisXY || (isControlHot && !xyAxisIsHot);
            var yzPlaneDisabled = isStatic || prevDisabled || lockedAxisYZ || (isControlHot && !yzAxisIsHot);

            var currentFocusControl = FocusControl;

            var xAxisIndirectlyFocused = (currentFocusControl == xyPlaneSlider || currentFocusControl == xzPlaneSlider);
            var yAxisIndirectlyFocused = (currentFocusControl == xyPlaneSlider || currentFocusControl == yzPlaneSlider);
            var zAxisIndirectlyFocused = (currentFocusControl == xzPlaneSlider || currentFocusControl == yzPlaneSlider);

            var xAxisSelected = xAxisIndirectlyFocused || (currentFocusControl == xAxisSlider);
            var yAxisSelected = yAxisIndirectlyFocused || (currentFocusControl == yAxisSlider);
            var zAxisSelected = zAxisIndirectlyFocused || (currentFocusControl == zAxisSlider);
            var xzAxiSelected = (currentFocusControl == xAxisSlider || currentFocusControl == zAxisSlider);
            var xyAxiSelected = (currentFocusControl == xAxisSlider || currentFocusControl == yAxisSlider);
            var yzAxiSelected = (currentFocusControl == yAxisSlider || currentFocusControl == zAxisSlider);

            var xAxisColor   = CSGHandles.StateColor(Handles.xAxisColor, xAxisDisabled, xAxisSelected);
            var yAxisColor   = CSGHandles.StateColor(Handles.yAxisColor, yAxisDisabled, yAxisSelected);
            var zAxisColor   = CSGHandles.StateColor(Handles.zAxisColor, zAxisDisabled, zAxisSelected);
            var xzPlaneColor = CSGHandles.StateColor(Handles.yAxisColor, xzPlaneDisabled, xzAxiSelected);
            var xyPlaneColor = CSGHandles.StateColor(Handles.zAxisColor, xyPlaneDisabled, xyAxiSelected);
            var yzPlaneColor = CSGHandles.StateColor(Handles.xAxisColor, yzPlaneDisabled, yzAxiSelected);


            CSGHandles.disabled = xAxisDisabled;
            {
                Handles.color = xAxisColor;

                position = CSGSlider1D.Do(camera, xAxisSlider, position, rotation * Vector3.right, size, ArrowHandleCap, snapMode, snapVertices, initFunction, shutdownFunction);
            }

            CSGHandles.disabled = yAxisDisabled;
            {
                Handles.color = yAxisColor;

                position = CSGSlider1D.Do(camera, yAxisSlider, position, rotation * Vector3.up, size, ArrowHandleCap, snapMode, snapVertices, initFunction, shutdownFunction);
            }

            CSGHandles.disabled = zAxisDisabled;
            {
                Handles.color = zAxisColor;

                position = CSGSlider1D.Do(camera, zAxisSlider, position, rotation * Vector3.forward, size, ArrowHandleCap, snapMode, snapVertices, initFunction, shutdownFunction);
            }


            CSGHandles.disabled = xzPlaneDisabled;
            if (!CSGHandles.disabled)
            {
                Handles.color = xzPlaneColor;
                position      = DoPlanarHandle(camera, xzPlaneSlider, PrincipleAxis2.XZ, position, rotation, size * 0.25f, snapMode, snapVertices, initFunction, shutdownFunction);
            }

            CSGHandles.disabled = xyPlaneDisabled;
            if (!CSGHandles.disabled)
            {
                Handles.color = xyPlaneColor;
                position      = DoPlanarHandle(camera, xyPlaneSlider, PrincipleAxis2.XY, position, rotation, size * 0.25f, snapMode, snapVertices, initFunction, shutdownFunction);
            }

            CSGHandles.disabled = yzPlaneDisabled;
            if (!CSGHandles.disabled)
            {
                Handles.color = yzPlaneColor;
                position      = DoPlanarHandle(camera, yzPlaneSlider, PrincipleAxis2.YZ, position, rotation, size * 0.25f, snapMode, snapVertices, initFunction, shutdownFunction);
            }


            CSGHandles.disabled = prevDisabled;
            Handles.color       = originalColor;

            return(position);
        }