Interface AssetManager

All Known Implementing Classes:
DesktopAssetManager

public interface AssetManager
AssetManager provides an interface for managing the data assets of a jME3 application.

The asset manager provides a means to register AssetLocators, which are used to find asset data on disk, network, or other file system. The asset locators are invoked in order of addition to find the asset data. Use the registerLocator(java.lang.String, java.lang.Class) method to add new AssetLocators. Some examples of locators:

The asset data is represented by the AssetInfo class, this data is passed into the registered AssetLoaders in order to convert the data into a usable object. Use the registerLoader(java.lang.Class, java.lang.String[]) method to add loaders. Some examples of loaders:

  • OBJLoader - Used to load Wavefront .OBJ model files
  • TGALoader - Used to load Targa image files

Once the asset has been loaded, it will be post-processed by the key's processor. If the key specifies a cache type, the asset will be cached in the specified cache. Next, the AssetProcessor will be requested to AssetProcessor.createClone(java.lang.Object) generate a clone for the asset. Some assets do not require cloning, such as immutable or shared assets. Others, like models, must be cloned so that modifications to one instance do not leak onto others.

  • Method Details

    • addClassLoader

      @Deprecated default void addClassLoader(ClassLoader loader)
      Deprecated.
      Adds a ClassLoader that is used to load classes that are needed for finding and loading Assets. This does not allow loading assets from that classpath, use registerLocator for that.
      Parameters:
      loader - A ClassLoader that Classes in asset files can be loaded from.
    • removeClassLoader

      @Deprecated default void removeClassLoader(ClassLoader loader)
      Deprecated.
      Remove a ClassLoader from the list of registered ClassLoaders
      Parameters:
      loader - the ClassLoader to be removed
    • getClassLoaders

      @Deprecated default List<ClassLoader> getClassLoaders()
      Deprecated.
      Retrieve the list of registered ClassLoaders that are used for loading classes from asset files.
      Returns:
      an unmodifiable list
    • registerLoader

      void registerLoader(Class<? extends AssetLoader> loaderClass, String... extensions)
      Register an AssetLoader by using a class object.
      Parameters:
      loaderClass - The loader class to register.
      extensions - Which extensions this loader is responsible for loading, if there are already other loaders registered for that extension, they will be overridden - there should only be one loader for each extension.
    • unregisterLoader

      void unregisterLoader(Class<? extends AssetLoader> loaderClass)
      Unregister a AssetLoader from loading its assigned extensions. This undoes the effect of calling registerLoader(java.lang.Class, java.lang.String[]).
      Parameters:
      loaderClass - The loader class to unregister.
      See Also:
    • registerLocator

      void registerLocator(String rootPath, Class<? extends AssetLocator> locatorClass)
      Registers the given locator class for locating assets with this AssetManager. AssetLocators are invoked in the order they were registered, to locate the asset by the AssetKey. Once an AssetLocator returns a non-null AssetInfo, it is sent to the AssetLoader to load the asset. Once a locator is registered, it can be removed via unregisterLocator(java.lang.String, java.lang.Class).
      Parameters:
      rootPath - Specifies the root path from which to locate assets for the given AssetLocator. The purpose of this parameter depends on the type of the AssetLocator.
      locatorClass - The class type of the AssetLocator to register.
      See Also:
    • unregisterLocator

      void unregisterLocator(String rootPath, Class<? extends AssetLocator> locatorClass)
      Unregisters the given locator class. This essentially undoes the operation done by registerLocator(java.lang.String, java.lang.Class).
      Parameters:
      rootPath - Should be the same as the root path specified in registerLocator(java.lang.String, java.lang.Class).
      locatorClass - The locator class to unregister
      See Also:
    • addAssetEventListener

      void addAssetEventListener(AssetEventListener listener)
      Add an AssetEventListener to receive events from this AssetManager.
      Parameters:
      listener - The asset event listener to add
    • removeAssetEventListener

      void removeAssetEventListener(AssetEventListener listener)
      Remove an AssetEventListener from receiving events from this AssetManager
      Parameters:
      listener - The asset event listener to remove
    • clearAssetEventListeners

      void clearAssetEventListeners()
      Removes all asset event listeners.
      See Also:
    • locateAsset

      AssetInfo locateAsset(AssetKey<?> key)
      Manually locates an asset with the given AssetKey. This method should be used for debugging or internal uses.
      The call will attempt to locate the asset by invoking the AssetLocator that are registered with this AssetManager, in the same way that the loadAsset(com.jme3.asset.AssetKey) method locates assets.
      Parameters:
      key - The AssetKey to locate.
      Returns:
      The AssetInfo object returned from the AssetLocator that located the asset, or null if the asset cannot be located.
    • loadAssetFromStream

      <T> T loadAssetFromStream(AssetKey<T> key, InputStream inputStream)
      Load an asset from an InputStream. In some cases it may be required to load an asset from memory or arbitrary streams so that registering a custom locator and key type is not necessary.
      Type Parameters:
      T - The object type that will be loaded from the AssetKey instance.
      Parameters:
      key - The AssetKey. Note that the asset will not be cached - following the same behavior as if AssetKey.getCacheType() returned null.
      inputStream - The input stream from which the asset shall be loaded.
      Returns:
      The loaded asset.
      Throws:
      AssetLoadException - If the AssetLoader has failed to load the asset due to an IOException or another error.
    • loadAsset

      <T> T loadAsset(AssetKey<T> key)
      Load an asset from a key, the asset will be located by one of the AssetLocator implementations provided in the registerLocator(java.lang.String, java.lang.Class) call. If located successfully, it will be loaded via the appropriate AssetLoader implementation based on the file's extension, as specified in the call registerLoader(java.lang.Class, java.lang.String[]).
      Type Parameters:
      T - The object type that will be loaded from the AssetKey instance.
      Parameters:
      key - The AssetKey
      Returns:
      The loaded asset.
      Throws:
      AssetNotFoundException - If all registered locators have failed to locate the asset.
      AssetLoadException - If the AssetLoader has failed to load the asset due to an IOException or another error.
    • loadAsset

      Object loadAsset(String name)
      Load an asset by name, calling this method is the same as calling loadAsset(new AssetKey(name)).
      Parameters:
      name - The name of the asset to load.
      Returns:
      The loaded asset, or null if failed to be loaded.
      See Also:
    • loadTexture

      Texture loadTexture(TextureKey key)
      Loads texture file, supported types are BMP, JPG, PNG, GIF, TGA, DDS, PFM, and HDR.
      Parameters:
      key - The TextureKey to use for loading.
      Returns:
      The loaded texture, or null if failed to be loaded.
      See Also:
    • loadTexture

      Texture loadTexture(String name)
      Loads texture file, supported types are BMP, JPG, PNG, GIF, TGA, DDS, PFM, and HDR. The texture will be loaded with mip-mapping enabled.
      Parameters:
      name - The name of the texture to load.
      Returns:
      The texture that was loaded
      See Also:
    • loadAudio

      AudioData loadAudio(AudioKey key)
      Load audio file, supported types are WAV or OGG.
      Parameters:
      key - Asset key of the audio file to load
      Returns:
      The audio data loaded
      See Also:
    • loadAudio

      AudioData loadAudio(String name)
      Load audio file, supported types are WAV or OGG. The file is loaded without stream-mode.
      Parameters:
      name - Asset name of the audio file to load
      Returns:
      The audio data loaded
      See Also:
    • loadModel

      Spatial loadModel(ModelKey key)
      Loads a 3D model with a ModelKey. Models can be jME3 object files (J3O), OgreXML (mesh.xml), BLEND, FBX and OBJ files.
      Parameters:
      key - Asset key of the model to load
      Returns:
      The model that was loaded
      See Also:
    • loadModel

      Spatial loadModel(String name)
      Loads a 3D model. Models can be jME3 object files (J3O), OgreXML (mesh.xml), BLEND, FBX and OBJ files.
      Parameters:
      name - Asset name of the model to load
      Returns:
      The model that was loaded
      See Also:
    • loadMaterial

      Material loadMaterial(String name)
      Load a material instance (J3M) file.
      Parameters:
      name - Asset name of the material to load
      Returns:
      The material that was loaded
      See Also:
    • loadFont

      BitmapFont loadFont(String name)
      Load a font file. Font files are in AngelCode text format, and are with the extension "fnt".
      Parameters:
      name - Asset name of the font to load
      Returns:
      The font loaded
      See Also:
    • loadFilter

      FilterPostProcessor loadFilter(FilterKey key)
      Loads a filter *.j3f file with a FilterKey.
      Parameters:
      key - Asset key of the filter file to load
      Returns:
      The filter that was loaded
      See Also:
    • loadFilter

      FilterPostProcessor loadFilter(String name)
      Loads a filter *.j3f file with a FilterKey.
      Parameters:
      name - Asset name of the filter file to load
      Returns:
      The filter that was loaded
      See Also:
    • setShaderGenerator

      void setShaderGenerator(ShaderGenerator generator)
      Sets the shaderGenerator to generate shaders based on shaderNodes.
      Parameters:
      generator - the shaderGenerator
    • getShaderGenerator

      ShaderGenerator getShaderGenerator(EnumSet<Caps> caps)
      Returns the shaderGenerator responsible for generating the shaders
      Parameters:
      caps - a set of required capabilities
      Returns:
      the shaderGenerator
    • getFromCache

      <T> T getFromCache(AssetKey<T> key)
      Retrieve an asset from the asset cache. NOTE: Do not modify the returned asset! It is the same reference as what is stored in the cache, therefore any modifications to it will leak onto assets loaded from the same key in the future.
      Type Parameters:
      T - The object type that will be retrieved from the AssetKey instance.
      Parameters:
      key - The AssetKey to get from the cache.
      Returns:
      The cached asset, if found. Otherwise, null.
      Throws:
      IllegalArgumentException - If caching is disabled for the key.
    • addToCache

      <T> void addToCache(AssetKey<T> key, T asset)
      Inject an asset into the asset cache. NOTE: Do not modify the cached asset after storing! It is the same reference as what is stored in the cache, therefore any modifications to it will leak onto assets loaded from the same key in the future.
      Type Parameters:
      T - The object type of the asset.
      Parameters:
      key - The key where the asset shall be stored.
      asset - The asset to inject into the cache.
      Throws:
      IllegalArgumentException - If caching is disabled for the key.
    • deleteFromCache

      <T> boolean deleteFromCache(AssetKey<T> key)
      Delete an asset from the asset cache.
      Type Parameters:
      T - The object type of the AssetKey instance.
      Parameters:
      key - The asset key to remove from the cache.
      Returns:
      True if the asset key was found in the cache and was removed successfully. False if the asset key was not present in the cache.
      Throws:
      IllegalArgumentException - If caching is disabled for the key.
    • clearCache

      void clearCache()
      Clears the asset cache.