API reference
API reference
Select your platform
No SDKs available
No versions available

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()}");
}

Member Enumerations

Enumeration SceneLabels

Flags enumeration for scene labels, indicating the type of object represented by an anchor and its classification.
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

Enumeration ComponentType

Flags enumeration for component type, scene anchors can either have plane or volume components associated with them or both.
None
= 0
Plane
= 1 << 0
Volume
= 1 << 1
All
= Plane | Volume

Properties

The scene label categorizing the anchor.
This represents the semantic classification of the anchor, such as "WALL_FACE" or "TABLE".
Optional rectangular bounds on a plane associated with the anchor.
Examples of anchors with a plane are a wall or a floor.
Optional volumetric bounds associated with the anchor.
Example of anchors with a volume are a table or a couch.
A list of local-space points defining the boundary of the plane associated with the anchor.
This is useful for any spatial calculations.
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.
Reference to the parent room object.
This is set during construction. Do not set this directly.
A ParentAnchor can be one of the following:
Note that this relationship is inferred based on the positioning and size of the anchors, and it is not guaranteed to be 100% accurate.
  • For Wall Art, Door/Window Frames, the parent anchor will be the wall it is attached to
  • For volumes it will the floor or another volume if they are stacked on top of each other
A list of child anchors associated with this anchor.
See ParentAnchor for details on how this relationship is determined.
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.
Mesh 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.

Member Functions

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.
Parameters
ray
The ray to test for intersections.
maxDist
The maximum distance the ray should check for intersections.
hitInfo
Output parameter that will contain the hit information if an intersection occurs.
componentTypes
The type of components to ray cast against.
Returns
True if the ray hits either the plane or the volume, false otherwise.
Determines if a given position is within the boundary of the plane associated with the anchor.
Parameters
position
The local space point to check.
Returns
True if the position is within the boundary, false otherwise.
Adds a reference to a child anchor.
Parameters
childObj
The child anchor to add.
Clears all references to child anchors.
Calculates the distance from a specified position to the closest surface of the anchor.
Parameters
position
The position from which to measure.
componentTypes
The component types to include.
Returns
The distance to the closest surface.
Finds the closest surface position from a given point and returns the distance to it.
Parameters
testPosition
The position to test.
closestPosition
The closest position on the surface.
componentTypes
The component types to include.
Returns
The distance to the closest surface position.
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.
Parameters
testPosition
The position to test.
closestPosition
The closest position on the surface.
normal
The normal at the closest position.
componentTypes
The component types to include.
Returns
The distance to the closest surface position.
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.
Returns
The center position of the anchor.
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
See Also
MRUKAnchor.PlaneRect, MRUKAnchor.VolumeBounds
or
Returns
The size of the anchor
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.
Returns
An array of Vector3 representing the centers of the bounding box faces or the plane center.
Tests if a given world position is inside the volume of the anchor, considering an optional distance buffer and whether to test vertical bounds.
Parameters
worldPosition
The world position to test.
testVerticalBounds
Whether to include vertical bounds in the test.
distanceBuffer
An optional buffer distance to expand the volume for the test.
Returns
True if the position is inside the volume, false otherwise.
Loads a mesh representing the global mesh associated with the anchor, if available.
Returns
A Mesh object containing the triangles of the global mesh, or null if not available.
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.
Parameters
label
The label to check, provided as a string.
Returns
True if the object has the specified label, false otherwise.
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.
Parameters
labels
A list of labels to check, provided as strings.
Returns
True if the object has any of the specified labels, false otherwise.
Checks if the anchor has any of the specified scene labels.
Parameters
labelFlags
The scene labels to check against the anchor's labels.
Returns
True if the anchor has any of the specified labels, false otherwise.
Retrieves the labels associated with this object as an enum.
This method is obsolete. Use the 'Label' property directly instead.
Returns
The labels as an enum of type SceneLabels.
OVRSemanticLabels.DeprecationMessage
Did you find this page helpful?
Thumbs up icon
Thumbs down icon