private void OnGizmoTransformChanged(GizmoTransform gizmoTransform, GizmoTransform.ChangeData changeData) { if (changeData.ChangeReason == GizmoTransform.ChangeReason.ParentChange || changeData.TRSDimension == GizmoDimension.Dim3D) { UpdateCamLookSlider(Gizmo.GetWorkCamera()); } }
protected override void OnVisibilityStateChanged() { _controllers[(int)LookAndFeel.CapType].UpdateHandles(); Camera camera = Gizmo.GetWorkCamera(); _controllers[(int)LookAndFeel.CapType].UpdateTransforms(GetZoomFactor(camera)); }
public void Refresh() { Camera camera = Gizmo.GetWorkCamera(); float zoomFactor = GetZoomFactor(camera); _controllers[(int)LookAndFeel.CapType].UpdateHandles(); _controllers[(int)LookAndFeel.CapType].UpdateTransforms(zoomFactor); }
public float GetZoomFactor(Vector3 position) { if (!LookAndFeel3D.UseZoomFactor) { return(1.0f); } return(Gizmo.GetWorkCamera().EstimateZoomFactor(position)); }
private void OnTransformChanged(GizmoTransform transform, GizmoTransform.ChangeData changeData) { if (changeData.ChangeReason == GizmoTransform.ChangeReason.ParentChange || changeData.TRSDimension == GizmoDimension.Dim3D) { float zoomFactor = GetZoomFactor(Gizmo.GetWorkCamera()); _controllers[(int)LookAndFeel.PlaneType].UpdateTransforms(zoomFactor); } }
protected override void OnVisibilityStateChanged() { _controllers[(int)LookAndFeel.PlaneType].UpdateHandles(); Camera camera = Gizmo.GetWorkCamera(); float zoomFactor = GetZoomFactor(camera); _controllers[(int)LookAndFeel.PlaneType].UpdateEpsilons(zoomFactor); _controllers[(int)LookAndFeel.PlaneType].UpdateTransforms(zoomFactor); }
protected override void OnVisibilityStateChanged() { _controllers[(int)LookAndFeel.LineType].UpdateHandles(); Camera camera = Gizmo.GetWorkCamera(); float zoomFactor = GetZoomFactor(camera); _controllers[(int)LookAndFeel.LineType].UpdateEpsilons(zoomFactor); _controllers[(int)LookAndFeel.LineType].UpdateTransforms(zoomFactor); _cap3D.CapSlider3D(GetRealDirection(), GetRealEndPosition(zoomFactor)); }
/// <summary> /// This function can be called after changing functional or look and feel settings /// to ensure that these settings take effect. /// </summary> public void Refresh() { Camera camera = Gizmo.GetWorkCamera(); float zoomFactor = GetZoomFactor(camera); _controllers[(int)LookAndFeel.LineType].UpdateHandles(); _controllers[(int)LookAndFeel.LineType].UpdateEpsilons(zoomFactor); _controllers[(int)LookAndFeel.LineType].UpdateTransforms(zoomFactor); _cap3D.CapSlider3D(GetRealDirection(), GetRealEndPosition(zoomFactor)); }
private void OnTransformChanged(GizmoTransform transform, GizmoTransform.ChangeData changeData) { if (changeData.ChangeReason == GizmoTransform.ChangeReason.ParentChange || changeData.TRSDimension == GizmoDimension.Dim3D) { Camera camera = Gizmo.GetWorkCamera(); float zoomFactor = GetZoomFactor(camera); _controllers[(int)LookAndFeel.LineType].UpdateTransforms(zoomFactor); _cap3D.CapSlider3D(GetRealDirection(), GetRealEndPosition(zoomFactor)); } }
public override void OnGizmoAttemptHandleDragBegin(int handleId) { if (handleId == _midCap.HandleId) { var workData = new GizmoUniformScaleDrag3D.WorkData(); workData.BaseSize = _midCap.GetRealBoxSize(_midCap.GetZoomFactor(Gizmo.GetWorkCamera())).magnitude; workData.DragOrigin = _midCap.Position; workData.CameraRight = Gizmo.FocusCamera.transform.right; workData.CameraUp = Gizmo.FocusCamera.transform.up; workData.SnapStep = Settings3D.UniformSnapStep; _unformScaleDrag.SetWorkData(workData); } }
public void CapSlider3DInvert(Vector3 sliderDirection, Vector3 sliderEndPt) { _controllers[(int)LookAndFeel.CapType].CapSlider3DInvert(sliderDirection, sliderEndPt, GetZoomFactor(Gizmo.GetWorkCamera())); }
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); } }
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); }
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); }
/// <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 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); }
private void Update2DGizmoPosition() { Gizmo.Transform.Position2D = Gizmo.GetWorkCamera().WorldToScreenPoint(Gizmo.Transform.Position3D); }
/// <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()))); }