Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. /*
  2.  * hexToCGColor(hex) :  takes hexadecimal string as input, like CSS/HTML color value #ffffff
  3.  *          and translate it to a ComputerGraphics color array [1,1,1] that is suitable
  4.  *          for managing materials from cg standard software (ie.Blender)
  5.  *                     
  6.  *          no alpha channel parsing
  7.  */
  8.  
  9. function hexToCGColor(hex) {
  10.  
  11.     //cut out #
  12.     splitted = hex.substr(1);
  13.     //retrieving rgb values
  14.     r = parseInt(splitted.slice(0, 2), 16) / 255;
  15.     g = parseInt(splitted.slice(2, 4), 16) / 255;
  16.     b = parseInt(splitted.slice(4, 6), 16) / 255;
  17.     cgcolor = [r, g, b];
  18.     return (cgcolor);
  19. }