Search in sources :

Example 11 with Picture

use of com.jme3.ui.Picture in project jmonkeyengine by jMonkeyEngine.

the class Picture method setWidth.

/**
     * Set the width in pixels of the picture, if the width
     * does not match the texture's width, then the texture will
     * be scaled to fit the picture.
     * 
     * @param width the width to set.
     */
public void setWidth(float width) {
    this.width = width;
    setLocalScale(new Vector3f(width, height, 1f));
}
Also used : Vector3f(com.jme3.math.Vector3f)

Example 12 with Picture

use of com.jme3.ui.Picture in project jmonkeyengine by jMonkeyEngine.

the class TestDepthStencil method simpleInitApp.

@Override
public void simpleInitApp() {
    int w = settings.getWidth();
    int h = settings.getHeight();
    //setup framebuffer
    fb = new FrameBuffer(w, h, 1);
    Texture2D fbTex = new Texture2D(w, h, Format.RGB8);
    fb.setDepthBuffer(Format.Depth24Stencil8);
    fb.setColorTexture(fbTex);
    // setup framebuffer's scene
    Sphere sphMesh = new Sphere(20, 20, 1);
    Material solidColor = assetManager.loadMaterial("Common/Materials/RedColor.j3m");
    final Geometry sphere = new Geometry("sphere", sphMesh);
    sphere.setMaterial(solidColor);
    fbNode.attachChild(sphere);
    sphere.addControl(new AbstractControl() {

        @Override
        protected void controlUpdate(float tpf) {
            Material mat = sphere.getMaterial();
            mat.getAdditionalRenderState().setStencil(enableStencil, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.TestFunction.Never, RenderState.TestFunction.Never);
        }

        @Override
        protected void controlRender(RenderManager rm, ViewPort vp) {
        }
    });
    //setup main scene
    Picture p = new Picture("Picture");
    p.setPosition(0, 0);
    p.setWidth(w);
    p.setHeight(h);
    p.setTexture(assetManager, fbTex, false);
    rootNode.attachChild(p);
    inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
    ActionListener acl = new ActionListener() {

        public void onAction(String name, boolean keyPressed, float tpf) {
            if (name.equals("toggle") && keyPressed) {
                if (enableStencil) {
                    enableStencil = false;
                    System.out.println("Stencil Enabled (model should be hidden)");
                } else {
                    enableStencil = true;
                    System.out.println("Stencil Disabled (model should be visible)");
                }
            }
        }
    };
    inputManager.addListener(acl, "toggle");
    System.out.println("Press space to toggle stencil");
}
Also used : Texture2D(com.jme3.texture.Texture2D) KeyTrigger(com.jme3.input.controls.KeyTrigger) AbstractControl(com.jme3.scene.control.AbstractControl) Material(com.jme3.material.Material) FrameBuffer(com.jme3.texture.FrameBuffer) Sphere(com.jme3.scene.shape.Sphere) Geometry(com.jme3.scene.Geometry) ActionListener(com.jme3.input.controls.ActionListener) Picture(com.jme3.ui.Picture) ViewPort(com.jme3.renderer.ViewPort) RenderManager(com.jme3.renderer.RenderManager)

Example 13 with Picture

use of com.jme3.ui.Picture in project jmonkeyengine by jMonkeyEngine.

the class EnvMapUtils method getCubeMapCrossDebugView.

/**
     * Creates a debug Node of the given cube map to attach to the gui node
     *
     * the cube map is layered this way :
     * <pre>
     *         _____
     *        |     |
     *        | +Y  |
     *   _____|_____|_____ _____
     *  |     |     |     |     |
     *  | -X  | +Z  | +X  | -Z  |
     *  |_____|_____|_____|_____|
     *        |     |
     *        | -Y  |
     *        |_____|
     *
     *</pre>
     *
     * @param cubeMap the cube map
     * @param assetManager the asset Manager
     * @return
     */
public static Node getCubeMapCrossDebugView(TextureCubeMap cubeMap, AssetManager assetManager) {
    Node n = new Node("CubeMapDebug" + cubeMap.getName());
    int size = cubeMap.getImage().getWidth();
    Picture[] pics = new Picture[6];
    float ratio = 128f / (float) size;
    for (int i = 0; i < 6; i++) {
        pics[i] = new Picture("bla");
        Texture2D tex = new Texture2D(new Image(cubeMap.getImage().getFormat(), size, size, cubeMap.getImage().getData(i), cubeMap.getImage().getColorSpace()));
        pics[i].setTexture(assetManager, tex, true);
        pics[i].setWidth(size);
        pics[i].setHeight(size);
        n.attachChild(pics[i]);
    }
    pics[0].setLocalTranslation(size, size * 2, 1);
    pics[0].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
    pics[1].setLocalTranslation(size * 3, size * 2, 1);
    pics[1].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
    pics[2].setLocalTranslation(size * 2, size * 3, 1);
    pics[2].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
    pics[3].setLocalTranslation(size * 2, size, 1);
    pics[3].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
    pics[4].setLocalTranslation(size * 2, size * 2, 1);
    pics[4].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
    pics[5].setLocalTranslation(size * 4, size * 2, 1);
    pics[5].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
    Quad q = new Quad(size * 4, size * 3);
    Geometry g = new Geometry("bg", q);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Black);
    g.setMaterial(mat);
    g.setLocalTranslation(0, 0, 0);
    n.attachChild(g);
    n.setLocalScale(ratio);
    return n;
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad) Texture2D(com.jme3.texture.Texture2D) Quaternion(com.jme3.math.Quaternion) Picture(com.jme3.ui.Picture) Node(com.jme3.scene.Node) Material(com.jme3.material.Material) Image(com.jme3.texture.Image)

