Search in sources :

Example 11 with Material

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

the class BillboardParticleBatch method allocRenderable.

protected Renderable allocRenderable() {
    Renderable renderable = new Renderable();
    renderable.meshPart.primitiveType = GL20.GL_TRIANGLES;
    renderable.meshPart.offset = 0;
    renderable.material = new Material(this.blendingAttribute, this.depthTestAttribute, TextureAttribute.createDiffuse(texture));
    renderable.meshPart.mesh = new Mesh(false, MAX_VERTICES_PER_MESH, MAX_PARTICLES_PER_MESH * 6, currentAttributes);
    renderable.meshPart.mesh.setIndices(indices);
    renderable.shader = shader;
    return renderable;
}
Also used : Renderable(com.badlogic.gdx.graphics.g3d.Renderable) Mesh(com.badlogic.gdx.graphics.Mesh) Material(com.badlogic.gdx.graphics.g3d.Material)

Example 12 with Material

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

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

Example 14 with Material

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

the class BasicShapesTest method create.

@Override
public void create() {
    super.create();
    final Texture texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
    disposables.add(texture);
    final Material material = new Material(TextureAttribute.createDiffuse(texture), ColorAttribute.createSpecular(1, 1, 1, 1), FloatAttribute.createShininess(8f));
    final long attributes = Usage.Position | Usage.Normal | Usage.TextureCoordinates;
    final Model sphere = modelBuilder.createSphere(4f, 4f, 4f, 24, 24, material, attributes);
    disposables.add(sphere);
    world.addConstructor("sphere", new BulletConstructor(sphere, 10f, new btSphereShape(2f)));
    final Model cylinder = modelBuilder.createCylinder(4f, 6f, 4f, 16, material, attributes);
    disposables.add(cylinder);
    world.addConstructor("cylinder", new BulletConstructor(cylinder, 10f, new btCylinderShape(tmpV1.set(2f, 3f, 2f))));
    final Model capsule = modelBuilder.createCapsule(2f, 6f, 16, material, attributes);
    disposables.add(capsule);
    world.addConstructor("capsule", new BulletConstructor(capsule, 10f, new btCapsuleShape(2f, 2f)));
    final Model box = modelBuilder.createBox(4f, 4f, 2f, material, attributes);
    disposables.add(box);
    world.addConstructor("box2", new BulletConstructor(box, 10f, new btBoxShape(tmpV1.set(2f, 2f, 1f))));
    final Model cone = modelBuilder.createCone(4f, 6f, 4f, 16, material, attributes);
    disposables.add(cone);
    world.addConstructor("cone", new BulletConstructor(cone, 10f, new btConeShape(2f, 6f)));
    // Create the entities
    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);
    world.add("sphere", 0, 5, 5);
    world.add("cylinder", 5, 5, 0);
    world.add("box2", 0, 5, 0);
    world.add("capsule", 5, 5, 5);
    world.add("cone", 10, 5, 0);
}
Also used : com.badlogic.gdx.physics.bullet.collision.btBoxShape(com.badlogic.gdx.physics.bullet.collision.btBoxShape) com.badlogic.gdx.physics.bullet.collision.btCylinderShape(com.badlogic.gdx.physics.bullet.collision.btCylinderShape) com.badlogic.gdx.physics.bullet.collision.btConeShape(com.badlogic.gdx.physics.bullet.collision.btConeShape) com.badlogic.gdx.physics.bullet.collision.btSphereShape(com.badlogic.gdx.physics.bullet.collision.btSphereShape) com.badlogic.gdx.physics.bullet.collision.btCapsuleShape(com.badlogic.gdx.physics.bullet.collision.btCapsuleShape) Model(com.badlogic.gdx.graphics.g3d.Model) Material(com.badlogic.gdx.graphics.g3d.Material) Texture(com.badlogic.gdx.graphics.Texture)

Example 15 with Material

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

the class RayPickRagdollTest method createCapsuleModel.

protected Model createCapsuleModel(float radius, float height) {
    final Model result = modelBuilder.createCapsule(radius, height + radius * 2f, 16, new Material(ColorAttribute.createDiffuse(Color.WHITE), ColorAttribute.createSpecular(Color.WHITE)), Usage.Position | Usage.Normal);
    disposables.add(result);
    return result;
}
Also used : Model(com.badlogic.gdx.graphics.g3d.Model) Material(com.badlogic.gdx.graphics.g3d.Material)

Aggregations

Material (com.badlogic.gdx.graphics.g3d.Material)32 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)17 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)17 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)16 Model (com.badlogic.gdx.graphics.g3d.Model)15 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)12 Environment (com.badlogic.gdx.graphics.g3d.Environment)12 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)12 Texture (com.badlogic.gdx.graphics.Texture)10 DirectionalLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalLight)10 MeshPartBuilder (com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder)7 Renderable (com.badlogic.gdx.graphics.g3d.Renderable)6 CameraInputController (com.badlogic.gdx.graphics.g3d.utils.CameraInputController)6 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)5 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)4 TextureAttribute (com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)4 DirectionalShadowLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalShadowLight)4 DefaultShaderProvider (com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider)4 com.badlogic.gdx.physics.bullet.collision.btBoxShape (com.badlogic.gdx.physics.bullet.collision.btBoxShape)4 com.badlogic.gdx.physics.bullet.collision.btSphereShape (com.badlogic.gdx.physics.bullet.collision.btSphereShape)4