/** * Resolves dependencies (using {@code #include } in the source code) * and delegates the combined source code to * {@link #createProgramFromSourceCode(java.lang.String) }. * Important: only absolute paths are allowed. * @param sourceCode the original source code * @param assetManager the asset manager to load the files * @return the created program object * @throws AssetNotFoundException if a dependency could not be loaded */ public Program createProgramFromSourceCodeWithDependencies(String sourceCode, AssetManager assetManager) { StringBuilder builder = new StringBuilder(sourceCode.length()); BufferedReader reader = new BufferedReader(new StringReader(sourceCode)); try { buildSourcesRec(reader, builder, assetManager); } catch (IOException ex) { throw new AssetNotFoundException("Unable to read a dependency file", ex); } return createProgramFromSourceCode(builder.toString()); } private void buildSourcesRec(BufferedReader reader, StringBuilder builder, AssetManager assetManager) throws IOException {
public AssetInfo locate(AssetManager manager, AssetKey key) { String name = key.getName(); File file = new File(root, name); if (file.exists() && file.isFile()){ try { // Now, check asset name requirements String canonical = file.getCanonicalPath(); String absolute = file.getAbsolutePath(); if (!canonical.endsWith(absolute)){ throw new AssetNotFoundException("Asset name doesn't match requirements.\n"+ "\"" + canonical + "\" doesn't match \"" + absolute + "\""); } } catch (IOException ex) { throw new AssetLoadException("Failed to get file canonical path " + file, ex); } return new AssetInfoFile(manager, key, file); }else{ return null; } }
private void buildSourcesRec(BufferedReader reader, StringBuilder builder, AssetManager assetManager) throws IOException { String ln; while ((ln = reader.readLine()) != null) { if (ln.trim().startsWith("#import ")) { ln = ln.trim().substring(8).trim(); if (ln.startsWith("\"")) { ln = ln.substring(1); } if (ln.endsWith("\"")) { ln = ln.substring(0, ln.length()-1); } AssetInfo info = assetManager.locateAsset(new AssetKey<String>(ln)); if (info == null) { throw new AssetNotFoundException("Unable to load source file \""+ln+"\""); } try (BufferedReader r = new BufferedReader(new InputStreamReader(info.openStream()))) { builder.append("//-- begin import ").append(ln).append(" --\n"); buildSourcesRec(r, builder, assetManager); builder.append("//-- end import ").append(ln).append(" --\n"); } } else { builder.append(ln).append('\n'); } } }
public InputStream getResourceAsStream(String path) { AssetKey<Object> key = new AssetKey<Object>(path); AssetInfo info = assetManager.locateAsset(key); if (info != null) { return info.openStream(); } else { throw new AssetNotFoundException(path); } }
AssetInfo info = assetManager.locateAsset(new AssetKey<String>(res)); if (info == null) { throw new AssetNotFoundException("Unable to load source file \""+res+"\"");
throw new AssetNotFoundException(sourceSettings.getSettingsDialogImage());
throw new AssetNotFoundException("Asset name doesn't match requirements.\n"+ "\"" + path + "\" doesn't match \"" + name + "\"");
entityNode.attachChild(ogreMesh); }catch(IOException e){ throw new AssetNotFoundException(meshKey.toString());
throw new AssetNotFoundException(key.toString());
/** * Resolves dependencies (using {@code #include } in the source code) * and delegates the combined source code to * {@link #createProgramFromSourceCode(java.lang.String) }. * Important: only absolute paths are allowed. * @param sourceCode the original source code * @param assetManager the asset manager to load the files * @return the created program object * @throws AssetNotFoundException if a dependency could not be loaded */ public Program createProgramFromSourceCodeWithDependencies(String sourceCode, AssetManager assetManager) { StringBuilder builder = new StringBuilder(sourceCode.length()); BufferedReader reader = new BufferedReader(new StringReader(sourceCode)); try { buildSourcesRec(reader, builder, assetManager); } catch (IOException ex) { throw new AssetNotFoundException("Unable to read a dependency file", ex); } return createProgramFromSourceCode(builder.toString()); } private void buildSourcesRec(BufferedReader reader, StringBuilder builder, AssetManager assetManager) throws IOException {
private void buildSourcesRec(BufferedReader reader, StringBuilder builder, AssetManager assetManager) throws IOException { String ln; while ((ln = reader.readLine()) != null) { if (ln.trim().startsWith("#import ")) { ln = ln.trim().substring(8).trim(); if (ln.startsWith("\"")) { ln = ln.substring(1); } if (ln.endsWith("\"")) { ln = ln.substring(0, ln.length()-1); } AssetInfo info = assetManager.locateAsset(new AssetKey<String>(ln)); if (info == null) { throw new AssetNotFoundException("Unable to load source file \""+ln+"\""); } try (BufferedReader r = new BufferedReader(new InputStreamReader(info.openStream()))) { builder.append("//-- begin import ").append(ln).append(" --\n"); buildSourcesRec(r, builder, assetManager); builder.append("//-- end import ").append(ln).append(" --\n"); } } else { builder.append(ln).append('\n'); } } }
public AssetInfo locate(AssetManager manager, AssetKey key) { String name = key.getName(); File file = new File(root, name); if (file.exists() && file.isFile()){ try { // Now, check asset name requirements String canonical = file.getCanonicalPath(); String absolute = file.getAbsolutePath(); if (!canonical.endsWith(absolute)){ throw new AssetNotFoundException("Asset name doesn't match requirements.\n"+ "\"" + canonical + "\" doesn't match \"" + absolute + "\""); } } catch (IOException ex) { throw new AssetLoadException("Failed to get file canonical path " + file, ex); } return new AssetInfoFile(manager, key, file); }else{ return null; } }
public AssetInfo locate(AssetManager manager, AssetKey key) { String name = key.getName(); File file = new File(root, name); if (file.exists() && file.isFile()){ try { // Now, check asset name requirements String canonical = file.getCanonicalPath(); String absolute = file.getAbsolutePath(); if (!canonical.endsWith(absolute)){ throw new AssetNotFoundException("Asset name doesn't match requirements.\n"+ "\"" + canonical + "\" doesn't match \"" + absolute + "\""); } } catch (IOException ex) { throw new AssetLoadException("Failed to get file canonical path " + file, ex); } return new AssetInfoFile(manager, key, file); }else{ return null; } }
protected void loadMtlLib(String name) throws IOException{ if (!name.toLowerCase().endsWith(".mtl")) throw new IOException("Expected .mtl file! Got: " + name); // NOTE: Cut off any relative/absolute paths name = new File(name).getName(); try { matList = (MaterialList) assetManager.loadAsset(key.getFolder() + name); } catch (AssetNotFoundException ex){ throw new AssetNotFoundException("Cannot find material " + name + " for model " + key.getName()); } if (matList != null){ // create face lists for every material for (String matName : matList.keySet()){ matFaces.put(matName, new ArrayList<Face>()); } }else{ logger.log(Level.WARNING, "Can't find MTL file. " + "Using default material for OBJ."); } }
AssetInfo info = assetManager.locateAsset(new AssetKey<String>(res)); if (info == null) { throw new AssetNotFoundException("Unable to load source file \""+res+"\"");
throw new AssetNotFoundException(sourceSettings.getSettingsDialogImage());
throw new AssetNotFoundException("Asset name doesn't match requirements.\n"+ "\"" + path + "\" doesn't match \"" + name + "\"");
throw new AssetNotFoundException("Asset name doesn't match requirements.\n"+ "\"" + path + "\" doesn't match \"" + name + "\"");
entityNode.attachChild(ogreMesh); }catch(IOException e){ throw new AssetNotFoundException(meshKey.toString());
throw new AssetNotFoundException(key.toString());