ResourceLoader

ResourceLoader loads external resources referenced by glTF assets.

ResourceLoader handles:

  • Loading textures from URIs

  • Uploading vertex/index buffer data

  • Computing tangent quaternions (via Mikktspace when needed)

  • Async resource loading for progressive rendering

Typical usage:

val stb = createStbProvider(engine)
val resourceLoader = ResourceLoader(ResourceConfiguration(engine))
resourceLoader.addTextureProvider("image/png", stb)
resourceLoader.addTextureProvider("image/jpeg", stb)
resourceLoader.loadResources(asset) // Synchronously load all resources
resourceLoader.destroy()
stb.destroy()

Async usage:

resourceLoader.asyncBeginLoad(asset)
while (resourceLoader.asyncGetLoadProgress() < 1.0f) {
resourceLoader.asyncUpdateLoad() // Load in chunks
}

See also

Constructors

Link copied to clipboard
constructor(config: ResourceConfiguration)

Properties

Link copied to clipboard

The native object, for interop with code calling the Fila* C API directly. Read-only: this wrapper owns it.

Functions

Link copied to clipboard
fun addResourceData(uri: String, buffer: ByteArray)

Feeds the binary content of an external resource into the loader's URI cache.

Link copied to clipboard
fun addTextureProvider(mimeType: String, provider: TextureProvider)

Registers provider to decode textures of mimeType (e.g. image/png). The loader doesn't own it: destroy it after the loader.

Link copied to clipboard

Starts an asynchronous resource load (texture decoding may use worker threads). Requires periodic calls to asyncUpdateLoad until asyncGetLoadProgress reaches 1.0.

Link copied to clipboard

Cancels pending decoder jobs, frees all CPU-side texel data, and flushes the Engine. Only needed if asyncBeginLoad was used and cancellation is required before completion.

Link copied to clipboard

Gets the status of an asynchronous load as a percentage in [0, 1].

Link copied to clipboard

Performs any pending main-thread work of an asynchronous load. Call periodically until asyncGetLoadProgress returns 1.0; harmless after that.

Link copied to clipboard
open override fun close()

Same as destroy; lets this be used with use { } and try-with-resources.

Link copied to clipboard
fun destroy()

Destroys this loader and frees its internal caches. Must happen on the same thread that calls Renderer.render(), because the loader listens to buffer callbacks to know when CPU-side data blobs can be freed.

Link copied to clipboard

Frees memory by evicting the URI cache populated via addResourceData. Call only after a model is fully loaded or loading has been cancelled.

Link copied to clipboard

Checks whether the given resource URI has already been added via addResourceData.

Link copied to clipboard

Synchronously loads resources for asset from the URI cache and finalizes the asset: transforms vertex data if necessary, decodes images, and supplies tangent data.

Link copied to clipboard

Replaces the configuration the loader was created with.