|
@@ -8,11 +8,13 @@ import { TextureNode } from './TextureNode.js';
|
|
|
|
|
|
function RTTNode( width, height, input, options ) {
|
|
|
|
|
|
+ options = options || {};
|
|
|
+
|
|
|
this.input = input;
|
|
|
|
|
|
- this.clear = true;
|
|
|
+ this.clear = options.clear !== undefined ? options.clear : true;
|
|
|
|
|
|
- this.rtt = new THREE.WebGLRenderTarget( width, height, options );
|
|
|
+ this.renderTarget = new THREE.WebGLRenderTarget( width, height, options );
|
|
|
|
|
|
this.material = new THREE.NodeMaterial();
|
|
|
|
|
@@ -23,7 +25,9 @@ function RTTNode( width, height, input, options ) {
|
|
|
this.quad.frustumCulled = false; // Avoid getting clipped
|
|
|
this.scene.add( this.quad );
|
|
|
|
|
|
- TextureNode.call( this, this.rtt.texture );
|
|
|
+ this.render = true;
|
|
|
+
|
|
|
+ TextureNode.call( this, this.renderTarget.texture );
|
|
|
|
|
|
};
|
|
|
|
|
@@ -31,18 +35,56 @@ RTTNode.prototype = Object.create( TextureNode.prototype );
|
|
|
RTTNode.prototype.constructor = RTTNode;
|
|
|
RTTNode.prototype.nodeType = "RTT";
|
|
|
|
|
|
-RTTNode.prototype.generate = function ( builder, output ) {
|
|
|
+RTTNode.prototype.build = function ( builder, output, uuid ) {
|
|
|
+
|
|
|
+ var rttBuilder = new THREE.NodeBuilder();
|
|
|
+ rttBuilder.nodes = builder.nodes;
|
|
|
+ rttBuilder.updaters = builder.updaters;
|
|
|
|
|
|
this.material.fragment.value = this.input;
|
|
|
+ this.material.build( { builder: rttBuilder } );
|
|
|
|
|
|
- return TextureNode.prototype.generate.call( this, builder, output );
|
|
|
+ return TextureNode.prototype.build.call( this, builder, output, uuid );
|
|
|
};
|
|
|
|
|
|
RTTNode.prototype.updateFrame = function ( frame ) {
|
|
|
|
|
|
if ( frame.renderer ) {
|
|
|
|
|
|
- frame.renderer.render( this.scene, this.camera, this.rtt, this.clear );
|
|
|
+ if (this.render) {
|
|
|
+
|
|
|
+ frame.renderer.render( this.scene, this.camera, this.renderTarget, this.clear );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if (this.saveToRTT) {
|
|
|
+
|
|
|
+ this.saveToRTT.render = false;
|
|
|
+
|
|
|
+ if (this.saveToRTT !== this.saveToRTTCurrent) {
|
|
|
+
|
|
|
+ if (this.saveToRTTMaterial) this.saveToRTTMaterial.dispose();
|
|
|
+
|
|
|
+ var material = new THREE.NodeMaterial();
|
|
|
+ material.fragment.value = this;
|
|
|
+ material.build();
|
|
|
+
|
|
|
+ var scene = new THREE.Scene();
|
|
|
+
|
|
|
+ var quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), material );
|
|
|
+ quad.frustumCulled = false; // Avoid getting clipped
|
|
|
+ scene.add( quad );
|
|
|
+
|
|
|
+ this.saveToRTTScene = scene;
|
|
|
+ this.saveToRTTMaterial = material;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ this.saveToRTTCurrent = this.saveToRTT;
|
|
|
+
|
|
|
+ frame.renderer.render( this.saveToRTTScene, this.camera, this.saveToRTT.renderTarget, this.saveToRTT.clear );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
} else {
|
|
|
|
|
@@ -52,4 +94,28 @@ RTTNode.prototype.updateFrame = function ( frame ) {
|
|
|
|
|
|
};
|
|
|
|
|
|
+RTTNode.prototype.copy = function ( source ) {
|
|
|
+
|
|
|
+ TextureNode.prototype.copy.call( this, source );
|
|
|
+
|
|
|
+ this.saveToRTT = source.saveToRTT;
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
+RTTNode.prototype.toJSON = function ( meta ) {
|
|
|
+
|
|
|
+ var data = this.getJSONNode( meta );
|
|
|
+
|
|
|
+ if ( ! data ) {
|
|
|
+
|
|
|
+ data = THREE.TextureNode.prototype.toJSON.call( this, meta );
|
|
|
+
|
|
|
+ if (this.saveToRTT) data.saveToRTT = this.saveToRTT.toJSON( meta ).uuid;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return data;
|
|
|
+
|
|
|
+};
|
|
|
+
|
|
|
export { RTTNode };
|