API reference

MRUKAnchor Class

Extends MonoBehaviour
Represents an anchor within MR Utility Kit, providing spatial and semantic information.
This class is used to define and manage anchors in a mixed reality environment, allowing for spatial mapping and interaction. An anchor is a world-locked frame of reference that gives a position and orientation to a virtual object in the real world, such as walls, floors, and furniture. Every anchor is childed to a MRUKRoom, and has SceneLabels to indicate its type. anchors might have a VolumeBounds, a PlaneRect, and a Mesh associated with them depending on their semantic label. It offers convenience methods such as a collisionless raycast and other utility functions to work with the anchors representation in space.
// Iterate through all the anchors in a room and print the label and the anchors' center
var room = MRUK.Instance.GetCurrentRoom();
foreach (var anchor in room.Anchors)
{
    Debug.Log($"Anchor {anchor.Label} is centered at {anchor.GetAnchorCenter()}");
}

Properties

Anchor : OVRAnchor
[Get]
Reference to the scene anchor associated with this anchor.
You should not need to use this directly, only use this if you know what you are doing.
Signature
OVRAnchor Anchor
ChildAnchors : List< MRUKAnchor >
[Get]
A list of child anchors associated with this anchor.
Signature
List<MRUKAnchor> ChildAnchors
GlobalMesh : Mesh
[Get]
The triangle mesh which covers the entire space, associated to the global mesh anchor.
The global mesh is a low-fidelity, high-coverage artifact which describes the boundary between free and occupied space in a room. It is generated automatically during the space setup experience. Use cases:
  • Fast Collisions When used as a collider, the scene mesh allows virtual content to collide against real objects. Bouncing balls, projectiles, and other forms of fast collisions benefit from the high coverage of the room.
  • Obstacle Avoidance When used for intersection checks or as part of a navmesh configuration, the scene mesh allows you to know where obstacles in the room are. This can inform content placement and AI navigation. See SceneNavigation if interested in this use case.
Signature
Mesh GlobalMesh
HasValidHandle : bool
[Get]
An anchor will have a valid handle if it was loaded from device and there is a system level anchor backing it.
Anchors loaded from JSON or Prefabs do not have a valid handle. You should not need to use this directly, only use this if you know what you are doing. The behaviour may change in the future.
Signature
bool HasValidHandle
Label : SceneLabels
[Get]
The scene label categorizing the anchor.
This represents the semantic classification of the anchor, such as "WALL_FACE" or "TABLE".
Signature
SceneLabels Label
ParentAnchor : MRUKAnchor
[Get]
References to child anchors, populated via MRUKRoom.CalculateHierarchyReferences.
Signature
MRUKAnchor ParentAnchor
PlaneBoundary2D : List< Vector2 >
[Get]
A list of local-space points defining the boundary of the plane associated with the anchor.
This is useful for any spatial calculations.
Signature
List<Vector2> PlaneBoundary2D
PlaneRect : Rect?
[Get]
Optional rectangular bounds on a plane associated with the anchor.
Examples of anchors with a plane are a wall or a floor.
Signature
Rect? PlaneRect
Room : MRUKRoom
[Get]
Reference to the parent room object.
This is set during construction. Do not set this directly.
Signature
MRUKRoom Room
VolumeBounds : Bounds?
[Get]
Optional volumetric bounds associated with the anchor.
Example of anchors with a volume are a table or a couch.
Signature
Bounds? VolumeBounds

Methods

