class Scene


Scene is the primary interface to SceneCore functionality for the application. Each spatialized Activity must create and hold an instance of a Scene.

Once created, the application can use the Scene object to create spatialized entities, such as Widget panels and geometric models, set the background environment, and anchor content to the real world.

Summary

Public constructors

Public functions

Unit

Adds the given Consumer as a listener to be invoked when this Session's current SpatialCapabilities change.

Unit
addSpatialCapabilitiesChangedListener(
    callbackExecutor: Executor,
    listener: Consumer<SpatialCapabilities>
)

Adds the given Consumer as a listener to be invoked when this Session's current SpatialCapabilities change.

Unit

Releases the listener previously set by setSpatialModeChangedListener and reinstates the default behavior of automatically updating the keyEntity's pose and scale on the main thread executor.

Unit

Releases the listener previously added by setSpatialVisibilityChangedListener.

List<T>
<T : Entity> getEntitiesOfType(type: Class<T>)

Returns all entities of the given type or its subtypes.

Unit

Releases the given Consumer from receiving updates when the Session's SpatialCapabilities change.

Unit

If the Activity has focus, causes the Activity to be placed in Full Space Mode.

Unit

If the Activity has focus, causes the Activity to be placed in Home Space Mode.

Unit

Sets the listener to be invoked on the main thread executor when the spatial mode for the scene has changed.

Unit
setSpatialModeChangedListener(
    callbackExecutor: Executor,
    listener: Consumer<SpatialModeChangeEvent>
)

Sets the listener to be invoked when the spatial mode for the scene has changed.

Unit

Sets the listener to be invoked on the main thread executor when the spatial visibility of the rendered content of the entire scene (all entities, including children of AnchorEntitys and ActivitySpace) changes within the user's field of view.

Unit
setSpatialVisibilityChangedListener(
    callbackExecutor: Executor,
    listener: Consumer<Int>
)

Sets the listener to be invoked when the spatial visibility of the rendered content of the entire scene (all entities, including children of AnchorEntitys and ActivitySpace) changes within the user's field of view.

Public properties

lateinit ActivitySpace

The ActivitySpace is a special entity that represents the space in which the application is launched.

Entity?

The primary Entity that acts as a spatial reference for the scene's content.

lateinit MainPanelEntity

A spatialized MainPanelEntity associated with the "main window" for the Activity.

PanelClippingConfig

The current clipping configuration of all panels in the Scene.

lateinit PerceptionSpace

The PerceptionSpace represents the origin of the space in which ARCore for Jetpack XR provides tracking info.

SpatialCapabilities

Returns the current SpatialCapabilities of the Session.

lateinit SpatialEnvironment

The SpatialEnvironment for this scene.

lateinit SpatialUser

The SpatialUser represents the user within the XR scene, providing access to tracking information for the user's head and eyes.

Public constructors

Scene

Added in 1.0.0-alpha07
Scene()

Public functions

addSpatialCapabilitiesChangedListener

Added in 1.0.0-alpha07
fun addSpatialCapabilitiesChangedListener(
    listener: Consumer<SpatialCapabilities>
): Unit

Adds the given Consumer as a listener to be invoked when this Session's current SpatialCapabilities change.

Parameters
listener: Consumer<SpatialCapabilities>

The Consumer to be invoked asynchronously on the main thread executor whenever the SpatialCapabilities changes.

addSpatialCapabilitiesChangedListener

Added in 1.0.0-alpha07
fun addSpatialCapabilitiesChangedListener(
    callbackExecutor: Executor,
    listener: Consumer<SpatialCapabilities>
): Unit

Adds the given Consumer as a listener to be invoked when this Session's current SpatialCapabilities change.

Parameters
callbackExecutor: Executor

The Executor to run the listener on.

listener: Consumer<SpatialCapabilities>

The Consumer to be invoked asynchronously on the given callbackExecutor whenever the SpatialCapabilities changes.

clearSpatialModeChangedListener

Added in 1.0.0-alpha07
fun clearSpatialModeChangedListener(): Unit

