 						callback err
 					else
 						callback null, new Uint8Array(data) 
+	
+	data : []
+	size : [0,0,0]
+	offset : [0,0,0]
+
+	BUCKET_WIDTH : 64
+
+	bucketIndex : (x, y, z) ->
+		
+		_bucket_width = @BUCKET_WIDTH
+		_offset = @offset
+		_size = @size
+
+		(x / _bucket_width - _offset[0] >> 0) + 
+		(y / _bucket_width - _offset[1] >> 0) * _size[0] + 
+		(z / _bucket_width - _offset[2] >> 0) * _size[0] * _size[1]
+	
+	pointIndex : (x, y, z) ->
+		
+		_bucket_width = @BUCKET_WIDTH
+
+		(x % _bucket_width >> 0) +
+		(y % _bucket_width >> 0) * _bucket_width +
+		(z % _bucket_width >> 0) * _bucket_width * _bucket_width
+
+	extendPoints : (x0, y0, z0, x1, y1, z1) ->
+		
+		_bucket_width = @BUCKET_WIDTH
+
+		@extendCube(
+			x0 / _bucket_width >> 0,
+			y0 / _bucket_width >> 0,
+			x0 / _bucket_width >> 0,
+			x1 / _bucket_width >> 0,
+			y1 / _bucket_width >> 0,
+			z1 / _bucket_width >> 0
+		)
+
+	extendCube : (x0, y0, z0, x1, y1, z1) ->
+		
+		_offset = @offset
+		_size = @size
+		_data = @data
+
+		cubeOffset = [
+			Math.min(x0, x1, _offset[0])
+			Math.min(y0, y1, _offset[1])
+			Math.min(z0, z1, _offset[2])
+		]
+		cubeSize = [
+			Math.max(x0, x1, _offset[0] + _size[0]) - cubeOffset[0] + 1
+			Math.max(y0, y1, _offset[1] + _size[1]) - cubeOffset[1] + 1
+			Math.max(z0, z1, _offset[2] + _size[2]) - cubeOffset[2] + 1
+		]
+
+		cube = []
+		for z in [0...cubeSize[2]]
+			for y in [0...cubeSize[1]]
+				for x in [0...cubeSize[0]]
+					index =
+						(x - _offset[0]) +
+						(y - _offset[1]) * _size[0] +
+						(z - _offset[2]) * _size[0] * _size[1] 
+					
+					cube.push _data[index]
+						
+					
+		@data = cube
+		@offset = cubeOffset
+		@size = cubeSize
+
+	value : (x, y, z, newValue) ->
+
+		bucketIndex = @bucketIndex(x, y, z)
+		bucket = @data[bucketIndex]
+
+		unless newValue?
+			if bucket?
+				bucket[@pointIndex(x, y, z)]
+			else
+				-1
+		else
+			if 0 <= bucketIndex < @data.length
+				unless bucket?
+					_bucket_width = @BUCKET_WIDTH
+					bucket = @data[bucketIndex] = new Float32Array(_bucket_width * _bucket_width * _bucket_width)
+				bucket[@pointIndex(x, y, z)] = newValue
+			else
+				throw "cube fault"
 
 
 Model.Mesh =


			@load position, direction, @synchronizingCallback(loadedData, finalCallback)

	load : (point, direction, callback) ->
		@lazyInitialize (err) ->
			return callback(err) if err

			request
				url : "/binary/data/cube?px=#{point[0]}&py=#{point[1]}&pz=#{point[2]}&ax=#{direction[0]}&ay=#{direction[1]}&az=#{direction[2]}"
				responseType : 'arraybuffer'
				,
				(err, data) ->

			colors[i / 3] = if xd == 0
				if yd == 0
					if zd == 0
						_value(x, y, z)
					else
						#linear z
						Interpolation.linear(_value(x, y, z0), _value(x, y, z1), zd)
				else
					if zd == 0
						#linear y
						Interpolation.linear(_value(x, y0, z), _value(x, y1, z), yd)
					else
						#bilinear y,z
						Interpolation.bilinear(
							_value(x, y0, z0), 
							_value(x, y1, z0), 
							_value(x, y0, z1), 
							_value(x, y1, z1), 
							yd, zd)
			else
				if yd == 0
					if zd == 0
						#linear x
						Interpolation.linear(_value(x0, y, z), _value(x1, y, z), xd)
					else
						#bilinear x,z
						Interpolation.bilinear(
							_value(x0, y, z0), 
							_value(x1, y, z0), 
							_value(x0, y, z1), 
							_value(x1, y, z1), 
							xd, zd)
				else
					if zd == 0
						#bilinear x,y
						Interpolation.bilinear(
							_value(x0, y0, z), 
							_value(x1, y0, z), 
							_value(x0, y1, z), 
							_value(x1, y1, z), 
							xd, yd)
					else
						#trilinear x,y,z
						Interpolation.trilinear(
							_value(x0, y0, z0),
							_value(x1, y0, z0),
							_value(x0, y1, z0),
							_value(x1, y1, z0),
							_value(x0, y0, z1),
							_value(x1, y0, z1),
							_value(x0, y1, z1),
							_value(x1, y1, z1),
							xd, yd, zd
						)
		
		callback(null, colors)

	
	ping : (position, direction, callback) ->

		@ping = _.throttle2 @_ping, 20000
		@ping(position, direction, callback)

	_ping : (position, direction, callback) ->
		
		@lazyInitialize (err) =>
			return callback err if err
