loadSceneFromDevice or loadSceneFromJsonString are called multiple times MRUK will add, update, and remove rooms to keep the rooms in MRUKFeature in sync with the rooms that are in the system. MRUKFeature provides callbacks that can be used to get notified when rooms or anchors get added, updated, or removed.
MRUKFeature
(
context
, systemManager
)
|
Signature
constructor(context: Context, systemManager: SystemManager) Parameters
context:
Context
systemManager:
SystemManager Returns |
context
: Context
[Get] |
Signature
val context: Context |
rooms
: MutableList
[Get] |
List of all currently loaded rooms in the scene.
Rooms are added, updated, or removed when loading scene data via MRUKFeature.loadSceneFromDevice or MRUKFeature.loadSceneFromJsonString. Use MRUKSceneEventListener to receive notifications when rooms change.
Signature
val rooms: MutableList<MRUKRoom> |
systemManager
: SystemManager
[Get] |
Signature
val systemManager: SystemManager |
addSceneEventListener
(
listener
)
|
Registers a listener for scene events.
This function adds a listener that will be notified when rooms or anchors are added, updated, or removed. Use this to respond to changes in the scene, such as when a new room is discovered or when an anchor's position is updated.
Signature
fun addSceneEventListener(listener: MRUKSceneEventListener) Parameters |
clearRooms
()
|
Clears all loaded rooms and their associated resources.
This function removes all rooms from memory and cleans up their resources. This is useful when you want to reset the state of the MRUK system or prepare for loading a new set of rooms.
Signature
fun clearRooms() |
componentsToRegister
()
|
Override this function to define a list of components that should be used by the application.
Signature
open override fun componentsToRegister(): List<ComponentRegistration> Returns
List
|
configureTrackers
(
trackers
)
|
Configures and starts the specified object trackers.
This function enables tracking of real-world objects like keyboards and QR codes. Once configured, the system will begin detecting and tracking these objects in the environment. When objects are detected, they will trigger the appropriate callbacks.
Signature
fun configureTrackers(trackers: Set<Tracker>): CompletableFuture<MRUKStartTrackerResult> Parameters
trackers:
Set
Returns
CompletableFuture
|
earlySystemsToRegister
()
|
Override this method to register your systems that should be executed with PriorityGroup EARLY.
Signature
open fun earlySystemsToRegister(): List<SystemBase> Returns
List
|
findRoom
(
roomUuid
)
|
Finds a room that matches the given UUID.
A room in MRUK represents a mapped physical space containing anchors for walls, floors, ceilings, and other detected elements. This function searches through all loaded rooms to find one with a matching UUID.
Signature
fun findRoom(roomUuid: UUID): MRUKRoom? Parameters
roomUuid:
UUID
Returns
The matching MRUKRoom object if found, or null if no room with the specified UUID exists
|
getCurrentRoom
()
|
Gets the room that the user is currently in, based on head position.
This function attempts to determine which room the user is currently in by checking if the user's head position is within any of the loaded rooms. If the user is not in any room, it defaults to the first room in the list (if any rooms are loaded).
Signature
fun getCurrentRoom(): MRUKRoom? Returns
The current room, or null if no rooms are loaded or the user is not in any room and there are no rooms to default to
|
getDependencies
()
|
Override this method to define a list of dependencies required by this feature. This will be verified at runtime.
Example:
// MyCustomFeature.kt
override fun getDependencies(): List<KClass<out SpatialFeature>> {
return listOf(ToolkitFeature::class)
}
@return A list of SpatialFeature classes representing the dependencies.
Signature
open fun getDependencies(): List<KClass<out SpatialFeature>> Returns
List
|
getEnvironmentRaycasterStatus
()
|
Get the environment raycasters current status.
Signature
fun getEnvironmentRaycasterStatus(): MRUKEnvironmentRaycasterStatus |
isWorldLockingEnabled
()
|
Returns whether World Locking is currently enabled.
Signature
fun isWorldLockingEnabled(): Boolean Returns
Boolean
|
lateSystemsToRegister
()
|
Override this method to register your systems that should be executed with PriorityGroup LATE.
Signature
open fun lateSystemsToRegister(): List<SystemBase> Returns
List
|
loadLibrary
(
libName
)
|
Loads a native library into the application.
Signature
open fun loadLibrary(libName: String) Parameters
libName:
String
|
loadSceneFromDevice
(
requestSceneCaptureIfNoDataFound
, removeMissingRooms
, sceneModel
)
|
Load the scene from the device.
Signature
fun loadSceneFromDevice(requestSceneCaptureIfNoDataFound: Boolean = true, removeMissingRooms: Boolean = true, sceneModel: SceneModel = SceneModel.V1): CompletableFuture<MRUKLoadDeviceResult> Parameters
requestSceneCaptureIfNoDataFound:
Boolean
removeMissingRooms:
Boolean
true any rooms that aren't found on the device anymore will be removed. Usually this the behavior you want. If you want to have rooms loaded from the device and rooms from JSON co-exist you want to set removeMissingRooms to false.
sceneModel:
SceneModel Returns
CompletableFuture
|
loadSceneFromJsonString
(
jsonString
, removeMissingRooms
, sceneModel
)
|
Load the scene from a JSON string.
Signature
fun loadSceneFromJsonString(jsonString: String, removeMissingRooms: Boolean = true, sceneModel: SceneModel = SceneModel.V1) Parameters
jsonString:
String
removeMissingRooms:
Boolean
sceneModel:
SceneModel |
onCreate
(
savedInstanceState
)
|
Called when the application is created. Override this method to perform actions during the OnCreate() lifecycle of the application.
Signature
open override fun onCreate(savedInstanceState: Bundle?) Parameters
savedInstanceState:
Bundle?
|
onDestroy
()
|
Called when the application is in onDestroy callback. Be aware that onDestroy() is not guaranteed to be called. Override this method to perform actions during the OnDestroy() lifecycle of the application.
Signature
open fun onDestroy() |
onPauseActivity
()
|
Called when the activity is in onPause callback. Override this method to perform actions during the OnPause() lifecycle of the application.
Signature
open fun onPauseActivity() |
onResume
()
|
Called when the application is resumed. Override this method to perform actions during the OnResume() lifecycle of the application.
Signature
open fun onResume() |
onSceneReady
()
|
Called when the scene is ready. Override this method to perform actions during the OnSceneReady() lifecycle of the application.
Signature
open fun onSceneReady() |
onSpatialShutdown
()
|
Called when the application is shutting down. Clean up all Spatial resources for your feature, e.g. entites.destroy(), in this callback.
Signature
open override fun onSpatialShutdown() |
onStart
()
|
Called when the application is started. Override this method to perform actions during the OnStart() lifecycle of the application.
Signature
open fun onStart() |
onStopActivity
()
|
Called when the activity is in onStop callback. Be aware that onStop() is not guaranteed to be called. Override this method to perform actions during the OnStop() lifecycle of the application.
Signature
open fun onStopActivity() |
onVRPause
()
|
Called when the VR mode is paused. Override this method to perform actions during the OnVRPause() lifecycle of the application.
Signature
open fun onVRPause() |
onVRReady
()
|
Called when the VR mode is ready. Override this method to perform actions during the onVRReady() lifecycle of the application.
Signature
open fun onVRReady() |
preRuntimeOnCreate
(
savedInstanceState
)
|
Called before the application's onCreate() method is called. Override this method to perform actions before the rest of the OnCreate() lifecycle of the application.
Signature
open fun preRuntimeOnCreate(savedInstanceState: Bundle?) Parameters
savedInstanceState:
Bundle?
|
raycastEnvironment
(
origin
, direction
, maxDistance
)
|
Performs a raycast in the environment and returns the first hit.
This function casts a ray from the specified origin in the given direction and returns information about the first hit. The raycast is performed against the depth of the real world. Which means no space setup is required prior to using this function. Note that this raycast does not interact with any spatial scene anchors. For that use raycastRoom.
Note: Before calling this function, startEnvironmentRaycaster() must be invoked to initialize the environment raycaster.
Signature
fun raycastEnvironment(origin: Vector3, direction: Vector3, maxDistance: Float = Float.MAX_VALUE): MRUKEnvironmentRaycastHit Parameters Returns
An MRUKEnvironmentRaycastHit object containing the result status and hit details. Check the result field for SUCCESS, NOT_READY, or NO_HIT to determine the outcome
|
raycastRoom
(
roomUuid
, origin
, direction
, maxDistance
, surfaceType
)
|
Performs a raycast against surfaces in the specified room and returns the first hit.
Signature
fun raycastRoom(roomUuid: UUID, origin: Vector3, direction: Vector3, maxDistance: Float = Float.POSITIVE_INFINITY, surfaceType: SurfaceType = SurfaceType.ALL): MRUKHit? Parameters
roomUuid:
UUID
maxDistance:
Float
|
raycastRoomAll
(
roomUuid
, origin
, direction
, maxDistance
, surfaceType
)
|
Performs a raycast against surfaces in the specified room and returns all hits. The hits are sorted by distance from closest to farthest.
Signature
fun raycastRoomAll(roomUuid: UUID, origin: Vector3, direction: Vector3, maxDistance: Float = Float.POSITIVE_INFINITY, surfaceType: SurfaceType = SurfaceType.ALL): Array<MRUKHit> Parameters
roomUuid:
UUID
maxDistance:
Float
Returns
Array
|
registerRequiredOpenXRExtensions
()
|
Override this function to define a list of required OpenXR extensions that should be enabled by your application.
Signature
open override fun registerRequiredOpenXRExtensions(): List<String> Returns
List
|
removeSceneEventListener
(
listener
)
|
Unregisters a previously added scene event listener.
This function removes a listener that was previously registered with addSceneEventListener(), stopping it from receiving notifications about scene changes. Call this when you no longer need to receive scene event notifications or when cleaning up resources.
Signature
fun removeSceneEventListener(listener: MRUKSceneEventListener) Parameters |
requestSceneCapture
()
|
Brings up the system dialog that prompts the user to set up a space (room mapping).
This function initiates the space setup process, which guides the user through mapping their physical environment. During this process, the system will identify walls, floors, ceilings, and other key elements of the space. Once completed, this spatial data becomes available to the application.
This function can be called:
Signature
fun requestSceneCapture(): CompletableFuture<Unit> Returns
CompletableFuture
|
saveSceneToJsonString
()
|
Saves the current scene data to a JSON string.
This function serializes all loaded rooms and their anchors into a JSON format that can be stored and later reloaded using loadSceneFromJsonString(). This is useful for:
Signature
fun saveSceneToJsonString(): String Returns
String
|
setWorldLockingEnabled
(
enabled
)
|
World Locking keeps virtual content stationary relative to the real world without manually parenting every object to anchors. When enabled (default true), MRUK applies subtle camera adjustments so anchors remain aligned. This allows your virtual objects to stay "static" in world space, improving stability and reducing the need to parent to each anchor.
Signature
fun setWorldLockingEnabled(enabled: Boolean) Parameters
enabled:
Boolean
|
startEnvironmentRaycaster
()
|
Starts the environment raycaster.
This function initializes the environment raycaster, which is used to perform raycasting operations in the environment. It requires the scene permission to function. This function must be called before using raycastEnvironment. Note that the raycaster takes a few frames to be ready, but its allowed to call raycastEnvironment even if they raycaster is not ready yet. In addition, getEnvironmentRaycasterStatus allows to check if the raycaster is ready.
Signature
fun startEnvironmentRaycaster(): MRUKStartEnvironmentRaycasterResult Returns
MRUKStartEnvironmentRaycasterResult.SUCCESS on success, or an error result if the operation fails.
|
stopEnvironmentRaycaster
()
|
Stops the environment raycaster.
This function deactivates the environment raycaster, preventing any further raycasting operations in the environment. After calling this function, raycastEnvironment can no longer be used until the raycaster is started again with startEnvironmentRaycaster.
Signature
fun stopEnvironmentRaycaster() |
stopTrackers
()
|
Stops all active object trackers.
This function disables any previously configured trackers (keyboards, QR codes, etc.) and stops the system from detecting and tracking these objects. Call this function when you no longer need tracking functionality or when switching between different tracking modes.
Signature
fun stopTrackers() |
systemsToRegister
()
|
Override this method to register your systems that should be executed PriorityGroup NORMAL.
Signature
open override fun systemsToRegister(): List<SystemBase> Returns
List
|