Search in sources :

Example 31 with Image

use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.

the class FbxImage method toJmeObject.

@Override
protected Object toJmeObject() {
    Image image = null;
    String fileName = null;
    String relativeFilePathJme;
    if (filePath != null) {
        fileName = getFileName(filePath);
    } else if (relativeFilePath != null) {
        fileName = getFileName(relativeFilePath);
    }
    if (fileName != null) {
        try {
            // Try to load filename relative to FBX folder
            key = new TextureKey(sceneFolderName + fileName);
            key.setGenerateMips(true);
            image = loadImageSafe(assetManager, key);
            // Try to load relative filepath relative to FBX folder
            if (image == null && relativeFilePath != null) {
                // Convert Windows paths to jME3 paths
                relativeFilePathJme = relativeFilePath.replace('\\', '/');
                key = new TextureKey(sceneFolderName + relativeFilePathJme);
                key.setGenerateMips(true);
                image = loadImageSafe(assetManager, key);
            }
            // Try to load embedded image
            if (image == null && content != null && content.length > 0) {
                key = new TextureKey(fileName);
                key.setGenerateMips(true);
                InputStream is = new ByteArrayInputStream(content);
                image = assetManager.loadAssetFromStream(key, is).getImage();
                // NOTE: embedded texture doesn't exist in the asset manager,
                //       so the texture key must not be saved.
                key = null;
            }
        } catch (AssetLoadException ex) {
            logger.log(Level.WARNING, "Error while attempting to load texture {0}:\n{1}", new Object[] { name, ex.toString() });
        }
    }
    if (image == null) {
        logger.log(Level.WARNING, "Cannot locate {0} for texture {1}", new Object[] { fileName, name });
        image = PlaceholderAssets.getPlaceholderImage(assetManager);
    }
    return image;
}
Also used : TextureKey(com.jme3.asset.TextureKey) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FbxObject(com.jme3.scene.plugins.fbx.obj.FbxObject) Image(com.jme3.texture.Image) AssetLoadException(com.jme3.asset.AssetLoadException)

Example 32 with Image

use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.

the class FbxTexture method toJmeObject.

@Override
protected Texture toJmeObject() {
    Image image = null;
    TextureKey key = null;
    if (media != null) {
        image = (Image) media.getJmeObject();
        key = media.getTextureKey();
    }
    if (image == null) {
        image = PlaceholderAssets.getPlaceholderImage(assetManager);
    }
    Texture2D tex = new Texture2D(image);
    if (key != null) {
        tex.setKey(key);
        tex.setName(key.getName());
        tex.setAnisotropicFilter(key.getAnisotropy());
    }
    tex.setMinFilter(MinFilter.Trilinear);
    tex.setMagFilter(MagFilter.Bilinear);
    if (wrapModeU == 0) {
        tex.setWrap(WrapAxis.S, WrapMode.Repeat);
    }
    if (wrapModeV == 0) {
        tex.setWrap(WrapAxis.T, WrapMode.Repeat);
    }
    return tex;
}
Also used : TextureKey(com.jme3.asset.TextureKey) Texture2D(com.jme3.texture.Texture2D) Image(com.jme3.texture.Image)

Example 33 with Image

use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.

the class HDRLoader method load.

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();
        }
    }
}
Also used : TextureKey(com.jme3.asset.TextureKey) InputStream(java.io.InputStream) Image(com.jme3.texture.Image)

Example 34 with Image

use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.

the class PFMLoader method load.

