RTTNode.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. import { InputNode } from '../core/InputNode.js';
  5. import { NodeMaterial } from '../materials/NodeMaterial.js';
  6. import { TextureNode } from './TextureNode.js';
  7. function RTTNode( width, height, node, options ) {
  8. this.node = node;
  9. this.clear = true;
  10. this.rtt = new THREE.WebGLRenderTarget( width, height, options );
  11. this.material = new THREE.NodeMaterial();
  12. this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  13. this.scene = new THREE.Scene();
  14. this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), this.material );
  15. this.quad.frustumCulled = false; // Avoid getting clipped
  16. this.scene.add( this.quad );
  17. TextureNode.call( this, this.rtt.texture );
  18. };
  19. RTTNode.prototype = Object.create( TextureNode.prototype );
  20. RTTNode.prototype.constructor = RTTNode;
  21. RTTNode.prototype.nodeType = "RTT";
  22. RTTNode.prototype.generate = function ( builder, output ) {
  23. this.material.fragment.value = this.node;
  24. return TextureNode.prototype.generate.call( this, builder, output );
  25. };
  26. RTTNode.prototype.updateFrame = function ( frame ) {
  27. if ( frame.renderer ) {
  28. frame.renderer.render( this.scene, this.camera, this.rtt, this.clear );
  29. } else {
  30. console.warn("RTTNode need a renderer in NodeFrame")
  31. }
  32. };
  33. export { RTTNode };