Search in sources :

Example 6 with Model

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

the class GimpactTest method create.

@Override
public void create() {
    super.create();
    final Model chassisModel = objLoader.loadModel(Gdx.files.internal("data/car.obj"));
    disposables.add(chassisModel);
    chassisModel.materials.get(0).clear();
    chassisModel.materials.get(0).set(ColorAttribute.createDiffuse(Color.RED), ColorAttribute.createSpecular(Color.WHITE));
    chassisVertexArray = new btTriangleIndexVertexArray(chassisModel.meshParts);
    btGImpactMeshShape chassisShape = new btGImpactMeshShape(chassisVertexArray);
    chassisShape.setLocalScaling(new Vector3(1f, 1f, 1f));
    chassisShape.setMargin(0f);
    chassisShape.updateBound();
    world.addConstructor("chassis", new BulletConstructor(chassisModel, 1f, chassisShape));
    (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);
    for (float y = 10f; y < 50f; y += 5f) world.add("chassis", -2f + (float) Math.random() * 4f, y, -2f + (float) Math.random() * 4f).setColor(0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 1f);
    btGImpactCollisionAlgorithm.registerAlgorithm(world.dispatcher);
}
Also used : Model(com.badlogic.gdx.graphics.g3d.Model) com.badlogic.gdx.physics.bullet.collision.btGImpactMeshShape(com.badlogic.gdx.physics.bullet.collision.btGImpactMeshShape) Vector3(com.badlogic.gdx.math.Vector3) com.badlogic.gdx.physics.bullet.collision.btTriangleIndexVertexArray(com.badlogic.gdx.physics.bullet.collision.btTriangleIndexVertexArray)

Example 7 with Model

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

Example 8 with Model

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

the class ConvexHullDistanceTest method create.

@Override
public void create() {
    super.create();
    final Model carModel = objLoader.loadModel(Gdx.files.internal("data/car.obj"));
    disposables.add(carModel);
    carModel.materials.get(0).clear();
    carModel.materials.get(0).set(ColorAttribute.createDiffuse(Color.WHITE), ColorAttribute.createSpecular(Color.WHITE));
    world.addConstructor("car", new BulletConstructor(carModel, 5f, createConvexHullShape(carModel, true)));
    // 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);
    for (float y = 10f; y < 50f; y += 5f) world.add("car", -2f + (float) Math.random() * 4f, y, -2f + (float) Math.random() * 4f).setColor(0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 1f);
    distance = new ConvexHullDistance();
    shapeRenderer = new ShapeRenderer();
}
Also used : Model(com.badlogic.gdx.graphics.g3d.Model) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 9 with Model

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

the class ConvexHullTest method create.

@Override
public void create() {
    super.create();
    final Model carModel = objLoader.loadModel(Gdx.files.internal("data/car.obj"));
    disposables.add(carModel);
    carModel.materials.get(0).clear();
    carModel.materials.get(0).set(ColorAttribute.createDiffuse(Color.WHITE), ColorAttribute.createSpecular(Color.WHITE));
    world.addConstructor("car", new BulletConstructor(carModel, 5f, createConvexHullShape(carModel, true)));
    // 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);
    for (float y = 10f; y < 50f; y += 5f) world.add("car", -2f + (float) Math.random() * 4f, y, -2f + (float) Math.random() * 4f).setColor(0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 1f);
}
Also used : Model(com.badlogic.gdx.graphics.g3d.Model)

Example 10 with Model

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

the class FrustumCullingTest method create.

@Override
public void create() {
    super.create();
    instructions = "Tap to toggle view\nLong press to toggle debug mode\nSwipe for next test\nCtrl+drag to rotate\nScroll to zoom";
    tempManifoldArr = new btPersistentManifoldArray();
    world.addConstructor("collisionBox", new BulletConstructor(world.getConstructor("box").model));
    // Create the entities
    final float dX = BOX_X_MAX - BOX_X_MIN;
    final float dY = BOX_Y_MAX - BOX_Y_MIN;
    final float dZ = BOX_Z_MAX - BOX_Z_MIN;
    for (int i = 0; i < BOXCOUNT; i++) world.add("collisionBox", BOX_X_MIN + dX * (float) Math.random(), BOX_Y_MIN + dY * (float) Math.random(), BOX_Z_MIN + dZ * (float) Math.random()).setColor(Color.GRAY);
    frustumCam = new PerspectiveCamera(camera.fieldOfView, camera.viewportWidth, camera.viewportHeight);
    frustumCam.far = Vector3.len(BOX_X_MAX, BOX_Y_MAX, BOX_Z_MAX);
    frustumCam.update();
    overviewCam = camera;
    overviewCam.position.set(BOX_X_MAX, BOX_Y_MAX, BOX_Z_MAX);
    overviewCam.lookAt(Vector3.Zero);
    overviewCam.far = 150f;
    overviewCam.update();
    final Model frustumModel = createFrustumModel(frustumCam.frustum.planePoints);
    disposables.add(frustumModel);
    frustumObject = createFrustumObject(frustumCam.frustum.planePoints);
    world.add(frustumEntity = new BulletEntity(frustumModel, frustumObject, 0, 0, 0));
    frustumEntity.setColor(Color.BLUE);
}
Also used : Model(com.badlogic.gdx.graphics.g3d.Model) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) com.badlogic.gdx.physics.bullet.collision.btPersistentManifoldArray(com.badlogic.gdx.physics.bullet.collision.btPersistentManifoldArray)

Aggregations

Model (com.badlogic.gdx.graphics.g3d.Model)34 Material (com.badlogic.gdx.graphics.g3d.Material)14 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)7 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)7 Texture (com.badlogic.gdx.graphics.Texture)6 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)5 Environment (com.badlogic.gdx.graphics.g3d.Environment)4 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)4 Vector3 (com.badlogic.gdx.math.Vector3)4 BoundingBox (com.badlogic.gdx.math.collision.BoundingBox)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 com.badlogic.gdx.physics.bullet.dynamics.btRigidBody (com.badlogic.gdx.physics.bullet.dynamics.btRigidBody)4 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)3 DirectionalLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalLight)3 Node (com.badlogic.gdx.graphics.g3d.model.Node)3 com.badlogic.gdx.physics.bullet.collision.btCollisionShape (com.badlogic.gdx.physics.bullet.collision.btCollisionShape)3 AssetDescriptor (com.badlogic.gdx.assets.AssetDescriptor)2 AssetManager (com.badlogic.gdx.assets.AssetManager)2 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)2