Search in sources :

Example 11 with TextureCubeMap

use of com.jme3.texture.TextureCubeMap 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 texture to use
     * @param normalScale The normal scale is multiplied by the 3D normal to get
     * a texture coordinate. Use Vector3f.UNIT_XYZ to not apply and
     * transformation to the normal.
     * @param envMapType see {@link EnvMapType}
     * @param sphereRadius the sky sphere's radius: for the sky to be visible,
     * its radius must fall between the near and far planes of the camera's
     * frustrum
     * @return a new spatial representing the sky, ready to be attached to the
     * scene graph     
     */
public static Spatial createSky(AssetManager assetManager, Texture texture, Vector3f normalScale, EnvMapType envMapType, float sphereRadius) {
    if (texture == null) {
        throw new IllegalArgumentException("texture cannot be null");
    }
    final Sphere sphereMesh = new Sphere(10, 10, sphereRadius, false, true);
    Geometry sky = new Geometry("Sky", sphereMesh);
    sky.setQueueBucket(Bucket.Sky);
    sky.setCullHint(Spatial.CullHint.Never);
    sky.setModelBound(new BoundingSphere(Float.POSITIVE_INFINITY, Vector3f.ZERO));
    Material skyMat = new Material(assetManager, "Common/MatDefs/Misc/Sky.j3md");
    skyMat.setVector3("NormalScale", normalScale);
    switch(envMapType) {
        case CubeMap:
            // make sure its a cubemap
            if (!(texture instanceof TextureCubeMap)) {
                Image img = texture.getImage();
                texture = new TextureCubeMap();
                texture.setImage(img);
            }
            break;
        case SphereMap:
            skyMat.setBoolean("SphereMap", true);
            break;
        case EquirectMap:
            skyMat.setBoolean("EquirectMap", true);
            break;
    }
    texture.setMagFilter(Texture.MagFilter.Bilinear);
    texture.setMinFilter(Texture.MinFilter.BilinearNoMipMaps);
    texture.setAnisotropicFilter(0);
    texture.setWrap(Texture.WrapMode.EdgeClamp);
    skyMat.setTexture("Texture", texture);
    sky.setMaterial(skyMat);
    return sky;
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) Sphere(com.jme3.scene.shape.Sphere) Geometry(com.jme3.scene.Geometry) BoundingSphere(com.jme3.bounding.BoundingSphere) TextureCubeMap(com.jme3.texture.TextureCubeMap) Material(com.jme3.material.Material) Image(com.jme3.texture.Image)

Example 12 with TextureCubeMap

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

the class SkyFactory method createSky.

/**
     * Create a cube-mapped sky using six textures.
     *
     * @param assetManager from which to load materials
     * @param west texture for the western face of the cube
     * @param east texture for the eastern face of the cube
     * @param north texture for the northern face of the cube
     * @param south texture for the southern face of the cube
     * @param up texture for the top face of the cube
     * @param down texture for the bottom face of the cube
     * @param normalScale The normal scale is multiplied by the 3D normal to get
     * a texture coordinate. Use Vector3f.UNIT_XYZ to not apply and
     * transformation to the normal.
     * @param sphereRadius the sky sphere's radius: for the sky to be visible,
     * its radius must fall between the near and far planes of the camera's
     * frustrum
     * @return a new spatial representing the sky, ready to be attached to the
     * scene graph
     */
