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);
}
}
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;
}
}
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);
}
}
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);
}
}
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();
}
Aggregations