private void SetHit(RaycastHit hit) { PlaneAlignment planeAlignment = this.planeAlignment; if (planeAlignment == PlaneAlignment.Surface || planeAlignment != PlaneAlignment.Beam) { this.SetClippingPlane(new Plane(hit.normal, hit.point)); return; } this.SetClippingPlane(new Plane(-base.transform.forward, hit.point)); }
/// <summary> /// Constructs a new <see cref="BoundedPlane"/>. This is just a data container /// for a plane's session relative data. These are typically created by /// <see cref="XRPlaneSubsystem.GetChanges(Unity.Collections.Allocator)"/>. /// </summary> /// <param name="trackableId">The <see cref="TrackableId"/> associated with the point cloud.</param> /// <param name="subsumedBy">The plane which subsumed this one. Use <see cref="TrackableId.invalidId"/> if it has not been subsumed.</param> /// <param name="pose">The <c>Pose</c> associated with the point cloud.</param> /// <param name="center">The center, in plane-space (relative to <paramref name="pose"/>) of the plane.</param> /// <param name="size">The dimensions associated with the point cloud.</param> /// <param name="alignment">The <see cref="PlaneAlignment"/> associated with the point cloud.</param> /// <param name="trackingState">The <see cref="TrackingState"/> associated with the point cloud.</param> /// <param name="nativePtr">The native pointer associated with the point cloud.</param> public BoundedPlane( TrackableId trackableId, TrackableId subsumedBy, Pose pose, Vector2 center, Vector2 size, PlaneAlignment alignment, TrackingState trackingState, IntPtr nativePtr) { m_TrackableId = trackableId; m_SubsumedById = subsumedBy; m_Pose = pose; m_Center = center; m_Size = size; m_Alignment = alignment; m_TrackingState = trackingState; m_NativePtr = nativePtr; }
public static MarsPlaneAlignment ToMarsPlaneAlignment(this PlaneAlignment arPlaneAlignment) { switch (arPlaneAlignment) { case PlaneAlignment.HorizontalDown: return(MarsPlaneAlignment.HorizontalDown); case PlaneAlignment.HorizontalUp: return(MarsPlaneAlignment.HorizontalUp); case PlaneAlignment.Vertical: return(MarsPlaneAlignment.Vertical); case PlaneAlignment.NotAxisAligned: return(MarsPlaneAlignment.NonAxis); } return(MarsPlaneAlignment.None); }
/// <summary> /// Draw a map quality indicator at the given position and enable it. /// </summary> /// <param name="planeAlignment">The alignment of the plane where the anchor is placed. /// </param> /// <param name="camera">The main camera.</param> public void DrawIndicator(PlaneAlignment planeAlignment, Camera camera) { // To use customized value, remove this line and set the desired range in inspector. Range = planeAlignment == PlaneAlignment.Vertical ? _verticalRange : _horizontalRange; _mainCamera = camera; // Get the direction from the center of the circle to the center of the arc // in world space. _centerDir = planeAlignment == PlaneAlignment.Vertical ? transform.TransformVector(Vector3.up) : transform.TransformVector(-Vector3.forward); DrawBars(); DrawRing(); gameObject.SetActive(true); }
private static int AlignmentToInt(PlaneAlignment alignment) { switch (alignment) { case UnityEngine.XR.ARSubsystems.PlaneAlignment.None: return(0); case UnityEngine.XR.ARSubsystems.PlaneAlignment.HorizontalUp: return(1); case UnityEngine.XR.ARSubsystems.PlaneAlignment.HorizontalDown: return(2); case UnityEngine.XR.ARSubsystems.PlaneAlignment.Vertical: return(3); case UnityEngine.XR.ARSubsystems.PlaneAlignment.NotAxisAligned: return(4); default: throw new ArgumentOutOfRangeException(nameof(alignment), alignment, null); } }
/// <summary> /// Determines whether the plane is vertical. /// </summary> /// <param name="alignment">The <see cref="PlaneAlignment"/> being extended.</param> /// <returns><c>true</c> if the plane is vertical.</returns> public static bool IsVertical(this PlaneAlignment alignment) { return(alignment == PlaneAlignment.Vertical); }
/// <summary> /// Determines whether the plane is horizontal (whether facing up or down). /// </summary> /// <param name="alignment">The <see cref="PlaneAlignment"/> being extended.</param> /// <returns><c>true</c> if the plane is horizontal.</returns> public static bool IsHorizontal(this PlaneAlignment alignment) { return ((alignment == PlaneAlignment.HorizontalUp) || (alignment == PlaneAlignment.HorizontalDown)); }
public override void OnInspectorGUI() { serializedObject.Update(); var terrain = (VoxelTerrain)target; CreatePlanes(terrain); EditorGUILayout.LabelField("Plane alignment"); GUILayout.BeginHorizontal(); foreach (var kvp in planeNormals) { if (GUILayout.Toggle(alignment == kvp.Key, kvp.Key.ToString(), "Button")) { alignment = kvp.Key; createPlane = true; } } GUILayout.EndHorizontal(); EditorGUILayout.LabelField("Paint mode"); GUILayout.BeginHorizontal(); foreach (var mode in paintModes) { if (GUILayout.Toggle(paintMode == mode, mode.ToString(), "Button")) { paintMode = mode; } } GUILayout.EndHorizontal(); EditorGUILayout.LabelField("Available block types"); ushort blockTypeCount = 0; if (GUILayout.Toggle(!paintBlockType, "Don't paint block", "Button")) { paintBlockType = false; } foreach (var blockType in terrain.BlockTypes) { if (GUILayout.Toggle(paintBlockType && selectedBlockType == blockTypeCount, blockType.BlockName, "Button")) { selectedBlockType = blockTypeCount; paintBlockType = true; } blockTypeCount++; } EditorGUILayout.LabelField("Mesh shape type"); if (GUILayout.Toggle(!paintShape, "Don't paint shape", "Button")) { paintShape = false; } foreach (var meshShape in meshShapeTypes) { if (GUILayout.Toggle(paintShape && selectedMeshShape == meshShape, meshShape.ToString(), "Button")) { selectedMeshShape = meshShape; paintShape = true; } } EditorGUILayout.LabelField("Rotation direction"); GUILayout.BeginHorizontal(); foreach (var rotation in rotationTypes) { if (GUILayout.Toggle(selectedRotation == rotation, rotation.ToString(), "Button")) { selectedRotation = rotation; } } GUILayout.EndHorizontal(); EditorGUILayout.LabelField("Delete all terrain!?"); if (GUILayout.Button("Clear terrain")) { terrain.Clear(); } serializedObject.ApplyModifiedProperties(); }
void OnSceneGUI() { var e = Event.current; var controlId = GUIUtility.GetControlID(FocusType.Passive); var terrain = (VoxelTerrain)target; if (e.type == EventType.KeyDown) { var newAlignment = PlaneAlignment.None; var useEvent = false; var index = 0; foreach (var planeNormal in planeNormals) { if (index >= Row1Keys.Count) { return; } if (e.keyCode == Row1Keys[index++]) { newAlignment = planeNormal.Key; } } if (newAlignment != PlaneAlignment.None) { createPlane = true; alignment = newAlignment; EditorUtility.SetDirty(terrain); useEvent = true; } index = 0; foreach (var blockType in terrain.BlockTypes) { if (index >= Row2Keys.Count) { return; } if (e.keyCode == Row2Keys[index]) { selectedBlockType = (ushort)index; useEvent = true; } index++; } index = 0; foreach (var meshShape in meshShapeTypes) { if (index >= Row3Keys.Count) { return; } if (e.keyCode == Row3Keys[index++]) { selectedMeshShape = meshShape; useEvent = true; } } index = 0; foreach (var rotation in rotationTypes) { if (index >= Row4Keys.Count) { return; } if (e.keyCode == Row4Keys[index++]) { selectedRotation = rotation; useEvent = true; } } if (e.keyCode == KeyCode.Space) { useEvent = true; var ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); RaycastHit rayHit; if (Physics.Raycast(ray, out rayHit)) { var cursorPosition = rayHit.point - rayHit.normal * 0.5f; tileCursorPosition = new Vector3(Mathf.Round(cursorPosition.x), Mathf.Round(cursorPosition.y), Mathf.Round(cursorPosition.z)); } } if (useEvent) { GUIUtility.hotControl = controlId; EditorUtility.SetDirty(terrain); e.Use(); } } CreatePlanes(terrain); if ((e.type == EventType.MouseDown || e.type == EventType.MouseDrag) && e.button == 0) { if (paintBlockType || paintShape) { GUIUtility.hotControl = controlId; var x = (int)tileCursorPosition.x; var y = (int)tileCursorPosition.y; var z = (int)tileCursorPosition.z; if (paintMode == PaintModeType.Single) { PaintAtPoint(terrain, x, y, z); } else if (paintMode == PaintModeType.Rectangle && e.type == EventType.MouseDown) { mouseDownTileCursorPosition = tileCursorPosition; } EditorUtility.SetDirty(terrain); } if (e.type == EventType.MouseDown) { e.Use(); } } if (e.type == EventType.MouseUp && e.button == 0) { if (mouseDownTileCursorPosition.HasValue && paintMode == PaintModeType.Rectangle) { var startX = (int)Mathf.Min(tileCursorPosition.x, mouseDownTileCursorPosition.Value.x); var startY = (int)Mathf.Min(tileCursorPosition.y, mouseDownTileCursorPosition.Value.y); var startZ = (int)Mathf.Min(tileCursorPosition.z, mouseDownTileCursorPosition.Value.z); var endX = (int)Mathf.Max(tileCursorPosition.x, mouseDownTileCursorPosition.Value.x); var endY = (int)Mathf.Max(tileCursorPosition.y, mouseDownTileCursorPosition.Value.y); var endZ = (int)Mathf.Max(tileCursorPosition.z, mouseDownTileCursorPosition.Value.z); for (var z = startZ; z <= endZ; z++) { for (var y = startY; y <= endY; y++) { for (var x = startX; x <= endX; x++) { PaintAtPoint(terrain, x, y, z); } } } EditorUtility.SetDirty(terrain); mouseDownTileCursorPosition = null; } } if (e.type == EventType.MouseMove || e.type == EventType.MouseDrag) { float rayDistance; var ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); if (plane.Raycast(ray, out rayDistance)) { cursorPosition = ray.GetPoint(rayDistance); var newCursor = new Vector3(Mathf.Round(cursorPosition.x), Mathf.Round(cursorPosition.y), Mathf.Round(cursorPosition.z)); if (alignment == PlaneAlignment.X) { tileCursorPosition = new Vector3(newCursor.x, tileCursorPosition.y, tileCursorPosition.z); } else if (alignment == PlaneAlignment.Y) { tileCursorPosition = new Vector3(tileCursorPosition.x, newCursor.y, tileCursorPosition.z); } else if (alignment == PlaneAlignment.Z) { tileCursorPosition = new Vector3(tileCursorPosition.x, tileCursorPosition.y, newCursor.z); } else { tileCursorPosition = newCursor; } SceneView.RepaintAll(); } } Handles.color = new Color(0.35f, 0.4f, 0.8f, 0.5f); Handles.CubeCap(0, tileCursorPosition, Quaternion.identity, 1.0f); if (mouseDownTileCursorPosition.HasValue) { Handles.color = new Color(0.4f, 0.8f, 0.35f, 0.5f); Handles.CubeCap(0, mouseDownTileCursorPosition.Value, Quaternion.identity, 1.0f); } var xColour = (alignment == PlaneAlignment.XY || alignment == PlaneAlignment.XZ || alignment == PlaneAlignment.X) ? Color.red : new Color(1, 1, 1, 0.5f); var yColour = (alignment == PlaneAlignment.YZ || alignment == PlaneAlignment.XY || alignment == PlaneAlignment.Y) ? Color.green : new Color(1, 1, 1, 0.5f); var zColour = (alignment == PlaneAlignment.XZ || alignment == PlaneAlignment.YZ || alignment == PlaneAlignment.Z) ? Color.blue : new Color(1, 1, 1, 0.5f); Handles.color = xColour; Handles.DrawLine(tileCursorPosition + Vector3.left * 100, tileCursorPosition + Vector3.right * 100); Handles.color = yColour; Handles.DrawLine(tileCursorPosition + Vector3.up * 100, tileCursorPosition + Vector3.down * 100); Handles.color = zColour; Handles.DrawLine(tileCursorPosition + Vector3.forward * 100, tileCursorPosition + Vector3.back * 100); var screenPos = Camera.current.WorldToScreenPoint(tileCursorPosition); Handles.BeginGUI(); GUI.Label(new Rect(screenPos.x, Screen.height - screenPos.y, 100, 40), string.Format("({0}, {1}, {2})", tileCursorPosition.x, tileCursorPosition.y, tileCursorPosition.z)); Handles.EndGUI(); }
static bool IsPlaneTypeAllowed(GestureTranslationMode gestureTranslationMode, PlaneAlignment planeAlignment) { if (gestureTranslationMode == GestureTranslationMode.Any) { return(true); } if (gestureTranslationMode == GestureTranslationMode.Horizontal && (planeAlignment == PlaneAlignment.HorizontalDown || planeAlignment == PlaneAlignment.HorizontalUp)) { return(true); } if (gestureTranslationMode == GestureTranslationMode.Vertical && planeAlignment == PlaneAlignment.Vertical) { return(true); } return(false); }
private Vector2Int GetAxisCorrectedAnchor(Vector2Int tileCoords, Vector2Int anchorCoords, bool locked, PlaneAlignment lockedAxis) { if (locked) { switch (lockedAxis) { case PlaneAlignment.Horizontal: return(new Vector2Int(tileCoords.x, anchorCoords.y)); case PlaneAlignment.Vertical: return(new Vector2Int(anchorCoords.x, tileCoords.y)); } } return(anchorCoords); }
private void UpdateCreateRamps() { Map map = GameManager.Instance.Map; float dragSensitivity = 0; float.TryParse(dragSensitivityInput.text, NumberStyles.Any, CultureInfo.InvariantCulture, out dragSensitivity); bool respectSlopes = respectOriginalSlopesToggle.isOn; if (state == HeightUpdaterState.Recovering) { state = HeightUpdaterState.Idle; } if (Input.GetMouseButtonDown(0)) { if (currentFrameHoveredHandles.Count == 1 && selectedHandles.Contains(currentFrameHoveredHandles[0])) { if (anchorHandle != null && anchorHandle != currentFrameHoveredHandles[0]) { activeHandle = currentFrameHoveredHandles[0]; } else { anchorHandle = currentFrameHoveredHandles[0]; } state = HeightUpdaterState.Manipulating; } else if (Input.GetKey(KeyCode.LeftShift)) { state = HeightUpdaterState.Dragging; } else { deselectedHandles = selectedHandles; selectedHandles = new List <HeightmapHandle>(); anchorHandle = null; anchorPlaneLine.gameObject.SetActive(false); state = HeightUpdaterState.Dragging; } } if (Input.GetMouseButton(0)) { if (state == HeightUpdaterState.Manipulating) { if (activeHandle != null && anchorHandle != null) { map.CommandManager.UndoAction(); bool locked = anchorPlaneLine.gameObject.activeSelf; PlaneAlignment lockedAxis = anchorPlaneLine.Alignment; int originalHeight = map[anchorHandle.TileCoords].SurfaceHeight; int heightDelta = (int)((dragEndPos.y - dragStartPos.y) * dragSensitivity); // instantly make smooth ramp from anchor handle to active handle if original slopes are not respected // turned off if original slopes are respected, because instantly making ramp is impractical in such case if (!respectSlopes) { heightDelta += map[activeHandle.TileCoords].SurfaceHeight - originalHeight; } Vector2Int manipulatedTileCoords = activeHandle.TileCoords; Vector2Int manipulatedAnchorCoords = GetAxisCorrectedAnchor(manipulatedTileCoords, anchorHandle.TileCoords, locked, lockedAxis); Vector2Int manipulatedDifference = manipulatedTileCoords - manipulatedAnchorCoords; foreach (HeightmapHandle heightmapHandle in selectedHandles) { Vector2Int tileCoords = heightmapHandle.TileCoords; Vector2Int anchorCoords = GetAxisCorrectedAnchor(tileCoords, anchorHandle.TileCoords, locked, lockedAxis); Vector2Int difference = tileCoords - anchorCoords; float deltaX = (float)difference.x / manipulatedDifference.x; if (float.IsNaN(deltaX) || float.IsInfinity(deltaX)) { deltaX = float.NegativeInfinity; } float deltaY = (float)difference.y / manipulatedDifference.y; if (float.IsNaN(deltaY) || float.IsInfinity(deltaY)) { deltaY = float.NegativeInfinity; } float delta = Mathf.Max(deltaX, deltaY); if (float.IsNegativeInfinity(delta)) { delta = 0; } if (respectSlopes) { map[tileCoords].SurfaceHeight += (int)(heightDelta * delta); } else { map[tileCoords].SurfaceHeight = originalHeight + (int)(heightDelta * delta); } } } else if (anchorHandle != null) { float anchorPositionX = anchorHandle.TileCoords.x * 4; float anchorPositionY = anchorHandle.TileCoords.y * 4; Vector2 anchorPosition = new Vector2(anchorPositionX, anchorPositionY); Vector3 raycastPoint = LayoutManager.Instance.CurrentCamera.CurrentRaycast.point; Vector2 raycastPosition = new Vector2(raycastPoint.x, raycastPoint.z); Vector2 positionDelta = raycastPosition - anchorPosition; if (positionDelta.magnitude > 4) { anchorPlaneLine.gameObject.SetActive(true); anchorPlaneLine.TileCoords = anchorHandle.TileCoords; bool horizontal = Mathf.Abs(positionDelta.x) > Mathf.Abs(positionDelta.y); anchorPlaneLine.Alignment = horizontal ? PlaneAlignment.Vertical : PlaneAlignment.Horizontal; } else { anchorPlaneLine.gameObject.SetActive(false); } } } } if (Input.GetMouseButtonUp(0)) { if (state == HeightUpdaterState.Dragging && Input.GetKey(KeyCode.LeftShift)) { selectedHandles.AddRange(lastFrameHoveredHandles); } else if (state == HeightUpdaterState.Dragging) { deselectedHandles = selectedHandles; selectedHandles = lastFrameHoveredHandles; } else if (state == HeightUpdaterState.Manipulating) { map.CommandManager.FinishAction(); activeHandle = null; } state = HeightUpdaterState.Idle; } if (Input.GetMouseButtonDown(1)) { if (state == HeightUpdaterState.Manipulating && activeHandle != null) { map.CommandManager.UndoAction(); activeHandle = null; state = HeightUpdaterState.Recovering; } else if (anchorHandle != null) { anchorHandle = null; anchorPlaneLine.gameObject.SetActive(false); state = HeightUpdaterState.Recovering; } else if (state == HeightUpdaterState.Idle) { deselectedHandles = selectedHandles; selectedHandles = new List <HeightmapHandle>(); } else { state = HeightUpdaterState.Recovering; } LayoutManager.Instance.CurrentCamera.RenderSelectionBox = false; } }