Пример #1
0
 private void OnTranslationGizmoPostUpdateEnd(RTG.Gizmo gizmo)
 {
     if (m_selectedJoint == null || !m_selectedJoint.CompareTag("TargetJoint"))
     {
         return;
     }
     m_jointController.SolveIK(m_selectedJoint, m_selectedJoint.transform.position);
 }
Пример #2
0
    private void OnRotationGizmoPostUpdateEnd(RTG.Gizmo gizmo)
    {
        if (m_selectedJoint == null)
        {
            return;
        }

        m_jointController.EditKeyRotation(m_selectedJoint);
        m_objectTranslationGizmo.SetTargetObject(m_selectedJoint);
    }
Пример #3
0
    private void OnTranslationGizmoPostUpdateEnd(RTG.Gizmo gizmo)
    {
        if (m_selectedPoint == null)
        {
            return;
        }

        if (m_selectedPoint.CompareTag("KeyPoint"))
        {
            m_curveController.EditVecKey(m_selectedPoint, m_selectedPoint.transform.position);
        }
        else if (m_selectedPoint.CompareTag("ControlPoint"))
        {
            m_curveController.EditVecControlPoint(m_selectedPoint, m_selectedPoint.transform.position);
        }
    }
Пример #4
0
    private void OnRotationGizmoPostUpdateEnd(RTG.Gizmo gizmo)
    {
        if (m_selectedPoint == null)
        {
            return;
        }
        // Update the axes
        m_objectTranslationGizmo.Gizmo.SetEnabled(false);
        m_objectTranslationGizmo.SetTargetObject(m_selectedPoint);
        m_objectTranslationGizmo.Gizmo.SetEnabled(true);

        if (m_selectedPoint.CompareTag("KeyPoint"))
        {
            m_curveController.EditRotationKey(m_selectedPoint, m_selectedPoint.transform.rotation);
        }
    }
        public GizmoCap3D(Gizmo gizmo, int handleId)
            : base(gizmo, handleId)
        {
            _coneIndex    = Handle.Add3DShape(_cone);
            _pyramidIndex = Handle.Add3DShape(_pyramid);
            _boxIndex     = Handle.Add3DShape(_box);
            _sphereIndex  = Handle.Add3DShape(_sphere);
            _trPrismIndex = Handle.Add3DShape(_trPrism);

            SetZoomFactorTransform(_transform);

            _controllerData.Gizmo        = Gizmo;
            _controllerData.Cap          = this;
            _controllerData.CapHandle    = Handle;
            _controllerData.Cone         = _cone;
            _controllerData.ConeIndex    = _coneIndex;
            _controllerData.Pyramid      = _pyramid;
            _controllerData.PyramidIndex = _pyramidIndex;
            _controllerData.Box          = _box;
            _controllerData.BoxIndex     = _boxIndex;
            _controllerData.Sphere       = _sphere;
            _controllerData.SphereIndex  = _sphereIndex;
            _controllerData.TrPrism      = _trPrism;
            _controllerData.TrPrismIndex = _trPrismIndex;

            _controllers[(int)GizmoCap3DType.Cone]        = new GizmoConeCap3DController(_controllerData);
            _controllers[(int)GizmoCap3DType.Pyramid]     = new GizmoPyramidCap3DController(_controllerData);
            _controllers[(int)GizmoCap3DType.Box]         = new GizmoBoxCap3DController(_controllerData);
            _controllers[(int)GizmoCap3DType.Sphere]      = new GizmoSphereCap3DController(_controllerData);
            _controllers[(int)GizmoCap3DType.TriangPrism] = new GizmoTriPrismCap3DController(_controllerData);

            _transform.Changed += OnTransformChanged;
            _transform.SetParent(Gizmo.Transform);
            Gizmo.PreUpdateBegin += OnGizmoPreUpdateBegin;
            Gizmo.PostEnabled    += OnGizmoPostEnabled;
            Gizmo.PostDisabled   += OnGizmoPostDisabled;
        }
        public GizmoLineSlider2D(Gizmo gizmo, int handleId, int capHandleId)
            : base(gizmo, handleId)
        {
            _segmentIndex = Handle.Add2DShape(_segment);
            _quadIndex    = Handle.Add2DShape(_quad);

            _controllerData.Gizmo        = Gizmo;
            _controllerData.Slider       = this;
            _controllerData.SliderHandle = Handle;
            _controllerData.Segment      = _segment;
            _controllerData.SegmentIndex = _segmentIndex;
            _controllerData.Quad         = _quad;
            _controllerData.QuadIndex    = _quadIndex;

            _controllers[(int)GizmoLine2DType.Thin] = new GizmoThinLineSlider2DController(_controllerData);
            _controllers[(int)GizmoLine2DType.Box]  = new GizmoBoxLineSlider2DController(_controllerData);

            _cap2D = new GizmoCap2D(gizmo, capHandleId);
            SetupSharedLookAndFeel();

            SetDragChannel(GizmoDragChannel.Offset);
            AddTargetTransform(Gizmo.Transform);
            AddTargetTransform(_transform);
            _cap2D.RegisterTransformAsDragTarget(_offsetDrag);
            _cap2D.RegisterTransformAsDragTarget(_rotationDrag);

            _transform.Changed += OnTransformChanged;
            _transform.SetParent(gizmo.Transform);

            Gizmo.PreUpdateBegin      += OnGizmoPreUpdateBegin;
            Gizmo.PreDragUpdate       += OnGizmoHandleDragUpdate;
            Gizmo.PreDragBeginAttempt += OnGizmoAttemptHandleDragBegin;
            Gizmo.PreHoverEnter       += OnGizmoHandleHoverEnter;
            Gizmo.PreHoverExit        += OnGizmoHandleHoverExit;
            Gizmo.PostEnabled         += OnGizmoPostEnabled;
        }