Releases the listener previously set by setSpatialModeChangedListener and reinstates the default behavior of automatically updating the keyEntity's pose and scale on the main thread executor.

clearSpatialVisibilityChangedListener

Added in 1.0.0-alpha07
fun clearSpatialVisibilityChangedListener(): Unit

Releases the listener previously added by setSpatialVisibilityChangedListener.

getEntitiesOfType

Added in 1.0.0-alpha07
fun <T : Entity> getEntitiesOfType(type: Class<T>): List<T>

Returns all entities of the given type or its subtypes.

Parameters
type: Class<T>

the type of Entity to return.

Returns
List<T>

a list of all entities of the given type.

removeSpatialCapabilitiesChangedListener

Added in 1.0.0-alpha07
fun removeSpatialCapabilitiesChangedListener(
    listener: Consumer<SpatialCapabilities>
): Unit

Releases the given Consumer from receiving updates when the Session's SpatialCapabilities change.

Parameters
listener: Consumer<SpatialCapabilities>

The Consumer to be removed. It will no longer receive change events.

requestFullSpaceMode

Added in 1.0.0-alpha07
fun requestFullSpaceMode(): Unit

If the Activity has focus, causes the Activity to be placed in Full Space Mode. Otherwise, this call does nothing.

requestHomeSpaceMode

Added in 1.0.0-alpha07
fun requestHomeSpaceMode(): Unit

If the Activity has focus, causes the Activity to be placed in Home Space Mode. Otherwise, this call does nothing.

setSpatialModeChangedListener

Added in 1.0.0-alpha07
fun setSpatialModeChangedListener(
    listener: Consumer<SpatialModeChangeEvent>
): Unit

Sets the listener to be invoked on the main thread executor when the spatial mode for the scene has changed.

There can only be one listener set at a time. If a new listener is set, the previous listener will be released.

Parameters
listener: Consumer<SpatialModeChangeEvent>

The Consumer to be invoked asynchronously on the main thread whenever the spatial mode has changed.

setSpatialModeChangedListener

Added in 1.0.0-alpha07
fun setSpatialModeChangedListener(
    callbackExecutor: Executor,
    listener: Consumer<SpatialModeChangeEvent>
): Unit

Sets the listener to be invoked when the spatial mode for the scene has changed.

The listener is invoked on the provided Executor.

There can only be one listener set at a time. If a new listener is set, the previous listener will be released.

Parameters
callbackExecutor: Executor

The Executor to run the listener on.

listener: Consumer<SpatialModeChangeEvent>

The Consumer to be invoked asynchronously on the given callbackExecutor whenever the spatial mode has changed.

setSpatialVisibilityChangedListener

Added in 1.0.0-alpha07
fun setSpatialVisibilityChangedListener(listener: Consumer<Int>): Unit

Sets the listener to be invoked on the main thread executor when the spatial visibility of the rendered content of the entire scene (all entities, including children of AnchorEntitys and ActivitySpace) changes within the user's field of view. In Home Space Mode, the listener continues to monitor the spatial visibility of the application's main panel.

This API only checks if the bounding box of all rendered content (even if partially transparent) is within the user's field of view. Content not rendered due to full transparency (alpha=0) or being hidden is not considered. If the entities in the scene or any of their ancestors are hidden using Entity.setEnabled (enabled=false) or if the entities are turned fully transparent using Entity.setAlpha (alpha=0.0), then the SpatialVisibility checks will return SpatialVisibility.SPATIAL_VISIBILITY_OUTSIDE_FIELD_OF_VIEW.

There can only be one listener set at a time. If a new listener is set, the previous listener will be released.

Parameters
listener: Consumer<Int>

The Consumer to be invoked asynchronously on the main thread whenever the SpatialVisibility of the renderable content changes.

setSpatialVisibilityChangedListener

Added in 1.0.0-alpha07
fun setSpatialVisibilityChangedListener(
    callbackExecutor: Executor,
    listener: Consumer<Int>
): Unit

