Search in sources :

Example 6 with ModelInstance

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

use of com.badlogic.gdx.graphics.g3d.ModelInstance 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 8 with ModelInstance

use of com.badlogic.gdx.graphics.g3d.ModelInstance 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 9 with ModelInstance

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

the class TextureRegion3DTest method create.

@Override
public void create() {
    Gdx.gl.glClearColor(0.2f, 0.3f, 1.0f, 0.f);
    atlas = new TextureAtlas(Gdx.files.internal("data/testpack"));
    regions = atlas.getRegions();
    modelBatch = new ModelBatch(new DefaultShaderProvider());
    environment = new Environment();
    environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f));
    environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
    cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    cam.position.set(10f, 10f, 10f);
    cam.lookAt(0, 0, 0);
    cam.near = 0.1f;
    cam.far = 300f;
    cam.update();
    ModelBuilder modelBuilder = new ModelBuilder();
    final Material material = new Material(ColorAttribute.createDiffuse(1f, 1f, 1f, 1f), new TextureAttribute(TextureAttribute.Diffuse));
    model = modelBuilder.createBox(5f, 5f, 5f, material, Usage.Position | Usage.Normal | Usage.TextureCoordinates);
    instance = new ModelInstance(model);
    attribute = instance.materials.get(0).get(TextureAttribute.class, TextureAttribute.Diffuse);
    Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(cam)));
}
Also used : DefaultShaderProvider(com.badlogic.gdx.graphics.g3d.utils.DefaultShaderProvider) Material(com.badlogic.gdx.graphics.g3d.Material) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) CameraInputController(com.badlogic.gdx.graphics.g3d.utils.CameraInputController) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) TextureAtlas(com.badlogic.gdx.graphics.g2d.TextureAtlas) DirectionalLight(com.badlogic.gdx.graphics.g3d.environment.DirectionalLight) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) Environment(com.badlogic.gdx.graphics.g3d.Environment) ColorAttribute(com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute) TextureAttribute(com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute)

Example 10 with ModelInstance

use of com.badlogic.gdx.graphics.g3d.ModelInstance 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)55 Material (com.badlogic.gdx.graphics.g3d.Material)29 ModelBuilder (com.badlogic.gdx.graphics.g3d.utils.ModelBuilder)26 Model (com.badlogic.gdx.graphics.g3d.Model)22 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)17 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)16 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)15 MeshPartBuilder (com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder)11 Texture (com.badlogic.gdx.graphics.Texture)10 Environment (com.badlogic.gdx.graphics.g3d.Environment)10 Vector3 (com.badlogic.gdx.math.Vector3)10 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)9 AnimationController (com.badlogic.gdx.graphics.g3d.utils.AnimationController)9 DungeonTileModelInstance (util.DungeonTileModelInstance)8 BlendingAttribute (com.badlogic.gdx.graphics.g3d.attributes.BlendingAttribute)7 DirectionalLight (com.badlogic.gdx.graphics.g3d.environment.DirectionalLight)7 CameraInputController (com.badlogic.gdx.graphics.g3d.utils.CameraInputController)6 InputMultiplexer (com.badlogic.gdx.InputMultiplexer)5 AssetManager (com.badlogic.gdx.assets.AssetManager)4 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)4