Search in sources :

Example 36 with Texture

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

the class TestPostFilters method setupSkyBox.

public void setupSkyBox() {
    Texture envMap;
    if (renderer.getCaps().contains(Caps.FloatTexture)) {
        envMap = assetManager.loadTexture("Textures/Sky/St Peters/StPeters.hdr");
    } else {
        envMap = assetManager.loadTexture("Textures/Sky/St Peters/StPeters.jpg");
    }
    rootNode.attachChild(SkyFactory.createSky(assetManager, envMap, new Vector3f(-1, -1, -1), true));
}
Also used : Texture(com.jme3.texture.Texture)

Example 37 with Texture

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

the class TestPostFiltersCompositing method simpleInitApp.

public void simpleInitApp() {
    this.flyCam.setMoveSpeed(10);
    cam.setLocation(new Vector3f(0.028406568f, 2.015769f, 7.386517f));
    cam.setRotation(new Quaternion(-1.0729783E-5f, 0.9999721f, -0.0073241726f, -0.0014647911f));
    makeScene();
    //Creating the main view port post processor
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(new ColorOverlayFilter(ColorRGBA.Blue));
    viewPort.addProcessor(fpp);
    //creating a frame buffer for the mainviewport
    FrameBuffer mainVPFrameBuffer = new FrameBuffer(cam.getWidth(), cam.getHeight(), 1);
    Texture2D mainVPTexture = new Texture2D(cam.getWidth(), cam.getHeight(), Image.Format.RGBA8);
    mainVPFrameBuffer.addColorTexture(mainVPTexture);
    mainVPFrameBuffer.setDepthBuffer(Image.Format.Depth);
    viewPort.setOutputFrameBuffer(mainVPFrameBuffer);
    //creating the post processor for the gui viewport
    final FilterPostProcessor guifpp = new FilterPostProcessor(assetManager);
    guifpp.setFrameBufferFormat(Image.Format.RGBA8);
    guifpp.addFilter(new ColorOverlayFilter(ColorRGBA.Red));
    //this will compose the main viewport texture with the guiviewport back buffer.
    //Note that you can switch the order of the filters so that guiviewport filters are applied or not to the main viewport texture
    guifpp.addFilter(new ComposeFilter(mainVPTexture));
    guiViewPort.addProcessor(guifpp);
    //compositing is done by mixing texture depending on the alpha channel, 
    //it's important that the guiviewport clear color alpha value is set to 0
    guiViewPort.setBackgroundColor(ColorRGBA.BlackNoAlpha);
    guiViewPort.setClearColor(true);
}
Also used : Texture2D(com.jme3.texture.Texture2D) ColorOverlayFilter(com.jme3.post.filters.ColorOverlayFilter) ComposeFilter(com.jme3.post.filters.ComposeFilter) Quaternion(com.jme3.math.Quaternion) Vector3f(com.jme3.math.Vector3f) FilterPostProcessor(com.jme3.post.FilterPostProcessor) FrameBuffer(com.jme3.texture.FrameBuffer)

Example 38 with Texture

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

the class TestCustomMesh method simpleInitApp.

@Override
public void simpleInitApp() {
    Mesh m = new Mesh();
    // Vertex positions in space
    Vector3f[] vertices = new Vector3f[4];
    vertices[0] = new Vector3f(0, 0, 0);
    vertices[1] = new Vector3f(3, 0, 0);
    vertices[2] = new Vector3f(0, 3, 0);
    vertices[3] = new Vector3f(3, 3, 0);
    // Texture coordinates
    Vector2f[] texCoord = new Vector2f[4];
    texCoord[0] = new Vector2f(0, 0);
    texCoord[1] = new Vector2f(1, 0);
    texCoord[2] = new Vector2f(0, 1);
    texCoord[3] = new Vector2f(1, 1);
    // Indexes. We define the order in which mesh should be constructed
    short[] indexes = { 2, 0, 1, 1, 3, 2 };
    // Setting buffers
    m.setBuffer(Type.Position, 3, BufferUtils.createFloatBuffer(vertices));
    m.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(texCoord));
    m.setBuffer(Type.Index, 1, BufferUtils.createShortBuffer(indexes));
    m.updateBound();
    // *************************************************************************
    // First mesh uses one solid color
    // *************************************************************************
    // Creating a geometry, and apply a single color material to it
    Geometry geom = new Geometry("OurMesh", m);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Blue);
    geom.setMaterial(mat);
    // Attaching our geometry to the root node.
    rootNode.attachChild(geom);
    // *************************************************************************
    // Second mesh uses vertex colors to color each vertex
    // *************************************************************************
    Mesh cMesh = m.clone();
    Geometry coloredMesh = new Geometry("ColoredMesh", cMesh);
    Material matVC = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matVC.setBoolean("VertexColor", true);
    //We have 4 vertices and 4 color values for each of them.
    //If you have more vertices, you need 'new float[yourVertexCount * 4]' here!
    float[] colorArray = new float[4 * 4];
    int colorIndex = 0;
    //Set custom RGBA value for each Vertex. Values range from 0.0f to 1.0f
    for (int i = 0; i < 4; i++) {
        // Red value (is increased by .2 on each next vertex here)
        colorArray[colorIndex++] = 0.1f + (.2f * i);
        // Green value (is reduced by .2 on each next vertex)
        colorArray[colorIndex++] = 0.9f - (0.2f * i);
        // Blue value (remains the same in our case)
        colorArray[colorIndex++] = 0.5f;
        // Alpha value (no transparency set here)
        colorArray[colorIndex++] = 1.0f;
    }
    // Set the color buffer
    cMesh.setBuffer(Type.Color, 4, colorArray);
    coloredMesh.setMaterial(matVC);
    // move mesh a bit so that it doesn't intersect with the first one
    coloredMesh.setLocalTranslation(4, 0, 0);
    rootNode.attachChild(coloredMesh);
    //        /** Alternatively, you can show the mesh vertixes as points
    //          * instead of coloring the faces. */
    //        cMesh.setMode(Mesh.Mode.Points);
    //        cMesh.setPointSize(10f);
    //        cMesh.updateBound();
    //        cMesh.setStatic();
    //        Geometry points = new Geometry("Points", m);
    //        points.setMaterial(mat);
    //        rootNode.attachChild(points);
    // *************************************************************************
    // Third mesh will use a wireframe shader to show wireframe
    // *************************************************************************
    Mesh wfMesh = m.clone();
    Geometry wfGeom = new Geometry("wireframeGeometry", wfMesh);
    Material matWireframe = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matWireframe.setColor("Color", ColorRGBA.Green);
    matWireframe.getAdditionalRenderState().setWireframe(true);
    wfGeom.setMaterial(matWireframe);
    wfGeom.setLocalTranslation(4, 4, 0);
    rootNode.attachChild(wfGeom);
}
Also used : Geometry(com.jme3.scene.Geometry) Vector2f(com.jme3.math.Vector2f) Vector3f(com.jme3.math.Vector3f) Mesh(com.jme3.scene.Mesh) Material(com.jme3.material.Material)

