-
public class ResourceLoaderPrepares and uploads vertex buffers and textures to the GPU.
For a usage example, see the documentation for AssetLoader. All methods should be called from the main thread.
-
-
Constructor Summary
Constructors Constructor Description ResourceLoader(Engine engine)Constructs a resource loader tied to the given Filament engine. ResourceLoader(Engine engine, boolean normalizeSkinningWeights)Constructs a resource loader tied to the given Filament engine.
-
Method Summary
Modifier and Type Method Description voiddestroy()Frees all memory associated with the native resource loader. ResourceLoaderaddResourceData(@NonNull() String uri, @NonNull() Buffer buffer)Feeds the binary content of an external resource into the loader's URI cache.On some platforms, `ResourceLoader` does not know how to download external resources on itsown (external resources might come from a filesystem, a database, or the internet) so thismethod allows clients to download external resources and push them to the loader.Every resource should be passed in before calling [loadResources] or [asyncBeginLoad]. booleanhasResourceData(@NonNull() String uri)Checks if the given resource has already been added to the URI cache. voidevictResourceData()Frees memory by evicting the URI cache that was populated via addResourceData.This can be called only after a model is fully loaded or after loading has been cancelled. ResourceLoaderloadResources(@NonNull() FilamentAsset asset)Iterates through all external buffers and images and creates corresponding Filament objects(vertex buffers, textures, etc), which become owned by the asset.NOTE: this is a synchronous API, please see [asyncBeginLoad] as an alternative. booleanasyncBeginLoad(@NonNull() FilamentAsset asset)Starts an asynchronous resource load.Returns false if the loading process was unable to start.This is an alternative to #loadResources and requires periodic calls to #asyncUpdateLoad.On multi-threaded systems this creates threads for texture decoding. floatasyncGetLoadProgress()Gets the status of an asynchronous resource load as a percentage in [0,1]. voidasyncUpdateLoad()Updates an asynchronous load by performing any pending work that must take placeon the main thread.Clients must periodically call this until #asyncGetLoadProgress returns 100%.After progress reaches 100%, calling this is harmless; it just does nothing. voidasyncCancelLoad()Cancels pending decoder jobs and frees all CPU-side texel data.Calling this is only necessary if the asyncBeginLoad API was usedand cancellation is required before progress reaches 100%. -
-
Constructor Detail
-
ResourceLoader
ResourceLoader(Engine engine)
Constructs a resource loader tied to the given Filament engine.- Parameters:
engine- the engine that gets passed to all builder methods
-
ResourceLoader
ResourceLoader(Engine engine, boolean normalizeSkinningWeights)
Constructs a resource loader tied to the given Filament engine.- Parameters:
engine- the engine that gets passed to all builder methodsnormalizeSkinningWeights- scale non-conformant skinning weights so they sum to 1
-
-
Method Detail
-
destroy
void destroy()
Frees all memory associated with the native resource loader.
-
addResourceData
@NonNull() ResourceLoader addResourceData(@NonNull() String uri, @NonNull() Buffer buffer)
Feeds the binary content of an external resource into the loader's URI cache.On some platforms, `ResourceLoader` does not know how to download external resources on itsown (external resources might come from a filesystem, a database, or the internet) so thismethod allows clients to download external resources and push them to the loader.Every resource should be passed in before calling [loadResources] or [asyncBeginLoad]. Seealso [FilamentAsset#getResourceUris].When loading GLB files (as opposed to JSON-based glTF files), clients typically do notneed to call this method.
- Parameters:
uri- the string path that matches an image URI or buffer URI in the glTFbuffer- the binary blob corresponding to the given URI
-
hasResourceData
boolean hasResourceData(@NonNull() String uri)
Checks if the given resource has already been added to the URI cache.
-
evictResourceData
void evictResourceData()
Frees memory by evicting the URI cache that was populated via addResourceData.This can be called only after a model is fully loaded or after loading has been cancelled.
-
loadResources
@NonNull() ResourceLoader loadResources(@NonNull() FilamentAsset asset)
Iterates through all external buffers and images and creates corresponding Filament objects(vertex buffers, textures, etc), which become owned by the asset.NOTE: this is a synchronous API, please see [asyncBeginLoad] as an alternative.
- Parameters:
asset- the Filament asset that contains URI-based resources
-
asyncBeginLoad
boolean asyncBeginLoad(@NonNull() FilamentAsset asset)
Starts an asynchronous resource load.Returns false if the loading process was unable to start.This is an alternative to #loadResources and requires periodic calls to #asyncUpdateLoad.On multi-threaded systems this creates threads for texture decoding.
-
asyncGetLoadProgress
float asyncGetLoadProgress()
Gets the status of an asynchronous resource load as a percentage in [0,1].
-
asyncUpdateLoad
void asyncUpdateLoad()
Updates an asynchronous load by performing any pending work that must take placeon the main thread.Clients must periodically call this until #asyncGetLoadProgress returns 100%.After progress reaches 100%, calling this is harmless; it just does nothing.
-
asyncCancelLoad
void asyncCancelLoad()
Cancels pending decoder jobs and frees all CPU-side texel data.Calling this is only necessary if the asyncBeginLoad API was usedand cancellation is required before progress reaches 100%.
-
-
-
-