public final 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 fields

final lateinit @NonNull ActivitySpace

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

final lateinit @NonNull MainPanelEntity

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

final lateinit @NonNull PerceptionSpace

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

final lateinit @NonNull Set<@NonNull SpatialCapability>

The current Set of SpatialCapability constants available in the Session.

final lateinit @NonNull SpatialEnvironment

The SpatialEnvironment for this scene.

Public methods

final void

Adds the given Consumer as a listener to be invoked when this androidx.xr.runtime.Session's spatial capabilities change.

final void

Adds the given Consumer as a listener to be invoked when this androidx.xr.runtime.Session's spatial capabilities change.

final void

Adds a 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.

final void

Adds a 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.

final void

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.

final @NonNull ActivitySpace

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

final @NonNull List<@NonNull T>
<T extends Entity> getEntitiesOfType(@NonNull Class<@NonNull T> type)

Returns all entities of the given type or its subtypes.

final Entity

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

final @NonNull MainPanelEntity

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

final @NonNull PanelClippingConfig

The current clipping configuration of all panels in the Scene.

final @NonNull PerceptionSpace

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

final @NonNull Set<@NonNull SpatialCapability>

The current Set of SpatialCapability constants available in the Session.

final @NonNull SpatialEnvironment

The SpatialEnvironment for this scene.

final void

Releases the given Consumer from receiving updates when the androidx.xr.runtime.Session's SpatialCapability change.

final void

Releases the listener previously added by addSpatialVisibilityChangedListener.

final void

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

final void

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

final void

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

final void

The current clipping configuration of all panels in the Scene.

final void

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

final void

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

Public fields

activitySpace

Added in 1.0.0-alpha15
public final lateinit @NonNull ActivitySpace activitySpace

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 androidx.xr.runtime.Session is created.

mainPanelEntity

Added in 1.0.0-alpha15
public final lateinit @NonNull MainPanelEntity mainPanelEntity

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.

perceptionSpace

Added in 1.0.0-alpha15
public final lateinit @NonNull PerceptionSpace perceptionSpace

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-alpha15
public final lateinit @NonNull Set<@NonNull SpatialCapabilityspatialCapabilities

The current Set of SpatialCapability constants available in the Session. The set may 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, or clients can subscribe to changes with addSpatialCapabilitiesChangedListener.

spatialEnvironment

Added in 1.0.0-alpha15
public final lateinit @NonNull SpatialEnvironment spatialEnvironment

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.

Public methods

addSpatialCapabilitiesChangedListener

Added in 1.0.0-alpha15
public final void addSpatialCapabilitiesChangedListener(
    @NonNull Consumer<@NonNull Set<@NonNull SpatialCapability>> listener
)

Adds the given Consumer as a listener to be invoked when this androidx.xr.runtime.Session's spatial capabilities change.

Parameters
@NonNull Consumer<@NonNull Set<@NonNull SpatialCapability>> listener

The Consumer to be invoked asynchronously, on the main thread. The set includes every currently-available SpatialCapability.

addSpatialCapabilitiesChangedListener

Added in 1.0.0-alpha15
public final void addSpatialCapabilitiesChangedListener(
    @NonNull Executor callbackExecutor,
    @NonNull Consumer<@NonNull Set<@NonNull SpatialCapability>> listener
)

Adds the given Consumer as a listener to be invoked when this androidx.xr.runtime.Session's spatial capabilities change.

Parameters
@NonNull Executor callbackExecutor

The Executor to run the listener on.

@NonNull Consumer<@NonNull Set<@NonNull SpatialCapability>> listener

The Consumer to be invoked asynchronously on the given callbackExecutor. The set includes every currently-available SpatialCapability.

addSpatialVisibilityChangedListener

Added in 1.0.0-alpha15
public final void addSpatialVisibilityChangedListener(
    @NonNull Consumer<@NonNull SpatialVisibility> listener
)

Adds a 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.OUTSIDE_FIELD_OF_VIEW.

Parameters
@NonNull Consumer<@NonNull SpatialVisibility> listener

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

addSpatialVisibilityChangedListener

Added in 1.0.0-alpha15
public final void addSpatialVisibilityChangedListener(
    @NonNull Executor callbackExecutor,
    @NonNull Consumer<@NonNull SpatialVisibility> listener
)

Adds a 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.OUTSIDE_FIELD_OF_VIEW.

The listener is invoked on the provided Executor.

Parameters
@NonNull Executor callbackExecutor

The Executor to run the listener on.

@NonNull Consumer<@NonNull SpatialVisibility> listener

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

clearSpatialModeChangedListener

Added in 1.0.0-alpha15
public final void clearSpatialModeChangedListener()

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.

The listener is automatically released at the end of the Scene's lifecycle even if this method is not explicitly called.

getActivitySpace

Added in 1.0.0-alpha15
public final @NonNull ActivitySpace getActivitySpace()

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 androidx.xr.runtime.Session is created.

getEntitiesOfType

Added in 1.0.0-alpha15
public final @NonNull List<@NonNull T> <T extends Entity> getEntitiesOfType(@NonNull Class<@NonNull T> type)

Returns all entities of the given type or its subtypes.

Parameters
@NonNull Class<@NonNull T> type

