Search in sources :

Example 1 with Picture

use of com.jme3.ui.Picture 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 2 with Picture

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

the class TestMultiRenderTarget method simpleInitApp.

@Override
public void simpleInitApp() {
    viewPort.addProcessor(this);
    //        flyCam.setEnabled(false);
    cam.setLocation(new Vector3f(4.8037705f, 4.851632f, 10.789033f));
    cam.setRotation(new Quaternion(-0.05143692f, 0.9483723f, -0.21131563f, -0.230846f));
    Node tank = (Node) assetManager.loadModel("Models/HoverTank/Tank2.mesh.xml");
    //tankMesh.getMaterial().setColor("Specular", ColorRGBA.Black);
    rootNode.attachChild(tank);
    display1 = new Picture("Picture");
    // make it appear behind stats view
    display1.move(0, 0, -1);
    display2 = (Picture) display1.clone();
    display3 = (Picture) display1.clone();
    display4 = (Picture) display1.clone();
    display = (Picture) display1.clone();
    ColorRGBA[] colors = new ColorRGBA[] { ColorRGBA.White, ColorRGBA.Blue, ColorRGBA.Cyan, ColorRGBA.DarkGray, ColorRGBA.Green, ColorRGBA.Magenta, ColorRGBA.Orange, ColorRGBA.Pink, ColorRGBA.Red, ColorRGBA.Yellow };
    pls = new PointLight[3];
    for (int i = 0; i < pls.length; i++) {
        PointLight pl = new PointLight();
        pl.setColor(colors[i % colors.length]);
        pl.setRadius(5);
        display.addLight(pl);
        pls[i] = pl;
    }
}
Also used : ColorRGBA(com.jme3.math.ColorRGBA) Quaternion(com.jme3.math.Quaternion) Picture(com.jme3.ui.Picture) Vector3f(com.jme3.math.Vector3f) Node(com.jme3.scene.Node) PointLight(com.jme3.light.PointLight)

Example 3 with Picture

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

the class VRMouseManager method initialize.

/**
     * Initialize the VR mouse manager.
     */
protected void initialize() {
    logger.config("Initializing VR mouse manager.");
    // load default mouseimage
    mouseImage = new Picture("mouse");
    setImage("Common/Util/mouse.png");
    // hide default cursor by making it invisible
    MouseInput mi = environment.getApplication().getContext().getMouseInput();
    if (mi instanceof GlfwMouseInputVR) {
        ((GlfwMouseInputVR) mi).hideActiveCursor();
    }
    centerMouse();
    logger.config("Initialized VR mouse manager [SUCCESS]");
}
Also used : GlfwMouseInputVR(com.jme3.input.lwjgl.GlfwMouseInputVR) Picture(com.jme3.ui.Picture) MouseInput(com.jme3.input.MouseInput)

Example 4 with Picture

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

the class VRViewManagerOpenVR method setupMirrorBuffers.

private ViewPort setupMirrorBuffers(Camera cam, Texture tex, boolean expand) {
    if (environment != null) {
        if (environment.getApplication() != null) {
            Camera clonecam = cam.clone();
            ViewPort viewPort = environment.getApplication().getRenderManager().createPostView("MirrorView", clonecam);
            clonecam.setParallelProjection(true);
            viewPort.setClearFlags(true, true, true);
            viewPort.setBackgroundColor(ColorRGBA.Black);
            Picture pic = new Picture("fullscene");
            pic.setLocalTranslation(-0.75f, -0.5f, 0f);
            if (expand) {
                pic.setLocalScale(3f, 1f, 1f);
            } else {
                pic.setLocalScale(1.5f, 1f, 1f);
            }
            pic.setQueueBucket(Bucket.Opaque);
            pic.setTexture(environment.getApplication().getAssetManager(), (Texture2D) tex, false);
            viewPort.attachScene(pic);
            viewPort.setOutputFrameBuffer(null);
            pic.updateGeometricState();
            return viewPort;
        } else {
            throw new IllegalStateException("This VR environment is not attached to any application.");
        }
    } else {
        throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
    }
}
Also used : Picture(com.jme3.ui.Picture) ViewPort(com.jme3.renderer.ViewPort) Camera(com.jme3.renderer.Camera)

Example 5 with Picture

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

the class TestAndroidTouch method simpleInitApp.