public static Spatial createSky(AssetManager assetManager, Texture west, Texture east, Texture north, Texture south, Texture up, Texture down, Vector3f normalScale, float sphereRadius) {
    Image westImg = west.getImage();
    Image eastImg = east.getImage();
    Image northImg = north.getImage();
    Image southImg = south.getImage();
    Image upImg = up.getImage();
    Image downImg = down.getImage();
    checkImagesForCubeMap(westImg, eastImg, northImg, southImg, upImg, downImg);
    Image cubeImage = new Image(westImg.getFormat(), westImg.getWidth(), westImg.getHeight(), null, westImg.getColorSpace());
    cubeImage.addData(westImg.getData(0));
    cubeImage.addData(eastImg.getData(0));
    cubeImage.addData(downImg.getData(0));
    cubeImage.addData(upImg.getData(0));
    cubeImage.addData(southImg.getData(0));
    cubeImage.addData(northImg.getData(0));
    TextureCubeMap cubeMap = new TextureCubeMap(cubeImage);
    return createSky(assetManager, cubeMap, normalScale, EnvMapType.CubeMap, sphereRadius);
}
Also used : TextureCubeMap(com.jme3.texture.TextureCubeMap) Image(com.jme3.texture.Image)

Example 13 with TextureCubeMap

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

the class TextureProcessor method postProcess.

@Override
public Object postProcess(AssetKey key, Object obj) {
    TextureKey texKey = (TextureKey) key;
    Image img = (Image) obj;
    if (img == null) {
        return null;
    }
    Texture tex;
    if (texKey.getTextureTypeHint() == Texture.Type.CubeMap) {
        if (texKey.isFlipY()) {
            // also flip -y and +y image in cubemap
            ByteBuffer pos_y = img.getData(2);
            img.setData(2, img.getData(3));
            img.setData(3, pos_y);
        }
        tex = new TextureCubeMap();
    } else if (texKey.getTextureTypeHint() == Texture.Type.ThreeDimensional) {
        tex = new Texture3D();
    } else {
        tex = new Texture2D();
    }
    // or generate them if requested by user
    if (img.hasMipmaps() || texKey.isGenerateMips()) {
        tex.setMinFilter(Texture.MinFilter.Trilinear);
    }
    tex.setAnisotropicFilter(texKey.getAnisotropy());
    tex.setName(texKey.getName());
    tex.setImage(img);
    return tex;
}
Also used : TextureKey(com.jme3.asset.TextureKey) ByteBuffer(java.nio.ByteBuffer)

Example 14 with TextureCubeMap

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

the class TestRenderToCubemap method setupOffscreenView.

public Texture setupOffscreenView() {
    Camera offCamera = new Camera(512, 512);
    offView = renderManager.createPreView("Offscreen View", offCamera);
    offView.setClearFlags(true, true, true);
    offView.setBackgroundColor(ColorRGBA.DarkGray);
    // create offscreen framebuffer
    FrameBuffer offBuffer = new FrameBuffer(512, 512, 1);
    //setup framebuffer's cam
    offCamera.setFrustumPerspective(45f, 1f, 1f, 1000f);
    offCamera.setLocation(new Vector3f(0f, 0f, -5f));
    offCamera.lookAt(new Vector3f(0f, 0f, 0f), Vector3f.UNIT_Y);
    //setup framebuffer's texture
    TextureCubeMap offTex = new TextureCubeMap(512, 512, Format.RGBA8);
    offTex.setMinFilter(Texture.MinFilter.Trilinear);
    offTex.setMagFilter(Texture.MagFilter.Bilinear);
    //setup framebuffer to use texture
    offBuffer.setDepthBuffer(Format.Depth);
    offBuffer.setMultiTarget(true);
    offBuffer.addColorTexture(offTex, TextureCubeMap.Face.NegativeX);
    offBuffer.addColorTexture(offTex, TextureCubeMap.Face.PositiveX);
    offBuffer.addColorTexture(offTex, TextureCubeMap.Face.NegativeY);
    offBuffer.addColorTexture(offTex, TextureCubeMap.Face.PositiveY);
    offBuffer.addColorTexture(offTex, TextureCubeMap.Face.NegativeZ);
    offBuffer.addColorTexture(offTex, TextureCubeMap.Face.PositiveZ);
    //set viewport to render to offscreen framebuffer
    offView.setOutputFrameBuffer(offBuffer);
    // setup framebuffer's scene
    Box boxMesh = new Box(1, 1, 1);
    Material material = assetManager.loadMaterial("Interface/Logo/Logo.j3m");
    offBox = new Geometry("box", boxMesh);
    offBox.setMaterial(material);
    // attach the scene to the viewport to be rendered
    offView.attachScene(offBox);
    return offTex;
}
Also used : Geometry(com.jme3.scene.Geometry) Vector3f(com.jme3.math.Vector3f) TextureCubeMap(com.jme3.texture.TextureCubeMap) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) Camera(com.jme3.renderer.Camera) FrameBuffer(com.jme3.texture.FrameBuffer)

