private void UpdateDragHandles() { if (_targetOOBB == null) { return; } float halfHandleScreenSize = _dragHandleSizeInPixels * 0.5f; Camera camera = EditorCamera.Instance.Camera; Plane cameraNearPlane = camera.GetNearPlane(); List <BoxFace> allBoxFaces = BoxFaces.GetAll(); foreach (BoxFace face in allBoxFaces) { Vector3 boxFaceCenter = _targetOOBB.GetBoxFaceCenter(face); Vector2 screenFaceCenter = camera.WorldToScreenPoint(boxFaceCenter); _dragHandles[(int)face].ScreenRect = new Rect(screenFaceCenter.x - halfHandleScreenSize, screenFaceCenter.y - halfHandleScreenSize, _dragHandleSizeInPixels, _dragHandleSizeInPixels); _dragHandles[(int)face].IsVisible = true; if (cameraNearPlane.GetDistanceToPoint(boxFaceCenter) < 0.0f) { _dragHandles[(int)face].IsVisible = false; } } }
private int GetIndexOfHoveredDragHandle() { Vector2 devicePos; if (!InputDevice.Instance.GetPosition(out devicePos)) { return(-1); } List <BoxFace> allBoxFaces = BoxFaces.GetAll(); foreach (BoxFace face in allBoxFaces) { DragHandle dragHandle = _dragHandles[(int)face]; if (!_axesVisibilityMask[(int)dragHandle.Axis]) { continue; } if (dragHandle.ScreenRect.Contains(devicePos, true)) { return((int)face); } } return(-1); }
public Plane GetBoxFacePlane(BoxFace boxFace) { switch (boxFace) { case BoxFace.Back: return(new Plane(BoxFaces.GetFaceNormal(BoxFace.Back), GetBoxPoint(BoxPoint.BackBottomLeft))); case BoxFace.Front: return(new Plane(BoxFaces.GetFaceNormal(BoxFace.Front), GetBoxPoint(BoxPoint.FrontBottomLeft))); case BoxFace.Left: return(new Plane(BoxFaces.GetFaceNormal(BoxFace.Left), GetBoxPoint(BoxPoint.FrontBottomLeft))); case BoxFace.Right: return(new Plane(BoxFaces.GetFaceNormal(BoxFace.Right), GetBoxPoint(BoxPoint.FrontBottomRight))); case BoxFace.Top: return(new Plane(BoxFaces.GetFaceNormal(BoxFace.Top), GetBoxPoint(BoxPoint.FrontTopLeft))); case BoxFace.Bottom: return(new Plane(BoxFaces.GetFaceNormal(BoxFace.Bottom), GetBoxPoint(BoxPoint.FrontBottomLeft))); default: return(new Plane()); } }
public List <Vector3> GetBoxFaceCornerPoints(BoxFace boxFace) { var points = new Vector3[BoxFaceCornerPoints.Count]; Vector3 boxFaceCenter = GetBoxFaceCenter(boxFace); Vector2 boxFaceXZSize = GetBoxFaceSizeAlongFaceLocalXZAxes(boxFace, Vector3.one); Vector2 halfXZSize = boxFaceXZSize * 0.5f; points[(int)BoxFaceCornerPoint.TopLeft] = boxFaceCenter - BoxFaces.GetFaceRightAxis(boxFace) * halfXZSize.x + BoxFaces.GetFaceLookAxis(boxFace) * halfXZSize.y; points[(int)BoxFaceCornerPoint.TopRight] = boxFaceCenter + BoxFaces.GetFaceRightAxis(boxFace) * halfXZSize.x + BoxFaces.GetFaceLookAxis(boxFace) * halfXZSize.y; points[(int)BoxFaceCornerPoint.BottomRight] = boxFaceCenter + BoxFaces.GetFaceRightAxis(boxFace) * halfXZSize.x - BoxFaces.GetFaceLookAxis(boxFace) * halfXZSize.y; points[(int)BoxFaceCornerPoint.BottomLeft] = boxFaceCenter - BoxFaces.GetFaceRightAxis(boxFace) * halfXZSize.x - BoxFaces.GetFaceLookAxis(boxFace) * halfXZSize.y; return(new List <Vector3>(points)); }
public Vector3 GetBoxFaceCenter(BoxFace boxFace) { Vector3 center = Center; Vector3 extents = Extents; switch (boxFace) { case BoxFace.Back: return(center + BoxFaces.GetFaceNormal(BoxFace.Back) * extents.z); case BoxFace.Front: return(center + BoxFaces.GetFaceNormal(BoxFace.Front) * extents.z); case BoxFace.Left: return(center + BoxFaces.GetFaceNormal(BoxFace.Left) * extents.x); case BoxFace.Right: return(center + BoxFaces.GetFaceNormal(BoxFace.Right) * extents.x); case BoxFace.Top: return(center + BoxFaces.GetFaceNormal(BoxFace.Top) * extents.y); case BoxFace.Bottom: return(center + BoxFaces.GetFaceNormal(BoxFace.Bottom) * extents.y); default: return(Vector3.zero); } }
protected override void OnInputDeviceFirstButtonDown() { base.OnInputDeviceFirstButtonDown(); if (_hoveredDragHandle != -1 && _targetOOBB != null && _targetObject != null) { _dragStartData.DragHandleFace = (BoxFace)_hoveredDragHandle; _dragStartData.TargetOOBB = new OrientedBox(_targetOOBB); _dragStartData.TargetObjectScale = _targetObject.transform.lossyScale; _dragStartData.ScaleFromCenter = _enableScaleFromCenterShortcut.IsActive(); _dragStartData.DragHandlePlane = _dragStartData.TargetOOBB.GetBoxFacePlane(_dragStartData.DragHandleFace); _dragStartData.ScaleAxisIndex = -1; if (_dragStartData.DragHandleFace == BoxFace.Left || _dragStartData.DragHandleFace == BoxFace.Right) { _dragStartData.ScaleAxisIndex = 0; } else if (_dragStartData.DragHandleFace == BoxFace.Bottom || _dragStartData.DragHandleFace == BoxFace.Top) { _dragStartData.ScaleAxisIndex = 1; } else { _dragStartData.ScaleAxisIndex = 2; } if (_dragStartData.ScaleFromCenter) { _dragStartData.ScalePivot = _dragStartData.TargetOOBB.Center; } else { _dragStartData.ScalePivot = _dragStartData.TargetOOBB.GetBoxFaceCenter(BoxFaces.GetOpposite(_dragStartData.DragHandleFace)); } _dragStartData.PivotPlane = new Plane(_dragStartData.DragHandlePlane.normal, _dragStartData.ScalePivot); _dragStartData.DragPlane = CalculateDragPlane(); _dragStartData.FromPivotToObjectPos = _targetObject.transform.position - _dragStartData.ScalePivot; } }
public Vector3 GetBoxPoint(BoxPoint boxPoint) { Vector3 center = Center; Vector3 extents = Extents; switch (boxPoint) { case BoxPoint.Center: return(center); case BoxPoint.FrontTopLeft: return(center - BoxFaces.GetFaceRightAxis(BoxFace.Front) * extents.x + BoxFaces.GetFaceLookAxis(BoxFace.Front) * extents.y + BoxFaces.GetFaceNormal(BoxFace.Front) * extents.z); case BoxPoint.FrontTopRight: return(center + BoxFaces.GetFaceRightAxis(BoxFace.Front) * extents.x + BoxFaces.GetFaceLookAxis(BoxFace.Front) * extents.y + BoxFaces.GetFaceNormal(BoxFace.Front) * extents.z); case BoxPoint.FrontBottomRight: return(center + BoxFaces.GetFaceRightAxis(BoxFace.Front) * extents.x - BoxFaces.GetFaceLookAxis(BoxFace.Front) * extents.y + BoxFaces.GetFaceNormal(BoxFace.Front) * extents.z); case BoxPoint.FrontBottomLeft: return(center - BoxFaces.GetFaceRightAxis(BoxFace.Front) * extents.x - BoxFaces.GetFaceLookAxis(BoxFace.Front) * extents.y + BoxFaces.GetFaceNormal(BoxFace.Front) * extents.z); case BoxPoint.BackTopLeft: return(center - BoxFaces.GetFaceRightAxis(BoxFace.Back) * extents.x + BoxFaces.GetFaceLookAxis(BoxFace.Back) * extents.y + BoxFaces.GetFaceNormal(BoxFace.Back) * extents.z); case BoxPoint.BackTopRight: return(center + BoxFaces.GetFaceRightAxis(BoxFace.Back) * extents.x + BoxFaces.GetFaceLookAxis(BoxFace.Back) * extents.y + BoxFaces.GetFaceNormal(BoxFace.Back) * extents.z); case BoxPoint.BackBottomRight: return(center + BoxFaces.GetFaceRightAxis(BoxFace.Back) * extents.x - BoxFaces.GetFaceLookAxis(BoxFace.Back) * extents.y + BoxFaces.GetFaceNormal(BoxFace.Back) * extents.z); case BoxPoint.BackBottomLeft: return(center - BoxFaces.GetFaceRightAxis(BoxFace.Back) * extents.x - BoxFaces.GetFaceLookAxis(BoxFace.Back) * extents.y + BoxFaces.GetFaceNormal(BoxFace.Back) * extents.z); default: return(Vector3.zero); } }