use of com.jme3.asset.AssetLoadException in project jmonkeyengine by jMonkeyEngine.
the class AWTLoader method load.
public Object load(AssetInfo info) throws IOException {
if (ImageIO.getImageReadersBySuffix(info.getKey().getExtension()) != null) {
boolean flip = ((TextureKey) info.getKey()).isFlipY();
InputStream in = null;
try {
in = info.openStream();
Image img = load(in, flip);
if (img == null) {
throw new AssetLoadException("The given image cannot be loaded " + info.getKey());
}
return img;
} finally {
if (in != null) {
in.close();
}
}
} else {
throw new AssetLoadException("The extension " + info.getKey().getExtension() + " is not supported");
}
}
use of com.jme3.asset.AssetLoadException in project jmonkeyengine by jMonkeyEngine.
the class GLSLLoader method loadNode.
/**
* Creates a {@link ShaderDependencyNode} from a stream representing shader code.
*
* @param in The input stream containing shader code
* @param nodeName
* @return
* @throws IOException
*/
private ShaderDependencyNode loadNode(Reader reader, String nodeName) {
ShaderDependencyNode node = new ShaderDependencyNode(nodeName);
StringBuilder sb = new StringBuilder();
StringBuilder sbExt = new StringBuilder();
BufferedReader bufReader = null;
try {
bufReader = new BufferedReader(reader);
String ln;
if (!nodeName.equals("[main]")) {
sb.append("// -- begin import ").append(nodeName).append(" --\n");
}
while ((ln = bufReader.readLine()) != null) {
if (ln.trim().startsWith("#import ")) {
ln = ln.trim().substring(8).trim();
if (ln.startsWith("\"") && ln.endsWith("\"") && ln.length() > 3) {
// import user code
// remove quotes to get filename
ln = ln.substring(1, ln.length() - 1);
if (ln.equals(nodeName)) {
throw new IOException("Node depends on itself.");
}
// check cache first
ShaderDependencyNode dependNode = dependCache.get(ln);
if (dependNode == null) {
Reader dependNodeReader = assetManager.loadAsset(new ShaderDependencyKey(ln));
dependNode = loadNode(dependNodeReader, ln);
}
node.addDependency(sb.length(), dependNode);
}
} else if (ln.trim().startsWith("#extension ")) {
sbExt.append(ln).append('\n');
} else {
sb.append(ln).append('\n');
}
}
if (!nodeName.equals("[main]")) {
sb.append("// -- end import ").append(nodeName).append(" --\n");
}
} catch (IOException ex) {
if (bufReader != null) {
try {
bufReader.close();
} catch (IOException ex1) {
}
}
throw new AssetLoadException("Failed to load shader node: " + nodeName, ex);
}
node.setSource(sb.toString());
node.setExtensions(sbExt.toString());
dependCache.put(nodeName, node);
return node;
}
use of com.jme3.asset.AssetLoadException in project jmonkeyengine by jMonkeyEngine.
the class UrlAssetInfo method openStream.
@Override
public InputStream openStream() {
if (in != null) {
// Reuse the already existing stream (only once)
InputStream in2 = in;
in = null;
return in2;
} else {
// Create a new stream for subsequent invocations.
try {
URLConnection conn = url.openConnection();
conn.setUseCaches(false);
return conn.getInputStream();
} catch (IOException ex) {
throw new AssetLoadException("Failed to read URL " + url, ex);
}
}
}
use of com.jme3.asset.AssetLoadException in project jmonkeyengine by jMonkeyEngine.
the class J3MLoader method loadFromRoot.
private void loadFromRoot(List<Statement> roots) throws IOException {
if (roots.size() == 2) {
Statement exception = roots.get(0);
String line = exception.getLine();
if (line.startsWith("Exception")) {
throw new AssetLoadException(line.substring("Exception ".length()));
} else {
throw new IOException("In multiroot material, expected first statement to be 'Exception'");
}
} else if (roots.size() != 1) {
throw new IOException("Too many roots in J3M/J3MD file");
}
boolean extending = false;
Statement materialStat = roots.get(0);
String materialName = materialStat.getLine();
if (materialName.startsWith("MaterialDef")) {
materialName = materialName.substring("MaterialDef ".length()).trim();
extending = false;
} else if (materialName.startsWith("Material")) {
materialName = materialName.substring("Material ".length()).trim();
extending = true;
} else {
throw new IOException("Specified file is not a Material file");
}
String[] split = materialName.split(":", 2);
if (materialName.equals("")) {
throw new MatParseException("Material name cannot be empty", materialStat);
}
if (split.length == 2) {
if (!extending) {
throw new MatParseException("Must use 'Material' when extending.", materialStat);
}
String extendedMat = split[1].trim();
MaterialDef def = (MaterialDef) assetManager.loadAsset(new AssetKey(extendedMat));
if (def == null) {
throw new MatParseException("Extended material " + extendedMat + " cannot be found.", materialStat);
}
material = new Material(def);
material.setKey(key);
material.setName(split[0].trim());
// material.setAssetName(fileName);
} else if (split.length == 1) {
if (extending) {
throw new MatParseException("Expected ':', got '{'", materialStat);
}
materialDef = new MaterialDef(assetManager, materialName);
// NOTE: pass file name for defs so they can be loaded later
materialDef.setAssetName(key.getName());
} else {
throw new MatParseException("Cannot use colon in material name/path", materialStat);
}
for (Statement statement : materialStat.getContents()) {
split = statement.getLine().split("[ \\{]");
String statType = split[0];
if (extending) {
if (statType.equals("MaterialParameters")) {
readExtendingMaterialParams(statement.getContents());
} else if (statType.equals("AdditionalRenderState")) {
readAdditionalRenderState(statement.getContents());
} else if (statType.equals("Transparent")) {
readTransparentStatement(statement.getLine());
}
} else {
if (statType.equals("Technique")) {
readTechnique(statement);
} else if (statType.equals("MaterialParameters")) {
readMaterialParams(statement.getContents());
} else {
throw new MatParseException("Expected material statement, got '" + statType + "'", statement);
}
}
}
}
use of com.jme3.asset.AssetLoadException in project jmonkeyengine by jMonkeyEngine.
the class FbxLoader method load.
@Override
public Object load(AssetInfo assetInfo) throws IOException {
this.assetManager = assetInfo.getManager();
AssetKey<?> assetKey = assetInfo.getKey();
if (!(assetKey instanceof ModelKey)) {
throw new AssetLoadException("Invalid asset key");
}
InputStream stream = assetInfo.openStream();
try {
sceneFilename = assetKey.getName();
sceneFolderName = assetKey.getFolder();
String ext = assetKey.getExtension();
sceneName = sceneFilename.substring(0, sceneFilename.length() - ext.length() - 1);
if (sceneFolderName != null && sceneFolderName.length() > 0) {
sceneName = sceneName.substring(sceneFolderName.length());
}
reset();
// Load the data from the stream.
loadData(stream);
// Bind poses are needed to compute world transforms.
applyBindPoses();
// Need world transforms for skeleton creation.
updateWorldTransforms();
// Need skeletons for meshs to be created in scene graph construction.
// Mesh bone indices require skeletons to determine bone index.
constructSkeletons();
// Create the jME3 scene graph from the FBX scene graph.
// Also creates SkeletonControls based on the constructed skeletons.
Spatial scene = constructSceneGraph();
// Load animations into AnimControls
constructAnimations();
return scene;
} finally {
releaseObjects();
if (stream != null) {
stream.close();
}
}
}
Aggregations