private Image load(InputStream in, boolean needYFlip) throws IOException {
    Format format = null;
    String fmtStr = readString(in);
    if (fmtStr.equals("PF")) {
        format = Format.RGB32F;
    } else if (fmtStr.equals("Pf")) {
        format = Format.Luminance32F;
    } else {
        throw new IOException("File is not PFM format");
    }
    String sizeStr = readString(in);
    int spaceIdx = sizeStr.indexOf(" ");
    if (spaceIdx <= 0 || spaceIdx >= sizeStr.length() - 1)
        throw new IOException("Invalid size syntax in PFM file");
    int width = Integer.parseInt(sizeStr.substring(0, spaceIdx));
    int height = Integer.parseInt(sizeStr.substring(spaceIdx + 1));
    if (width <= 0 || height <= 0)
        throw new IOException("Invalid size specified in PFM file");
    String scaleStr = readString(in);
    float scale = Float.parseFloat(scaleStr);
    ByteOrder order = scale < 0 ? ByteOrder.LITTLE_ENDIAN : ByteOrder.BIG_ENDIAN;
    boolean needEndienFlip = order != ByteOrder.nativeOrder();
    // make sure all unneccessary stuff gets deleted from heap
    // before allocating large amount of memory
    System.gc();
    int bytesPerPixel = format.getBitsPerPixel() / 8;
    int scanLineBytes = bytesPerPixel * width;
    ByteBuffer imageData = BufferUtils.createByteBuffer(width * height * bytesPerPixel);
    byte[] scanline = new byte[width * bytesPerPixel];
    for (int y = height - 1; y >= 0; y--) {
        if (!needYFlip)
            imageData.position(scanLineBytes * y);
        int read = 0;
        int off = 0;
        do {
            read = in.read(scanline, off, scanline.length - off);
            off += read;
        } while (read > 0);
        if (needEndienFlip) {
            flipScanline(scanline);
        }
        imageData.put(scanline);
    }
    imageData.rewind();
    return new Image(format, width, height, imageData, null, ColorSpace.Linear);
}
Also used : Format(com.jme3.texture.Image.Format) IOException(java.io.IOException) ByteOrder(java.nio.ByteOrder) Image(com.jme3.texture.Image) ByteBuffer(java.nio.ByteBuffer)

Example 35 with Image

use of com.jme3.texture.Image in project jmonkeyengine by jMonkeyEngine.

the class KTXLoader method createImage.

/**
     * Create an image with given parameters
     * @param nbSlices
     * @param byteBuffersSize
     * @param imgFormat
     * @param pixelWidth
     * @param pixelHeight
     * @param depth
     * @return 
     */
private Image createImage(int nbSlices, int byteBuffersSize, Image.Format imgFormat, int pixelWidth, int pixelHeight, int depth) {
    ArrayList<ByteBuffer> imageData = new ArrayList<ByteBuffer>(nbSlices);
    for (int i = 0; i < nbSlices; i++) {
        imageData.add(BufferUtils.createByteBuffer(byteBuffersSize));
    }
    Image image = new Image(imgFormat, pixelWidth, pixelHeight, depth, imageData, ColorSpace.sRGB);
    return image;
}
Also used : ArrayList(java.util.ArrayList) Image(com.jme3.texture.Image) ByteBuffer(java.nio.ByteBuffer)

Aggregations

Image (com.jme3.texture.Image)68 ByteBuffer (java.nio.ByteBuffer)38 Texture (com.jme3.texture.Texture)27 Texture2D (com.jme3.texture.Texture2D)19 ArrayList (java.util.ArrayList)19 Material (com.jme3.material.Material)18 TextureKey (com.jme3.asset.TextureKey)17 Vector3f (com.jme3.math.Vector3f)17 Format (com.jme3.texture.Image.Format)15 TextureCubeMap (com.jme3.texture.TextureCubeMap)14 ColorRGBA (com.jme3.math.ColorRGBA)13 PixelInputOutput (com.jme3.scene.plugins.blender.textures.io.PixelInputOutput)12 BufferedImage (java.awt.image.BufferedImage)12 Geometry (com.jme3.scene.Geometry)10 InputStream (java.io.InputStream)10 IOException (java.io.IOException)8 TerrainLodControl (com.jme3.terrain.geomipmap.TerrainLodControl)7 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)7 DistanceLodCalculator (com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator)7 AbstractHeightMap (com.jme3.terrain.heightmap.AbstractHeightMap)7