Example 39 with Texture

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

the class TestCylinder method simpleInitApp.

@Override
public void simpleInitApp() {
    Cylinder t = new Cylinder(20, 50, 1, 2, true);
    Geometry geom = new Geometry("Cylinder", t);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    TextureKey key = new TextureKey("Interface/Logo/Monkey.jpg", true);
    key.setGenerateMips(true);
    Texture tex = assetManager.loadTexture(key);
    tex.setMinFilter(Texture.MinFilter.Trilinear);
    mat.setTexture("ColorMap", tex);
    geom.setMaterial(mat);
    rootNode.attachChild(geom);
}
Also used : Geometry(com.jme3.scene.Geometry) Cylinder(com.jme3.scene.shape.Cylinder) TextureKey(com.jme3.asset.TextureKey) Material(com.jme3.material.Material) Texture(com.jme3.texture.Texture)

Example 40 with Texture

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

the class VRMouseManager method setImage.

/**
     * Set the image to use as mouse cursor. The given string describe an asset that the underlying application asset manager has to load.
     * @param texture the image to use as mouse cursor.
     */
public void setImage(String texture) {
    if (environment != null) {
        if (environment.getApplication() != null) {
            if (environment.isInVR() == false) {
                Texture tex = environment.getApplication().getAssetManager().loadTexture(texture);
                mouseImage.setTexture(environment.getApplication().getAssetManager(), (Texture2D) tex, true);
                ySize = tex.getImage().getHeight();
                mouseImage.setHeight(ySize);
                mouseImage.setWidth(tex.getImage().getWidth());
                mouseImage.getMaterial().getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
                mouseImage.getMaterial().getAdditionalRenderState().setDepthWrite(false);
            } else {
                Texture tex = environment.getApplication().getAssetManager().loadTexture(texture);
                mouseImage.setTexture(environment.getApplication().getAssetManager(), (Texture2D) tex, true);
                ySize = tex.getImage().getHeight();
                mouseImage.setHeight(ySize);
                mouseImage.setWidth(tex.getImage().getWidth());
                mouseImage.getMaterial().getAdditionalRenderState().setBlendMode(BlendMode.Alpha);
                mouseImage.getMaterial().getAdditionalRenderState().setDepthWrite(false);
            }
        } 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 : Texture(com.jme3.texture.Texture)

Aggregations

Material (com.jme3.material.Material)97 Texture (com.jme3.texture.Texture)94 Vector3f (com.jme3.math.Vector3f)66 Geometry (com.jme3.scene.Geometry)40 Image (com.jme3.texture.Image)39 TextureKey (com.jme3.asset.TextureKey)31 ArrayList (java.util.ArrayList)27 Texture2D (com.jme3.texture.Texture2D)25 ColorRGBA (com.jme3.math.ColorRGBA)23 Box (com.jme3.scene.shape.Box)19 Spatial (com.jme3.scene.Spatial)18 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)18 ParticleEmitter (com.jme3.effect.ParticleEmitter)17 DirectionalLight (com.jme3.light.DirectionalLight)17 Vector2f (com.jme3.math.Vector2f)17 TerrainLodControl (com.jme3.terrain.geomipmap.TerrainLodControl)16 ByteBuffer (java.nio.ByteBuffer)16 AbstractHeightMap (com.jme3.terrain.heightmap.AbstractHeightMap)15 ImageBasedHeightMap (com.jme3.terrain.heightmap.ImageBasedHeightMap)15 Camera (com.jme3.renderer.Camera)14