ColorNode.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. import { Color } from '../../../../build/three.module.js';
  5. import { InputNode } from '../core/InputNode.js';
  6. import { NodeUtils } from '../core/NodeUtils.js';
  7. function ColorNode( color, g, b ) {
  8. InputNode.call( this, 'c' );
  9. this.value = color instanceof Color ? color : new Color( color || 0, g, b );
  10. }
  11. ColorNode.prototype = Object.create( InputNode.prototype );
  12. ColorNode.prototype.constructor = ColorNode;
  13. ColorNode.prototype.nodeType = "Color";
  14. NodeUtils.addShortcuts( ColorNode.prototype, 'value', [ 'r', 'g', 'b' ] );
  15. ColorNode.prototype.generateReadonly = function ( builder, output, uuid, type/*, ns, needsUpdate */ ) {
  16. return builder.format( "vec3( " + this.r + ", " + this.g + ", " + this.b + " )", type, output );
  17. };
  18. ColorNode.prototype.copy = function ( source ) {
  19. InputNode.prototype.copy.call( this, source );
  20. this.value.copy( source );
  21. return this;
  22. };
  23. ColorNode.prototype.toJSON = function ( meta ) {
  24. var data = this.getJSONNode( meta );
  25. if ( ! data ) {
  26. data = this.createJSONNode( meta );
  27. data.r = this.r;
  28. data.g = this.g;
  29. data.b = this.b;
  30. if ( this.readonly === true ) data.readonly = true;
  31. }
  32. return data;
  33. };
  34. export { ColorNode };