AddChildReference ( childObj )
Adds a reference to a child anchor.
Signature
void AddChildReference(MRUKAnchor childObj)
Parameters
childObj: MRUKAnchor  The child anchor to add.
Returns
void
ClearChildReferences ()
Clears all references to child anchors.
Signature
void ClearChildReferences()
Returns
void
GetAnchorCenter ()
Gets the center position of the anchor.
If volume bounds are defined, it returns the center of the volume; otherwise, it returns the anchor's position.
Signature
Vector3 GetAnchorCenter()
Returns
Vector3  The center position of the anchor.
GetAnchorSize ()
A convenience function to get a transform-friendly Vector3 size of an anchor.
If you'd like the size of the quad or volume instead, use
Signature
Vector3 GetAnchorSize()
Returns
Vector3  The size of the anchor
GetBoundsFaceCenters ()
Retrieves the centers of the bounding box faces if a volume is defined, or the center of the plane if only a plane is defined.
Signature
Vector3[] GetBoundsFaceCenters()
Returns
Vector3[]  An array of Vector3 representing the centers of the bounding box faces or the plane center.
GetClosestSurfacePosition ( testPosition , closestPosition , componentTypes )
Finds the closest surface position from a given point and returns the distance to it.
Signature
float GetClosestSurfacePosition(Vector3 testPosition, out Vector3 closestPosition, ComponentType componentTypes=ComponentType.All)
Parameters
testPosition: Vector3  The position to test.
closestPosition: out Vector3  The closest position on the surface.
componentTypes: ComponentType  The component types to include.
Returns
float  The distance to the closest surface position.
GetClosestSurfacePosition ( testPosition , closestPosition , normal , componentTypes )
Finds the closest surface position from a given point, providing the position, normal at that position, and the distance.
If the point is inside a volume, it will return a negative distance representing the distance beneath the surface.
Signature
float GetClosestSurfacePosition(Vector3 testPosition, out Vector3 closestPosition, out Vector3 normal, ComponentType componentTypes=ComponentType.All)
Parameters
testPosition: Vector3  The position to test.
closestPosition: out Vector3  The closest position on the surface.
normal: out Vector3  The normal at the closest position.
componentTypes: ComponentType  The component types to include.
Returns
float  The distance to the closest surface position.
GetDistanceToSurface ( position , componentTypes )
Calculates the distance from a specified position to the closest surface of the anchor.
Signature
float GetDistanceToSurface(Vector3 position, ComponentType componentTypes=ComponentType.All)
Parameters
position: Vector3  The position from which to measure.
componentTypes: ComponentType  The component types to include.
Returns
float  The distance to the closest surface.
GetLabelsAsEnum ()
Retrieves the labels associated with this object as an enum.
This method is obsolete. Use the 'Label' property directly instead.
Signature
SceneLabels GetLabelsAsEnum()
Returns
SceneLabels  The labels as an enum of type SceneLabels.
HasAnyLabel ( labels )
Checks if the current object has any of the specified labels.
This method is obsolete. String-based labels are deprecated as of version 65. Please use the equivalent enum-based method.
Signature
bool HasAnyLabel(List< string > labels)
Parameters
labels: List< string >  A list of labels to check, provided as strings.
Returns
bool  True if the object has any of the specified labels, false otherwise.
HasAnyLabel ( labelFlags )
Checks if the anchor has any of the specified scene labels.
Signature
bool HasAnyLabel(SceneLabels labelFlags)
Parameters
labelFlags: SceneLabels  The scene labels to check against the anchor's labels.
Returns
bool  True if the anchor has any of the specified labels, false otherwise.
HasLabel ( label )
Checks if the current object has a specific label.
This method is obsolete. String-based labels are deprecated as of version 65. Please use the equivalent enum-based method.
Signature
bool HasLabel(string label)
Parameters
label: string  The label to check, provided as a string.
Returns
bool  True if the object has the specified label, false otherwise.
IsPositionInBoundary ( position )
Determines if a given position is within the boundary of the plane associated with the anchor.
Signature
bool IsPositionInBoundary(Vector2 position)
Parameters
position: Vector2  The local space point to check.
Returns
bool  True if the position is within the boundary, false otherwise.
IsPositionInVolume ( worldPosition , testVerticalBounds , distanceBuffer )
Tests if a given world position is inside the volume of the anchor, considering an optional distance buffer and whether to test vertical bounds.
Signature
bool IsPositionInVolume(Vector3 worldPosition, bool testVerticalBounds, float distanceBuffer=0.0f)
Parameters
worldPosition: Vector3  The world position to test.
testVerticalBounds: bool  Whether to include vertical bounds in the test.
distanceBuffer: float  An optional buffer distance to expand the volume for the test.
Returns
bool  True if the position is inside the volume, false otherwise.
LoadGlobalMeshTriangles ()
Loads a mesh representing the global mesh associated with the anchor, if available.
Signature
Mesh LoadGlobalMeshTriangles()
Returns
Mesh  A Mesh object containing the triangles of the global mesh, or null if not available.
Raycast ( ray , maxDist , hitInfo , componentTypes )
Performs a raycast against the anchor's plane and volume to determine if and where a ray intersects.
This method avoids using colliders and Physics.Raycast for several reasons:
  • It requires tags/layers to filter out Scene API object hits from general raycasts, which can be intrusive to a developer's pipeline by altering their project settings.
  • It necessitates specific Plane and Volume prefabs that MRUK instantiates with colliders as children.
  • Using Physics.Raycast is considered overkill since the locations of all Scene API primitives are already known; thus, there's no need to raycast everywhere to find them.
Instead, this method uses Plane.Raycast and other custom methods to determine if the ray has hit the surface of the object.
Signature
bool Raycast(Ray ray, float maxDist, out RaycastHit hitInfo, ComponentType componentTypes=ComponentType.All)
Parameters
ray: Ray  The ray to test for intersections.
maxDist: float  The maximum distance the ray should check for intersections.
hitInfo: out RaycastHit  Output parameter that will contain the hit information if an intersection occurs.
componentTypes: ComponentType  The type of components to ray cast against.
Returns
bool  True if the ray hits either the plane or the volume, false otherwise.

Inner Enums

SceneLabels Enum

Flags enumeration for scene labels, indicating the type of object represented by an anchor and its classification.

Enumeration Constants

MemberValue
FLOOR
1 << OVRSemanticLabels.Classification.Floor
CEILING
1 << OVRSemanticLabels.Classification.Ceiling
WALL_FACE
1 << OVRSemanticLabels.Classification.WallFace
TABLE
1 << OVRSemanticLabels.Classification.Table
COUCH
1 << OVRSemanticLabels.Classification.Couch
DOOR_FRAME
1 << OVRSemanticLabels.Classification.DoorFrame
WINDOW_FRAME
1 << OVRSemanticLabels.Classification.WindowFrame
OTHER
1 << OVRSemanticLabels.Classification.Other
STORAGE
1 << OVRSemanticLabels.Classification.Storage
BED
1 << OVRSemanticLabels.Classification.Bed
SCREEN
1 << OVRSemanticLabels.Classification.Screen
LAMP
1 << OVRSemanticLabels.Classification.Lamp
PLANT
1 << OVRSemanticLabels.Classification.Plant
WALL_ART
1 << OVRSemanticLabels.Classification.WallArt
GLOBAL_MESH
1 << OVRSemanticLabels.Classification.SceneMesh
INVISIBLE_WALL_FACE
1 << OVRSemanticLabels.Classification.InvisibleWallFace

ComponentType Enum

Flags enumeration for component type, scene anchors can either have plane or volume components associated with them or both.

Enumeration Constants

MemberValue
None
0
Plane
1 << 0
Volume
1 << 1
All
Plane | Volume