Example usage for com.badlogic.gdx.graphics.g3d.attributes BlendingAttribute BlendingAttribute

List of usage examples for com.badlogic.gdx.graphics.g3d.attributes BlendingAttribute BlendingAttribute

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g3d.attributes BlendingAttribute BlendingAttribute.

Prototype

public BlendingAttribute(final boolean blended, final float opacity) 

Source Link

Usage

From source file:br.com.raphaelbruno.game.zombieinvaders.vr.model.GameObject.java

License:Apache License

public GameObject(ScreenBase context, Model model, BoundingBox bounds) {
    super(model);
    this.context = context;
    this.customBounds = bounds;

    this.bounds = this.customBounds != null ? this.customBounds : new BoundingBox();
    this.center = new Vector3();
    this.enabled = true;
    updateBox();// w w w.  java 2 s  .com

    this.animations = new AnimationController(this);
    this.blending = new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

    for (Material item : materials) {
        item.set(new DepthTestAttribute(GL20.GL_LEQUAL, 0.01f, 25f, true));
        item.set(FloatAttribute.createAlphaTest(0.01f));
        item.set(blending);
    }
}

From source file:com.badlogic.invaders.simulation.Simulation.java

License:Apache License

private void populate() {
    ObjLoader objLoader = new ObjLoader();
    shipModel = objLoader.loadModel(Gdx.files.internal("data/ship.obj"));
    invaderModel = objLoader.loadModel(Gdx.files.internal("data/invader.obj"));
    blockModel = objLoader.loadModel(Gdx.files.internal("data/block.obj"));
    shotModel = objLoader.loadModel(Gdx.files.internal("data/shot.obj"));

    final Texture shipTexture = new Texture(Gdx.files.internal("data/ship.png"), Format.RGB565, true);
    shipTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);
    final Texture invaderTexture = new Texture(Gdx.files.internal("data/invader.png"), Format.RGB565, true);
    invaderTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);
    shipModel.materials.get(0).set(TextureAttribute.createDiffuse(shipTexture));
    invaderModel.materials.get(0).set(TextureAttribute.createDiffuse(invaderTexture));

    ((ColorAttribute) blockModel.materials.get(0).get(ColorAttribute.Diffuse)).color.set(0, 0, 1, 0.5f);
    blockModel.materials.get(0).set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));

    shotModel.materials.get(0).set(ColorAttribute.createDiffuse(1, 1, 0, 1f));

    final Texture explosionTexture = new Texture(Gdx.files.internal("data/explode.png"), Format.RGBA4444, true);
    explosionTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);

    final Mesh explosionMesh = new Mesh(true, 4 * 16, 6 * 16,
            new VertexAttribute(Usage.Position, 3, "a_position"),
            new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoord0"));

    float[] vertices = new float[4 * 16 * (3 + 2)];
    short[] indices = new short[6 * 16];
    int idx = 0;/*from  w ww.j av a2  s  .co m*/
    int index = 0;
    for (int row = 0; row < 4; row++) {
        for (int column = 0; column < 4; column++) {
            vertices[idx++] = 1;
            vertices[idx++] = 1;
            vertices[idx++] = 0;
            vertices[idx++] = 0.25f + column * 0.25f;
            vertices[idx++] = 0 + row * 0.25f;

            vertices[idx++] = -1;
            vertices[idx++] = 1;
            vertices[idx++] = 0;
            vertices[idx++] = 0 + column * 0.25f;
            vertices[idx++] = 0 + row * 0.25f;

            vertices[idx++] = -1;
            vertices[idx++] = -1;
            vertices[idx++] = 0;
            vertices[idx++] = 0f + column * 0.25f;
            vertices[idx++] = 0.25f + row * 0.25f;

            vertices[idx++] = 1;
            vertices[idx++] = -1;
            vertices[idx++] = 0;
            vertices[idx++] = 0.25f + column * 0.25f;
            vertices[idx++] = 0.25f + row * 0.25f;

            final int t = (4 * row + column) * 4;
            indices[index++] = (short) (t);
            indices[index++] = (short) (t + 1);
            indices[index++] = (short) (t + 2);
            indices[index++] = (short) (t);
            indices[index++] = (short) (t + 2);
            indices[index++] = (short) (t + 3);
        }
    }

    explosionMesh.setVertices(vertices);
    explosionMesh.setIndices(indices);

    explosionModel = ModelBuilder.createFromMesh(explosionMesh, GL20.GL_TRIANGLES,
            new Material(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA),
                    TextureAttribute.createDiffuse(explosionTexture)));

    ship = new Ship(shipModel);
    ship.transform.rotate(0, 1, 0, 180);

    for (int row = 0; row < 4; row++) {
        for (int column = 0; column < 8; column++) {
            Invader invader = new Invader(invaderModel, -PLAYFIELD_MAX_X / 2 + column * 2f, 0,
                    PLAYFIELD_MIN_Z + row * 2f);
            invaders.add(invader);
        }
    }

    for (int shield = 0; shield < 3; shield++) {
        blocks.add(new Block(blockModel, -10 + shield * 10 - 1, 0, -2));
        blocks.add(new Block(blockModel, -10 + shield * 10 - 1, 0, -3));
        blocks.add(new Block(blockModel, -10 + shield * 10 + 0, 0, -3));
        blocks.add(new Block(blockModel, -10 + shield * 10 + 1, 0, -3));
        blocks.add(new Block(blockModel, -10 + shield * 10 + 1, 0, -2));
    }
}

