Example usage for com.badlogic.gdx.graphics.g3d.utils MeshPartBuilder box

List of usage examples for com.badlogic.gdx.graphics.g3d.utils MeshPartBuilder box

Introduction

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

Prototype

public void box(float x, float y, float z, float width, float height, float depth);

Source Link

Document

Add a box at the specified location, with the specified dimensions

Usage

From source file:graphics.CargoSpace3D.java

License:Apache License

private void drawCargoCube(ModelBuilder modelBuilder, List<Model> models, float x, float y, float z,
        Color cubeColor) {/*from  w  w w .ja va  2  s  .c  o  m*/
    MeshPartBuilder builder;
    modelBuilder.begin();
    //      builder = modelBuilder.part("grid",GL20.GL_TRIANGLES,Usage.Position | Usage.Normal,new Material(ColorAttribute.createDiffuse(new Color((MathUtils.random(0, 1)+0.1f), MathUtils.random(0, 1)+0.1f, MathUtils.random(0, 1)+0.1f, 0))));

    builder = modelBuilder.part("grid", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal,
            new Material(ColorAttribute.createDiffuse(cubeColor)));
    builder.setColor(Color.GREEN);
    builder.box(x, y, z, .9f, .9f, .9f);
    models.add(modelBuilder.end());

    instances.add(new ModelInstance(models.get(models.size() - 1)));
}

From source file:graphics.Shape3D.java

License:Apache License

@Override
public void create() {
    lights = new Environment();
    lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
    lights.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));

    modelBatch = new ModelBatch();

    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(10f, 10f, 10f);//from   w  w w. j  a  v  a 2  s  .  c o  m
    cam.lookAt(0, 0, 0);
    cam.near = 1f;
    cam.far = 300f;
    cam.update();

    //        ModelBuilder modelBuilder = new ModelBuilder();
    //        model = modelBuilder.createBox(5f, 5f, 5f, new Material(ColorAttribute.createDiffuse(Color.GREEN)),
    //        Usage.Position | Usage.Normal);
    //        instance = new ModelInstance(model);

    ModelBuilder modelBuilder = new ModelBuilder();
    MeshPartBuilder builder;

    List<Model> models = new ArrayList<Model>();
    instances = new ArrayList<ModelInstance>();

    for (float y = GRID_MIN; y <= GRID_MAX_Y; y += 1) {
        for (float x = GRID_MIN; x <= GRID_MAX_X; x += 1) {
            for (float z = GRID_MIN; z <= GRID_MAX_Z; z += 1) {

                if (aShape.getShape()[(int) y][(int) x][(int) z] != 0) {
                    modelBuilder.begin();
                    builder = modelBuilder.part("grid", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal,
                            new Material(ColorAttribute.createDiffuse(new Color(0.9f, 0.4f, 0.2f, 0))));
                    builder.setColor(Color.GREEN);
                    builder.box(y, x, z, 1f, 1f, 1f);
                    models.add(modelBuilder.end());

                    instances.add(new ModelInstance(models.get(models.size() - 1)));
                }
            }
        }
    }
    System.out.println("Done");

}