com.jme3.asset
Interface AssetManager

All Known Implementing Classes:
AndroidAssetManager, 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:

Once the asset has been loaded,


Method Summary
 void addAssetEventListener(AssetEventListener listener)
          Add an AssetEventListener to receive events from this AssetManager.
 void addClassLoader(java.lang.ClassLoader loader)
          Adds a ClassLoader that is used to load classes that are needed for finding and loading Assets.
 void clearAssetEventListeners()
          Removes all asset event listeners.
 java.util.List<java.lang.ClassLoader> getClassLoaders()
          Retrieve the list of registered ClassLoaders that are used for loading classes from asset files.
<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.
 java.lang.Object loadAsset(java.lang.String name)
          Load an asset by name, calling this method is the same as calling loadAsset(new AssetKey(name)).
 AudioData loadAudio(AudioKey key)
          Load audio file, supported types are WAV or OGG.
 AudioData loadAudio(java.lang.String name)
          Load audio file, supported types are WAV or OGG.
 BitmapFont loadFont(java.lang.String name)
          Load a font file.
 Material loadMaterial(java.lang.String name)
          Load a material instance (J3M) file.
 Spatial loadModel(ModelKey key)
          Loads a 3D model with a ModelKey.
 Spatial loadModel(java.lang.String name)
          Loads a 3D model.
 Shader loadShader(ShaderKey key)
          Loads shader file(s), shouldn't be used by end-user in most cases.
 Texture loadTexture(java.lang.String name)
          Loads texture file, supported types are BMP, JPG, PNG, GIF, TGA and DDS.
 Texture loadTexture(TextureKey key)
          Loads texture file, supported types are BMP, JPG, PNG, GIF, TGA and DDS.
 AssetInfo locateAsset(AssetKey<?> key)
          Manually locates an asset with the given AssetKey.
 void registerLoader(java.lang.Class<? extends AssetLoader> loaderClass, java.lang.String... extensions)
          Register an AssetLoader by using a class object.
 void registerLoader(java.lang.String loaderClassName, java.lang.String... extensions)
          Deprecated. Please use registerLoader(java.lang.Class, java.lang.String[]) together with Class.forName(java.lang.String) to find a class and then register it.
 void registerLocator(java.lang.String rootPath, java.lang.Class<? extends AssetLocator> locatorClass)
          Registers the given locator class for locating assets with this AssetManager.
 void registerLocator(java.lang.String rootPath, java.lang.String locatorClassName)
          Deprecated. Please use registerLocator(java.lang.String, java.lang.Class) together with Class.forName(java.lang.String) to find a class and then register it.
 void removeAssetEventListener(AssetEventListener listener)
          Remove an AssetEventListener from receiving events from this AssetManager
 void removeClassLoader(java.lang.ClassLoader loader)
          Remove a ClassLoader from the list of registered ClassLoaders
 void setAssetEventListener(AssetEventListener listener)
          Deprecated. Please use addAssetEventListener(com.jme3.asset.AssetEventListener) to listen for asset events.
 void unregisterLoader(java.lang.Class<? extends AssetLoader> loaderClass)
          Unregister a AssetLoader from loading its assigned extensions.
 void unregisterLocator(java.lang.String rootPath, java.lang.Class<? extends AssetLocator> locatorClass)
          Unregisters the given locator class.
 

Method Detail

addClassLoader

void addClassLoader(java.lang.ClassLoader loader)
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

void removeClassLoader(java.lang.ClassLoader loader)
Remove a ClassLoader from the list of registered ClassLoaders


getClassLoaders

java.util.List<java.lang.ClassLoader> getClassLoaders()
Retrieve the list of registered ClassLoaders that are used for loading classes from asset files.


registerLoader

@Deprecated
void registerLoader(java.lang.String loaderClassName,
                               java.lang.String... extensions)
Deprecated. Please use registerLoader(java.lang.Class, java.lang.String[]) together with Class.forName(java.lang.String) to find a class and then register it.

