예제 #1
0
        private void Undo()
        {
            if (!_isEnabled || _stackPointer < 0)
            {
                return;
            }

            var         group  = _actionGroupStack[_stackPointer];
            YesNoAnswer answer = new YesNoAnswer();

            if (CanUndoRedo != null)
            {
                CanUndoRedo(UndoRedoOpType.Undo, answer);
            }
            if (answer.HasNo)
            {
                return;
            }

            --_stackPointer;

            foreach (var action in group.Actions)
            {
                if (UndoStart != null)
                {
                    UndoStart(action);
                }
                action.Undo();
                if (UndoEnd != null)
                {
                    UndoEnd(action);
                }
            }
        }
예제 #2
0
 private void OnCanUndoRedo(UndoRedoOpType undoRedoOpType, YesNoAnswer answer)
 {
     if (RTGizmosEngine.Get.DraggedGizmo == null)
     {
         answer.Yes();
     }
     else
     {
         answer.No();
     }
 }
예제 #3
0
 private void OnCanCameraProcessInput(YesNoAnswer answer)
 {
     if (RTGizmosEngine.Get.DraggedGizmo != null)
     {
         answer.No();
     }
     else
     {
         answer.Yes();
     }
 }
예제 #4
0
 private void OnCanCameraUseScrollWheel(YesNoAnswer answer)
 {
     if (RTScene.Get.IsAnyUIElementHovered())
     {
         answer.No();
     }
     else
     {
         answer.Yes();
     }
 }
예제 #5
0
        private bool CanUseMouseScrollWheel()
        {
            if (CanUseScrollWheel == null)
            {
                return(true);
            }

            YesNoAnswer answer = new YesNoAnswer();

            CanUseScrollWheel(answer);
            return(answer.HasOnlyYes);
        }
예제 #6
0
        private bool CanCameraProcessInput()
        {
            if (!_settings.CanProcessInput || _isDoingFocus ||
                IsDoingProjectionSwitch || _isDoingRotationSwitch)
            {
                return(false);
            }

            if (CanProcessInput == null)
            {
                return(true);
            }

            YesNoAnswer answer = new YesNoAnswer();

            CanProcessInput(answer);
            return(answer.HasOnlyYes);
        }
예제 #7
0
        private void Redo()
        {
            if (!_isEnabled)
            {
                return;
            }
            if (_actionGroupStack.Count == 0 || _stackPointer == _actionGroupStack.Count - 1)
            {
                return;
            }

            var         group  = _actionGroupStack[_stackPointer + 1];
            YesNoAnswer answer = new YesNoAnswer();

            if (CanUndoRedo != null)
            {
                CanUndoRedo(UndoRedoOpType.Redo, answer);
            }
            if (answer.HasNo)
            {
                return;
            }

            ++_stackPointer;

            foreach (var action in group.Actions)
            {
                if (RedoStart != null)
                {
                    RedoStart(action);
                }
                action.Redo();
                if (RedoEnd != null)
                {
                    RedoEnd(action);
                }
            }
        }
