public class DesktopAssetManager extends java.lang.Object implements AssetManager
AssetManager
is the primary method for managing and loading
assets inside jME.Constructor and Description |
---|
DesktopAssetManager() |
DesktopAssetManager(boolean usePlatformConfig) |
DesktopAssetManager(java.net.URL configFile) |
Modifier and Type | Method and Description |
---|---|
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)
Inject an asset into the asset cache.
|
void |
clearAssetEventListeners()
Removes all asset event listeners.
|
void |
clearCache()
Clears the asset cache.
|
<T> boolean |
deleteFromCache(AssetKey<T> key)
Delete an asset from the asset cache.
|
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)
Retrieve an asset from the asset cache.
|
ShaderGenerator |
getShaderGenerator(java.util.EnumSet<Caps> caps)
Returns the shaderGenerator responsible for generating the shaders
|
<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
AssetManager.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)) . |
<T> T |
loadAssetFromStream(AssetKey<T> key,
java.io.InputStream inputStream)
Load an asset from an
InputStream . |
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.
|
FilterPostProcessor |
loadFilter(FilterKey key)
Loads a filter *.j3f file with a FilterKey.
|
FilterPostProcessor |
loadFilter(java.lang.String name)
Loads a filter *.j3f file with a FilterKey.
|
BitmapFont |
loadFont(java.lang.String name)
Load a font file.
|
protected <T> T |
loadLocatedAsset(AssetKey<T> key,
AssetInfo info,
AssetProcessor proc,
AssetCache cache)
Loads an asset that has already been located.
|
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.
|
Texture |
loadTexture(java.lang.String name)
Loads texture file, supported types are BMP, JPG, PNG, GIF,
TGA, DDS, PFM, and HDR.
|
Texture |
loadTexture(TextureKey key)
Loads texture file, supported types are BMP, JPG, PNG, GIF,
TGA, DDS, PFM, and HDR.
|
AssetInfo |
locateAsset(AssetKey<?> key)
Manually locates an asset with the given
AssetKey . |
protected <T> T |
registerAndCloneSmartAsset(AssetKey<T> key,
T obj,
AssetProcessor proc,
AssetCache cache)
Clones the asset using the given processor and registers the clone
with the cache.
|
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) |
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) |
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) |
void |
setShaderGenerator(ShaderGenerator shaderGenerator)
Sets the shaderGenerator to generate shaders based on shaderNodes.
|
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.
|
public DesktopAssetManager()
public DesktopAssetManager(boolean usePlatformConfig)
public DesktopAssetManager(java.net.URL configFile)
public void addClassLoader(java.lang.ClassLoader loader)
AssetManager
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.addClassLoader
in interface AssetManager
loader
- A ClassLoader that Classes in asset files can be loaded from.public void removeClassLoader(java.lang.ClassLoader loader)
AssetManager
ClassLoader
from the list of registered ClassLoadersremoveClassLoader
in interface AssetManager
public java.util.List<java.lang.ClassLoader> getClassLoaders()
AssetManager
classes
from asset files.getClassLoaders
in interface AssetManager
public void addAssetEventListener(AssetEventListener listener)
AssetManager
AssetEventListener
to receive events from this
AssetManager
.addAssetEventListener
in interface AssetManager
listener
- The asset event listener to addpublic void removeAssetEventListener(AssetEventListener listener)
AssetManager
AssetEventListener
from receiving events from this
AssetManager
removeAssetEventListener
in interface AssetManager
listener
- The asset event listener to removepublic void clearAssetEventListeners()
AssetManager
clearAssetEventListeners
in interface AssetManager
AssetManager.addAssetEventListener(com.jme3.asset.AssetEventListener)
public void setAssetEventListener(AssetEventListener listener)
public void registerLoader(java.lang.Class<? extends AssetLoader> loader, java.lang.String... extensions)
AssetManager
AssetLoader
by using a class object.registerLoader
in interface AssetManager
loader
- 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.public void registerLoader(java.lang.String clsName, java.lang.String... extensions)
public void unregisterLoader(java.lang.Class<? extends AssetLoader> loaderClass)
AssetManager
AssetLoader
from loading its assigned extensions.
This undoes the effect of calling
AssetManager.registerLoader(java.lang.Class, java.lang.String[])
.unregisterLoader
in interface AssetManager
loaderClass
- The loader class to unregister.AssetManager.registerLoader(java.lang.Class, java.lang.String[])
public void registerLocator(java.lang.String rootPath, java.lang.Class<? extends AssetLocator> locatorClass)
AssetManager
AssetManager
. AssetLocator
s 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)
.registerLocator
in interface AssetManager
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.AssetLocator.setRootPath(java.lang.String)
,
AssetLocator.locate(com.jme3.asset.AssetManager, com.jme3.asset.AssetKey)
,
AssetManager.unregisterLocator(java.lang.String, java.lang.Class)
public void registerLocator(java.lang.String rootPath, java.lang.String clsName)
public void unregisterLocator(java.lang.String rootPath, java.lang.Class<? extends AssetLocator> clazz)
AssetManager
AssetManager.registerLocator(java.lang.String, java.lang.Class)
.unregisterLocator
in interface AssetManager
rootPath
- Should be the same as the root path specified in AssetManager.registerLocator(java.lang.String, java.lang.Class)
.clazz
- The locator class to unregisterAssetManager.registerLocator(java.lang.String, java.lang.Class)
public AssetInfo locateAsset(AssetKey<?> key)
AssetManager
AssetKey
.
This method should be used for debugging or internal uses.
AssetLocator
that are registered with this AssetManager
,
in the same way that the AssetManager.loadAsset(com.jme3.asset.AssetKey)
method locates assets.locateAsset
in interface AssetManager
key
- The AssetKey
to locate.AssetInfo
object returned from the AssetLocator
that located the asset, or null if the asset cannot be located.public <T> T getFromCache(AssetKey<T> key)
AssetManager
getFromCache
in interface AssetManager
T
- The object type that will be retrieved from the AssetKey instance.key
- The AssetKey to get from the cache.null
.public <T> void addToCache(AssetKey<T> key, T asset)
AssetManager
addToCache
in interface AssetManager
T
- The object type of the asset.key
- The key where the asset shall be stored.asset
- The asset to inject into the cache.public <T> boolean deleteFromCache(AssetKey<T> key)
AssetManager
deleteFromCache
in interface AssetManager
T
- The object type of the AssetKey instance.key
- The asset key to remove from the cache.public void clearCache()
AssetManager
clearCache
in interface AssetManager
protected <T> T loadLocatedAsset(AssetKey<T> key, AssetInfo info, AssetProcessor proc, AssetCache cache)
T
- The asset typekey
- The asset keyinfo
- The AssetInfo from the locatorproc
- AssetProcessor to use, or null to disable processingcache
- The cache to store the asset in, or null to disable cachingAssetLoadException
- If failed to load asset due to exception or
other error.protected <T> T registerAndCloneSmartAsset(AssetKey<T> key, T obj, AssetProcessor proc, AssetCache cache)
T
- The asset typekey
- The asset keyobj
- The asset to clone / register, must implement
CloneableSmartAsset
.proc
- The processor which will generate the clone, cannot be nullcache
- The cache to register the clone with, cannot be null.java.lang.IllegalStateException
- If asset does not implement
CloneableSmartAsset
, if the cache is null, or if the
processor did not clone the asset.public <T> T loadAssetFromStream(AssetKey<T> key, java.io.InputStream inputStream)
AssetManager
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.loadAssetFromStream
in interface AssetManager
T
- The object type that will be loaded from the AssetKey instance.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.public <T> T loadAsset(AssetKey<T> key)
AssetManager
AssetLocator
implementations provided in the
AssetManager.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
AssetManager.registerLoader(java.lang.Class, java.lang.String[])
.loadAsset
in interface AssetManager
T
- The object type that will be loaded from the AssetKey instance.key
- The AssetKeypublic java.lang.Object loadAsset(java.lang.String name)
AssetManager
loadAsset(new AssetKey(name))
.loadAsset
in interface AssetManager
name
- The name of the asset to load.AssetManager.loadAsset(com.jme3.asset.AssetKey)
public Texture loadTexture(TextureKey key)
AssetManager
loadTexture
in interface AssetManager
key
- The TextureKey
to use for loading.AssetManager.loadAsset(com.jme3.asset.AssetKey)
public Material loadMaterial(java.lang.String name)
AssetManager
loadMaterial
in interface AssetManager
name
- Asset name of the material to loadAssetManager.loadAsset(com.jme3.asset.AssetKey)
public Texture loadTexture(java.lang.String name)
AssetManager
loadTexture
in interface AssetManager
name
- The name of the texture to load.AssetManager.loadAsset(com.jme3.asset.AssetKey)
public AudioData loadAudio(AudioKey key)
AssetManager
loadAudio
in interface AssetManager
key
- Asset key of the audio file to loadAssetManager.loadAsset(com.jme3.asset.AssetKey)
public AudioData loadAudio(java.lang.String name)
AssetManager
loadAudio
in interface AssetManager
name
- Asset name of the audio file to loadAssetManager.loadAsset(com.jme3.asset.AssetKey)
public BitmapFont loadFont(java.lang.String name)
AssetManager
loadFont
in interface AssetManager
name
- Asset name of the font to loadAssetManager.loadAsset(com.jme3.asset.AssetKey)
public Spatial loadModel(ModelKey key)
AssetManager
loadModel
in interface AssetManager
key
- Asset key of the model to loadAssetManager.loadAsset(com.jme3.asset.AssetKey)
public Spatial loadModel(java.lang.String name)
AssetManager
loadModel
in interface AssetManager
name
- Asset name of the model to loadAssetManager.loadAsset(com.jme3.asset.AssetKey)
public FilterPostProcessor loadFilter(FilterKey key)
AssetManager
loadFilter
in interface AssetManager
key
- Asset key of the filter file to loadAssetManager.loadAsset(com.jme3.asset.AssetKey)
public FilterPostProcessor loadFilter(java.lang.String name)
AssetManager
loadFilter
in interface AssetManager
name
- Asset name of the filter file to loadAssetManager.loadAsset(com.jme3.asset.AssetKey)
public ShaderGenerator getShaderGenerator(java.util.EnumSet<Caps> caps)
getShaderGenerator
in interface AssetManager
public void setShaderGenerator(ShaderGenerator shaderGenerator)
setShaderGenerator
in interface AssetManager
shaderGenerator
- the shaderGenerator