Search in sources :

Example 96 with Texture

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

the class BombControl method prepareEffect.

private void prepareEffect(AssetManager assetManager) {
    int COUNT_FACTOR = 1;
    float COUNT_FACTOR_F = 1f;
    effect = new ParticleEmitter("Flame", Type.Triangle, 32 * COUNT_FACTOR);
    effect.setSelectRandomImage(true);
    effect.setStartColor(new ColorRGBA(1f, 0.4f, 0.05f, (float) (1f / COUNT_FACTOR_F)));
    effect.setEndColor(new ColorRGBA(.4f, .22f, .12f, 0f));
    effect.setStartSize(1.3f);
    effect.setEndSize(2f);
    effect.setShape(new EmitterSphereShape(Vector3f.ZERO, 1f));
    effect.setParticlesPerSec(0);
    effect.setGravity(0, -5f, 0);
    effect.setLowLife(.4f);
    effect.setHighLife(.5f);
    effect.setInitialVelocity(new Vector3f(0, 7, 0));
    effect.setVelocityVariation(1f);
    effect.setImagesX(2);
    effect.setImagesY(2);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
    mat.setTexture("Texture", assetManager.loadTexture("Effects/Explosion/flame.png"));
    effect.setMaterial(mat);
}
Also used : ParticleEmitter(com.jme3.effect.ParticleEmitter) ColorRGBA(com.jme3.math.ColorRGBA) Vector3f(com.jme3.math.Vector3f) EmitterSphereShape(com.jme3.effect.shapes.EmitterSphereShape) Material(com.jme3.material.Material)

Example 97 with Texture

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

the class TestHoveringTank method createTerrain.

private void createTerrain() {
    matRock = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
    matRock.setBoolean("useTriPlanarMapping", false);
    matRock.setBoolean("WardIso", true);
    matRock.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
    Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
    Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
    grass.setWrap(WrapMode.Repeat);
    matRock.setTexture("DiffuseMap", grass);
    matRock.setFloat("DiffuseMap_0_scale", 64);
    Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
    dirt.setWrap(WrapMode.Repeat);
    matRock.setTexture("DiffuseMap_1", dirt);
    matRock.setFloat("DiffuseMap_1_scale", 16);
    Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
    rock.setWrap(WrapMode.Repeat);
    matRock.setTexture("DiffuseMap_2", rock);
    matRock.setFloat("DiffuseMap_2_scale", 128);
    Texture normalMap0 = assetManager.loadTexture("Textures/Terrain/splat/grass_normal.jpg");
    normalMap0.setWrap(WrapMode.Repeat);
    Texture normalMap1 = assetManager.loadTexture("Textures/Terrain/splat/dirt_normal.png");
    normalMap1.setWrap(WrapMode.Repeat);
    Texture normalMap2 = assetManager.loadTexture("Textures/Terrain/splat/road_normal.png");
    normalMap2.setWrap(WrapMode.Repeat);
    matRock.setTexture("NormalMap", normalMap0);
    matRock.setTexture("NormalMap_1", normalMap2);
    matRock.setTexture("NormalMap_2", normalMap2);
    AbstractHeightMap heightmap = null;
    try {
        heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f);
        heightmap.load();
    } catch (Exception e) {
        e.printStackTrace();
    }
    terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());
    List<Camera> cameras = new ArrayList<Camera>();
    cameras.add(getCamera());
    TerrainLodControl control = new TerrainLodControl(terrain, cameras);
    terrain.addControl(control);
    terrain.setMaterial(matRock);
    terrain.setLocalScale(new Vector3f(2, 2, 2));
    // unlock it so we can edit the height
    terrain.setLocked(false);
    terrain.setShadowMode(ShadowMode.CastAndReceive);
    terrain.addControl(new RigidBodyControl(0));
    rootNode.attachChild(terrain);
    getPhysicsSpace().addAll(terrain);
}
Also used : AbstractHeightMap(com.jme3.terrain.heightmap.AbstractHeightMap) ArrayList(java.util.ArrayList) TerrainLodControl(com.jme3.terrain.geomipmap.TerrainLodControl) Material(com.jme3.material.Material) Camera(com.jme3.renderer.Camera) ChaseCamera(com.jme3.input.ChaseCamera) Texture(com.jme3.texture.Texture) TerrainQuad(com.jme3.terrain.geomipmap.TerrainQuad) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl) ImageBasedHeightMap(com.jme3.terrain.heightmap.ImageBasedHeightMap)

