ColorNode.js 1004 B

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