From source file:com.bladecoder.engine.util.Utils3D.java

License:Apache License

public static void createFloor() {

    ModelBuilder modelBuilder = new ModelBuilder();
    modelBuilder.begin();/* w w  w  .java  2s  .co m*/
    MeshPartBuilder mpb = modelBuilder.part("parts", GL20.GL_TRIANGLES,
            Usage.Position | Usage.Normal | Usage.ColorUnpacked,
            new Material(ColorAttribute.createDiffuse(Color.WHITE)));
    mpb.setColor(1f, 1f, 1f, 1f);
    //      mpb.box(0, -0.1f, 0, 10, .2f, 10);
    mpb.rect(-10, 0, -10, -10, 0, 10, 10, 0, 10, 10, 0, -10, 0, 1, 0);
    floorModel = modelBuilder.end();
    floorInstance = new ModelInstance(floorModel);

    // TODO Set only when FBO is active
    floorInstance.materials.get(0).set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));
}

From source file:com.github.fauu.helix.core.Object.java

License:Open Source License

public Object(Vector2 position, String modelName, Model model, int elevation, Direction facing) {
    this.position = position;
    this.elevation = elevation;
    this.modelInstance = new ModelInstance(model);
    this.modelName = modelName;
    this.facing = facing;

    modelInstance.transform.setToTranslation(position.x, elevation, position.y + 1).rotate(new Vector3(0, 1, 0),
            -90);/*from  w  ww  .ja  v  a 2  s  .  c om*/

    final TextureAttribute textureAttribute = (TextureAttribute) modelInstance.materials.first()
            .get(TextureAttribute.Diffuse);
    textureAttribute.textureDescription.magFilter = Texture.TextureFilter.Nearest;
    textureAttribute.textureDescription.minFilter = Texture.TextureFilter.Nearest;
    modelInstance.materials.first().set(textureAttribute);

    modelInstance.materials.first().set(new ColorAttribute(ColorAttribute.createDiffuse(Color.WHITE)));
    modelInstance.materials.first().set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));
    //modelInstance.materials.first().set(new FloatAttribute(FloatAttribute.AlphaTest, 0.14f));
}

From source file:com.github.fauu.helix.displayable.AreaDisplayable.java

License:Open Source License

