Scene
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 |
final lateinit @NonNull MainPanelEntity |
A spatialized |
final lateinit @NonNull PerceptionSpace |
The |
final lateinit @NonNull Set<@NonNull SpatialCapability> |
The current |
final lateinit @NonNull SpatialEnvironment |
The |
final lateinit @NonNull SpatialUser |
The |
Public methods |
|
|---|---|
final void |
addSpatialCapabilitiesChangedListener(Adds the given |
final void |
addSpatialCapabilitiesChangedListener(Adds the given |
final void |
Releases the listener previously set by |
final void |
Releases the listener previously added by |
final @NonNull ActivitySpace |
The |
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 |
final @NonNull MainPanelEntity |
A spatialized |
final @NonNull PanelClippingConfig |
The current clipping configuration of all panels in the Scene. |
final @NonNull PerceptionSpace |
The |
final @NonNull Set<@NonNull SpatialCapability> |
The current |
final @NonNull SpatialEnvironment |
The |
final @NonNull SpatialUser |
The |
final void |
removeSpatialCapabilitiesChangedListener(Releases the given |
final void |
If the |
final void |
If the |
final void |
setKeyEntity(Entity keyEntity)The primary |
final void |
setPanelClippingConfig(@NonNull PanelClippingConfig panelClippingConfig)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 |
setSpatialModeChangedListener(Sets the listener to be invoked when the spatial mode for the scene has changed. |
final void |
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 |
final void |
setSpatialVisibilityChangedListener(Sets the listener to be invoked when the spatial visibility of the rendered content of the entire scene (all entities, including children of |
Public fields
activitySpace
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
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
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
public final lateinit @NonNull Set<@NonNull SpatialCapability> spatialCapabilities
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
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.
| See also | |
|---|---|
SpatialEnvironment |
spatialUser
public final lateinit @NonNull SpatialUser spatialUser
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.headto get the position and orientation of the user's head in the scene. -
Camera Views: Access
SpatialUser.cameraViewsto 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.
| See also | |
|---|---|
SpatialUser |
|
Head |
|
CameraView |
Public methods
addSpatialCapabilitiesChangedListener
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 |
addSpatialCapabilitiesChangedListener
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 |
@NonNull Consumer<@NonNull Set<@NonNull SpatialCapability>> listener |
The Consumer to be invoked asynchronously on the given callbackExecutor. The set includes every currently-available |
clearSpatialModeChangedListener
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.
clearSpatialVisibilityChangedListener
public final void clearSpatialVisibilityChangedListener()
Releases the listener previously added by setSpatialVisibilityChangedListener.
The listener is automatically released at the end of the Scene's lifecycle even if this method is not explicitly called.
getActivitySpace
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
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.
getKeyEntity
public final Entity getKeyEntity()
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.
getMainPanelEntity
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
public final @NonNull PanelClippingConfig getPanelClippingConfig()
The current clipping configuration of all panels in the Scene.
Setting this property updates the clipping behavior.
| See also | |
|---|---|
PanelClippingConfig |
getPerceptionSpace
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
public final @NonNull Set<@NonNull SpatialCapability> getSpatialCapabilities()
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
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.
| See also | |
|---|---|
SpatialEnvironment |
getSpatialUser
public final @NonNull SpatialUser getSpatialUser()
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.headto get the position and orientation of the user's head in the scene. -
Camera Views: Access
SpatialUser.cameraViewsto 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.
| See also | |
|---|---|
SpatialUser |
|
Head |
|
CameraView |
removeSpatialCapabilitiesChangedListener
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.
requestFullSpaceMode
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
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
public final void setKeyEntity(Entity keyEntity)
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.
setPanelClippingConfig
public final void setPanelClippingConfig(@NonNull PanelClippingConfig panelClippingConfig)
The current clipping configuration of all panels in the Scene.
Setting this property updates the clipping behavior.
| See also | |
|---|---|
PanelClippingConfig |
setSpatialModeChangedListener
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.
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 |
setSpatialModeChangedListener
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.
setSpatialVisibilityChangedListener
public final void setSpatialVisibilityChangedListener(
@NonNull Consumer<@NonNull SpatialVisibility> listener
)
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.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 | |
|---|---|
@NonNull Consumer<@NonNull SpatialVisibility> listener |
The |
setSpatialVisibilityChangedListener
public final void setSpatialVisibilityChangedListener(
@NonNull Executor callbackExecutor,
@NonNull Consumer<@NonNull SpatialVisibility> listener
)
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.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 | |
|---|---|
@NonNull Executor callbackExecutor |
The |
@NonNull Consumer<@NonNull SpatialVisibility> listener |
The |