Пример #7
0
 private void OnGizmoPostEnabled(Gizmo gizmo)
 {
     Refresh();
 }
Пример #8
0
        public float GetRealQuadHeight()
        {
            float scaleFactor = 1.0f;

            if (IsScaling)
            {
                Vector3 realScaleAxis   = _scaleAxisUp * TotalDragScaleUp;
                Vector2 screenScaleAxis = Vector3Ex.ConvertDirTo2D(ScaleDragOrigin, ScaleDragOrigin + realScaleAxis, Gizmo.GetWorkCamera());
                scaleFactor = screenScaleAxis.magnitude / (LookAndFeel.QuadHeight * LookAndFeel.Scale * 0.5f) * Mathf.Sign(TotalDragScaleUp);
            }

            return(LookAndFeel.QuadHeight * LookAndFeel.Scale * scaleFactor);
        }
Пример #9
0
        public float GetRealCircleRadius()
        {
            float scaleFactor = 1.0f;

            if (IsScaling)
            {
                float maxTotalDragScale = TotalDragScaleRight;
                if (Mathf.Abs(TotalDragScaleRight) < Mathf.Abs(TotalDragScaleUp))
                {
                    maxTotalDragScale = TotalDragScaleUp;
                }

                Vector3 realScaleAxis   = _scaleAxisUp * maxTotalDragScale;
                Vector2 screenScaleAxis = Vector3Ex.ConvertDirTo2D(ScaleDragOrigin, ScaleDragOrigin + realScaleAxis, Gizmo.GetWorkCamera());
                scaleFactor = (screenScaleAxis.magnitude / (LookAndFeel.CircleRadius * LookAndFeel.Scale)) * Mathf.Sign(maxTotalDragScale);
            }

            return(LookAndFeel.CircleRadius * LookAndFeel.Scale * scaleFactor);
        }
Пример #10
0
 /// <summary>
 /// Returns the size (length and thickness) of the slider along the specified direction
 /// axis. The function will take into accoun the look and feel settings such as the slider
 /// type (line, box, cylinder), scale and whether or not a zoom factor should be applied.
 /// </summary>
 /// <param name="camera">
 /// This is the camera needed to calculate the slider zoom factor if necessary.
 /// </param>
 /// <param name="direction">
 /// The direction along which the slider size will be calculated.
 /// </param>
 public float GetRealSizeAlongDirection(Camera camera, Vector3 direction)
 {
     return(_controllers[(int)LookAndFeel.LineType].GetRealSizeAlongDirection(direction, GetZoomFactor(Gizmo.GetWorkCamera())));
 }
        /// <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);
        }
Пример #12
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;
        }
Пример #13
0
 private void RegisterGizmo(Gizmo gizmo)
 {
     _gizmos.Add(gizmo);
     gizmo.PreDragBegin += OnGizmoDragBegin;
     gizmo.PreDragEnd   += OnGizmoDragEnd;
 }
