Search in sources :

Example 21 with TextureKey

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

the class SkyFactory method createSky.

/**
    * Create a sky using the given cubemap or spheremap texture.
    *
    * @param assetManager from which to load materials
    * @param textureName the path to the texture asset to use    
    * @param envMapType see {@link EnvMapType}
    * @return a new spatial representing the sky, ready to be attached to the
    * scene graph    
    */
public static Spatial createSky(AssetManager assetManager, String textureName, EnvMapType envMapType) {
    TextureKey key = new TextureKey(textureName, true);
    key.setGenerateMips(false);
    if (envMapType == EnvMapType.CubeMap) {
        key.setTextureTypeHint(Texture.Type.CubeMap);
    }
    Texture tex = assetManager.loadTexture(key);
    return createSky(assetManager, tex, envMapType);
}
Also used : TextureKey(com.jme3.asset.TextureKey) Texture(com.jme3.texture.Texture)

Example 22 with TextureKey

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

the class MTLLoader method loadTexture.

protected Texture loadTexture(String path) {
    String[] split = path.trim().split("\\p{javaWhitespace}+");
    // will crash if path is an empty string
    path = split[split.length - 1];
    String name = new File(path).getName();
    TextureKey texKey = new TextureKey(folderName + name);
    texKey.setGenerateMips(true);
    Texture texture;
    try {
        texture = assetManager.loadTexture(texKey);
        texture.setWrap(WrapMode.Repeat);
    } catch (AssetNotFoundException ex) {
        logger.log(Level.WARNING, "Cannot locate {0} for material {1}", new Object[] { texKey, key });
        texture = new Texture2D(PlaceholderAssets.getPlaceholderImage(assetManager));
        texture.setWrap(WrapMode.Repeat);
        texture.setKey(key);
    }
    return texture;
}
Also used : Texture2D(com.jme3.texture.Texture2D) File(java.io.File) Texture(com.jme3.texture.Texture)

Example 23 with TextureKey

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

the class TestTexture3DLoading method simpleInitApp.

@Override
public void simpleInitApp() {
    viewPort.setBackgroundColor(ColorRGBA.DarkGray);
    flyCam.setEnabled(false);
    Quad q = new Quad(10, 10);
    Geometry geom = new Geometry("Quad", q);
    Material material = new Material(assetManager, "jme3test/texture/tex3DThumb.j3md");
    TextureKey key = new TextureKey("Textures/3D/flame.dds");
    key.setGenerateMips(true);
    key.setTextureTypeHint(Texture.Type.ThreeDimensional);
    Texture t = assetManager.loadTexture(key);
    //4 * 4
    int rows = 4;
    q.scaleTextureCoordinates(new Vector2f(rows, rows));
    //The image only have 8 pictures and we have 16 thumbs, the data will be interpolated by the GPU
    material.setFloat("InvDepth", 1f / 16f);
    material.setInt("Rows", rows);
    material.setTexture("Texture", t);
    geom.setMaterial(material);
    rootNode.attachChild(geom);
    cam.setLocation(new Vector3f(4.7444625f, 5.160054f, 13.1939f));
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad) TextureKey(com.jme3.asset.TextureKey) Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) Material(com.jme3.material.Material) Texture(com.jme3.texture.Texture)

Example 24 with TextureKey

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

the class IosImageLoader method load.

public Object load(AssetInfo info) throws IOException {
    boolean flip = ((TextureKey) info.getKey()).isFlipY();
    Image img = null;
    InputStream in = null;
    try {
        in = info.openStream();
        img = loadImageData(Format.RGBA8, flip, in);
    } finally {
        if (in != null) {
            in.close();
        }
    }
    return img;
}
Also used : TextureKey(com.jme3.asset.TextureKey) InputStream(java.io.InputStream) Image(com.jme3.texture.Image)

Example 25 with TextureKey

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

the class MatParam method getValueAsString.

/**
     * Returns the material parameter value as it would appear in a J3M
     * file. E.g.<br/>
     * <code>
     * MaterialParameters {<br/>
     *     ABC : 1 2 3 4<br/>
     * }<br/>
     * </code>
     * Assuming "ABC" is a Vector4 parameter, then the value
     * "1 2 3 4" would be returned by this method.
     * <br/><br/>
     * @return material parameter value as it would appear in a J3M file.
     */