예제 #8
0
        public void Update_SystemCall()
        {
            foreach (var sceneGizmoCam in _sceneGizmoCameras)
            {
                sceneGizmoCam.Update_SystemCall();
            }

            _pipelineStage = GizmosEnginePipelineStage.Update;
            IInputDevice inputDevice      = RTInputDevice.Get.Device;
            bool         deviceHasPointer = inputDevice.HasPointer();
            Vector3      inputDevicePos   = inputDevice.GetPositionYAxisUp();

            bool isUIHovered        = RTScene.Get.IsAnyUIElementHovered();
            bool canUpdateHoverInfo = _draggedGizmo == null && !isUIHovered;

            if (canUpdateHoverInfo)
            {
                YesNoAnswer answer = new YesNoAnswer();
                if (CanDoHoverUpdate != null)
                {
                    CanDoHoverUpdate(answer);
                }
                if (answer.HasNo)
                {
                    canUpdateHoverInfo = false;
                }
            }

            if (canUpdateHoverInfo)
            {
                _hoveredGizmo = null;
                _gizmoHoverInfo.Reset();
            }

            bool isDeviceInsideFocusCamera  = deviceHasPointer && RTFocusCamera.Get.IsViewportHoveredByDevice(); //RTFocusCamera.Get.TargetCamera.pixelRect.Contains(inputDevicePos);
            bool focusCameraCanRenderGizmos = IsRenderCamera(RTFocusCamera.Get.TargetCamera);
            var  hoverDataCollection        = new List <GizmoHandleHoverData>(10);

            foreach (var gizmo in _gizmos)
            {
                gizmo.OnUpdateBegin_SystemCall();
                if (canUpdateHoverInfo && gizmo.IsEnabled &&
                    isDeviceInsideFocusCamera && deviceHasPointer && focusCameraCanRenderGizmos)
                {
                    var handleHoverData = GetGizmoHandleHoverData(gizmo);
                    if (handleHoverData != null)
                    {
                        hoverDataCollection.Add(handleHoverData);
                    }
                }
            }

            GizmoHandleHoverData hoverData = null;

            if (canUpdateHoverInfo && hoverDataCollection.Count != 0)
            {
                SortHandleHoverDataCollection(hoverDataCollection, inputDevicePos);

                hoverData                       = hoverDataCollection[0];
                _hoveredGizmo                   = hoverData.Gizmo;
                _gizmoHoverInfo.HandleId        = hoverData.HandleId;
                _gizmoHoverInfo.HandleDimension = hoverData.HandleDimension;
                _gizmoHoverInfo.HoverPoint      = hoverData.HoverPoint;
                _gizmoHoverInfo.IsHovered       = true;
            }

            foreach (var gizmo in _gizmos)
            {
                _gizmoHoverInfo.IsHovered = (gizmo == _hoveredGizmo);
                gizmo.UpdateHandleHoverInfo_SystemCall(_gizmoHoverInfo);

                gizmo.HandleInputDeviceEvents_SystemCall();
                gizmo.OnUpdateEnd_SystemCall();
            }

            _pipelineStage = GizmosEnginePipelineStage.PostUpdate;
        }
        /// <summary>
        /// This function traverses the handle's 2D and 3D shapes and decides which one is hovered
        /// by the specified ray. It then returns the hover information inside an instance of the
        /// 'GizmoHandleHoverData' class. The ray should be created using the 'Camera.ScreenPointToRay'
        /// function and it represents the ray which is cast out from the screen into the 3D scene.
        /// The function will always give priority to 2D shapes. So for example, if the handle has
        /// a 2D and a 3D shape, and the ray hovers both of them, only the 2D shape will be taken into
        /// account.
        /// </summary>
        /// <param name="hoverRay">
        /// The hover ray. This should be created using the 'Camera.ScreenPointToRay' function. The
        /// function will convert the origin of the ray in screen space to detect the 2D shapes which
        /// are hovered by the ray.
        /// </param>
        /// <returns>
        /// If a shape is hovered by the input ray, the function returns an instance of the
        /// 'GizmoHandleHoverData' class. Otherwise, it returns null. The function also returns
        /// null if there are any subscribers to the 'CanHover' event that don't allow the handle
        /// to be hovered.
        /// </returns>
        public GizmoHandleHoverData GetHoverData(Ray hoverRay)
        {
            float minDist = float.MaxValue;
            GizmoHandleHoverData handleHoverData = null;

            if (Is2DHoverable && Is2DVisible)
            {
                Vector2            screenRayOrigin = Gizmo.GetWorkCamera().WorldToScreenPoint(hoverRay.origin);
                GizmoHandleShape2D hovered2DShape  = null;
                foreach (var shape in _2DShapes)
                {
                    if (shape.IsVisible && shape.IsHoverable)
                    {
                        if (shape.Shape.ContainsPoint(screenRayOrigin))
                        {
                            float dist = (shape.Shape.GetEncapsulatingRect().center - screenRayOrigin).magnitude;
                            if (hovered2DShape == null || dist < minDist)
                            {
                                hovered2DShape = shape;
                                minDist        = dist;
                            }
                        }
                    }
                }

                if (hovered2DShape != null)
                {
                    handleHoverData = new GizmoHandleHoverData(hoverRay, this, screenRayOrigin);
                    if (CanHover != null)
                    {
                        var answer = new YesNoAnswer();
                        CanHover(Id, Gizmo, handleHoverData, answer);
                        if (answer.HasNo)
                        {
                            return(null);
                        }
                    }
                    return(handleHoverData);
                }
            }

            if (Is3DHoverable && Is3DVisible)
            {
                minDist = float.MaxValue;
                GizmoHandleShape3D hovered3DShape = null;
                foreach (var shape in _3DShapes)
                {
                    if (shape.IsVisible && shape.IsHoverable)
                    {
                        float t;
                        if (shape.Shape.Raycast(hoverRay, out t))
                        {
                            if (hovered3DShape == null || t < minDist)
                            {
                                hovered3DShape = shape;
                                minDist        = t;
                            }
                        }
                    }
                }

                if (hovered3DShape != null)
                {
                    handleHoverData = new GizmoHandleHoverData(hoverRay, this, minDist);
                    if (CanHover != null)
                    {
                        var answer = new YesNoAnswer();
                        CanHover(Id, Gizmo, handleHoverData, answer);
                        if (answer.HasNo)
                        {
                            return(null);
                        }
                    }

                    return(handleHoverData);
                }
            }

            return(null);
        }