Пример #14
0
        private void OnGizmoAttemptHandleDragBegin(Gizmo gizmo, int handleId)
        {
            if (handleId == HandleId)
            {
                if (_dragChannel == GizmoDragChannel.Offset)
                {
                    GizmoDblAxisOffsetDrag3D.WorkData workData = new GizmoDblAxisOffsetDrag3D.WorkData();
                    workData.Axis0      = Vector2Ex.ConvertDirTo3D(_transform.Right2D, OffsetDragOrigin, Gizmo.FocusCamera).normalized;
                    workData.Axis1      = Vector2Ex.ConvertDirTo3D(_transform.Up2D, OffsetDragOrigin, Gizmo.FocusCamera).normalized;
                    workData.DragOrigin = OffsetDragOrigin;
                    workData.SnapStep0  = Settings.OffsetSnapStepRight;
                    workData.SnapStep1  = Settings.OffsetSnapStepUp;
                    _offsetDrag.SetWorkData(workData);
                }
                else
                if (_dragChannel == GizmoDragChannel.Rotation)
                {
                    GizmoSglAxisRotationDrag3D.WorkData workData = new GizmoSglAxisRotationDrag3D.WorkData();
                    workData.Axis     = Gizmo.FocusCamera.transform.forward;
                    workData.SnapMode = Settings.RotationSnapMode;
                    workData.SnapStep = Settings.RotationSnapStep;
                    if (LookAndFeel.PlaneType != GizmoPlane2DType.Polygon)
                    {
                        workData.RotationPlanePos = Gizmo.FocusCamera.ScreenToWorldPoint(new Vector3(Position.x, Position.y, Gizmo.FocusCamera.nearClipPlane));
                    }

                    if (LookAndFeel.PlaneType == GizmoPlane2DType.Circle)
                    {
                        _rotationArc.SetArcData(Position, Gizmo.HoverInfo.HoverPoint, GetRealCircleRadius());
                        _rotationArc.Type = GizmoRotationArc2D.ArcType.Standard;
                    }
                    else
                    if (LookAndFeel.PlaneType == GizmoPlane2DType.Polygon)
                    {
                        Vector3 polyCenter = PolyCenter;
                        workData.RotationPlanePos = Gizmo.FocusCamera.ScreenToWorldPoint(new Vector3(polyCenter.x, polyCenter.y, Gizmo.FocusCamera.nearClipPlane));
                        _rotationArc.SetArcData(PolyCenter, Gizmo.HoverInfo.HoverPoint, 1.0f);
                        _rotationArc.Type               = GizmoRotationArc2D.ArcType.PolyProjected;
                        _rotationArc.ProjectionPoly     = _polygon;
                        _rotationArc.NumProjectedPoints = 100;
                    }
                    _rotationDrag.SetWorkData(workData);
                }
                else
                if (_dragChannel == GizmoDragChannel.Scale)
                {
                    _scaleAxisRight = Vector2Ex.ConvertDirTo3D(Position, GetRealExtentPoint(Shape2DExtentPoint.Right), ScaleDragOrigin, Gizmo.FocusCamera);
                    _scaleAxisUp    = Vector2Ex.ConvertDirTo3D(Position, GetRealExtentPoint(Shape2DExtentPoint.Top), ScaleDragOrigin, Gizmo.FocusCamera);

                    GizmoDblAxisScaleDrag3D.WorkData workData = new GizmoDblAxisScaleDrag3D.WorkData();
                    workData.Axis0        = _scaleAxisRight.normalized;
                    workData.Axis1        = _scaleAxisUp.normalized;
                    workData.AxisIndex0   = _scaleDragAxisIndexRight;
                    workData.AxisIndex1   = _scaleDragAxisIndexUp;
                    workData.DragOrigin   = ScaleDragOrigin;
                    workData.ScaleMode    = Settings.ScaleMode;
                    workData.IndBaseSize0 = _scaleAxisRight.magnitude;
                    workData.IndBaseSize1 = _scaleAxisUp.magnitude;

                    if (workData.ScaleMode == GizmoDblAxisScaleMode.Independent)
                    {
                        workData.IndSnapStep0 = Settings.ScaleSnapStepRight;
                        workData.IndSnapStep1 = Settings.ScaleSnapStepUp;
                        workData.IndBaseSize0 = _scaleAxisRight.magnitude;
                        workData.IndBaseSize1 = _scaleAxisUp.magnitude;
                    }
                    else
                    {
                        Vector2 triSides = new Vector2(_scaleAxisRight.magnitude, _scaleAxisUp.magnitude);
                        workData.PropBaseSize = TriangleMath.CalcRATriangleHypotenuse(triSides);
                        workData.PropSnapStep = Settings.ProportionalScaleSnapStep;
                        workData.PropAxis     = ((Right + Up) * 0.5f).normalized;
                    }

                    _scaleDrag.SetWorkData(workData);
                }
            }
        }
