InputNode.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. this.hashProperties = this.readonly ? [ "value" ] : undefined;
  16. return this;
  17. };
  18. InputNode.prototype.getReadonly = function ( /* builder */ ) {
  19. return this.readonly;
  20. };
  21. InputNode.prototype.copy = function ( source ) {
  22. TempNode.prototype.copy.call( this, source );
  23. if ( source.readonly !== undefined ) this.readonly = source.readonly;
  24. return this;
  25. };
  26. InputNode.prototype.createJSONNode = function ( meta ) {
  27. var data = TempNode.prototype.createJSONNode.call( this, meta );
  28. if ( this.readonly === true ) data.readonly = this.readonly;
  29. return data;
  30. };
  31. InputNode.prototype.generate = function ( builder, output, uuid, type, ns, needsUpdate ) {
  32. uuid = builder.getUuid( uuid || this.getUuid() );
  33. type = type || this.getType( builder );
  34. var data = builder.getNodeData( uuid ),
  35. readonly = this.getReadonly( builder ) && this.generateReadonly !== undefined;
  36. if ( readonly ) {
  37. return this.generateReadonly( builder, output, uuid, type, ns, needsUpdate );
  38. } else {
  39. if ( builder.isShader( 'vertex' ) ) {
  40. if ( ! data.vertex ) {
  41. data.vertex = builder.createVertexUniform( type, this, ns, needsUpdate, this.getLabel() );
  42. }
  43. return builder.format( data.vertex.name, type, output );
  44. } else {
  45. if ( ! data.fragment ) {
  46. data.fragment = builder.createFragmentUniform( type, this, ns, needsUpdate, this.getLabel() );
  47. }
  48. return builder.format( data.fragment.name, type, output );
  49. }
  50. }
  51. };
  52. export { InputNode };