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 added by setSpatialVisibilityChangedListener.

open Unit

Closes the SessionConnector.

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

Returns all Entitys of the given type or its subtypes.

open Unit
initialize(
    lifecycleManager: LifecycleManager,
    platformAdapter: JxrPlatformAdapter
)

Initializes the SessionConnector.

Unit

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

Bundle

Sets the full space mode flag to the given android.os.Bundle.

Bundle

Sets the inherit full space mode environvment flag to the given android.os.Bundle.

Unit
setPreferredAspectRatio(activity: Activity, preferredRatio: Float)

Sets a preferred main panel aspect ratio for home space mode.

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 anchors and activitySpace) changes within the user's field of view.

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

Sets the listener to be invoked when the spatial visibility of the rendered content of the entire scene (all entities, including children of anchors 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.

lateinit Entity
lateinit PanelEntity

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

lateinit PerceptionSpace

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

lateinit SpatialCapabilities

Returns the current SpatialCapabilities of the Session.

lateinit SpatialEnvironment
lateinit SpatialUser

The SpatialUser contains information about the user.

Public constructors

Scene

Added in 1.0.0-alpha04
Scene()

Public functions

addSpatialCapabilitiesChangedListener

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

Adds the given Consumer as a listener to be invoked when this Session's current SpatialCapabilities change. Consumer#accept(SpatialCapabilities) will be invoked on the main thread.

addSpatialCapabilitiesChangedListener

Added in 1.0.0-alpha04
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. Consumer#accept(SpatialCapabilities) will be invoked on the given callbackExecutor, or the main thread if the callbackExecutor is null (default).

clearSpatialVisibilityChangedListener

Added in 1.0.0-alpha04
fun clearSpatialVisibilityChangedListener(): Unit

Releases the listener previously added by setSpatialVisibilityChangedListener.

close

Added in 1.0.0-alpha04
open fun close(): Unit

Closes the SessionConnector. Called when the Session is destroyed.

getEntitiesOfType

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

Returns all Entitys of the given type or its subtypes.

Parameters
type: Class<T>

the type of Entity to return.

Returns
List<T>

a list of all Entitys of the given type.

initialize

Added in 1.0.0-alpha04
open fun initialize(
    lifecycleManager: LifecycleManager,
    platformAdapter: JxrPlatformAdapter
): Unit

Initializes the SessionConnector.

removeSpatialCapabilitiesChangedListener

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

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

setFullSpaceMode

Added in 1.0.0-alpha04
fun setFullSpaceMode(bundle: Bundle): Bundle

Sets the full space mode flag to the given android.os.Bundle.

The android.os.Bundle then could be used to launch an android.app.Activity with requesting to enter full space mode through android.app.Activity.startActivity. If there's a bundle used for customizing how the android.app.Activity should be started by android.app.ActivityOptions.toBundle or androidx.core.app.ActivityOptionsCompat.toBundle, it's suggested to use the bundle to call this method.

The flag will be ignored when no android.content.Intent.FLAG_ACTIVITY_NEW_TASK is set in the bundle, or it is not started from a focused Activity context.

This flag is also ignored when the android.window.PROPERTY_XR_ACTIVITY_START_MODE property is set to a value other than XR_ACTIVITY_START_MODE_UNDEFINED in the AndroidManifest.xml file for the activity being launched.

Parameters
bundle: Bundle

the input bundle to set with the full space mode flag.

Returns
Bundle

the input bundle with the full space mode flag set.

setFullSpaceModeWithEnvironmentInherited

Added in 1.0.0-alpha04
fun setFullSpaceModeWithEnvironmentInherited(bundle: Bundle): Bundle

Sets the inherit full space mode environvment flag to the given android.os.Bundle.

The android.os.Bundle then could be used to launch an android.app.Activity with requesting to enter full space mode while inherit the existing environment through android.app.Activity.startActivity. If there's a bundle used for customizing how the android.app.Activity should be started by android.app.ActivityOptions.toBundle or androidx.core.app.ActivityOptionsCompat.toBundle, it's suggested to use the bundle to call this method.

When launched, the activity will be in full space mode and also inherits the environment from the launching activity. If the inherited environment needs to be animated, the launching activity has to continue updating the environment even after the activity is put into the stopped state.

The flag will be ignored when no android.content.Intent.FLAG_ACTIVITY_NEW_TASK is set in the intent, or it is not started from a focused Activity context.

The flag will also be ignored when there is no environment to inherit or the activity has its own environment set already.

This flag is ignored too when the android.window.PROPERTY_XR_ACTIVITY_START_MODE property is set to a value other than XR_ACTIVITY_START_MODE_UNDEFINED in the AndroidManifest.xml file for the activity being launched.

For security reasons, Z testing for the new activity is disabled, and the activity is always drawn on top of the inherited environment. Because Z testing is disabled, the activity should not spatialize itself.

Parameters
bundle: Bundle

the input bundle to set with the inherit full space mode environment flag.

Returns
Bundle

the input bundle with the inherit full space mode flag set.

setPreferredAspectRatio

Added in 1.0.0-alpha04
fun setPreferredAspectRatio(activity: Activity, preferredRatio: Float): Unit

Sets a preferred main panel aspect ratio for home space mode.

The ratio is only applied to the activity. If the activity launches another activity in the same task, the ratio is not applied to the new activity. Also, while the activity is in full space mode, the preference is temporarily removed.

If the activity's current aspect ratio differs from the preferredRatio, the panel is automatically resized. This resizing preserves the panel's area. To avoid runtime resizing, consider specifying the desired aspect ratio in your AndroidManifest.xml. This ensures your activity launches with the preferred aspect ratio from the start.

Parameters
activity: Activity

the activity to set the preference.

preferredRatio: Float

the aspect ratio determined by taking the panel's width over its height. A value <= 0.0f means there are no preferences.

setSpatialVisibilityChangedListener

Added in 1.0.0-alpha04
fun setSpatialVisibilityChangedListener(
    listener: Consumer<SpatialVisibility>
): 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 anchors and activitySpace) changes within the user's field of view.

