Ejemplo n.º 1
0
        public GizmoHandleHoverData(Ray hoverRay, IGizmoHandle gizmoHandle, Vector2 hoverPt2D)
        {
            _handleId        = gizmoHandle.Id;
            _gizmo           = gizmoHandle.Gizmo;
            _handleDimension = GizmoDimension.Dim2D;

            _hoverRay   = hoverRay;
            _hoverPoint = hoverPt2D;
        }
        public void Add(IGizmoHandle handle)
        {
            if (Contains(handle) || handle.Gizmo != Gizmo)
            {
                return;
            }

            _handles.Add(handle);
            _idToHandle.Add(handle.Id, handle);
        }
Ejemplo n.º 3
0
        public GizmoHandleHoverData(Ray hoverRay, IGizmoHandle gizmoHandle, float hoverEnter3D)
        {
            _handleId        = gizmoHandle.Id;
            _gizmo           = gizmoHandle.Gizmo;
            _handleDimension = GizmoDimension.Dim3D;

            _hoverRay     = hoverRay;
            _hoverEnter3D = hoverEnter3D;
            _hoverPoint   = _hoverRay.GetPoint(_hoverEnter3D);
        }
Ejemplo n.º 4
0
        public void SetEnabled(bool enabled)
        {
            if (enabled == _isEnabled)
            {
                return;
            }

            if (!enabled)
            {
                EndDragSession();

                _hoverInfo.Reset();
                _hoveredHandle = null;

                _isEnabled = false;

                foreach (var behaviour in _behaviours)
                {
                    if (behaviour.IsEnabled)
                    {
                        behaviour.OnGizmoDisabled();
                    }
                }

                if (PostDisabled != null)
                {
                    PostDisabled(this);
                }
            }
            else
            {
                _isEnabled = true;

                foreach (var behaviour in _behaviours)
                {
                    if (behaviour.IsEnabled)
                    {
                        behaviour.OnGizmoEnabled();
                    }
                }

                if (PostEnabled != null)
                {
                    PostEnabled(this);
                }
            }
        }
Ejemplo n.º 5
0
        public Rect GetVisible2DHandlesRect(Camera camera)
        {
            List <Vector2> allRectPts = new List <Vector2>();
            int            numHandles = _handles.Count;

            for (int handleIndex = 0; handleIndex < numHandles; ++handleIndex)
            {
                IGizmoHandle handle     = _handles[handleIndex];
                Rect         handleRect = handle.GetVisible2DShapesRect(camera);
                if (handleRect.width != 0 || handleRect.height != 0)
                {
                    allRectPts.AddRange(handleRect.GetCornerPoints());
                }
            }

            if (allRectPts.Count != 0)
            {
                return(RectEx.FromPoints(allRectPts));
            }
            return(new Rect());
        }
Ejemplo n.º 6
0
        public AABB GetVisible3DHandlesAABB()
        {
            AABB aabb       = AABB.GetInvalid();
            int  numHandles = _handles.Count;

            for (int handleIndex = 0; handleIndex < numHandles; ++handleIndex)
            {
                IGizmoHandle handle     = _handles[handleIndex];
                AABB         handleAABB = handle.GetVisible3DShapesAABB();
                if (handleAABB.IsValid)
                {
                    if (aabb.IsValid)
                    {
                        aabb.Encapsulate(handleAABB);
                    }
                    else
                    {
                        aabb = handleAABB;
                    }
                }
            }

            return(aabb);
        }
 public void Remove(IGizmoHandle handle)
 {
     _handles.Remove(handle);
     _idToHandle.Remove(handle.Id);
 }
 public bool Contains(IGizmoHandle handle)
 {
     return(_idToHandle.ContainsKey(handle.Id));
 }