public String getValueAsString() {
    switch(type) {
        case Boolean:
        case Float:
        case Int:
            return value.toString();
        case Vector2:
            Vector2f v2 = (Vector2f) value;
            return v2.getX() + " " + v2.getY();
        /* 
This may get used at a later point of time
When arrays can be inserted in J3M files

            case Vector2Array:
                Vector2f[] v2Arr = (Vector2f[]) value;
                String v2str = "";
                for (int i = 0; i < v2Arr.length ; i++) {
                    v2str += v2Arr[i].getX() + " " + v2Arr[i].getY() + "\n";
                }
                return v2str;
*/
        case Vector3:
            Vector3f v3 = (Vector3f) value;
            return v3.getX() + " " + v3.getY() + " " + v3.getZ();
        /*
            case Vector3Array:
                Vector3f[] v3Arr = (Vector3f[]) value;
                String v3str = "";
                for (int i = 0; i < v3Arr.length ; i++) {
                    v3str += v3Arr[i].getX() + " "
                            + v3Arr[i].getY() + " "
                            + v3Arr[i].getZ() + "\n";
                }
                return v3str;
            case Vector4Array:
                // can be either ColorRGBA, Vector4f or Quaternion
                if (value instanceof Vector4f) {
                    Vector4f[] v4arr = (Vector4f[]) value;
                    String v4str = "";
                    for (int i = 0; i < v4arr.length ; i++) {
                        v4str += v4arr[i].getX() + " "
                                + v4arr[i].getY() + " "
                                + v4arr[i].getZ() + " "
                                + v4arr[i].getW() + "\n";
                    }
                    return v4str;
                } else if (value instanceof ColorRGBA) {
                    ColorRGBA[] colorArr = (ColorRGBA[]) value;
                    String colStr = "";
                    for (int i = 0; i < colorArr.length ; i++) {
                        colStr += colorArr[i].getRed() + " "
                                + colorArr[i].getGreen() + " "
                                + colorArr[i].getBlue() + " "
                                + colorArr[i].getAlpha() + "\n";
                    }
                    return colStr;
                } else if (value instanceof Quaternion) {
                    Quaternion[] quatArr = (Quaternion[]) value;
                    String quatStr = "";
                    for (int i = 0; i < quatArr.length ; i++) {
                        quatStr += quatArr[i].getX() + " "
                                + quatArr[i].getY() + " "
                                + quatArr[i].getZ() + " "
                                + quatArr[i].getW() + "\n";
                    }
                    return quatStr;
                } else {
                    throw new UnsupportedOperationException("Unexpected Vector4Array type: " + value);
                }
*/
        case Vector4:
            // can be either ColorRGBA, Vector4f or Quaternion
            if (value instanceof Vector4f) {
                Vector4f v4 = (Vector4f) value;
                return v4.getX() + " " + v4.getY() + " " + v4.getZ() + " " + v4.getW();
            } else if (value instanceof ColorRGBA) {
                ColorRGBA color = (ColorRGBA) value;
                return color.getRed() + " " + color.getGreen() + " " + color.getBlue() + " " + color.getAlpha();
            } else if (value instanceof Quaternion) {
                Quaternion quat = (Quaternion) value;
                return quat.getX() + " " + quat.getY() + " " + quat.getZ() + " " + quat.getW();
            } else {
                throw new UnsupportedOperationException("Unexpected Vector4 type: " + value);
            }
        case Texture2D:
        case Texture3D:
        case TextureArray:
        case TextureBuffer:
        case TextureCubeMap:
            Texture texVal = (Texture) value;
            TextureKey texKey = (TextureKey) texVal.getKey();
            if (texKey == null) {
                // often does as well, even implicitly. 
                return texVal + ":returned null key";
            }
            String ret = "";
            if (texKey.isFlipY()) {
                ret += "Flip ";
            }
            //Wrap mode
            ret += getWrapMode(texVal, Texture.WrapAxis.S);
            ret += getWrapMode(texVal, Texture.WrapAxis.T);
            ret += getWrapMode(texVal, Texture.WrapAxis.R);
            //Min and Mag filter
            Texture.MinFilter def = Texture.MinFilter.BilinearNoMipMaps;
            if (texVal.getImage().hasMipmaps() || texKey.isGenerateMips()) {
                def = Texture.MinFilter.Trilinear;
            }
            if (texVal.getMinFilter() != def) {
                ret += "Min" + texVal.getMinFilter().name() + " ";
            }
            if (texVal.getMagFilter() != Texture.MagFilter.Bilinear) {
                ret += "Mag" + texVal.getMagFilter().name() + " ";
            }
            return ret + "\"" + texKey.getName() + "\"";
        default:
            // parameter type not supported in J3M
            return null;
    }
}
Also used : TextureKey(com.jme3.asset.TextureKey) 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