Пример #15
0
 private void OnGizmoDragEnd(Gizmo gizmo, int handleId)
 {
     _draggedGizmo = null;
 }
Пример #16
0
 public override void OnGizmoAttemptHandleDragBegin(int handleId)
 {
     if (handleId == _rtMidCap.HandleId)
     {
         var workData = new GizmoDblAxisRotationDrag3D.WorkData();
         workData.Axis0       = Gizmo.FocusCamera.transform.up;
         workData.Axis1       = Gizmo.FocusCamera.transform.right;
         workData.ScreenAxis0 = -Vector3.right;
         workData.ScreenAxis1 = Vector3.up;
         workData.SnapMode    = Settings3D.RtSnapMode;
         workData.SnapStep0   = Settings3D.RtCamUpSnapStep;
         workData.SnapStep1   = Settings3D.RtCamRightSnapStep;
         _rtCamXYRotationDrag.SetWorkData(workData);
     }
     else if (handleId == _scMidCap.HandleId)
     {
         var workData = new GizmoUniformScaleDrag3D.WorkData();
         workData.BaseSize    = _scMidCap.GetRealBoxSize(_scMidCap.GetZoomFactor(Gizmo.GetWorkCamera())).magnitude;
         workData.DragOrigin  = _scMidCap.Position;
         workData.CameraRight = Gizmo.FocusCamera.transform.right;
         workData.CameraUp    = Gizmo.FocusCamera.transform.up;
         workData.SnapStep    = Settings3D.ScUniformSnapStep;
         _scUnformScaleDrag.SetWorkData(workData);
     }
 }
Пример #17
0
 private void Update2DGizmoPosition()
 {
     Gizmo.Transform.Position2D = Gizmo.GetWorkCamera().WorldToScreenPoint(Gizmo.Transform.Position3D);
 }
 public void Init_SystemCall(GizmoBehaviorInitParams initParams)
 {
     _gizmo = initParams.Gizmo;
 }
Пример #19
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="gizmo">The gizmo which owns the slider.</param>
 /// <param name="handleId">The id of the slider handle.</param>
 public GizmoSlider(Gizmo gizmo, int handleId)
 {
     _gizmo  = gizmo;
     _handle = Gizmo.CreateHandle(handleId);
 }
Пример #20
0
 private void OnGizmoPostDisabled(Gizmo gizmo)
 {
     OverrideColor.IsActive        = false;
     _cap3D.OverrideColor.IsActive = false;
 }
Пример #21
0
 private void OnGizmoPreUpdateBegin(Gizmo gizmo)
 {
     _sceneGizmo.LookAndFeel.ConnectMidCapLookAndFeel(_cap);
 }
 public GizmoHandleCollection(Gizmo gizmo)
 {
     _gizmo = gizmo;
 }
