com.jme3.asset.AssetInfo Java Examples
The following examples show how to use
com.jme3.asset.AssetInfo.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PMDLoaderGLSLSkinning2.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private Object load3(AssetInfo ai) throws IOException { this.assetManager = ai.getManager(); folderName = ai.getKey().getFolder(); InputStream is = ai.openStream(); meshConverter = PMDFileUtil.readPMDCache1(is); is.close(); model = meshConverter.getModel(); PMDNode pmdNode = createNode(ai.getKey().getName()); // if (JmeSystem.getFullName().indexOf("Android") == -1) { // try { // String vendor = GL11.glGetString(GL11.GL_VENDOR); // if (vendor != null && vendor.toLowerCase().contains("intel")) { // pmdNode.setGlslSkinning(false); // } else { // pmdNode.setGlslSkinning(true); // } // } catch(Exception ex) { // pmdNode.setGlslSkinning(false); // } // } return pmdNode; }
Example #2
Source File: AWTLoader.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override 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"); } }
Example #3
Source File: FileLocator.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
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; } }
Example #4
Source File: WAVLoader.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public Object load(AssetInfo info) throws IOException { AudioData data; InputStream inputStream = null; try { inputStream = info.openStream(); data = load(inputStream, ((AudioKey)info.getKey()).isStream()); if (data instanceof AudioStream){ inputStream = null; } return data; } finally { if (inputStream != null){ inputStream.close(); } } }
Example #5
Source File: AssetLinkNode.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
@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()); } } }
Example #6
Source File: GLSLLoader.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
/** * * @param owner * @param in * @param extension * @param key * @return * @throws java.io.IOException */ public Object load(AssetInfo info) throws IOException { // The input stream provided is for the vertex shader, // to retrieve the fragment shader, use the content manager this.owner = info.getManager(); if (info.getKey().getExtension().equals("glsllib")){ // NOTE: Loopback, GLSLLIB is loaded by this loader // and needs data as InputStream return info.openStream(); }else{ // GLSLLoader wants result as String for // fragment shader DependencyNode rootNode = loadNode(info.openStream(), "[main]"); String code = resolveDependencies(rootNode); dependCache.clear(); return code; } }
Example #7
Source File: J3MLoader.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public Object load(AssetInfo info) throws IOException { this.owner = info.getManager(); InputStream in = info.openStream(); try { key = info.getKey(); loadFromRoot(BlockLanguageParser.parse(in)); } finally { if (in != null){ in.close(); } } if (material != null){ if (!(info.getKey() instanceof MaterialKey)){ throw new IOException("Material instances must be loaded via MaterialKey"); } // material implementation return material; }else{ // material definition return materialDef; } }
Example #8
Source File: NativeVorbisLoader.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
private static AudioBuffer loadBuffer(AssetInfo assetInfo) throws IOException { AndroidAssetInfo aai = (AndroidAssetInfo) assetInfo; AssetFileDescriptor afd = null; NativeVorbisFile file = null; try { afd = aai.openFileDescriptor(); int fd = afd.getParcelFileDescriptor().getFd(); file = new NativeVorbisFile(fd, afd.getStartOffset(), afd.getLength()); ByteBuffer data = BufferUtils.createByteBuffer(file.totalBytes); file.readFully(data); AudioBuffer ab = new AudioBuffer(); ab.setupFormat(file.channels, 16, file.sampleRate); ab.updateData(data); return ab; } finally { if (file != null) { file.close(); } if (afd != null) { afd.close(); } } }
Example #9
Source File: HttpZipLocator.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public AssetInfo locate(AssetManager manager, AssetKey key){ final ZipEntry2 entry = entries.get(key.getName()); if (entry == null) return null; return new AssetInfo(manager, key){ @Override public InputStream openStream() { try { return HttpZipLocator.this.openStream(entry); } catch (IOException ex) { logger.log(Level.WARNING, "Error retrieving "+entry.name, ex); return null; } } }; }
Example #10
Source File: DDSLoader.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public Object load(AssetInfo info) throws IOException { if (!(info.getKey() instanceof TextureKey)) { throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey"); } InputStream stream = null; try { stream = info.openStream(); in = new LittleEndien(stream); loadHeader(); if (texture3D) { ((TextureKey) info.getKey()).setTextureTypeHint(Type.ThreeDimensional); } else if (depth > 1) { ((TextureKey) info.getKey()).setTextureTypeHint(Type.CubeMap); } ArrayList<ByteBuffer> data = readData(((TextureKey) info.getKey()).isFlipY()); return new Image(pixelFormat, width, height, depth, data, sizes); } finally { if (stream != null){ stream.close(); } } }
Example #11
Source File: TGALoader.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public Object load(AssetInfo info) throws IOException{ if (!(info.getKey() instanceof TextureKey)) throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey"); boolean flip = ((TextureKey)info.getKey()).isFlipY(); InputStream in = null; try { in = info.openStream(); Image img = load(in, flip); return img; } finally { if (in != null){ in.close(); } } }
Example #12
Source File: OGGLoader.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public Object load(AssetInfo info) throws IOException { if (!(info.getKey() instanceof AudioKey)){ throw new IllegalArgumentException("Audio assets must be loaded using an AudioKey"); } AudioKey key = (AudioKey) info.getKey(); boolean readStream = key.isStream(); boolean streamCache = key.useStreamCache(); InputStream in = null; try { in = info.openStream(); AudioData data = load(in, readStream, streamCache); if (readStream && !streamCache) { // we still need the stream in this case .. in = null; } return data; } finally { if (in != null){ in.close(); } } }
Example #13
Source File: AndroidLocator.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
@SuppressWarnings("rawtypes") @Override public AssetInfo locate(com.jme3.asset.AssetManager manager, AssetKey key) { InputStream in = null; String sAssetPath = rootPath + key.getName(); // Fix path issues if (sAssetPath.startsWith("/")) { // Remove leading / sAssetPath = sAssetPath.substring(1); } sAssetPath = sAssetPath.replace("//", "/"); try { in = androidManager.open(sAssetPath); if (in == null) return null; return new AndroidAssetInfo(manager, key, sAssetPath); } catch (IOException ex) { //logger.log(Level.WARNING, "Failed to locate {0} ", sAssetPath); } return null; }
Example #14
Source File: AndroidTGALoader.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public Object load(AssetInfo info) throws IOException{ if (!(info.getKey() instanceof TextureKey)) throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey"); boolean flip = ((TextureKey)info.getKey()).isFlipY(); InputStream in = null; try { in = info.openStream(); Image img = load(in, flip); return img; } finally { if (in != null){ in.close(); } } }
Example #15
Source File: ContentTextureLocator.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@SuppressWarnings("rawtypes") @Override public AssetInfo locate(AssetManager manager, AssetKey key) { if(key instanceof ContentTextureKey) { String name = key.getName(); byte[] content = ((ContentTextureKey) key).getContent(); if(content != null) { return new ContentAssetInfo(manager, key, content); } else { logger.log(Level.WARNING, "No content for " + name); return null; } } else { logger.log(Level.SEVERE, "AssetKey should be TextureContentKey instance"); return null; } }
Example #16
Source File: FolderAssetLocator.java From jmonkeybuilder with Apache License 2.0 | 6 votes |
@Override @JmeThread public AssetInfo locate(@NotNull final AssetManager manager, @NotNull final AssetKey key) { if (IGNORE_LOCAL.get() == Boolean.TRUE) { return null; } final Path absoluteFile = Paths.get(key.getName()); if (Files.exists(absoluteFile)) { return null; } final EditorConfig editorConfig = EditorConfig.getInstance(); final Path currentAsset = editorConfig.getCurrentAsset(); if (currentAsset == null) { return null; } final String name = key.getName(); final Path resolve = currentAsset.resolve(name); if (!Files.exists(resolve)) { return null; } return new PathAssetInfo(manager, key, resolve); }
Example #17
Source File: Context.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
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'); } } }
Example #18
Source File: Context.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Creates a program object from the provided source code and files. * The source code is made up from the specified include string first, * then all files specified by the resource array (array of asset paths) * are loaded by the provided asset manager and appended to the source code. * <p> * The typical use case is: * <ul> * <li>The include string contains some compiler constants like the grid size </li> * <li>Some common OpenCL files used as libraries (Convention: file names end with {@code .clh}</li> * <li>One main OpenCL file containing the actual kernels (Convention: file name ends with {@code .cl})</li> * </ul> * * After the files were combined, additional include statements are resolved * by {@link #createProgramFromSourceCodeWithDependencies(java.lang.String, com.jme3.asset.AssetManager) }. * * @param assetManager the asset manager used to load the files * @param include an additional include string * @param resources an array of asset paths pointing to OpenCL source files * @return the new program objects * @throws AssetNotFoundException if a file could not be loaded */ public Program createProgramFromSourceFilesWithInclude(AssetManager assetManager, String include, List<String> resources) { StringBuilder str = new StringBuilder(); 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 + "\""); } try (BufferedReader reader = new BufferedReader(new InputStreamReader(info.openStream()))) { while (true) { String line = reader.readLine(); if (line == null) { break; } str.append(line).append('\n'); } } catch (IOException ex) { LOG.log(Level.WARNING, "unable to load source file '" + res + "'", ex); } } return createProgramFromSourceCodeWithDependencies(str.toString(), assetManager); }
Example #19
Source File: PMDLoaderGLSLSkinning2.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
private Object load2(AssetInfo ai) throws IOException { this.assetManager = ai.getManager(); model = new PMDModel(ai.openStream()); folderName = ai.getKey().getFolder(); meshConverter = new MeshConverter(model); meshConverter.convertMesh(); // PMNData pmdData = meshConverter.createPMNData(); // model.setVertexList(null); model.setFaceVertIndex(null); PMDNode pmdNode = createNode(ai.getKey().getName()); // if (JmeSystem.getFullName().indexOf("Android") == -1) { // try { // String vendor = GL11.glGetString(GL11.GL_VENDOR); // if (vendor != null && vendor.toLowerCase().contains("intel")) { // pmdNode.setGlslSkinning(false); // } else { // pmdNode.setGlslSkinning(true); // } // } catch(Exception ex) { // pmdNode.setGlslSkinning(false); // } // } return pmdNode; }
Example #20
Source File: PMDLoaderGLSLSkinning2.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
@Override public Object load(AssetInfo ai) throws IOException { boolean errFlag = false; for(;;) { try { PMDLoaderGLSLSkinning2 loader = new PMDLoaderGLSLSkinning2(); Object result; if (ai.getKey().getName().toLowerCase().endsWith(".pmd")) { result = loader.load2(ai); } else { result = loader.load3(ai); } return result; }catch(OutOfMemoryError ex) { if (errFlag) { throw ex; } errFlag = true; // if (ai.getManager() instanceof DesktopAssetManager) { // ((DesktopAssetManager)ai.getManager()).clearCache(); // } System.gc(); System.runFinalization(); } } }
Example #21
Source File: DDSLoader.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public Object load(AssetInfo info) throws IOException { if (!(info.getKey() instanceof TextureKey)) { throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey"); } InputStream stream = null; try { stream = info.openStream(); in = new LittleEndien(stream); loadHeader(); if (texture3D) { ((TextureKey) info.getKey()).setTextureTypeHint(Texture.Type.ThreeDimensional); } else if (depth > 1) { ((TextureKey) info.getKey()).setTextureTypeHint(Texture.Type.CubeMap); } ArrayList<ByteBuffer> data = readData(((TextureKey) info.getKey()).isFlipY()); return new Image(pixelFormat, width, height, depth, data, sizes, ColorSpace.sRGB); } finally { if (stream != null){ stream.close(); } } }
Example #22
Source File: PFMLoader.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public Object load(AssetInfo info) throws IOException { if (!(info.getKey() instanceof TextureKey)) throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey"); InputStream in = null; try { in = info.openStream(); return load(in, ((TextureKey)info.getKey()).isFlipY()); } finally { if (in != null){ in.close(); } } }
Example #23
Source File: TGALoader.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public Object load(AssetInfo info) throws IOException { if (!(info.getKey() instanceof TextureKey)) { throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey"); } boolean flip = ((TextureKey) info.getKey()).isFlipY(); InputStream in = null; try { in = info.openStream(); Image img = load(in, flip); return img; } finally { if (in != null) { in.close(); } } }
Example #24
Source File: HDRLoader.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public Object load(AssetInfo info) throws IOException { if (!(info.getKey() instanceof TextureKey)) throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey"); boolean flip = ((TextureKey) info.getKey()).isFlipY(); InputStream in = null; try { in = info.openStream(); Image img = load(in, flip); return img; } finally { if (in != null){ in.close(); } } }
Example #25
Source File: KTXLoader.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public Object load(AssetInfo info) throws IOException { if (!(info.getKey() instanceof TextureKey)) { throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey"); } InputStream in = null; try { in = info.openStream(); Image img = load(in); return img; } finally { if (in != null) { in.close(); } } }
Example #26
Source File: OGGLoader.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public Object load(AssetInfo info) throws IOException { if (!(info.getKey() instanceof AudioKey)){ throw new IllegalArgumentException("Audio assets must be loaded using an AudioKey"); } AudioKey key = (AudioKey) info.getKey(); boolean readStream = key.isStream(); boolean streamCache = key.useStreamCache(); InputStream in = null; try { in = info.openStream(); AudioData data = load(in, readStream, streamCache); if (data instanceof AudioStream){ // audio streams must remain open in = null; } return data; } finally { if (in != null){ in.close(); } } }
Example #27
Source File: WAVLoader.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public Object load(AssetInfo info) throws IOException { AudioData data; InputStream inputStream = null; try { inputStream = info.openStream(); data = load(info, inputStream, ((AudioKey)info.getKey()).isStream()); if (data instanceof AudioStream){ inputStream = null; } return data; } finally { if (inputStream != null){ inputStream.close(); } } }
Example #28
Source File: HttpZipLocator.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public AssetInfo locate(AssetManager manager, AssetKey key){ final ZipEntry2 entry = entries.get(key.getName()); if (entry == null) return null; return new AssetInfo(manager, key){ @Override public InputStream openStream() { try { return HttpZipLocator.this.openStream(entry); } catch (IOException ex) { logger.log(Level.WARNING, "Error retrieving "+entry.name, ex); return null; } } }; }
Example #29
Source File: UrlLocator.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public AssetInfo locate(AssetManager manager, AssetKey key) { String name = key.getName(); try{ //TODO: remove workaround for SDK // URL url = new URL(root, name); if(name.startsWith("/")){ name = name.substring(1); } URL url = new URL(root.toExternalForm() + name); return UrlAssetInfo.create(manager, key, url); }catch (FileNotFoundException e){ return null; }catch (IOException ex){ logger.log(Level.WARNING, "Error while locating " + name, ex); return null; } }
Example #30
Source File: GdxTGALoader.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
public Object load(AssetInfo info) throws IOException{ if (!(info.getKey() instanceof TextureKey)) throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey"); boolean flip = ((TextureKey)info.getKey()).isFlipY(); InputStream in = null; try { in = info.openStream(); Image img = load(in, flip); return img; } finally { if (in != null){ in.close(); } } }