Search in sources :

Example 6 with AnimationController

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

the class ModelTest 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 + 1);
        e.value.animate((animIndex == e.key.animations.size) ? null : 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 7 with AnimationController

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

the class SkeletonTest method onLoaded.

@Override
protected void onLoaded() {
    if (currentlyLoading == null || currentlyLoading.isEmpty())
        return;
    instances.clear();
    animationControllers.clear();
    final ModelInstance instance = new ModelInstance(assets.get(currentlyLoading, Model.class));
    for (Material m : instance.materials) m.set(new BlendingAttribute(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA, 0.8f));
    instances.add(instance);
    if (instance.animations.size > 0)
        animationControllers.put(instance, new AnimationController(instance));
    currentlyLoading = null;
}
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) Model(com.badlogic.gdx.graphics.g3d.Model) Material(com.badlogic.gdx.graphics.g3d.Material)

Example 8 with AnimationController

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

the class SceneManager method loadAssets.

private void loadAssets(Integer entity) {
    final ModelComponent modelComponent = modelMapper.get(entity);
    // Group all assets
    final Array<Asset> allAssets = new Array<>();
    final Asset modelAsset = modelComponent.asset;
    for (PbrMaterial mat : modelComponent.pbrMaterials) {
        if (mat.albedoAsset != null) {
            allAssets.add(mat.albedoAsset);
        }
        if (mat.metalnessAsset != null) {
            allAssets.add(mat.metalnessAsset);
        }
        if (mat.roughnessAsset != null) {
            allAssets.add(mat.roughnessAsset);
        }
        if (mat.normalAsset != null) {
            allAssets.add(mat.normalAsset);
        }
        if (mat.ambientOcclusionAsset != null) {
            allAssets.add(mat.ambientOcclusionAsset);
        }
    }
    // Start loading them
    assets.queueAsset(modelAsset);
    // Wait for them
    messaging.get(Strings.Events.assetLoaded).subscribe(new Consumer<Message>() {

        @Override
        public void accept(Message message) throws Exception {
            Asset asset = (Asset) message.data.get(Strings.Defaults.assetKey);
            if (asset != null) {
                if (asset.is(modelAsset.alias)) {
                    Model model = assets.get(asset);
                    modelComponent.model = new ModelInstance(model);
                    if (modelComponent.model.animations.size > 0) {
                        modelComponent.animationController = new AnimationController(modelComponent.model);
                    }
                    assets.queueAssets(allAssets);
                } else {
                    if (allAssets.contains(asset, false)) {
                        temporaryLoadedAssets.add(asset);
                        allAssets.removeValue(asset, false);
                        Bundle bundle = new Bundle();
                        bundle.put("size", allAssets.size);
                        bundle.put("modelComponent", modelComponent);
                        sizeSubject.onNext(bundle);
                    }
                }
            }
        }
    });
}
Also used : Message(io.github.voidzombie.nhglib.runtime.messaging.Message) Bundle(io.github.voidzombie.nhglib.utils.data.Bundle) Array(com.badlogic.gdx.utils.Array) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelComponent(io.github.voidzombie.nhglib.runtime.ecs.components.graphics.ModelComponent) AnimationController(com.badlogic.gdx.graphics.g3d.utils.AnimationController) Model(com.badlogic.gdx.graphics.g3d.Model) Asset(io.github.voidzombie.nhglib.assets.Asset) PbrMaterial(io.github.voidzombie.nhglib.graphics.utils.PbrMaterial)

Example 9 with AnimationController

use of com.badlogic.gdx.graphics.g3d.utils.AnimationController in project bladecoder-adventure-engine by bladecoder.

the class Sprite3DRenderer method retrieveSource.

private void retrieveSource(String source) {
    ModelCacheEntry entry = (ModelCacheEntry) sourceCache.get(source);
    if (entry == null || entry.refCounter < 1) {
        loadSource(source);
        EngineAssetManager.getInstance().finishLoading();
        entry = (ModelCacheEntry) sourceCache.get(source);
    }
    if (entry.modelInstance == null) {
        Model model3d = EngineAssetManager.getInstance().getModel3D(source);
        entry.modelInstance = new ModelInstance(model3d);
        entry.controller = new AnimationController(entry.modelInstance);
        entry.camera3d = getCamera(entry.modelInstance);
    }
}
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