public void init() { AssetInfo info = assetManager.locateAsset(new AssetKey<Shader>(fileName)); if (info != null && info instanceof UrlAssetInfo) { try { Field f = info.getClass().getDeclaredField("url"); f.setAccessible(true); URL url = (URL) f.get(info); file = new File(url.getFile()); fileLastM = file.lastModified(); } catch (NoSuchFieldException ex) { Logger.getLogger(MaterialDebugAppState.class.getName()).log(Level.SEVERE, null, ex); } catch (SecurityException ex) { Logger.getLogger(MaterialDebugAppState.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalArgumentException ex) { Logger.getLogger(MaterialDebugAppState.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { Logger.getLogger(MaterialDebugAppState.class.getName()).log(Level.SEVERE, null, ex); } } }
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); } }
str.append(include); for (String res : resources) { AssetInfo info = assetManager.locateAsset(new AssetKey<String>(res)); if (info == null) { throw new AssetNotFoundException("Unable to load source file \""+res+"\"");
AssetInfo a = am.locateAsset(new AssetKey<Object>("Interface/Fonts/Default.fnt")); AssetInfo b = am.locateAsset(new ModelKey("casaamarela.jpg")); AssetInfo c = am.locateAsset(new ModelKey("glasstile2.png")); AssetInfo d = am.locateAsset(new TextureKey("beginner-physics.png"));
try { try{ Spatial ogreMesh=(Spatial)meshLoader.load(assetManager.locateAsset(meshKey)); entityNode.attachChild(ogreMesh); }catch(IOException e){
key.setFlipY(true); key.setGenerateMips(generateMipmaps); AssetInfo info = assetManager.locateAsset(key); if (info != null) { Texture texture = assetManager.loadTexture(key);
private static void drawImage(AssetManager assetManager, Graphics2D g, int width, int height, String image) { if (image != null) { try { // TODO: cache the images BufferedImage img = ImageIO.read(assetManager.locateAsset(new AssetKey(image)).openStream()); g.drawImage(img, (width - img.getWidth()) / 2, (height - img.getHeight()) / 2, null); } catch (Exception ex) { logger.log(Level.SEVERE, "Can't load the texture " + image + "!", ex); } } }
public void init() { AssetInfo info = assetManager.locateAsset(new AssetKey<Shader>(fileName)); if (info != null && info instanceof UrlAssetInfo) { try { Field f = info.getClass().getDeclaredField("url"); f.setAccessible(true); URL url = (URL) f.get(info); file = new File(url.getFile()); fileLastM = file.lastModified(); } catch (NoSuchFieldException ex) { Logger.getLogger(MaterialDebugAppState.class.getName()).log(Level.SEVERE, null, ex); } catch (SecurityException ex) { Logger.getLogger(MaterialDebugAppState.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalArgumentException ex) { Logger.getLogger(MaterialDebugAppState.class.getName()).log(Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { Logger.getLogger(MaterialDebugAppState.class.getName()).log(Level.SEVERE, null, ex); } } }
@Override protected Texture getLoadingScreenTexture() { // Load up the texture, there are few localized ones available TextureKey texKey = new TextureKey("Textures/TitleScreen/Titlescreen-" + Locale.getDefault().getDisplayLanguage(Locale.ENGLISH) + ".png"); if (assetManager.locateAsset(texKey) == null) { texKey = new TextureKey("Textures/TitleScreen/Titlescreen.png"); } return assetManager.loadTexture(texKey); } }
public static InputStream loadFile(String filepath, AssetManager assetManager) { return assetManager.locateAsset(new AssetKey(filepath)).openStream(); }
public static InputStream loadFile(String filepath, AssetManager assetManager) { return assetManager.locateAsset(new AssetKey(filepath)).openStream(); }
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'); } } }
str.append(include); for (String res : resources) { AssetInfo info = assetManager.locateAsset(new AssetKey<String>(res)); if (info == null) { throw new AssetNotFoundException("Unable to load source file \""+res+"\"");
@Override public void read(JmeImporter e) throws IOException { super.read(e); InputCapsule capsule = e.getCapsule(this); BinaryImporter importer = BinaryImporter.getInstance(); AssetManager loaderManager = e.getAssetManager(); assetLoaderKeys = (ArrayList<ModelKey>) capsule.readSavableArrayList("assetLoaderKeyList", new ArrayList<ModelKey>()); for (Iterator<ModelKey> it = assetLoaderKeys.iterator(); it.hasNext();) { ModelKey modelKey = it.next(); AssetInfo info = loaderManager.locateAsset(modelKey); Spatial child = null; if (info != null) { child = (Spatial) importer.load(info); } if (child != null) { child.parent = this; children.add(child); assetChildren.put(modelKey, child); } else { Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Could not load linked child spatial: {0}", modelKey.getName()); } } }
private Texture createTexture() throws IOException { String name = "ktorch"; //float[] scales = {1f, 1f, 1f, 1f}; //float[] offsets = new float[4]; //RescaleOp rop = new RescaleOp(scales, offsets, null); // Get the first frame, the frames need to be same size BufferedImage img = ImageIO.read(assetManager.locateAsset(new AssetKey(ConversionUtils.getCanonicalAssetKey("Textures/" + name + "0.png"))).openStream()); // Create image big enough to fit all the frames BufferedImage text = new BufferedImage(img.getWidth() * frames, img.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g = text.createGraphics(); g.drawImage(makeColorTransparent(img), 0, 0, null); for (int x = 1; x < frames; x++) { AssetInfo asset = assetManager.locateAsset(new AssetKey(ConversionUtils.getCanonicalAssetKey("Textures/" + name + x + ".png"))); img = ImageIO.read(asset.openStream()); g.drawImage(makeColorTransparent(img), img.getWidth() * x, 0, null); } g.dispose(); // Convert the new image to a texture AWTLoader loader = new AWTLoader(); Texture result = new Texture2D(loader.load(text, false)); return result; }
private static void assignMapToMaterial(AssetManager assetManager, Material material, String paramName, String textureName) { // Try to locate the texture Boolean found = textureMapCache.get(textureName); if (found == null) { TextureKey textureKey = new TextureKey(textureName, false); // See if it exists AssetInfo assetInfo = assetManager.locateAsset(textureKey); found = (assetInfo != null); textureMapCache.put(textureName, found); } // Set it if (found) { TextureKey textureKey = new TextureKey(textureName, false); material.setTexture(paramName, assetManager.loadTexture(textureKey)); } else { material.clearParam(paramName); } }
/** * See if the map thumbnail exist, otherwise create one TODO maybe move to * KwdFile class ??? * * @param map * @return path to map thumbnail file */ protected String getMapThumbnail(KwdFile map) { // See if the map thumbnail exist, otherwise create one String asset = AssetsConverter.MAP_THUMBNAILS_FOLDER + File.separator + ConversionUtils.stripFileName(map.getGameLevel().getName()) + ".png"; if (assetManager.locateAsset(new TextureKey(asset)) == null) { // Generate try { AssetsConverter.genererateMapThumbnail(map, AssetsConverter.getAssetsFolder() + AssetsConverter.MAP_THUMBNAILS_FOLDER + File.separator); } catch (Exception e) { LOGGER.log(java.util.logging.Level.WARNING, "Failed to generate map file out of {0}!", map); asset = "Textures/Unique_NoTextureName.png"; } } return asset; }
try { try{ Spatial ogreMesh=(Spatial)meshLoader.load(assetManager.locateAsset(meshKey)); entityNode.attachChild(ogreMesh); }catch(IOException e){
BufferedImage img = ImageIO.read(assetManager.locateAsset(new AssetKey(ConversionUtils.getCanonicalAssetKey(assetFolder + resource.getName() + "0.png"))).openStream()); g.drawImage(img, rop, 0, 0); for (int x = 1; x < frames; x++) { AssetInfo asset = assetManager.locateAsset(new AssetKey(ConversionUtils.getCanonicalAssetKey(assetFolder + resource.getName() + x + ".png"))); if (asset != null) { img = ImageIO.read(asset.openStream());