Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

ARFoundation: TryAddReferencePoint(Pose pose) creates a new Pose

Discussion in 'AR' started by steffen-itterheim, Jun 22, 2018.

  1. steffen-itterheim

    steffen-itterheim

    Joined:
    Nov 10, 2015
    Posts:
    24
    A colleague found this inefficiency in UnityEngine.XR.ARFoundation.ARReferencePointManager:

    Code (CSharp):
    1. // Takes a Pose as input and calls the partner method with pose.position/pose.rotation
    2. public ARReferencePoint TryAddReferencePoint(Pose pose)
    3.         {
    4.             return TryAddReferencePoint(pose.position, pose.rotation);
    5.         }
    6.  
    7. // creates a new Pose using position and rotation
    8.         public ARReferencePoint TryAddReferencePoint(Vector3 position, Quaternion rotation)
    9.         {
    10.             var referencePointSubsystem = ARSubsystemManager.referencePointSubsystem;
    11.             if (referencePointSubsystem == null)
    12.                 return null;
    13.  
    14.             // World space pose
    15.             var pose = new Pose(position, rotation);
    16.  
    17.             // Session space pose
    18.             var sessionRelativePose = m_SessionOrigin.trackablesParent.InverseTransformPose(pose);
    19.  
    20.             // Add the reference point to the XRReferencePointSubsystem
    21.             TrackableId referencePointId;
    22.             if (!referencePointSubsystem.TryAddReferencePoint(sessionRelativePose.position, sessionRelativePose.rotation, out referencePointId))
    23.                 return null;
    24.  
    25.             return CreateReferencePointComponent(referencePointId, sessionRelativePose);
    26.         }
    We would expect the version taking a position/rotation to create a Pose instance, then forwarding this Pose instance to the method taking a pose which then performs all the tracking stuff and returning a ReferencePointComponent.

    Right now, providing an existing Pose to the function will cause a second Pose object to be created for no obvious reason (Pose is a struct).