@Override
public void simpleInitApp() {
    getViewPort().setBackgroundColor(ColorRGBA.White);
    analogFormat.setMaximumFractionDigits(3);
    analogFormat.setMinimumFractionDigits(3);
    locationFormat.setMaximumFractionDigits(0);
    locationFormat.setMinimumFractionDigits(0);
    // Setup list of triggers based on different keyboard key codes. For Android, the soft keyboard key events
    // are translated into jme key events.
    int[] keyCodes = new int[] { KeyInput.KEY_0, KeyInput.KEY_1, KeyInput.KEY_2, KeyInput.KEY_3, KeyInput.KEY_4, KeyInput.KEY_5, KeyInput.KEY_6, KeyInput.KEY_7, KeyInput.KEY_8, KeyInput.KEY_9, KeyInput.KEY_DECIMAL, KeyInput.KEY_PERIOD, KeyInput.KEY_A, KeyInput.KEY_B, KeyInput.KEY_C, KeyInput.KEY_D, KeyInput.KEY_E, KeyInput.KEY_F, KeyInput.KEY_G, KeyInput.KEY_H, KeyInput.KEY_I, KeyInput.KEY_J, KeyInput.KEY_K, KeyInput.KEY_L, KeyInput.KEY_M, KeyInput.KEY_N, KeyInput.KEY_O, KeyInput.KEY_P, KeyInput.KEY_Q, KeyInput.KEY_R, KeyInput.KEY_S, KeyInput.KEY_T, KeyInput.KEY_U, KeyInput.KEY_V, KeyInput.KEY_W, KeyInput.KEY_X, KeyInput.KEY_Y, KeyInput.KEY_Z, KeyInput.KEY_CAPITAL, KeyInput.KEY_LSHIFT, KeyInput.KEY_RSHIFT, KeyInput.KEY_UP, KeyInput.KEY_DOWN, KeyInput.KEY_LEFT, KeyInput.KEY_RIGHT };
    for (int idx = 0; idx < keyCodes.length; idx++) {
        String keyMapping = mappingKeyPrefix + KeyNames.getName(keyCodes[idx]);
        inputManager.addMapping(keyMapping, new KeyTrigger(keyCodes[idx]));
        inputManager.addListener(actionListener, keyMapping);
        logger.log(Level.INFO, "Adding key mapping: {0}", keyMapping);
    }
    // setup InputManager to trigger our listeners when the various triggers are received.
    // Touch inputs are all sent to the TouchTrigger.  To have one mapping for all touch events, use TouchInput.ALL.
    inputManager.addMapping(touchMapping, new TouchTrigger(TouchInput.ALL));
    inputManager.addListener(touchListener, touchMapping);
    // If inputManager.isSimulateMouse = true, touch events will be translated into Mouse Button and Axis events.
    // To enable this, call inputManager.setSimulateMouse(true).
    inputManager.addMapping(mappingMouseLeft, new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(actionListener, mappingMouseLeft);
    inputManager.addMapping(mappingMouseXNeg, new MouseAxisTrigger(MouseInput.AXIS_X, true));
    inputManager.addMapping(mappingMouseXPos, new MouseAxisTrigger(MouseInput.AXIS_X, false));
    inputManager.addMapping(mappingMouseYNeg, new MouseAxisTrigger(MouseInput.AXIS_Y, true));
    inputManager.addMapping(mappingMouseYPos, new MouseAxisTrigger(MouseInput.AXIS_Y, false));
    inputManager.addListener(analogListener, mappingMouseXNeg, mappingMouseXPos, mappingMouseYNeg, mappingMouseYPos);
    // add raw input listener to inputManager
    inputManager.addRawInputListener(rawInputListener);
    float mouseSize = (settings.getWidth() >= settings.getHeight()) ? settings.getHeight() / 2f : settings.getWidth() / 2f;
    picMouseBackground = new Picture("Mouse Background");
    picMouseBackground.setImage(assetManager, "mouse_none.png", true);
    picMouseBackground.setWidth(mouseSize);
    picMouseBackground.setHeight(mouseSize);
    picMouseBackground.setLocalTranslation(settings.getWidth() - mouseSize, 0f, 0f);
    picMouseLeftButton = new Picture("Mouse Button Left");
    picMouseLeftButton.setImage(assetManager, "mouse_left.png", true);
    picMouseLeftButton.setWidth(mouseSize);
    picMouseLeftButton.setHeight(mouseSize);
    picMouseLeftButton.setLocalTranslation(settings.getWidth() - mouseSize, 0f, 1f);
    picMouseDisabled = new Picture("Mouse Disabled");
    picMouseDisabled.setImage(assetManager, "mouse_disabled.png", true);
    picMouseDisabled.setWidth(mouseSize);
    picMouseDisabled.setHeight(mouseSize);
    picMouseDisabled.setLocalTranslation(settings.getWidth() - mouseSize, 0f, 1f);
    float phoneSize = (settings.getWidth() >= settings.getHeight()) ? settings.getHeight() / 2f : settings.getWidth() / 2f;
    // preload images to send data to gpu to avoid hesitations during run time the first time the image is displayed
    renderManager.preloadScene(picMouseBackground);
    renderManager.preloadScene(picMouseLeftButton);
    renderManager.preloadScene(picMouseDisabled);
    guiNode.attachChild(picMouseBackground);
    if (inputManager.isSimulateMouse()) {
        picMouseDisabled.removeFromParent();
    } else {
        guiNode.attachChild(picMouseDisabled);
    }
    textMouseLabel = new BitmapText(guiFont, false);
    textMouseLabel.setSize(mouseSize / 10f);
    textMouseLabel.setColor(ColorRGBA.Blue);
    textMouseLabel.setBox(new Rectangle(0f, 0f, mouseSize, mouseSize / 5f));
    textMouseLabel.setAlignment(BitmapFont.Align.Center);
    textMouseLabel.setVerticalAlignment(BitmapFont.VAlign.Bottom);
    textMouseLabel.setText("Mouse Analog\nand Position");
    textMouseLabel.setLocalTranslation(settings.getWidth() - mouseSize, mouseSize * 1.25f, 1f);
    guiNode.attachChild(textMouseLabel);
    textMouseAnalog = new BitmapText(guiFont, false);
    textMouseAnalog.setSize(mouseSize / 10f);
    textMouseAnalog.setColor(ColorRGBA.Blue);
    textMouseAnalog.setBox(new Rectangle(0f, 0f, mouseSize, mouseSize / 10f));
    textMouseAnalog.setAlignment(BitmapFont.Align.Center);
    textMouseAnalog.setVerticalAlignment(BitmapFont.VAlign.Center);
    textMouseAnalog.setText("0.000, 0.000");
    textMouseAnalog.setLocalTranslation(settings.getWidth() - mouseSize, mouseSize / 2f, 2f);
    guiNode.attachChild(textMouseAnalog);
    textMouseLocation = new BitmapText(guiFont, false);
    textMouseLocation.setSize(mouseSize / 10f);
    textMouseLocation.setColor(ColorRGBA.Blue);
    textMouseLocation.setBox(new Rectangle(0f, 0f, mouseSize, mouseSize / 10f));
    textMouseLocation.setAlignment(BitmapFont.Align.Center);
    textMouseLocation.setVerticalAlignment(BitmapFont.VAlign.Center);
    textMouseLocation.setText("0, 0");
    textMouseLocation.setLocalTranslation(settings.getWidth() - mouseSize, mouseSize / 2f - mouseSize / 10f, 2f);
    guiNode.attachChild(textMouseLocation);
    textCursorLocation = new BitmapText(guiFont, false);
    textCursorLocation.setSize(mouseSize / 10f);
    textCursorLocation.setColor(ColorRGBA.Blue);
    textCursorLocation.setBox(new Rectangle(0f, 0f, mouseSize, mouseSize / 10f));
    textCursorLocation.setAlignment(BitmapFont.Align.Center);
    textCursorLocation.setVerticalAlignment(BitmapFont.VAlign.Center);
    textCursorLocation.setText("0, 0");
    textCursorLocation.setLocalTranslation(settings.getWidth() - mouseSize, mouseSize / 2f - mouseSize / 10f * 2f, 2f);
    guiNode.attachChild(textCursorLocation);
    textKeyPressed = new BitmapText(guiFont, false);
    textKeyPressed.setSize(mouseSize / 10f);
    textKeyPressed.setColor(ColorRGBA.Blue);
    textKeyPressed.setBox(new Rectangle(0f, 0f, settings.getWidth(), mouseSize / 10f));
    textKeyPressed.setAlignment(BitmapFont.Align.Center);
    textKeyPressed.setVerticalAlignment(BitmapFont.VAlign.Top);
    textKeyPressed.setText("Last Key Pressed: None");
    textKeyPressed.setLocalTranslation(0f, settings.getHeight() - mouseSize / 10f, 2f);
    guiNode.attachChild(textKeyPressed);
    picPhone = new Picture("Phone");
    picPhone.setImage(assetManager, "phone_landscape.png", true);
    picPhone.setWidth(phoneSize);
    picPhone.setHeight(phoneSize);
    picPhone.setLocalTranslation(picMouseBackground.getLocalTranslation().x - phoneSize, 0f, 1f);
    guiNode.attachChild(picPhone);
    textPhoneLocation = new BitmapText(guiFont, false);
    textPhoneLocation.setSize(phoneSize / 10f);
    textPhoneLocation.setColor(ColorRGBA.White);
    textPhoneLocation.setBox(new Rectangle(0f, 0f, phoneSize, phoneSize / 10f));
    textPhoneLocation.setAlignment(BitmapFont.Align.Center);
    textPhoneLocation.setVerticalAlignment(BitmapFont.VAlign.Center);
    textPhoneLocation.setText("0, 0");
    textPhoneLocation.setLocalTranslation(picMouseBackground.getLocalTranslation().x - phoneSize, phoneSize * 0.5f, 2f);
    guiNode.attachChild(textPhoneLocation);
    textPhoneLabel = new BitmapText(guiFont, false);
    textPhoneLabel.setSize(phoneSize / 10f);
    textPhoneLabel.setColor(ColorRGBA.Blue);
    textPhoneLabel.setBox(new Rectangle(0f, 0f, phoneSize, phoneSize / 10f));
    textPhoneLabel.setAlignment(BitmapFont.Align.Center);
    textPhoneLabel.setVerticalAlignment(BitmapFont.VAlign.Bottom);
    textPhoneLabel.setText("Touch Location");
    textPhoneLabel.setLocalTranslation(picMouseBackground.getLocalTranslation().x - phoneSize, picPhone.getLocalTranslation().y + phoneSize * 0.75f, 1f);
    guiNode.attachChild(textPhoneLabel);
    renderManager.preloadScene(picPhone);
}
Also used : BitmapText(com.jme3.font.BitmapText) Picture(com.jme3.ui.Picture) Rectangle(com.jme3.font.Rectangle)

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