SceneCore entities

Applicable XR devices
This guidance helps you build experiences for these types of XR devices.
XR Headsets
Wired XR Glasses

A SceneCoreEntity is a subspace composable that bridges the Jetpack SceneCore and Compose for XR libraries so that you can use entities built with SceneCore in Compose layouts. This lets you build lower-level entities and custom components while allowing Compose to size, position, reparent, add children, and apply modifiers to those entities.

Use a SceneCore entity to place entities in your layout

The following example shows how to use a SceneCore entity to place entities in your layout:

val virtualPixelDensity = session.scene.virtualPixelDensity

Subspace {
    SceneCoreEntity(
        modifier = SubspaceModifier.offset(x = 50.dp),
        factory = {
            SurfaceEntity.create(
                session = session,
                pose = Pose.Identity,
                stereoMode = SurfaceEntity.StereoMode.MONO
            )
        },
        update = { entity ->
            // Compose state changes may be applied to the SceneCore entity here.
            entity.stereoMode = SurfaceEntity.StereoMode.SIDE_BY_SIDE
        },
        sizeAdapter =
            object : SceneCoreEntitySizeAdapter<SurfaceEntity> {
                override fun onLayoutSizeChanged(
                    entity: SurfaceEntity,
                    size: IntVolumeSize
                ) {
                    val extents = FloatSize2d(
                        size.width.toFloat(),
                        size.height.toFloat()
                    )
                    entity.shape = SurfaceEntity.Shape.Quad(extents)
                }
            },
    ) {
        // Content here will be children of the SceneCoreEntity
        // in the scene graph.
    }
}

Key points about the code

  • Factory block: The factory block is where you initialize the underlying SurfaceEntity entity from SceneCore.
  • Update block: Use the update block to modify the entity's properties in response to changes in your Compose state.
  • Size Adaptation: The sizeAdapter communicates the entity's dimensions back to the Compose layout system.

Additional information