Ejemplo n.º 9
0
        public void UpdateHandleHoverInfo_SystemCall(GizmoHoverInfo hoverInfo)
        {
            if (!IsEnabled || IsDragged)
            {
                return;
            }

            bool wasHovered          = _hoverInfo.IsHovered;
            int  prevHoveredHandleId = _hoverInfo.HandleId;

            _hoverInfo.Reset();
            _hoveredHandle = null;

            if (hoverInfo.IsHovered && hoverInfo.HandleId != GizmoHandleId.None)
            {
                _hoverInfo.IsHovered       = true;
                _hoverInfo.HandleId        = hoverInfo.HandleId;
                _hoverInfo.HoverPoint      = hoverInfo.HoverPoint;
                _hoveredHandle             = _handles.GetHandleById(hoverInfo.HandleId);
                _hoverInfo.HandleDimension = hoverInfo.HandleDimension;
            }

            if (wasHovered && !_hoverInfo.IsHovered)
            {
                if (PreHoverExit != null)
                {
                    PreHoverExit(this, prevHoveredHandleId);
                }
                foreach (var behaviour in _behaviours)
                {
                    if (behaviour.IsEnabled)
                    {
                        behaviour.OnGizmoHoverExit(prevHoveredHandleId);
                    }
                }
                if (PostHoverExit != null)
                {
                    PostHoverExit(this, prevHoveredHandleId);
                }
            }
            else if (!wasHovered && _hoverInfo.IsHovered)
            {
                if (PreHoverEnter != null)
                {
                    PreHoverEnter(this, _hoverInfo.HandleId);
                }
                foreach (var behaviour in _behaviours)
                {
                    if (behaviour.IsEnabled)
                    {
                        behaviour.OnGizmoHoverEnter(_hoverInfo.HandleId);
                    }
                }
                if (PostHoverEnter != null)
                {
                    PostHoverEnter(this, _hoverInfo.HandleId);
                }
            }
            else
            if (wasHovered && _hoverInfo.IsHovered)
            {
                if (prevHoveredHandleId != _hoverInfo.HandleId)
                {
                    if (PreHoverExit != null)
                    {
                        PreHoverExit(this, prevHoveredHandleId);
                    }
                    foreach (var behaviour in _behaviours)
                    {
                        if (behaviour.IsEnabled)
                        {
                            behaviour.OnGizmoHoverExit(prevHoveredHandleId);
                        }
                    }
                    if (PostHoverExit != null)
                    {
                        PostHoverExit(this, prevHoveredHandleId);
                    }
                }

                if (PreHoverEnter != null)
                {
                    PreHoverEnter(this, _hoverInfo.HandleId);
                }
                foreach (var behaviour in _behaviours)
                {
                    if (behaviour.IsEnabled)
                    {
                        behaviour.OnGizmoHoverEnter(_hoverInfo.HandleId);
                    }
                }
                if (PostHoverEnter != null)
                {
                    PostHoverEnter(this, _hoverInfo.HandleId);
                }
            }
        }
Ejemplo n.º 10
0
        public GizmoHandleHoverData GetGizmoHandleHoverData(Gizmo gizmo)
        {
            Camera focusCamera = gizmo.FocusCamera;
            Ray    hoverRay    = RTInputDevice.Get.Device.GetRay(focusCamera);
            List <GizmoHandleHoverData> hoverDataCollection = gizmo.GetAllHandlesHoverData(hoverRay);

            Vector3 screenRayOrigin = focusCamera.WorldToScreenPoint(hoverRay.origin);

            hoverDataCollection.Sort(delegate(GizmoHandleHoverData h0, GizmoHandleHoverData h1)
            {
                IGizmoHandle handle0 = gizmo.GetHandleById_SystemCall(h0.HandleId);
                IGizmoHandle handle1 = gizmo.GetHandleById_SystemCall(h1.HandleId);

                // Same dimensions?
                bool sameDims = (h0.HandleDimension == h1.HandleDimension);
                if (sameDims)
                {
                    // 2D dimension?
                    if (h0.HandleDimension == GizmoDimension.Dim2D)
                    {
                        // If the priorities are equal, we sort by distance from screen ray origin.
                        // Otherwise, we sort by priority.
                        if (handle0.HoverPriority2D == handle1.HoverPriority2D)
                        {
                            float d0 = (screenRayOrigin - h0.HoverPoint).sqrMagnitude;
                            float d1 = (screenRayOrigin - h1.HoverPoint).sqrMagnitude;
                            return(d0.CompareTo(d1));
                        }
                        else
                        {
                            return(handle0.HoverPriority2D.CompareTo(handle1.HoverPriority2D));
                        }
                    }
                    // 3D dimension
                    else
                    {
                        // If the priorities are equal, we sort by hover enter. Otherwise, we sort by priority.
                        if (handle0.HoverPriority3D == handle1.HoverPriority3D)
                        {
                            return(h0.HoverEnter3D.CompareTo(h1.HoverEnter3D));
                        }
                        else
                        {
                            return(handle0.HoverPriority3D.CompareTo(handle1.HoverPriority3D));
                        }
                    }
                }
                else
                {
                    // When the dimensions differ, we will sort by the gizmo generic priority. If the priorities are equal,
                    // we will give priority to 2D handles.
                    if (handle0.GenericHoverPriority == handle1.GenericHoverPriority)
                    {
                        if (h0.HandleDimension == GizmoDimension.Dim2D)
                        {
                            return(-1);
                        }
                        return(1);
                    }
                    return(handle0.GenericHoverPriority.CompareTo(handle1.GenericHoverPriority));
                }
            });

            return(hoverDataCollection.Count != 0 ? hoverDataCollection[0] : null);
        }