InputNode.js 1.6 KB

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