Search in sources :

Example 6 with Environment

use of com.badlogic.gdx.graphics.g3d.Environment 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 7 with Environment

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

the class Benchmark3DTest method randomizeLights.

protected void randomizeLights() {
    int pointLights = MathUtils.random(5);
    int directionalLights = MathUtils.random(5);
    DefaultShader.Config config = new Config();
    config.numDirectionalLights = directionalLights;
    config.numPointLights = pointLights;
    config.numSpotLights = 0;
    modelBatch.dispose();
    modelBatch = new ModelBatch(new DefaultShaderProvider(config));
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
    for (int i = 0; i < pointLights; i++) {
        environment.add(new PointLight().set(randomColor(), randomPosition(), MathUtils.random(10f)));
    }
    for (int i = 0; i < directionalLights; i++) {
        environment.add(new DirectionalLight().set(randomColor(), randomPosition()));
    }
}
Also used : DefaultShaderProvider(com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider) Config(com.badlogic.gdx.graphics.g3d.shaders.DefaultShader.Config) 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) PointLight(com.badlogic.gdx.graphics.g3d.environment.PointLight) Config(com.badlogic.gdx.graphics.g3d.shaders.DefaultShader.Config) DefaultShader(com.badlogic.gdx.graphics.g3d.shaders.DefaultShader)

Example 8 with Environment

use of com.badlogic.gdx.graphics.g3d.Environment 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 9 with Environment

use of com.badlogic.gdx.graphics.g3d.Environment 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 10 with Environment

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

the class BasicBulletTest method create.

