Skip to content

Commit

Permalink
Fix issue in ScaleLogic when multiple interactors have same position (#…
Browse files Browse the repository at this point in the history
…933)

* With XRI3, the interactor is no longer necessarily positioned with
  something like a TrackedPoseDriver.  Instead, the interactor can
  use an InteractionAttachController, which will instantiate GameObjects
  to represent the attach points (anchor parent and child) for the
  interaction.  In these cases, like the default XRI3 rig hands, the
  interactor itself (NearFarInteractor within hands group) will not get
  positioned.  So in this issue's case, both the right and left hand
  far interactor positions are left at defaults and match exactly.

---------

Co-authored-by: Scott Haynie <shaynie@users.noreply.github.com>
  • Loading branch information
whebertML and shaynie authored Nov 6, 2024
1 parent c32edd7 commit 0a732c5
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ public class ScaleLogic : ManipulationLogic<Vector3>
private Vector3 startAttachTransformScale;
private float startHandDistanceMeters;

// Meaningful minimum squared distance of scaling handles to calculate scale.
private const float scaleDistanceSquaredEpsilon = .0001f;

/// <inheritdoc />
public override void Setup(List<IXRSelectInteractor> interactors, IXRSelectInteractable interactable, MixedRealityTransform currentTarget)
{
Expand Down Expand Up @@ -80,6 +83,17 @@ private float GetScaleBetweenInteractors(List<IXRSelectInteractor> interactors,
// Defer square root until end for performance.
var distance = Vector3.SqrMagnitude(interactors[i].transform.position -
interactors[j].transform.position);

// Prefer to use the interactor positions directly above for scaling stability, but
// fallback to attach transforms if the interactor positions appear identical.
if (distance < Mathf.Epsilon)
{
distance = Vector3.SqrMagnitude(interactors[i].GetAttachTransform(interactable).position -
interactors[j].GetAttachTransform(interactable).position);
}
// Ensure distance is a meaningful magnitude for scaling.
distance = Mathf.Max(distance, scaleDistanceSquaredEpsilon);

if (distance < result)
{
result = distance;
Expand Down

0 comments on commit 0a732c5

Please sign in to comment.