Search in sources :

Example 1 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 2 with Material

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

the class CharacterTest method create.

@Override
public void create() {
    super.create();
    instructions = "Tap to shoot\nArrow keys to move\nR to reset\nLong press to toggle debug mode\nSwipe for next test";
    // Create a visual representation of the character (note that we don't use the physics part of BulletEntity, we'll do that manually)
    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 capsule = modelBuilder.createCapsule(2f, 6f, 16, material, attributes);
    disposables.add(capsule);
    world.addConstructor("capsule", new BulletConstructor(capsule, null));
    character = world.add("capsule", 5f, 3f, 5f);
    // Set by reference
    characterTransform = character.transform;
    characterTransform.rotate(Vector3.X, 90);
    // Create the physics representation of the character
    ghostObject = new btPairCachingGhostObject();
    ghostObject.setWorldTransform(characterTransform);
    ghostShape = new btCapsuleShape(2f, 2f);
    ghostObject.setCollisionShape(ghostShape);
    ghostObject.setCollisionFlags(btCollisionObject.CollisionFlags.CF_CHARACTER_OBJECT);
    characterController = new btKinematicCharacterController(ghostObject, ghostShape, .35f, Vector3.Y);
    // And add it to the physics world
    world.collisionWorld.addCollisionObject(ghostObject, (short) btBroadphaseProxy.CollisionFilterGroups.CharacterFilter, (short) (btBroadphaseProxy.CollisionFilterGroups.StaticFilter | btBroadphaseProxy.CollisionFilterGroups.DefaultFilter));
    ((btDiscreteDynamicsWorld) (world.collisionWorld)).addAction(characterController);
    // Add the ground
    (ground = 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);
    // Create some boxes to play with
    for (int x = 0; x < BOXCOUNT_X; x++) {
        for (int y = 0; y < BOXCOUNT_Y; y++) {
            for (int z = 0; z < BOXCOUNT_Z; z++) {
                world.add("box", BOXOFFSET_X + x, BOXOFFSET_Y + y, BOXOFFSET_Z + z).setColor(0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 1f);
            }
        }
    }
}
Also used : com.badlogic.gdx.physics.bullet.collision.btCapsuleShape(com.badlogic.gdx.physics.bullet.collision.btCapsuleShape) Model(com.badlogic.gdx.graphics.g3d.Model) com.badlogic.gdx.physics.bullet.dynamics.btDiscreteDynamicsWorld(com.badlogic.gdx.physics.bullet.dynamics.btDiscreteDynamicsWorld) Material(com.badlogic.gdx.graphics.g3d.Material) Texture(com.badlogic.gdx.graphics.Texture) com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject(com.badlogic.gdx.physics.bullet.collision.btPairCachingGhostObject) com.badlogic.gdx.physics.bullet.dynamics.btKinematicCharacterController(com.badlogic.gdx.physics.bullet.dynamics.btKinematicCharacterController)

Example 3 with Material

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

the class ContactCacheTest method create.

@Override
public void create() {
    super.create();
    final Model sphereModel = modelBuilder.createSphere(1f, 1f, 1f, 8, 8, new Material(ColorAttribute.createDiffuse(Color.WHITE), ColorAttribute.createSpecular(Color.WHITE)), Usage.Position | Usage.Normal);
    disposables.add(sphereModel);
    final BulletConstructor sphereConstructor = new BulletConstructor(sphereModel, 0.5f, new btSphereShape(0.5f));
    sphereConstructor.bodyInfo.setRestitution(1f);
    world.addConstructor("sphere", sphereConstructor);
    final Model sceneModel = objLoader.loadModel(Gdx.files.internal("data/scene.obj"));
    disposables.add(sceneModel);
    final BulletConstructor sceneConstructor = new BulletConstructor(sceneModel, 0f, new btBvhTriangleMeshShape(sceneModel.meshParts));
    sceneConstructor.bodyInfo.setRestitution(0.25f);
    world.addConstructor("scene", sceneConstructor);
    final BulletEntity scene = world.add("scene", (new Matrix4()).setToTranslation(0f, 2f, 0f).rotate(Vector3.Y, -90));
    scene.setColor(0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 1f);
    scene.body.setContactCallbackFlag(2);
    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);
    for (int x = 0; x < SPHERECOUNT_X; x++) {
        for (int y = 0; y < SPHERECOUNT_Y; y++) {
            for (int z = 0; z < SPHERECOUNT_Z; z++) {
                final BulletEntity e = (BulletEntity) world.add("sphere", SPHEREOFFSET_X + x * 3f, SPHEREOFFSET_Y + y * 3f, SPHEREOFFSET_Z + z * 3f);
                e.setColor(0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 1f);
                e.body.setContactCallbackFilter(2);
            }
        }
    }
    if (USE_CONTACT_CACHE) {
        contactCache = new TestContactCache();
        contactCache.entities = world.entities;
        contactCache.setCacheTime(0.5f);
    } else {
        contactListener = new TestContactListener();
        contactListener.entities = world.entities;
    }
    time = 0;
}
Also used : com.badlogic.gdx.physics.bullet.collision.btBvhTriangleMeshShape(com.badlogic.gdx.physics.bullet.collision.btBvhTriangleMeshShape) com.badlogic.gdx.physics.bullet.collision.btSphereShape(com.badlogic.gdx.physics.bullet.collision.btSphereShape) Model(com.badlogic.gdx.graphics.g3d.Model) Material(com.badlogic.gdx.graphics.g3d.Material) TestContactListener(com.badlogic.gdx.tests.bullet.ContactCallbackTest2.TestContactListener) Matrix4(com.badlogic.gdx.math.Matrix4)

