Search in sources :

Example 6 with Texture2D

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

the class JmeBatchRenderBackend method loadImage.

@Override
public Image loadImage(final String filename) {
    TextureKey key = new TextureKey(filename, false);
    key.setAnisotropy(0);
    key.setGenerateMips(false);
    Texture2D texture = (Texture2D) display.getAssetManager().loadTexture(key);
    return new ImageImpl(texture.getImage());
}
Also used : TextureKey(com.jme3.asset.TextureKey) Texture2D(com.jme3.texture.Texture2D)

Example 7 with Texture2D

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

the class JmeBatchRenderBackend method createNonAtlasTexture.

@Override
public int createNonAtlasTexture(final Image image) {
    ImageImpl imageImpl = (ImageImpl) image;
    Texture2D texture = new Texture2D(imageImpl.image);
    texture.setMinFilter(MinFilter.NearestNoMipMaps);
    texture.setMagFilter(MagFilter.Nearest);
    return addTexture(texture);
}
Also used : Texture2D(com.jme3.texture.Texture2D)

Example 8 with Texture2D

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

the class JmeBatchRenderBackend method modifyTexture.

private void modifyTexture(final Texture2D textureAtlas, final com.jme3.texture.Image image, final int x, final int y) {
    Renderer renderer = display.getRenderer();
    if (renderer == null) {
        // we have no renderer (yet) so we'll need to cache this call to the next beginFrame() call
        modifyTextureCalls.add(new ModifyTexture(textureAtlas, image, x, y));
        return;
    }
    // all is well, we can execute the modify right away
    renderer.modifyTexture(textureAtlas, image, x, y);
}
Also used : Renderer(com.jme3.renderer.Renderer)

Example 9 with Texture2D

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

the class CombinedTexture method generateSkyTexture.

/**
     * Generates a texture that will be used by the sky spatial.
     * The result texture has 6 layers. Every image in each layer has equal size and its shape is a square.
     * The size of each image is the maximum size (width or height) of the textures given.
     * The default sky generated texture size is used (this value is set in the BlenderKey) if no picture textures
     * are present or their sizes is lower than the generated texture size.
     * The textures of lower sizes are properly scaled.
     * All the textures are mixed into one and put as layers in the result texture.
     * 
     * @param horizontalColor
     *            the horizon color
     * @param zenithColor
     *            the zenith color
     * @param blenderContext
     *            the blender context
     * @return texture for the sky
     */
