(function (global, factory) { if (typeof define === "function" && define.amd) { define(["exports", "../core/InputNode.js", "../core/ExpressionNode.js", "../accessors/UVNode.js", "../display/ColorSpaceNode.js"], factory); } else if (typeof exports !== "undefined") { factory(exports, require("../core/InputNode.js"), require("../core/ExpressionNode.js"), require("../accessors/UVNode.js"), require("../display/ColorSpaceNode.js")); } else { var mod = { exports: {} }; factory(mod.exports, global.InputNode, global.ExpressionNode, global.UVNode, global.ColorSpaceNode); global.TextureNode = mod.exports; } })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _InputNode2, _ExpressionNode, _UVNode, _ColorSpaceNode) { "use strict"; Object.defineProperty(_exports, "__esModule", { value: true }); _exports.default = void 0; _InputNode2 = _interopRequireDefault(_InputNode2); _ExpressionNode = _interopRequireDefault(_ExpressionNode); _UVNode = _interopRequireDefault(_UVNode); _ColorSpaceNode = _interopRequireDefault(_ColorSpaceNode); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } 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 TextureNode = /*#__PURE__*/function (_InputNode) { _inherits(TextureNode, _InputNode); var _super = _createSuper(TextureNode); function TextureNode() { var _this; var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; var uv = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new _UVNode.default(); var bias = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null; _classCallCheck(this, TextureNode); _this = _super.call(this, 'texture'); _this.value = value; _this.uv = uv; _this.bias = bias; return _this; } _createClass(TextureNode, [{ key: "generate", value: function generate(builder, output) { var texture = this.value; if (!texture || texture.isTexture !== true) { throw new Error("TextureNode: Need a three.js texture."); } var type = this.getNodeType(builder); var textureProperty = _get(_getPrototypeOf(TextureNode.prototype), "generate", this).call(this, builder, type); if (output === 'sampler2D' || output === 'texture2D') { return textureProperty; } else if (output === 'sampler') { return textureProperty + '_sampler'; } else { var nodeData = builder.getDataFromNode(this); var colorSpace = nodeData.colorSpace; if (colorSpace === undefined) { var uvSnippet = this.uv.build(builder, 'vec2'); var bias = this.bias; var biasSnippet = null; if (bias !== null) { biasSnippet = bias.build(builder, 'float'); } var textureCallSnippet = builder.getTexture(textureProperty, uvSnippet, biasSnippet); colorSpace = new _ColorSpaceNode.default(); colorSpace.node = new _ExpressionNode.default(textureCallSnippet, 'vec4'); colorSpace.fromDecoding(builder.getTextureEncodingFromMap(texture)); nodeData.colorSpace = colorSpace; } return colorSpace.build(builder, output); } } }]); return TextureNode; }(_InputNode2.default); TextureNode.prototype.isTextureNode = true; var _default = TextureNode; _exports.default = _default; });