Example usage for com.badlogic.gdx.graphics.g3d.utils MeshBuilder begin

List of usage examples for com.badlogic.gdx.graphics.g3d.utils MeshBuilder begin

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics.g3d.utils MeshBuilder begin.

Prototype

public void begin(final VertexAttributes attributes, int primitiveType) 

Source Link

Document

Begin building a mesh

Usage

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

License:Open Source License

public TilePermissionsGridDisplayable(Tile[][] tiles, TextureAtlas atlas) {
    this.atlas = atlas;

    MeshBuilder meshBuilder = new MeshBuilder();

    meshBuilder.begin(VertexAttributes.Usage.Position | VertexAttributes.Usage.TextureCoordinates,
            GL20.GL_TRIANGLES);/*from  w w  w. ja v a  2s .  c o m*/

    for (int y = 0; y < tiles.length; y++) {
        for (int x = 0; x < tiles[y].length; x++) {
            // TODO: Cache regions
            meshBuilder.setUVRange(atlas.findRegion(tiles[y][x].getPermissions().name()));

            meshBuilder.rect(x, y, 0, x + 1, y, 0, x + 1, y + 1, 0, x, y + 1, 0, 0, 0, 1);
        }
    }

    Mesh mesh = meshBuilder.end();

    ModelBuilder modelBuilder = new ModelBuilder();
    modelBuilder.begin();

    TextureAttribute diffuse = TextureAttribute.createDiffuse(atlas.getTextures().first());

    modelBuilder.part("grid", mesh, GL20.GL_TRIANGLES, new Material(diffuse));

    instance = new ModelInstance(modelBuilder.end());

    instance.transform.translate(0, 0, Z_OFFSET);
}