the type of Entity to return.

Returns
@NonNull List<@NonNull T>

a list of all entities of the given type.

getKeyEntity

Added in 1.0.0-alpha15
public final Entity getKeyEntity()

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

This entity is used to maintain visual continuity during spatial mode transitions. When entering Full Space Mode or re-centering the scene, the system provides a recommended pose and scale. SceneCore's default mode change handler applies those to the entity designated as keyEntity to help preserve the user's spatial context across these mode transitions.

Starting with Spatial API v2, setting keyEntity allows SceneCore to share the entity's pose with the system as a spatial continuity hint. The system uses this hint to maintain visual consistency when the current activity transitions to the Home Space or when a new activity is launched.

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

By default, this is set to mainPanelEntity. This field can be null if the key entity was cleared by setting this value to null. When null, the default listener takes no action during spatial mode changes.

When a new non-null Entity is assigned as keyEntity, the spatialModeChangedListener is immediately invoked with the last known recommended pose and scale values if the following conditions are met:

  1. The previous value of keyEntity was null.

  2. There are cached pose and scale values, provided by the system earlier.

getMainPanelEntity

Added in 1.0.0-alpha15
public final @NonNull MainPanelEntity getMainPanelEntity()

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.

getPanelClippingConfig

Added in 1.0.0-alpha15
public final @NonNull PanelClippingConfig getPanelClippingConfig()

The current clipping configuration of all panels in the Scene.

Setting this property updates the clipping behavior.

getPerceptionSpace

Added in 1.0.0-alpha15
public final @NonNull PerceptionSpace getPerceptionSpace()

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.

getSpatialCapabilities

Added in 1.0.0-alpha15
public final @NonNull Set<@NonNull SpatialCapabilitygetSpatialCapabilities()

The current Set of SpatialCapability constants available in the Session. The set may 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, or clients can subscribe to changes with addSpatialCapabilitiesChangedListener.

getSpatialEnvironment

Added in 1.0.0-alpha15
public final @NonNull SpatialEnvironment getSpatialEnvironment()

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.

removeSpatialCapabilitiesChangedListener

Added in 1.0.0-alpha15
public final void removeSpatialCapabilitiesChangedListener(
    @NonNull Consumer<@NonNull Set<@NonNull SpatialCapability>> listener
)

Releases the given Consumer from receiving updates when the androidx.xr.runtime.Session's SpatialCapability change.

The listeners are automatically released at the end of the Scene's lifecycle even if this method is not explicitly called.

Parameters
@NonNull Consumer<@NonNull Set<@NonNull SpatialCapability>> listener

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

removeSpatialVisibilityChangedListener

Added in 1.0.0-alpha15
public final void removeSpatialVisibilityChangedListener(
    @NonNull Consumer<@NonNull SpatialVisibility> listener
)

Releases the listener previously added by addSpatialVisibilityChangedListener.

The listener is automatically released at the end of the Scene's lifecycle even if this method is not explicitly called.

requestFullSpaceMode

Added in 1.0.0-alpha15
public final void requestFullSpaceMode()

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-alpha15
public final void requestHomeSpaceMode()

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

setKeyEntity

Added in 1.0.0-alpha15
public final void setKeyEntity(Entity value)

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

This entity is used to maintain visual continuity during spatial mode transitions. When entering Full Space Mode or re-centering the scene, the system provides a recommended pose and scale. SceneCore's default mode change handler applies those to the entity designated as keyEntity to help preserve the user's spatial context across these mode transitions.

Starting with Spatial API v2, setting keyEntity allows SceneCore to share the entity's pose with the system as a spatial continuity hint. The system uses this hint to maintain visual consistency when the current activity transitions to the Home Space or when a new activity is launched.

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

By default, this is set to mainPanelEntity. This field can be null if the key entity was cleared by setting this value to null. When null, the default listener takes no action during spatial mode changes.

When a new non-null Entity is assigned as keyEntity, the spatialModeChangedListener is immediately invoked with the last known recommended pose and scale values if the following conditions are met:

  1. The previous value of keyEntity was null.

  2. There are cached pose and scale values, provided by the system earlier.

setPanelClippingConfig

Added in 1.0.0-alpha15
public final void setPanelClippingConfig(@NonNull PanelClippingConfig value)

The current clipping configuration of all panels in the Scene.

Setting this property updates the clipping behavior.

setSpatialModeChangedListener

Added in 1.0.0-alpha15
public final void setSpatialModeChangedListener(
    @NonNull Consumer<@NonNull SpatialModeChangeEvent> listener
)

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

Because the listener will typically update the keyEntity's pose and/or scale, there can only be one listener set at a time. If a new listener is set, the previous listener will be released.

Parameters
@NonNull Consumer<@NonNull SpatialModeChangeEvent> listener

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

setSpatialModeChangedListener

Added in 1.0.0-alpha15
public final void setSpatialModeChangedListener(
    @NonNull Executor callbackExecutor,
    @NonNull Consumer<@NonNull SpatialModeChangeEvent> listener
)

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
@NonNull Executor callbackExecutor

The Executor to run the listener on.

@NonNull Consumer<@NonNull SpatialModeChangeEvent> listener

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