com.jme3.asset
Class DesktopAssetManager

java.lang.Object
  extended by com.jme3.asset.DesktopAssetManager
All Implemented Interfaces:
AssetManager
Direct Known Subclasses:
AndroidAssetManager

public class DesktopAssetManager
extends java.lang.Object
implements AssetManager

AssetManager is the primary method for managing and loading assets inside jME.


Constructor Summary
DesktopAssetManager()
           
DesktopAssetManager(boolean loadDefaults)
          Deprecated. 
DesktopAssetManager(java.net.URL configFile)
           
 
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.
<T> void
addToCache(AssetKey<T> key, T asset)
           
 void clearAssetEventListeners()
          Removes all asset event listeners.
 void clearCache()
           
<T> boolean
deleteFromCache(AssetKey<T> key)
           
 java.util.List<java.lang.ClassLoader> getClassLoaders()
          Retrieve the list of registered ClassLoaders that are used for loading classes from asset files.
<T> T
getFromCache(AssetKey<T> key)
           
<T> T
loadAsset(AssetKey<T> key)
          Thread-safe.
 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)
          Load a vertex/fragment shader combo.
 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> loader, java.lang.String... extensions)
          Register an AssetLoader by using a class object.
 void registerLoader(java.lang.String clsName, java.lang.String... extensions)
          Registers a loader for the given extensions.
 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 clsName)
          Registers an AssetLocator by using a class name.
 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)
          Set an AssetEventListener to receive events from this AssetManager.
 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> clazz)
          Unregisters the given locator class.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DesktopAssetManager

public DesktopAssetManager()

DesktopAssetManager

@Deprecated
public DesktopAssetManager(boolean loadDefaults)
Deprecated. 


DesktopAssetManager

public DesktopAssetManager(java.net.URL configFile)
Method Detail

addClassLoader

public void addClassLoader(java.lang.ClassLoader loader)
Description copied from interface: AssetManager
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.

Specified by:
addClassLoader in interface AssetManager
Parameters:
loader - A ClassLoader that Classes in asset files can be loaded from.

removeClassLoader

public void removeClassLoader(java.lang.ClassLoader loader)
Description copied from interface: AssetManager
Remove a ClassLoader from the list of registered ClassLoaders

Specified by:
removeClassLoader in interface AssetManager

getClassLoaders

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

Specified by:
getClassLoaders in interface AssetManager

addAssetEventListener

public void addAssetEventListener(AssetEventListener listener)
Description copied from interface: AssetManager
Add an AssetEventListener to receive events from this AssetManager.

Specified by:
addAssetEventListener in interface AssetManager
Parameters:
listener - The asset event listener to add

removeAssetEventListener

public void removeAssetEventListener(AssetEventListener listener)
Description copied from interface: AssetManager
Remove an AssetEventListener from receiving events from this AssetManager

Specified by:
removeAssetEventListener in interface AssetManager
Parameters:
listener - The asset event listener to remove

clearAssetEventListeners

public void clearAssetEventListeners()
Description copied from interface: AssetManager
Removes all asset event listeners.

Specified by:
clearAssetEventListeners in interface AssetManager
See Also:
AssetManager.addAssetEventListener(com.jme3.asset.AssetEventListener)

setAssetEventListener

public void setAssetEventListener(AssetEventListener listener)
Description copied from interface: AssetManager
Set an AssetEventListener to receive events from this AssetManager. Any currently added listeners are cleared and then the given listener is added.

Specified by:
setAssetEventListener in interface AssetManager
Parameters:
listener - The listener to set

registerLoader

public void registerLoader(java.lang.Class<? extends AssetLoader> loader,
                           java.lang.String... extensions)
Description copied from interface: AssetManager
Register an AssetLoader by using a class object.

Specified by:
registerLoader in interface AssetManager

registerLoader

public void registerLoader(java.lang.String clsName,
                           java.lang.String... extensions)
Description copied from interface: AssetManager
Registers a loader for the given extensions.

Specified by:
registerLoader in interface AssetManager

unregisterLoader

public void unregisterLoader(java.lang.Class<? extends AssetLoader> loaderClass)
Description copied from interface: AssetManager
Unregister a AssetLoader from loading its assigned extensions. This undoes the effect of calling AssetManager.registerLoader(java.lang.Class, java.lang.String[]).

Specified by:
unregisterLoader in interface AssetManager
Parameters:
loaderClass - The loader class to unregister.
See Also:
AssetManager.registerLoader(java.lang.Class, java.lang.String[])

registerLocator

public void registerLocator(java.lang.String rootPath,
                            java.lang.Class<? extends AssetLocator> locatorClass)
Description copied from interface: AssetManager
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 AssetManager.unregisterLocator(java.lang.String, java.lang.Class).

