BypassNode.js 1.1 KB

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