Пример #1
0
 /**
  * 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) {
   for (final NodeAnimation nodeAnim : animation.nodeAnimations) {
     final Node node = nodeAnim.node;
     node.isAnimated = true;
     // Find the keyframe(s)
     final int n = nodeAnim.keyframes.size - 1;
     int first = 0, second = -1;
     for (int i = 0; i < n; i++) {
       if (time >= nodeAnim.keyframes.get(i).keytime
           && time <= nodeAnim.keyframes.get(i + 1).keytime) {
         first = i;
         second = i + 1;
         break;
       }
     }
     // Apply the first keyframe:
     final Transform transform = tmpT;
     final NodeKeyframe firstKeyframe = nodeAnim.keyframes.get(first);
     transform.set(firstKeyframe.translation, firstKeyframe.rotation, firstKeyframe.scale);
     // Lerp the second keyframe
     if (second > first) {
       final NodeKeyframe secondKeyframe = nodeAnim.keyframes.get(second);
       final float t =
           (time - firstKeyframe.keytime) / (secondKeyframe.keytime - firstKeyframe.keytime);
       transform.lerp(
           secondKeyframe.translation, secondKeyframe.rotation, secondKeyframe.scale, t);
     }
     // Apply the transform, either directly to the bone or to out when blending
     if (out == null) transform.toMatrix4(node.localTransform);
     else {
       if (out.containsKey(node)) {
         if (alpha == 1.f) out.get(node).set(transform);
         else out.get(node).lerp(transform, alpha);
       } else {
         out.put(node, pool.obtain().set(transform));
       }
     }
   }
 }