Search in sources :

Example 11 with Model

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

the class VehicleTest method create.

@Override
public void create() {
    super.create();
    instructions = "Tap to shoot\nArrow keys to drive\nR to reset\nLong press to toggle debug mode\nSwipe for next test";
    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));
    final Model wheelModel = objLoader.loadModel(Gdx.files.internal("data/wheel.obj"));
    disposables.add(wheelModel);
    wheelModel.materials.get(0).clear();
    wheelModel.materials.get(0).set(ColorAttribute.createDiffuse(Color.BLACK), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(128));
    Texture checkboard = new Texture(Gdx.files.internal("data/g3d/checkboard.png"));
    final Model largeGroundModel = modelBuilder.createBox(200f, 2f, 200f, new Material(TextureAttribute.createDiffuse(checkboard), ColorAttribute.createSpecular(Color.WHITE), FloatAttribute.createShininess(16f)), Usage.Position | Usage.Normal | Usage.TextureCoordinates);
    largeGroundModel.manageDisposable(checkboard);
    disposables.add(largeGroundModel);
    world.addConstructor("largeground", new BulletConstructor(largeGroundModel, 0f));
    BoundingBox bounds = new BoundingBox();
    Vector3 chassisHalfExtents = chassisModel.calculateBoundingBox(bounds).getDimensions(new Vector3()).scl(0.5f);
    Vector3 wheelHalfExtents = wheelModel.calculateBoundingBox(bounds).getDimensions(new Vector3()).scl(0.5f);
    world.addConstructor("chassis", new BulletConstructor(chassisModel, 5f, new btBoxShape(chassisHalfExtents)));
    world.addConstructor("wheel", new BulletConstructor(wheelModel, 0, null));
    for (int i = 0; i < 1000; i += 200) world.add("largeground", 0f, -1f, i);
    chassis = world.add("chassis", 0, 3f, 0);
    wheels[0] = world.add("wheel", 0, 0, 0);
    wheels[1] = world.add("wheel", 0, 0, 0);
    wheels[2] = world.add("wheel", 0, 0, 0);
    wheels[3] = world.add("wheel", 0, 0, 0);
    // Create the vehicle
    raycaster = getRaycaster();
    tuning = new btVehicleTuning();
    vehicle = new btRaycastVehicle(tuning, (btRigidBody) chassis.body, raycaster);
    chassis.body.setActivationState(Collision.DISABLE_DEACTIVATION);
    ((btDynamicsWorld) world.collisionWorld).addVehicle(vehicle);
    vehicle.setCoordinateSystem(0, 1, 2);
    btWheelInfo wheelInfo;
    Vector3 point = new Vector3();
    Vector3 direction = new Vector3(0, -1, 0);
    Vector3 axis = new Vector3(-1, 0, 0);
    wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(0.9f, -0.8f, 0.7f), direction, axis, wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, true);
    wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(-0.9f, -0.8f, 0.7f), direction, axis, wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, true);
    wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(0.9f, -0.8f, -0.5f), direction, axis, wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, false);
    wheelInfo = vehicle.addWheel(point.set(chassisHalfExtents).scl(-0.9f, -0.8f, -0.5f), direction, axis, wheelHalfExtents.z * 0.3f, wheelHalfExtents.z, tuning, false);
}
Also used : com.badlogic.gdx.physics.bullet.collision.btBoxShape(com.badlogic.gdx.physics.bullet.collision.btBoxShape) com.badlogic.gdx.physics.bullet.dynamics.btRaycastVehicle(com.badlogic.gdx.physics.bullet.dynamics.btRaycastVehicle) com.badlogic.gdx.physics.bullet.dynamics.btWheelInfo(com.badlogic.gdx.physics.bullet.dynamics.btWheelInfo) com.badlogic.gdx.physics.bullet.dynamics.btRaycastVehicle.btVehicleTuning(com.badlogic.gdx.physics.bullet.dynamics.btRaycastVehicle.btVehicleTuning) Material(com.badlogic.gdx.graphics.g3d.Material) Vector3(com.badlogic.gdx.math.Vector3) Texture(com.badlogic.gdx.graphics.Texture) com.badlogic.gdx.physics.bullet.dynamics.btRigidBody(com.badlogic.gdx.physics.bullet.dynamics.btRigidBody) com.badlogic.gdx.physics.bullet.dynamics.btDynamicsWorld(com.badlogic.gdx.physics.bullet.dynamics.btDynamicsWorld) BoundingBox(com.badlogic.gdx.math.collision.BoundingBox) Model(com.badlogic.gdx.graphics.g3d.Model)

Example 12 with Model

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

the class Animation3DTest method onLoaded.

