Class ResourceLoader
- java.lang.Object
-
- com.google.android.filament.gltfio.ResourceLoader
-
public class ResourceLoader extends java.lang.ObjectPrepares 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.- See Also:
AssetLoader,FilamentAsset
-
-
Constructor Summary
Constructors Constructor Description ResourceLoader(com.google.android.filament.Engine engine)Constructs a resource loader tied to the given Filament engine.ResourceLoader(com.google.android.filament.Engine engine, boolean normalizeSkinningWeights, boolean recomputeBoundingBoxes, boolean ignoreBindTransform)Constructs a resource loader tied to the given Filament engine.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ResourceLoaderaddResourceData(java.lang.String uri, java.nio.Buffer buffer)Feeds the binary content of an external resource into the loader's URI cache.booleanasyncBeginLoad(FilamentAsset asset)Starts an asynchronous resource load.voidasyncCancelLoad()Cancels pending decoder jobs and frees all CPU-side texel data.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 place on the main thread.voiddestroy()Frees all memory associated with the native resource loader.voidevictResourceData()Frees memory by evicting the URI cache that was populated via addResourceData.booleanhasResourceData(java.lang.String uri)Checks if the given resource has already been added to the URI cache.ResourceLoaderloadResources(FilamentAsset asset)Iterates through all external buffers and images and creates corresponding Filament objects (vertex buffers, textures, etc), which become owned by the asset.
-
-
-
Constructor Detail
-
ResourceLoader
public ResourceLoader(@NonNull com.google.android.filament.Engine engine)Constructs a resource loader tied to the given Filament engine.- Parameters:
engine- the engine that gets passed to all builder methods- Throws:
java.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetException
-
ResourceLoader
public ResourceLoader(@NonNull com.google.android.filament.Engine engine, boolean normalizeSkinningWeights, boolean recomputeBoundingBoxes, boolean ignoreBindTransform)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 1recomputeBoundingBoxes- use computed bounding boxes rather than the ones in the assetignoreBindTransform- ignore skinned primitives bind transform when compute bounding boxes- Throws:
java.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetException
-
-
Method Detail
-
destroy
public void destroy()
Frees all memory associated with the native resource loader.
-
addResourceData
@NonNull public ResourceLoader addResourceData(@NonNull java.lang.String uri, @NonNull java.nio.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 its own (external resources might come from a filesystem, a database, or the internet) so this method allows clients to download external resources and push them to the loader. Every resource should be passed in before calling [loadResources] or [asyncBeginLoad]. See also [FilamentAsset#getResourceUris]. When loading GLB files (as opposed to JSON-based glTF files), clients typically do not need 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- Returns:
- self (for daisy chaining)
-
hasResourceData
public boolean hasResourceData(@NonNull java.lang.String uri)Checks if the given resource has already been added to the URI cache.
-
evictResourceData
public 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 public 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- Returns:
- self (for daisy chaining)
-
asyncBeginLoad
public 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
public float asyncGetLoadProgress()
Gets the status of an asynchronous resource load as a percentage in [0,1].
-
asyncUpdateLoad
public void asyncUpdateLoad()
Updates an asynchronous load by performing any pending work that must take place on 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
public void asyncCancelLoad()
Cancels pending decoder jobs and frees all CPU-side texel data. Calling this is only necessary if the asyncBeginLoad API was used and cancellation is required before progress reaches 100%.
-
-