(function (global, factory) { if (typeof define === "function" && define.amd) { define(["exports", "three"], factory); } else if (typeof exports !== "undefined") { factory(exports, require("three")); } else { var mod = { exports: {} }; factory(mod.exports, global.three); global.LUTCubeLoader = mod.exports; } })(typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : this, function (_exports, _three) { "use strict"; Object.defineProperty(_exports, "__esModule", { value: true }); _exports.LUTCubeLoader = 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 _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 LUTCubeLoader = /*#__PURE__*/function (_Loader) { _inherits(LUTCubeLoader, _Loader); var _super = _createSuper(LUTCubeLoader); function LUTCubeLoader() { _classCallCheck(this, LUTCubeLoader); return _super.apply(this, arguments); } _createClass(LUTCubeLoader, [{ key: "load", value: function load(url, onLoad, onProgress, onError) { var _this = this; var loader = new _three.FileLoader(this.manager); loader.setPath(this.path); loader.setResponseType('text'); loader.load(url, function (text) { try { onLoad(_this.parse(text)); } catch (e) { if (onError) { onError(e); } else { console.error(e); } _this.manager.itemError(url); } }, onProgress, onError); } }, { key: "parse", value: function parse(str) { // Remove empty lines and comments str = str.replace(/^#.*?(\n|\r)/gm, '').replace(/^\s*?(\n|\r)/gm, '').trim(); var title = null; var size = null; var domainMin = new _three.Vector3(0, 0, 0); var domainMax = new _three.Vector3(1, 1, 1); var lines = str.split(/[\n\r]+/g); var data = null; var currIndex = 0; for (var i = 0, l = lines.length; i < l; i++) { var line = lines[i].trim(); var split = line.split(/\s/g); switch (split[0]) { case 'TITLE': title = line.substring(7, line.length - 1); break; case 'LUT_3D_SIZE': // TODO: A .CUBE LUT file specifies floating point values and could be represented with // more precision than can be captured with Uint8Array. var sizeToken = split[1]; size = parseFloat(sizeToken); data = new Uint8Array(size * size * size * 3); break; case 'DOMAIN_MIN': domainMin.x = parseFloat(split[1]); domainMin.y = parseFloat(split[2]); domainMin.z = parseFloat(split[3]); break; case 'DOMAIN_MAX': domainMax.x = parseFloat(split[1]); domainMax.y = parseFloat(split[2]); domainMax.z = parseFloat(split[3]); break; default: var r = parseFloat(split[0]); var g = parseFloat(split[1]); var b = parseFloat(split[2]); if (r > 1.0 || r < 0.0 || g > 1.0 || g < 0.0 || b > 1.0 || b < 0.0) { throw new Error('LUTCubeLoader : Non normalized values not supported.'); } data[currIndex + 0] = r * 255; data[currIndex + 1] = g * 255; data[currIndex + 2] = b * 255; currIndex += 3; } } var texture = new _three.DataTexture(); texture.image.data = data; texture.image.width = size; texture.image.height = size * size; texture.format = _three.RGBFormat; texture.type = _three.UnsignedByteType; texture.magFilter = _three.LinearFilter; texture.minFilter = _three.LinearFilter; texture.wrapS = _three.ClampToEdgeWrapping; texture.wrapT = _three.ClampToEdgeWrapping; texture.generateMipmaps = false; var texture3D = new _three.DataTexture3D(); texture3D.image.data = data; texture3D.image.width = size; texture3D.image.height = size; texture3D.image.depth = size; texture3D.format = _three.RGBFormat; texture3D.type = _three.UnsignedByteType; texture3D.magFilter = _three.LinearFilter; texture3D.minFilter = _three.LinearFilter; texture3D.wrapS = _three.ClampToEdgeWrapping; texture3D.wrapT = _three.ClampToEdgeWrapping; texture3D.wrapR = _three.ClampToEdgeWrapping; texture3D.generateMipmaps = false; return { title: title, size: size, domainMin: domainMin, domainMax: domainMax, texture: texture, texture3D: texture3D }; } }]); return LUTCubeLoader; }(_three.Loader); _exports.LUTCubeLoader = LUTCubeLoader; });