This API only checks if the bounds of the renderable content are within the user's field of view. It does not check if the rendered content is visible to the user. For example, if the user is looking straight ahead, and there's only a single invisible child entity (alpha = 0) in front of the user, this API will return SpatialVisibility.WITHIN_FOV even though the user cannot see anything.

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<SpatialVisibility>

The Consumer to be invoked asynchronously on the main thread whenever the spatial visibility of the renderable content changes. The parameter passed to the Consumer’s accept method is the new value for SpatialVisibility.

setSpatialVisibilityChangedListener

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

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

This API only checks if the bounds of the renderable content are within the user's field of view. It does not check if the rendered content is visible to the user. For example, if the user is looking straight ahead, and there's only a single invisible child entity (alpha = 0) in front of the user, this API will return SpatialVisibility.WITHIN_FOV even though the user cannot see anything.

The listener is invoked on the provided executor. If the app intends to modify the UI elements/views during the callback, the app should provide the thread executor that is appropriate for the UI operations. For example, if the app is using the main thread to render the UI, the app should provide the main thread (Looper.getMainLooper()) executor. If the app is using a separate thread to render the UI, the app should provide the executor for that thread.

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<SpatialVisibility>

The Consumer to be invoked asynchronously on the given callbackExecutor whenever the spatial visibility of the renderable content changes. The parameter passed to the Consumer’s accept method is the new value for SpatialVisibility.

Public properties

activitySpace

Added in 1.0.0-alpha04
lateinit var 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.

activitySpaceRoot

Added in 1.0.0-alpha04
lateinit var activitySpaceRootEntity

mainPanelEntity

Added in 1.0.0-alpha04
lateinit var mainPanelEntityPanelEntity

A spatialized PanelEntity associated with the "main window" for the Activity. When in HomeSpace mode, this is the application's "main window".

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

perceptionSpace

Added in 1.0.0-alpha04
lateinit var perceptionSpacePerceptionSpace

The PerceptionSpace represents the origin of the space in which the ARCore for XR API 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-alpha04
lateinit var 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-alpha04
lateinit var spatialEnvironmentSpatialEnvironment

spatialUser

Added in 1.0.0-alpha04
lateinit var spatialUserSpatialUser

The SpatialUser contains information about the user.