SpatialGltfModelSource

interface SpatialGltfModelSource


Defines the source for a 3D model to be rendered by the SpatialGltfModel composable.

Instances of SpatialGltfModelSource are created using fromPath, fromUri, or fromData.

Summary

Public companion functions

SpatialGltfModelSource
fromData(assetData: ByteArray, assetKey: String)

Creates a SpatialGltfModelSource that loads a glTF model from a ByteArray.

SpatialGltfModelSource
fromPath(path: Path)

Creates a SpatialGltfModelSource that loads a glTF model from a Path relative to the application's assets/ folder.

SpatialGltfModelSource
fromUri(uri: Uri)

Creates a SpatialGltfModelSource that loads a glTF model from a content Uri.

Public functions

suspend GltfModel
createModel(session: Session)

Creates a GltfModel from the source.

Public companion functions

fromData

Added in 1.0.0-alpha13
fun fromData(
    assetData: ByteArray,
    assetKey: String = assetData.hashCode().toString()
): SpatialGltfModelSource

Creates a SpatialGltfModelSource that loads a glTF model from a ByteArray.

This is useful for loading models that are embedded directly in the application or generated at runtime.

Currently, only binary glTF (.glb) files are supported.

Parameters
assetData: ByteArray

The byte array data of a binary glTF (.glb) model.

assetKey: String = assetData.hashCode().toString()

A unique key to identify the model in the internal cache. If not provided, the hashCode of the assetData will be used. Providing a stable key can improve performance by avoiding redundant parsing of the same model data.

Returns
SpatialGltfModelSource

A SpatialGltfModelSource that can be used with the SpatialGltfModel composable.

fromPath

Added in 1.0.0-alpha13
fun fromPath(path: Path): SpatialGltfModelSource

Creates a SpatialGltfModelSource that loads a glTF model from a Path relative to the application's assets/ folder.

Currently, only binary glTF (.glb) files are supported.

Parameters
path: Path

The path of the binary glTF (.glb) model to be loaded, relative to the application's assets/ folder.

Returns
SpatialGltfModelSource

A SpatialGltfModelSource that can be used with the SpatialGltfModel composable.

Throws
IllegalArgumentException

if path is an absolute path.

fromUri

Added in 1.0.0-alpha13
fun fromUri(uri: Uri): SpatialGltfModelSource

Creates a SpatialGltfModelSource that loads a glTF model from a content Uri.

This is suitable for loading models from various sources, such as network locations or local storage, that can be represented by a Uri.

Currently, only binary glTF (.glb) files are supported.

Parameters
uri: Uri

The Uri for the binary glTF (.glb) model to be loaded.

Returns
SpatialGltfModelSource

A SpatialGltfModelSource that can be used with the SpatialGltfModel composable.

Public functions

createModel

suspend fun createModel(session: Session): GltfModel

Creates a GltfModel from the source.

Parameters
session: Session

The XR session to create the model in.

Returns
GltfModel

The created GltfModel.