Example 14 with Picture

use of com.jme3.ui.Picture in project jmonkeyengine by jMonkeyEngine.

the class SimpleWaterProcessor method initialize.

public void initialize(RenderManager rm, ViewPort vp) {
    this.rm = rm;
    this.vp = vp;
    loadTextures(manager);
    createTextures();
    applyTextures(material);
    createPreViews();
    material.setVector2("FrustumNearFar", new Vector2f(vp.getCamera().getFrustumNear(), vp.getCamera().getFrustumFar()));
    if (debug) {
        dispRefraction = new Picture("dispRefraction");
        dispRefraction.setTexture(manager, refractionTexture, false);
        dispReflection = new Picture("dispRefraction");
        dispReflection.setTexture(manager, reflectionTexture, false);
        dispDepth = new Picture("depthTexture");
        dispDepth.setTexture(manager, depthTexture, false);
    }
}
Also used : Picture(com.jme3.ui.Picture)

Example 15 with Picture

use of com.jme3.ui.Picture in project jmonkeyengine by jMonkeyEngine.

the class EnvMapUtils method getCubeMapCrossDebugViewWithMipMaps.

public static Node getCubeMapCrossDebugViewWithMipMaps(TextureCubeMap cubeMap, AssetManager assetManager) {
    Node n = new Node("CubeMapDebug" + cubeMap.getName());
    int size = cubeMap.getImage().getWidth();
    int nbMips = cubeMap.getImage().getMipMapSizes().length;
    Picture[] pics = new Picture[6 * nbMips];
    // 128f / (float) size;
    float ratio = 1f;
    int offset = 0;
    int guiOffset = 0;
    for (int mipLevel = 0; mipLevel < nbMips; mipLevel++) {
        size = Math.max(1, cubeMap.getImage().getWidth() >> mipLevel);
        int dataSize = cubeMap.getImage().getMipMapSizes()[mipLevel];
        byte[] dataArray = new byte[dataSize];
        for (int i = 0; i < 6; i++) {
            ByteBuffer bb = cubeMap.getImage().getData(i);
            bb.rewind();
            bb.position(offset);
            bb.get(dataArray, 0, dataSize);
            ByteBuffer data = BufferUtils.createByteBuffer(dataArray);
            pics[i] = new Picture("bla");
            Texture2D tex = new Texture2D(new Image(cubeMap.getImage().getFormat(), size, size, data, cubeMap.getImage().getColorSpace()));
            pics[i].setTexture(assetManager, tex, true);
            pics[i].setWidth(size);
            pics[i].setHeight(size);
            n.attachChild(pics[i]);
        }
        pics[0].setLocalTranslation(guiOffset + size, guiOffset + size * 2, 1);
        pics[0].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
        pics[1].setLocalTranslation(guiOffset + size * 3, guiOffset + size * 2, 1);
        pics[1].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
        pics[2].setLocalTranslation(guiOffset + size * 2, guiOffset + size * 3, 1);
        pics[2].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
        pics[3].setLocalTranslation(guiOffset + size * 2, guiOffset + size, 1);
        pics[3].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
        pics[4].setLocalTranslation(guiOffset + size * 2, guiOffset + size * 2, 1);
        pics[4].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
        pics[5].setLocalTranslation(guiOffset + size * 4, guiOffset + size * 2, 1);
        pics[5].setLocalRotation(new Quaternion().fromAngleAxis(PI, Vector3f.UNIT_Z));
        guiOffset += size * 2 + 1;
        offset += dataSize;
    }
    Quad q = new Quad(cubeMap.getImage().getWidth() * 4 + nbMips, guiOffset + size);
    Geometry g = new Geometry("bg", q);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Black);
    g.setMaterial(mat);
    g.setLocalTranslation(0, 0, 0);
    n.attachChild(g);
    n.setLocalScale(ratio);
    return n;
}
Also used : Quad(com.jme3.scene.shape.Quad) Texture2D(com.jme3.texture.Texture2D) Quaternion(com.jme3.math.Quaternion) Node(com.jme3.scene.Node) Material(com.jme3.material.Material) Image(com.jme3.texture.Image) ByteBuffer(java.nio.ByteBuffer) Geometry(com.jme3.scene.Geometry) Picture(com.jme3.ui.Picture)

Aggregations

Picture (com.jme3.ui.Picture)22 Texture2D (com.jme3.texture.Texture2D)11 Material (com.jme3.material.Material)9 Geometry (com.jme3.scene.Geometry)5 FrameBuffer (com.jme3.texture.FrameBuffer)5 Quaternion (com.jme3.math.Quaternion)4 Vector3f (com.jme3.math.Vector3f)4 Node (com.jme3.scene.Node)4 Image (com.jme3.texture.Image)4 ViewPort (com.jme3.renderer.ViewPort)3 Quad (com.jme3.scene.shape.Quad)3 ActionListener (com.jme3.input.controls.ActionListener)2 KeyTrigger (com.jme3.input.controls.KeyTrigger)2 Matrix4f (com.jme3.math.Matrix4f)2 Camera (com.jme3.renderer.Camera)2 Sphere (com.jme3.scene.shape.Sphere)2 Format (com.jme3.texture.Image.Format)2 ByteBuffer (java.nio.ByteBuffer)2 TextureKey (com.jme3.asset.TextureKey)1 EnvironmentCamera (com.jme3.environment.EnvironmentCamera)1