Пример #23
0
        private void OnGizmoAttemptHandleDragBegin(Gizmo gizmo, int handleId)
        {
            if (handleId == HandleId)
            {
                if (_dragChannel == GizmoDragChannel.Offset)
                {
                    GizmoDblAxisOffsetDrag3D.WorkData workData = new GizmoDblAxisOffsetDrag3D.WorkData();
                    workData.Axis0      = Right;
                    workData.Axis1      = Up;
                    workData.DragOrigin = Position;
                    workData.SnapStep0  = Settings.OffsetSnapStepRight;
                    workData.SnapStep1  = Settings.OffsetSnapStepUp;
                    _dblAxisOffsetDrag.SetWorkData(workData);
                }
                else
                if (_dragChannel == GizmoDragChannel.Rotation)
                {
                    GizmoSglAxisRotationDrag3D.WorkData workData = new GizmoSglAxisRotationDrag3D.WorkData();
                    workData.Axis             = Normal;
                    workData.RotationPlanePos = Position;
                    workData.SnapMode         = Settings.RotationSnapMode;
                    workData.SnapStep         = Settings.RotationSnapStep;
                    _rotationDrag.SetWorkData(workData);

                    Vector3 arcStart = Plane.ProjectPoint(Gizmo.HoverInfo.HoverPoint);
                    _rotationArc.SetArcData(Normal, Position, arcStart, GetRealCircleRadius(GetZoomFactor(Gizmo.FocusCamera)));
                }
                else
                if (_dragChannel == GizmoDragChannel.Scale)
                {
                    float zoomFactor = GetZoomFactor(Gizmo.FocusCamera);

                    GizmoDblAxisScaleDrag3D.WorkData workData = new GizmoDblAxisScaleDrag3D.WorkData();
                    workData.Axis0      = Right;
                    workData.Axis1      = Up;
                    workData.DragOrigin = Position;
                    workData.AxisIndex0 = _scaleDragAxisIndexRight;
                    workData.AxisIndex1 = _scaleDragAxisIndexUp;
                    workData.ScaleMode  = Settings.ScaleMode;

                    if (workData.ScaleMode == GizmoDblAxisScaleMode.Independent)
                    {
                        workData.IndSnapStep0 = Settings.ScaleSnapStepRight;
                        workData.IndSnapStep1 = Settings.ScaleSnapStepUp;

                        if (LookAndFeel.PlaneType == GizmoPlane3DType.Quad)
                        {
                            workData.IndBaseSize0 = GetRealQuadWidth(zoomFactor) * 0.5f;
                            workData.IndBaseSize1 = GetRealQuadHeight(zoomFactor) * 0.5f;
                        }
                        else
                        if (LookAndFeel.PlaneType == GizmoPlane3DType.RATriangle)
                        {
                            workData.IndBaseSize0 = GetRealRATriXLength(zoomFactor);
                            workData.IndBaseSize1 = GetRealRATriYLength(zoomFactor);
                        }
                    }
                    else
                    {
                        if (LookAndFeel.PlaneType == GizmoPlane3DType.Quad)
                        {
                            workData.PropBaseSize = TriangleMath.CalcRATriangleHypotenuse(GetRealQuadSize(zoomFactor) * 0.5f);
                        }
                        else
                        if (LookAndFeel.PlaneType == GizmoPlane3DType.RATriangle)
                        {
                            workData.PropBaseSize = TriangleMath.CalcRATriangleAltitude(GetRealRATriSize(zoomFactor));
                        }

                        workData.PropSnapStep = Settings.ProportionalScaleSnapStep;
                        workData.PropAxis     = ((Right + Up) * 0.5f).normalized;
                    }

                    _scaleDrag.SetWorkData(workData);
                }
            }
        }
Пример #24
0
 public void RemoveGizmo(Gizmo gizmo)
 {
     UnregisterGizmo(gizmo);
 }
Пример #25
0
        public GizmoHandleHoverData GetGizmoHandleHoverData(Gizmo gizmo)
        {
            Camera focusCamera         = gizmo.FocusCamera;
            Ray    hoverRay            = RTInputDevice.Get.Device.GetRay(focusCamera);
            var    hoverDataCollection = gizmo.GetAllHandlesHoverData(hoverRay);

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

            hoverDataCollection.Sort(delegate(GizmoHandleHoverData h0, GizmoHandleHoverData h1)
            {
                var handle0 = gizmo.GetHandleById_SystemCall(h0.HandleId);
                var 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);
        }
Пример #26
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;
        }
Пример #27
0
 private void OnGizmoDragBegin(Gizmo gizmo, int handleId)
 {
     _draggedGizmo = gizmo;
 }
Пример #28
0
 private void OnGizmoPreUpdateBegin(Gizmo gizmo)
 {
     _handle.Is2DVisible = _sceneGizmo.LookAndFeel.IsCamPrjSwitchLabelVisible;
     UpdateTransform();
 }
Пример #29
0
 private void OnGizmoPreUpdateBegin(Gizmo gizmo)
 {
     _controllers[(int)_planeSlider.LookAndFeel.PolygonBorderType].UpdateHandles();
     _controllers[(int)_planeSlider.LookAndFeel.PolygonBorderType].UpdateEpsilons();
 }
        public float GetRealLength()
        {
            float scaleFactor = 1.0f;

            if (IsScaling)
            {
                Vector3 realScaleAxis   = _scaleAxis * TotalDragScale;
                Vector2 screenScaleAxis = Vector3Ex.ConvertDirTo2D(ScaleDragOrigin, ScaleDragOrigin + realScaleAxis, Gizmo.GetWorkCamera());
                scaleFactor = (screenScaleAxis.magnitude / (LookAndFeel.Length * LookAndFeel.Scale)) * Mathf.Sign(TotalDragScale);
            }

            return(LookAndFeel.Length * LookAndFeel.Scale * scaleFactor);
        }