     @creatureManager.stop()
     @creatureRenderer.stop()
 
+  _applyBoneCorrection: (bone, correction) ->
+    bone.world_start_pt[0] += correction.x
+    bone.world_start_pt[1] -= correction.y
+    bone.world_end_pt[0] += correction.x
+    bone.world_end_pt[1] -= correction.y
+
+    for child in bone.children
+      @_applyBoneCorrection child, correction
+
   animationNames: ->
-    _.keys @data()?.animation
+    _.keys @dataEntry()?.animation
 
   update: (appTime, updateData = true) ->
     @_accumulatedTime += appTime.elapsedAppTime


      @materials.updated()

    # Prepare animation data.
    @correctedData = new ComputedField =>
      return unless data = @data()

      boneCorrections = @boneCorrections()
      return if @options.waitForBoneCorrections and not boneCorrections

      if boneCorrections
        if @options.dataUrl
          data = @constructor.getCachedDataWithBoneCorrections @options.dataUrl, boneCorrections

        else
          data = @constructor._applyBoneCorrections data, boneCorrections

      data

    # Create creature objects.
    @creature = new ComputedField =>
      return unless data = @correctedData()

      new AS.Creature data
    ,
      true

    @creatureManager = new ComputedField =>
      return unless creature = @creature()
      data = @correctedData()

      creatureManager = new AS.CreatureManager creature
      @_autoBlendSet = false

      creatureManager.SetTimeScale @options.dataFPS

      for name, animationData of data.animation
        creatureManager.AddAnimation new AS.CreatureAnimation data, name

      creatureManager
    ,

AS = Artificial.Spectrum

class AS.AnimatedMesh extends AS.RenderObject
  @_dataEntryCache = {}

  @getCachedDataEntryField: (dataUrl) ->
    # Return the singleton field if we already have it.
    return @_dataEntryCache[dataUrl] if @_dataEntryCache[dataUrl]

    # Create a new field.
    @_dataEntryCache[dataUrl] = new ReactiveField null

    # Start loading its content.
    $.getJSON dataUrl, (data) =>
      animations = {}
      
      for name, animationData of data.animation
        animations[name] = new AS.CreatureAnimation data, name

      @_dataEntryCache[dataUrl] {data, animations}

    # Return the new field.
    @_dataEntryCache[dataUrl]

  constructor: (@options) ->
    super arguments...

    # Load data if provided with its URLs.
    if @options.dataUrl
      @dataEntry = @constructor.getCachedDataEntryField @options.dataUrl

    else
      @dataEntry = new ReactiveField @options.data

    @boneCorrections = new ReactiveField @options.boneCorrections

