use of com.badlogic.gdx.graphics.g3d.model.NodeAnimation in project libgdx by libgdx.
the class Model method loadAnimations.
protected void loadAnimations(Iterable<ModelAnimation> modelAnimations) {
for (final ModelAnimation anim : modelAnimations) {
Animation animation = new Animation();
animation.id = anim.id;
for (ModelNodeAnimation nanim : anim.nodeAnimations) {
final Node node = getNode(nanim.nodeId);
if (node == null)
continue;
NodeAnimation nodeAnim = new NodeAnimation();
nodeAnim.node = node;
if (nanim.translation != null) {
nodeAnim.translation = new Array<NodeKeyframe<Vector3>>();
nodeAnim.translation.ensureCapacity(nanim.translation.size);
for (ModelNodeKeyframe<Vector3> kf : nanim.translation) {
if (kf.keytime > animation.duration)
animation.duration = kf.keytime;
nodeAnim.translation.add(new NodeKeyframe<Vector3>(kf.keytime, new Vector3(kf.value == null ? node.translation : kf.value)));
}
}
if (nanim.rotation != null) {
nodeAnim.rotation = new Array<NodeKeyframe<Quaternion>>();
nodeAnim.rotation.ensureCapacity(nanim.rotation.size);
for (ModelNodeKeyframe<Quaternion> kf : nanim.rotation) {
if (kf.keytime > animation.duration)
animation.duration = kf.keytime;
nodeAnim.rotation.add(new NodeKeyframe<Quaternion>(kf.keytime, new Quaternion(kf.value == null ? node.rotation : kf.value)));
}
}
if (nanim.scaling != null) {
nodeAnim.scaling = new Array<NodeKeyframe<Vector3>>();
nodeAnim.scaling.ensureCapacity(nanim.scaling.size);
for (ModelNodeKeyframe<Vector3> kf : nanim.scaling) {
if (kf.keytime > animation.duration)
animation.duration = kf.keytime;
nodeAnim.scaling.add(new NodeKeyframe<Vector3>(kf.keytime, new Vector3(kf.value == null ? node.scale : kf.value)));
}
}
if ((nodeAnim.translation != null && nodeAnim.translation.size > 0) || (nodeAnim.rotation != null && nodeAnim.rotation.size > 0) || (nodeAnim.scaling != null && nodeAnim.scaling.size > 0))
animation.nodeAnimations.add(nodeAnim);
}
if (animation.nodeAnimations.size > 0)
animations.add(animation);
}
}
use of com.badlogic.gdx.graphics.g3d.model.NodeAnimation in project libgdx by libgdx.
the class ModelInstance method copyAnimations.
private void copyAnimations(final Iterable<Animation> source, boolean shareKeyframes) {
for (final Animation anim : source) {
Animation animation = new Animation();
animation.id = anim.id;
animation.duration = anim.duration;
for (final NodeAnimation nanim : anim.nodeAnimations) {
final Node node = getNode(nanim.node.id);
if (node == null)
continue;
NodeAnimation nodeAnim = new NodeAnimation();
nodeAnim.node = node;
if (shareKeyframes) {
nodeAnim.translation = nanim.translation;
nodeAnim.rotation = nanim.rotation;
nodeAnim.scaling = nanim.scaling;
} else {
if (nanim.translation != null) {
nodeAnim.translation = new Array<NodeKeyframe<Vector3>>();
for (final NodeKeyframe<Vector3> kf : nanim.translation) nodeAnim.translation.add(new NodeKeyframe<Vector3>(kf.keytime, kf.value));
}
if (nanim.rotation != null) {
nodeAnim.rotation = new Array<NodeKeyframe<Quaternion>>();
for (final NodeKeyframe<Quaternion> kf : nanim.rotation) nodeAnim.rotation.add(new NodeKeyframe<Quaternion>(kf.keytime, kf.value));
}
if (nanim.scaling != null) {
nodeAnim.scaling = new Array<NodeKeyframe<Vector3>>();
for (final NodeKeyframe<Vector3> kf : nanim.scaling) nodeAnim.scaling.add(new NodeKeyframe<Vector3>(kf.keytime, kf.value));
}
}
if (nodeAnim.translation != null || nodeAnim.rotation != null || nodeAnim.scaling != null)
animation.nodeAnimations.add(nodeAnim);
}
if (animation.nodeAnimations.size > 0)
animations.add(animation);
}
}
use of com.badlogic.gdx.graphics.g3d.model.NodeAnimation in project libgdx by libgdx.
the class BaseAnimationController method applyAnimation.
/** Helper method to apply one animation to either an objectmap for blending or directly to the bones. */
protected static void applyAnimation(final ObjectMap<Node, Transform> out, final Pool<Transform> pool, final float alpha, final Animation animation, final float time) {
if (out == null) {
for (final NodeAnimation nodeAnim : animation.nodeAnimations) applyNodeAnimationDirectly(nodeAnim, time);
} else {
for (final Node node : out.keys()) node.isAnimated = false;
for (final NodeAnimation nodeAnim : animation.nodeAnimations) applyNodeAnimationBlending(nodeAnim, out, pool, alpha, time);
for (final ObjectMap.Entry<Node, Transform> e : out.entries()) {
if (!e.key.isAnimated) {
e.key.isAnimated = true;
e.value.lerp(e.key.translation, e.key.rotation, e.key.scale, alpha);
}
}
}
}
Aggregations