Package 

Class ResourceLoader


  • 
    public class ResourceLoader
    
                        

    Prepares 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
      void destroy() Frees all memory associated with the native resource loader.
      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].
      boolean hasResourceData(@NonNull() String uri) Checks if the given resource has already been added to the URI cache.
      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.
      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.
      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.
      float asyncGetLoadProgress() Gets the status of an asynchronous resource load as a percentage in [0,1].
      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.
      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%.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 methods
        normalizeSkinningWeights - 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 glTF
        buffer - the binary blob corresponding to the given URI
      • 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%.