public void Render() { if (SharedLookAndFeel == null) { return; } if (IsActive && _grabSurfaceInfo.SurfaceType != GrabSurfaceType.Invalid) { Material material = MaterialPool.Get.SimpleColor; if (SharedLookAndFeel.DrawAnchorLines) { var linePoints = new List <Vector3>(_grabTargets.Count * 2); foreach (var grabTarget in _grabTargets) { linePoints.Add(grabTarget.Transform.position); linePoints.Add(_grabSurfaceInfo.AnchorPoint); } material.SetZTestAlways(); material.SetColor(_sharedLookAndFeel.AnchorLineColor); material.SetPass(0); GLRenderer.DrawLines3D(linePoints); } if (SharedLookAndFeel.DrawObjectBoxes) { material.SetZTestLess(); material.SetColor(SharedLookAndFeel.ObjectBoxWireColor); material.SetPass(0); var boundsQConfig = GetObjectBoundsQConfig(); foreach (var grabTarget in _grabTargets) { OBB obb = ObjectBounds.CalcHierarchyWorldOBB(grabTarget.GameObject, boundsQConfig); if (obb.IsValid) { GraphicsEx.DrawWireBox(obb); } } } if (SharedLookAndFeel.DrawObjectPosTicks) { material.SetColor(SharedLookAndFeel.ObjectPosTickColor); material.SetPass(0); foreach (var grabTarget in _grabTargets) { Vector2 screenPos = Camera.current.WorldToScreenPoint(grabTarget.Transform.position); GLRenderer.DrawRect2D(RectEx.FromCenterAndSize(screenPos, Vector2Ex.FromValue(SharedLookAndFeel.ObjectPosTickSize)), Camera.current); } } if (SharedLookAndFeel.DrawAnchorPosTick) { material.SetColor(SharedLookAndFeel.AnchorPosTickColor); material.SetPass(0); Vector2 anchorScreenPos = Camera.current.WorldToScreenPoint(_grabSurfaceInfo.AnchorPoint); GLRenderer.DrawRect2D(RectEx.FromCenterAndSize(anchorScreenPos, Vector2Ex.FromValue(SharedLookAndFeel.AnchorPosTickSize)), Camera.current); } } }
public override void UpdateEpsilons() { _data.Quad.SizeEps = Vector2Ex.FromValue(_data.Slider.Settings.BoxHoverEps); }
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); } } }
public float GetSizeAlongDirection(Vector2 direction) { return(Vector2Ex.AbsDot(direction, Rotation * _size)); }
public override void UpdateEpsilons(float zoomFactor) { _data.Quad.SizeEps = Vector2Ex.FromValue(_data.Slider.Settings.AreaHoverEps * zoomFactor); _data.Quad.ExtrudeEps = _data.Slider.Settings.ExtrudeHoverEps * zoomFactor; }
public void Render() { if (_sharedLookAndFeel == null) { return; } if (IsActive) { Material material = MaterialPool.Get.SimpleColor; if (_sharedLookAndFeel.DrawBoxes) { material.SetColor(_sharedLookAndFeel.BoxLineColor); material.SetZTestEnabled(true); material.SetPass(0); ObjectBounds.QueryConfig boundsQConfig = GetObjectBoundsQConfig(); foreach (GameObject targetObject in _targetObjects) { if (targetObject == null) { continue; } OBB worldOBB = ObjectBounds.CalcWorldOBB(targetObject, boundsQConfig); if (worldOBB.IsValid) { GraphicsEx.DrawWireBox(worldOBB); } } } Camera camera = Camera.current; Vector2 screenSnapPivot = camera.WorldToScreenPoint(_snapPivotPoint); if (_sharedLookAndFeel.PivotShapeType == PivotPointShapeType.Circle) { material.SetZTestEnabled(false); material.SetColor(_sharedLookAndFeel.PivotPointFillColor); material.SetPass(0); const int numCirclePoints = 100; List <Vector2> pivotCirclePoints = PrimitiveFactory.Generate2DCircleBorderPointsCW(screenSnapPivot, _sharedLookAndFeel.PivotCircleRadius, numCirclePoints); GLRenderer.DrawTriangleFan2D(screenSnapPivot, pivotCirclePoints, camera); if (_sharedLookAndFeel.DrawPivotBorder) { material.SetColor(_sharedLookAndFeel.PivotPointBorderColor); material.SetPass(0); GLRenderer.DrawLineLoop2D(pivotCirclePoints, camera); } } else if (_sharedLookAndFeel.PivotShapeType == PivotPointShapeType.Square) { material.SetZTestEnabled(false); material.SetColor(_sharedLookAndFeel.PivotPointFillColor); material.SetPass(0); Rect pivotRect = RectEx.FromCenterAndSize(screenSnapPivot, Vector2Ex.FromValue(_sharedLookAndFeel.PivotSquareSideLength)); GLRenderer.DrawRect2D(pivotRect, camera); if (_sharedLookAndFeel.DrawPivotBorder) { material.SetColor(_sharedLookAndFeel.PivotPointBorderColor); material.SetPass(0); GLRenderer.DrawRectBorder2D(pivotRect, camera); } } } }