Example 4 with Material

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

the class BaseBulletTest method create.

@Override
public void create() {
    init();
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.f));
    light = shadows ? new DirectionalShadowLight(1024, 1024, 20f, 20f, 1f, 300f) : new DirectionalLight();
    light.set(0.8f, 0.8f, 0.8f, -0.5f, -1f, 0.7f);
    environment.add(light);
    if (shadows)
        environment.shadowMap = (DirectionalShadowLight) light;
    shadowBatch = new ModelBatch(new DepthShaderProvider());
    modelBatch = new ModelBatch();
    world = createWorld();
    world.performanceCounter = performanceCounter;
    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 some simple 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.WHITE), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(16f)), Usage.Position | Usage.Normal);
    disposables.add(groundModel);
    final Model boxModel = modelBuilder.createBox(1f, 1f, 1f, new Material(ColorAttribute.createDiffuse(Color.WHITE), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(64f)), Usage.Position | Usage.Normal);
    disposables.add(boxModel);
    // Add the constructors
    // mass = 0: static body
    world.addConstructor("ground", new BulletConstructor(groundModel, 0f));
    // mass = 1kg: dynamic body
    world.addConstructor("box", new BulletConstructor(boxModel, 1f));
    // mass = 0: static body
    world.addConstructor("staticbox", new BulletConstructor(boxModel, 0f));
}
Also used : DirectionalShadowLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalShadowLight) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) 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) DepthShaderProvider(com.badlogic.gdx.graphics.g3d.utils.DepthShaderProvider)

Example 5 with Material

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

the class MeshShapeTest method create.

@Override
public void create() {
    super.create();
    final Model sphereModel = modelBuilder.createSphere(0.5f, 0.5f, 0.5f, 8, 8, new Material(ColorAttribute.createDiffuse(Color.WHITE), ColorAttribute.createSpecular(Color.WHITE)), Usage.Position | Usage.Normal);
    disposables.add(sphereModel);
    final BulletConstructor sphereConstructor = new BulletConstructor(sphereModel, 0.25f, new btSphereShape(0.25f));
    sphereConstructor.bodyInfo.setRestitution(1f);
    world.addConstructor("sphere", sphereConstructor);
    final Model sceneModel = objLoader.loadModel(Gdx.files.internal("data/scene.obj"));
    disposables.add(sceneModel);
    final BulletConstructor sceneConstructor = new BulletConstructor(sceneModel, 0f, new btBvhTriangleMeshShape(sceneModel.meshParts));
    sceneConstructor.bodyInfo.setRestitution(0.25f);
    world.addConstructor("scene", sceneConstructor);
    world.add("scene", (new Matrix4()).setToTranslation(0f, 2f, 0f).rotate(Vector3.Y, -90)).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("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);
    for (float x = -3; x < 7; x++) {
        for (float z = -5; z < 5; z++) {
            world.add("sphere", x, 10f + (float) Math.random() * 0.1f, z).setColor(0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 0.5f + 0.5f * (float) Math.random(), 1f);
        }
    }
}
Also used : com.badlogic.gdx.physics.bullet.collision.btBvhTriangleMeshShape(com.badlogic.gdx.physics.bullet.collision.btBvhTriangleMeshShape) com.badlogic.gdx.physics.bullet.collision.btSphereShape(com.badlogic.gdx.physics.bullet.collision.btSphereShape) Model(com.badlogic.gdx.graphics.g3d.Model) Material(com.badlogic.gdx.graphics.g3d.Material) Matrix4(com.badlogic.gdx.math.Matrix4)

Aggregations

Material (com.badlogic.gdx.graphics.g3d.Material)47 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)32 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)29 Model (com.badlogic.gdx.graphics.g3d.Model)27 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)19 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)14 Environment (com.badlogic.gdx.graphics.g3d.Environment)14 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)14 Texture (com.badlogic.gdx.graphics.Texture)13 MeshPartBuilder (com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder)13 DirectionalLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalLight)10 Vector3 (com.badlogic.gdx.math.Vector3)9 Renderable (com.badlogic.gdx.graphics.g3d.Renderable)8 CameraInputController (com.badlogic.gdx.graphics.g3d.utils.CameraInputController)7 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)6 BlendingAttribute (com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute)6 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)5 AssetManager (com.badlogic.gdx.assets.AssetManager)4 TextureAttribute (com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)4 DirectionalShadowLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalShadowLight)4