ColorNode.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. };
  22. ColorNode.prototype.toJSON = function ( meta ) {
  23. var data = this.getJSONNode( meta );
  24. if ( ! data ) {
  25. data = this.createJSONNode( meta );
  26. data.r = this.r;
  27. data.g = this.g;
  28. data.b = this.b;
  29. if ( this.readonly === true ) data.readonly = true;
  30. }
  31. return data;
  32. };
  33. export { ColorNode };