Class ResourceLoader


  • public class ResourceLoader
    extends java.lang.Object
    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.

    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
      ResourceLoader addResourceData​(java.lang.String uri, java.nio.Buffer buffer)
      Feeds the binary content of an external resource into the loader's URI cache.
      boolean asyncBeginLoad​(FilamentAsset asset)
      Starts an asynchronous resource load.
      void asyncCancelLoad()
      Cancels pending decoder jobs and frees all CPU-side texel data.
      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 place on the main thread.
      void destroy()
      Frees all memory associated with the native resource loader.
      void evictResourceData()
      Frees memory by evicting the URI cache that was populated via addResourceData.
      boolean hasResourceData​(java.lang.String uri)
      Checks if the given resource has already been added to the URI cache.
      ResourceLoader loadResources​(FilamentAsset asset)
      Iterates through all external buffers and images and creates corresponding Filament objects (vertex buffers, textures, etc), which become owned by the asset.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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.IllegalAccessException
        java.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 methods
        normalizeSkinningWeights - scale non-conformant skinning weights so they sum to 1
        recomputeBoundingBoxes - use computed bounding boxes rather than the ones in the asset
        ignoreBindTransform - ignore skinned primitives bind transform when compute bounding boxes
        Throws:
        java.lang.IllegalAccessException
        java.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 glTF
        buffer - 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%.