InputNode.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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.isReadonly = function ( builder ) {
  14. return this.readonly;
  15. };
  16. InputNode.prototype.copy = function ( source ) {
  17. TempNode.prototype.copy.call( this, source );
  18. if ( source.readonly !== undefined ) this.readonly = source.readonly;
  19. };
  20. InputNode.prototype.createJSONNode = function ( meta ) {
  21. var data = TempNode.prototype.createJSONNode.call( this, meta );
  22. if ( this.readonly === true ) data.readonly = this.readonly;
  23. return data;
  24. };
  25. InputNode.prototype.generate = function ( builder, output, uuid, type, ns, needsUpdate ) {
  26. uuid = builder.getUuid( uuid || this.getUuid() );
  27. type = type || this.getType( builder );
  28. var data = builder.getNodeData( uuid ),
  29. readonly = this.isReadonly( builder ) && this.generateReadonly !== undefined;
  30. if ( readonly ) {
  31. return this.generateReadonly( builder, output, uuid, type, ns, needsUpdate );
  32. } else {
  33. if ( builder.isShader( 'vertex' ) ) {
  34. if ( ! data.vertex ) {
  35. data.vertex = builder.createVertexUniform( type, this, ns, needsUpdate );
  36. }
  37. return builder.format( data.vertex.name, type, output );
  38. } else {
  39. if ( ! data.fragment ) {
  40. data.fragment = builder.createFragmentUniform( type, this, ns, needsUpdate );
  41. }
  42. return builder.format( data.fragment.name, type, output );
  43. }
  44. }
  45. };
  46. export { InputNode };