BypassNode.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. import { Node } from '../core/Node.js';
  2. function BypassNode( code, value ) {
  3. Node.call( this );
  4. this.code = code;
  5. this.value = value;
  6. }
  7. BypassNode.prototype = Object.create( Node.prototype );
  8. BypassNode.prototype.constructor = BypassNode;
  9. BypassNode.prototype.nodeType = 'Bypass';
  10. BypassNode.prototype.getType = function ( builder ) {
  11. if ( this.value ) {
  12. return this.value.getType( builder );
  13. } else if ( builder.isShader( 'fragment' ) ) {
  14. return 'f';
  15. }
  16. return 'void';
  17. };
  18. BypassNode.prototype.generate = function ( builder, output ) {
  19. var code = this.code.build( builder, output ) + ';';
  20. builder.addNodeCode( code );
  21. if ( builder.isShader( 'vertex' ) ) {
  22. if ( this.value ) {
  23. return this.value.build( builder, output );
  24. }
  25. } else {
  26. return this.value ? this.value.build( builder, output ) : builder.format( '0.0', 'f', output );
  27. }
  28. };
  29. BypassNode.prototype.copy = function ( source ) {
  30. Node.prototype.copy.call( this, source );
  31. this.code = source.code;
  32. this.value = source.value;
  33. return this;
  34. };
  35. BypassNode.prototype.toJSON = function ( meta ) {
  36. var data = this.getJSONNode( meta );
  37. if ( ! data ) {
  38. data = this.createJSONNode( meta );
  39. data.code = this.code.toJSON( meta ).uuid;
  40. if ( this.value ) data.value = this.value.toJSON( meta ).uuid;
  41. }
  42. return data;
  43. };
  44. export { BypassNode };