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); } } }
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); } } }