public TextureCubeMap generateSkyTexture(ColorRGBA horizontalColor, ColorRGBA zenithColor, BlenderContext blenderContext) {
    LOGGER.log(Level.FINE, "Preparing sky texture from {0} applied textures.", textureDatas.size());
    LOGGER.fine("Computing the texture size.");
    int size = -1;
    for (TextureData textureData : textureDatas) {
        if (textureData.texture instanceof Texture2D) {
            size = Math.max(textureData.texture.getImage().getWidth(), size);
            size = Math.max(textureData.texture.getImage().getHeight(), size);
        }
    }
    if (size < 0) {
        size = blenderContext.getBlenderKey().getSkyGeneratedTextureSize();
    }
    LOGGER.log(Level.FINE, "The sky texture size will be: {0}x{0}.", size);
    TextureCubeMap result = null;
    for (TextureData textureData : textureDatas) {
        TextureCubeMap texture = null;
        if (textureData.texture instanceof GeneratedTexture) {
            texture = ((GeneratedTexture) textureData.texture).generateSkyTexture(size, horizontalColor, zenithColor, blenderContext);
        } else {
            // first create a grayscale version of the image
            Image image = textureData.texture.getImage();
            if (image.getWidth() != image.getHeight() || image.getWidth() != size) {
                image = ImageUtils.resizeTo(image, size, size);
            }
            Image grayscaleImage = ImageUtils.convertToGrayscaleTexture(image);
            // add the sky colors to the image
            PixelInputOutput sourcePixelIO = PixelIOFactory.getPixelIO(grayscaleImage.getFormat());
            PixelInputOutput targetPixelIO = PixelIOFactory.getPixelIO(image.getFormat());
            TexturePixel texturePixel = new TexturePixel();
            for (int x = 0; x < image.getWidth(); ++x) {
                for (int y = 0; y < image.getHeight(); ++y) {
                    sourcePixelIO.read(grayscaleImage, 0, texturePixel, x, y);
                    // no matter which factor we use here, in grayscale they are all equal
                    texturePixel.intensity = texturePixel.red;
                    ImageUtils.color(texturePixel, horizontalColor, zenithColor);
                    targetPixelIO.write(image, 0, texturePixel, x, y);
                }
            }
            // create the cubemap texture from the coloured image
            ByteBuffer sourceData = image.getData(0);
            ArrayList<ByteBuffer> data = new ArrayList<ByteBuffer>(6);
            for (int i = 0; i < 6; ++i) {
                data.add(BufferUtils.clone(sourceData));
            }
            texture = new TextureCubeMap(new Image(image.getFormat(), image.getWidth(), image.getHeight(), 6, data, ColorSpace.Linear));
        }
        if (result == null) {
            result = texture;
        } else {
            ImageUtils.mix(result.getImage(), texture.getImage());
        }
    }
    return result;
}
Also used : Texture2D(com.jme3.texture.Texture2D) PixelInputOutput(com.jme3.scene.plugins.blender.textures.io.PixelInputOutput) TextureCubeMap(com.jme3.texture.TextureCubeMap) ArrayList(java.util.ArrayList) Image(com.jme3.texture.Image) BufferedImage(java.awt.image.BufferedImage) ByteBuffer(java.nio.ByteBuffer)

Example 10 with Texture2D

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

the class CombinedTexture method scale.

/**
     * This method scales the given texture to the given size.
     * 
     * @param texture
     *            the texture to be scaled
     * @param width
     *            new width of the texture
     * @param height
     *            new height of the texture
     */
private void scale(Texture2D texture, int width, int height) {
    // first determine if scaling is required
    boolean scaleRequired = texture.getImage().getWidth() != width || texture.getImage().getHeight() != height;
    if (scaleRequired) {
        Image image = texture.getImage();
        BufferedImage sourceImage = ImageToAwt.convert(image, false, true, 0);
        int sourceWidth = sourceImage.getWidth();
        int sourceHeight = sourceImage.getHeight();
        BufferedImage targetImage = new BufferedImage(width, height, sourceImage.getType());
        Graphics2D g = targetImage.createGraphics();
        g.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        g.drawImage(sourceImage, 0, 0, width, height, 0, 0, sourceWidth, sourceHeight, null);
        g.dispose();
        Image output = new ImageLoader().load(targetImage, false);
        image.setWidth(width);
        image.setHeight(height);
        image.setData(output.getData(0));
        image.setFormat(output.getFormat());
    }
}
Also used : Image(com.jme3.texture.Image) BufferedImage(java.awt.image.BufferedImage) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Aggregations

Texture2D (com.jme3.texture.Texture2D)53 Material (com.jme3.material.Material)19 FrameBuffer (com.jme3.texture.FrameBuffer)18 Picture (com.jme3.ui.Picture)12 Geometry (com.jme3.scene.Geometry)11 Image (com.jme3.texture.Image)10 ViewPort (com.jme3.renderer.ViewPort)9 Texture (com.jme3.texture.Texture)9 Camera (com.jme3.renderer.Camera)8 Node (com.jme3.scene.Node)7 Spatial (com.jme3.scene.Spatial)7 TextureKey (com.jme3.asset.TextureKey)6 ByteBuffer (java.nio.ByteBuffer)6 Quaternion (com.jme3.math.Quaternion)5 Vector3f (com.jme3.math.Vector3f)5 Test (org.junit.Test)4 DirectionalLight (com.jme3.light.DirectionalLight)3 FilterPostProcessor (com.jme3.post.FilterPostProcessor)3 Box (com.jme3.scene.shape.Box)3 BufferedImage (java.awt.image.BufferedImage)3