BypassNode.js 1.4 KB

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