BypassNode.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. THREE.BypassNode = function ( code, value ) {
  5. THREE.GLNode.call( this );
  6. this.code = code;
  7. this.value = value;
  8. };
  9. THREE.BypassNode.prototype = Object.create( THREE.GLNode.prototype );
  10. THREE.BypassNode.prototype.constructor = THREE.BypassNode;
  11. THREE.BypassNode.prototype.nodeType = "Bypass";
  12. THREE.BypassNode.prototype.getType = function ( builder ) {
  13. if ( this.value ) {
  14. return this.value.getType( builder );
  15. } else if (builder.isShader( 'fragment' )) {
  16. return 'fv1';
  17. }
  18. return 'void';
  19. };
  20. THREE.BypassNode.prototype.generate = function ( builder, output ) {
  21. var code = this.code.build( builder, output ) + ';';
  22. if ( builder.isShader( 'vertex' ) ) {
  23. builder.material.addVertexNode( code );
  24. if (this.value) {
  25. return this.value.build( builder, output );
  26. }
  27. } else {
  28. builder.material.addFragmentNode( code );
  29. return this.value ? this.value.build( builder, output ) : builder.format( '0.0', 'fv1', output );
  30. }
  31. };
  32. THREE.BypassNode.prototype.copy = function ( source ) {
  33. THREE.GLNode.prototype.copy.call( this, source );
  34. this.code = source.code;
  35. this.value = source.value;
  36. };
  37. THREE.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. };