ColorNode.js 1.2 KB

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