Specified by:
registerLocator in interface AssetManager
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), AssetManager.unregisterLocator(java.lang.String, java.lang.Class)

registerLocator

public void registerLocator(java.lang.String rootPath,
                            java.lang.String clsName)
Description copied from interface: AssetManager
Registers an AssetLocator by using a class name. See the AssetManager.registerLocator(java.lang.String, java.lang.Class) method for more information.

Specified by:
registerLocator in interface AssetManager
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).
clsName - The full class name of the AssetLocator implementation.

unregisterLocator

public void unregisterLocator(java.lang.String rootPath,
                              java.lang.Class<? extends AssetLocator> clazz)
Description copied from interface: AssetManager
Unregisters the given locator class. This essentially undoes the operation done by AssetManager.registerLocator(java.lang.String, java.lang.Class).

Specified by:
unregisterLocator in interface AssetManager
Parameters:
rootPath - Should be the same as the root path specified in AssetManager.registerLocator(java.lang.String, java.lang.Class).
clazz - The locator class to unregister
See Also:
AssetManager.registerLocator(java.lang.String, java.lang.Class)

locateAsset

public AssetInfo locateAsset(AssetKey<?> key)
Description copied from interface: AssetManager
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 AssetManager.loadAsset(com.jme3.asset.AssetKey) method locates assets.

Specified by:
locateAsset in interface AssetManager
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.

getFromCache

public <T> T getFromCache(AssetKey<T> key)

addToCache

public <T> void addToCache(AssetKey<T> key,
                           T asset)

deleteFromCache

public <T> boolean deleteFromCache(AssetKey<T> key)

clearCache

public void clearCache()

loadAsset

public <T> T loadAsset(AssetKey<T> key)
Thread-safe.

Specified by:
loadAsset in interface AssetManager
Type Parameters:
T -
Parameters:
key -
Returns:
the loaded asset

loadAsset

public java.lang.Object loadAsset(java.lang.String name)
Description copied from interface: AssetManager
Load an asset by name, calling this method is the same as calling loadAsset(new AssetKey(name)).

Specified by:
loadAsset in interface AssetManager
Parameters:
name - The name of the asset to load.
Returns:
The loaded asset, or null if failed to be loaded.
See Also:
AssetManager.loadAsset(com.jme3.asset.AssetKey)

loadTexture

public Texture loadTexture(TextureKey key)
Description copied from interface: AssetManager
Loads texture file, supported types are BMP, JPG, PNG, GIF, TGA and DDS.

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

loadMaterial

public Material loadMaterial(java.lang.String name)
Description copied from interface: AssetManager
Load a material instance (J3M) file.

Specified by:
loadMaterial in interface AssetManager
Parameters:
name - Asset name of the material to load
Returns:
The material that was loaded
See Also:
AssetManager.loadAsset(com.jme3.asset.AssetKey)

loadTexture

public Texture loadTexture(java.lang.String name)
Description copied from interface: AssetManager
Loads texture file, supported types are BMP, JPG, PNG, GIF, TGA and DDS.

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

loadAudio

public AudioData loadAudio(AudioKey key)
Description copied from interface: AssetManager
Load audio file, supported types are WAV or OGG.

Specified by:
loadAudio in interface AssetManager
Parameters:
key - Asset key of the audio file to load
Returns:
The audio data loaded
See Also:
AssetManager.loadAsset(com.jme3.asset.AssetKey)

loadAudio

public AudioData loadAudio(java.lang.String name)
Description copied from interface: AssetManager
Load audio file, supported types are WAV or OGG. The file is loaded without stream-mode.

Specified by:
loadAudio in interface AssetManager
Parameters:
name - Asset name of the audio file to load
Returns:
The audio data loaded
See Also:
AssetManager.loadAsset(com.jme3.asset.AssetKey)

loadFont

public BitmapFont loadFont(java.lang.String name)
Description copied from interface: AssetManager
Load a font file. Font files are in AngelCode text format, and are with the extension "fnt".

Specified by:
loadFont in interface AssetManager
Parameters:
name - Asset name of the font to load
Returns:
The font loaded
See Also:
AssetManager.loadAsset(com.jme3.asset.AssetKey)

loadModel

public Spatial loadModel(ModelKey key)
Description copied from interface: AssetManager
Loads a 3D model with a ModelKey. Models can be jME3 object files (J3O) or OgreXML/OBJ files.

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

loadModel

public Spatial loadModel(java.lang.String name)
Description copied from interface: AssetManager
Loads a 3D model. Models can be jME3 object files (J3O) or OgreXML/OBJ files.

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

loadShader

public Shader loadShader(ShaderKey key)
Load a vertex/fragment shader combo.

Specified by:
loadShader in interface AssetManager
Parameters:
key -
Returns:
the loaded Shader
See Also:
AssetManager.loadAsset(com.jme3.asset.AssetKey)