BypassNode.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. import { GLNode } from '../core/GLNode.js';
  5. function BypassNode( code, value ) {
  6. GLNode.call( this );
  7. this.code = code;
  8. this.value = value;
  9. };
  10. BypassNode.prototype = Object.create( GLNode.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 'fv1';
  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', 'fv1', output );
  30. }
  31. };
  32. BypassNode.prototype.copy = function ( source ) {
  33. GLNode.prototype.copy.call( this, source );
  34. this.code = source.code;
  35. this.value = source.value;
  36. };
  37. BypassNode.prototype.toJSON = function ( meta ) {
  38. var data = this.getJSONNode( meta );
  39. if ( ! data ) {
  40. data = this.createJSONNode( meta );
  41. data.code = this.code.toJSON( meta ).uuid;
  42. if (this.value) data.value = this.value.toJSON( meta ).uuid;
  43. }
  44. return data;
  45. };
  46. export { BypassNode };