Example 98 with Texture

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

the class TextureUtil method uploadSubTexture.

/**
     * Update the texture currently bound to target at with data from the given Image at position x and y. The parameter
     * index is used as the zoffset in case a 3d texture or texture 2d array is being updated.
     *
     * @param image Image with the source data (this data will be put into the texture)
     * @param target the target texture
     * @param index the mipmap level to update
     * @param x the x position where to put the image in the texture
     * @param y the y position where to put the image in the texture
     */
public static void uploadSubTexture(Image image, int target, int index, int x, int y, boolean linearizeSrgb) {
    GL gl = GLContext.getCurrentGL();
    Image.Format fmt = image.getFormat();
    GLImageFormat glFmt = getImageFormatWithError(fmt, image.getColorSpace() == ColorSpace.sRGB && linearizeSrgb);
    ByteBuffer data = null;
    if (index >= 0 && image.getData() != null && image.getData().size() > 0) {
        data = image.getData(index);
    }
    int width = image.getWidth();
    int height = image.getHeight();
    int depth = image.getDepth();
    if (data != null) {
        gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
    }
    int[] mipSizes = image.getMipMapSizes();
    int pos = 0;
    // TODO: Remove unneccessary allocation
    if (mipSizes == null) {
        if (data != null) {
            mipSizes = new int[] { data.capacity() };
        } else {
            mipSizes = new int[] { width * height * fmt.getBitsPerPixel() / 8 };
        }
    }
    int samples = image.getMultiSamples();
    for (int i = 0; i < mipSizes.length; i++) {
        int mipWidth = Math.max(1, width >> i);
        int mipHeight = Math.max(1, height >> i);
        int mipDepth = Math.max(1, depth >> i);
        if (data != null) {
            data.position(pos);
            data.limit(pos + mipSizes[i]);
        }
        // to remove the cumbersome if/then/else stuff below we'll update the pos right here and use continue after each
        // gl*Image call in an attempt to unclutter things a bit
        pos += mipSizes[i];
        int glFmtInternal = glFmt.internalFormat;
        int glFmtFormat = glFmt.format;
        int glFmtDataType = glFmt.dataType;
        if (glFmt.compressed && data != null) {
            if (target == GL2ES2.GL_TEXTURE_3D) {
                gl.getGL2ES2().glCompressedTexSubImage3D(target, i, x, y, index, mipWidth, mipHeight, mipDepth, glFmtInternal, data.limit(), data);
                continue;
            }
            // all other targets use 2D: array, cubemap, 2d
            gl.getGL2ES2().glCompressedTexSubImage2D(target, i, x, y, mipWidth, mipHeight, glFmtInternal, data.limit(), data);
            continue;
        }
        if (target == GL2ES2.GL_TEXTURE_3D) {
            gl.getGL2ES2().glTexSubImage3D(target, i, x, y, index, mipWidth, mipHeight, mipDepth, glFmtFormat, glFmtDataType, data);
            continue;
        }
        if (samples > 1) {
            throw new IllegalStateException("Cannot update multisample textures");
        }
        gl.glTexSubImage2D(target, i, x, y, mipWidth, mipHeight, glFmtFormat, glFmtDataType, data);
        continue;
    }
}
Also used : GL(com.jogamp.opengl.GL) Format(com.jme3.texture.Image.Format) Image(com.jme3.texture.Image) ByteBuffer(java.nio.ByteBuffer)

Example 99 with Texture

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

the class J3MLoader method parseTextureType.