@Override
public void create() {
    super.create();
    instructions = "Swipe for next test";
    lights = new Environment();
    lights.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.2f, 0.2f, 0.2f, 1.f));
    lights.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -0.5f, -1f, -0.7f));
    // Set up the camera
    final float width = Gdx.graphics.getWidth();
    final float height = Gdx.graphics.getHeight();
    if (width > height)
        camera = new PerspectiveCamera(67f, 3f * width / height, 3f);
    else
        camera = new PerspectiveCamera(67f, 3f, 3f * height / width);
    camera.position.set(10f, 10f, 10f);
    camera.lookAt(0, 0, 0);
    camera.update();
    // Create the model batch
    modelBatch = new ModelBatch();
    // Create some basic models
    final Model groundModel = modelBuilder.createRect(20f, 0f, -20f, -20f, 0f, -20f, -20f, 0f, 20f, 20f, 0f, 20f, 0, 1, 0, new Material(ColorAttribute.createDiffuse(Color.BLUE), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(16f)), Usage.Position | Usage.Normal);
    models.add(groundModel);
    final Model sphereModel = modelBuilder.createSphere(1f, 1f, 1f, 10, 10, new Material(ColorAttribute.createDiffuse(Color.RED), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(64f)), Usage.Position | Usage.Normal);
    models.add(sphereModel);
    // Load the bullet library
    // Normally use: Bullet.init();
    BaseBulletTest.init();
    // Create the bullet world
    collisionConfiguration = new btDefaultCollisionConfiguration();
    dispatcher = new btCollisionDispatcher(collisionConfiguration);
    broadphase = new btDbvtBroadphase();
    solver = new btSequentialImpulseConstraintSolver();
    collisionWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfiguration);
    collisionWorld.setGravity(gravity);
    // Create the shapes and body construction infos
    btCollisionShape groundShape = new btBoxShape(tempVector.set(20, 0, 20));
    shapes.add(groundShape);
    btRigidBodyConstructionInfo groundInfo = new btRigidBodyConstructionInfo(0f, null, groundShape, Vector3.Zero);
    bodyInfos.add(groundInfo);
    btCollisionShape sphereShape = new btSphereShape(0.5f);
    shapes.add(sphereShape);
    sphereShape.calculateLocalInertia(1f, tempVector);
    btRigidBodyConstructionInfo sphereInfo = new btRigidBodyConstructionInfo(1f, null, sphereShape, tempVector);
    bodyInfos.add(sphereInfo);
    // Create the ground
    ModelInstance ground = new ModelInstance(groundModel);
    instances.add(ground);
    btDefaultMotionState groundMotionState = new btDefaultMotionState();
    groundMotionState.setWorldTransform(ground.transform);
    motionStates.add(groundMotionState);
    btRigidBody groundBody = new btRigidBody(groundInfo);
    groundBody.setMotionState(groundMotionState);
    bodies.add(groundBody);
    collisionWorld.addRigidBody(groundBody);
    // Create the spheres
    for (float x = -10f; x <= 10f; x += 2f) {
        for (float y = 5f; y <= 15f; y += 2f) {
            for (float z = 0f; z <= 0f; z += 2f) {
                ModelInstance sphere = new ModelInstance(sphereModel);
                instances.add(sphere);
                sphere.transform.trn(x + 0.1f * MathUtils.random(), y + 0.1f * MathUtils.random(), z + 0.1f * MathUtils.random());
                btDefaultMotionState sphereMotionState = new btDefaultMotionState();
                sphereMotionState.setWorldTransform(sphere.transform);
                motionStates.add(sphereMotionState);
                btRigidBody sphereBody = new btRigidBody(sphereInfo);
                sphereBody.setMotionState(sphereMotionState);
                bodies.add(sphereBody);
                collisionWorld.addRigidBody(sphereBody);
            }
        }
    }
}
Also used : com.badlogic.gdx.physics.bullet.collision.btBoxShape(com.badlogic.gdx.physics.bullet.collision.btBoxShape) com.badlogic.gdx.physics.bullet.collision.btCollisionDispatcher(com.badlogic.gdx.physics.bullet.collision.btCollisionDispatcher) Material(com.badlogic.gdx.graphics.g3d.Material) com.badlogic.gdx.physics.bullet.collision.btDefaultCollisionConfiguration(com.badlogic.gdx.physics.bullet.collision.btDefaultCollisionConfiguration) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) com.badlogic.gdx.physics.bullet.linearmath.btDefaultMotionState(com.badlogic.gdx.physics.bullet.linearmath.btDefaultMotionState) com.badlogic.gdx.physics.bullet.collision.btCollisionShape(com.badlogic.gdx.physics.bullet.collision.btCollisionShape) com.badlogic.gdx.physics.bullet.dynamics.btRigidBody.btRigidBodyConstructionInfo(com.badlogic.gdx.physics.bullet.dynamics.btRigidBody.btRigidBodyConstructionInfo) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) com.badlogic.gdx.physics.bullet.dynamics.btRigidBody(com.badlogic.gdx.physics.bullet.dynamics.btRigidBody) com.badlogic.gdx.physics.bullet.collision.btSphereShape(com.badlogic.gdx.physics.bullet.collision.btSphereShape) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Model(com.badlogic.gdx.graphics.g3d.Model) com.badlogic.gdx.physics.bullet.collision.btDbvtBroadphase(com.badlogic.gdx.physics.bullet.collision.btDbvtBroadphase) Environment(com.badlogic.gdx.graphics.g3d.Environment) com.badlogic.gdx.physics.bullet.dynamics.btDiscreteDynamicsWorld(com.badlogic.gdx.physics.bullet.dynamics.btDiscreteDynamicsWorld) com.badlogic.gdx.physics.bullet.dynamics.btSequentialImpulseConstraintSolver(com.badlogic.gdx.physics.bullet.dynamics.btSequentialImpulseConstraintSolver) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)

Aggregations

Environment (com.badlogic.gdx.graphics.g3d.Environment)23 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)17 DirectionalLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalLight)17 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)13 Material (com.badlogic.gdx.graphics.g3d.Material)12 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)10 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)10 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)8 CameraInputController (com.badlogic.gdx.graphics.g3d.utils.CameraInputController)6 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)4 Texture (com.badlogic.gdx.graphics.Texture)4 Model (com.badlogic.gdx.graphics.g3d.Model)4 DefaultShaderProvider (com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider)4 DirectionalShadowLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalShadowLight)3 PointLight (com.badlogic.gdx.graphics.g3d.environment.PointLight)3 DepthShaderProvider (com.badlogic.gdx.graphics.g3d.utils.DepthShaderProvider)3 MeshPartBuilder (com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder)3 JsonValue (com.badlogic.gdx.utils.JsonValue)3 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)2 SpotLight (com.badlogic.gdx.graphics.g3d.environment.SpotLight)2