Sets the listener to be invoked when the spatial visibility of the rendered content of the entire scene (all entities, including children of AnchorEntitys and ActivitySpace) changes within the user's field of view. In Home Space Mode, the listener continues to monitor the spatial visibility of the application's main panel.

This API only checks if the bounding box of all rendered content (even if partially transparent) is within the user's field of view. Content not rendered due to full transparency (alpha=0) or being hidden is not considered. If the entities in the scene or any of their ancestors are hidden using Entity.setEnabled (enabled=false) or if the entities are turned fully transparent using Entity.setAlpha (alpha=0.0), then the SpatialVisibility checks will return SpatialVisibility.SPATIAL_VISIBILITY_OUTSIDE_FIELD_OF_VIEW.

The listener is invoked on the provided Executor.

There can only be one listener set at a time. If a new listener is set, the previous listener will be released.

Parameters
callbackExecutor: Executor

The Executor to run the listener on.

listener: Consumer<Int>

The Consumer to be invoked asynchronously on the given callbackExecutor whenever the SpatialVisibility of the renderable content changes.

Public properties

activitySpace

Added in 1.0.0-alpha07
lateinit val activitySpaceActivitySpace

The ActivitySpace is a special entity that represents the space in which the application is launched. It is the default parent of all entities in the scene.

The ActivitySpace is created automatically when the Session is created.

keyEntity

Added in 1.0.0-alpha07
var keyEntityEntity?

The primary Entity that acts as a spatial reference for the scene's content.

The default behavior on a spatial mode change uses this Entity to maintain a consistent spatial context for the user. When the scene enters Full Space Mode or is re-centered, the system provides a recommended pose and scale. This ensures continuity of the user's attention across spatial mode changes such as during transitions into Full Space Mode.

Unmovable Entities, such as AnchorEntity or ActivitySpace, cannot be set as the Scene.keyEntity and will throw IllegalArgumentException if set.

This field can be null if no key entity has been set (default), or if the key entity was cleared by setting this value to null. When null, the default listener takes no action during spatial mode changes.

mainPanelEntity

Added in 1.0.0-alpha07
lateinit val mainPanelEntityMainPanelEntity

A spatialized MainPanelEntity associated with the "main window" for the Activity. When in Home Space Mode, this is the application's "main window".

If called multiple times, this will return the same MainPanelEntity.

panelClippingConfig

Added in 1.0.0-alpha07
var panelClippingConfigPanelClippingConfig

The current clipping configuration of all panels in the Scene.

Setting this property updates the clipping behavior.

perceptionSpace

Added in 1.0.0-alpha07
lateinit val perceptionSpacePerceptionSpace

The PerceptionSpace represents the origin of the space in which ARCore for Jetpack XR provides tracking info. The transformations provided by the PerceptionSpace are only valid for the call frame, as the transformation can be changed by the system at any time.

spatialCapabilities

Added in 1.0.0-alpha07
val spatialCapabilitiesSpatialCapabilities

Returns the current SpatialCapabilities of the Session. The set of capabilities can change within a session. The returned object will not update if the capabilities change; this method should be called again to get the latest set of capabilities.

spatialEnvironment

Added in 1.0.0-alpha07
lateinit val spatialEnvironmentSpatialEnvironment

The SpatialEnvironment for this scene.

This object provides APIs to manage the XR background and passthrough settings. Use it to set a custom skybox, define the 3D geometry of the environment, and control the opacity of the camera passthrough feed.

spatialUser

Added in 1.0.0-alpha07
lateinit val spatialUserSpatialUser

The SpatialUser represents the user within the XR scene, providing access to tracking information for the user's head and eyes.

Use it to get the following:

  • Head Pose: Access SpatialUser.head to get the position and orientation of the user's head in the scene.

  • Camera Views: Access SpatialUser.cameraViews to get the pose and field of view for each of the user's camera views.

Note: Accessing properties on SpatialUser requires head tracking to be enabled in the session androidx.xr.runtime.Session.config.