예제 #10
0
        public void Update_SystemCall()
        {
            foreach (var sceneGizmoCam in _sceneGizmoCameras)
            {
                sceneGizmoCam.Update_SystemCall();
            }

            _pipelineStage = GizmosEnginePipelineStage.Update;
            IInputDevice inputDevice      = RTInputDevice.Get.Device;
            bool         deviceHasPointer = inputDevice.HasPointer();
            Vector3      inputDevicePos   = inputDevice.GetPositionYAxisUp();

            bool isUIHovered        = RTScene.Get.IsAnyUIElementHovered();
            bool canUpdateHoverInfo = _draggedGizmo == null && !isUIHovered;

            if (canUpdateHoverInfo)
            {
                YesNoAnswer answer = new YesNoAnswer();
                if (CanDoHoverUpdate != null)
                {
                    CanDoHoverUpdate(answer);
                }
                if (answer.HasNo)
                {
                    canUpdateHoverInfo = false;
                }
            }

            //if (canUpdateHoverInfo)
            {
                // Note: We always reset the hovered info even if the UI is hovered. This is because
                //       we want to catch special cases where the mouse cursor moves from the gizmo
                //       over to the UI. In that case, if we don't reset the hovered info, the gizmo
                //       will be affected by mouse movements when interacting with the UI.
                _hoveredGizmo = null;
                _gizmoHoverInfo.Reset();
            }

            bool isDeviceInsideFocusCamera  = deviceHasPointer && RTFocusCamera.Get.IsViewportHoveredByDevice(); //RTFocusCamera.Get.TargetCamera.pixelRect.Contains(inputDevicePos);
            bool focusCameraCanRenderGizmos = IsRenderCamera(RTFocusCamera.Get.TargetCamera);
            var  hoverDataCollection        = new List <GizmoHandleHoverData>(10);

            foreach (var gizmo in _gizmos)
            {
                gizmo.OnUpdateBegin_SystemCall();
                if (canUpdateHoverInfo && gizmo.IsEnabled &&
                    isDeviceInsideFocusCamera && deviceHasPointer && focusCameraCanRenderGizmos)
                {
                    var handleHoverData = GetGizmoHandleHoverData(gizmo);
                    if (handleHoverData != null)
                    {
                        hoverDataCollection.Add(handleHoverData);
                    }
                }
            }

            GizmoHandleHoverData hoverData = null;

            if (canUpdateHoverInfo && hoverDataCollection.Count != 0)
            {
                SortHandleHoverDataCollection(hoverDataCollection, inputDevicePos);

                hoverData                       = hoverDataCollection[0];
                _hoveredGizmo                   = hoverData.Gizmo;
                _gizmoHoverInfo.HandleId        = hoverData.HandleId;
                _gizmoHoverInfo.HandleDimension = hoverData.HandleDimension;
                _gizmoHoverInfo.HoverPoint      = hoverData.HoverPoint;
                _gizmoHoverInfo.IsHovered       = true;
            }

            foreach (var gizmo in _gizmos)
            {
                _gizmoHoverInfo.IsHovered = (gizmo == _hoveredGizmo);
                gizmo.UpdateHandleHoverInfo_SystemCall(_gizmoHoverInfo);

                gizmo.HandleInputDeviceEvents_SystemCall();
                gizmo.OnUpdateEnd_SystemCall();
            }

            _pipelineStage = GizmosEnginePipelineStage.PostUpdate;
        }
예제 #11
0
 private void OnCanDoGizmoHoverUpdate(YesNoAnswer answer)
 {
     answer.Yes();
 }
예제 #12
0
        private void OnCanHoverHandle(int handleId, Gizmo gizmo, GizmoHandleHoverData hoverData, YesNoAnswer answer)
        {
            if (handleId == HandleId && gizmo == Gizmo)
            {
                if (LookAndFeel.PlaneType == GizmoPlane3DType.Circle && Settings.IsCircleHoverCullEnabled)
                {
                    Vector3 hoverNormal = (hoverData.HoverPoint - Position).normalized;
                    if (Gizmo.FocusCamera.IsPointFacingCamera(hoverData.HoverPoint, hoverNormal))
                    {
                        answer.Yes();
                    }
                    else
                    {
                        answer.No();
                    }
                    return;
                }
            }

            answer.Yes();
        }