SpatialGltfModel

Functions summary

Unit

This composable renders a glTF or .glb model that is loaded asynchronously from the provided source.

Functions

SpatialGltfModel

@Composable
@SubspaceComposable
fun SpatialGltfModel(
    state: SpatialGltfModelState,
    modifier: SubspaceModifier = SubspaceModifier,
    content: @Composable @SubspaceComposable () -> Unit = {}
): Unit

This composable renders a glTF or .glb model that is loaded asynchronously from the provided source.

Layout and Sizing

The SpatialGltfModel's layout size is determined by the bounding box size of the glTFmodel that is being displayed coerced into the constraints of the layout.

  • By default, the layout size will match the bounding box of the loaded 3D asset once it is loaded bounded by the current constraints.

  • To force the SpatialGltfModel to a specific size, use a size modifier like SubspaceModifier.size().

  • The rendered model will be scaled uniformly to fit within the constraints imposed by the layout and modifiers.

  • The content will be positioned at the center of the SpatialGltfModel by default. The developer may use GltfModelNode pose and size information to offset content relative to a desired position. Note: Because the model is loaded asynchronously, its intrinsic size will be zero during initial composition. The layout will be remeasured with the correct size once the model has finished loading. You can use the state parameter to observe the loading status via SpatialGltfModelState.status.

import androidx.xr.compose.subspace.SpatialGltfModel
import androidx.xr.compose.subspace.SpatialGltfModelSource
import androidx.xr.compose.subspace.rememberSpatialGltfModelState

val duckModelUri =
    "https://raw.githubusercontent.com/KhronosGroup/glTF-Sample-Assets/main/Models/Duck/glTF-Binary/Duck.glb"
val state =
    rememberSpatialGltfModelState(SpatialGltfModelSource.fromUri(Uri.parse(duckModelUri)))
SpatialGltfModel(state = state, modifier = modifier)
Parameters
state: SpatialGltfModelState

A SpatialGltfModelState object to observe and control the SpatialGltfModel. This can be created using rememberSpatialGltfModelState. The state should be created with a SpatialGltfModelSource that defines where to load the 3D model from. Use the helper functions fromPath, fromUri, or fromData to create a SpatialGltfModelSource.

modifier: SubspaceModifier = SubspaceModifier

The SubspaceModifier to be applied to this SpatialGltfModel.

content: @Composable @SubspaceComposable () -> Unit = {}

The content within the space of the SpatialGltfModel