public void Update(RTSceneGizmoCamera sceneGizmoCamera)
        {
            SceneGizmoLookAndFeel lookAndFeel = _sceneGizmo.LookAndFeel;
            Vector2 screenOffset              = lookAndFeel.ScreenOffset;
            Rect    sceneCameraViewRect       = sceneGizmoCamera.SceneCamera.pixelRect;
            Vector2 camPrjSwitchLabelRectSize = lookAndFeel.CalculateMaxPrjSwitchLabelRectSize();
            bool    usesPrjSwitchLabel        = lookAndFeel.IsCamPrjSwitchLabelVisible;
            float   screenSize = lookAndFeel.ScreenSize;

            if (lookAndFeel.ScreenCorner == SceneGizmoScreenCorner.TopRight)
            {
                sceneGizmoCamera.Camera.pixelRect = new Rect(sceneCameraViewRect.xMax - screenSize + screenOffset.x, sceneCameraViewRect.yMax - screenSize + screenOffset.y, screenSize, screenSize);
            }
            else
            if (lookAndFeel.ScreenCorner == SceneGizmoScreenCorner.TopLeft)
            {
                sceneGizmoCamera.Camera.pixelRect = new Rect(sceneCameraViewRect.xMin + screenOffset.x, sceneCameraViewRect.yMax - screenSize + screenOffset.y, screenSize, screenSize);
            }
            else
            if (lookAndFeel.ScreenCorner == SceneGizmoScreenCorner.BottomRight)
            {
                sceneGizmoCamera.Camera.pixelRect = new Rect(sceneCameraViewRect.xMax - screenSize + screenOffset.x,
                                                             sceneCameraViewRect.yMin + (usesPrjSwitchLabel ? camPrjSwitchLabelRectSize.y + 1.0f : 0.0f) + screenOffset.y, screenSize, screenSize);
            }
            else
            {
                sceneGizmoCamera.Camera.pixelRect = new Rect(sceneCameraViewRect.xMin + screenOffset.x,
                                                             sceneCameraViewRect.yMin + (usesPrjSwitchLabel ? camPrjSwitchLabelRectSize.y + 1.0f : 0.0f) + screenOffset.y, screenSize, screenSize);
            }
        }
        public override void Render(Camera camera)
        {
            var sgLookAndFeel = _sceneGizmo.LookAndFeel;
            RTSceneGizmoCamera sceneGizmoCamera = _sceneGizmo.SceneGizmoCamera;

            _cap.Render(camera);

            if (_axisDesc.IsPositive)
            {
                GizmoLabelMaterial labelMaterial = GizmoLabelMaterial.Get;
                labelMaterial.SetZWriteEnabled(false);
                labelMaterial.SetZTestLessEqual();
                labelMaterial.SetColor(ColorEx.KeepAllButAlpha(sgLookAndFeel.AxesLabelTint, _color.Value.a));
                labelMaterial.SetTexture(_labelTexture);
                labelMaterial.SetPass(0);

                Vector3 gizmoAxis  = _sceneGizmo.Gizmo.Transform.GetAxis3D(_axisDesc);
                Vector3 labelScale = Vector3Ex.FromValue(sgLookAndFeel.GetAxesLabelWorldSize(sceneGizmoCamera.Camera, _cap.Position));
                Vector3 labelPos   = _cap.Position + gizmoAxis * (labelScale.x * 0.5f);

                Vector2 labelScreenPos   = sceneGizmoCamera.Camera.WorldToScreenPoint(labelPos);
                Vector2 midAxisScreenPos = sceneGizmoCamera.Camera.WorldToScreenPoint(_sceneGizmo.SceneGizmoCamera.LookAtPoint);
                Vector2 labelScreenDir   = (labelScreenPos - midAxisScreenPos).normalized;

                float absDotCamLook = Mathf.Abs(Vector3Ex.AbsDot(sceneGizmoCamera.Look, gizmoAxis));
                labelScreenPos = labelScreenPos + Vector2.Scale(labelScreenDir, Vector2Ex.FromValue(SceneGizmoLookAndFeel.AxisLabelScreenSize)) * absDotCamLook;
                labelPos       = sceneGizmoCamera.Camera.ScreenToWorldPoint(new Vector3(labelScreenPos.x, labelScreenPos.y, (labelPos - sceneGizmoCamera.WorldPosition).magnitude));

                Quaternion labelRotation     = Quaternion.LookRotation(sceneGizmoCamera.Look, sceneGizmoCamera.Up);
                Matrix4x4  labelTransformMtx = Matrix4x4.TRS(labelPos, labelRotation, labelScale);

                Graphics.DrawMeshNow(MeshPool.Get.UnitQuadXY, labelTransformMtx);
            }
        }
