ColorNode.js 1.2 KB

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