use of com.jme3.asset.AssetNotFoundException in project jmonkeyengine by jMonkeyEngine.
the class AbstractBlenderHelper method loadLibrary.
/**
* The method loads library of a given ID from linked blender file.
* @param id
* the ID of the linked feature (it contains its name and blender path)
* @return loaded feature or null if none was found
* @throws BlenderFileException
* and exception is throw when problems with reading a blend file occur
*/
protected Object loadLibrary(Structure id) throws BlenderFileException {
Pointer pLib = (Pointer) id.getFieldValue("lib");
if (pLib.isNotNull()) {
// we need full name with the prefix
String fullName = id.getFieldValue("name").toString();
String nameOfFeatureToLoad = id.getName();
Structure library = pLib.fetchData().get(0);
String path = library.getFieldValue("filepath").toString();
if (!blenderContext.getLinkedFeatures().keySet().contains(path)) {
Spatial loadedAsset = null;
BlenderKey blenderKey = new BlenderKey(path);
blenderKey.setLoadUnlinkedAssets(true);
try {
loadedAsset = blenderContext.getAssetManager().loadAsset(blenderKey);
} catch (AssetNotFoundException e) {
LOGGER.log(Level.FINEST, "Cannot locate linked resource at path: {0}.", path);
}
if (loadedAsset != null) {
Map<String, Map<String, Object>> linkedData = loadedAsset.getUserData("linkedData");
for (Entry<String, Map<String, Object>> entry : linkedData.entrySet()) {
String linkedDataFilePath = "this".equals(entry.getKey()) ? path : entry.getKey();
blenderContext.getLinkedFeatures().put(linkedDataFilePath, entry.getValue());
}
} else {
LOGGER.log(Level.WARNING, "No features loaded from path: {0}.", path);
}
}
Object result = blenderContext.getLinkedFeature(path, fullName);
if (result == null) {
LOGGER.log(Level.WARNING, "Could NOT find asset named {0} in the library of path: {1}.", new Object[] { nameOfFeatureToLoad, path });
} else {
blenderContext.addLoadedFeatures(id.getOldMemoryAddress(), LoadedDataType.STRUCTURE, id);
blenderContext.addLoadedFeatures(id.getOldMemoryAddress(), LoadedDataType.FEATURE, result);
}
return result;
} else {
LOGGER.warning("Library link points to nothing!");
}
return null;
}
use of com.jme3.asset.AssetNotFoundException in project jmonkeyengine by jMonkeyEngine.
the class J3MLoader method parseTextureType.
private Texture parseTextureType(final VarType type, final String value) {
final List<String> textureValues = tokenizeTextureValue(value);
final List<TextureOptionValue> textureOptionValues = parseTextureOptions(textureValues);
TextureKey textureKey = null;
// If there is only one token on the value, it must be the path to the texture.
if (textureValues.size() == 1) {
textureKey = new TextureKey(textureValues.get(0), false);
} else {
String texturePath = value.trim();
// If there are no valid "new" texture options specified but the path is split into several parts, lets parse the old way.
if (isTexturePathDeclaredTheTraditionalWay(textureOptionValues, texturePath)) {
boolean flipY = false;
if (texturePath.startsWith("Flip Repeat ") || texturePath.startsWith("Repeat Flip ")) {
texturePath = texturePath.substring(12).trim();
flipY = true;
} else if (texturePath.startsWith("Flip ")) {
texturePath = texturePath.substring(5).trim();
flipY = true;
} else if (texturePath.startsWith("Repeat ")) {
texturePath = texturePath.substring(7).trim();
}
// Support path starting with quotes (double and single)
if (texturePath.startsWith("\"") || texturePath.startsWith("'")) {
texturePath = texturePath.substring(1);
}
// Support path ending with quotes (double and single)
if (texturePath.endsWith("\"") || texturePath.endsWith("'")) {
texturePath = texturePath.substring(0, texturePath.length() - 1);
}
textureKey = new TextureKey(texturePath, flipY);
}
if (textureKey == null) {
textureKey = new TextureKey(textureValues.get(textureValues.size() - 1), false);
}
// Apply texture options to the texture key
if (!textureOptionValues.isEmpty()) {
for (final TextureOptionValue textureOptionValue : textureOptionValues) {
textureOptionValue.applyToTextureKey(textureKey);
}
}
}
switch(type) {
case Texture3D:
textureKey.setTextureTypeHint(Texture.Type.ThreeDimensional);
break;
case TextureArray:
textureKey.setTextureTypeHint(Texture.Type.TwoDimensionalArray);
break;
case TextureCubeMap:
textureKey.setTextureTypeHint(Texture.Type.CubeMap);
break;
}
textureKey.setGenerateMips(true);
Texture texture;
try {
texture = assetManager.loadTexture(textureKey);
} catch (AssetNotFoundException ex) {
logger.log(Level.WARNING, "Cannot locate {0} for material {1}", new Object[] { textureKey, key });
texture = null;
}
if (texture == null) {
texture = new Texture2D(PlaceholderAssets.getPlaceholderImage(assetManager));
texture.setKey(textureKey);
texture.setName(textureKey.getName());
}
// Apply texture options to the texture
if (!textureOptionValues.isEmpty()) {
for (final TextureOptionValue textureOptionValue : textureOptionValues) {
textureOptionValue.applyToTexture(texture);
}
}
return texture;
}
use of com.jme3.asset.AssetNotFoundException in project jmonkeyengine by jMonkeyEngine.
the class MTLLoader method loadTexture.
protected Texture loadTexture(String path) {
String[] split = path.trim().split("\\p{javaWhitespace}+");
// will crash if path is an empty string
path = split[split.length - 1];
String name = new File(path).getName();
TextureKey texKey = new TextureKey(folderName + name);
texKey.setGenerateMips(true);
Texture texture;
try {
texture = assetManager.loadTexture(texKey);
texture.setWrap(WrapMode.Repeat);
} catch (AssetNotFoundException ex) {
logger.log(Level.WARNING, "Cannot locate {0} for material {1}", new Object[] { texKey, key });
texture = new Texture2D(PlaceholderAssets.getPlaceholderImage(assetManager));
texture.setWrap(WrapMode.Repeat);
texture.setKey(key);
}
return texture;
}
use of com.jme3.asset.AssetNotFoundException in project jmonkeyengine by jMonkeyEngine.
the class ShaderNodeLoaderDelegate method findDefinition.
/**
* find the definition from this statement (loads it if necessary)
*
* @param statement the statement being read
* @return the definition
* @throws IOException
*/
public ShaderNodeDefinition findDefinition(Statement statement) throws IOException {
String[] defLine = statement.getLine().split(":");
String defName = defLine[1].trim();
ShaderNodeDefinition def = getNodeDefinitions().get(defName);
if (def == null) {
if (defLine.length == 3) {
List<ShaderNodeDefinition> defs = null;
try {
defs = assetManager.loadAsset(new ShaderNodeDefinitionKey(defLine[2].trim()));
} catch (AssetNotFoundException e) {
throw new MatParseException("Couldn't find " + defLine[2].trim(), statement, e);
}
for (ShaderNodeDefinition definition : defs) {
definition.setPath(defLine[2].trim());
if (defName.equals(definition.getName())) {
def = definition;
}
if (!(getNodeDefinitions().containsKey(definition.getName()))) {
getNodeDefinitions().put(definition.getName(), definition);
}
}
}
if (def == null) {
throw new MatParseException(defName + " is not a declared as Shader Node Definition", statement);
}
}
return def;
}
use of com.jme3.asset.AssetNotFoundException in project jmonkeyengine by jMonkeyEngine.
the class DesktopAssetManager method loadAsset.
@Override
public <T> T loadAsset(AssetKey<T> key) {
if (key == null)
throw new IllegalArgumentException("key cannot be null");
for (AssetEventListener listener : eventListeners) {
listener.assetRequested(key);
}
AssetCache cache = handler.getCache(key.getCacheType());
AssetProcessor proc = handler.getProcessor(key.getProcessorType());
Object obj = cache != null ? cache.getFromCache(key) : null;
if (obj == null) {
// Asset not in cache, load it from file system.
AssetInfo info = handler.tryLocate(key);
if (info == null) {
if (handler.getParentKey() != null) {
// that something went wrong.
for (AssetEventListener listener : eventListeners) {
listener.assetDependencyNotFound(handler.getParentKey(), key);
}
}
throw new AssetNotFoundException(key.toString());
}
obj = loadLocatedAsset(key, info, proc, cache);
}
T clone = (T) obj;
if (obj instanceof CloneableSmartAsset) {
clone = registerAndCloneSmartAsset(key, clone, proc, cache);
}
return clone;
}
Aggregations