public AreaDisplayable(Model model) {
    instance = new ModelInstance(model);

    animationController = new AnimationController(instance);

    instance.transform.rotate(new Vector3(1, 0, 0), 90);

    for (Material material : instance.materials) {
        TextureAttribute ta = (TextureAttribute) material.get(TextureAttribute.Diffuse);

        ta.textureDescription.magFilter = Texture.TextureFilter.Nearest;
        ta.textureDescription.minFilter = Texture.TextureFilter.Nearest;

        material.set(ta);/*from  w  w  w . j ava2  s. co  m*/
        material.set(ColorAttribute.createDiffuse(Color.WHITE));

        BlendingAttribute ba = new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);

        material.set(ba);
    }
}

From source file:com.github.fauu.helix.editor.displayable.TileHighlightDisplayable.java

License:Open Source License

public TileHighlightDisplayable() {
    ModelBuilder modelBuilder = new ModelBuilder();

    Model model = modelBuilder.createRect(0, 0, Z_OFFSET, 1, 0, Z_OFFSET, 1, 1, Z_OFFSET, 0, 1, Z_OFFSET, 0, 0,
            1, GL20.GL_TRIANGLES,/*w ww .j  ava  2s  .  c  om*/
            new Material(new ColorAttribute(ColorAttribute.createDiffuse(color)),
                    new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)),
            VertexAttributes.Usage.Position | VertexAttributes.Usage.TextureCoordinates);

    instance = new ModelInstance(model);
}

From source file:com.github.fauu.helix.game.Game.java

License:Open Source License

@Override
public void create() {
    camera = new Camera(new Vector3(32, 32, 0));

    cameraInputController = new CameraInputController(camera);
    //    Gdx.input.setInputProcessor(cameraInputController);

    assets = new AssetManager();
    assets.setLoader(GeometrySet.class, new GeometrySetLoader(new InternalFileHandleResolver()));
    assets.setLoader(MapRegion.class, new MapRegionLoader(new InternalFileHandleResolver()));
    assets.load("assets/mapregions/0.hmr", MapRegion.class);
    assets.finishLoading();/*from  www .j  av  a  2s.co  m*/

    mapRegion = assets.get("assets/mapregions/0.hmr", MapRegion.class);

    spriteBatch = new SpriteBatch();

    renderer = new Renderer();

    player = new Player(new Vector2(8, 17), new Texture(Gdx.files.internal("assets/sprites/player.png")));
    camera.move(player.getRealPosition());

    final ModelBuilder modelBuilder = new ModelBuilder();

    waterTexture = new Texture("assets/textures/water.png");

    final MeshPartBuilder.VertexInfo corner00 = new MeshPartBuilder.VertexInfo();
    corner00.hasPosition = true;
    corner00.hasNormal = true;
    corner00.hasUV = true;
    corner00.setPos(0, 0, 0);
    corner00.setNor(0, 1, 0);
    corner00.setUV(0, 0);

    final MeshPartBuilder.VertexInfo corner10 = new MeshPartBuilder.VertexInfo();
    corner10.hasPosition = true;
    corner10.hasNormal = true;
    corner10.hasUV = true;
    corner10.setPos(4, 0, 0);
    corner10.setNor(0, 1, 0);
    corner10.setUV(0, 1);

    final MeshPartBuilder.VertexInfo corner11 = new MeshPartBuilder.VertexInfo();
    corner11.hasPosition = true;
    corner11.hasNormal = true;
    corner11.hasUV = true;
    corner11.setPos(4, 0, 14);
    corner11.setNor(0, 1, 0);
    corner11.setUV(1, 1);

    final MeshPartBuilder.VertexInfo corner01 = new MeshPartBuilder.VertexInfo();
    corner01.hasPosition = true;
    corner01.hasNormal = true;
    corner01.hasUV = true;
    corner01.setPos(0, 0, 14);
    corner01.setNor(0, 1, 0);
    corner01.setUV(1, 0);

    modelBuilder.begin();
    modelBuilder.node();
    MeshPartBuilder meshPartBuilder = modelBuilder.part("water1", GL20.GL_TRIANGLES,
            VertexAttributes.Usage.Position | VertexAttributes.Usage.TextureCoordinates,
            new Material(TextureAttribute.createDiffuse(waterTexture),
                    ColorAttribute.createDiffuse(Color.WHITE),
                    new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)));
    meshPartBuilder.rect(corner00, corner10, corner11, corner01);

    waterModel = modelBuilder.end();

    waterModelInstance = new ModelInstance(waterModel);
    WaterData waterData = new WaterData();
    waterData.waveAmplitude = 0.02f;
    waterData.waveAngle = 0;
    waterData.waveFrequency = 0.5f;
    waterModelInstance.userData = waterData;
    //    waterModelInstance.userData = new float[2];
    //    ((float[]) waterModelInstance.userData)[0] = 0; // waveAngle
    //    ((float[]) waterModelInstance.userData)[1] = 0.1f; // waveAmplitude

    waterModelInstance.transform.translate(8, -0.1f, 19).rotate(0, 1, 0, -90).scale(1, 1, -1);
    //    ((float[]) waterModelInstance.userData)[2] = 8; // startX
    //    ((float[]) waterModelInstance.userData)[3] = 7; // sizeX
    //    ((float[]) waterModelInstance.userData)[4] = 19; // startZ
    //    ((float[]) waterModelInstance.userData)[5] = 5; // sizeZ
}

