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

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

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

            --_stackPointer;

            foreach (IUndoRedoAction action in group.Actions)
            {
                if (UndoStart != null)
                {
                    UndoStart(action);
                }
                action.Undo();
                if (UndoEnd != null)
                {
                    UndoEnd(action);
                }
            }
        }
Example #2
0
 // Note: Currently not used. Causes performance issues.
 private void OnSceneCanRenderCameraIcon(Camera camera, YesNoAnswer answer)
 {
     if (camera == RTFocusCamera.Get.TargetCamera ||
         RTGizmosEngine.Get.IsSceneGizmoCamera(camera))
     {
         answer.No();
     }
 }
Example #3
0
 private void OnCanObjectSelectionClickAndMultiSelectDeselect(YesNoAnswer answer)
 {
     if (RTSceneGrid.Get.Hotkeys.SnapToCursorPickPoint.IsActive())
     {
         answer.No();
     }
     else
     {
         answer.Yes();
     }
 }
Example #4
0
 private void OnCanCameraProcessInput(YesNoAnswer answer)
 {
     if (RTGizmosEngine.Get.DraggedGizmo != null)
     {
         answer.No();
     }
     else
     {
         answer.Yes();
     }
 }
Example #5
0
 private void OnCanCameraUseScrollWheel(YesNoAnswer answer)
 {
     if (RTScene.Get.IsAnyUIElementHovered())
     {
         answer.No();
     }
     else
     {
         answer.Yes();
     }
 }
 /// <summary>
 /// Event handler for the 'CanClickSelectDeselect' and 'CanMultiSelectDeselect'
 /// events thrown by the object selection module. It allows us to stop objects
 /// from being selected as long as we are snapping.
 /// </summary>
 private void OnCanChangeObjectSelection(YesNoAnswer answer)
 {
     if (_isSnapSessionActive)
     {
         answer.No();
     }
     else
     {
         answer.Yes();
     }
 }
Example #7
0
 private void OnCanDoGizmoHoverUpdate(YesNoAnswer answer)
 {
     if (RTObjectSelection.Get != null &&
         RTObjectSelection.Get.IsMultiSelectShapeVisible)
     {
         answer.No();
     }
     else
     {
         answer.Yes();
     }
 }
Example #8
0
        private bool CanUseMouseScrollWheel()
        {
            if (CanUseScrollWheel == null)
            {
                return(true);
            }

            YesNoAnswer answer = new YesNoAnswer();

            CanUseScrollWheel(answer);
            return(answer.HasOnlyYes);
        }
Example #9
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);
        }
Example #10
0
        private void OnCanUndoRedo(UndoRedoOpType undoRedoOpType, YesNoAnswer answer)
        {
            if (RTGizmosEngine.Get.DraggedGizmo == null && !RTObjectSelection.Get.IsMultiSelectShapeVisible)
            {
                answer.Yes();
            }
            else
            {
                answer.No();
            }

            if (!RTObjectSelection.Get.IsManipSessionActive)
            {
                answer.Yes();
            }
            else
            {
                answer.No();
            }
        }
Example #11
0
        private void Redo()
        {
            if (!_isEnabled)
            {
                return;
            }
            if (_actionGroupStack.Count == 0 || _stackPointer == _actionGroupStack.Count - 1)
            {
                return;
            }

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

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

            ++_stackPointer;

            foreach (IUndoRedoAction action in group.Actions)
            {
                if (RedoStart != null)
                {
                    RedoStart(action);
                }
                action.Redo();
                if (RedoEnd != null)
                {
                    RedoEnd(action);
                }
            }
        }
        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();
        }
Example #13
0
        /// <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);
        }
        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;
        }
Example #15
0
        public void Render_SystemCall()
        {
            var iconMaterial = MaterialPool.Get.TintedTexture;
            var iconMesh     = MeshPool.Get.UnitQuadXY;

            Camera     renderCam          = Camera.current;
            Transform  renderCamTransform = renderCam.transform;
            Vector3    renderCamPos       = renderCamTransform.position;
            Quaternion renderCamRotation  = renderCamTransform.rotation;

            if (LookAndFeel.DrawCameraIcons && LookAndFeel.CameraIcon != null)
            {
                iconMaterial.SetTexture("_MainTex", LookAndFeel.CameraIcon);
                iconMaterial.SetColor(ColorEx.KeepAllButAlpha(Color.white, LookAndFeel.CameraIconAlpha));
                iconMaterial.SetZTestAlways();
                iconMaterial.SetPass(0);

                Vector3 scale = new Vector3(Settings.NonMeshObjectSize, Settings.NonMeshObjectSize, 1.0f);
                foreach (var camera in _cameras)
                {
                    if (camera != null && camera.gameObject.activeInHierarchy)
                    {
                        if (CanRenderCameraIconHandler != null)
                        {
                            var answer = new YesNoAnswer();
                            CanRenderCameraIconHandler(camera, answer);
                            if (answer.HasNo)
                            {
                                continue;
                            }
                        }

                        Transform  objectTransform = camera.gameObject.transform;
                        Vector3    position        = objectTransform.position;
                        Quaternion rotation        = renderCamTransform.rotation;

                        Matrix4x4 transformMatrix = Matrix4x4.TRS(position, rotation, scale);
                        Graphics.DrawMeshNow(iconMesh, transformMatrix);
                    }
                }
            }

            if (LookAndFeel.DrawParticleSystemIcons && LookAndFeel.ParticleSystemIcon != null)
            {
                iconMaterial.SetTexture("_MainTex", LookAndFeel.ParticleSystemIcon);
                iconMaterial.SetColor(ColorEx.KeepAllButAlpha(Color.white, LookAndFeel.ParticleSystemIconAlpha));
                iconMaterial.SetZTestAlways();
                iconMaterial.SetPass(0);

                Vector3 scale = new Vector3(Settings.NonMeshObjectSize, Settings.NonMeshObjectSize, 1.0f);
                foreach (var particleSystem in _particleSystems)
                {
                    if (particleSystem != null && particleSystem.gameObject.activeInHierarchy)
                    {
                        Transform  objectTransform = particleSystem.gameObject.transform;
                        Vector3    position        = objectTransform.position;
                        Quaternion rotation        = renderCamTransform.rotation;

                        Matrix4x4 transformMatrix = Matrix4x4.TRS(position, rotation, scale);
                        Graphics.DrawMeshNow(iconMesh, transformMatrix);
                    }
                }
            }

            if (LookAndFeel.DrawLightIcons && LookAndFeel.LightIcon != null)
            {
                iconMaterial.SetTexture("_MainTex", LookAndFeel.LightIcon);
                iconMaterial.SetZTestAlways();

                Vector3 scale = new Vector3(Settings.NonMeshObjectSize, Settings.NonMeshObjectSize, 1.0f);
                foreach (var light in _lights)
                {
                    if (light != null && light.enabled && light.gameObject.activeInHierarchy)
                    {
                        Transform  objectTransform = light.gameObject.transform;
                        Vector3    position        = objectTransform.position;
                        Quaternion rotation        = renderCamTransform.rotation;

                        Matrix4x4 transformMatrix = Matrix4x4.TRS(position, rotation, scale);

                        iconMaterial.SetColor(ColorEx.KeepAllButAlpha(light.color, LookAndFeel.LightIconAlpha));
                        iconMaterial.SetPass(0);
                        Graphics.DrawMeshNow(iconMesh, transformMatrix);
                    }
                }
            }
        }