private Texture parseTextureType(final VarType type, final String value) {
    final List<String> textureValues = tokenizeTextureValue(value);
    final List<TextureOptionValue> textureOptionValues = parseTextureOptions(textureValues);
    TextureKey textureKey = null;
    // If there is only one token on the value, it must be the path to the texture.
    if (textureValues.size() == 1) {
        textureKey = new TextureKey(textureValues.get(0), false);
    } else {
        String texturePath = value.trim();
        // If there are no valid "new" texture options specified but the path is split into several parts, lets parse the old way.
        if (isTexturePathDeclaredTheTraditionalWay(textureOptionValues, texturePath)) {
            boolean flipY = false;
            if (texturePath.startsWith("Flip Repeat ") || texturePath.startsWith("Repeat Flip ")) {
                texturePath = texturePath.substring(12).trim();
                flipY = true;
            } else if (texturePath.startsWith("Flip ")) {
                texturePath = texturePath.substring(5).trim();
                flipY = true;
            } else if (texturePath.startsWith("Repeat ")) {
                texturePath = texturePath.substring(7).trim();
            }
            // Support path starting with quotes (double and single)
            if (texturePath.startsWith("\"") || texturePath.startsWith("'")) {
                texturePath = texturePath.substring(1);
            }
            // Support path ending with quotes (double and single)
            if (texturePath.endsWith("\"") || texturePath.endsWith("'")) {
                texturePath = texturePath.substring(0, texturePath.length() - 1);
            }
            textureKey = new TextureKey(texturePath, flipY);
        }
        if (textureKey == null) {
            textureKey = new TextureKey(textureValues.get(textureValues.size() - 1), false);
        }
        // Apply texture options to the texture key
        if (!textureOptionValues.isEmpty()) {
            for (final TextureOptionValue textureOptionValue : textureOptionValues) {
                textureOptionValue.applyToTextureKey(textureKey);
            }
        }
    }
    switch(type) {
        case Texture3D:
            textureKey.setTextureTypeHint(Texture.Type.ThreeDimensional);
            break;
        case TextureArray:
            textureKey.setTextureTypeHint(Texture.Type.TwoDimensionalArray);
            break;
        case TextureCubeMap:
            textureKey.setTextureTypeHint(Texture.Type.CubeMap);
            break;
    }
    textureKey.setGenerateMips(true);
    Texture texture;
    try {
        texture = assetManager.loadTexture(textureKey);
    } catch (AssetNotFoundException ex) {
        logger.log(Level.WARNING, "Cannot locate {0} for material {1}", new Object[] { textureKey, key });
        texture = null;
    }
    if (texture == null) {
        texture = new Texture2D(PlaceholderAssets.getPlaceholderImage(assetManager));
        texture.setKey(textureKey);
        texture.setName(textureKey.getName());
    }
    // Apply texture options to the texture
    if (!textureOptionValues.isEmpty()) {
        for (final TextureOptionValue textureOptionValue : textureOptionValues) {
            textureOptionValue.applyToTexture(texture);
        }
    }
    return texture;
}
Also used : Texture2D(com.jme3.texture.Texture2D) Texture(com.jme3.texture.Texture)

Example 100 with Texture

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

the class MikktspaceTangentGenerator method calcTexArea.

// returns the texture area times 2
static float calcTexArea(final MikkTSpaceContext mikkTSpace, final int[] indices) {
    final Vector3f t1 = getTexCoord(mikkTSpace, indices[0]);
    final Vector3f t2 = getTexCoord(mikkTSpace, indices[1]);
    final Vector3f t3 = getTexCoord(mikkTSpace, indices[2]);
    final float t21x = t2.x - t1.x;
    final float t21y = t2.y - t1.y;
    final float t31x = t3.x - t1.x;
    final float t31y = t3.y - t1.y;
    final float fSignedAreaSTx2 = t21x * t31y - t21y * t31x;
    return fSignedAreaSTx2 < 0 ? (-fSignedAreaSTx2) : fSignedAreaSTx2;
}
Also used : Vector3f(com.jme3.math.Vector3f)

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