From source file:com.mygdx.game.simulation.Simulation.java

License:Apache License

private void populate() {
    ObjLoader objLoader = new ObjLoader();

    for (int i = 0; i < MAX_SHIPS; i++) {
        shipModels[i] = objLoader.loadModel(Gdx.files.internal("data/ship.obj"));
    }/*from  w ww . jav a2s .c o m*/
    invaderModel = objLoader.loadModel(Gdx.files.internal("data/invader.obj"));
    blockModel = objLoader.loadModel(Gdx.files.internal("data/block.obj"));
    shotModel = objLoader.loadModel(Gdx.files.internal("data/shot.obj"));

    final Texture shipTexture = new Texture(Gdx.files.internal("data/ship.png"), Format.RGB565, true);
    shipTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);
    final Texture shipTexture2 = new Texture(Gdx.files.internal("data/ship.png"), Format.RGB565, true);
    shipTexture2.setFilter(TextureFilter.MipMap, TextureFilter.Linear);
    final Texture invaderTexture = new Texture(Gdx.files.internal("data/invader.png"), Format.RGB565, true);
    invaderTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);

    for (int i = 0; i < MAX_SHIPS; i++) {
        shipModels[i].materials.get(0).set(TextureAttribute.createDiffuse(shipTexture));
    }
    invaderModel.materials.get(0).set(TextureAttribute.createDiffuse(invaderTexture));

    ((ColorAttribute) blockModel.materials.get(0).get(ColorAttribute.Diffuse)).color.set(0, 0, 1, 0.5f);
    blockModel.materials.get(0).set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));

    shotModel.materials.get(0).set(ColorAttribute.createDiffuse(1, 1, 0, 1f));

    final Texture explosionTexture = new Texture(Gdx.files.internal("data/explode.png"), Format.RGBA4444, true);
    explosionTexture.setFilter(TextureFilter.MipMap, TextureFilter.Linear);

    final Mesh explosionMesh = new Mesh(true, 4 * 16, 6 * 16,
            new VertexAttribute(Usage.Position, 3, "a_position"),
            new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoord0"));

    float[] vertices = new float[4 * 16 * (3 + 2)];
    short[] indices = new short[6 * 16];
    int idx = 0;
    int index = 0;
    for (int row = 0; row < 4; row++) {
        for (int column = 0; column < 4; column++) {
            vertices[idx++] = 1;
            vertices[idx++] = 1;
            vertices[idx++] = 0;
            vertices[idx++] = 0.25f + column * 0.25f;
            vertices[idx++] = 0 + row * 0.25f;

            vertices[idx++] = -1;
            vertices[idx++] = 1;
            vertices[idx++] = 0;
            vertices[idx++] = 0 + column * 0.25f;
            vertices[idx++] = 0 + row * 0.25f;

            vertices[idx++] = -1;
            vertices[idx++] = -1;
            vertices[idx++] = 0;
            vertices[idx++] = 0f + column * 0.25f;
            vertices[idx++] = 0.25f + row * 0.25f;

            vertices[idx++] = 1;
            vertices[idx++] = -1;
            vertices[idx++] = 0;
            vertices[idx++] = 0.25f + column * 0.25f;
            vertices[idx++] = 0.25f + row * 0.25f;

            final int t = (4 * row + column) * 4;
            indices[index++] = (short) (t);
            indices[index++] = (short) (t + 1);
            indices[index++] = (short) (t + 2);
            indices[index++] = (short) (t);
            indices[index++] = (short) (t + 2);
            indices[index++] = (short) (t + 3);
        }
    }

    explosionMesh.setVertices(vertices);
    explosionMesh.setIndices(indices);

    Material explosionMeshMaterial = new Material(
            new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA),
            TextureAttribute.createDiffuse(explosionTexture));
    explosionModel = new Model();
    MeshPart meshPart = new MeshPart();
    meshPart.id = "part1";
    meshPart.offset = 0;
    meshPart.size = explosionMesh.getNumIndices();
    meshPart.primitiveType = GL20.GL_TRIANGLES;
    meshPart.mesh = explosionMesh;

    NodePart partMaterial = new NodePart();
    partMaterial.material = explosionMeshMaterial;
    partMaterial.meshPart = meshPart;
    Node node = new Node();
    node.id = "node1";
    node.parts.add(partMaterial);

    explosionModel.meshes.add(explosionMesh);
    explosionModel.materials.add(explosionMeshMaterial);
    explosionModel.nodes.add(node);
    explosionModel.meshParts.add(meshPart);
    explosionModel.manageDisposable(explosionMesh);

    for (int i = 0; i < MAX_SHIPS; i++) {
        ships[i] = new Ship(shipModels[i]);
        ships[i].transform.rotate(1, 0, 0, 180);
    }

    for (int row = 0; row < 4; row++) {
        for (int column = 0; column < 8; column++) {
            Invader invader = new Invader(invaderModel, -PLAYFIELD_MAX_X / 2 + column * 2f, 0,
                    PLAYFIELD_MIN_Z + row * 2f);
            invaders.add(invader);
        }
    }

    for (int shield = 0; shield < 3; shield++) {
        blocks.add(new Block(blockModel, -10 + shield * 10 - 1, 0, -2));
        blocks.add(new Block(blockModel, -10 + shield * 10 - 1, 0, -3));
        blocks.add(new Block(blockModel, -10 + shield * 10 + 0, 0, -3));
        blocks.add(new Block(blockModel, -10 + shield * 10 + 1, 0, -3));
        blocks.add(new Block(blockModel, -10 + shield * 10 + 1, 0, -2));
    }
}

