Search in sources :

Example 6 with ModelBuilder

use of com.badlogic.gdx.graphics.g3d.utils.ModelBuilder in project libgdx by libgdx.

the class ViewportTest3 method create.

public void create() {
    modelBatch = new ModelBatch();
    modelBuilder = new ModelBuilder();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.f));
    shadowLight = new DirectionalLight();
    shadowLight.set(0.8f, 0.8f, 0.8f, -0.5f, -1f, 0.7f);
    environment.add(shadowLight);
    modelBatch = new ModelBatch();
    camera = new PerspectiveCamera();
    camera.fieldOfView = 67;
    camera.near = 0.1f;
    camera.far = 300f;
    camera.position.set(0, 0, 100);
    camera.lookAt(0, 0, 0);
    viewports = ViewportTest1.getViewports(camera);
    viewport = viewports.first();
    names = ViewportTest1.getViewportNames();
    name = names.first();
    ModelBuilder modelBuilder = new ModelBuilder();
    Model boxModel = modelBuilder.createBox(50f, 50f, 50f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position | Usage.Normal);
    boxInstance = new ModelInstance(boxModel);
    boxInstance.transform.rotate(1, 0, 0, 30);
    boxInstance.transform.rotate(0, 1, 0, 30);
    Gdx.input.setInputProcessor(new InputAdapter() {

        public boolean keyDown(int keycode) {
            if (keycode == Input.Keys.SPACE) {
                int index = (viewports.indexOf(viewport, true) + 1) % viewports.size;
                name = names.get(index);
                viewport = viewports.get(index);
                resize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
            }
            return false;
        }
    });
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) InputAdapter(com.badlogic.gdx.InputAdapter) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Model(com.badlogic.gdx.graphics.g3d.Model) Environment(com.badlogic.gdx.graphics.g3d.Environment) Material(com.badlogic.gdx.graphics.g3d.Material) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)

Example 7 with ModelBuilder

use of com.badlogic.gdx.graphics.g3d.utils.ModelBuilder in project libgdx by libgdx.

the class SoftBodyTest method create.

@Override
public void create() {
    super.create();
    world.add("ground", 0f, 0f, 0f).setColor(0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 1f);
    float x0 = -2f, y0 = 6f, z0 = -2f;
    float x1 = 8f, y1 = 6f, z1 = 8f;
    Vector3 patch00 = new Vector3(x0, y0, z0);
    Vector3 patch10 = new Vector3(x1, y1, z0);
    Vector3 patch01 = new Vector3(x0, y0, z1);
    Vector3 patch11 = new Vector3(x1, y1, z1);
    softBody = btSoftBodyHelpers.CreatePatch(worldInfo, patch00, patch10, patch01, patch11, 15, 15, 15, false);
    softBody.takeOwnership();
    softBody.setTotalMass(100f);
    ((btSoftRigidDynamicsWorld) (world.collisionWorld)).addSoftBody(softBody);
    final int vertCount = softBody.getNodeCount();
    final int faceCount = softBody.getFaceCount();
    mesh = new Mesh(false, vertCount, faceCount * 3, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
    final int vertSize = mesh.getVertexSize() / 4;
    mesh.getVerticesBuffer().position(0);
    mesh.getVerticesBuffer().limit(vertCount * vertSize);
    mesh.getIndicesBuffer().position(0);
    mesh.getIndicesBuffer().limit(faceCount * 3);
    softBody.getVertices(mesh.getVerticesBuffer(), vertCount, mesh.getVertexSize(), 0);
    softBody.getIndices(mesh.getIndicesBuffer(), faceCount);
    final float[] verts = new float[vertCount * vertSize];
    final int uvOffset = mesh.getVertexAttribute(Usage.TextureCoordinates).offset / 4;
    final int normalOffset = mesh.getVertexAttribute(Usage.Normal).offset / 4;
    mesh.getVertices(verts);
    for (int i = 0; i < vertCount; i++) {
        verts[i * vertSize + normalOffset] = 0f;
        verts[i * vertSize + normalOffset + 1] = 1f;
        verts[i * vertSize + normalOffset + 2] = 0f;
        verts[i * vertSize + uvOffset] = (verts[i * vertSize] - x0) / (x1 - x0);
        verts[i * vertSize + uvOffset + 1] = (verts[i * vertSize + 2] - z0) / (z1 - z0);
    }
    mesh.setVertices(verts);
    texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    ModelBuilder builder = new ModelBuilder();
    builder.begin();
    builder.part(new MeshPart("", mesh, 0, mesh.getNumIndices(), GL20.GL_TRIANGLES), new Material(TextureAttribute.createDiffuse(texture), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(64f), IntAttribute.createCullFace(0)));
    model = builder.end();
    instance = new ModelInstance(model);
    world.add(new BulletEntity(instance, null));
}
Also used : com.badlogic.gdx.physics.bullet.softbody.btSoftRigidDynamicsWorld(com.badlogic.gdx.physics.bullet.softbody.btSoftRigidDynamicsWorld) Mesh(com.badlogic.gdx.graphics.Mesh) Vector3(com.badlogic.gdx.math.Vector3) Material(com.badlogic.gdx.graphics.g3d.Material) MeshPart(com.badlogic.gdx.graphics.g3d.model.MeshPart) Texture(com.badlogic.gdx.graphics.Texture) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) VertexAttribute(com.badlogic.gdx.graphics.VertexAttribute)

