'use strict';

/**
 * An Animator class for animating Skeleton's based on an AnimationData.
 *
 * Note: Internally makes use of the THREE.Animation class.
 *
 * @param skeleton
 * @param {AnimationData} animationData
 * @constructor
 */
function SkeletonAnimator(skeleton, animationData) {
  this.animation =
      SkeletonAnimator._createThreeAnimation(skeleton, animationData);
}

/**
 * @param [startTime]
 */
SkeletonAnimator.prototype.play = function(startTime) {
  this.animation.play(startTime);
};


SkeletonAnimator.prototype.pause = function() {
  this.animation.pause();
};

SkeletonAnimator.prototype.stop = function() {
  this.animation.stop();
};

/**
 * @param skeleton
 * @param {AnimationData} animationData
 * @private
 */
SkeletonAnimator._createThreeAnimation = function(skeleton, animationData) {
  var animD = {
    name: name,
    fps: animationData.fps,
    length: animationData.frameCount / animationData.fps,
    hierarchy: []
  };

  // Set up all the base bone animations
  for (var i = 0; i < skeleton.bones.length; ++i) {
    var b = skeleton.bones[i];

    var animT = {
      parent: i,
      keys: []
    };
    for (var j = 0; j < animationData.frameCount; ++j) {
      animT.keys.push({
        time: j / animationData.fps,
        pos: [b.position.x, b.position.y, b.position.z],
        rot: [b.rotation.x, b.rotation.y, b.rotation.z, b.rotation.w],
        scl: [1, 1, 1]
      });
    }
    animD.hierarchy.push(animT);
  }

  // Apply the channel transformations
  for (var j = 0; j < animationData.channels.length; ++j) {
    var c = animationData.channels[j];
    for (var i = 0; i < animationData.frameCount; ++i) {
      var thisKey = animD.hierarchy[c.index].keys[i];
      switch (c.type) {
        case AnimationData.CHANNEL_TYPE.Position:
          thisKey.pos = [c.frames[i].x, c.frames[i].y, c.frames[i].z];
          break;
        case AnimationData.CHANNEL_TYPE.Rotation:
          thisKey.rot = [c.frames[i].x, c.frames[i].y, c.frames[i].z, c.frames[i].w];
          break;
      }
    }
  }

  // Create the actual animation, we use a dummy root object since we manually
  //   configure the animated hierarchy below.
  var anim = new THREE.Animation({children: []}, animD);
  anim.hierarchy = skeleton.bones;
  return anim;
};

@@ -92,71 +92,8 @@
 %0A *%0A
- * Note: Internally makes use of the THREE.Animation class.%0A *%0A
  * @
@@ -226,30 +226,19 @@
 %7B%0A  
-this.animation =%0A     
+var animD =
  Ske
@@ -303,212 +303,224 @@
 a);%0A
-%7D%0A%0A/**%0A * @param %5BstartTime%5D%0A */%0ASkeletonAnimator.prototype.play = function(startTime) %7B%0A  this.animation.play(startTime);%0A%7D;%0A%0A%0ASkeletonAnimator.prototype.pause = function() %7B%0A  this.animation.pause()
+%0A  // Create the actual animation, we use a dummy root object since we manually%0A  //   configure the animated hierarchy below.%0A  THREE.Animation.call(this, %7Bchildren: %5B%5D%7D, animD);%0A  this.hierarchy = skeleton.bones
 ;%0A%7D
-;
 %0A%0ASk
@@ -547,55 +547,53 @@
 type
-.stop = function() %7B%0A  this.animation.stop();%0A%7D
+ = Object.create( THREE.Animation.prototype )
 ;%0A%0A/
@@ -1983,226 +1983,8 @@
 %0A%0A  
-// Create the actual animation, we use a dummy root object since we manually%0A  //   configure the animated hierarchy below.%0A  var anim = new THREE.Animation(%7Bchildren: %5B%5D%7D, animD);%0A  anim.hierarchy = skeleton.bones;%0A  
 retu
@@ -1990,13 +1990,14 @@
 urn anim
+D
 ;%0A%7D;%0A

Make SkeletonAnimator an actual THREE.Animation.