ColorAdjustmentNode.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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.toJSON = function ( meta ) {
  43. var data = this.getJSONNode( meta );
  44. if ( ! data ) {
  45. data = this.createJSONNode( meta );
  46. data.rgb = this.rgb.toJSON( meta ).uuid;
  47. data.adjustment = this.adjustment.toJSON( meta ).uuid;
  48. data.method = this.method;
  49. }
  50. return data;
  51. };