Search in sources :

Example 1 with AnimationController

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

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

the class ShaderCollectionTest method onLoaded.

@Override
protected void onLoaded() {
    if (currentlyLoading == null || currentlyLoading.length() == 0)
        return;
    if (loadingMaterial) {
        loadingMaterial = false;
        if (currentMaterial != null && !currentMaterial.equals(currentlyLoading))
            assets.unload(currentMaterial);
        currentMaterial = currentlyLoading;
        currentlyLoading = null;
        ModelInstance instance = instances.get(0);
        if (instance != null) {
            instance.materials.get(0).clear();
            instance.materials.get(0).set(assets.get(currentMaterial, Model.class).materials.get(0));
        }
    } else {
        if (currentModel != null && !currentModel.equals(currentlyLoading))
            assets.unload(currentModel);
        currentModel = currentlyLoading;
        currentlyLoading = null;
        instances.clear();
        animationControllers.clear();
        final ModelInstance instance = new ModelInstance(assets.get(currentModel, Model.class), transform);
        instances.add(instance);
        if (instance.animations.size > 0)
            animationControllers.put(instance, new AnimationController(instance));
        instance.calculateBoundingBox(bounds);
        cam.position.set(1, 1, 1).nor().scl(bounds.getDimensions(tmpV).len() * 0.75f).add(bounds.getCenter(tmpV));
        cam.up.set(0, 1, 0);
        cam.lookAt(inputController.target.set(bounds.getCenter(tmpV)));
        cam.far = Math.max(100f, bounds.getDimensions(tmpV).len() * 2.0f);
        cam.update();
        moveRadius = bounds.getDimensions(tmpV).len() * 0.25f;
    }
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) AnimationController(com.badlogic.gdx.graphics.g3d.utils.AnimationController) Model(com.badlogic.gdx.graphics.g3d.Model)

Example 3 with AnimationController

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

the class ShaderCollectionTest method switchAnimation.

protected void switchAnimation() {
    for (ObjectMap.Entry<ModelInstance, AnimationController> e : animationControllers.entries()) {
        int animIndex = 0;
        if (e.value.current != null) {
            for (int i = 0; i < e.key.animations.size; i++) {
                final Animation animation = e.key.animations.get(i);
                if (e.value.current.animation == animation) {
                    animIndex = i;
                    break;
                }
            }
        }
        animIndex = (animIndex + 1) % e.key.animations.size;
        e.value.animate(e.key.animations.get(animIndex).id, -1, 1f, null, 0.2f);
    }
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ObjectMap(com.badlogic.gdx.utils.ObjectMap) AnimationController(com.badlogic.gdx.graphics.g3d.utils.AnimationController) Animation(com.badlogic.gdx.graphics.g3d.model.Animation)

Example 4 with AnimationController

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

the class SkeletonTest method switchAnimation.

protected void switchAnimation() {
    for (ObjectMap.Entry<ModelInstance, AnimationController> e : animationControllers.entries()) {
        int animIndex = 0;
        if (e.value.current != null) {
            for (int i = 0; i < e.key.animations.size; i++) {
                final Animation animation = e.key.animations.get(i);
                if (e.value.current.animation == animation) {
                    animIndex = i;
                    break;
                }
            }
        }
        animIndex = (animIndex + 1) % e.key.animations.size;
        e.value.animate(e.key.animations.get(animIndex).id, -1, 1f, null, 0.2f);
    }
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ObjectMap(com.badlogic.gdx.utils.ObjectMap) AnimationController(com.badlogic.gdx.graphics.g3d.utils.AnimationController) Animation(com.badlogic.gdx.graphics.g3d.model.Animation)

Example 5 with AnimationController

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

the class ModelTest method onLoaded.

@Override
protected void onLoaded() {
    if (currentlyLoading == null || currentlyLoading.length() == 0)
        return;
    instances.clear();
    animationControllers.clear();
    final ModelInstance instance = new ModelInstance(assets.get(currentlyLoading, Model.class));
    instance.transform = transform;
    instances.add(instance);
    if (instance.animations.size > 0)
        animationControllers.put(instance, new AnimationController(instance));
    currentlyLoading = null;
    instance.calculateBoundingBox(bounds);
    cam.position.set(1, 1, 1).nor().scl(bounds.getDimensions(tmpV1).len() * 0.75f + bounds.getCenter(tmpV2).len());
    cam.up.set(0, 1, 0);
    cam.lookAt(0, 0, 0);
    cam.far = 50f + bounds.getDimensions(tmpV1).len() * 2.0f;
    cam.update();
}
Also used : ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) AnimationController(com.badlogic.gdx.graphics.g3d.utils.AnimationController) Model(com.badlogic.gdx.graphics.g3d.Model)

Aggregations

ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)9 AnimationController (com.badlogic.gdx.graphics.g3d.utils.AnimationController)9 Model (com.badlogic.gdx.graphics.g3d.Model)6 Animation (com.badlogic.gdx.graphics.g3d.model.Animation)4 ObjectMap (com.badlogic.gdx.utils.ObjectMap)3 BlendingAttribute (com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute)2 Material (com.badlogic.gdx.graphics.g3d.Material)1 BoundingBox (com.badlogic.gdx.math.collision.BoundingBox)1 Array (com.badlogic.gdx.utils.Array)1 Asset (io.github.voidzombie.nhglib.assets.Asset)1 PbrMaterial (io.github.voidzombie.nhglib.graphics.utils.PbrMaterial)1 ModelComponent (io.github.voidzombie.nhglib.runtime.ecs.components.graphics.ModelComponent)1 Message (io.github.voidzombie.nhglib.runtime.messaging.Message)1 Bundle (io.github.voidzombie.nhglib.utils.data.Bundle)1