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
ConstructorsConstructorDescriptionDesktopAssetManager(boolean usePlatformConfig) DesktopAssetManager(URL configFile) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAssetEventListener(AssetEventListener listener) Add anAssetEventListenerto receive events from thisAssetManager.voidaddClassLoader(ClassLoader loader) Deprecated.<T> voidaddToCache(AssetKey<T> key, T asset) Inject an asset into the asset cache.voidRemoves all asset event listeners.voidClears the asset cache.<T> booleandeleteFromCache(AssetKey<T> key) Delete an asset from the asset cache.Deprecated.<T> TgetFromCache(AssetKey<T> key) Retrieve an asset from the asset cache.getShaderGenerator(EnumSet<Caps> caps) Returns the shaderGenerator responsible for generating the shaders<T> TLoad an asset from a key, the asset will be located by one of theAssetLocatorimplementations 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> TloadAssetFromStream(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> TloadLocatedAsset(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> TregisterAndCloneSmartAsset(AssetKey<T> key, T obj, AssetProcessor proc, AssetCache cache) Clones the asset using the given processor and registers the clone with the cache.voidregisterLoader(Class<? extends AssetLoader> loader, String... extensions) Register anAssetLoaderby using a class object.voidregisterLoader(String clsName, String... extensions) voidregisterLocator(String rootPath, Class<? extends AssetLocator> locatorClass) Registers the given locator class for locating assets with thisAssetManager.voidregisterLocator(String rootPath, String clsName) voidremoveAssetEventListener(AssetEventListener listener) Remove anAssetEventListenerfrom receiving events from thisAssetManagervoidremoveClassLoader(ClassLoader loader) Deprecated.voidsetAssetEventListener(AssetEventListener listener) voidsetShaderGenerator(ShaderGenerator shaderGenerator) Sets the shaderGenerator to generate shaders based on shaderNodes.voidunregisterLoader(Class<? extends AssetLoader> loaderClass) Unregister aAssetLoaderfrom loading its assigned extensions.voidunregisterLocator(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:AssetManagerAdds aClassLoaderthat is used to loadclassesthat are needed for finding and loading Assets. This does not allow loading assets from that classpath, use registerLocator for that.- Specified by:
addClassLoaderin interfaceAssetManager- Parameters:
loader- A ClassLoader that Classes in asset files can be loaded from.
-
removeClassLoader
Deprecated.Description copied from interface:AssetManagerRemove aClassLoaderfrom the list of registered ClassLoaders- Specified by:
removeClassLoaderin interfaceAssetManager- Parameters:
loader- the ClassLoader to be removed
-
getClassLoaders
Deprecated.Description copied from interface:AssetManagerRetrieve the list of registered ClassLoaders that are used for loadingclassesfrom asset files.- Specified by:
getClassLoadersin interfaceAssetManager- Returns:
- an unmodifiable list
-
addAssetEventListener
Description copied from interface:AssetManagerAdd anAssetEventListenerto receive events from thisAssetManager.- Specified by:
addAssetEventListenerin interfaceAssetManager- Parameters:
listener- The asset event listener to add
-
removeAssetEventListener
Description copied from interface:AssetManagerRemove anAssetEventListenerfrom receiving events from thisAssetManager- Specified by:
removeAssetEventListenerin interfaceAssetManager- Parameters:
listener- The asset event listener to remove
-
clearAssetEventListeners
public void clearAssetEventListeners()Description copied from interface:AssetManagerRemoves all asset event listeners.- Specified by:
clearAssetEventListenersin interfaceAssetManager- See Also:
-
setAssetEventListener
-
registerLoader
Description copied from interface:AssetManagerRegister anAssetLoaderby using a class object.- Specified by:
registerLoaderin 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:AssetManagerUnregister aAssetLoaderfrom loading its assigned extensions. This undoes the effect of callingAssetManager.registerLoader(java.lang.Class, java.lang.String[]).- Specified by:
unregisterLoaderin interfaceAssetManager- Parameters:
loaderClass- The loader class to unregister.- See Also:
-
registerLocator
Description copied from interface:AssetManagerRegisters the given locator class for locating assets with thisAssetManager.AssetLocators are invoked in the order they were registered, to locate the asset by theAssetKey. Once anAssetLocatorreturns a non-null AssetInfo, it is sent to theAssetLoaderto load the asset. Once a locator is registered, it can be removed viaAssetManager.unregisterLocator(java.lang.String, java.lang.Class).- Specified by:
registerLocatorin 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 theAssetLocatorto register.- See Also:
-
registerLocator
-
unregisterLocator
Description copied from interface:AssetManagerUnregisters the given locator class. This essentially undoes the operation done byAssetManager.registerLocator(java.lang.String, java.lang.Class).- Specified by:
unregisterLocatorin 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:AssetManagerManually 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 theAssetLocatorthat are registered with thisAssetManager, in the same way that theAssetManager.loadAsset(com.jme3.asset.AssetKey)method locates assets.- Specified by:
locateAssetin interfaceAssetManager- Parameters:
key- TheAssetKeyto locate.- Returns:
- The
AssetInfoobject returned from theAssetLocatorthat located the asset, or null if the asset cannot be located.
-
getFromCache
Description copied from interface:AssetManagerRetrieve 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:
getFromCachein 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:AssetManagerInject 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:
addToCachein 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:AssetManagerDelete an asset from the asset cache.- Specified by:
deleteFromCachein 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:AssetManagerClears the asset cache.- Specified by:
clearCachein 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:AssetManagerLoad 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:
loadAssetFromStreamin 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:AssetManagerLoad an asset from a key, the asset will be located by one of theAssetLocatorimplementations provided in theAssetManager.registerLocator(java.lang.String, java.lang.Class)call. If located successfully, it will be loaded via the appropriateAssetLoaderimplementation based on the file's extension, as specified in the callAssetManager.registerLoader(java.lang.Class, java.lang.String[]).- Specified by:
loadAssetin 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:AssetManagerLoad an asset by name, calling this method is the same as callingloadAsset(new AssetKey(name)).- Specified by:
loadAssetin 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:AssetManagerLoads texture file, supported types are BMP, JPG, PNG, GIF, TGA, DDS, PFM, and HDR.- Specified by:
loadTexturein interfaceAssetManager- Parameters:
key- TheTextureKeyto use for loading.- Returns:
- The loaded texture, or null if failed to be loaded.
- See Also:
-
loadMaterial
Description copied from interface:AssetManagerLoad a material instance (J3M) file.- Specified by:
loadMaterialin interfaceAssetManager- Parameters:
name- Asset name of the material to load- Returns:
- The material that was loaded
- See Also:
-
loadTexture
Description copied from interface:AssetManagerLoads 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:
loadTexturein interfaceAssetManager- Parameters:
name- The name of the texture to load.- Returns:
- The texture that was loaded
- See Also:
-
loadAudio
Description copied from interface:AssetManagerLoad audio file, supported types are WAV or OGG.- Specified by:
loadAudioin interfaceAssetManager- Parameters:
key- Asset key of the audio file to load- Returns:
- The audio data loaded
- See Also:
-
loadAudio
Description copied from interface:AssetManagerLoad audio file, supported types are WAV or OGG. The file is loaded without stream-mode.- Specified by:
loadAudioin interfaceAssetManager- Parameters:
name- Asset name of the audio file to load- Returns:
- The audio data loaded
- See Also:
-
loadFont
Description copied from interface:AssetManagerLoad a font file. Font files are in AngelCode text format, and are with the extension "fnt".- Specified by:
loadFontin interfaceAssetManager- Parameters:
name- Asset name of the font to load- Returns:
- The font loaded
- See Also:
-
loadModel
Description copied from interface:AssetManagerLoads a 3D model with a ModelKey. Models can be jME3 object files (J3O), OgreXML (mesh.xml), BLEND, FBX and OBJ files.- Specified by:
loadModelin interfaceAssetManager- Parameters:
key- Asset key of the model to load- Returns:
- The model that was loaded
- See Also:
-
loadModel
Description copied from interface:AssetManagerLoads a 3D model. Models can be jME3 object files (J3O), OgreXML (mesh.xml), BLEND, FBX and OBJ files.- Specified by:
loadModelin interfaceAssetManager- Parameters:
name- Asset name of the model to load- Returns:
- The model that was loaded
- See Also:
-
loadFilter
Description copied from interface:AssetManagerLoads a filter *.j3f file with a FilterKey.- Specified by:
loadFilterin interfaceAssetManager- Parameters:
key- Asset key of the filter file to load- Returns:
- The filter that was loaded
- See Also:
-
loadFilter
Description copied from interface:AssetManagerLoads a filter *.j3f file with a FilterKey.- Specified by:
loadFilterin 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:
getShaderGeneratorin interfaceAssetManager- Parameters:
caps- a set of required capabilities- Returns:
- the shaderGenerator
-
setShaderGenerator
Sets the shaderGenerator to generate shaders based on shaderNodes.- Specified by:
setShaderGeneratorin interfaceAssetManager- Parameters:
shaderGenerator- the shaderGenerator
-