Search in sources :

Example 41 with TextureKey

use of com.jme3.asset.TextureKey in project jmonkeyengine by jMonkeyEngine.

the class MaterialLoader method readTextureImage.

private void readTextureImage(String content) {
    // texture image def
    String path = null;
    // find extension
    int extStart = content.lastIndexOf(".");
    for (int i = extStart; i < content.length(); i++) {
        char c = content.charAt(i);
        if (Character.isWhitespace(c)) {
            // extension ends here
            path = content.substring(0, i).trim();
            content = content.substring(i + 1).trim();
            break;
        }
    }
    if (path == null) {
        path = content.trim();
        content = "";
    }
    Scanner lnScan = new Scanner(content);
    String mips = null;
    String type = null;
    if (lnScan.hasNext()) {
        // more params
        type = lnScan.next();
    //            if (!lnScan.hasNext("\n") && lnScan.hasNext()){
    //                mips = lnScan.next();
    //                if (lnScan.hasNext()){
    // even more params..
    // will have to ignore
    //                }
    //            }
    }
    boolean genMips = true;
    boolean cubic = false;
    if (type != null && type.equals("0"))
        genMips = false;
    if (type != null && type.equals("cubic")) {
        cubic = true;
    }
    TextureKey texKey = new TextureKey(folderName + path, false);
    texKey.setGenerateMips(genMips);
    if (cubic) {
        texKey.setTextureTypeHint(Texture.Type.CubeMap);
    }
    try {
        Texture loadedTexture = assetManager.loadTexture(texKey);
        textures[texUnit].setImage(loadedTexture.getImage());
        textures[texUnit].setMinFilter(loadedTexture.getMinFilter());
        textures[texUnit].setMagFilter(loadedTexture.getMagFilter());
        textures[texUnit].setAnisotropicFilter(loadedTexture.getAnisotropicFilter());
        textures[texUnit].setKey(loadedTexture.getKey());
        // XXX: Is this really neccessary?
        textures[texUnit].setWrap(WrapMode.Repeat);
        if (texName != null) {
            textures[texUnit].setName(texName);
            texName = null;
        } else {
            textures[texUnit].setName(texKey.getName());
        }
    } catch (AssetNotFoundException ex) {
        logger.log(Level.WARNING, "Cannot locate {0} for material {1}", new Object[] { texKey, matName });
        textures[texUnit].setImage(PlaceholderAssets.getPlaceholderImage(assetManager));
        textures[texUnit].setKey(texKey);
    }
}
Also used : Scanner(java.util.Scanner) Texture(com.jme3.texture.Texture)

Aggregations

TextureKey (com.jme3.asset.TextureKey)37 Texture (com.jme3.texture.Texture)26 Material (com.jme3.material.Material)16 Image (com.jme3.texture.Image)9 InputStream (java.io.InputStream)9 Geometry (com.jme3.scene.Geometry)7 Vector3f (com.jme3.math.Vector3f)6 Texture2D (com.jme3.texture.Texture2D)6 MatParamTexture (com.jme3.material.MatParamTexture)4 AssetLoadException (com.jme3.asset.AssetLoadException)3 AssetNotFoundException (com.jme3.asset.AssetNotFoundException)3 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)3 DirectionalLight (com.jme3.light.DirectionalLight)3 ByteBuffer (java.nio.ByteBuffer)3 AssetManager (com.jme3.asset.AssetManager)2 Vector2f (com.jme3.math.Vector2f)2 FilterPostProcessor (com.jme3.post.FilterPostProcessor)2 Spatial (com.jme3.scene.Spatial)2 Box (com.jme3.scene.shape.Box)2 Quad (com.jme3.scene.shape.Quad)2