Package com.jme3.asset
Class DesktopAssetManager
java.lang.Object
com.jme3.asset.DesktopAssetManager
- All Implemented Interfaces:
AssetManager
AssetManager
is the primary method for managing and loading
assets inside jME.-
Constructor Summary
ConstructorDescriptionDesktopAssetManager
(boolean usePlatformConfig) DesktopAssetManager
(URL configFile) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAssetEventListener
(AssetEventListener listener) Add anAssetEventListener
to receive events from thisAssetManager
.void
addClassLoader
(ClassLoader loader) Deprecated.<T> void
addToCache
(AssetKey<T> key, T asset) Inject an asset into the asset cache.void
Removes all asset event listeners.void
Clears the asset cache.<T> boolean
deleteFromCache
(AssetKey<T> key) Delete an asset from the asset cache.Deprecated.<T> T
getFromCache
(AssetKey<T> key) Retrieve an asset from the asset cache.getShaderGenerator
(EnumSet<Caps> caps) Returns the shaderGenerator responsible for generating the shaders<T> T
Load an asset from a key, the asset will be located by one of theAssetLocator
implementations provided in theAssetManager.registerLocator(java.lang.String, java.lang.Class)
call.Load an asset by name, calling this method is the same as callingloadAsset(new AssetKey(name))
.<T> T
loadAssetFromStream
(AssetKey<T> key, InputStream inputStream) Load an asset from anInputStream
.Load audio file, supported types are WAV or OGG.Load audio file, supported types are WAV or OGG.loadFilter
(FilterKey key) Loads a filter *.j3f file with a FilterKey.loadFilter
(String name) Loads a filter *.j3f file with a FilterKey.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.loadMaterial
(String name) Load a material instance (J3M) file.Loads a 3D model with a ModelKey.Loads a 3D model.loadTexture
(TextureKey key) Loads texture file, supported types are BMP, JPG, PNG, GIF, TGA, DDS, PFM, and HDR.loadTexture
(String name) Loads texture file, supported types are BMP, JPG, PNG, GIF, TGA, DDS, PFM, and HDR.locateAsset
(AssetKey<?> key) Manually locates an asset with the givenAssetKey
.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
(Class<? extends AssetLoader> loader, String... extensions) Register anAssetLoader
by using a class object.void
registerLoader
(String clsName, String... extensions) void
registerLocator
(String rootPath, Class<? extends AssetLocator> locatorClass) Registers the given locator class for locating assets with thisAssetManager
.void
registerLocator
(String rootPath, String clsName) void
removeAssetEventListener
(AssetEventListener listener) Remove anAssetEventListener
from receiving events from thisAssetManager
void
removeClassLoader
(ClassLoader loader) Deprecated.void
setAssetEventListener
(AssetEventListener listener) void
setShaderGenerator
(ShaderGenerator shaderGenerator) Sets the shaderGenerator to generate shaders based on shaderNodes.void
unregisterLoader
(Class<? extends AssetLoader> loaderClass) Unregister aAssetLoader
from loading its assigned extensions.void
unregisterLocator
(String rootPath, Class<? extends AssetLocator> clazz) Unregisters the given locator class.
-
Constructor Details
-
DesktopAssetManager
public DesktopAssetManager() -
DesktopAssetManager
public DesktopAssetManager(boolean usePlatformConfig) -
DesktopAssetManager
-
-
Method Details
-
addClassLoader
Deprecated.Description copied from interface:AssetManager
Adds aClassLoader
that is used to loadclasses
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 interfaceAssetManager
- Parameters:
loader
- A ClassLoader that Classes in asset files can be loaded from.
-
removeClassLoader
Deprecated.Description copied from interface:AssetManager
Remove aClassLoader
from the list of registered ClassLoaders- Specified by:
removeClassLoader
in interfaceAssetManager
- Parameters:
loader
- the ClassLoader to be removed
-
getClassLoaders
Deprecated.Description copied from interface:AssetManager
Retrieve the list of registered ClassLoaders that are used for loadingclasses
from asset files.- Specified by:
getClassLoaders
in interfaceAssetManager
- Returns:
- an unmodifiable list
-
addAssetEventListener
Description copied from interface:AssetManager
Add anAssetEventListener
to receive events from thisAssetManager
.- Specified by:
addAssetEventListener
in interfaceAssetManager
- Parameters:
listener
- The asset event listener to add
-
removeAssetEventListener
Description copied from interface:AssetManager
Remove anAssetEventListener
from receiving events from thisAssetManager
- Specified by:
removeAssetEventListener
in interfaceAssetManager
- 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 interfaceAssetManager
- See Also:
-
setAssetEventListener
-
registerLoader
Description copied from interface:AssetManager
Register anAssetLoader
by using a class object.- Specified by:
registerLoader
in interfaceAssetManager
- Parameters:
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.
-
registerLoader
-
unregisterLoader
Description copied from interface:AssetManager
Unregister aAssetLoader
from loading its assigned extensions. This undoes the effect of callingAssetManager.registerLoader(java.lang.Class, java.lang.String[])
.- Specified by:
unregisterLoader
in interfaceAssetManager
- Parameters:
loaderClass
- The loader class to unregister.- See Also:
-
registerLocator
Description copied from interface:AssetManager
Registers the given locator class for locating assets with thisAssetManager
.AssetLocator
s are invoked in the order they were registered, to locate the asset by theAssetKey
. Once anAssetLocator
returns a non-null AssetInfo, it is sent to theAssetLoader
to load the asset. Once a locator is registered, it can be removed viaAssetManager.unregisterLocator(java.lang.String, java.lang.Class)
.- Specified by:
registerLocator
in interfaceAssetManager
- Parameters:
rootPath
- Specifies the root path from which to locate assets for the givenAssetLocator
. The purpose of this parameter depends on the type of theAssetLocator
.locatorClass
- The class type of theAssetLocator
to register.- See Also:
-
registerLocator
-
unregisterLocator
Description copied from interface:AssetManager
Unregisters the given locator class. This essentially undoes the operation done byAssetManager.registerLocator(java.lang.String, java.lang.Class)
.- Specified by:
unregisterLocator
in interfaceAssetManager
- Parameters:
rootPath
- Should be the same as the root path specified inAssetManager.registerLocator(java.lang.String, java.lang.Class)
.clazz
- The locator class to unregister- See Also:
-
locateAsset
Description copied from interface:AssetManager
Manually locates an asset with the givenAssetKey
. This method should be used for debugging or internal uses.
The call will attempt to locate the asset by invoking theAssetLocator
that are registered with thisAssetManager
, in the same way that theAssetManager.loadAsset(com.jme3.asset.AssetKey)
method locates assets.- Specified by:
locateAsset
in interfaceAssetManager
- Parameters:
key
- TheAssetKey
to locate.- Returns:
- The
AssetInfo
object returned from theAssetLocator
that located the asset, or null if the asset cannot be located.
-
getFromCache
Description copied from interface:AssetManager
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.- Specified by:
getFromCache
in interfaceAssetManager
- 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
.
-
addToCache
Description copied from interface:AssetManager
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.- Specified by:
addToCache
in interfaceAssetManager
- 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.
-
deleteFromCache
Description copied from interface:AssetManager
Delete an asset from the asset cache.- Specified by:
deleteFromCache
in interfaceAssetManager
- 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.
-
clearCache
public void clearCache()Description copied from interface:AssetManager
Clears the asset cache.- Specified by:
clearCache
in interfaceAssetManager
-
loadLocatedAsset
protected <T> T loadLocatedAsset(AssetKey<T> key, AssetInfo info, AssetProcessor proc, AssetCache cache) Loads an asset that has already been located.- Type Parameters:
T
- The asset type- Parameters:
key
- 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 caching- Returns:
- The loaded asset
- Throws:
AssetLoadException
- If failed to load asset due to exception or other error.
-
registerAndCloneSmartAsset
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.- Type Parameters:
T
- The asset type- Parameters:
key
- The asset keyobj
- The asset to clone / register, must implementCloneableSmartAsset
.proc
- The processor which will generate the clone, cannot be nullcache
- The cache to register the clone with, cannot be null.- Returns:
- The cloned asset, cannot be the same as the given asset since it is a clone.
- Throws:
IllegalStateException
- If asset does not implementCloneableSmartAsset
, if the cache is null, or if the processor did not clone the asset.
-
loadAssetFromStream
Description copied from interface:AssetManager
Load an asset from anInputStream
. 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.- Specified by:
loadAssetFromStream
in interfaceAssetManager
- 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 ifAssetKey.getCacheType()
returned null.inputStream
- The input stream from which the asset shall be loaded.- Returns:
- The loaded asset.
-
loadAsset
Description copied from interface:AssetManager
Load an asset from a key, the asset will be located by one of theAssetLocator
implementations provided in theAssetManager.registerLocator(java.lang.String, java.lang.Class)
call. If located successfully, it will be loaded via the appropriateAssetLoader
implementation based on the file's extension, as specified in the callAssetManager.registerLoader(java.lang.Class, java.lang.String[])
.- Specified by:
loadAsset
in interfaceAssetManager
- Type Parameters:
T
- The object type that will be loaded from the AssetKey instance.- Parameters:
key
- The AssetKey- Returns:
- The loaded asset.
-
loadAsset
Description copied from interface:AssetManager
Load an asset by name, calling this method is the same as callingloadAsset(new AssetKey(name))
.- Specified by:
loadAsset
in interfaceAssetManager
- Parameters:
name
- The name of the asset to load.- Returns:
- The loaded asset, or null if failed to be loaded.
- See Also:
-
loadTexture
Description copied from interface:AssetManager
Loads texture file, supported types are BMP, JPG, PNG, GIF, TGA, DDS, PFM, and HDR.- Specified by:
loadTexture
in interfaceAssetManager
- Parameters:
key
- TheTextureKey
to use for loading.- Returns:
- The loaded texture, or null if failed to be loaded.
- See Also:
-
loadMaterial
Description copied from interface:AssetManager
Load a material instance (J3M) file.- Specified by:
loadMaterial
in interfaceAssetManager
- Parameters:
name
- Asset name of the material to load- Returns:
- The material that was loaded
- See Also:
-
loadTexture
Description copied from interface:AssetManager
Loads texture file, supported types are BMP, JPG, PNG, GIF, TGA, DDS, PFM, and HDR. The texture will be loaded with mip-mapping enabled.- Specified by:
loadTexture
in interfaceAssetManager
- Parameters:
name
- The name of the texture to load.- Returns:
- The texture that was loaded
- See Also:
-
loadAudio
Description copied from interface:AssetManager
Load audio file, supported types are WAV or OGG.- Specified by:
loadAudio
in interfaceAssetManager
- Parameters:
key
- Asset key of the audio file to load- Returns:
- The audio data loaded
- See Also:
-
loadAudio
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 interfaceAssetManager
- Parameters:
name
- Asset name of the audio file to load- Returns:
- The audio data loaded
- See Also:
-
loadFont
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 interfaceAssetManager
- Parameters:
name
- Asset name of the font to load- Returns:
- The font loaded
- See Also:
-
loadModel
Description copied from interface:AssetManager
Loads a 3D model with a ModelKey. Models can be jME3 object files (J3O), OgreXML (mesh.xml), BLEND, FBX and OBJ files.- Specified by:
loadModel
in interfaceAssetManager
- Parameters:
key
- Asset key of the model to load- Returns:
- The model that was loaded
- See Also:
-
loadModel
Description copied from interface:AssetManager
Loads a 3D model. Models can be jME3 object files (J3O), OgreXML (mesh.xml), BLEND, FBX and OBJ files.- Specified by:
loadModel
in interfaceAssetManager
- Parameters:
name
- Asset name of the model to load- Returns:
- The model that was loaded
- See Also:
-
loadFilter
Description copied from interface:AssetManager
Loads a filter *.j3f file with a FilterKey.- Specified by:
loadFilter
in interfaceAssetManager
- Parameters:
key
- Asset key of the filter file to load- Returns:
- The filter that was loaded
- See Also:
-
loadFilter
Description copied from interface:AssetManager
Loads a filter *.j3f file with a FilterKey.- Specified by:
loadFilter
in interfaceAssetManager
- Parameters:
name
- Asset name of the filter file to load- Returns:
- The filter that was loaded
- See Also:
-
getShaderGenerator
Returns the shaderGenerator responsible for generating the shaders- Specified by:
getShaderGenerator
in interfaceAssetManager
- Parameters:
caps
- a set of required capabilities- Returns:
- the shaderGenerator
-
setShaderGenerator
Sets the shaderGenerator to generate shaders based on shaderNodes.- Specified by:
setShaderGenerator
in interfaceAssetManager
- Parameters:
shaderGenerator
- the shaderGenerator
-