AssetBundle

class AssetBundle : Closeable

An AssetBundle is a packaged collection of resources.

Notes:

  • An AssetBundle is generated by packaging resources using the Spatial Editor. It helps compress and manage resources efficiently.

  • A Model corresponds to a scene description file (typically a Scene in the Spatial Editor), usually saved in the project as a USD file.

  • The model input path examples:

    1. Scenes/Scene.usda -> Scene name: Scene (default case)

    2. Scenes/Sub/Scene.usda -> Scene name: Sub/Scene

    3. Scenes/Sub/Sub/Scene.usda -> Scene name: Sub/Sub/Scene

Example Usage

// Load an AssetBundle
val assetBundle = AssetBundle.load("asset://AssetBundles/MyAssetBundle.bundle")

// Load a model from the AssetBundle
val model = assetBundle.loadModel("Sub/Sub/Scene")

// Load a material from the AssetBundle
val material = assetBundle.loadMaterial("Sub/Sub/Scene/MyMaterial/NewMaterial")

// Release model and material resources
assetBundle.releaseModel("Sub/Sub/Scene")
assetBundle.releaseResource("Sub/Sub/Scene/MyMaterial/NewMaterial")

// Close the AssetBundle when it is no longer needed
assetBundle.close()

Types

Link copied to clipboard
object Companion

The companion of AssetBundle.

Properties

Link copied to clipboard
@get:JvmName(name = "isValid")
val valid: Boolean

The AssetBundle is valid.

Functions

Link copied to clipboard
open override fun close()

Closes an AssetBundle and releases the resources occupied by it.

Link copied to clipboard
fun loadAudioResource(path: String): AudioResource

Asynchronously loads an audio resource from a relative path.

Link copied to clipboard
suspend fun loadAudioResourceSuspend(path: String): AudioResource

Asynchronously loads an audio resource from a relative path.

Link copied to clipboard
fun loadMaterial(path: String): Material

Loads a material from the specified path.

Link copied to clipboard
fun loadMeshResource(path: String): MeshResource

Loads a mesh resource from the specified path.

Link copied to clipboard
fun loadModel(name: String): Entity

Loads a model by its name.

Link copied to clipboard
suspend fun loadModelSuspend(name: String): Entity

Asynchronously loads a model by its name. This is a suspend function.

Link copied to clipboard

Loads a texture resource from the specified path.

Link copied to clipboard
fun preloadModel(name: String)

Preloads the specified model into memory.

Link copied to clipboard
fun releaseModel(name: String)

Releases a previously loaded model by its name.

Link copied to clipboard
fun releaseResource(path: String)

Releases a previously loaded resource at the specified path.