@Override
protected void onLoaded() {
    if (skydome == null) {
        skydome = new ModelInstance(assets.get("data/g3d/skydome.g3db", Model.class));
        floorModel.getMaterial("concrete").set(TextureAttribute.createDiffuse(assets.get("data/g3d/concrete.png", Texture.class)));
        floorModel.getMaterial("tree").set(TextureAttribute.createDiffuse(assets.get("data/tree.png", Texture.class)), new BlendingAttribute());
        instances.add(new ModelInstance(floorModel, "floor"));
        instances.add(tree = new ModelInstance(floorModel, "tree"));
        assets.load("data/g3d/knight.g3db", Model.class);
        loading = true;
    } else if (character == null) {
        character = new ModelInstance(assets.get("data/g3d/knight.g3db", Model.class));
        BoundingBox bbox = new BoundingBox();
        character.calculateBoundingBox(bbox);
        character.transform.setToRotation(Vector3.Y, 180).trn(0, -bbox.min.y, 0);
        instances.add(character);
        animation = new AnimationController(character);
        animation.animate("Idle", -1, 1f, null, 0.2f);
        status = idle;
        for (Animation anim : character.animations) Gdx.app.log("Test", anim.id);
        // Now attach the node of another model at the tip of this knights sword:
        ship = assets.get("data/g3d/ship.obj", Model.class).nodes.get(0).copy();
        ship.detach();
        // offset from the sword node to the tip of the sword, in rest pose
        ship.translation.x = 10f;
        ship.rotation.set(Vector3.Z, 90f);
        ship.scale.scl(5f);
        ship.parts.get(0).enabled = false;
        character.getNode("sword").addChild(ship);
    }
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) BlendingAttribute(com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute) AnimationController(com.badlogic.gdx.graphics.g3d.utils.AnimationController) BoundingBox(com.badlogic.gdx.math.collision.BoundingBox) Model(com.badlogic.gdx.graphics.g3d.Model) Animation(com.badlogic.gdx.graphics.g3d.model.Animation)

Example 13 with Model

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

the class PairCacheTest 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";
    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(0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 0.25f + 0.5f * (float) Math.random(), 1f);
    manifoldArray = new btPersistentManifoldArray();
    disposables.add(manifoldArray);
    overviewCam = camera;
    overviewCam.position.set(BOX_X_MAX, BOX_Y_MAX, BOX_Z_MAX);
    overviewCam.lookAt(Vector3.Zero);
    overviewCam.far = 150f;
    overviewCam.update();
    frustumCam = new PerspectiveCamera(camera.fieldOfView, camera.viewportWidth, camera.viewportHeight);
    frustumCam.far = Vector3.len(BOX_X_MAX, BOX_Y_MAX, BOX_Z_MAX);
    frustumCam.update();
    final Model ghostModel = FrustumCullingTest.createFrustumModel(frustumCam.frustum.planePoints);
    disposables.add(ghostModel);
    // The ghost object does not need to be shaped as a camera frustum, it can have any collision shape.
    ghostObject = FrustumCullingTest.createFrustumObject(frustumCam.frustum.planePoints);
    disposables.add(ghostObject);
    world.add(ghostEntity = new BulletEntity(ghostModel, ghostObject, 0, 0, 0));
    disposables.add(ghostEntity);
    shapeRenderer = new ShapeRenderer();
    disposables.add(shapeRenderer);
}
Also used : Model(com.badlogic.gdx.graphics.g3d.Model) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer)

Example 14 with Model

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

the class MeshSpawnShapeValue method load.

@Override
public void load(AssetManager manager, ResourceData data) {
    SaveData saveData = data.getSaveData();
    AssetDescriptor descriptor = saveData.loadAsset();
    if (descriptor != null) {
        Model model = (Model) manager.get(descriptor);
        setMesh(model.meshes.get((Integer) saveData.load("index")), model);
    }
}
Also used : Model(com.badlogic.gdx.graphics.g3d.Model) SaveData(com.badlogic.gdx.graphics.g3d.particles.ResourceData.SaveData) AssetDescriptor(com.badlogic.gdx.assets.AssetDescriptor)

Example 15 with Model

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

the class ModelInfluencer method load.

@Override
public void load(AssetManager manager, ResourceData resources) {
    SaveData data = resources.getSaveData();
    AssetDescriptor descriptor;
    while ((descriptor = data.loadAsset()) != null) {
        Model model = (Model) manager.get(descriptor);
        if (model == null)
            throw new RuntimeException("Model is null");
        models.add(model);
    }
}
Also used : Model(com.badlogic.gdx.graphics.g3d.Model) SaveData(com.badlogic.gdx.graphics.g3d.particles.ResourceData.SaveData) AssetDescriptor(com.badlogic.gdx.assets.AssetDescriptor)

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