Class GestureTransformationUtility
Provides helper functions for common functionality to transform objects in AR.
Inherited Members
Namespace: UnityEngine.XR.Interaction.Toolkit.AR
Assembly: Unity.XR.Interaction.Toolkit.dll
Syntax
public static class GestureTransformationUtility
Methods
GetBestPlacementPosition(Vector3, Vector2, float, float, float, GestureTranslationMode, XROrigin, TrackableType, int)
Calculates the best position to place an object in AR based on screen position. Could be used for tapping a location on the screen, dragging an object, or using a fixed cursor in the center of the screen for placing and moving objects.
Declaration
public static GestureTransformationUtility.Placement GetBestPlacementPosition(Vector3 currentAnchorPosition, Vector2 screenPosition, float groundingPlaneHeight, float hoverOffset, float maxTranslationDistance, GestureTransformationUtility.GestureTranslationMode gestureTranslationMode, XROrigin sessionOrigin, TrackableType trackableTypes = null, int fallbackLayerMask = 0)
Parameters
Type | Name | Description |
---|---|---|
Vector3 | currentAnchorPosition | Position of the parent anchor, i.e., where the object is before translation starts. |
Vector2 | screenPosition | Location on the screen in pixels to place the object at. |
float | groundingPlaneHeight | The starting height of the plane to place the object on. |
float | hoverOffset | How much should the object hover above the groundingPlane before it has been placed. |
float | maxTranslationDistance | The maximum distance allowed to translate the object. |
GestureTransformationUtility.GestureTranslationMode | gestureTranslationMode | The translation mode, indicating the plane types allowed. |
XROrigin | sessionOrigin | The Unity.XR.CoreUtils.XROrigin used for ray casting. |
TrackableType | trackableTypes | (Optional) The types of trackables to cast against. |
int | fallbackLayerMask | (Optional) The LayerMask that Unity uses during an additional ray cast when no trackables are hit. Defaults to Nothing which skips the fallback ray cast. |
Returns
Type | Description |
---|---|
GestureTransformationUtility.Placement | Returns the best placement position. |
Remarks
Unity places objects along the x/z of the grounding plane. When placed on an AR plane below the grounding plane, the object will drop straight down onto it in world space. This prevents the object from being pushed deeper into the scene when moving from a higher plane to a lower plane. When moving from a lower plane to a higher plane, this function returns a new groundingPlane to replace the old one.
Raycast(Vector2, List<ARRaycastHit>, XROrigin, TrackableType, int)
Cast a ray from a point in screen space against trackables, i.e., detected features such as planes. Can optionally fallback to hit test against Colliders in the loaded Scenes when no trackables were hit.
Declaration
public static bool Raycast(Vector2 screenPoint, List<ARRaycastHit> hitResults, XROrigin sessionOrigin, TrackableType trackableTypes = null, int fallbackLayerMask = 0)
Parameters
Type | Name | Description |
---|---|---|
Vector2 | screenPoint | The point, in device screen pixels, from which to cast. |
List<ARRaycastHit> | hitResults | Contents are replaced with the ray cast results, if successful. |
XROrigin | sessionOrigin | The Unity.XR.CoreUtils.XROrigin used for ray casting. |
TrackableType | trackableTypes | (Optional) The types of trackables to cast against. |
int | fallbackLayerMask | (Optional) The LayerMask that Unity uses during an additional ray cast when no trackables are hit. Defaults to Nothing which skips the fallback ray cast. |
Returns
Type | Description |
---|---|
bool | Returns true if the ray cast hit a trackable in the |
Remarks
Unity uses the 3D physics scene of the camera when performing the fallback ray cast.