use of com.badlogic.gdx.graphics.g3d.utils.MeshBuilder in project libgdx by libgdx.
the class MeshBuilderTest method create.
@Override
public void create() {
super.create();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -0.5f, -1.0f, -0.8f));
modelsWindow.setVisible(false);
Texture texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
Material material = new Material(TextureAttribute.createDiffuse(texture));
MeshBuilder meshBuilder = new MeshBuilder();
meshBuilder.begin(Usage.Position | Usage.Normal | Usage.ColorPacked | Usage.TextureCoordinates, GL20.GL_TRIANGLES);
meshBuilder.box(1f, 1f, 1f);
Mesh mesh = new Mesh(true, meshBuilder.getNumVertices(), meshBuilder.getNumIndices(), meshBuilder.getAttributes());
mesh = meshBuilder.end(mesh);
ModelBuilder modelBuilder = new ModelBuilder();
modelBuilder.begin();
modelBuilder.manage(texture);
modelBuilder.node().id = "box";
MeshPartBuilder mpb = modelBuilder.part("box", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates | Usage.ColorPacked, material);
mpb.setColor(Color.RED);
mpb.box(1f, 1f, 1f);
modelBuilder.node().id = "sphere";
mpb = modelBuilder.part("sphere", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates | Usage.ColorPacked, material);
mpb.sphere(2f, 2f, 2f, 10, 5);
modelBuilder.node().id = "cone";
mpb = modelBuilder.part("cone", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates | Usage.ColorPacked, material);
mpb.setVertexTransform(new Matrix4().rotate(Vector3.X, -45f));
mpb.cone(2f, 3f, 1f, 8);
modelBuilder.node().id = "cylinder";
mpb = modelBuilder.part("cylinder", GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates | Usage.ColorPacked, material);
mpb.setUVRange(1f, 1f, 0f, 0f);
mpb.cylinder(2f, 4f, 3f, 15);
modelBuilder.node().id = "mesh";
mpb = modelBuilder.part("mesh", GL20.GL_TRIANGLES, mesh.getVertexAttributes(), material);
Matrix4 transform = new Matrix4();
mpb.setVertexTransform(transform.setToTranslation(0, 2, 0));
mpb.addMesh(mesh);
mpb.setColor(Color.BLUE);
mpb.setVertexTransform(transform.setToTranslation(1, 1, 0));
mpb.addMesh(mesh);
mpb.setColor(null);
mpb.setVertexTransform(transform.setToTranslation(-1, 1, 0).rotate(Vector3.X, 45));
mpb.addMesh(mesh);
mpb.setVertexTransform(transform.setToTranslation(0, 1, 1));
mpb.setUVRange(0.75f, 0.75f, 0.25f, 0.25f);
mpb.addMesh(mesh);
model = modelBuilder.end();
instances.add(new ModelInstance(model, new Matrix4().trn(0f, 0f, 0f), "mesh", true));
instances.add(new ModelInstance(model, new Matrix4().trn(-5f, 0f, -5f), "box", true));
instances.add(new ModelInstance(model, new Matrix4().trn(5f, 0f, -5f), "sphere", true));
instances.add(new ModelInstance(model, new Matrix4().trn(-5f, 0f, 5f), "cone", true));
instances.add(new ModelInstance(model, new Matrix4().trn(5f, 0f, 5f), "cylinder", true));
}
use of com.badlogic.gdx.graphics.g3d.utils.MeshBuilder in project libgdx by libgdx.
the class Animation3DTest method create.
@Override
public void create() {
super.create();
lights = new Environment();
lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
lights.add((shadowLight = new DirectionalShadowLight(1024, 1024, 30f, 30f, 1f, 100f)).set(0.8f, 0.8f, 0.8f, -.4f, -.4f, -.4f));
lights.shadowMap = shadowLight;
inputController.rotateLeftKey = inputController.rotateRightKey = inputController.forwardKey = inputController.backwardKey = 0;
cam.position.set(25, 25, 25);
cam.lookAt(0, 0, 0);
cam.update();
modelsWindow.setVisible(false);
assets.load("data/g3d/skydome.g3db", Model.class);
assets.load("data/g3d/concrete.png", Texture.class);
assets.load("data/tree.png", Texture.class);
assets.load("data/g3d/ship.obj", Model.class);
loading = true;
trForward.translation.set(0, 0, 8f);
trBackward.translation.set(0, 0, -8f);
trLeft.rotation.setFromAxis(Vector3.Y, 90);
trRight.rotation.setFromAxis(Vector3.Y, -90);
ModelBuilder builder = new ModelBuilder();
builder.begin();
builder.node().id = "floor";
MeshPartBuilder part = builder.part("floor", GL20.GL_TRIANGLES, Usage.Position | Usage.TextureCoordinates | Usage.Normal, new Material("concrete"));
((MeshBuilder) part).ensureRectangles(1600);
for (float x = -200f; x < 200f; x += 10f) {
for (float z = -200f; z < 200f; z += 10f) {
part.rect(x, 0, z + 10f, x + 10f, 0, z + 10f, x + 10f, 0, z, x, 0, z, 0, 1, 0);
}
}
builder.node().id = "tree";
part = builder.part("tree", GL20.GL_TRIANGLES, Usage.Position | Usage.TextureCoordinates | Usage.Normal, new Material("tree"));
part.rect(0f, 0f, -10f, 10f, 0f, -10f, 10f, 10f, -10f, 0f, 10f, -10f, 0, 0, 1f);
part.setUVRange(1, 0, 0, 1);
part.rect(10f, 0f, -10f, 0f, 0f, -10f, 0f, 10f, -10f, 10f, 10f, -10f, 0, 0, -1f);
floorModel = builder.end();
shadowBatch = new ModelBatch(new DepthShaderProvider());
}
Aggregations