Skip to content

Commit

Permalink
HPUIInteractable exposes bounds max and min
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-shariff committed Jan 14, 2024
1 parent 11c445b commit 8cccccd
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Runtime/Interaction/DeformableSurfaceCollidersManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Unity.Jobs;
using UnityEngine.Jobs;
using System;
using System.Linq;

namespace ubco.ovilab.HPUI.Interaction
{
Expand All @@ -26,6 +27,9 @@ public class DeformableSurfaceCollidersManager: MonoBehaviour

private Dictionary<Collider, Vector2> colliderCoords;

public Vector2 boundsMax { get; protected set; }
public Vector2 boundsMin { get; protected set; }

/// <inheritdoc />
private void OnDestroy()
{
Expand Down Expand Up @@ -160,6 +164,10 @@ private List<Collider> GenerateColliders(List<Vector3> positions, List<Vector3>
}

colliderObjects = new TransformAccessArray(colliderTransforms);

boundsMax = new Vector2(colliderCoords.Values.Select(v => v.x).Max(), colliderCoords.Values.Select(v => v.y).Max());
boundsMin = new Vector2(colliderCoords.Values.Select(v => v.x).Min(), colliderCoords.Values.Select(v => v.y).Min());

return colliders;
}

Expand Down
8 changes: 8 additions & 0 deletions Runtime/Interaction/HPUIBaseInteractable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ public Handedness Handedness
/// <inheritdoc />
public int zOrder { get => _zOrder; set => _zOrder = value; }

/// <inheritdoc />
public virtual Vector2 boundsMax { get; protected set; }

/// <inheritdoc />
public virtual Vector2 boundsMin { get; protected set; }

[SerializeField]
private HPUITapEvent tapEvent = new HPUITapEvent();

Expand Down Expand Up @@ -78,6 +84,8 @@ protected virtual void ComputeSurfaceBounds()

Bounds colliderBounds = boundsCollider.bounds;
Transform interactableTransform = GetAttachTransform(null);
boundsMax = ComputeTargetPointOnInteractablePlane(colliderBounds.max, interactableTransform);
boundsMin = ComputeTargetPointOnInteractablePlane(colliderBounds.min, interactableTransform);
}

protected DistanceInfo GetDistanceOverride(IXRInteractable interactable, Vector3 position)
Expand Down
6 changes: 6 additions & 0 deletions Runtime/Interaction/HPUIContinuousInteractable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ public class HPUIContinuousInteractable: HPUIBaseInteractable
[Tooltip("(Optional) the MeshFilter of the corresponding SkinnedMeshRenderer. If not set, will create a child object with the MeshFilter and SkinnedMeshRenderer.")]
public MeshFilter filter;

/// <inheritdoc />
public override Vector2 boundsMax { get => surfaceCollidersManager?.boundsMax ?? Vector2.zero; }

/// <inheritdoc />
public override Vector2 boundsMin { get => surfaceCollidersManager?.boundsMin ?? Vector2.zero; }

[SerializeField]
private HPUIContinuousSurfaceEvent continuousSurfaceCreatedEvent = new HPUIContinuousSurfaceEvent();

Expand Down
12 changes: 12 additions & 0 deletions Runtime/Interaction/IHPUIInteractable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@ public interface IHPUIInteractable : IXRInteractable, IXRSelectInteractable
/// </summary>
int zOrder { get; set; }

/// <summary>
/// The max point on the surface of the interactable, relative to the center of the object.
/// Center is the position of transform returned by the <see cref="GetAttachTransform"/>.
/// </summary>
Vector2 boundsMax { get; }

/// <summary>
/// The min point on the surface of the interactable, relative to the center of the object.
/// Center is the position of transform returned by the <see cref="GetAttachTransform"/>.
/// </summary>
Vector2 boundsMin { get; }

/// <summary>
/// Get the projection of the interactors position on the xz plane of this interactable, normalized.
/// the returned Vector2 - (x, z) on the xz-plane, relative to the center of the interactable.
Expand Down
5 changes: 5 additions & 0 deletions Tests/HPUIGestureLogicUnifiedTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,11 @@ public void Reset()
#region IHPUIInteracttable only
public int zOrder { get; set; }

public Vector2 boundsMax { get; set; }

public Vector2 boundsMin { get; set; }


Vector2 IHPUIInteractable.ComputeInteractorPostion(IXRInteractor interactor)
{
return interactorPosition;
Expand Down

0 comments on commit 8cccccd

Please sign in to comment.