Example #3
0
        public RTSceneGizmoCamera CreateSceneGizmoCamera(Camera sceneCamera, ISceneGizmoCamViewportUpdater viewportUpdater)
        {
            GameObject sceneGizmoCamObject = new GameObject(typeof(RTSceneGizmoCamera).ToString());

            sceneGizmoCamObject.transform.parent = RTGizmosEngine.Get.transform;

            RTSceneGizmoCamera sgCamera = sceneGizmoCamObject.AddComponent <RTSceneGizmoCamera>();

            sgCamera.ViewportUpdater = viewportUpdater;
            sgCamera.SceneCamera     = sceneCamera;

            _sceneGizmoCameras.Add(sgCamera);

            return(sgCamera);
        }
        private void UpdateTransform(Camera camera)
        {
            Vector3            midAxisPos       = _sceneGizmo.SceneGizmoCamera.LookAtPoint;
            RTSceneGizmoCamera sceneGizmoCamera = _sceneGizmo.SceneGizmoCamera;
            Vector3            axisDirection    = _sceneGizmo.Gizmo.Transform.GetAxis3D(_axisDesc);

            _zoomFactorTransform.Position3D = midAxisPos;
            float zoomFactor = _cap.GetZoomFactor(camera);

            Vector3 midCapSize = _sceneGizmo.LookAndFeel.MidCapType == GizmoCap3DType.Box ?
                                 Vector3Ex.FromValue(SceneGizmoLookAndFeel.MidCapBoxSize * zoomFactor) : Vector3Ex.FromValue(SceneGizmoLookAndFeel.MidCapSphereRadius * 2.0f * zoomFactor);
            Vector3 midBoxFaceCenter = BoxMath.CalcBoxFaceCenter(midAxisPos, midCapSize, Quaternion.identity, _midAxisBoxFace);

            _cap.CapSlider3DInvert(axisDirection, midBoxFaceCenter);
        }
        public override void OnAttached()
        {
            _sceneGizmoCamera = RTGizmosEngine.Get.CreateSceneGizmoCamera(RTFocusCamera.Get.TargetCamera, new SceneGizmoCamViewportUpdater(this));

            // Create the mid axis handle
            _midAxisHandle = new SceneGizmoMidCap(this);
            _renderSortedHandles.Add(_midAxisHandle);

            // Create the axes handles
            AxisDescriptor[] axesDescriptors = new AxisDescriptor[]
            {
                new AxisDescriptor(0, AxisSign.Positive), new AxisDescriptor(1, AxisSign.Positive),
                new AxisDescriptor(2, AxisSign.Positive), new AxisDescriptor(0, AxisSign.Negative),
                new AxisDescriptor(1, AxisSign.Negative), new AxisDescriptor(2, AxisSign.Negative)
            };
            int[] handleIds = new int[]
            {
                GizmoHandleId.SceneGizmoPositiveXAxis, GizmoHandleId.SceneGizmoPositiveYAxis,
                GizmoHandleId.SceneGizmoPositiveZAxis, GizmoHandleId.SceneGizmoNegativeXAxis,
                GizmoHandleId.SceneGizmoNegativeYAxis, GizmoHandleId.SceneGizmoNegativeZAxis
            };
            for (int axisIndex = 0; axisIndex < axesDescriptors.Length; ++axisIndex)
            {
                _axesHandles[axisIndex] = new SceneGizmoAxisCap(this, handleIds[axisIndex], axesDescriptors[axisIndex]);
                _renderSortedHandles.Add(_axesHandles[axisIndex]);
            }

            // Create the camera projection switch handle
            _camPrjSwitchLabel = new SceneGizmoCamPrjSwitchLabel(this);

            // Establish the scene gizmo's transform. These will remain unchanged.
            Gizmo.Transform.Position3D = _sceneGizmoCamera.LookAtPoint;
            Gizmo.Transform.Rotation3D = Quaternion.identity;

            // We want the scene gizmo to have the highest hover priority. This way, whatever
            // other gizmo lies behind it, the scene gizmo will be the one hovered by the cursor.
            Gizmo.GenericHoverPriority.MakeHighest();
            Gizmo.HoverPriority2D.MakeHighest();
            Gizmo.HoverPriority3D.MakeHighest();
        }