Search in sources :

Example 1 with ModelBuilder

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

the class TextureRegion3DTest method create.

@Override
public void create() {
    Gdx.gl.glClearColor(0.2f, 0.3f, 1.0f, 0.f);
    atlas = new TextureAtlas(Gdx.files.internal("data/testpack"));
    regions = atlas.getRegions();
    modelBatch = new ModelBatch(new DefaultShaderProvider());
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(10f, 10f, 10f);
    cam.lookAt(0, 0, 0);
    cam.near = 0.1f;
    cam.far = 300f;
    cam.update();
    ModelBuilder modelBuilder = new ModelBuilder();
    final Material material = new Material(ColorAttribute.createDiffuse(1f, 1f, 1f, 1f), new TextureAttribute(TextureAttribute.Diffuse));
    model = modelBuilder.createBox(5f, 5f, 5f, material, Usage.Position | Usage.Normal | Usage.TextureCoordinates);
    instance = new ModelInstance(model);
    attribute = instance.materials.get(0).get(TextureAttribute.class, TextureAttribute.Diffuse);
    Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(cam)));
}
Also used : DefaultShaderProvider(com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider) Material(com.badlogic.gdx.graphics.g3d.Material) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) CameraInputController(com.badlogic.gdx.graphics.g3d.utils.CameraInputController) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Environment(com.badlogic.gdx.graphics.g3d.Environment) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) TextureAttribute(com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)

Example 2 with ModelBuilder

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

the class Basic3DTest method create.

@Override
public void create() {
    modelBatch = new ModelBatch(new DefaultShaderProvider());
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(10f, 10f, 10f);
    cam.lookAt(0, 0, 0);
    cam.near = 1f;
    cam.far = 30f;
    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);
    Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(cam)));
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) DefaultShaderProvider(com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) CameraInputController(com.badlogic.gdx.graphics.g3d.utils.CameraInputController) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) 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 3 with ModelBuilder

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

the class LightsTest method create.

@Override
public void create() {
    super.create();
    environment.clear();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.2f, 0.2f, 0.2f, 1.0f));
    environment.add(dirLight = new DirectionalLight().set(0.8f, 0.2f, 0.2f, -1f, -2f, -0.5f));
    environment.add(pointLight = new PointLight().set(0.2f, 0.8f, 0.2f, 0f, 0f, 0f, 100f));
    ModelBuilder mb = new ModelBuilder();
    lightModel = mb.createSphere(1, 1, 1, 10, 10, new Material(ColorAttribute.createDiffuse(1, 1, 1, 1)), Usage.Position);
    lightModel.nodes.get(0).parts.get(0).setRenderable(pLight = new Renderable());
}
Also used : ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) Renderable(com.badlogic.gdx.graphics.g3d.Renderable) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) Material(com.badlogic.gdx.graphics.g3d.Material) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) PointLight(com.badlogic.gdx.graphics.g3d.environment.PointLight)

Example 4 with ModelBuilder

use of com.badlogic.gdx.graphics.g3d.utils.ModelBuilder 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));
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) MeshBuilder(com.badlogic.gdx.graphics.g3d.utils.MeshBuilder) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) Environment(com.badlogic.gdx.graphics.g3d.Environment) Mesh(com.badlogic.gdx.graphics.Mesh) Material(com.badlogic.gdx.graphics.g3d.Material) MeshPartBuilder(com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) Texture(com.badlogic.gdx.graphics.Texture) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 5 with ModelBuilder

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

the class Scene method createModel.

public Model createModel(JsonValue model) {
    ModelBuilder builder = new ModelBuilder();
    builder.begin();
    short idx = 0;
    for (JsonValue mat : model) {
        Material m = materials.get(mat.name);
        if (mat.name.equals(defaultMaterial.id))
            m = new Material(m);
        MeshPartBuilder mpb = builder.part(model.name, GL20.GL_TRIANGLES, Usage.Position | Usage.Normal | Usage.TextureCoordinates, m);
        float[] verts = mat.asFloatArray();
        mpb.vertex(verts);
        int len = verts.length / Bdx.VERT_STRIDE;
        try {
            for (short i = 0; i < len; ++i) {
                mpb.index(idx);
                idx += 1;
            }
        } catch (Error e) {
            throw new RuntimeException("MODEL ERROR: Models with more than 32767 vertices are not supported. " + model.name + " has " + Integer.toString(len) + " vertices.");
        }
    }
    return builder.end();
}
Also used : ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) JsonValue(com.badlogic.gdx.utils.JsonValue) MeshPartBuilder(com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder)

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