InputNode.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. import { TempNode } from './TempNode.js';
  5. function InputNode( type, params ) {
  6. params = params || {};
  7. params.shared = params.shared !== undefined ? params.shared : false;
  8. TempNode.call( this, type, params );
  9. this.readonly = false;
  10. }
  11. InputNode.prototype = Object.create( TempNode.prototype );
  12. InputNode.prototype.constructor = InputNode;
  13. InputNode.prototype.setReadonly = function ( value ) {
  14. this.readonly = value;
  15. return this;
  16. };
  17. InputNode.prototype.getReadonly = function ( /* builder */ ) {
  18. return this.readonly;
  19. };
  20. InputNode.prototype.copy = function ( source ) {
  21. TempNode.prototype.copy.call( this, source );
  22. if ( source.readonly !== undefined ) this.readonly = source.readonly;
  23. };
  24. InputNode.prototype.createJSONNode = function ( meta ) {
  25. var data = TempNode.prototype.createJSONNode.call( this, meta );
  26. if ( this.readonly === true ) data.readonly = this.readonly;
  27. return data;
  28. };
  29. InputNode.prototype.generate = function ( builder, output, uuid, type, ns, needsUpdate ) {
  30. uuid = builder.getUuid( uuid || this.getUuid() );
  31. type = type || this.getType( builder );
  32. var data = builder.getNodeData( uuid ),
  33. readonly = this.getReadonly( builder ) && this.generateReadonly !== undefined;
  34. if ( readonly ) {
  35. return this.generateReadonly( builder, output, uuid, type, ns, needsUpdate );
  36. } else {
  37. if ( builder.isShader( 'vertex' ) ) {
  38. if ( ! data.vertex ) {
  39. data.vertex = builder.createVertexUniform( type, this, ns, needsUpdate, this.getLabel() );
  40. }
  41. return builder.format( data.vertex.name, type, output );
  42. } else {
  43. if ( ! data.fragment ) {
  44. data.fragment = builder.createFragmentUniform( type, this, ns, needsUpdate, this.getLabel() );
  45. }
  46. return builder.format( data.fragment.name, type, output );
  47. }
  48. }
  49. };
  50. export { InputNode };