예제 #1
0
  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);
    }
  }
예제 #2
0
파일: Model.java 프로젝트: moly/libgdx
 private 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;
       for (ModelNodeKeyframe kf : nanim.keyframes) {
         if (kf.keytime > animation.duration) animation.duration = kf.keytime;
         NodeKeyframe keyframe = new NodeKeyframe();
         keyframe.keytime = kf.keytime;
         keyframe.rotation.set(kf.rotation == null ? node.rotation : kf.rotation);
         keyframe.scale.set(kf.scale == null ? node.scale : kf.scale);
         keyframe.translation.set(kf.translation == null ? node.translation : kf.translation);
         nodeAnim.keyframes.add(keyframe);
       }
       if (nodeAnim.keyframes.size > 0) animation.nodeAnimations.add(nodeAnim);
     }
     if (animation.nodeAnimations.size > 0) animations.add(animation);
   }
 }