Skip to content

Commit

Permalink
Refactor how colliders are processed in interactor.preproces step
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmed-shariff committed Mar 5, 2024
1 parent 4168c18 commit e676b0f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 7 deletions.
14 changes: 8 additions & 6 deletions Runtime/Interaction/HPUIInteractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ public class HPUIInteractor: XRBaseInteractor, IHPUIInteractor
private bool justStarted = false;
private Vector3 lastInteractionPoint;
private PhysicsScene physicsScene;
private RaycastHit[] sphereCastHits = new RaycastHit[25];
private Collider[] overlapSphereHits = new Collider[25];
private RaycastHit[] sphereCastHits = new RaycastHit[200];
private Collider[] overlapSphereHits = new Collider[200];

/// <inheritdoc />
protected override void Awake()
Expand Down Expand Up @@ -130,6 +130,7 @@ public override void PreprocessInteractor(XRInteractionUpdateOrder.UpdatePhase u
// If no movement is recorded.
// Check if spherecast size is sufficient for proper cast, or if first frame since last frame poke position will be invalid.
int numberOfOverlaps;
List<Collider> colliders;

if (justStarted || overlapSqrMagnitude < 0.001f)
{
Expand All @@ -141,6 +142,7 @@ public override void PreprocessInteractor(XRInteractionUpdateOrder.UpdatePhase u
Physics.AllLayers,
// FIXME: QueryTriggerInteraction should be allowed to be set in inpsector
QueryTriggerInteraction.Ignore);
colliders = overlapSphereHits.ToList();
}
else
{
Expand All @@ -154,17 +156,17 @@ public override void PreprocessInteractor(XRInteractionUpdateOrder.UpdatePhase u
Physics.AllLayers,
// FIXME: QueryTriggerInteraction should be allowed to be set in inpsector
QueryTriggerInteraction.Ignore);

colliders = sphereCastHits.Select(s => s.collider).ToList();
}

lastInteractionPoint = pokeInteractionPoint;
justStarted = false;

for (var i = 0; i < numberOfOverlaps; ++i)
{
if (interactionManager.TryGetInteractableForCollider(sphereCastHits[i].collider, out var interactable) &&
interactable is IXRSelectInteractable selectable &&
interactable is IXRHoverInteractable hoverable && hoverable.IsHoverableBy(this))
if (interactionManager.TryGetInteractableForCollider(colliders[i], out var interactable) &&
!validTargets.Contains(interactable) &&
interactable is IHPUIInteractable hpuiInteractable && hpuiInteractable.IsHoverableBy(this))
{
validTargets.Add(interactable);
}
Expand Down
2 changes: 1 addition & 1 deletion Runtime/Interaction/IHPUIInteractable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace ubco.ovilab.HPUI.Interaction
{
public interface IHPUIInteractable : IXRInteractable, IXRSelectInteractable
public interface IHPUIInteractable : IXRSelectInteractable, IXRHoverInteractable
{
/// <summary>
/// Lower z order will get higher priority.
Expand Down
37 changes: 37 additions & 0 deletions Tests/HPUIGestureLogicUnifiedTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,18 @@ void IHPUIInteractable.OnTap(HPUITapEventArgs args)

Transform IXRInteractable.transform => throw new NotImplementedException();

HoverEnterEvent IXRHoverInteractable.firstHoverEntered => throw new NotImplementedException();

HoverExitEvent IXRHoverInteractable.lastHoverExited => throw new NotImplementedException();

HoverEnterEvent IXRHoverInteractable.hoverEntered => throw new NotImplementedException();

HoverExitEvent IXRHoverInteractable.hoverExited => throw new NotImplementedException();

List<IXRHoverInteractor> IXRHoverInteractable.interactorsHovering => throw new NotImplementedException();

bool IXRHoverInteractable.isHovered => throw new NotImplementedException();

event Action<InteractableRegisteredEventArgs> IXRInteractable.registered
{
add
Expand Down Expand Up @@ -509,6 +521,31 @@ void IXRInteractable.ProcessInteractable(XRInteractionUpdateOrder.UpdatePhase up
{
throw new NotImplementedException();
}

bool IXRHoverInteractable.IsHoverableBy(IXRHoverInteractor interactor)
{
throw new NotImplementedException();
}

void IXRHoverInteractable.OnHoverEntering(HoverEnterEventArgs args)
{
throw new NotImplementedException();
}

void IXRHoverInteractable.OnHoverEntered(HoverEnterEventArgs args)
{
throw new NotImplementedException();
}

void IXRHoverInteractable.OnHoverExiting(HoverExitEventArgs args)
{
throw new NotImplementedException();
}

void IXRHoverInteractable.OnHoverExited(HoverExitEventArgs args)
{
throw new NotImplementedException();
}
#endregion
}
}
Expand Down

0 comments on commit e676b0f

Please sign in to comment.