159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/* 259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Copyright (c) 2009-2010 jMonkeyEngine 359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * All rights reserved. 459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Redistribution and use in source and binary forms, with or without 659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * modification, are permitted provided that the following conditions are 759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * met: 859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Redistributions of source code must retain the above copyright 1059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * notice, this list of conditions and the following disclaimer. 1159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 1259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Redistributions in binary form must reproduce the above copyright 1359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * notice, this list of conditions and the following disclaimer in the 1459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * documentation and/or other materials provided with the distribution. 1559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 1659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * * Neither the name of 'jMonkeyEngine' nor the names of its contributors 1759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * may be used to endorse or promote products derived from this software 1859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * without specific prior written permission. 1959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 2059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 2259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 2359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 2459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 2559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 2659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 2759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 2859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 2959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 3059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 3259b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapackage com.jme3.asset; 3359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 3459b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.asset.plugins.AndroidLocator; 3559b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.asset.plugins.ClasspathLocator; 3659b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.audio.plugins.AndroidAudioLoader; 3759b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.texture.Texture; 3859b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport com.jme3.texture.plugins.AndroidImageLoader; 3959b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport java.net.URL; 40a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Bartaimport java.util.logging.Level; 4159b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartaimport java.util.logging.Logger; 4259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 4359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta/** 4459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * <code>AndroidAssetManager</code> is an implementation of DesktopAssetManager for Android 4559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 4659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @author larynx 4759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 4859b2e6871c65f58fdad78cd7229c292f6a177578Scott Bartapublic class AndroidAssetManager extends DesktopAssetManager { 4959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 5059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta private static final Logger logger = Logger.getLogger(AndroidAssetManager.class.getName()); 5159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 5259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public AndroidAssetManager() { 5359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta this(null); 5459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 5559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 5659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta @Deprecated 5759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public AndroidAssetManager(boolean loadDefaults) { 5859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta //this(Thread.currentThread().getContextClassLoader().getResource("com/jme3/asset/Android.cfg")); 5959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta this(null); 6059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 61a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta 62a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta private void registerLoaderSafe(Class<? extends AssetLoader> loaderClass, String ... extensions) { 63a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta try { 64a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta registerLoader(loaderClass, extensions); 65a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta } catch (Exception e){ 66a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta logger.log(Level.WARNING, "Failed to load AssetLoader", e); 67a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta } 68a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta } 6959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 7059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 7159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * AndroidAssetManager constructor 7259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * If URL == null then a default list of locators and loaders for android is set 7359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @param configFile 7459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 7559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public AndroidAssetManager(URL configFile) { 7659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta System.setProperty("org.xml.sax.driver", "org.xmlpull.v1.sax2.Driver"); 7759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 7859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta // Set Default Android config 79a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta registerLocator("", AndroidLocator.class); 80a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta registerLocator("", ClasspathLocator.class); 81a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta 82a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta registerLoader(AndroidImageLoader.class, "jpg", "bmp", "gif", "png", "jpeg"); 83a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta registerLoader(AndroidAudioLoader.class, "ogg", "mp3", "wav"); 84a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta registerLoader(com.jme3.material.plugins.J3MLoader.class, "j3m"); 85a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta registerLoader(com.jme3.material.plugins.J3MLoader.class, "j3md"); 86a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta registerLoader(com.jme3.shader.plugins.GLSLLoader.class, "vert", "frag", "glsl", "glsllib"); 87a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta registerLoader(com.jme3.export.binary.BinaryImporter.class, "j3o"); 88a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta registerLoader(com.jme3.font.plugins.BitmapFontLoader.class, "fnt"); 89a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta 90a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta // Less common loaders (especially on Android) 91a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta registerLoaderSafe(com.jme3.texture.plugins.DDSLoader.class, "dds"); 92a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta registerLoaderSafe(com.jme3.texture.plugins.PFMLoader.class, "pfm"); 93a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta registerLoaderSafe(com.jme3.texture.plugins.HDRLoader.class, "hdr"); 94a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta registerLoaderSafe(com.jme3.texture.plugins.TGALoader.class, "tga"); 95a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta registerLoaderSafe(com.jme3.scene.plugins.OBJLoader.class, "obj"); 96a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta registerLoaderSafe(com.jme3.scene.plugins.MTLLoader.class, "mtl"); 97a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta registerLoaderSafe(com.jme3.scene.plugins.ogre.MeshLoader.class, "mesh.xml"); 98a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta registerLoaderSafe(com.jme3.scene.plugins.ogre.SkeletonLoader.class, "skeleton.xml"); 99a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta registerLoaderSafe(com.jme3.scene.plugins.ogre.MaterialLoader.class, "material"); 100a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta registerLoaderSafe(com.jme3.scene.plugins.ogre.SceneLoader.class, "scene"); 101a6b44658eb1c55295f132a36233a11aa2bd8f9cfScott Barta 10259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 10359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta logger.info("AndroidAssetManager created."); 10459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 10559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 10659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta /** 10759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * Loads a texture. 10859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * 10959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta * @return 11059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta */ 11159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta @Override 11259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta public Texture loadTexture(TextureKey key) { 11359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta Texture tex = (Texture) loadAsset(key); 11459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta 11559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta // XXX: This will improve performance on some really 11659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta // low end GPUs (e.g. ones with OpenGL ES 1 support only) 11759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta // but otherwise won't help on the higher ones. 11859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta // Strongly consider removing this. 11959b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta tex.setMagFilter(Texture.MagFilter.Nearest); 12059b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta tex.setAnisotropicFilter(0); 12159b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta if (tex.getMinFilter().usesMipMapLevels()) { 12259b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta tex.setMinFilter(Texture.MinFilter.NearestNearestMipMap); 12359b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } else { 12459b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta tex.setMinFilter(Texture.MinFilter.NearestNoMipMaps); 12559b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 12659b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta return tex; 12759b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta } 12859b2e6871c65f58fdad78cd7229c292f6a177578Scott Barta} 129