Registers a loader for the given extensions.

Parameters:
loaderClassName -
extensions -

registerLocator

@Deprecated
void registerLocator(java.lang.String rootPath,
                                java.lang.String locatorClassName)
Deprecated. Please use registerLocator(java.lang.String, java.lang.Class) together with Class.forName(java.lang.String) to find a class and then register it.

Registers an AssetLocator by using a class name. See the registerLocator(java.lang.String, java.lang.Class) method for more information.

Parameters:
rootPath - The root path from which to locate assets, this depends on the implementation of the asset locator. A URL based locator will expect a url folder such as "http://www.example.com/" while a File based locator will expect a file path (OS dependent).
locatorClassName - The full class name of the AssetLocator implementation.

registerLoader

void registerLoader(java.lang.Class<? extends AssetLoader> loaderClass,
                    java.lang.String... extensions)
Register an AssetLoader by using a class object.

Parameters:
loaderClass -
extensions -

unregisterLoader

void unregisterLoader(java.lang.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:
registerLoader(java.lang.Class, java.lang.String[])

registerLocator

void registerLocator(java.lang.String rootPath,
                     java.lang.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:
AssetLocator.setRootPath(java.lang.String), AssetLocator.locate(com.jme3.asset.AssetManager, com.jme3.asset.AssetKey), unregisterLocator(java.lang.String, java.lang.Class)

unregisterLocator

void unregisterLocator(java.lang.String rootPath,
                       java.lang.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:
registerLocator(java.lang.String, java.lang.Class)

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:
addAssetEventListener(com.jme3.asset.AssetEventListener)

setAssetEventListener

@Deprecated
void setAssetEventListener(AssetEventListener listener)
Deprecated. Please use addAssetEventListener(com.jme3.asset.AssetEventListener) to listen for asset events.

Set an AssetEventListener to receive events from this AssetManager. Any currently added listeners are cleared and then the given listener is added.

Parameters:
listener - The listener to set

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.

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 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, or null if it was failed to be located or loaded.

loadAsset

java.lang.Object loadAsset(java.lang.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:
loadAsset(com.jme3.asset.AssetKey)

loadTexture

Texture loadTexture(TextureKey key)
Loads texture file, supported types are BMP, JPG, PNG, GIF, TGA and DDS.

Parameters:
key - The TextureKey to use for loading.
Returns:
The loaded texture, or null if failed to be loaded.
See Also:
loadAsset(com.jme3.asset.AssetKey)

loadTexture

Texture loadTexture(java.lang.String name)
Loads texture file, supported types are BMP, JPG, PNG, GIF, TGA and DDS.

Parameters:
name - The name of the texture to load.
Returns:
The texture that was loaded
See Also:
loadAsset(com.jme3.asset.AssetKey)

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:
loadAsset(com.jme3.asset.AssetKey)

loadAudio

AudioData loadAudio(java.lang.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:
loadAsset(com.jme3.asset.AssetKey)

loadModel

Spatial loadModel(ModelKey key)
Loads a 3D model with a ModelKey. Models can be jME3 object files (J3O) or OgreXML/OBJ files.

Parameters:
key - Asset key of the model to load
Returns:
The model that was loaded
See Also:
loadAsset(com.jme3.asset.AssetKey)

loadModel

Spatial loadModel(java.lang.String name)
Loads a 3D model. Models can be jME3 object files (J3O) or OgreXML/OBJ files.

Parameters:
name - Asset name of the model to load
Returns:
The model that was loaded
See Also:
loadAsset(com.jme3.asset.AssetKey)

loadMaterial

Material loadMaterial(java.lang.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:
loadAsset(com.jme3.asset.AssetKey)

loadShader

Shader loadShader(ShaderKey key)
Loads shader file(s), shouldn't be used by end-user in most cases.

See Also:
loadAsset(com.jme3.asset.AssetKey)

loadFont

BitmapFont loadFont(java.lang.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:
loadAsset(com.jme3.asset.AssetKey)