               ###
 
             else
-              @_destinationColor = shadedColor
+              destinationColor = shadedColor
 
           else
-            @_destinationColor = sourceColor
+            destinationColor = sourceColor
 
         if erase
           @_imageData.data[pixelIndex + 3] = 0
 
         else
-          @_imageData.data[pixelIndex] = @_destinationColor.r * 255
-          @_imageData.data[pixelIndex + 1] = @_destinationColor.g * 255
-          @_imageData.data[pixelIndex + 2] = @_destinationColor.b * 255
-          @_imageData.data[pixelIndex + 3] = (@_destinationColor.a or 1) * 255
+          @_imageData.data[pixelIndex] = destinationColor.r * 255
+          @_imageData.data[pixelIndex + 1] = destinationColor.g * 255
+          @_imageData.data[pixelIndex + 2] = destinationColor.b * 255
+          @_imageData.data[pixelIndex + 3] = (destinationColor.a or 1) * 255
 
     @_canvas.putFullImageData @_imageData

    # On the server we need to manually request pixel maps.
    spriteData.requirePixelMaps() if Meteor.isServer

    palette = @palette()

    # Build a new canvas if needed.
    unless @_canvas?.width is spriteData.bounds.width and @_canvas?.height is spriteData.bounds.height


class LOI.Assets.Engine.Sprite
  constructor: (@options) ->
    @ready = new ComputedField =>
      return unless spriteData = @options.spriteData()
      return unless spriteData.layers?.length and spriteData.bounds
      return unless spriteData.customPalette or LOI.Assets.Palette.documents.findOne(spriteData.palette?._id) or @options.visualizeNormals?()

      true

    # Create temporary objects and constants.
    @_normal = new THREE.Vector3
    @_backward = new THREE.Vector3 0, 0, 1
    @_color = new THREE.Color
    @_lightColor = new THREE.Color
    @_averageNormal = new THREE.Vector3

