Advertisement
Guest User

Untitled

a guest
Nov 18th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     PickFramebuffer.prototype.endWithRect = function(screenSpaceRectangle) {
  2.         var width = defaultValue(screenSpaceRectangle.width, 1.0);
  3.         var height = defaultValue(screenSpaceRectangle.height, 1.0);
  4.  
  5.         var context = this._context;
  6.         var pixels = context.readPixels({
  7.             x : screenSpaceRectangle.x,
  8.             y : screenSpaceRectangle.y,
  9.             width : width,
  10.             height : height,
  11.             framebuffer : this._fb
  12.         });
  13.  
  14.         var temp = [];
  15.         var length = width * height;
  16.  
  17.         // Collect all objects in the captured buffer
  18.         var i = 0;
  19.         while (i < length) {
  20.             colorScratch.red = Color.byteToFloat(pixels[i]);
  21.             colorScratch.green = Color.byteToFloat(pixels[i + 1]);
  22.             colorScratch.blue = Color.byteToFloat(pixels[i + 2]);
  23.             colorScratch.alpha = Color.byteToFloat(pixels[i + 3]);
  24.  
  25.             var object = context.getObjectByPickColor(colorScratch);
  26.             if (defined(object)) {
  27.                 temp.push(object);
  28.             }
  29.            
  30.             i+=4;
  31.         }
  32.  
  33.         // now copy only unique objects to result
  34.         var result = [];
  35.         for (var i = 0; i < temp.length; i++ ) {
  36.             var current = temp[i];
  37.             if (result.indexOf(current) < 0) result.push(current);
  38.         }        
  39.        
  40.         return result;
  41.     };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement