(function (global, factory) { if (typeof define === "function" && define.amd) { define(["exports", "three", "../core/NodeBuilder.js", "../materials/NodeMaterial.js", "./TextureNode.js"], factory); } else if (typeof exports !== "undefined") { factory(exports, require("three"), require("../core/NodeBuilder.js"), require("../materials/NodeMaterial.js"), require("./TextureNode.js")); } else { var mod = { exports: {} }; factory(mod.exports, global.three, global.NodeBuilder, global.NodeMaterial, global.TextureNode); global.RTTNode = mod.exports; } })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _three, _NodeBuilder, _NodeMaterial, _TextureNode2) { "use strict"; Object.defineProperty(_exports, "__esModule", { value: true }); _exports.RTTNode = void 0; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _get() { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(arguments.length < 3 ? target : receiver); } return desc.value; }; } return _get.apply(this, arguments); } function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } Object.defineProperty(subClass, "prototype", { value: Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }), writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (typeof call === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var RTTNode = /*#__PURE__*/function (_TextureNode) { _inherits(RTTNode, _TextureNode); var _super = _createSuper(RTTNode); function RTTNode(width, height, input) { var _this; var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {}; _classCallCheck(this, RTTNode); var renderTarget = new _three.WebGLRenderTarget(width, height, options); _this = _super.call(this, renderTarget.texture); _this.input = input; _this.clear = options.clear !== undefined ? options.clear : true; _this.renderTarget = renderTarget; _this.material = new _NodeMaterial.NodeMaterial(); _this.camera = new _three.OrthographicCamera(-1, 1, 1, -1, 0, 1); _this.scene = new _three.Scene(); _this.quad = new _three.Mesh(new _three.PlaneGeometry(2, 2), _this.material); _this.quad.frustumCulled = false; // Avoid getting clipped _this.scene.add(_this.quad); _this.render = true; return _this; } _createClass(RTTNode, [{ key: "build", value: function build(builder, output, uuid) { var rttBuilder = new _NodeBuilder.NodeBuilder(); rttBuilder.nodes = builder.nodes; rttBuilder.updaters = builder.updaters; this.material.fragment.value = this.input; this.material.build({ builder: rttBuilder }); return _get(_getPrototypeOf(RTTNode.prototype), "build", this).call(this, builder, output, uuid); } }, { key: "updateFramesaveTo", value: function updateFramesaveTo(frame) { this.saveTo.render = false; if (this.saveTo !== this.saveToCurrent) { if (this.saveToMaterial) this.saveToMaterial.dispose(); var material = new _NodeMaterial.NodeMaterial(); material.fragment.value = this; material.build(); var scene = new _three.Scene(); var quad = new _three.Mesh(new _three.PlaneGeometry(2, 2), material); quad.frustumCulled = false; // Avoid getting clipped scene.add(quad); this.saveToScene = scene; this.saveToMaterial = material; } this.saveToCurrent = this.saveTo; frame.renderer.setRenderTarget(this.saveTo.renderTarget); if (this.saveTo.clear) frame.renderer.clear(); frame.renderer.render(this.saveToScene, this.camera); } }, { key: "updateFrame", value: function updateFrame(frame) { if (frame.renderer) { // from the second frame if (this.saveTo && this.saveTo.render === false) { this.updateFramesaveTo(frame); } if (this.render) { if (this.material.uniforms.renderTexture) { this.material.uniforms.renderTexture.value = frame.renderTexture; } frame.renderer.setRenderTarget(this.renderTarget); if (this.clear) frame.renderer.clear(); frame.renderer.render(this.scene, this.camera); } // first frame if (this.saveTo && this.saveTo.render === true) { this.updateFramesaveTo(frame); } } else { console.warn('RTTNode need a renderer in NodeFrame'); } } }, { key: "copy", value: function copy(source) { _get(_getPrototypeOf(RTTNode.prototype), "copy", this).call(this, source); this.saveTo = source.saveTo; return this; } }, { key: "toJSON", value: function toJSON(meta) { var data = this.getJSONNode(meta); if (!data) { data = _get(_getPrototypeOf(RTTNode.prototype), "toJSON", this).call(this, meta); if (this.saveTo) data.saveTo = this.saveTo.toJSON(meta).uuid; } return data; } }]); return RTTNode; }(_TextureNode2.TextureNode); _exports.RTTNode = RTTNode; RTTNode.prototype.nodeType = 'RTT'; });