ColorAdjustmentNode.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.ColorAdjustmentNode = function ( rgb, adjustment, method ) {
  5. THREE.TempNode.call( this, 'v3' );
  6. this.rgb = rgb;
  7. this.adjustment = adjustment;
  8. this.method = method || THREE.ColorAdjustmentNode.SATURATION;
  9. };
  10. THREE.ColorAdjustmentNode.SATURATION = 'saturation';
  11. THREE.ColorAdjustmentNode.HUE = 'hue';
  12. THREE.ColorAdjustmentNode.VIBRANCE = 'vibrance';
  13. THREE.ColorAdjustmentNode.BRIGHTNESS = 'brightness';
  14. THREE.ColorAdjustmentNode.CONTRAST = 'contrast';
  15. THREE.ColorAdjustmentNode.prototype = Object.create( THREE.TempNode.prototype );
  16. THREE.ColorAdjustmentNode.prototype.constructor = THREE.ColorAdjustmentNode;
  17. THREE.ColorAdjustmentNode.prototype.nodeType = "ColorAdjustment";
  18. THREE.ColorAdjustmentNode.prototype.generate = function ( builder, output ) {
  19. var rgb = this.rgb.build( builder, 'v3' );
  20. var adjustment = this.adjustment.build( builder, 'fv1' );
  21. var name;
  22. switch ( this.method ) {
  23. case THREE.ColorAdjustmentNode.SATURATION:
  24. name = 'saturation_rgb';
  25. break;
  26. case THREE.ColorAdjustmentNode.HUE:
  27. name = 'hue_rgb';
  28. break;
  29. case THREE.ColorAdjustmentNode.VIBRANCE:
  30. name = 'vibrance_rgb';
  31. break;
  32. case THREE.ColorAdjustmentNode.BRIGHTNESS:
  33. return builder.format( '(' + rgb + '+' + adjustment + ')', this.getType( builder ), output );
  34. break;
  35. case THREE.ColorAdjustmentNode.CONTRAST:
  36. return builder.format( '(' + rgb + '*' + adjustment + ')', this.getType( builder ), output );
  37. break;
  38. }
  39. builder.include( name );
  40. return builder.format( name + '(' + rgb + ',' + adjustment + ')', this.getType( builder ), output );
  41. };
  42. THREE.ColorAdjustmentNode.prototype.copy = function ( source ) {
  43. THREE.GLNode.prototype.copy.call( this, source );
  44. this.rgb = source.rgb;
  45. this.adjustment = source.adjustment;
  46. this.method = source.method;
  47. };
  48. THREE.ColorAdjustmentNode.prototype.toJSON = function ( meta ) {
  49. var data = this.getJSONNode( meta );
  50. if ( ! data ) {
  51. data = this.createJSONNode( meta );
  52. data.rgb = this.rgb.toJSON( meta ).uuid;
  53. data.adjustment = this.adjustment.toJSON( meta ).uuid;
  54. data.method = this.method;
  55. }
  56. return data;
  57. };