Example 15 with TextureCubeMap

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

the class EnvMapUtils method duplicateCubeMap.

/**
     * Make a duplicate of this cube Map. That means that it's another instant
     * od TextureCubeMap, but the underlying buffers are duplicates of the
     * original ones. see {@link ByteBuffer#duplicate()}
     *
     * Use this if you need to read from the map from multiple threads, it
     * should garanty the thread safety. Note that if you want to write to the
     * cube map you have to make sure that the different thread do not write to
     * the same area of the buffer. The position, limit and mark are not an
     * issue.
     *
     * @param sourceMap
     * @return
     */
public static TextureCubeMap duplicateCubeMap(TextureCubeMap sourceMap) {
    Image srcImg = sourceMap.getImage();
    Image cubeImage = new Image(srcImg.getFormat(), srcImg.getWidth(), srcImg.getHeight(), null, srcImg.getColorSpace());
    for (ByteBuffer d : srcImg.getData()) {
        cubeImage.addData(d.duplicate());
    }
    if (srcImg.getEfficentData() != null) {
        // also consilidate efficient data
        ArrayList<Object> efficientData = new ArrayList<Object>(6);
        efficientData.add(srcImg.getEfficentData());
        cubeImage.setEfficentData(efficientData);
    }
    TextureCubeMap cubeMap = new TextureCubeMap(cubeImage);
    cubeMap.setAnisotropicFilter(sourceMap.getAnisotropicFilter());
    cubeMap.setMagFilter(sourceMap.getMagFilter());
    cubeMap.setMinFilter(sourceMap.getMinFilter());
    cubeMap.setWrap(sourceMap.getWrap(Texture.WrapAxis.S));
    return cubeMap;
}
Also used : TextureCubeMap(com.jme3.texture.TextureCubeMap) ArrayList(java.util.ArrayList) Image(com.jme3.texture.Image) ByteBuffer(java.nio.ByteBuffer)

Aggregations

TextureCubeMap (com.jme3.texture.TextureCubeMap)16 Image (com.jme3.texture.Image)10 ColorRGBA (com.jme3.math.ColorRGBA)6 Vector3f (com.jme3.math.Vector3f)6 ByteBuffer (java.nio.ByteBuffer)6 Material (com.jme3.material.Material)4 Geometry (com.jme3.scene.Geometry)4 Texture2D (com.jme3.texture.Texture2D)4 ArrayList (java.util.ArrayList)4 PixelInputOutput (com.jme3.scene.plugins.blender.textures.io.PixelInputOutput)3 TextureKey (com.jme3.asset.TextureKey)2 BoundingSphere (com.jme3.bounding.BoundingSphere)2 CubeMapWrapper (com.jme3.environment.util.CubeMapWrapper)2 Quaternion (com.jme3.math.Quaternion)2 Node (com.jme3.scene.Node)2 Quad (com.jme3.scene.shape.Quad)2 Texture (com.jme3.texture.Texture)2 Picture (com.jme3.ui.Picture)2 IrradianceMapGenerator (com.jme3.environment.generation.IrradianceMapGenerator)1 PrefilteredEnvMapFaceGenerator (com.jme3.environment.generation.PrefilteredEnvMapFaceGenerator)1