InputNode.js 1.9 KB

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