From source file:com.nsoft.boxuniverse.misc.BaseMaterial.java

License:Open Source License

public BaseMaterial(String name) {

    materialName = name;//from ww w  . j a  v  a2s .  c om
    material = materials.materials.get(name);
    t = new Texture(Gdx.files.internal(material.path));

    RealMaterial = new Material(TextureAttribute.createDiffuse(t)); //Create GD3 Material

    if (material.hasAlpha)
        RealMaterial.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA)); //Set Alpha
    worldmaterials.put(name, this); // Add Material

    System.out.println("New Material Created");
}

From source file:com.zombie.game.actors.SteeringActor.java

License:Apache License

public void setModelInstance(ModelInstance modelInstance) {
    this.modelInstance = modelInstance;
    this.transform = modelInstance.transform.val;
    for (Material m : modelInstance.materials) {
        m.set(new IntAttribute(IntAttribute.CullFace, GL20.GL_NONE));
        m.set(new FloatAttribute(FloatAttribute.AlphaTest, 0.5f));
        m.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA));
    }//from   w w  w  .java2  s .  c  o m
    //Get animations if any
    if (modelInstance.animations.size > 0) {
        animationController = new AnimationController(modelInstance);
        animationController.allowSameAnimation = true;
        animationController.animate(modelInstance.animations.get(0).id, -1, 1f, this, 1f);
    }
}