2
0

InputNode.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. return this;
  24. };
  25. InputNode.prototype.createJSONNode = function ( meta ) {
  26. var data = TempNode.prototype.createJSONNode.call( this, meta );
  27. if ( this.readonly === true ) data.readonly = this.readonly;
  28. return data;
  29. };
  30. InputNode.prototype.generate = function ( builder, output, uuid, type, ns, needsUpdate ) {
  31. uuid = builder.getUuid( uuid || this.getUuid() );
  32. type = type || this.getType( builder );
  33. var data = builder.getNodeData( uuid ),
  34. readonly = this.getReadonly( builder ) && this.generateReadonly !== undefined;
  35. if ( readonly ) {
  36. return this.generateReadonly( builder, output, uuid, type, ns, needsUpdate );
  37. } else {
  38. if ( builder.isShader( 'vertex' ) ) {
  39. if ( ! data.vertex ) {
  40. data.vertex = builder.createVertexUniform( type, this, ns, needsUpdate, this.getLabel() );
  41. }
  42. return builder.format( data.vertex.name, type, output );
  43. } else {
  44. if ( ! data.fragment ) {
  45. data.fragment = builder.createFragmentUniform( type, this, ns, needsUpdate, this.getLabel() );
  46. }
  47. return builder.format( data.fragment.name, type, output );
  48. }
  49. }
  50. };
  51. export { InputNode };