(function (global, factory) { if (typeof define === "function" && define.amd) { define(["exports", "../core/TempNode.js", "../core/FunctionNode.js", "../inputs/FloatNode.js", "../accessors/PositionNode.js"], factory); } else if (typeof exports !== "undefined") { factory(exports, require("../core/TempNode.js"), require("../core/FunctionNode.js"), require("../inputs/FloatNode.js"), require("../accessors/PositionNode.js")); } else { var mod = { exports: {} }; factory(mod.exports, global.TempNode, global.FunctionNode, global.FloatNode, global.PositionNode); global.CameraNode = mod.exports; } })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _TempNode2, _FunctionNode, _FloatNode, _PositionNode) { "use strict"; Object.defineProperty(_exports, "__esModule", { value: true }); _exports.CameraNode = 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 CameraNode = /*#__PURE__*/function (_TempNode) { _inherits(CameraNode, _TempNode); var _super = _createSuper(CameraNode); function CameraNode(scope, camera) { var _this; _classCallCheck(this, CameraNode); _this = _super.call(this, 'v3'); _this.setScope(scope || CameraNode.POSITION); _this.setCamera(camera); return _this; } _createClass(CameraNode, [{ key: "setCamera", value: function setCamera(camera) { this.camera = camera; this.updateFrame = camera !== undefined ? this.onUpdateFrame : undefined; } }, { key: "setScope", value: function setScope(scope) { switch (this.scope) { case CameraNode.DEPTH: delete this.near; delete this.far; break; } this.scope = scope; switch (scope) { case CameraNode.DEPTH: var camera = this.camera; this.near = new _FloatNode.FloatNode(camera ? camera.near : 1); this.far = new _FloatNode.FloatNode(camera ? camera.far : 1200); break; } } }, { key: "getType", value: function /* builder */ getType() { switch (this.scope) { case CameraNode.DEPTH: return 'f'; } return this.type; } }, { key: "getUnique", value: function /* builder */ getUnique() { switch (this.scope) { case CameraNode.DEPTH: case CameraNode.TO_VERTEX: return true; } return false; } }, { key: "getShared", value: function /* builder */ getShared() { switch (this.scope) { case CameraNode.POSITION: return false; } return true; } }, { key: "generate", value: function generate(builder, output) { var result; switch (this.scope) { case CameraNode.POSITION: result = 'cameraPosition'; break; case CameraNode.DEPTH: var depthColor = builder.include(CameraNode.Nodes.depthColor); result = depthColor + '( ' + this.near.build(builder, 'f') + ', ' + this.far.build(builder, 'f') + ' )'; break; case CameraNode.TO_VERTEX: result = 'normalize( ' + new _PositionNode.PositionNode(_PositionNode.PositionNode.WORLD).build(builder, 'v3') + ' - cameraPosition )'; break; } return builder.format(result, this.getType(builder), output); } }, { key: "onUpdateFrame", value: function /* frame */ onUpdateFrame() { switch (this.scope) { case CameraNode.DEPTH: var camera = this.camera; this.near.value = camera.near; this.far.value = camera.far; break; } } }, { key: "copy", value: function copy(source) { _get(_getPrototypeOf(CameraNode.prototype), "copy", this).call(this, source); this.setScope(source.scope); if (source.camera) { this.setCamera(source.camera); } switch (source.scope) { case CameraNode.DEPTH: this.near.number = source.near; this.far.number = source.far; break; } return this; } }, { key: "toJSON", value: function toJSON(meta) { var data = this.getJSONNode(meta); if (!data) { data = this.createJSONNode(meta); data.scope = this.scope; if (this.camera) data.camera = this.camera.uuid; switch (this.scope) { case CameraNode.DEPTH: data.near = this.near.value; data.far = this.far.value; break; } } return data; } }]); return CameraNode; }(_TempNode2.TempNode); _exports.CameraNode = CameraNode; CameraNode.Nodes = function () { var depthColor = new _FunctionNode.FunctionNode( /* glsl */ "\n\t\tfloat depthColor( float mNear, float mFar ) {\n\n\t\t\t#ifdef USE_LOGDEPTHBUF_EXT\n\n\t\t\t\tfloat depth = gl_FragDepthEXT / gl_FragCoord.w;\n\n\t\t\t#else\n\n\t\t\t\tfloat depth = gl_FragCoord.z / gl_FragCoord.w;\n\n\t\t\t#endif\n\n\t\t\treturn 1.0 - smoothstep( mNear, mFar, depth );\n\n\t\t}"); return { depthColor: depthColor }; }(); CameraNode.POSITION = 'position'; CameraNode.DEPTH = 'depth'; CameraNode.TO_VERTEX = 'toVertex'; CameraNode.prototype.nodeType = 'Camera'; });