Example 8 with ModelBuilder

use of com.badlogic.gdx.graphics.g3d.utils.ModelBuilder 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());
}
Also used : ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) DirectionalShadowLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalShadowLight) MeshBuilder(com.badlogic.gdx.graphics.g3d.utils.MeshBuilder) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Environment(com.badlogic.gdx.graphics.g3d.Environment) Material(com.badlogic.gdx.graphics.g3d.Material) MeshPartBuilder(com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) DepthShaderProvider(com.badlogic.gdx.graphics.g3d.utils.DepthShaderProvider)

Example 9 with ModelBuilder

use of com.badlogic.gdx.graphics.g3d.utils.ModelBuilder in project libgdx by libgdx.

the class BaseG3dTest method createAxes.

private void createAxes() {
    ModelBuilder modelBuilder = new ModelBuilder();
    modelBuilder.begin();
    MeshPartBuilder builder = modelBuilder.part("grid", GL20.GL_LINES, Usage.Position | Usage.ColorUnpacked, new Material());
    builder.setColor(Color.LIGHT_GRAY);
    for (float t = GRID_MIN; t <= GRID_MAX; t += GRID_STEP) {
        builder.line(t, 0, GRID_MIN, t, 0, GRID_MAX);
        builder.line(GRID_MIN, 0, t, GRID_MAX, 0, t);
    }
    builder = modelBuilder.part("axes", GL20.GL_LINES, Usage.Position | Usage.ColorUnpacked, new Material());
    builder.setColor(Color.RED);
    builder.line(0, 0, 0, 100, 0, 0);
    builder.setColor(Color.GREEN);
    builder.line(0, 0, 0, 0, 100, 0);
    builder.setColor(Color.BLUE);
    builder.line(0, 0, 0, 0, 0, 100);
    axesModel = modelBuilder.end();
    axesInstance = new ModelInstance(axesModel);
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) Material(com.badlogic.gdx.graphics.g3d.Material) MeshPartBuilder(com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder)

Example 10 with ModelBuilder

use of com.badlogic.gdx.graphics.g3d.utils.ModelBuilder in project libgdx by libgdx.

the class FrustumCullingTest method createFrustumModel.

public static Model createFrustumModel(final Vector3... p) {
    ModelBuilder builder = new ModelBuilder();
    builder.begin();
    MeshPartBuilder mpb = builder.part("", GL20.GL_LINES, Usage.Position | Usage.Normal, new Material(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE)));
    mpb.vertex(p[0].x, p[0].y, p[0].z, 0, 0, 1, p[1].x, p[1].y, p[1].z, 0, 0, 1, p[2].x, p[2].y, p[2].z, 0, 0, 1, p[3].x, p[3].y, p[3].z, 0, 0, // near
    1, p[4].x, p[4].y, p[4].z, 0, 0, -1, p[5].x, p[5].y, p[5].z, 0, 0, -1, p[6].x, p[6].y, p[6].z, 0, 0, -1, p[7].x, p[7].y, p[7].z, 0, 0, -1);
    mpb.index((short) 0, (short) 1, (short) 1, (short) 2, (short) 2, (short) 3, (short) 3, (short) 0);
    mpb.index((short) 4, (short) 5, (short) 5, (short) 6, (short) 6, (short) 7, (short) 7, (short) 4);
    mpb.index((short) 0, (short) 4, (short) 1, (short) 5, (short) 2, (short) 6, (short) 3, (short) 7);
    return builder.end();
}
Also used : ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) Material(com.badlogic.gdx.graphics.g3d.Material) MeshPartBuilder(com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)

Aggregations

ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)20 Material (com.badlogic.gdx.graphics.g3d.Material)17 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)13 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)12 Environment (com.badlogic.gdx.graphics.g3d.Environment)10 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)10 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)9 MeshPartBuilder (com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder)9 DirectionalLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalLight)7 CameraInputController (com.badlogic.gdx.graphics.g3d.utils.CameraInputController)6 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)5 Texture (com.badlogic.gdx.graphics.Texture)4 Model (com.badlogic.gdx.graphics.g3d.Model)4 DefaultShaderProvider (com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider)4 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)3 Renderable (com.badlogic.gdx.graphics.g3d.Renderable)3 Vector3 (com.badlogic.gdx.math.Vector3)3 JsonValue (com.badlogic.gdx.utils.JsonValue)3 Mesh (com.badlogic.gdx.graphics.Mesh)2 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)2