/* THIS IS A GENERATED/BUNDLED FILE BY ESBUILD if you want to view the source, please visit the github repository of this plugin */ var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __commonJS = (cb, mod) => function __require() { return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports; }; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( // If the importer is in node compatibility mode or this is not an ESM // file that has been converted to a CommonJS file using a Babel- // compatible transform (i.e. "__esModule" has not been set), then set // "default" to the CommonJS "module.exports" for node compatibility. isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // node_modules/observable-slim/observable-slim.js var require_observable_slim = __commonJS({ "node_modules/observable-slim/observable-slim.js"(exports, module2) { var ObservableSlim2 = function() { var paths = []; var observables = []; var targets = []; var targetsProxy = []; var dupProxy = null; var _getProperty = function(obj, path) { return path.split(".").reduce(function(prev, curr) { return prev ? prev[curr] : void 0; }, obj || self); }; var _create = function(target, domDelay, originalObservable, originalPath) { var observable = originalObservable || null; var path = originalPath || [{ "target": target, "property": "" }]; paths.push(path); if (target instanceof Array) { if (!target.hasOwnProperty("__length")) Object.defineProperty(target, "__length", { enumerable: false, value: target.length, writable: true }); else target.__length = target.length; } var changes = []; var _getPath = function(target2, property, jsonPointer) { var fullPath = ""; var lastTarget = null; for (var i = 0; i < path.length; i++) { if (lastTarget instanceof Array && !isNaN(path[i].property)) { path[i].property = lastTarget.indexOf(path[i].target); } fullPath = fullPath + "." + path[i].property; lastTarget = path[i].target; } fullPath = fullPath + "." + property; fullPath = fullPath.substring(2); if (jsonPointer === true) fullPath = "/" + fullPath.replace(/\./g, "/"); return fullPath; }; var _notifyObservers = function(numChanges) { if (observable.paused === true) return; var domDelayIsNumber = typeof domDelay === "number"; if (domDelayIsNumber || domDelay === true) { setTimeout(function() { if (numChanges === changes.length) { var changesCopy2 = changes.slice(0); changes = []; for (var i2 = 0; i2 < observable.observers.length; i2++) observable.observers[i2](changesCopy2); } }, domDelayIsNumber && domDelay > 0 ? domDelay : 10); } else { var changesCopy = changes.slice(0); changes = []; for (var i = 0; i < observable.observers.length; i++) observable.observers[i](changesCopy); } }; var handler = { get: function(target2, property) { if (property === "__getTarget") { return target2; } else if (property === "__isProxy") { return true; } else if (property === "__getParent") { return function(i2) { if (typeof i2 === "undefined") var i2 = 1; var parentPath2 = _getPath(target2, "__getParent").split("."); parentPath2.splice(-(i2 + 1), i2 + 1); return _getProperty(observable.parentProxy, parentPath2.join(".")); }; } else if (property === "__getPath") { var parentPath = _getPath(target2, "__getParent"); return parentPath.slice(0, -12); } var targetProp = target2[property]; if (target2 instanceof Date && targetProp instanceof Function && targetProp !== null) { return targetProp.bind(target2); } if (targetProp instanceof Object && targetProp !== null && target2.hasOwnProperty(property)) { if (targetProp.__isProxy === true) targetProp = targetProp.__getTarget; if (targetProp.__targetPosition > -1 && targets[targetProp.__targetPosition] !== null) { var ttp = targetsProxy[targetProp.__targetPosition]; for (var i = 0, l = ttp.length; i < l; i++) { if (observable === ttp[i].observable) { return ttp[i].proxy; } } } var newPath = path.slice(0); newPath.push({ "target": targetProp, "property": property }); return _create(targetProp, domDelay, observable, newPath); } else { return targetProp; } }, deleteProperty: function(target2, property) { var originalChange = true; if (dupProxy === proxy) { originalChange = false; dupProxy = null; } var previousValue = Object.assign({}, target2); changes.push({ "type": "delete", "target": target2, "property": property, "newValue": null, "previousValue": previousValue[property], "currentPath": _getPath(target2, property), "jsonPointer": _getPath(target2, property, true), "proxy": proxy }); if (originalChange === true) { if (!observable.changesPaused) delete target2[property]; for (var a2 = 0, l = targets.length; a2 < l; a2++) if (target2 === targets[a2]) break; var currentTargetProxy = targetsProxy[a2] || []; var b = currentTargetProxy.length; while (b--) { if (currentTargetProxy[b].proxy !== proxy) { dupProxy = currentTargetProxy[b].proxy; delete currentTargetProxy[b].proxy[property]; } } } _notifyObservers(changes.length); return true; }, set: function(target2, property, value, receiver) { if (value && value.__isProxy) value = value.__getTarget; var originalChange = true; if (dupProxy === proxy) { originalChange = false; dupProxy = null; } var targetProp = target2[property]; if (targetProp !== value || originalChange === false || property === "length" && target2 instanceof Array && target2.__length !== value) { var foundObservable = true; var typeOfTargetProp = typeof targetProp; var type = "update"; if (typeOfTargetProp === "undefined") type = "add"; changes.push({ "type": type, "target": target2, "property": property, "newValue": value, "previousValue": receiver[property], "currentPath": _getPath(target2, property), "jsonPointer": _getPath(target2, property, true), "proxy": proxy }); if (property === "length" && target2 instanceof Array && target2.__length !== value) { changes[changes.length - 1].previousValue = target2.__length; target2.__length = value; } if (originalChange === true) { if (!observable.changesPaused) target2[property] = value; foundObservable = false; var targetPosition = target2.__targetPosition; var z4 = targetsProxy[targetPosition].length; while (z4--) { if (observable === targetsProxy[targetPosition][z4].observable) { if (targets[targetsProxy[targetPosition][z4].observable.parentTarget.__targetPosition] !== null) { foundObservable = true; break; } } } if (foundObservable) { var currentTargetProxy = targetsProxy[targetPosition]; for (var b = 0, l = currentTargetProxy.length; b < l; b++) { if (currentTargetProxy[b].proxy !== proxy) { dupProxy = currentTargetProxy[b].proxy; currentTargetProxy[b].proxy[property] = value; } } setTimeout(function() { if (typeOfTargetProp === "object" && targetProp !== null) { var keys = Object.keys(target2); for (var i = 0, l2 = keys.length; i < l2; i++) { if (target2[keys[i]] === targetProp) return; } var stillExists = false; (function iterate(target3) { var keys2 = Object.keys(target3); for (var i2 = 0, l3 = keys2.length; i2 < l3; i2++) { var property2 = keys2[i2]; var nestedTarget = target3[property2]; if (nestedTarget instanceof Object && nestedTarget !== null) iterate(nestedTarget); if (nestedTarget === targetProp) { stillExists = true; return; } } ; })(target2); if (stillExists === true) return; (function iterate(obj) { var keys2 = Object.keys(obj); for (var i2 = 0, l3 = keys2.length; i2 < l3; i2++) { var objProp = obj[keys2[i2]]; if (objProp instanceof Object && objProp !== null) iterate(objProp); } var c2 = -1; for (var i2 = 0, l3 = targets.length; i2 < l3; i2++) { if (obj === targets[i2]) { c2 = i2; break; } } if (c2 > -1) { var currentTargetProxy2 = targetsProxy[c2]; var d = currentTargetProxy2.length; while (d--) { if (observable === currentTargetProxy2[d].observable) { currentTargetProxy2.splice(d, 1); break; } } if (currentTargetProxy2.length == 0) { targets[c2] = null; } } })(targetProp); } }, 1e4); } } ; if (foundObservable) { _notifyObservers(changes.length); } } return true; } }; var __targetPosition = target.__targetPosition; if (!(__targetPosition > -1)) { Object.defineProperty(target, "__targetPosition", { value: targets.length, writable: false, enumerable: false, configurable: false }); } var proxy = new Proxy(target, handler); if (observable === null) { observable = { "parentTarget": target, "domDelay": domDelay, "parentProxy": proxy, "observers": [], "paused": false, "path": path, "changesPaused": false }; observables.push(observable); } var proxyItem = { "target": target, "proxy": proxy, "observable": observable }; if (__targetPosition > -1) { if (targets[__targetPosition] === null) { targets[__targetPosition] = target; } targetsProxy[__targetPosition].push(proxyItem); } else { targets.push(target); targetsProxy.push([proxyItem]); } return proxy; }; return { /** * Create a new ES6 `Proxy` whose changes we can observe through the `observe()` method. * @param {object} target Plain object that we want to observe for changes. * @param {boolean|number} domDelay If `true`, then the observed changes to `target` will be batched up on a 10ms delay (via `setTimeout()`). * If `false`, then the `observer` function will be immediately invoked after each individual change made to `target`. It is helpful to set * `domDelay` to `true` when your `observer` function makes DOM manipulations (fewer DOM redraws means better performance). If a number greater * than zero, then it defines the DOM delay in milliseconds. * @param {function(ObservableSlimChange[])} [observer] Function that will be invoked when a change is made to the proxy of `target`. * When invoked, this function is passed a single argument: an array of `ObservableSlimChange` detailing each change that has been made. * @returns {ProxyConstructor} Proxy of the target object. */ create: function(target, domDelay, observer) { if (target.__isProxy === true) { var target = target.__getTarget; } var proxy = _create(target, domDelay); if (typeof observer === "function") this.observe(proxy, observer); (function iterate(proxy2) { var target2 = proxy2.__getTarget; var keys = Object.keys(target2); for (var i = 0, l = keys.length; i < l; i++) { var property = keys[i]; if (target2[property] instanceof Object && target2[property] !== null) iterate(proxy2[property]); } })(proxy); return proxy; }, /** * Add a new observer function to an existing proxy. * @param {ProxyConstructor} proxy An ES6 `Proxy` created by the `create()` method. * @param {function(ObservableSlimChange[])} observer Function that will be invoked when a change is made to the proxy of `target`. * When invoked, this function is passed a single argument: an array of `ObservableSlimChange` detailing each change that has been made. * @returns {void} Does not return any value. */ observe: function(proxy, observer) { var i = observables.length; while (i--) { if (observables[i].parentProxy === proxy) { observables[i].observers.push(observer); break; } } ; }, /** * Prevent any observer functions from being invoked when a change occurs to a proxy. * @param {ProxyConstructor} proxy An ES6 `Proxy` created by the `create()` method. * @returns {void} Does not return any value. */ pause: function(proxy) { var i = observables.length; var foundMatch = false; while (i--) { if (observables[i].parentProxy === proxy) { observables[i].paused = true; foundMatch = true; break; } } ; if (foundMatch == false) throw new Error("ObseravableSlim could not pause observable -- matching proxy not found."); }, /** * Resume execution of any observer functions when a change is made to a proxy. * @param {ProxyConstructor} proxy An ES6 `Proxy` created by the `create()` method. * @returns {void} Does not return any value. */ resume: function(proxy) { var i = observables.length; var foundMatch = false; while (i--) { if (observables[i].parentProxy === proxy) { observables[i].paused = false; foundMatch = true; break; } } ; if (foundMatch == false) throw new Error("ObseravableSlim could not resume observable -- matching proxy not found."); }, /** * Prevent any changes (i.e., `set`, and `deleteProperty`) from being written to the target object. * However, the observer functions will still be invoked to let you know what changes **WOULD** have been made. * This can be useful if the changes need to be approved by an external source before the changes take effect. * @param {ProxyConstructor} proxy An ES6 `Proxy` created by the `create()` method. * @returns {void} Does not return any value. */ pauseChanges: function(proxy) { var i = observables.length; var foundMatch = false; while (i--) { if (observables[i].parentProxy === proxy) { observables[i].changesPaused = true; foundMatch = true; break; } } ; if (foundMatch == false) throw new Error("ObseravableSlim could not pause changes on observable -- matching proxy not found."); }, /** * Resume the changes that were taking place prior to the call to `pauseChanges()` method. * @param {ProxyConstructor} proxy An ES6 `Proxy` created by the `create()` method. * @returns {void} Does not return any value. */ resumeChanges: function(proxy) { var i = observables.length; var foundMatch = false; while (i--) { if (observables[i].parentProxy === proxy) { observables[i].changesPaused = false; foundMatch = true; break; } } ; if (foundMatch == false) throw new Error("ObseravableSlim could not resume changes on observable -- matching proxy not found."); }, /** * Remove the observable and proxy thereby preventing any further callback observers for changes occurring to the target object. * @param {ProxyConstructor} proxy An ES6 `Proxy` created by the `create()` method. * @returns {void} Does not return any value. */ remove: function(proxy) { var matchedObservable = null; var foundMatch = false; var c2 = observables.length; while (c2--) { if (observables[c2].parentProxy === proxy) { matchedObservable = observables[c2]; foundMatch = true; break; } } ; var a2 = targetsProxy.length; while (a2--) { var b = targetsProxy[a2].length; while (b--) { if (targetsProxy[a2][b].observable === matchedObservable) { targetsProxy[a2].splice(b, 1); if (targetsProxy[a2].length === 0) { targets[a2] = null; } ; } } ; } ; if (foundMatch === true) { observables.splice(c2, 1); } } }; }(); try { module2.exports = ObservableSlim2; } catch (err) { } } }); // node_modules/obsidian-dataview/lib/index.js var require_lib = __commonJS({ "node_modules/obsidian-dataview/lib/index.js"(exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); require("obsidian"); var LuxonError = class extends Error { }; var InvalidDateTimeError = class extends LuxonError { constructor(reason) { super(`Invalid DateTime: ${reason.toMessage()}`); } }; var InvalidIntervalError = class extends LuxonError { constructor(reason) { super(`Invalid Interval: ${reason.toMessage()}`); } }; var InvalidDurationError = class extends LuxonError { constructor(reason) { super(`Invalid Duration: ${reason.toMessage()}`); } }; var ConflictingSpecificationError = class extends LuxonError { }; var InvalidUnitError = class extends LuxonError { constructor(unit) { super(`Invalid unit ${unit}`); } }; var InvalidArgumentError = class extends LuxonError { }; var ZoneIsAbstractError = class extends LuxonError { constructor() { super("Zone is an abstract class"); } }; var n = "numeric"; var s = "short"; var l = "long"; var DATE_SHORT = { year: n, month: n, day: n }; var DATE_MED = { year: n, month: s, day: n }; var DATE_MED_WITH_WEEKDAY = { year: n, month: s, day: n, weekday: s }; var DATE_FULL = { year: n, month: l, day: n }; var DATE_HUGE = { year: n, month: l, day: n, weekday: l }; var TIME_SIMPLE = { hour: n, minute: n }; var TIME_WITH_SECONDS = { hour: n, minute: n, second: n }; var TIME_WITH_SHORT_OFFSET = { hour: n, minute: n, second: n, timeZoneName: s }; var TIME_WITH_LONG_OFFSET = { hour: n, minute: n, second: n, timeZoneName: l }; var TIME_24_SIMPLE = { hour: n, minute: n, hourCycle: "h23" }; var TIME_24_WITH_SECONDS = { hour: n, minute: n, second: n, hourCycle: "h23" }; var TIME_24_WITH_SHORT_OFFSET = { hour: n, minute: n, second: n, hourCycle: "h23", timeZoneName: s }; var TIME_24_WITH_LONG_OFFSET = { hour: n, minute: n, second: n, hourCycle: "h23", timeZoneName: l }; var DATETIME_SHORT = { year: n, month: n, day: n, hour: n, minute: n }; var DATETIME_SHORT_WITH_SECONDS = { year: n, month: n, day: n, hour: n, minute: n, second: n }; var DATETIME_MED = { year: n, month: s, day: n, hour: n, minute: n }; var DATETIME_MED_WITH_SECONDS = { year: n, month: s, day: n, hour: n, minute: n, second: n }; var DATETIME_MED_WITH_WEEKDAY = { year: n, month: s, day: n, weekday: s, hour: n, minute: n }; var DATETIME_FULL = { year: n, month: l, day: n, hour: n, minute: n, timeZoneName: s }; var DATETIME_FULL_WITH_SECONDS = { year: n, month: l, day: n, hour: n, minute: n, second: n, timeZoneName: s }; var DATETIME_HUGE = { year: n, month: l, day: n, weekday: l, hour: n, minute: n, timeZoneName: l }; var DATETIME_HUGE_WITH_SECONDS = { year: n, month: l, day: n, weekday: l, hour: n, minute: n, second: n, timeZoneName: l }; var Zone = class { /** * The type of zone * @abstract * @type {string} */ get type() { throw new ZoneIsAbstractError(); } /** * The name of this zone. * @abstract * @type {string} */ get name() { throw new ZoneIsAbstractError(); } get ianaName() { return this.name; } /** * Returns whether the offset is known to be fixed for the whole year. * @abstract * @type {boolean} */ get isUniversal() { throw new ZoneIsAbstractError(); } /** * Returns the offset's common name (such as EST) at the specified timestamp * @abstract * @param {number} ts - Epoch milliseconds for which to get the name * @param {Object} opts - Options to affect the format * @param {string} opts.format - What style of offset to return. Accepts 'long' or 'short'. * @param {string} opts.locale - What locale to return the offset name in. * @return {string} */ offsetName(ts, opts) { throw new ZoneIsAbstractError(); } /** * Returns the offset's value as a string * @abstract * @param {number} ts - Epoch milliseconds for which to get the offset * @param {string} format - What style of offset to return. * Accepts 'narrow', 'short', or 'techie'. Returning '+6', '+06:00', or '+0600' respectively * @return {string} */ formatOffset(ts, format2) { throw new ZoneIsAbstractError(); } /** * Return the offset in minutes for this zone at the specified timestamp. * @abstract * @param {number} ts - Epoch milliseconds for which to compute the offset * @return {number} */ offset(ts) { throw new ZoneIsAbstractError(); } /** * Return whether this Zone is equal to another zone * @abstract * @param {Zone} otherZone - the zone to compare * @return {boolean} */ equals(otherZone) { throw new ZoneIsAbstractError(); } /** * Return whether this Zone is valid. * @abstract * @type {boolean} */ get isValid() { throw new ZoneIsAbstractError(); } }; var singleton$1 = null; var SystemZone = class extends Zone { /** * Get a singleton instance of the local zone * @return {SystemZone} */ static get instance() { if (singleton$1 === null) { singleton$1 = new SystemZone(); } return singleton$1; } /** @override **/ get type() { return "system"; } /** @override **/ get name() { return new Intl.DateTimeFormat().resolvedOptions().timeZone; } /** @override **/ get isUniversal() { return false; } /** @override **/ offsetName(ts, { format: format2, locale }) { return parseZoneInfo(ts, format2, locale); } /** @override **/ formatOffset(ts, format2) { return formatOffset(this.offset(ts), format2); } /** @override **/ offset(ts) { return -new Date(ts).getTimezoneOffset(); } /** @override **/ equals(otherZone) { return otherZone.type === "system"; } /** @override **/ get isValid() { return true; } }; var dtfCache = {}; function makeDTF(zone) { if (!dtfCache[zone]) { dtfCache[zone] = new Intl.DateTimeFormat("en-US", { hour12: false, timeZone: zone, year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit", era: "short" }); } return dtfCache[zone]; } var typeToPos = { year: 0, month: 1, day: 2, era: 3, hour: 4, minute: 5, second: 6 }; function hackyOffset(dtf, date) { const formatted = dtf.format(date).replace(/\u200E/g, ""), parsed = /(\d+)\/(\d+)\/(\d+) (AD|BC),? (\d+):(\d+):(\d+)/.exec(formatted), [, fMonth, fDay, fYear, fadOrBc, fHour, fMinute, fSecond] = parsed; return [fYear, fMonth, fDay, fadOrBc, fHour, fMinute, fSecond]; } function partsOffset(dtf, date) { const formatted = dtf.formatToParts(date); const filled = []; for (let i = 0; i < formatted.length; i++) { const { type, value } = formatted[i]; const pos = typeToPos[type]; if (type === "era") { filled[pos] = value; } else if (!isUndefined2(pos)) { filled[pos] = parseInt(value, 10); } } return filled; } var ianaZoneCache = {}; var IANAZone = class extends Zone { /** * @param {string} name - Zone name * @return {IANAZone} */ static create(name) { if (!ianaZoneCache[name]) { ianaZoneCache[name] = new IANAZone(name); } return ianaZoneCache[name]; } /** * Reset local caches. Should only be necessary in testing scenarios. * @return {void} */ static resetCache() { ianaZoneCache = {}; dtfCache = {}; } /** * Returns whether the provided string is a valid specifier. This only checks the string's format, not that the specifier identifies a known zone; see isValidZone for that. * @param {string} s - The string to check validity on * @example IANAZone.isValidSpecifier("America/New_York") //=> true * @example IANAZone.isValidSpecifier("Sport~~blorp") //=> false * @deprecated This method returns false for some valid IANA names. Use isValidZone instead. * @return {boolean} */ static isValidSpecifier(s2) { return this.isValidZone(s2); } /** * Returns whether the provided string identifies a real zone * @param {string} zone - The string to check * @example IANAZone.isValidZone("America/New_York") //=> true * @example IANAZone.isValidZone("Fantasia/Castle") //=> false * @example IANAZone.isValidZone("Sport~~blorp") //=> false * @return {boolean} */ static isValidZone(zone) { if (!zone) { return false; } try { new Intl.DateTimeFormat("en-US", { timeZone: zone }).format(); return true; } catch (e) { return false; } } constructor(name) { super(); this.zoneName = name; this.valid = IANAZone.isValidZone(name); } /** @override **/ get type() { return "iana"; } /** @override **/ get name() { return this.zoneName; } /** @override **/ get isUniversal() { return false; } /** @override **/ offsetName(ts, { format: format2, locale }) { return parseZoneInfo(ts, format2, locale, this.name); } /** @override **/ formatOffset(ts, format2) { return formatOffset(this.offset(ts), format2); } /** @override **/ offset(ts) { const date = new Date(ts); if (isNaN(date)) return NaN; const dtf = makeDTF(this.name); let [year, month, day, adOrBc, hour, minute, second] = dtf.formatToParts ? partsOffset(dtf, date) : hackyOffset(dtf, date); if (adOrBc === "BC") { year = -Math.abs(year) + 1; } const adjustedHour = hour === 24 ? 0 : hour; const asUTC = objToLocalTS({ year, month, day, hour: adjustedHour, minute, second, millisecond: 0 }); let asTS = +date; const over = asTS % 1e3; asTS -= over >= 0 ? over : 1e3 + over; return (asUTC - asTS) / (60 * 1e3); } /** @override **/ equals(otherZone) { return otherZone.type === "iana" && otherZone.name === this.name; } /** @override **/ get isValid() { return this.valid; } }; var intlLFCache = {}; function getCachedLF(locString, opts = {}) { const key = JSON.stringify([locString, opts]); let dtf = intlLFCache[key]; if (!dtf) { dtf = new Intl.ListFormat(locString, opts); intlLFCache[key] = dtf; } return dtf; } var intlDTCache = {}; function getCachedDTF(locString, opts = {}) { const key = JSON.stringify([locString, opts]); let dtf = intlDTCache[key]; if (!dtf) { dtf = new Intl.DateTimeFormat(locString, opts); intlDTCache[key] = dtf; } return dtf; } var intlNumCache = {}; function getCachedINF(locString, opts = {}) { const key = JSON.stringify([locString, opts]); let inf = intlNumCache[key]; if (!inf) { inf = new Intl.NumberFormat(locString, opts); intlNumCache[key] = inf; } return inf; } var intlRelCache = {}; function getCachedRTF(locString, opts = {}) { const { base, ...cacheKeyOpts } = opts; const key = JSON.stringify([locString, cacheKeyOpts]); let inf = intlRelCache[key]; if (!inf) { inf = new Intl.RelativeTimeFormat(locString, opts); intlRelCache[key] = inf; } return inf; } var sysLocaleCache = null; function systemLocale() { if (sysLocaleCache) { return sysLocaleCache; } else { sysLocaleCache = new Intl.DateTimeFormat().resolvedOptions().locale; return sysLocaleCache; } } function parseLocaleString(localeStr) { const xIndex = localeStr.indexOf("-x-"); if (xIndex !== -1) { localeStr = localeStr.substring(0, xIndex); } const uIndex = localeStr.indexOf("-u-"); if (uIndex === -1) { return [localeStr]; } else { let options; let selectedStr; try { options = getCachedDTF(localeStr).resolvedOptions(); selectedStr = localeStr; } catch (e) { const smaller = localeStr.substring(0, uIndex); options = getCachedDTF(smaller).resolvedOptions(); selectedStr = smaller; } const { numberingSystem, calendar } = options; return [selectedStr, numberingSystem, calendar]; } } function intlConfigString(localeStr, numberingSystem, outputCalendar) { if (outputCalendar || numberingSystem) { if (!localeStr.includes("-u-")) { localeStr += "-u"; } if (outputCalendar) { localeStr += `-ca-${outputCalendar}`; } if (numberingSystem) { localeStr += `-nu-${numberingSystem}`; } return localeStr; } else { return localeStr; } } function mapMonths(f) { const ms = []; for (let i = 1; i <= 12; i++) { const dt = DateTime.utc(2009, i, 1); ms.push(f(dt)); } return ms; } function mapWeekdays(f) { const ms = []; for (let i = 1; i <= 7; i++) { const dt = DateTime.utc(2016, 11, 13 + i); ms.push(f(dt)); } return ms; } function listStuff(loc, length, englishFn, intlFn) { const mode = loc.listingMode(); if (mode === "error") { return null; } else if (mode === "en") { return englishFn(length); } else { return intlFn(length); } } function supportsFastNumbers(loc) { if (loc.numberingSystem && loc.numberingSystem !== "latn") { return false; } else { return loc.numberingSystem === "latn" || !loc.locale || loc.locale.startsWith("en") || new Intl.DateTimeFormat(loc.intl).resolvedOptions().numberingSystem === "latn"; } } var PolyNumberFormatter = class { constructor(intl, forceSimple, opts) { this.padTo = opts.padTo || 0; this.floor = opts.floor || false; const { padTo, floor, ...otherOpts } = opts; if (!forceSimple || Object.keys(otherOpts).length > 0) { const intlOpts = { useGrouping: false, ...opts }; if (opts.padTo > 0) intlOpts.minimumIntegerDigits = opts.padTo; this.inf = getCachedINF(intl, intlOpts); } } format(i) { if (this.inf) { const fixed = this.floor ? Math.floor(i) : i; return this.inf.format(fixed); } else { const fixed = this.floor ? Math.floor(i) : roundTo(i, 3); return padStart(fixed, this.padTo); } } }; var PolyDateFormatter = class { constructor(dt, intl, opts) { this.opts = opts; this.originalZone = void 0; let z4 = void 0; if (this.opts.timeZone) { this.dt = dt; } else if (dt.zone.type === "fixed") { const gmtOffset = -1 * (dt.offset / 60); const offsetZ = gmtOffset >= 0 ? `Etc/GMT+${gmtOffset}` : `Etc/GMT${gmtOffset}`; if (dt.offset !== 0 && IANAZone.create(offsetZ).valid) { z4 = offsetZ; this.dt = dt; } else { z4 = "UTC"; this.dt = dt.offset === 0 ? dt : dt.setZone("UTC").plus({ minutes: dt.offset }); this.originalZone = dt.zone; } } else if (dt.zone.type === "system") { this.dt = dt; } else if (dt.zone.type === "iana") { this.dt = dt; z4 = dt.zone.name; } else { z4 = "UTC"; this.dt = dt.setZone("UTC").plus({ minutes: dt.offset }); this.originalZone = dt.zone; } const intlOpts = { ...this.opts }; intlOpts.timeZone = intlOpts.timeZone || z4; this.dtf = getCachedDTF(intl, intlOpts); } format() { if (this.originalZone) { return this.formatToParts().map(({ value }) => value).join(""); } return this.dtf.format(this.dt.toJSDate()); } formatToParts() { const parts = this.dtf.formatToParts(this.dt.toJSDate()); if (this.originalZone) { return parts.map((part) => { if (part.type === "timeZoneName") { const offsetName = this.originalZone.offsetName(this.dt.ts, { locale: this.dt.locale, format: this.opts.timeZoneName }); return { ...part, value: offsetName }; } else { return part; } }); } return parts; } resolvedOptions() { return this.dtf.resolvedOptions(); } }; var PolyRelFormatter = class { constructor(intl, isEnglish, opts) { this.opts = { style: "long", ...opts }; if (!isEnglish && hasRelative()) { this.rtf = getCachedRTF(intl, opts); } } format(count, unit) { if (this.rtf) { return this.rtf.format(count, unit); } else { return formatRelativeTime(unit, count, this.opts.numeric, this.opts.style !== "long"); } } formatToParts(count, unit) { if (this.rtf) { return this.rtf.formatToParts(count, unit); } else { return []; } } }; var Locale = class { static fromOpts(opts) { return Locale.create(opts.locale, opts.numberingSystem, opts.outputCalendar, opts.defaultToEN); } static create(locale, numberingSystem, outputCalendar, defaultToEN = false) { const specifiedLocale = locale || Settings.defaultLocale; const localeR = specifiedLocale || (defaultToEN ? "en-US" : systemLocale()); const numberingSystemR = numberingSystem || Settings.defaultNumberingSystem; const outputCalendarR = outputCalendar || Settings.defaultOutputCalendar; return new Locale(localeR, numberingSystemR, outputCalendarR, specifiedLocale); } static resetCache() { sysLocaleCache = null; intlDTCache = {}; intlNumCache = {}; intlRelCache = {}; } static fromObject({ locale, numberingSystem, outputCalendar } = {}) { return Locale.create(locale, numberingSystem, outputCalendar); } constructor(locale, numbering, outputCalendar, specifiedLocale) { const [parsedLocale, parsedNumberingSystem, parsedOutputCalendar] = parseLocaleString(locale); this.locale = parsedLocale; this.numberingSystem = numbering || parsedNumberingSystem || null; this.outputCalendar = outputCalendar || parsedOutputCalendar || null; this.intl = intlConfigString(this.locale, this.numberingSystem, this.outputCalendar); this.weekdaysCache = { format: {}, standalone: {} }; this.monthsCache = { format: {}, standalone: {} }; this.meridiemCache = null; this.eraCache = {}; this.specifiedLocale = specifiedLocale; this.fastNumbersCached = null; } get fastNumbers() { if (this.fastNumbersCached == null) { this.fastNumbersCached = supportsFastNumbers(this); } return this.fastNumbersCached; } listingMode() { const isActuallyEn = this.isEnglish(); const hasNoWeirdness = (this.numberingSystem === null || this.numberingSystem === "latn") && (this.outputCalendar === null || this.outputCalendar === "gregory"); return isActuallyEn && hasNoWeirdness ? "en" : "intl"; } clone(alts) { if (!alts || Object.getOwnPropertyNames(alts).length === 0) { return this; } else { return Locale.create( alts.locale || this.specifiedLocale, alts.numberingSystem || this.numberingSystem, alts.outputCalendar || this.outputCalendar, alts.defaultToEN || false ); } } redefaultToEN(alts = {}) { return this.clone({ ...alts, defaultToEN: true }); } redefaultToSystem(alts = {}) { return this.clone({ ...alts, defaultToEN: false }); } months(length, format2 = false) { return listStuff(this, length, months, () => { const intl = format2 ? { month: length, day: "numeric" } : { month: length }, formatStr = format2 ? "format" : "standalone"; if (!this.monthsCache[formatStr][length]) { this.monthsCache[formatStr][length] = mapMonths((dt) => this.extract(dt, intl, "month")); } return this.monthsCache[formatStr][length]; }); } weekdays(length, format2 = false) { return listStuff(this, length, weekdays, () => { const intl = format2 ? { weekday: length, year: "numeric", month: "long", day: "numeric" } : { weekday: length }, formatStr = format2 ? "format" : "standalone"; if (!this.weekdaysCache[formatStr][length]) { this.weekdaysCache[formatStr][length] = mapWeekdays( (dt) => this.extract(dt, intl, "weekday") ); } return this.weekdaysCache[formatStr][length]; }); } meridiems() { return listStuff( this, void 0, () => meridiems, () => { if (!this.meridiemCache) { const intl = { hour: "numeric", hourCycle: "h12" }; this.meridiemCache = [DateTime.utc(2016, 11, 13, 9), DateTime.utc(2016, 11, 13, 19)].map( (dt) => this.extract(dt, intl, "dayperiod") ); } return this.meridiemCache; } ); } eras(length) { return listStuff(this, length, eras, () => { const intl = { era: length }; if (!this.eraCache[length]) { this.eraCache[length] = [DateTime.utc(-40, 1, 1), DateTime.utc(2017, 1, 1)].map( (dt) => this.extract(dt, intl, "era") ); } return this.eraCache[length]; }); } extract(dt, intlOpts, field) { const df = this.dtFormatter(dt, intlOpts), results = df.formatToParts(), matching = results.find((m2) => m2.type.toLowerCase() === field); return matching ? matching.value : null; } numberFormatter(opts = {}) { return new PolyNumberFormatter(this.intl, opts.forceSimple || this.fastNumbers, opts); } dtFormatter(dt, intlOpts = {}) { return new PolyDateFormatter(dt, this.intl, intlOpts); } relFormatter(opts = {}) { return new PolyRelFormatter(this.intl, this.isEnglish(), opts); } listFormatter(opts = {}) { return getCachedLF(this.intl, opts); } isEnglish() { return this.locale === "en" || this.locale.toLowerCase() === "en-us" || new Intl.DateTimeFormat(this.intl).resolvedOptions().locale.startsWith("en-us"); } equals(other) { return this.locale === other.locale && this.numberingSystem === other.numberingSystem && this.outputCalendar === other.outputCalendar; } }; var singleton = null; var FixedOffsetZone = class extends Zone { /** * Get a singleton instance of UTC * @return {FixedOffsetZone} */ static get utcInstance() { if (singleton === null) { singleton = new FixedOffsetZone(0); } return singleton; } /** * Get an instance with a specified offset * @param {number} offset - The offset in minutes * @return {FixedOffsetZone} */ static instance(offset2) { return offset2 === 0 ? FixedOffsetZone.utcInstance : new FixedOffsetZone(offset2); } /** * Get an instance of FixedOffsetZone from a UTC offset string, like "UTC+6" * @param {string} s - The offset string to parse * @example FixedOffsetZone.parseSpecifier("UTC+6") * @example FixedOffsetZone.parseSpecifier("UTC+06") * @example FixedOffsetZone.parseSpecifier("UTC-6:00") * @return {FixedOffsetZone} */ static parseSpecifier(s2) { if (s2) { const r = s2.match(/^utc(?:([+-]\d{1,2})(?::(\d{2}))?)?$/i); if (r) { return new FixedOffsetZone(signedOffset(r[1], r[2])); } } return null; } constructor(offset2) { super(); this.fixed = offset2; } /** @override **/ get type() { return "fixed"; } /** @override **/ get name() { return this.fixed === 0 ? "UTC" : `UTC${formatOffset(this.fixed, "narrow")}`; } get ianaName() { if (this.fixed === 0) { return "Etc/UTC"; } else { return `Etc/GMT${formatOffset(-this.fixed, "narrow")}`; } } /** @override **/ offsetName() { return this.name; } /** @override **/ formatOffset(ts, format2) { return formatOffset(this.fixed, format2); } /** @override **/ get isUniversal() { return true; } /** @override **/ offset() { return this.fixed; } /** @override **/ equals(otherZone) { return otherZone.type === "fixed" && otherZone.fixed === this.fixed; } /** @override **/ get isValid() { return true; } }; var InvalidZone = class extends Zone { constructor(zoneName) { super(); this.zoneName = zoneName; } /** @override **/ get type() { return "invalid"; } /** @override **/ get name() { return this.zoneName; } /** @override **/ get isUniversal() { return false; } /** @override **/ offsetName() { return null; } /** @override **/ formatOffset() { return ""; } /** @override **/ offset() { return NaN; } /** @override **/ equals() { return false; } /** @override **/ get isValid() { return false; } }; function normalizeZone(input, defaultZone2) { if (isUndefined2(input) || input === null) { return defaultZone2; } else if (input instanceof Zone) { return input; } else if (isString(input)) { const lowered = input.toLowerCase(); if (lowered === "default") return defaultZone2; else if (lowered === "local" || lowered === "system") return SystemZone.instance; else if (lowered === "utc" || lowered === "gmt") return FixedOffsetZone.utcInstance; else return FixedOffsetZone.parseSpecifier(lowered) || IANAZone.create(input); } else if (isNumber(input)) { return FixedOffsetZone.instance(input); } else if (typeof input === "object" && "offset" in input && typeof input.offset === "function") { return input; } else { return new InvalidZone(input); } } var now5 = () => Date.now(); var defaultZone = "system"; var defaultLocale = null; var defaultNumberingSystem = null; var defaultOutputCalendar = null; var twoDigitCutoffYear = 60; var throwOnInvalid; var Settings = class { /** * Get the callback for returning the current timestamp. * @type {function} */ static get now() { return now5; } /** * Set the callback for returning the current timestamp. * The function should return a number, which will be interpreted as an Epoch millisecond count * @type {function} * @example Settings.now = () => Date.now() + 3000 // pretend it is 3 seconds in the future * @example Settings.now = () => 0 // always pretend it's Jan 1, 1970 at midnight in UTC time */ static set now(n2) { now5 = n2; } /** * Set the default time zone to create DateTimes in. Does not affect existing instances. * Use the value "system" to reset this value to the system's time zone. * @type {string} */ static set defaultZone(zone) { defaultZone = zone; } /** * Get the default time zone object currently used to create DateTimes. Does not affect existing instances. * The default value is the system's time zone (the one set on the machine that runs this code). * @type {Zone} */ static get defaultZone() { return normalizeZone(defaultZone, SystemZone.instance); } /** * Get the default locale to create DateTimes with. Does not affect existing instances. * @type {string} */ static get defaultLocale() { return defaultLocale; } /** * Set the default locale to create DateTimes with. Does not affect existing instances. * @type {string} */ static set defaultLocale(locale) { defaultLocale = locale; } /** * Get the default numbering system to create DateTimes with. Does not affect existing instances. * @type {string} */ static get defaultNumberingSystem() { return defaultNumberingSystem; } /** * Set the default numbering system to create DateTimes with. Does not affect existing instances. * @type {string} */ static set defaultNumberingSystem(numberingSystem) { defaultNumberingSystem = numberingSystem; } /** * Get the default output calendar to create DateTimes with. Does not affect existing instances. * @type {string} */ static get defaultOutputCalendar() { return defaultOutputCalendar; } /** * Set the default output calendar to create DateTimes with. Does not affect existing instances. * @type {string} */ static set defaultOutputCalendar(outputCalendar) { defaultOutputCalendar = outputCalendar; } /** * Get the cutoff year after which a string encoding a year as two digits is interpreted to occur in the current century. * @type {number} */ static get twoDigitCutoffYear() { return twoDigitCutoffYear; } /** * Set the cutoff year after which a string encoding a year as two digits is interpreted to occur in the current century. * @type {number} * @example Settings.twoDigitCutoffYear = 0 // cut-off year is 0, so all 'yy' are interpreted as current century * @example Settings.twoDigitCutoffYear = 50 // '49' -> 1949; '50' -> 2050 * @example Settings.twoDigitCutoffYear = 1950 // interpreted as 50 * @example Settings.twoDigitCutoffYear = 2050 // ALSO interpreted as 50 */ static set twoDigitCutoffYear(cutoffYear) { twoDigitCutoffYear = cutoffYear % 100; } /** * Get whether Luxon will throw when it encounters invalid DateTimes, Durations, or Intervals * @type {boolean} */ static get throwOnInvalid() { return throwOnInvalid; } /** * Set whether Luxon will throw when it encounters invalid DateTimes, Durations, or Intervals * @type {boolean} */ static set throwOnInvalid(t) { throwOnInvalid = t; } /** * Reset Luxon's global caches. Should only be necessary in testing scenarios. * @return {void} */ static resetCaches() { Locale.resetCache(); IANAZone.resetCache(); } }; function isUndefined2(o) { return typeof o === "undefined"; } function isNumber(o) { return typeof o === "number"; } function isInteger(o) { return typeof o === "number" && o % 1 === 0; } function isString(o) { return typeof o === "string"; } function isDate(o) { return Object.prototype.toString.call(o) === "[object Date]"; } function hasRelative() { try { return typeof Intl !== "undefined" && !!Intl.RelativeTimeFormat; } catch (e) { return false; } } function maybeArray(thing) { return Array.isArray(thing) ? thing : [thing]; } function bestBy(arr, by, compare) { if (arr.length === 0) { return void 0; } return arr.reduce((best, next) => { const pair = [by(next), next]; if (!best) { return pair; } else if (compare(best[0], pair[0]) === best[0]) { return best; } else { return pair; } }, null)[1]; } function pick(obj, keys) { return keys.reduce((a2, k) => { a2[k] = obj[k]; return a2; }, {}); } function hasOwnProperty2(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } function integerBetween(thing, bottom, top) { return isInteger(thing) && thing >= bottom && thing <= top; } function floorMod(x3, n2) { return x3 - n2 * Math.floor(x3 / n2); } function padStart(input, n2 = 2) { const isNeg = input < 0; let padded; if (isNeg) { padded = "-" + ("" + -input).padStart(n2, "0"); } else { padded = ("" + input).padStart(n2, "0"); } return padded; } function parseInteger(string) { if (isUndefined2(string) || string === null || string === "") { return void 0; } else { return parseInt(string, 10); } } function parseFloating(string) { if (isUndefined2(string) || string === null || string === "") { return void 0; } else { return parseFloat(string); } } function parseMillis(fraction) { if (isUndefined2(fraction) || fraction === null || fraction === "") { return void 0; } else { const f = parseFloat("0." + fraction) * 1e3; return Math.floor(f); } } function roundTo(number, digits, towardZero = false) { const factor = 10 ** digits, rounder = towardZero ? Math.trunc : Math.round; return rounder(number * factor) / factor; } function isLeapYear(year) { return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0); } function daysInYear(year) { return isLeapYear(year) ? 366 : 365; } function daysInMonth(year, month) { const modMonth = floorMod(month - 1, 12) + 1, modYear = year + (month - modMonth) / 12; if (modMonth === 2) { return isLeapYear(modYear) ? 29 : 28; } else { return [31, null, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][modMonth - 1]; } } function objToLocalTS(obj) { let d = Date.UTC( obj.year, obj.month - 1, obj.day, obj.hour, obj.minute, obj.second, obj.millisecond ); if (obj.year < 100 && obj.year >= 0) { d = new Date(d); d.setUTCFullYear(obj.year, obj.month - 1, obj.day); } return +d; } function weeksInWeekYear(weekYear) { const p1 = (weekYear + Math.floor(weekYear / 4) - Math.floor(weekYear / 100) + Math.floor(weekYear / 400)) % 7, last = weekYear - 1, p2 = (last + Math.floor(last / 4) - Math.floor(last / 100) + Math.floor(last / 400)) % 7; return p1 === 4 || p2 === 3 ? 53 : 52; } function untruncateYear(year) { if (year > 99) { return year; } else return year > Settings.twoDigitCutoffYear ? 1900 + year : 2e3 + year; } function parseZoneInfo(ts, offsetFormat, locale, timeZone = null) { const date = new Date(ts), intlOpts = { hourCycle: "h23", year: "numeric", month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit" }; if (timeZone) { intlOpts.timeZone = timeZone; } const modified = { timeZoneName: offsetFormat, ...intlOpts }; const parsed = new Intl.DateTimeFormat(locale, modified).formatToParts(date).find((m2) => m2.type.toLowerCase() === "timezonename"); return parsed ? parsed.value : null; } function signedOffset(offHourStr, offMinuteStr) { let offHour = parseInt(offHourStr, 10); if (Number.isNaN(offHour)) { offHour = 0; } const offMin = parseInt(offMinuteStr, 10) || 0, offMinSigned = offHour < 0 || Object.is(offHour, -0) ? -offMin : offMin; return offHour * 60 + offMinSigned; } function asNumber(value) { const numericValue = Number(value); if (typeof value === "boolean" || value === "" || Number.isNaN(numericValue)) throw new InvalidArgumentError(`Invalid unit value ${value}`); return numericValue; } function normalizeObject(obj, normalizer) { const normalized = {}; for (const u in obj) { if (hasOwnProperty2(obj, u)) { const v = obj[u]; if (v === void 0 || v === null) continue; normalized[normalizer(u)] = asNumber(v); } } return normalized; } function formatOffset(offset2, format2) { const hours = Math.trunc(Math.abs(offset2 / 60)), minutes = Math.trunc(Math.abs(offset2 % 60)), sign = offset2 >= 0 ? "+" : "-"; switch (format2) { case "short": return `${sign}${padStart(hours, 2)}:${padStart(minutes, 2)}`; case "narrow": return `${sign}${hours}${minutes > 0 ? `:${minutes}` : ""}`; case "techie": return `${sign}${padStart(hours, 2)}${padStart(minutes, 2)}`; default: throw new RangeError(`Value format ${format2} is out of range for property format`); } } function timeObject(obj) { return pick(obj, ["hour", "minute", "second", "millisecond"]); } var monthsLong = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ]; var monthsShort = [ "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ]; var monthsNarrow = ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"]; function months(length) { switch (length) { case "narrow": return [...monthsNarrow]; case "short": return [...monthsShort]; case "long": return [...monthsLong]; case "numeric": return ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"]; case "2-digit": return ["01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"]; default: return null; } } var weekdaysLong = [ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ]; var weekdaysShort = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]; var weekdaysNarrow = ["M", "T", "W", "T", "F", "S", "S"]; function weekdays(length) { switch (length) { case "narrow": return [...weekdaysNarrow]; case "short": return [...weekdaysShort]; case "long": return [...weekdaysLong]; case "numeric": return ["1", "2", "3", "4", "5", "6", "7"]; default: return null; } } var meridiems = ["AM", "PM"]; var erasLong = ["Before Christ", "Anno Domini"]; var erasShort = ["BC", "AD"]; var erasNarrow = ["B", "A"]; function eras(length) { switch (length) { case "narrow": return [...erasNarrow]; case "short": return [...erasShort]; case "long": return [...erasLong]; default: return null; } } function meridiemForDateTime(dt) { return meridiems[dt.hour < 12 ? 0 : 1]; } function weekdayForDateTime(dt, length) { return weekdays(length)[dt.weekday - 1]; } function monthForDateTime(dt, length) { return months(length)[dt.month - 1]; } function eraForDateTime(dt, length) { return eras(length)[dt.year < 0 ? 0 : 1]; } function formatRelativeTime(unit, count, numeric = "always", narrow = false) { const units = { years: ["year", "yr."], quarters: ["quarter", "qtr."], months: ["month", "mo."], weeks: ["week", "wk."], days: ["day", "day", "days"], hours: ["hour", "hr."], minutes: ["minute", "min."], seconds: ["second", "sec."] }; const lastable = ["hours", "minutes", "seconds"].indexOf(unit) === -1; if (numeric === "auto" && lastable) { const isDay = unit === "days"; switch (count) { case 1: return isDay ? "tomorrow" : `next ${units[unit][0]}`; case -1: return isDay ? "yesterday" : `last ${units[unit][0]}`; case 0: return isDay ? "today" : `this ${units[unit][0]}`; } } const isInPast = Object.is(count, -0) || count < 0, fmtValue = Math.abs(count), singular = fmtValue === 1, lilUnits = units[unit], fmtUnit = narrow ? singular ? lilUnits[1] : lilUnits[2] || lilUnits[1] : singular ? units[unit][0] : unit; return isInPast ? `${fmtValue} ${fmtUnit} ago` : `in ${fmtValue} ${fmtUnit}`; } function stringifyTokens(splits, tokenToString) { let s2 = ""; for (const token of splits) { if (token.literal) { s2 += token.val; } else { s2 += tokenToString(token.val); } } return s2; } var macroTokenToFormatOpts = { D: DATE_SHORT, DD: DATE_MED, DDD: DATE_FULL, DDDD: DATE_HUGE, t: TIME_SIMPLE, tt: TIME_WITH_SECONDS, ttt: TIME_WITH_SHORT_OFFSET, tttt: TIME_WITH_LONG_OFFSET, T: TIME_24_SIMPLE, TT: TIME_24_WITH_SECONDS, TTT: TIME_24_WITH_SHORT_OFFSET, TTTT: TIME_24_WITH_LONG_OFFSET, f: DATETIME_SHORT, ff: DATETIME_MED, fff: DATETIME_FULL, ffff: DATETIME_HUGE, F: DATETIME_SHORT_WITH_SECONDS, FF: DATETIME_MED_WITH_SECONDS, FFF: DATETIME_FULL_WITH_SECONDS, FFFF: DATETIME_HUGE_WITH_SECONDS }; var Formatter = class { static create(locale, opts = {}) { return new Formatter(locale, opts); } static parseFormat(fmt) { let current = null, currentFull = "", bracketed = false; const splits = []; for (let i = 0; i < fmt.length; i++) { const c2 = fmt.charAt(i); if (c2 === "'") { if (currentFull.length > 0) { splits.push({ literal: bracketed || /^\s+$/.test(currentFull), val: currentFull }); } current = null; currentFull = ""; bracketed = !bracketed; } else if (bracketed) { currentFull += c2; } else if (c2 === current) { currentFull += c2; } else { if (currentFull.length > 0) { splits.push({ literal: /^\s+$/.test(currentFull), val: currentFull }); } currentFull = c2; current = c2; } } if (currentFull.length > 0) { splits.push({ literal: bracketed || /^\s+$/.test(currentFull), val: currentFull }); } return splits; } static macroTokenToFormatOpts(token) { return macroTokenToFormatOpts[token]; } constructor(locale, formatOpts) { this.opts = formatOpts; this.loc = locale; this.systemLoc = null; } formatWithSystemDefault(dt, opts) { if (this.systemLoc === null) { this.systemLoc = this.loc.redefaultToSystem(); } const df = this.systemLoc.dtFormatter(dt, { ...this.opts, ...opts }); return df.format(); } dtFormatter(dt, opts = {}) { return this.loc.dtFormatter(dt, { ...this.opts, ...opts }); } formatDateTime(dt, opts) { return this.dtFormatter(dt, opts).format(); } formatDateTimeParts(dt, opts) { return this.dtFormatter(dt, opts).formatToParts(); } formatInterval(interval2, opts) { const df = this.dtFormatter(interval2.start, opts); return df.dtf.formatRange(interval2.start.toJSDate(), interval2.end.toJSDate()); } resolvedOptions(dt, opts) { return this.dtFormatter(dt, opts).resolvedOptions(); } num(n2, p = 0) { if (this.opts.forceSimple) { return padStart(n2, p); } const opts = { ...this.opts }; if (p > 0) { opts.padTo = p; } return this.loc.numberFormatter(opts).format(n2); } formatDateTimeFromString(dt, fmt) { const knownEnglish = this.loc.listingMode() === "en", useDateTimeFormatter = this.loc.outputCalendar && this.loc.outputCalendar !== "gregory", string = (opts, extract) => this.loc.extract(dt, opts, extract), formatOffset2 = (opts) => { if (dt.isOffsetFixed && dt.offset === 0 && opts.allowZ) { return "Z"; } return dt.isValid ? dt.zone.formatOffset(dt.ts, opts.format) : ""; }, meridiem = () => knownEnglish ? meridiemForDateTime(dt) : string({ hour: "numeric", hourCycle: "h12" }, "dayperiod"), month = (length, standalone) => knownEnglish ? monthForDateTime(dt, length) : string(standalone ? { month: length } : { month: length, day: "numeric" }, "month"), weekday = (length, standalone) => knownEnglish ? weekdayForDateTime(dt, length) : string( standalone ? { weekday: length } : { weekday: length, month: "long", day: "numeric" }, "weekday" ), maybeMacro = (token) => { const formatOpts = Formatter.macroTokenToFormatOpts(token); if (formatOpts) { return this.formatWithSystemDefault(dt, formatOpts); } else { return token; } }, era = (length) => knownEnglish ? eraForDateTime(dt, length) : string({ era: length }, "era"), tokenToString = (token) => { switch (token) { case "S": return this.num(dt.millisecond); case "u": case "SSS": return this.num(dt.millisecond, 3); case "s": return this.num(dt.second); case "ss": return this.num(dt.second, 2); case "uu": return this.num(Math.floor(dt.millisecond / 10), 2); case "uuu": return this.num(Math.floor(dt.millisecond / 100)); case "m": return this.num(dt.minute); case "mm": return this.num(dt.minute, 2); case "h": return this.num(dt.hour % 12 === 0 ? 12 : dt.hour % 12); case "hh": return this.num(dt.hour % 12 === 0 ? 12 : dt.hour % 12, 2); case "H": return this.num(dt.hour); case "HH": return this.num(dt.hour, 2); case "Z": return formatOffset2({ format: "narrow", allowZ: this.opts.allowZ }); case "ZZ": return formatOffset2({ format: "short", allowZ: this.opts.allowZ }); case "ZZZ": return formatOffset2({ format: "techie", allowZ: this.opts.allowZ }); case "ZZZZ": return dt.zone.offsetName(dt.ts, { format: "short", locale: this.loc.locale }); case "ZZZZZ": return dt.zone.offsetName(dt.ts, { format: "long", locale: this.loc.locale }); case "z": return dt.zoneName; case "a": return meridiem(); case "d": return useDateTimeFormatter ? string({ day: "numeric" }, "day") : this.num(dt.day); case "dd": return useDateTimeFormatter ? string({ day: "2-digit" }, "day") : this.num(dt.day, 2); case "c": return this.num(dt.weekday); case "ccc": return weekday("short", true); case "cccc": return weekday("long", true); case "ccccc": return weekday("narrow", true); case "E": return this.num(dt.weekday); case "EEE": return weekday("short", false); case "EEEE": return weekday("long", false); case "EEEEE": return weekday("narrow", false); case "L": return useDateTimeFormatter ? string({ month: "numeric", day: "numeric" }, "month") : this.num(dt.month); case "LL": return useDateTimeFormatter ? string({ month: "2-digit", day: "numeric" }, "month") : this.num(dt.month, 2); case "LLL": return month("short", true); case "LLLL": return month("long", true); case "LLLLL": return month("narrow", true); case "M": return useDateTimeFormatter ? string({ month: "numeric" }, "month") : this.num(dt.month); case "MM": return useDateTimeFormatter ? string({ month: "2-digit" }, "month") : this.num(dt.month, 2); case "MMM": return month("short", false); case "MMMM": return month("long", false); case "MMMMM": return month("narrow", false); case "y": return useDateTimeFormatter ? string({ year: "numeric" }, "year") : this.num(dt.year); case "yy": return useDateTimeFormatter ? string({ year: "2-digit" }, "year") : this.num(dt.year.toString().slice(-2), 2); case "yyyy": return useDateTimeFormatter ? string({ year: "numeric" }, "year") : this.num(dt.year, 4); case "yyyyyy": return useDateTimeFormatter ? string({ year: "numeric" }, "year") : this.num(dt.year, 6); case "G": return era("short"); case "GG": return era("long"); case "GGGGG": return era("narrow"); case "kk": return this.num(dt.weekYear.toString().slice(-2), 2); case "kkkk": return this.num(dt.weekYear, 4); case "W": return this.num(dt.weekNumber); case "WW": return this.num(dt.weekNumber, 2); case "o": return this.num(dt.ordinal); case "ooo": return this.num(dt.ordinal, 3); case "q": return this.num(dt.quarter); case "qq": return this.num(dt.quarter, 2); case "X": return this.num(Math.floor(dt.ts / 1e3)); case "x": return this.num(dt.ts); default: return maybeMacro(token); } }; return stringifyTokens(Formatter.parseFormat(fmt), tokenToString); } formatDurationFromString(dur, fmt) { const tokenToField = (token) => { switch (token[0]) { case "S": return "millisecond"; case "s": return "second"; case "m": return "minute"; case "h": return "hour"; case "d": return "day"; case "w": return "week"; case "M": return "month"; case "y": return "year"; default: return null; } }, tokenToString = (lildur) => (token) => { const mapped = tokenToField(token); if (mapped) { return this.num(lildur.get(mapped), token.length); } else { return token; } }, tokens = Formatter.parseFormat(fmt), realTokens = tokens.reduce( (found, { literal, val }) => literal ? found : found.concat(val), [] ), collapsed = dur.shiftTo(...realTokens.map(tokenToField).filter((t) => t)); return stringifyTokens(tokens, tokenToString(collapsed)); } }; var Invalid = class { constructor(reason, explanation) { this.reason = reason; this.explanation = explanation; } toMessage() { if (this.explanation) { return `${this.reason}: ${this.explanation}`; } else { return this.reason; } } }; var ianaRegex = /[A-Za-z_+-]{1,256}(?::?\/[A-Za-z0-9_+-]{1,256}(?:\/[A-Za-z0-9_+-]{1,256})?)?/; function combineRegexes(...regexes) { const full = regexes.reduce((f, r) => f + r.source, ""); return RegExp(`^${full}$`); } function combineExtractors(...extractors) { return (m2) => extractors.reduce( ([mergedVals, mergedZone, cursor], ex) => { const [val, zone, next] = ex(m2, cursor); return [{ ...mergedVals, ...val }, zone || mergedZone, next]; }, [{}, null, 1] ).slice(0, 2); } function parse(s2, ...patterns) { if (s2 == null) { return [null, null]; } for (const [regex, extractor] of patterns) { const m2 = regex.exec(s2); if (m2) { return extractor(m2); } } return [null, null]; } function simpleParse(...keys) { return (match2, cursor) => { const ret = {}; let i; for (i = 0; i < keys.length; i++) { ret[keys[i]] = parseInteger(match2[cursor + i]); } return [ret, null, cursor + i]; }; } var offsetRegex = /(?:(Z)|([+-]\d\d)(?::?(\d\d))?)/; var isoExtendedZone = `(?:${offsetRegex.source}?(?:\\[(${ianaRegex.source})\\])?)?`; var isoTimeBaseRegex = /(\d\d)(?::?(\d\d)(?::?(\d\d)(?:[.,](\d{1,30}))?)?)?/; var isoTimeRegex = RegExp(`${isoTimeBaseRegex.source}${isoExtendedZone}`); var isoTimeExtensionRegex = RegExp(`(?:T${isoTimeRegex.source})?`); var isoYmdRegex = /([+-]\d{6}|\d{4})(?:-?(\d\d)(?:-?(\d\d))?)?/; var isoWeekRegex = /(\d{4})-?W(\d\d)(?:-?(\d))?/; var isoOrdinalRegex = /(\d{4})-?(\d{3})/; var extractISOWeekData = simpleParse("weekYear", "weekNumber", "weekDay"); var extractISOOrdinalData = simpleParse("year", "ordinal"); var sqlYmdRegex = /(\d{4})-(\d\d)-(\d\d)/; var sqlTimeRegex = RegExp( `${isoTimeBaseRegex.source} ?(?:${offsetRegex.source}|(${ianaRegex.source}))?` ); var sqlTimeExtensionRegex = RegExp(`(?: ${sqlTimeRegex.source})?`); function int(match2, pos, fallback) { const m2 = match2[pos]; return isUndefined2(m2) ? fallback : parseInteger(m2); } function extractISOYmd(match2, cursor) { const item = { year: int(match2, cursor), month: int(match2, cursor + 1, 1), day: int(match2, cursor + 2, 1) }; return [item, null, cursor + 3]; } function extractISOTime(match2, cursor) { const item = { hours: int(match2, cursor, 0), minutes: int(match2, cursor + 1, 0), seconds: int(match2, cursor + 2, 0), milliseconds: parseMillis(match2[cursor + 3]) }; return [item, null, cursor + 4]; } function extractISOOffset(match2, cursor) { const local = !match2[cursor] && !match2[cursor + 1], fullOffset = signedOffset(match2[cursor + 1], match2[cursor + 2]), zone = local ? null : FixedOffsetZone.instance(fullOffset); return [{}, zone, cursor + 3]; } function extractIANAZone(match2, cursor) { const zone = match2[cursor] ? IANAZone.create(match2[cursor]) : null; return [{}, zone, cursor + 1]; } var isoTimeOnly = RegExp(`^T?${isoTimeBaseRegex.source}$`); var isoDuration = /^-?P(?:(?:(-?\d{1,20}(?:\.\d{1,20})?)Y)?(?:(-?\d{1,20}(?:\.\d{1,20})?)M)?(?:(-?\d{1,20}(?:\.\d{1,20})?)W)?(?:(-?\d{1,20}(?:\.\d{1,20})?)D)?(?:T(?:(-?\d{1,20}(?:\.\d{1,20})?)H)?(?:(-?\d{1,20}(?:\.\d{1,20})?)M)?(?:(-?\d{1,20})(?:[.,](-?\d{1,20}))?S)?)?)$/; function extractISODuration(match2) { const [s2, yearStr, monthStr, weekStr, dayStr, hourStr, minuteStr, secondStr, millisecondsStr] = match2; const hasNegativePrefix = s2[0] === "-"; const negativeSeconds = secondStr && secondStr[0] === "-"; const maybeNegate = (num, force = false) => num !== void 0 && (force || num && hasNegativePrefix) ? -num : num; return [ { years: maybeNegate(parseFloating(yearStr)), months: maybeNegate(parseFloating(monthStr)), weeks: maybeNegate(parseFloating(weekStr)), days: maybeNegate(parseFloating(dayStr)), hours: maybeNegate(parseFloating(hourStr)), minutes: maybeNegate(parseFloating(minuteStr)), seconds: maybeNegate(parseFloating(secondStr), secondStr === "-0"), milliseconds: maybeNegate(parseMillis(millisecondsStr), negativeSeconds) } ]; } var obsOffsets = { GMT: 0, EDT: -4 * 60, EST: -5 * 60, CDT: -5 * 60, CST: -6 * 60, MDT: -6 * 60, MST: -7 * 60, PDT: -7 * 60, PST: -8 * 60 }; function fromStrings(weekdayStr, yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr) { const result = { year: yearStr.length === 2 ? untruncateYear(parseInteger(yearStr)) : parseInteger(yearStr), month: monthsShort.indexOf(monthStr) + 1, day: parseInteger(dayStr), hour: parseInteger(hourStr), minute: parseInteger(minuteStr) }; if (secondStr) result.second = parseInteger(secondStr); if (weekdayStr) { result.weekday = weekdayStr.length > 3 ? weekdaysLong.indexOf(weekdayStr) + 1 : weekdaysShort.indexOf(weekdayStr) + 1; } return result; } var rfc2822 = /^(?:(Mon|Tue|Wed|Thu|Fri|Sat|Sun),\s)?(\d{1,2})\s(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s(\d{2,4})\s(\d\d):(\d\d)(?::(\d\d))?\s(?:(UT|GMT|[ECMP][SD]T)|([Zz])|(?:([+-]\d\d)(\d\d)))$/; function extractRFC2822(match2) { const [ , weekdayStr, dayStr, monthStr, yearStr, hourStr, minuteStr, secondStr, obsOffset, milOffset, offHourStr, offMinuteStr ] = match2, result = fromStrings(weekdayStr, yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr); let offset2; if (obsOffset) { offset2 = obsOffsets[obsOffset]; } else if (milOffset) { offset2 = 0; } else { offset2 = signedOffset(offHourStr, offMinuteStr); } return [result, new FixedOffsetZone(offset2)]; } function preprocessRFC2822(s2) { return s2.replace(/\([^()]*\)|[\n\t]/g, " ").replace(/(\s\s+)/g, " ").trim(); } var rfc1123 = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\d\d) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{4}) (\d\d):(\d\d):(\d\d) GMT$/; var rfc850 = /^(Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (\d\d)-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d\d) (\d\d):(\d\d):(\d\d) GMT$/; var ascii = /^(Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ( \d|\d\d) (\d\d):(\d\d):(\d\d) (\d{4})$/; function extractRFC1123Or850(match2) { const [, weekdayStr, dayStr, monthStr, yearStr, hourStr, minuteStr, secondStr] = match2, result = fromStrings(weekdayStr, yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr); return [result, FixedOffsetZone.utcInstance]; } function extractASCII(match2) { const [, weekdayStr, monthStr, dayStr, hourStr, minuteStr, secondStr, yearStr] = match2, result = fromStrings(weekdayStr, yearStr, monthStr, dayStr, hourStr, minuteStr, secondStr); return [result, FixedOffsetZone.utcInstance]; } var isoYmdWithTimeExtensionRegex = combineRegexes(isoYmdRegex, isoTimeExtensionRegex); var isoWeekWithTimeExtensionRegex = combineRegexes(isoWeekRegex, isoTimeExtensionRegex); var isoOrdinalWithTimeExtensionRegex = combineRegexes(isoOrdinalRegex, isoTimeExtensionRegex); var isoTimeCombinedRegex = combineRegexes(isoTimeRegex); var extractISOYmdTimeAndOffset = combineExtractors( extractISOYmd, extractISOTime, extractISOOffset, extractIANAZone ); var extractISOWeekTimeAndOffset = combineExtractors( extractISOWeekData, extractISOTime, extractISOOffset, extractIANAZone ); var extractISOOrdinalDateAndTime = combineExtractors( extractISOOrdinalData, extractISOTime, extractISOOffset, extractIANAZone ); var extractISOTimeAndOffset = combineExtractors( extractISOTime, extractISOOffset, extractIANAZone ); function parseISODate(s2) { return parse( s2, [isoYmdWithTimeExtensionRegex, extractISOYmdTimeAndOffset], [isoWeekWithTimeExtensionRegex, extractISOWeekTimeAndOffset], [isoOrdinalWithTimeExtensionRegex, extractISOOrdinalDateAndTime], [isoTimeCombinedRegex, extractISOTimeAndOffset] ); } function parseRFC2822Date(s2) { return parse(preprocessRFC2822(s2), [rfc2822, extractRFC2822]); } function parseHTTPDate(s2) { return parse( s2, [rfc1123, extractRFC1123Or850], [rfc850, extractRFC1123Or850], [ascii, extractASCII] ); } function parseISODuration(s2) { return parse(s2, [isoDuration, extractISODuration]); } var extractISOTimeOnly = combineExtractors(extractISOTime); function parseISOTimeOnly(s2) { return parse(s2, [isoTimeOnly, extractISOTimeOnly]); } var sqlYmdWithTimeExtensionRegex = combineRegexes(sqlYmdRegex, sqlTimeExtensionRegex); var sqlTimeCombinedRegex = combineRegexes(sqlTimeRegex); var extractISOTimeOffsetAndIANAZone = combineExtractors( extractISOTime, extractISOOffset, extractIANAZone ); function parseSQL(s2) { return parse( s2, [sqlYmdWithTimeExtensionRegex, extractISOYmdTimeAndOffset], [sqlTimeCombinedRegex, extractISOTimeOffsetAndIANAZone] ); } var INVALID$2 = "Invalid Duration"; var lowOrderMatrix = { weeks: { days: 7, hours: 7 * 24, minutes: 7 * 24 * 60, seconds: 7 * 24 * 60 * 60, milliseconds: 7 * 24 * 60 * 60 * 1e3 }, days: { hours: 24, minutes: 24 * 60, seconds: 24 * 60 * 60, milliseconds: 24 * 60 * 60 * 1e3 }, hours: { minutes: 60, seconds: 60 * 60, milliseconds: 60 * 60 * 1e3 }, minutes: { seconds: 60, milliseconds: 60 * 1e3 }, seconds: { milliseconds: 1e3 } }; var casualMatrix = { years: { quarters: 4, months: 12, weeks: 52, days: 365, hours: 365 * 24, minutes: 365 * 24 * 60, seconds: 365 * 24 * 60 * 60, milliseconds: 365 * 24 * 60 * 60 * 1e3 }, quarters: { months: 3, weeks: 13, days: 91, hours: 91 * 24, minutes: 91 * 24 * 60, seconds: 91 * 24 * 60 * 60, milliseconds: 91 * 24 * 60 * 60 * 1e3 }, months: { weeks: 4, days: 30, hours: 30 * 24, minutes: 30 * 24 * 60, seconds: 30 * 24 * 60 * 60, milliseconds: 30 * 24 * 60 * 60 * 1e3 }, ...lowOrderMatrix }; var daysInYearAccurate = 146097 / 400; var daysInMonthAccurate = 146097 / 4800; var accurateMatrix = { years: { quarters: 4, months: 12, weeks: daysInYearAccurate / 7, days: daysInYearAccurate, hours: daysInYearAccurate * 24, minutes: daysInYearAccurate * 24 * 60, seconds: daysInYearAccurate * 24 * 60 * 60, milliseconds: daysInYearAccurate * 24 * 60 * 60 * 1e3 }, quarters: { months: 3, weeks: daysInYearAccurate / 28, days: daysInYearAccurate / 4, hours: daysInYearAccurate * 24 / 4, minutes: daysInYearAccurate * 24 * 60 / 4, seconds: daysInYearAccurate * 24 * 60 * 60 / 4, milliseconds: daysInYearAccurate * 24 * 60 * 60 * 1e3 / 4 }, months: { weeks: daysInMonthAccurate / 7, days: daysInMonthAccurate, hours: daysInMonthAccurate * 24, minutes: daysInMonthAccurate * 24 * 60, seconds: daysInMonthAccurate * 24 * 60 * 60, milliseconds: daysInMonthAccurate * 24 * 60 * 60 * 1e3 }, ...lowOrderMatrix }; var orderedUnits$1 = [ "years", "quarters", "months", "weeks", "days", "hours", "minutes", "seconds", "milliseconds" ]; var reverseUnits = orderedUnits$1.slice(0).reverse(); function clone$1(dur, alts, clear = false) { const conf = { values: clear ? alts.values : { ...dur.values, ...alts.values || {} }, loc: dur.loc.clone(alts.loc), conversionAccuracy: alts.conversionAccuracy || dur.conversionAccuracy, matrix: alts.matrix || dur.matrix }; return new Duration(conf); } function durationToMillis(matrix, vals) { var _a3; let sum = (_a3 = vals.milliseconds) != null ? _a3 : 0; for (const unit of reverseUnits.slice(1)) { if (vals[unit]) { sum += vals[unit] * matrix[unit]["milliseconds"]; } } return sum; } function normalizeValues(matrix, vals) { const factor = durationToMillis(matrix, vals) < 0 ? -1 : 1; orderedUnits$1.reduceRight((previous, current) => { if (!isUndefined2(vals[current])) { if (previous) { const previousVal = vals[previous] * factor; const conv = matrix[current][previous]; const rollUp = Math.floor(previousVal / conv); vals[current] += rollUp * factor; vals[previous] -= rollUp * conv * factor; } return current; } else { return previous; } }, null); orderedUnits$1.reduce((previous, current) => { if (!isUndefined2(vals[current])) { if (previous) { const fraction = vals[previous] % 1; vals[previous] -= fraction; vals[current] += fraction * matrix[previous][current]; } return current; } else { return previous; } }, null); } function removeZeroes(vals) { const newVals = {}; for (const [key, value] of Object.entries(vals)) { if (value !== 0) { newVals[key] = value; } } return newVals; } var Duration = class { /** * @private */ constructor(config2) { const accurate = config2.conversionAccuracy === "longterm" || false; let matrix = accurate ? accurateMatrix : casualMatrix; if (config2.matrix) { matrix = config2.matrix; } this.values = config2.values; this.loc = config2.loc || Locale.create(); this.conversionAccuracy = accurate ? "longterm" : "casual"; this.invalid = config2.invalid || null; this.matrix = matrix; this.isLuxonDuration = true; } /** * Create Duration from a number of milliseconds. * @param {number} count of milliseconds * @param {Object} opts - options for parsing * @param {string} [opts.locale='en-US'] - the locale to use * @param {string} opts.numberingSystem - the numbering system to use * @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use * @return {Duration} */ static fromMillis(count, opts) { return Duration.fromObject({ milliseconds: count }, opts); } /** * Create a Duration from a JavaScript object with keys like 'years' and 'hours'. * If this object is empty then a zero milliseconds duration is returned. * @param {Object} obj - the object to create the DateTime from * @param {number} obj.years * @param {number} obj.quarters * @param {number} obj.months * @param {number} obj.weeks * @param {number} obj.days * @param {number} obj.hours * @param {number} obj.minutes * @param {number} obj.seconds * @param {number} obj.milliseconds * @param {Object} [opts=[]] - options for creating this Duration * @param {string} [opts.locale='en-US'] - the locale to use * @param {string} opts.numberingSystem - the numbering system to use * @param {string} [opts.conversionAccuracy='casual'] - the preset conversion system to use * @param {string} [opts.matrix=Object] - the custom conversion system to use * @return {Duration} */ static fromObject(obj, opts = {}) { if (obj == null || typeof obj !== "object") { throw new InvalidArgumentError( `Duration.fromObject: argument expected to be an object, got ${obj === null ? "null" : typeof obj}` ); } return new Duration({ values: normalizeObject(obj, Duration.normalizeUnit), loc: Locale.fromObject(opts), conversionAccuracy: opts.conversionAccuracy, matrix: opts.matrix }); } /** * Create a Duration from DurationLike. * * @param {Object | number | Duration} durationLike * One of: * - object with keys like 'years' and 'hours'. * - number representing milliseconds * - Duration instance * @return {Duration} */ static fromDurationLike(durationLike) { if (isNumber(durationLike)) { return Duration.fromMillis(durationLike); } else if (Duration.isDuration(durationLike)) { return durationLike; } else if (typeof durationLike === "object") { return Duration.fromObject(durationLike); } else { throw new InvalidArgumentError( `Unknown duration argument ${durationLike} of type ${typeof durationLike}` ); } } /** * Create a Duration from an ISO 8601 duration string. * @param {string} text - text to parse * @param {Object} opts - options for parsing * @param {string} [opts.locale='en-US'] - the locale to use * @param {string} opts.numberingSystem - the numbering system to use * @param {string} [opts.conversionAccuracy='casual'] - the preset conversion system to use * @param {string} [opts.matrix=Object] - the preset conversion system to use * @see https://en.wikipedia.org/wiki/ISO_8601#Durations * @example Duration.fromISO('P3Y6M1W4DT12H30M5S').toObject() //=> { years: 3, months: 6, weeks: 1, days: 4, hours: 12, minutes: 30, seconds: 5 } * @example Duration.fromISO('PT23H').toObject() //=> { hours: 23 } * @example Duration.fromISO('P5Y3M').toObject() //=> { years: 5, months: 3 } * @return {Duration} */ static fromISO(text, opts) { const [parsed] = parseISODuration(text); if (parsed) { return Duration.fromObject(parsed, opts); } else { return Duration.invalid("unparsable", `the input "${text}" can't be parsed as ISO 8601`); } } /** * Create a Duration from an ISO 8601 time string. * @param {string} text - text to parse * @param {Object} opts - options for parsing * @param {string} [opts.locale='en-US'] - the locale to use * @param {string} opts.numberingSystem - the numbering system to use * @param {string} [opts.conversionAccuracy='casual'] - the preset conversion system to use * @param {string} [opts.matrix=Object] - the conversion system to use * @see https://en.wikipedia.org/wiki/ISO_8601#Times * @example Duration.fromISOTime('11:22:33.444').toObject() //=> { hours: 11, minutes: 22, seconds: 33, milliseconds: 444 } * @example Duration.fromISOTime('11:00').toObject() //=> { hours: 11, minutes: 0, seconds: 0 } * @example Duration.fromISOTime('T11:00').toObject() //=> { hours: 11, minutes: 0, seconds: 0 } * @example Duration.fromISOTime('1100').toObject() //=> { hours: 11, minutes: 0, seconds: 0 } * @example Duration.fromISOTime('T1100').toObject() //=> { hours: 11, minutes: 0, seconds: 0 } * @return {Duration} */ static fromISOTime(text, opts) { const [parsed] = parseISOTimeOnly(text); if (parsed) { return Duration.fromObject(parsed, opts); } else { return Duration.invalid("unparsable", `the input "${text}" can't be parsed as ISO 8601`); } } /** * Create an invalid Duration. * @param {string} reason - simple string of why this datetime is invalid. Should not contain parameters or anything else data-dependent * @param {string} [explanation=null] - longer explanation, may include parameters and other useful debugging information * @return {Duration} */ static invalid(reason, explanation = null) { if (!reason) { throw new InvalidArgumentError("need to specify a reason the Duration is invalid"); } const invalid = reason instanceof Invalid ? reason : new Invalid(reason, explanation); if (Settings.throwOnInvalid) { throw new InvalidDurationError(invalid); } else { return new Duration({ invalid }); } } /** * @private */ static normalizeUnit(unit) { const normalized = { year: "years", years: "years", quarter: "quarters", quarters: "quarters", month: "months", months: "months", week: "weeks", weeks: "weeks", day: "days", days: "days", hour: "hours", hours: "hours", minute: "minutes", minutes: "minutes", second: "seconds", seconds: "seconds", millisecond: "milliseconds", milliseconds: "milliseconds" }[unit ? unit.toLowerCase() : unit]; if (!normalized) throw new InvalidUnitError(unit); return normalized; } /** * Check if an object is a Duration. Works across context boundaries * @param {object} o * @return {boolean} */ static isDuration(o) { return o && o.isLuxonDuration || false; } /** * Get the locale of a Duration, such 'en-GB' * @type {string} */ get locale() { return this.isValid ? this.loc.locale : null; } /** * Get the numbering system of a Duration, such 'beng'. The numbering system is used when formatting the Duration * * @type {string} */ get numberingSystem() { return this.isValid ? this.loc.numberingSystem : null; } /** * Returns a string representation of this Duration formatted according to the specified format string. You may use these tokens: * * `S` for milliseconds * * `s` for seconds * * `m` for minutes * * `h` for hours * * `d` for days * * `w` for weeks * * `M` for months * * `y` for years * Notes: * * Add padding by repeating the token, e.g. "yy" pads the years to two digits, "hhhh" pads the hours out to four digits * * Tokens can be escaped by wrapping with single quotes. * * The duration will be converted to the set of units in the format string using {@link Duration#shiftTo} and the Durations's conversion accuracy setting. * @param {string} fmt - the format string * @param {Object} opts - options * @param {boolean} [opts.floor=true] - floor numerical values * @example Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toFormat("y d s") //=> "1 6 2" * @example Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toFormat("yy dd sss") //=> "01 06 002" * @example Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toFormat("M S") //=> "12 518402000" * @return {string} */ toFormat(fmt, opts = {}) { const fmtOpts = { ...opts, floor: opts.round !== false && opts.floor !== false }; return this.isValid ? Formatter.create(this.loc, fmtOpts).formatDurationFromString(this, fmt) : INVALID$2; } /** * Returns a string representation of a Duration with all units included. * To modify its behavior use the `listStyle` and any Intl.NumberFormat option, though `unitDisplay` is especially relevant. * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat * @param opts - On option object to override the formatting. Accepts the same keys as the options parameter of the native `Int.NumberFormat` constructor, as well as `listStyle`. * @example * ```js * var dur = Duration.fromObject({ days: 1, hours: 5, minutes: 6 }) * dur.toHuman() //=> '1 day, 5 hours, 6 minutes' * dur.toHuman({ listStyle: "long" }) //=> '1 day, 5 hours, and 6 minutes' * dur.toHuman({ unitDisplay: "short" }) //=> '1 day, 5 hr, 6 min' * ``` */ toHuman(opts = {}) { if (!this.isValid) return INVALID$2; const l2 = orderedUnits$1.map((unit) => { const val = this.values[unit]; if (isUndefined2(val)) { return null; } return this.loc.numberFormatter({ style: "unit", unitDisplay: "long", ...opts, unit: unit.slice(0, -1) }).format(val); }).filter((n2) => n2); return this.loc.listFormatter({ type: "conjunction", style: opts.listStyle || "narrow", ...opts }).format(l2); } /** * Returns a JavaScript object with this Duration's values. * @example Duration.fromObject({ years: 1, days: 6, seconds: 2 }).toObject() //=> { years: 1, days: 6, seconds: 2 } * @return {Object} */ toObject() { if (!this.isValid) return {}; return { ...this.values }; } /** * Returns an ISO 8601-compliant string representation of this Duration. * @see https://en.wikipedia.org/wiki/ISO_8601#Durations * @example Duration.fromObject({ years: 3, seconds: 45 }).toISO() //=> 'P3YT45S' * @example Duration.fromObject({ months: 4, seconds: 45 }).toISO() //=> 'P4MT45S' * @example Duration.fromObject({ months: 5 }).toISO() //=> 'P5M' * @example Duration.fromObject({ minutes: 5 }).toISO() //=> 'PT5M' * @example Duration.fromObject({ milliseconds: 6 }).toISO() //=> 'PT0.006S' * @return {string} */ toISO() { if (!this.isValid) return null; let s2 = "P"; if (this.years !== 0) s2 += this.years + "Y"; if (this.months !== 0 || this.quarters !== 0) s2 += this.months + this.quarters * 3 + "M"; if (this.weeks !== 0) s2 += this.weeks + "W"; if (this.days !== 0) s2 += this.days + "D"; if (this.hours !== 0 || this.minutes !== 0 || this.seconds !== 0 || this.milliseconds !== 0) s2 += "T"; if (this.hours !== 0) s2 += this.hours + "H"; if (this.minutes !== 0) s2 += this.minutes + "M"; if (this.seconds !== 0 || this.milliseconds !== 0) s2 += roundTo(this.seconds + this.milliseconds / 1e3, 3) + "S"; if (s2 === "P") s2 += "T0S"; return s2; } /** * Returns an ISO 8601-compliant string representation of this Duration, formatted as a time of day. * Note that this will return null if the duration is invalid, negative, or equal to or greater than 24 hours. * @see https://en.wikipedia.org/wiki/ISO_8601#Times * @param {Object} opts - options * @param {boolean} [opts.suppressMilliseconds=false] - exclude milliseconds from the format if they're 0 * @param {boolean} [opts.suppressSeconds=false] - exclude seconds from the format if they're 0 * @param {boolean} [opts.includePrefix=false] - include the `T` prefix * @param {string} [opts.format='extended'] - choose between the basic and extended format * @example Duration.fromObject({ hours: 11 }).toISOTime() //=> '11:00:00.000' * @example Duration.fromObject({ hours: 11 }).toISOTime({ suppressMilliseconds: true }) //=> '11:00:00' * @example Duration.fromObject({ hours: 11 }).toISOTime({ suppressSeconds: true }) //=> '11:00' * @example Duration.fromObject({ hours: 11 }).toISOTime({ includePrefix: true }) //=> 'T11:00:00.000' * @example Duration.fromObject({ hours: 11 }).toISOTime({ format: 'basic' }) //=> '110000.000' * @return {string} */ toISOTime(opts = {}) { if (!this.isValid) return null; const millis = this.toMillis(); if (millis < 0 || millis >= 864e5) return null; opts = { suppressMilliseconds: false, suppressSeconds: false, includePrefix: false, format: "extended", ...opts, includeOffset: false }; const dateTime = DateTime.fromMillis(millis, { zone: "UTC" }); return dateTime.toISOTime(opts); } /** * Returns an ISO 8601 representation of this Duration appropriate for use in JSON. * @return {string} */ toJSON() { return this.toISO(); } /** * Returns an ISO 8601 representation of this Duration appropriate for use in debugging. * @return {string} */ toString() { return this.toISO(); } /** * Returns an milliseconds value of this Duration. * @return {number} */ toMillis() { if (!this.isValid) return NaN; return durationToMillis(this.matrix, this.values); } /** * Returns an milliseconds value of this Duration. Alias of {@link toMillis} * @return {number} */ valueOf() { return this.toMillis(); } /** * Make this Duration longer by the specified amount. Return a newly-constructed Duration. * @param {Duration|Object|number} duration - The amount to add. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject() * @return {Duration} */ plus(duration) { if (!this.isValid) return this; const dur = Duration.fromDurationLike(duration), result = {}; for (const k of orderedUnits$1) { if (hasOwnProperty2(dur.values, k) || hasOwnProperty2(this.values, k)) { result[k] = dur.get(k) + this.get(k); } } return clone$1(this, { values: result }, true); } /** * Make this Duration shorter by the specified amount. Return a newly-constructed Duration. * @param {Duration|Object|number} duration - The amount to subtract. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject() * @return {Duration} */ minus(duration) { if (!this.isValid) return this; const dur = Duration.fromDurationLike(duration); return this.plus(dur.negate()); } /** * Scale this Duration by the specified amount. Return a newly-constructed Duration. * @param {function} fn - The function to apply to each unit. Arity is 1 or 2: the value of the unit and, optionally, the unit name. Must return a number. * @example Duration.fromObject({ hours: 1, minutes: 30 }).mapUnits(x => x * 2) //=> { hours: 2, minutes: 60 } * @example Duration.fromObject({ hours: 1, minutes: 30 }).mapUnits((x, u) => u === "hours" ? x * 2 : x) //=> { hours: 2, minutes: 30 } * @return {Duration} */ mapUnits(fn) { if (!this.isValid) return this; const result = {}; for (const k of Object.keys(this.values)) { result[k] = asNumber(fn(this.values[k], k)); } return clone$1(this, { values: result }, true); } /** * Get the value of unit. * @param {string} unit - a unit such as 'minute' or 'day' * @example Duration.fromObject({years: 2, days: 3}).get('years') //=> 2 * @example Duration.fromObject({years: 2, days: 3}).get('months') //=> 0 * @example Duration.fromObject({years: 2, days: 3}).get('days') //=> 3 * @return {number} */ get(unit) { return this[Duration.normalizeUnit(unit)]; } /** * "Set" the values of specified units. Return a newly-constructed Duration. * @param {Object} values - a mapping of units to numbers * @example dur.set({ years: 2017 }) * @example dur.set({ hours: 8, minutes: 30 }) * @return {Duration} */ set(values) { if (!this.isValid) return this; const mixed = { ...this.values, ...normalizeObject(values, Duration.normalizeUnit) }; return clone$1(this, { values: mixed }); } /** * "Set" the locale and/or numberingSystem. Returns a newly-constructed Duration. * @example dur.reconfigure({ locale: 'en-GB' }) * @return {Duration} */ reconfigure({ locale, numberingSystem, conversionAccuracy, matrix } = {}) { const loc = this.loc.clone({ locale, numberingSystem }); const opts = { loc, matrix, conversionAccuracy }; return clone$1(this, opts); } /** * Return the length of the duration in the specified unit. * @param {string} unit - a unit such as 'minutes' or 'days' * @example Duration.fromObject({years: 1}).as('days') //=> 365 * @example Duration.fromObject({years: 1}).as('months') //=> 12 * @example Duration.fromObject({hours: 60}).as('days') //=> 2.5 * @return {number} */ as(unit) { return this.isValid ? this.shiftTo(unit).get(unit) : NaN; } /** * Reduce this Duration to its canonical representation in its current units. * Assuming the overall value of the Duration is positive, this means: * - excessive values for lower-order units are converted to higher-order units (if possible, see first and second example) * - negative lower-order units are converted to higher order units (there must be such a higher order unit, otherwise * the overall value would be negative, see second example) * - fractional values for higher-order units are converted to lower-order units (if possible, see fourth example) * * If the overall value is negative, the result of this method is equivalent to `this.negate().normalize().negate()`. * @example Duration.fromObject({ years: 2, days: 5000 }).normalize().toObject() //=> { years: 15, days: 255 } * @example Duration.fromObject({ days: 5000 }).normalize().toObject() //=> { days: 5000 } * @example Duration.fromObject({ hours: 12, minutes: -45 }).normalize().toObject() //=> { hours: 11, minutes: 15 } * @example Duration.fromObject({ years: 2.5, days: 0, hours: 0 }).normalize().toObject() //=> { years: 2, days: 182, hours: 12 } * @return {Duration} */ normalize() { if (!this.isValid) return this; const vals = this.toObject(); normalizeValues(this.matrix, vals); return clone$1(this, { values: vals }, true); } /** * Rescale units to its largest representation * @example Duration.fromObject({ milliseconds: 90000 }).rescale().toObject() //=> { minutes: 1, seconds: 30 } * @return {Duration} */ rescale() { if (!this.isValid) return this; const vals = removeZeroes(this.normalize().shiftToAll().toObject()); return clone$1(this, { values: vals }, true); } /** * Convert this Duration into its representation in a different set of units. * @example Duration.fromObject({ hours: 1, seconds: 30 }).shiftTo('minutes', 'milliseconds').toObject() //=> { minutes: 60, milliseconds: 30000 } * @return {Duration} */ shiftTo(...units) { if (!this.isValid) return this; if (units.length === 0) { return this; } units = units.map((u) => Duration.normalizeUnit(u)); const built = {}, accumulated = {}, vals = this.toObject(); let lastUnit; for (const k of orderedUnits$1) { if (units.indexOf(k) >= 0) { lastUnit = k; let own = 0; for (const ak in accumulated) { own += this.matrix[ak][k] * accumulated[ak]; accumulated[ak] = 0; } if (isNumber(vals[k])) { own += vals[k]; } const i = Math.trunc(own); built[k] = i; accumulated[k] = (own * 1e3 - i * 1e3) / 1e3; } else if (isNumber(vals[k])) { accumulated[k] = vals[k]; } } for (const key in accumulated) { if (accumulated[key] !== 0) { built[lastUnit] += key === lastUnit ? accumulated[key] : accumulated[key] / this.matrix[lastUnit][key]; } } normalizeValues(this.matrix, built); return clone$1(this, { values: built }, true); } /** * Shift this Duration to all available units. * Same as shiftTo("years", "months", "weeks", "days", "hours", "minutes", "seconds", "milliseconds") * @return {Duration} */ shiftToAll() { if (!this.isValid) return this; return this.shiftTo( "years", "months", "weeks", "days", "hours", "minutes", "seconds", "milliseconds" ); } /** * Return the negative of this Duration. * @example Duration.fromObject({ hours: 1, seconds: 30 }).negate().toObject() //=> { hours: -1, seconds: -30 } * @return {Duration} */ negate() { if (!this.isValid) return this; const negated = {}; for (const k of Object.keys(this.values)) { negated[k] = this.values[k] === 0 ? 0 : -this.values[k]; } return clone$1(this, { values: negated }, true); } /** * Get the years. * @type {number} */ get years() { return this.isValid ? this.values.years || 0 : NaN; } /** * Get the quarters. * @type {number} */ get quarters() { return this.isValid ? this.values.quarters || 0 : NaN; } /** * Get the months. * @type {number} */ get months() { return this.isValid ? this.values.months || 0 : NaN; } /** * Get the weeks * @type {number} */ get weeks() { return this.isValid ? this.values.weeks || 0 : NaN; } /** * Get the days. * @type {number} */ get days() { return this.isValid ? this.values.days || 0 : NaN; } /** * Get the hours. * @type {number} */ get hours() { return this.isValid ? this.values.hours || 0 : NaN; } /** * Get the minutes. * @type {number} */ get minutes() { return this.isValid ? this.values.minutes || 0 : NaN; } /** * Get the seconds. * @return {number} */ get seconds() { return this.isValid ? this.values.seconds || 0 : NaN; } /** * Get the milliseconds. * @return {number} */ get milliseconds() { return this.isValid ? this.values.milliseconds || 0 : NaN; } /** * Returns whether the Duration is invalid. Invalid durations are returned by diff operations * on invalid DateTimes or Intervals. * @return {boolean} */ get isValid() { return this.invalid === null; } /** * Returns an error code if this Duration became invalid, or null if the Duration is valid * @return {string} */ get invalidReason() { return this.invalid ? this.invalid.reason : null; } /** * Returns an explanation of why this Duration became invalid, or null if the Duration is valid * @type {string} */ get invalidExplanation() { return this.invalid ? this.invalid.explanation : null; } /** * Equality check * Two Durations are equal iff they have the same units and the same values for each unit. * @param {Duration} other * @return {boolean} */ equals(other) { if (!this.isValid || !other.isValid) { return false; } if (!this.loc.equals(other.loc)) { return false; } function eq(v1, v2) { if (v1 === void 0 || v1 === 0) return v2 === void 0 || v2 === 0; return v1 === v2; } for (const u of orderedUnits$1) { if (!eq(this.values[u], other.values[u])) { return false; } } return true; } }; var INVALID$1 = "Invalid Interval"; function validateStartEnd(start, end) { if (!start || !start.isValid) { return Interval.invalid("missing or invalid start"); } else if (!end || !end.isValid) { return Interval.invalid("missing or invalid end"); } else if (end < start) { return Interval.invalid( "end before start", `The end of an interval must be after its start, but you had start=${start.toISO()} and end=${end.toISO()}` ); } else { return null; } } var Interval = class { /** * @private */ constructor(config2) { this.s = config2.start; this.e = config2.end; this.invalid = config2.invalid || null; this.isLuxonInterval = true; } /** * Create an invalid Interval. * @param {string} reason - simple string of why this Interval is invalid. Should not contain parameters or anything else data-dependent * @param {string} [explanation=null] - longer explanation, may include parameters and other useful debugging information * @return {Interval} */ static invalid(reason, explanation = null) { if (!reason) { throw new InvalidArgumentError("need to specify a reason the Interval is invalid"); } const invalid = reason instanceof Invalid ? reason : new Invalid(reason, explanation); if (Settings.throwOnInvalid) { throw new InvalidIntervalError(invalid); } else { return new Interval({ invalid }); } } /** * Create an Interval from a start DateTime and an end DateTime. Inclusive of the start but not the end. * @param {DateTime|Date|Object} start * @param {DateTime|Date|Object} end * @return {Interval} */ static fromDateTimes(start, end) { const builtStart = friendlyDateTime(start), builtEnd = friendlyDateTime(end); const validateError = validateStartEnd(builtStart, builtEnd); if (validateError == null) { return new Interval({ start: builtStart, end: builtEnd }); } else { return validateError; } } /** * Create an Interval from a start DateTime and a Duration to extend to. * @param {DateTime|Date|Object} start * @param {Duration|Object|number} duration - the length of the Interval. * @return {Interval} */ static after(start, duration) { const dur = Duration.fromDurationLike(duration), dt = friendlyDateTime(start); return Interval.fromDateTimes(dt, dt.plus(dur)); } /** * Create an Interval from an end DateTime and a Duration to extend backwards to. * @param {DateTime|Date|Object} end * @param {Duration|Object|number} duration - the length of the Interval. * @return {Interval} */ static before(end, duration) { const dur = Duration.fromDurationLike(duration), dt = friendlyDateTime(end); return Interval.fromDateTimes(dt.minus(dur), dt); } /** * Create an Interval from an ISO 8601 string. * Accepts `/`, `/`, and `/` formats. * @param {string} text - the ISO string to parse * @param {Object} [opts] - options to pass {@link DateTime#fromISO} and optionally {@link Duration#fromISO} * @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals * @return {Interval} */ static fromISO(text, opts) { const [s2, e] = (text || "").split("/", 2); if (s2 && e) { let start, startIsValid; try { start = DateTime.fromISO(s2, opts); startIsValid = start.isValid; } catch (e2) { startIsValid = false; } let end, endIsValid; try { end = DateTime.fromISO(e, opts); endIsValid = end.isValid; } catch (e2) { endIsValid = false; } if (startIsValid && endIsValid) { return Interval.fromDateTimes(start, end); } if (startIsValid) { const dur = Duration.fromISO(e, opts); if (dur.isValid) { return Interval.after(start, dur); } } else if (endIsValid) { const dur = Duration.fromISO(s2, opts); if (dur.isValid) { return Interval.before(end, dur); } } } return Interval.invalid("unparsable", `the input "${text}" can't be parsed as ISO 8601`); } /** * Check if an object is an Interval. Works across context boundaries * @param {object} o * @return {boolean} */ static isInterval(o) { return o && o.isLuxonInterval || false; } /** * Returns the start of the Interval * @type {DateTime} */ get start() { return this.isValid ? this.s : null; } /** * Returns the end of the Interval * @type {DateTime} */ get end() { return this.isValid ? this.e : null; } /** * Returns whether this Interval's end is at least its start, meaning that the Interval isn't 'backwards'. * @type {boolean} */ get isValid() { return this.invalidReason === null; } /** * Returns an error code if this Interval is invalid, or null if the Interval is valid * @type {string} */ get invalidReason() { return this.invalid ? this.invalid.reason : null; } /** * Returns an explanation of why this Interval became invalid, or null if the Interval is valid * @type {string} */ get invalidExplanation() { return this.invalid ? this.invalid.explanation : null; } /** * Returns the length of the Interval in the specified unit. * @param {string} unit - the unit (such as 'hours' or 'days') to return the length in. * @return {number} */ length(unit = "milliseconds") { return this.isValid ? this.toDuration(...[unit]).get(unit) : NaN; } /** * Returns the count of minutes, hours, days, months, or years included in the Interval, even in part. * Unlike {@link Interval#length} this counts sections of the calendar, not periods of time, e.g. specifying 'day' * asks 'what dates are included in this interval?', not 'how many days long is this interval?' * @param {string} [unit='milliseconds'] - the unit of time to count. * @return {number} */ count(unit = "milliseconds") { if (!this.isValid) return NaN; const start = this.start.startOf(unit), end = this.end.startOf(unit); return Math.floor(end.diff(start, unit).get(unit)) + (end.valueOf() !== this.end.valueOf()); } /** * Returns whether this Interval's start and end are both in the same unit of time * @param {string} unit - the unit of time to check sameness on * @return {boolean} */ hasSame(unit) { return this.isValid ? this.isEmpty() || this.e.minus(1).hasSame(this.s, unit) : false; } /** * Return whether this Interval has the same start and end DateTimes. * @return {boolean} */ isEmpty() { return this.s.valueOf() === this.e.valueOf(); } /** * Return whether this Interval's start is after the specified DateTime. * @param {DateTime} dateTime * @return {boolean} */ isAfter(dateTime) { if (!this.isValid) return false; return this.s > dateTime; } /** * Return whether this Interval's end is before the specified DateTime. * @param {DateTime} dateTime * @return {boolean} */ isBefore(dateTime) { if (!this.isValid) return false; return this.e <= dateTime; } /** * Return whether this Interval contains the specified DateTime. * @param {DateTime} dateTime * @return {boolean} */ contains(dateTime) { if (!this.isValid) return false; return this.s <= dateTime && this.e > dateTime; } /** * "Sets" the start and/or end dates. Returns a newly-constructed Interval. * @param {Object} values - the values to set * @param {DateTime} values.start - the starting DateTime * @param {DateTime} values.end - the ending DateTime * @return {Interval} */ set({ start, end } = {}) { if (!this.isValid) return this; return Interval.fromDateTimes(start || this.s, end || this.e); } /** * Split this Interval at each of the specified DateTimes * @param {...DateTime} dateTimes - the unit of time to count. * @return {Array} */ splitAt(...dateTimes) { if (!this.isValid) return []; const sorted = dateTimes.map(friendlyDateTime).filter((d) => this.contains(d)).sort(), results = []; let { s: s2 } = this, i = 0; while (s2 < this.e) { const added = sorted[i] || this.e, next = +added > +this.e ? this.e : added; results.push(Interval.fromDateTimes(s2, next)); s2 = next; i += 1; } return results; } /** * Split this Interval into smaller Intervals, each of the specified length. * Left over time is grouped into a smaller interval * @param {Duration|Object|number} duration - The length of each resulting interval. * @return {Array} */ splitBy(duration) { const dur = Duration.fromDurationLike(duration); if (!this.isValid || !dur.isValid || dur.as("milliseconds") === 0) { return []; } let { s: s2 } = this, idx = 1, next; const results = []; while (s2 < this.e) { const added = this.start.plus(dur.mapUnits((x3) => x3 * idx)); next = +added > +this.e ? this.e : added; results.push(Interval.fromDateTimes(s2, next)); s2 = next; idx += 1; } return results; } /** * Split this Interval into the specified number of smaller intervals. * @param {number} numberOfParts - The number of Intervals to divide the Interval into. * @return {Array} */ divideEqually(numberOfParts) { if (!this.isValid) return []; return this.splitBy(this.length() / numberOfParts).slice(0, numberOfParts); } /** * Return whether this Interval overlaps with the specified Interval * @param {Interval} other * @return {boolean} */ overlaps(other) { return this.e > other.s && this.s < other.e; } /** * Return whether this Interval's end is adjacent to the specified Interval's start. * @param {Interval} other * @return {boolean} */ abutsStart(other) { if (!this.isValid) return false; return +this.e === +other.s; } /** * Return whether this Interval's start is adjacent to the specified Interval's end. * @param {Interval} other * @return {boolean} */ abutsEnd(other) { if (!this.isValid) return false; return +other.e === +this.s; } /** * Return whether this Interval engulfs the start and end of the specified Interval. * @param {Interval} other * @return {boolean} */ engulfs(other) { if (!this.isValid) return false; return this.s <= other.s && this.e >= other.e; } /** * Return whether this Interval has the same start and end as the specified Interval. * @param {Interval} other * @return {boolean} */ equals(other) { if (!this.isValid || !other.isValid) { return false; } return this.s.equals(other.s) && this.e.equals(other.e); } /** * Return an Interval representing the intersection of this Interval and the specified Interval. * Specifically, the resulting Interval has the maximum start time and the minimum end time of the two Intervals. * Returns null if the intersection is empty, meaning, the intervals don't intersect. * @param {Interval} other * @return {Interval} */ intersection(other) { if (!this.isValid) return this; const s2 = this.s > other.s ? this.s : other.s, e = this.e < other.e ? this.e : other.e; if (s2 >= e) { return null; } else { return Interval.fromDateTimes(s2, e); } } /** * Return an Interval representing the union of this Interval and the specified Interval. * Specifically, the resulting Interval has the minimum start time and the maximum end time of the two Intervals. * @param {Interval} other * @return {Interval} */ union(other) { if (!this.isValid) return this; const s2 = this.s < other.s ? this.s : other.s, e = this.e > other.e ? this.e : other.e; return Interval.fromDateTimes(s2, e); } /** * Merge an array of Intervals into a equivalent minimal set of Intervals. * Combines overlapping and adjacent Intervals. * @param {Array} intervals * @return {Array} */ static merge(intervals) { const [found, final] = intervals.sort((a2, b) => a2.s - b.s).reduce( ([sofar, current], item) => { if (!current) { return [sofar, item]; } else if (current.overlaps(item) || current.abutsStart(item)) { return [sofar, current.union(item)]; } else { return [sofar.concat([current]), item]; } }, [[], null] ); if (final) { found.push(final); } return found; } /** * Return an array of Intervals representing the spans of time that only appear in one of the specified Intervals. * @param {Array} intervals * @return {Array} */ static xor(intervals) { let start = null, currentCount = 0; const results = [], ends = intervals.map((i) => [ { time: i.s, type: "s" }, { time: i.e, type: "e" } ]), flattened = Array.prototype.concat(...ends), arr = flattened.sort((a2, b) => a2.time - b.time); for (const i of arr) { currentCount += i.type === "s" ? 1 : -1; if (currentCount === 1) { start = i.time; } else { if (start && +start !== +i.time) { results.push(Interval.fromDateTimes(start, i.time)); } start = null; } } return Interval.merge(results); } /** * Return an Interval representing the span of time in this Interval that doesn't overlap with any of the specified Intervals. * @param {...Interval} intervals * @return {Array} */ difference(...intervals) { return Interval.xor([this].concat(intervals)).map((i) => this.intersection(i)).filter((i) => i && !i.isEmpty()); } /** * Returns a string representation of this Interval appropriate for debugging. * @return {string} */ toString() { if (!this.isValid) return INVALID$1; return `[${this.s.toISO()} \u2013 ${this.e.toISO()})`; } /** * Returns a localized string representing this Interval. Accepts the same options as the * Intl.DateTimeFormat constructor and any presets defined by Luxon, such as * {@link DateTime.DATE_FULL} or {@link DateTime.TIME_SIMPLE}. The exact behavior of this method * is browser-specific, but in general it will return an appropriate representation of the * Interval in the assigned locale. Defaults to the system's locale if no locale has been * specified. * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat * @param {Object} [formatOpts=DateTime.DATE_SHORT] - Either a DateTime preset or * Intl.DateTimeFormat constructor options. * @param {Object} opts - Options to override the configuration of the start DateTime. * @example Interval.fromISO('2022-11-07T09:00Z/2022-11-08T09:00Z').toLocaleString(); //=> 11/7/2022 – 11/8/2022 * @example Interval.fromISO('2022-11-07T09:00Z/2022-11-08T09:00Z').toLocaleString(DateTime.DATE_FULL); //=> November 7 – 8, 2022 * @example Interval.fromISO('2022-11-07T09:00Z/2022-11-08T09:00Z').toLocaleString(DateTime.DATE_FULL, { locale: 'fr-FR' }); //=> 7–8 novembre 2022 * @example Interval.fromISO('2022-11-07T17:00Z/2022-11-07T19:00Z').toLocaleString(DateTime.TIME_SIMPLE); //=> 6:00 – 8:00 PM * @example Interval.fromISO('2022-11-07T17:00Z/2022-11-07T19:00Z').toLocaleString({ weekday: 'short', month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' }); //=> Mon, Nov 07, 6:00 – 8:00 p * @return {string} */ toLocaleString(formatOpts = DATE_SHORT, opts = {}) { return this.isValid ? Formatter.create(this.s.loc.clone(opts), formatOpts).formatInterval(this) : INVALID$1; } /** * Returns an ISO 8601-compliant string representation of this Interval. * @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals * @param {Object} opts - The same options as {@link DateTime#toISO} * @return {string} */ toISO(opts) { if (!this.isValid) return INVALID$1; return `${this.s.toISO(opts)}/${this.e.toISO(opts)}`; } /** * Returns an ISO 8601-compliant string representation of date of this Interval. * The time components are ignored. * @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals * @return {string} */ toISODate() { if (!this.isValid) return INVALID$1; return `${this.s.toISODate()}/${this.e.toISODate()}`; } /** * Returns an ISO 8601-compliant string representation of time of this Interval. * The date components are ignored. * @see https://en.wikipedia.org/wiki/ISO_8601#Time_intervals * @param {Object} opts - The same options as {@link DateTime#toISO} * @return {string} */ toISOTime(opts) { if (!this.isValid) return INVALID$1; return `${this.s.toISOTime(opts)}/${this.e.toISOTime(opts)}`; } /** * Returns a string representation of this Interval formatted according to the specified format * string. **You may not want this.** See {@link Interval#toLocaleString} for a more flexible * formatting tool. * @param {string} dateFormat - The format string. This string formats the start and end time. * See {@link DateTime#toFormat} for details. * @param {Object} opts - Options. * @param {string} [opts.separator = ' – '] - A separator to place between the start and end * representations. * @return {string} */ toFormat(dateFormat, { separator = " \u2013 " } = {}) { if (!this.isValid) return INVALID$1; return `${this.s.toFormat(dateFormat)}${separator}${this.e.toFormat(dateFormat)}`; } /** * Return a Duration representing the time spanned by this interval. * @param {string|string[]} [unit=['milliseconds']] - the unit or units (such as 'hours' or 'days') to include in the duration. * @param {Object} opts - options that affect the creation of the Duration * @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use * @example Interval.fromDateTimes(dt1, dt2).toDuration().toObject() //=> { milliseconds: 88489257 } * @example Interval.fromDateTimes(dt1, dt2).toDuration('days').toObject() //=> { days: 1.0241812152777778 } * @example Interval.fromDateTimes(dt1, dt2).toDuration(['hours', 'minutes']).toObject() //=> { hours: 24, minutes: 34.82095 } * @example Interval.fromDateTimes(dt1, dt2).toDuration(['hours', 'minutes', 'seconds']).toObject() //=> { hours: 24, minutes: 34, seconds: 49.257 } * @example Interval.fromDateTimes(dt1, dt2).toDuration('seconds').toObject() //=> { seconds: 88489.257 } * @return {Duration} */ toDuration(unit, opts) { if (!this.isValid) { return Duration.invalid(this.invalidReason); } return this.e.diff(this.s, unit, opts); } /** * Run mapFn on the interval start and end, returning a new Interval from the resulting DateTimes * @param {function} mapFn * @return {Interval} * @example Interval.fromDateTimes(dt1, dt2).mapEndpoints(endpoint => endpoint.toUTC()) * @example Interval.fromDateTimes(dt1, dt2).mapEndpoints(endpoint => endpoint.plus({ hours: 2 })) */ mapEndpoints(mapFn) { return Interval.fromDateTimes(mapFn(this.s), mapFn(this.e)); } }; var Info = class { /** * Return whether the specified zone contains a DST. * @param {string|Zone} [zone='local'] - Zone to check. Defaults to the environment's local zone. * @return {boolean} */ static hasDST(zone = Settings.defaultZone) { const proto = DateTime.now().setZone(zone).set({ month: 12 }); return !zone.isUniversal && proto.offset !== proto.set({ month: 6 }).offset; } /** * Return whether the specified zone is a valid IANA specifier. * @param {string} zone - Zone to check * @return {boolean} */ static isValidIANAZone(zone) { return IANAZone.isValidZone(zone); } /** * Converts the input into a {@link Zone} instance. * * * If `input` is already a Zone instance, it is returned unchanged. * * If `input` is a string containing a valid time zone name, a Zone instance * with that name is returned. * * If `input` is a string that doesn't refer to a known time zone, a Zone * instance with {@link Zone#isValid} == false is returned. * * If `input is a number, a Zone instance with the specified fixed offset * in minutes is returned. * * If `input` is `null` or `undefined`, the default zone is returned. * @param {string|Zone|number} [input] - the value to be converted * @return {Zone} */ static normalizeZone(input) { return normalizeZone(input, Settings.defaultZone); } /** * Return an array of standalone month names. * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat * @param {string} [length='long'] - the length of the month representation, such as "numeric", "2-digit", "narrow", "short", "long" * @param {Object} opts - options * @param {string} [opts.locale] - the locale code * @param {string} [opts.numberingSystem=null] - the numbering system * @param {string} [opts.locObj=null] - an existing locale object to use * @param {string} [opts.outputCalendar='gregory'] - the calendar * @example Info.months()[0] //=> 'January' * @example Info.months('short')[0] //=> 'Jan' * @example Info.months('numeric')[0] //=> '1' * @example Info.months('short', { locale: 'fr-CA' } )[0] //=> 'janv.' * @example Info.months('numeric', { locale: 'ar' })[0] //=> '١' * @example Info.months('long', { outputCalendar: 'islamic' })[0] //=> 'Rabiʻ I' * @return {Array} */ static months(length = "long", { locale = null, numberingSystem = null, locObj = null, outputCalendar = "gregory" } = {}) { return (locObj || Locale.create(locale, numberingSystem, outputCalendar)).months(length); } /** * Return an array of format month names. * Format months differ from standalone months in that they're meant to appear next to the day of the month. In some languages, that * changes the string. * See {@link Info#months} * @param {string} [length='long'] - the length of the month representation, such as "numeric", "2-digit", "narrow", "short", "long" * @param {Object} opts - options * @param {string} [opts.locale] - the locale code * @param {string} [opts.numberingSystem=null] - the numbering system * @param {string} [opts.locObj=null] - an existing locale object to use * @param {string} [opts.outputCalendar='gregory'] - the calendar * @return {Array} */ static monthsFormat(length = "long", { locale = null, numberingSystem = null, locObj = null, outputCalendar = "gregory" } = {}) { return (locObj || Locale.create(locale, numberingSystem, outputCalendar)).months(length, true); } /** * Return an array of standalone week names. * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat * @param {string} [length='long'] - the length of the weekday representation, such as "narrow", "short", "long". * @param {Object} opts - options * @param {string} [opts.locale] - the locale code * @param {string} [opts.numberingSystem=null] - the numbering system * @param {string} [opts.locObj=null] - an existing locale object to use * @example Info.weekdays()[0] //=> 'Monday' * @example Info.weekdays('short')[0] //=> 'Mon' * @example Info.weekdays('short', { locale: 'fr-CA' })[0] //=> 'lun.' * @example Info.weekdays('short', { locale: 'ar' })[0] //=> 'الاثنين' * @return {Array} */ static weekdays(length = "long", { locale = null, numberingSystem = null, locObj = null } = {}) { return (locObj || Locale.create(locale, numberingSystem, null)).weekdays(length); } /** * Return an array of format week names. * Format weekdays differ from standalone weekdays in that they're meant to appear next to more date information. In some languages, that * changes the string. * See {@link Info#weekdays} * @param {string} [length='long'] - the length of the month representation, such as "narrow", "short", "long". * @param {Object} opts - options * @param {string} [opts.locale=null] - the locale code * @param {string} [opts.numberingSystem=null] - the numbering system * @param {string} [opts.locObj=null] - an existing locale object to use * @return {Array} */ static weekdaysFormat(length = "long", { locale = null, numberingSystem = null, locObj = null } = {}) { return (locObj || Locale.create(locale, numberingSystem, null)).weekdays(length, true); } /** * Return an array of meridiems. * @param {Object} opts - options * @param {string} [opts.locale] - the locale code * @example Info.meridiems() //=> [ 'AM', 'PM' ] * @example Info.meridiems({ locale: 'my' }) //=> [ 'နံနက်', 'ညနေ' ] * @return {Array} */ static meridiems({ locale = null } = {}) { return Locale.create(locale).meridiems(); } /** * Return an array of eras, such as ['BC', 'AD']. The locale can be specified, but the calendar system is always Gregorian. * @param {string} [length='short'] - the length of the era representation, such as "short" or "long". * @param {Object} opts - options * @param {string} [opts.locale] - the locale code * @example Info.eras() //=> [ 'BC', 'AD' ] * @example Info.eras('long') //=> [ 'Before Christ', 'Anno Domini' ] * @example Info.eras('long', { locale: 'fr' }) //=> [ 'avant Jésus-Christ', 'après Jésus-Christ' ] * @return {Array} */ static eras(length = "short", { locale = null } = {}) { return Locale.create(locale, null, "gregory").eras(length); } /** * Return the set of available features in this environment. * Some features of Luxon are not available in all environments. For example, on older browsers, relative time formatting support is not available. Use this function to figure out if that's the case. * Keys: * * `relative`: whether this environment supports relative time formatting * @example Info.features() //=> { relative: false } * @return {Object} */ static features() { return { relative: hasRelative() }; } }; function dayDiff(earlier, later) { const utcDayStart = (dt) => dt.toUTC(0, { keepLocalTime: true }).startOf("day").valueOf(), ms = utcDayStart(later) - utcDayStart(earlier); return Math.floor(Duration.fromMillis(ms).as("days")); } function highOrderDiffs(cursor, later, units) { const differs = [ ["years", (a2, b) => b.year - a2.year], ["quarters", (a2, b) => b.quarter - a2.quarter + (b.year - a2.year) * 4], ["months", (a2, b) => b.month - a2.month + (b.year - a2.year) * 12], [ "weeks", (a2, b) => { const days = dayDiff(a2, b); return (days - days % 7) / 7; } ], ["days", dayDiff] ]; const results = {}; const earlier = cursor; let lowestOrder, highWater; for (const [unit, differ] of differs) { if (units.indexOf(unit) >= 0) { lowestOrder = unit; results[unit] = differ(cursor, later); highWater = earlier.plus(results); if (highWater > later) { results[unit]--; cursor = earlier.plus(results); if (cursor > later) { highWater = cursor; results[unit]--; cursor = earlier.plus(results); } } else { cursor = highWater; } } } return [cursor, results, highWater, lowestOrder]; } function diff(earlier, later, units, opts) { let [cursor, results, highWater, lowestOrder] = highOrderDiffs(earlier, later, units); const remainingMillis = later - cursor; const lowerOrderUnits = units.filter( (u) => ["hours", "minutes", "seconds", "milliseconds"].indexOf(u) >= 0 ); if (lowerOrderUnits.length === 0) { if (highWater < later) { highWater = cursor.plus({ [lowestOrder]: 1 }); } if (highWater !== cursor) { results[lowestOrder] = (results[lowestOrder] || 0) + remainingMillis / (highWater - cursor); } } const duration = Duration.fromObject(results, opts); if (lowerOrderUnits.length > 0) { return Duration.fromMillis(remainingMillis, opts).shiftTo(...lowerOrderUnits).plus(duration); } else { return duration; } } var numberingSystems = { arab: "[\u0660-\u0669]", arabext: "[\u06F0-\u06F9]", bali: "[\u1B50-\u1B59]", beng: "[\u09E6-\u09EF]", deva: "[\u0966-\u096F]", fullwide: "[\uFF10-\uFF19]", gujr: "[\u0AE6-\u0AEF]", hanidec: "[\u3007|\u4E00|\u4E8C|\u4E09|\u56DB|\u4E94|\u516D|\u4E03|\u516B|\u4E5D]", khmr: "[\u17E0-\u17E9]", knda: "[\u0CE6-\u0CEF]", laoo: "[\u0ED0-\u0ED9]", limb: "[\u1946-\u194F]", mlym: "[\u0D66-\u0D6F]", mong: "[\u1810-\u1819]", mymr: "[\u1040-\u1049]", orya: "[\u0B66-\u0B6F]", tamldec: "[\u0BE6-\u0BEF]", telu: "[\u0C66-\u0C6F]", thai: "[\u0E50-\u0E59]", tibt: "[\u0F20-\u0F29]", latn: "\\d" }; var numberingSystemsUTF16 = { arab: [1632, 1641], arabext: [1776, 1785], bali: [6992, 7001], beng: [2534, 2543], deva: [2406, 2415], fullwide: [65296, 65303], gujr: [2790, 2799], khmr: [6112, 6121], knda: [3302, 3311], laoo: [3792, 3801], limb: [6470, 6479], mlym: [3430, 3439], mong: [6160, 6169], mymr: [4160, 4169], orya: [2918, 2927], tamldec: [3046, 3055], telu: [3174, 3183], thai: [3664, 3673], tibt: [3872, 3881] }; var hanidecChars = numberingSystems.hanidec.replace(/[\[|\]]/g, "").split(""); function parseDigits(str) { let value = parseInt(str, 10); if (isNaN(value)) { value = ""; for (let i = 0; i < str.length; i++) { const code = str.charCodeAt(i); if (str[i].search(numberingSystems.hanidec) !== -1) { value += hanidecChars.indexOf(str[i]); } else { for (const key in numberingSystemsUTF16) { const [min2, max2] = numberingSystemsUTF16[key]; if (code >= min2 && code <= max2) { value += code - min2; } } } } return parseInt(value, 10); } else { return value; } } function digitRegex({ numberingSystem }, append = "") { return new RegExp(`${numberingSystems[numberingSystem || "latn"]}${append}`); } var MISSING_FTP = "missing Intl.DateTimeFormat.formatToParts support"; function intUnit(regex, post = (i) => i) { return { regex, deser: ([s2]) => post(parseDigits(s2)) }; } var NBSP = String.fromCharCode(160); var spaceOrNBSP = `[ ${NBSP}]`; var spaceOrNBSPRegExp = new RegExp(spaceOrNBSP, "g"); function fixListRegex(s2) { return s2.replace(/\./g, "\\.?").replace(spaceOrNBSPRegExp, spaceOrNBSP); } function stripInsensitivities(s2) { return s2.replace(/\./g, "").replace(spaceOrNBSPRegExp, " ").toLowerCase(); } function oneOf(strings, startIndex) { if (strings === null) { return null; } else { return { regex: RegExp(strings.map(fixListRegex).join("|")), deser: ([s2]) => strings.findIndex((i) => stripInsensitivities(s2) === stripInsensitivities(i)) + startIndex }; } } function offset(regex, groups) { return { regex, deser: ([, h, m2]) => signedOffset(h, m2), groups }; } function simple(regex) { return { regex, deser: ([s2]) => s2 }; } function escapeToken(value) { return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&"); } function unitForToken(token, loc) { const one = digitRegex(loc), two = digitRegex(loc, "{2}"), three4 = digitRegex(loc, "{3}"), four = digitRegex(loc, "{4}"), six = digitRegex(loc, "{6}"), oneOrTwo = digitRegex(loc, "{1,2}"), oneToThree = digitRegex(loc, "{1,3}"), oneToSix = digitRegex(loc, "{1,6}"), oneToNine = digitRegex(loc, "{1,9}"), twoToFour = digitRegex(loc, "{2,4}"), fourToSix = digitRegex(loc, "{4,6}"), literal = (t) => ({ regex: RegExp(escapeToken(t.val)), deser: ([s2]) => s2, literal: true }), unitate = (t) => { if (token.literal) { return literal(t); } switch (t.val) { case "G": return oneOf(loc.eras("short"), 0); case "GG": return oneOf(loc.eras("long"), 0); case "y": return intUnit(oneToSix); case "yy": return intUnit(twoToFour, untruncateYear); case "yyyy": return intUnit(four); case "yyyyy": return intUnit(fourToSix); case "yyyyyy": return intUnit(six); case "M": return intUnit(oneOrTwo); case "MM": return intUnit(two); case "MMM": return oneOf(loc.months("short", true), 1); case "MMMM": return oneOf(loc.months("long", true), 1); case "L": return intUnit(oneOrTwo); case "LL": return intUnit(two); case "LLL": return oneOf(loc.months("short", false), 1); case "LLLL": return oneOf(loc.months("long", false), 1); case "d": return intUnit(oneOrTwo); case "dd": return intUnit(two); case "o": return intUnit(oneToThree); case "ooo": return intUnit(three4); case "HH": return intUnit(two); case "H": return intUnit(oneOrTwo); case "hh": return intUnit(two); case "h": return intUnit(oneOrTwo); case "mm": return intUnit(two); case "m": return intUnit(oneOrTwo); case "q": return intUnit(oneOrTwo); case "qq": return intUnit(two); case "s": return intUnit(oneOrTwo); case "ss": return intUnit(two); case "S": return intUnit(oneToThree); case "SSS": return intUnit(three4); case "u": return simple(oneToNine); case "uu": return simple(oneOrTwo); case "uuu": return intUnit(one); case "a": return oneOf(loc.meridiems(), 0); case "kkkk": return intUnit(four); case "kk": return intUnit(twoToFour, untruncateYear); case "W": return intUnit(oneOrTwo); case "WW": return intUnit(two); case "E": case "c": return intUnit(one); case "EEE": return oneOf(loc.weekdays("short", false), 1); case "EEEE": return oneOf(loc.weekdays("long", false), 1); case "ccc": return oneOf(loc.weekdays("short", true), 1); case "cccc": return oneOf(loc.weekdays("long", true), 1); case "Z": case "ZZ": return offset(new RegExp(`([+-]${oneOrTwo.source})(?::(${two.source}))?`), 2); case "ZZZ": return offset(new RegExp(`([+-]${oneOrTwo.source})(${two.source})?`), 2); case "z": return simple(/[a-z_+-/]{1,256}?/i); case " ": return simple(/[^\S\n\r]/); default: return literal(t); } }; const unit = unitate(token) || { invalidReason: MISSING_FTP }; unit.token = token; return unit; } var partTypeStyleToTokenVal = { year: { "2-digit": "yy", numeric: "yyyyy" }, month: { numeric: "M", "2-digit": "MM", short: "MMM", long: "MMMM" }, day: { numeric: "d", "2-digit": "dd" }, weekday: { short: "EEE", long: "EEEE" }, dayperiod: "a", dayPeriod: "a", hour12: { numeric: "h", "2-digit": "hh" }, hour24: { numeric: "H", "2-digit": "HH" }, minute: { numeric: "m", "2-digit": "mm" }, second: { numeric: "s", "2-digit": "ss" }, timeZoneName: { long: "ZZZZZ", short: "ZZZ" } }; function tokenForPart(part, formatOpts, resolvedOpts) { const { type, value } = part; if (type === "literal") { const isSpace = /^\s+$/.test(value); return { literal: !isSpace, val: isSpace ? " " : value }; } const style = formatOpts[type]; let actualType = type; if (type === "hour") { if (formatOpts.hour12 != null) { actualType = formatOpts.hour12 ? "hour12" : "hour24"; } else if (formatOpts.hourCycle != null) { if (formatOpts.hourCycle === "h11" || formatOpts.hourCycle === "h12") { actualType = "hour12"; } else { actualType = "hour24"; } } else { actualType = resolvedOpts.hour12 ? "hour12" : "hour24"; } } let val = partTypeStyleToTokenVal[actualType]; if (typeof val === "object") { val = val[style]; } if (val) { return { literal: false, val }; } return void 0; } function buildRegex(units) { const re = units.map((u) => u.regex).reduce((f, r) => `${f}(${r.source})`, ""); return [`^${re}$`, units]; } function match(input, regex, handlers) { const matches = input.match(regex); if (matches) { const all = {}; let matchIndex = 1; for (const i in handlers) { if (hasOwnProperty2(handlers, i)) { const h = handlers[i], groups = h.groups ? h.groups + 1 : 1; if (!h.literal && h.token) { all[h.token.val[0]] = h.deser(matches.slice(matchIndex, matchIndex + groups)); } matchIndex += groups; } } return [matches, all]; } else { return [matches, {}]; } } function dateTimeFromMatches(matches) { const toField = (token) => { switch (token) { case "S": return "millisecond"; case "s": return "second"; case "m": return "minute"; case "h": case "H": return "hour"; case "d": return "day"; case "o": return "ordinal"; case "L": case "M": return "month"; case "y": return "year"; case "E": case "c": return "weekday"; case "W": return "weekNumber"; case "k": return "weekYear"; case "q": return "quarter"; default: return null; } }; let zone = null; let specificOffset; if (!isUndefined2(matches.z)) { zone = IANAZone.create(matches.z); } if (!isUndefined2(matches.Z)) { if (!zone) { zone = new FixedOffsetZone(matches.Z); } specificOffset = matches.Z; } if (!isUndefined2(matches.q)) { matches.M = (matches.q - 1) * 3 + 1; } if (!isUndefined2(matches.h)) { if (matches.h < 12 && matches.a === 1) { matches.h += 12; } else if (matches.h === 12 && matches.a === 0) { matches.h = 0; } } if (matches.G === 0 && matches.y) { matches.y = -matches.y; } if (!isUndefined2(matches.u)) { matches.S = parseMillis(matches.u); } const vals = Object.keys(matches).reduce((r, k) => { const f = toField(k); if (f) { r[f] = matches[k]; } return r; }, {}); return [vals, zone, specificOffset]; } var dummyDateTimeCache = null; function getDummyDateTime() { if (!dummyDateTimeCache) { dummyDateTimeCache = DateTime.fromMillis(1555555555555); } return dummyDateTimeCache; } function maybeExpandMacroToken(token, locale) { if (token.literal) { return token; } const formatOpts = Formatter.macroTokenToFormatOpts(token.val); const tokens = formatOptsToTokens(formatOpts, locale); if (tokens == null || tokens.includes(void 0)) { return token; } return tokens; } function expandMacroTokens(tokens, locale) { return Array.prototype.concat(...tokens.map((t) => maybeExpandMacroToken(t, locale))); } function explainFromTokens(locale, input, format2) { const tokens = expandMacroTokens(Formatter.parseFormat(format2), locale), units = tokens.map((t) => unitForToken(t, locale)), disqualifyingUnit = units.find((t) => t.invalidReason); if (disqualifyingUnit) { return { input, tokens, invalidReason: disqualifyingUnit.invalidReason }; } else { const [regexString, handlers] = buildRegex(units), regex = RegExp(regexString, "i"), [rawMatches, matches] = match(input, regex, handlers), [result, zone, specificOffset] = matches ? dateTimeFromMatches(matches) : [null, null, void 0]; if (hasOwnProperty2(matches, "a") && hasOwnProperty2(matches, "H")) { throw new ConflictingSpecificationError( "Can't include meridiem when specifying 24-hour format" ); } return { input, tokens, regex, rawMatches, matches, result, zone, specificOffset }; } } function parseFromTokens(locale, input, format2) { const { result, zone, specificOffset, invalidReason } = explainFromTokens(locale, input, format2); return [result, zone, specificOffset, invalidReason]; } function formatOptsToTokens(formatOpts, locale) { if (!formatOpts) { return null; } const formatter = Formatter.create(locale, formatOpts); const df = formatter.dtFormatter(getDummyDateTime()); const parts = df.formatToParts(); const resolvedOpts = df.resolvedOptions(); return parts.map((p) => tokenForPart(p, formatOpts, resolvedOpts)); } var nonLeapLadder = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]; var leapLadder = [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335]; function unitOutOfRange(unit, value) { return new Invalid( "unit out of range", `you specified ${value} (of type ${typeof value}) as a ${unit}, which is invalid` ); } function dayOfWeek(year, month, day) { const d = new Date(Date.UTC(year, month - 1, day)); if (year < 100 && year >= 0) { d.setUTCFullYear(d.getUTCFullYear() - 1900); } const js = d.getUTCDay(); return js === 0 ? 7 : js; } function computeOrdinal(year, month, day) { return day + (isLeapYear(year) ? leapLadder : nonLeapLadder)[month - 1]; } function uncomputeOrdinal(year, ordinal2) { const table = isLeapYear(year) ? leapLadder : nonLeapLadder, month0 = table.findIndex((i) => i < ordinal2), day = ordinal2 - table[month0]; return { month: month0 + 1, day }; } function gregorianToWeek(gregObj) { const { year, month, day } = gregObj, ordinal2 = computeOrdinal(year, month, day), weekday = dayOfWeek(year, month, day); let weekNumber = Math.floor((ordinal2 - weekday + 10) / 7), weekYear; if (weekNumber < 1) { weekYear = year - 1; weekNumber = weeksInWeekYear(weekYear); } else if (weekNumber > weeksInWeekYear(year)) { weekYear = year + 1; weekNumber = 1; } else { weekYear = year; } return { weekYear, weekNumber, weekday, ...timeObject(gregObj) }; } function weekToGregorian(weekData) { const { weekYear, weekNumber, weekday } = weekData, weekdayOfJan4 = dayOfWeek(weekYear, 1, 4), yearInDays = daysInYear(weekYear); let ordinal2 = weekNumber * 7 + weekday - weekdayOfJan4 - 3, year; if (ordinal2 < 1) { year = weekYear - 1; ordinal2 += daysInYear(year); } else if (ordinal2 > yearInDays) { year = weekYear + 1; ordinal2 -= daysInYear(weekYear); } else { year = weekYear; } const { month, day } = uncomputeOrdinal(year, ordinal2); return { year, month, day, ...timeObject(weekData) }; } function gregorianToOrdinal(gregData) { const { year, month, day } = gregData; const ordinal2 = computeOrdinal(year, month, day); return { year, ordinal: ordinal2, ...timeObject(gregData) }; } function ordinalToGregorian(ordinalData) { const { year, ordinal: ordinal2 } = ordinalData; const { month, day } = uncomputeOrdinal(year, ordinal2); return { year, month, day, ...timeObject(ordinalData) }; } function hasInvalidWeekData(obj) { const validYear = isInteger(obj.weekYear), validWeek = integerBetween(obj.weekNumber, 1, weeksInWeekYear(obj.weekYear)), validWeekday = integerBetween(obj.weekday, 1, 7); if (!validYear) { return unitOutOfRange("weekYear", obj.weekYear); } else if (!validWeek) { return unitOutOfRange("week", obj.week); } else if (!validWeekday) { return unitOutOfRange("weekday", obj.weekday); } else return false; } function hasInvalidOrdinalData(obj) { const validYear = isInteger(obj.year), validOrdinal = integerBetween(obj.ordinal, 1, daysInYear(obj.year)); if (!validYear) { return unitOutOfRange("year", obj.year); } else if (!validOrdinal) { return unitOutOfRange("ordinal", obj.ordinal); } else return false; } function hasInvalidGregorianData(obj) { const validYear = isInteger(obj.year), validMonth = integerBetween(obj.month, 1, 12), validDay = integerBetween(obj.day, 1, daysInMonth(obj.year, obj.month)); if (!validYear) { return unitOutOfRange("year", obj.year); } else if (!validMonth) { return unitOutOfRange("month", obj.month); } else if (!validDay) { return unitOutOfRange("day", obj.day); } else return false; } function hasInvalidTimeData(obj) { const { hour, minute, second, millisecond } = obj; const validHour = integerBetween(hour, 0, 23) || hour === 24 && minute === 0 && second === 0 && millisecond === 0, validMinute = integerBetween(minute, 0, 59), validSecond = integerBetween(second, 0, 59), validMillisecond = integerBetween(millisecond, 0, 999); if (!validHour) { return unitOutOfRange("hour", hour); } else if (!validMinute) { return unitOutOfRange("minute", minute); } else if (!validSecond) { return unitOutOfRange("second", second); } else if (!validMillisecond) { return unitOutOfRange("millisecond", millisecond); } else return false; } var INVALID2 = "Invalid DateTime"; var MAX_DATE = 864e13; function unsupportedZone(zone) { return new Invalid("unsupported zone", `the zone "${zone.name}" is not supported`); } function possiblyCachedWeekData(dt) { if (dt.weekData === null) { dt.weekData = gregorianToWeek(dt.c); } return dt.weekData; } function clone2(inst, alts) { const current = { ts: inst.ts, zone: inst.zone, c: inst.c, o: inst.o, loc: inst.loc, invalid: inst.invalid }; return new DateTime({ ...current, ...alts, old: current }); } function fixOffset(localTS, o, tz) { let utcGuess = localTS - o * 60 * 1e3; const o2 = tz.offset(utcGuess); if (o === o2) { return [utcGuess, o]; } utcGuess -= (o2 - o) * 60 * 1e3; const o3 = tz.offset(utcGuess); if (o2 === o3) { return [utcGuess, o2]; } return [localTS - Math.min(o2, o3) * 60 * 1e3, Math.max(o2, o3)]; } function tsToObj(ts, offset2) { ts += offset2 * 60 * 1e3; const d = new Date(ts); return { year: d.getUTCFullYear(), month: d.getUTCMonth() + 1, day: d.getUTCDate(), hour: d.getUTCHours(), minute: d.getUTCMinutes(), second: d.getUTCSeconds(), millisecond: d.getUTCMilliseconds() }; } function objToTS(obj, offset2, zone) { return fixOffset(objToLocalTS(obj), offset2, zone); } function adjustTime(inst, dur) { const oPre = inst.o, year = inst.c.year + Math.trunc(dur.years), month = inst.c.month + Math.trunc(dur.months) + Math.trunc(dur.quarters) * 3, c2 = { ...inst.c, year, month, day: Math.min(inst.c.day, daysInMonth(year, month)) + Math.trunc(dur.days) + Math.trunc(dur.weeks) * 7 }, millisToAdd = Duration.fromObject({ years: dur.years - Math.trunc(dur.years), quarters: dur.quarters - Math.trunc(dur.quarters), months: dur.months - Math.trunc(dur.months), weeks: dur.weeks - Math.trunc(dur.weeks), days: dur.days - Math.trunc(dur.days), hours: dur.hours, minutes: dur.minutes, seconds: dur.seconds, milliseconds: dur.milliseconds }).as("milliseconds"), localTS = objToLocalTS(c2); let [ts, o] = fixOffset(localTS, oPre, inst.zone); if (millisToAdd !== 0) { ts += millisToAdd; o = inst.zone.offset(ts); } return { ts, o }; } function parseDataToDateTime(parsed, parsedZone, opts, format2, text, specificOffset) { const { setZone, zone } = opts; if (parsed && Object.keys(parsed).length !== 0 || parsedZone) { const interpretationZone = parsedZone || zone, inst = DateTime.fromObject(parsed, { ...opts, zone: interpretationZone, specificOffset }); return setZone ? inst : inst.setZone(zone); } else { return DateTime.invalid( new Invalid("unparsable", `the input "${text}" can't be parsed as ${format2}`) ); } } function toTechFormat(dt, format2, allowZ = true) { return dt.isValid ? Formatter.create(Locale.create("en-US"), { allowZ, forceSimple: true }).formatDateTimeFromString(dt, format2) : null; } function toISODate(o, extended) { const longFormat = o.c.year > 9999 || o.c.year < 0; let c2 = ""; if (longFormat && o.c.year >= 0) c2 += "+"; c2 += padStart(o.c.year, longFormat ? 6 : 4); if (extended) { c2 += "-"; c2 += padStart(o.c.month); c2 += "-"; c2 += padStart(o.c.day); } else { c2 += padStart(o.c.month); c2 += padStart(o.c.day); } return c2; } function toISOTime(o, extended, suppressSeconds, suppressMilliseconds, includeOffset, extendedZone) { let c2 = padStart(o.c.hour); if (extended) { c2 += ":"; c2 += padStart(o.c.minute); if (o.c.millisecond !== 0 || o.c.second !== 0 || !suppressSeconds) { c2 += ":"; } } else { c2 += padStart(o.c.minute); } if (o.c.millisecond !== 0 || o.c.second !== 0 || !suppressSeconds) { c2 += padStart(o.c.second); if (o.c.millisecond !== 0 || !suppressMilliseconds) { c2 += "."; c2 += padStart(o.c.millisecond, 3); } } if (includeOffset) { if (o.isOffsetFixed && o.offset === 0 && !extendedZone) { c2 += "Z"; } else if (o.o < 0) { c2 += "-"; c2 += padStart(Math.trunc(-o.o / 60)); c2 += ":"; c2 += padStart(Math.trunc(-o.o % 60)); } else { c2 += "+"; c2 += padStart(Math.trunc(o.o / 60)); c2 += ":"; c2 += padStart(Math.trunc(o.o % 60)); } } if (extendedZone) { c2 += "[" + o.zone.ianaName + "]"; } return c2; } var defaultUnitValues = { month: 1, day: 1, hour: 0, minute: 0, second: 0, millisecond: 0 }; var defaultWeekUnitValues = { weekNumber: 1, weekday: 1, hour: 0, minute: 0, second: 0, millisecond: 0 }; var defaultOrdinalUnitValues = { ordinal: 1, hour: 0, minute: 0, second: 0, millisecond: 0 }; var orderedUnits = ["year", "month", "day", "hour", "minute", "second", "millisecond"]; var orderedWeekUnits = [ "weekYear", "weekNumber", "weekday", "hour", "minute", "second", "millisecond" ]; var orderedOrdinalUnits = ["year", "ordinal", "hour", "minute", "second", "millisecond"]; function normalizeUnit(unit) { const normalized = { year: "year", years: "year", month: "month", months: "month", day: "day", days: "day", hour: "hour", hours: "hour", minute: "minute", minutes: "minute", quarter: "quarter", quarters: "quarter", second: "second", seconds: "second", millisecond: "millisecond", milliseconds: "millisecond", weekday: "weekday", weekdays: "weekday", weeknumber: "weekNumber", weeksnumber: "weekNumber", weeknumbers: "weekNumber", weekyear: "weekYear", weekyears: "weekYear", ordinal: "ordinal" }[unit.toLowerCase()]; if (!normalized) throw new InvalidUnitError(unit); return normalized; } function quickDT(obj, opts) { const zone = normalizeZone(opts.zone, Settings.defaultZone), loc = Locale.fromObject(opts), tsNow = Settings.now(); let ts, o; if (!isUndefined2(obj.year)) { for (const u of orderedUnits) { if (isUndefined2(obj[u])) { obj[u] = defaultUnitValues[u]; } } const invalid = hasInvalidGregorianData(obj) || hasInvalidTimeData(obj); if (invalid) { return DateTime.invalid(invalid); } const offsetProvis = zone.offset(tsNow); [ts, o] = objToTS(obj, offsetProvis, zone); } else { ts = tsNow; } return new DateTime({ ts, zone, loc, o }); } function diffRelative(start, end, opts) { const round = isUndefined2(opts.round) ? true : opts.round, format2 = (c2, unit) => { c2 = roundTo(c2, round || opts.calendary ? 0 : 2, true); const formatter = end.loc.clone(opts).relFormatter(opts); return formatter.format(c2, unit); }, differ = (unit) => { if (opts.calendary) { if (!end.hasSame(start, unit)) { return end.startOf(unit).diff(start.startOf(unit), unit).get(unit); } else return 0; } else { return end.diff(start, unit).get(unit); } }; if (opts.unit) { return format2(differ(opts.unit), opts.unit); } for (const unit of opts.units) { const count = differ(unit); if (Math.abs(count) >= 1) { return format2(count, unit); } } return format2(start > end ? -0 : 0, opts.units[opts.units.length - 1]); } function lastOpts(argList) { let opts = {}, args; if (argList.length > 0 && typeof argList[argList.length - 1] === "object") { opts = argList[argList.length - 1]; args = Array.from(argList).slice(0, argList.length - 1); } else { args = Array.from(argList); } return [opts, args]; } var DateTime = class { /** * @access private */ constructor(config2) { const zone = config2.zone || Settings.defaultZone; let invalid = config2.invalid || (Number.isNaN(config2.ts) ? new Invalid("invalid input") : null) || (!zone.isValid ? unsupportedZone(zone) : null); this.ts = isUndefined2(config2.ts) ? Settings.now() : config2.ts; let c2 = null, o = null; if (!invalid) { const unchanged = config2.old && config2.old.ts === this.ts && config2.old.zone.equals(zone); if (unchanged) { [c2, o] = [config2.old.c, config2.old.o]; } else { const ot = zone.offset(this.ts); c2 = tsToObj(this.ts, ot); invalid = Number.isNaN(c2.year) ? new Invalid("invalid input") : null; c2 = invalid ? null : c2; o = invalid ? null : ot; } } this._zone = zone; this.loc = config2.loc || Locale.create(); this.invalid = invalid; this.weekData = null; this.c = c2; this.o = o; this.isLuxonDateTime = true; } // CONSTRUCT /** * Create a DateTime for the current instant, in the system's time zone. * * Use Settings to override these default values if needed. * @example DateTime.now().toISO() //~> now in the ISO format * @return {DateTime} */ static now() { return new DateTime({}); } /** * Create a local DateTime * @param {number} [year] - The calendar year. If omitted (as in, call `local()` with no arguments), the current time will be used * @param {number} [month=1] - The month, 1-indexed * @param {number} [day=1] - The day of the month, 1-indexed * @param {number} [hour=0] - The hour of the day, in 24-hour time * @param {number} [minute=0] - The minute of the hour, meaning a number between 0 and 59 * @param {number} [second=0] - The second of the minute, meaning a number between 0 and 59 * @param {number} [millisecond=0] - The millisecond of the second, meaning a number between 0 and 999 * @example DateTime.local() //~> now * @example DateTime.local({ zone: "America/New_York" }) //~> now, in US east coast time * @example DateTime.local(2017) //~> 2017-01-01T00:00:00 * @example DateTime.local(2017, 3) //~> 2017-03-01T00:00:00 * @example DateTime.local(2017, 3, 12, { locale: "fr" }) //~> 2017-03-12T00:00:00, with a French locale * @example DateTime.local(2017, 3, 12, 5) //~> 2017-03-12T05:00:00 * @example DateTime.local(2017, 3, 12, 5, { zone: "utc" }) //~> 2017-03-12T05:00:00, in UTC * @example DateTime.local(2017, 3, 12, 5, 45) //~> 2017-03-12T05:45:00 * @example DateTime.local(2017, 3, 12, 5, 45, 10) //~> 2017-03-12T05:45:10 * @example DateTime.local(2017, 3, 12, 5, 45, 10, 765) //~> 2017-03-12T05:45:10.765 * @return {DateTime} */ static local() { const [opts, args] = lastOpts(arguments), [year, month, day, hour, minute, second, millisecond] = args; return quickDT({ year, month, day, hour, minute, second, millisecond }, opts); } /** * Create a DateTime in UTC * @param {number} [year] - The calendar year. If omitted (as in, call `utc()` with no arguments), the current time will be used * @param {number} [month=1] - The month, 1-indexed * @param {number} [day=1] - The day of the month * @param {number} [hour=0] - The hour of the day, in 24-hour time * @param {number} [minute=0] - The minute of the hour, meaning a number between 0 and 59 * @param {number} [second=0] - The second of the minute, meaning a number between 0 and 59 * @param {number} [millisecond=0] - The millisecond of the second, meaning a number between 0 and 999 * @param {Object} options - configuration options for the DateTime * @param {string} [options.locale] - a locale to set on the resulting DateTime instance * @param {string} [options.outputCalendar] - the output calendar to set on the resulting DateTime instance * @param {string} [options.numberingSystem] - the numbering system to set on the resulting DateTime instance * @example DateTime.utc() //~> now * @example DateTime.utc(2017) //~> 2017-01-01T00:00:00Z * @example DateTime.utc(2017, 3) //~> 2017-03-01T00:00:00Z * @example DateTime.utc(2017, 3, 12) //~> 2017-03-12T00:00:00Z * @example DateTime.utc(2017, 3, 12, 5) //~> 2017-03-12T05:00:00Z * @example DateTime.utc(2017, 3, 12, 5, 45) //~> 2017-03-12T05:45:00Z * @example DateTime.utc(2017, 3, 12, 5, 45, { locale: "fr" }) //~> 2017-03-12T05:45:00Z with a French locale * @example DateTime.utc(2017, 3, 12, 5, 45, 10) //~> 2017-03-12T05:45:10Z * @example DateTime.utc(2017, 3, 12, 5, 45, 10, 765, { locale: "fr" }) //~> 2017-03-12T05:45:10.765Z with a French locale * @return {DateTime} */ static utc() { const [opts, args] = lastOpts(arguments), [year, month, day, hour, minute, second, millisecond] = args; opts.zone = FixedOffsetZone.utcInstance; return quickDT({ year, month, day, hour, minute, second, millisecond }, opts); } /** * Create a DateTime from a JavaScript Date object. Uses the default zone. * @param {Date} date - a JavaScript Date object * @param {Object} options - configuration options for the DateTime * @param {string|Zone} [options.zone='local'] - the zone to place the DateTime into * @return {DateTime} */ static fromJSDate(date, options = {}) { const ts = isDate(date) ? date.valueOf() : NaN; if (Number.isNaN(ts)) { return DateTime.invalid("invalid input"); } const zoneToUse = normalizeZone(options.zone, Settings.defaultZone); if (!zoneToUse.isValid) { return DateTime.invalid(unsupportedZone(zoneToUse)); } return new DateTime({ ts, zone: zoneToUse, loc: Locale.fromObject(options) }); } /** * Create a DateTime from a number of milliseconds since the epoch (meaning since 1 January 1970 00:00:00 UTC). Uses the default zone. * @param {number} milliseconds - a number of milliseconds since 1970 UTC * @param {Object} options - configuration options for the DateTime * @param {string|Zone} [options.zone='local'] - the zone to place the DateTime into * @param {string} [options.locale] - a locale to set on the resulting DateTime instance * @param {string} options.outputCalendar - the output calendar to set on the resulting DateTime instance * @param {string} options.numberingSystem - the numbering system to set on the resulting DateTime instance * @return {DateTime} */ static fromMillis(milliseconds, options = {}) { if (!isNumber(milliseconds)) { throw new InvalidArgumentError( `fromMillis requires a numerical input, but received a ${typeof milliseconds} with value ${milliseconds}` ); } else if (milliseconds < -MAX_DATE || milliseconds > MAX_DATE) { return DateTime.invalid("Timestamp out of range"); } else { return new DateTime({ ts: milliseconds, zone: normalizeZone(options.zone, Settings.defaultZone), loc: Locale.fromObject(options) }); } } /** * Create a DateTime from a number of seconds since the epoch (meaning since 1 January 1970 00:00:00 UTC). Uses the default zone. * @param {number} seconds - a number of seconds since 1970 UTC * @param {Object} options - configuration options for the DateTime * @param {string|Zone} [options.zone='local'] - the zone to place the DateTime into * @param {string} [options.locale] - a locale to set on the resulting DateTime instance * @param {string} options.outputCalendar - the output calendar to set on the resulting DateTime instance * @param {string} options.numberingSystem - the numbering system to set on the resulting DateTime instance * @return {DateTime} */ static fromSeconds(seconds, options = {}) { if (!isNumber(seconds)) { throw new InvalidArgumentError("fromSeconds requires a numerical input"); } else { return new DateTime({ ts: seconds * 1e3, zone: normalizeZone(options.zone, Settings.defaultZone), loc: Locale.fromObject(options) }); } } /** * Create a DateTime from a JavaScript object with keys like 'year' and 'hour' with reasonable defaults. * @param {Object} obj - the object to create the DateTime from * @param {number} obj.year - a year, such as 1987 * @param {number} obj.month - a month, 1-12 * @param {number} obj.day - a day of the month, 1-31, depending on the month * @param {number} obj.ordinal - day of the year, 1-365 or 366 * @param {number} obj.weekYear - an ISO week year * @param {number} obj.weekNumber - an ISO week number, between 1 and 52 or 53, depending on the year * @param {number} obj.weekday - an ISO weekday, 1-7, where 1 is Monday and 7 is Sunday * @param {number} obj.hour - hour of the day, 0-23 * @param {number} obj.minute - minute of the hour, 0-59 * @param {number} obj.second - second of the minute, 0-59 * @param {number} obj.millisecond - millisecond of the second, 0-999 * @param {Object} opts - options for creating this DateTime * @param {string|Zone} [opts.zone='local'] - interpret the numbers in the context of a particular zone. Can take any value taken as the first argument to setZone() * @param {string} [opts.locale='system's locale'] - a locale to set on the resulting DateTime instance * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance * @param {string} opts.numberingSystem - the numbering system to set on the resulting DateTime instance * @example DateTime.fromObject({ year: 1982, month: 5, day: 25}).toISODate() //=> '1982-05-25' * @example DateTime.fromObject({ year: 1982 }).toISODate() //=> '1982-01-01' * @example DateTime.fromObject({ hour: 10, minute: 26, second: 6 }) //~> today at 10:26:06 * @example DateTime.fromObject({ hour: 10, minute: 26, second: 6 }, { zone: 'utc' }), * @example DateTime.fromObject({ hour: 10, minute: 26, second: 6 }, { zone: 'local' }) * @example DateTime.fromObject({ hour: 10, minute: 26, second: 6 }, { zone: 'America/New_York' }) * @example DateTime.fromObject({ weekYear: 2016, weekNumber: 2, weekday: 3 }).toISODate() //=> '2016-01-13' * @return {DateTime} */ static fromObject(obj, opts = {}) { obj = obj || {}; const zoneToUse = normalizeZone(opts.zone, Settings.defaultZone); if (!zoneToUse.isValid) { return DateTime.invalid(unsupportedZone(zoneToUse)); } const tsNow = Settings.now(), offsetProvis = !isUndefined2(opts.specificOffset) ? opts.specificOffset : zoneToUse.offset(tsNow), normalized = normalizeObject(obj, normalizeUnit), containsOrdinal = !isUndefined2(normalized.ordinal), containsGregorYear = !isUndefined2(normalized.year), containsGregorMD = !isUndefined2(normalized.month) || !isUndefined2(normalized.day), containsGregor = containsGregorYear || containsGregorMD, definiteWeekDef = normalized.weekYear || normalized.weekNumber, loc = Locale.fromObject(opts); if ((containsGregor || containsOrdinal) && definiteWeekDef) { throw new ConflictingSpecificationError( "Can't mix weekYear/weekNumber units with year/month/day or ordinals" ); } if (containsGregorMD && containsOrdinal) { throw new ConflictingSpecificationError("Can't mix ordinal dates with month/day"); } const useWeekData = definiteWeekDef || normalized.weekday && !containsGregor; let units, defaultValues, objNow = tsToObj(tsNow, offsetProvis); if (useWeekData) { units = orderedWeekUnits; defaultValues = defaultWeekUnitValues; objNow = gregorianToWeek(objNow); } else if (containsOrdinal) { units = orderedOrdinalUnits; defaultValues = defaultOrdinalUnitValues; objNow = gregorianToOrdinal(objNow); } else { units = orderedUnits; defaultValues = defaultUnitValues; } let foundFirst = false; for (const u of units) { const v = normalized[u]; if (!isUndefined2(v)) { foundFirst = true; } else if (foundFirst) { normalized[u] = defaultValues[u]; } else { normalized[u] = objNow[u]; } } const higherOrderInvalid = useWeekData ? hasInvalidWeekData(normalized) : containsOrdinal ? hasInvalidOrdinalData(normalized) : hasInvalidGregorianData(normalized), invalid = higherOrderInvalid || hasInvalidTimeData(normalized); if (invalid) { return DateTime.invalid(invalid); } const gregorian = useWeekData ? weekToGregorian(normalized) : containsOrdinal ? ordinalToGregorian(normalized) : normalized, [tsFinal, offsetFinal] = objToTS(gregorian, offsetProvis, zoneToUse), inst = new DateTime({ ts: tsFinal, zone: zoneToUse, o: offsetFinal, loc }); if (normalized.weekday && containsGregor && obj.weekday !== inst.weekday) { return DateTime.invalid( "mismatched weekday", `you can't specify both a weekday of ${normalized.weekday} and a date of ${inst.toISO()}` ); } return inst; } /** * Create a DateTime from an ISO 8601 string * @param {string} text - the ISO string * @param {Object} opts - options to affect the creation * @param {string|Zone} [opts.zone='local'] - use this zone if no offset is specified in the input string itself. Will also convert the time to this zone * @param {boolean} [opts.setZone=false] - override the zone with a fixed-offset zone specified in the string itself, if it specifies one * @param {string} [opts.locale='system's locale'] - a locale to set on the resulting DateTime instance * @param {string} [opts.outputCalendar] - the output calendar to set on the resulting DateTime instance * @param {string} [opts.numberingSystem] - the numbering system to set on the resulting DateTime instance * @example DateTime.fromISO('2016-05-25T09:08:34.123') * @example DateTime.fromISO('2016-05-25T09:08:34.123+06:00') * @example DateTime.fromISO('2016-05-25T09:08:34.123+06:00', {setZone: true}) * @example DateTime.fromISO('2016-05-25T09:08:34.123', {zone: 'utc'}) * @example DateTime.fromISO('2016-W05-4') * @return {DateTime} */ static fromISO(text, opts = {}) { const [vals, parsedZone] = parseISODate(text); return parseDataToDateTime(vals, parsedZone, opts, "ISO 8601", text); } /** * Create a DateTime from an RFC 2822 string * @param {string} text - the RFC 2822 string * @param {Object} opts - options to affect the creation * @param {string|Zone} [opts.zone='local'] - convert the time to this zone. Since the offset is always specified in the string itself, this has no effect on the interpretation of string, merely the zone the resulting DateTime is expressed in. * @param {boolean} [opts.setZone=false] - override the zone with a fixed-offset zone specified in the string itself, if it specifies one * @param {string} [opts.locale='system's locale'] - a locale to set on the resulting DateTime instance * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance * @param {string} opts.numberingSystem - the numbering system to set on the resulting DateTime instance * @example DateTime.fromRFC2822('25 Nov 2016 13:23:12 GMT') * @example DateTime.fromRFC2822('Fri, 25 Nov 2016 13:23:12 +0600') * @example DateTime.fromRFC2822('25 Nov 2016 13:23 Z') * @return {DateTime} */ static fromRFC2822(text, opts = {}) { const [vals, parsedZone] = parseRFC2822Date(text); return parseDataToDateTime(vals, parsedZone, opts, "RFC 2822", text); } /** * Create a DateTime from an HTTP header date * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1 * @param {string} text - the HTTP header date * @param {Object} opts - options to affect the creation * @param {string|Zone} [opts.zone='local'] - convert the time to this zone. Since HTTP dates are always in UTC, this has no effect on the interpretation of string, merely the zone the resulting DateTime is expressed in. * @param {boolean} [opts.setZone=false] - override the zone with the fixed-offset zone specified in the string. For HTTP dates, this is always UTC, so this option is equivalent to setting the `zone` option to 'utc', but this option is included for consistency with similar methods. * @param {string} [opts.locale='system's locale'] - a locale to set on the resulting DateTime instance * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance * @param {string} opts.numberingSystem - the numbering system to set on the resulting DateTime instance * @example DateTime.fromHTTP('Sun, 06 Nov 1994 08:49:37 GMT') * @example DateTime.fromHTTP('Sunday, 06-Nov-94 08:49:37 GMT') * @example DateTime.fromHTTP('Sun Nov 6 08:49:37 1994') * @return {DateTime} */ static fromHTTP(text, opts = {}) { const [vals, parsedZone] = parseHTTPDate(text); return parseDataToDateTime(vals, parsedZone, opts, "HTTP", opts); } /** * Create a DateTime from an input string and format string. * Defaults to en-US if no locale has been specified, regardless of the system's locale. For a table of tokens and their interpretations, see [here](https://moment.github.io/luxon/#/parsing?id=table-of-tokens). * @param {string} text - the string to parse * @param {string} fmt - the format the string is expected to be in (see the link below for the formats) * @param {Object} opts - options to affect the creation * @param {string|Zone} [opts.zone='local'] - use this zone if no offset is specified in the input string itself. Will also convert the DateTime to this zone * @param {boolean} [opts.setZone=false] - override the zone with a zone specified in the string itself, if it specifies one * @param {string} [opts.locale='en-US'] - a locale string to use when parsing. Will also set the DateTime to this locale * @param {string} opts.numberingSystem - the numbering system to use when parsing. Will also set the resulting DateTime to this numbering system * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance * @return {DateTime} */ static fromFormat(text, fmt, opts = {}) { if (isUndefined2(text) || isUndefined2(fmt)) { throw new InvalidArgumentError("fromFormat requires an input string and a format"); } const { locale = null, numberingSystem = null } = opts, localeToUse = Locale.fromOpts({ locale, numberingSystem, defaultToEN: true }), [vals, parsedZone, specificOffset, invalid] = parseFromTokens(localeToUse, text, fmt); if (invalid) { return DateTime.invalid(invalid); } else { return parseDataToDateTime(vals, parsedZone, opts, `format ${fmt}`, text, specificOffset); } } /** * @deprecated use fromFormat instead */ static fromString(text, fmt, opts = {}) { return DateTime.fromFormat(text, fmt, opts); } /** * Create a DateTime from a SQL date, time, or datetime * Defaults to en-US if no locale has been specified, regardless of the system's locale * @param {string} text - the string to parse * @param {Object} opts - options to affect the creation * @param {string|Zone} [opts.zone='local'] - use this zone if no offset is specified in the input string itself. Will also convert the DateTime to this zone * @param {boolean} [opts.setZone=false] - override the zone with a zone specified in the string itself, if it specifies one * @param {string} [opts.locale='en-US'] - a locale string to use when parsing. Will also set the DateTime to this locale * @param {string} opts.numberingSystem - the numbering system to use when parsing. Will also set the resulting DateTime to this numbering system * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance * @example DateTime.fromSQL('2017-05-15') * @example DateTime.fromSQL('2017-05-15 09:12:34') * @example DateTime.fromSQL('2017-05-15 09:12:34.342') * @example DateTime.fromSQL('2017-05-15 09:12:34.342+06:00') * @example DateTime.fromSQL('2017-05-15 09:12:34.342 America/Los_Angeles') * @example DateTime.fromSQL('2017-05-15 09:12:34.342 America/Los_Angeles', { setZone: true }) * @example DateTime.fromSQL('2017-05-15 09:12:34.342', { zone: 'America/Los_Angeles' }) * @example DateTime.fromSQL('09:12:34.342') * @return {DateTime} */ static fromSQL(text, opts = {}) { const [vals, parsedZone] = parseSQL(text); return parseDataToDateTime(vals, parsedZone, opts, "SQL", text); } /** * Create an invalid DateTime. * @param {string} reason - simple string of why this DateTime is invalid. Should not contain parameters or anything else data-dependent. * @param {string} [explanation=null] - longer explanation, may include parameters and other useful debugging information * @return {DateTime} */ static invalid(reason, explanation = null) { if (!reason) { throw new InvalidArgumentError("need to specify a reason the DateTime is invalid"); } const invalid = reason instanceof Invalid ? reason : new Invalid(reason, explanation); if (Settings.throwOnInvalid) { throw new InvalidDateTimeError(invalid); } else { return new DateTime({ invalid }); } } /** * Check if an object is an instance of DateTime. Works across context boundaries * @param {object} o * @return {boolean} */ static isDateTime(o) { return o && o.isLuxonDateTime || false; } /** * Produce the format string for a set of options * @param formatOpts * @param localeOpts * @returns {string} */ static parseFormatForOpts(formatOpts, localeOpts = {}) { const tokenList = formatOptsToTokens(formatOpts, Locale.fromObject(localeOpts)); return !tokenList ? null : tokenList.map((t) => t ? t.val : null).join(""); } /** * Produce the the fully expanded format token for the locale * Does NOT quote characters, so quoted tokens will not round trip correctly * @param fmt * @param localeOpts * @returns {string} */ static expandFormat(fmt, localeOpts = {}) { const expanded = expandMacroTokens(Formatter.parseFormat(fmt), Locale.fromObject(localeOpts)); return expanded.map((t) => t.val).join(""); } // INFO /** * Get the value of unit. * @param {string} unit - a unit such as 'minute' or 'day' * @example DateTime.local(2017, 7, 4).get('month'); //=> 7 * @example DateTime.local(2017, 7, 4).get('day'); //=> 4 * @return {number} */ get(unit) { return this[unit]; } /** * Returns whether the DateTime is valid. Invalid DateTimes occur when: * * The DateTime was created from invalid calendar information, such as the 13th month or February 30 * * The DateTime was created by an operation on another invalid date * @type {boolean} */ get isValid() { return this.invalid === null; } /** * Returns an error code if this DateTime is invalid, or null if the DateTime is valid * @type {string} */ get invalidReason() { return this.invalid ? this.invalid.reason : null; } /** * Returns an explanation of why this DateTime became invalid, or null if the DateTime is valid * @type {string} */ get invalidExplanation() { return this.invalid ? this.invalid.explanation : null; } /** * Get the locale of a DateTime, such 'en-GB'. The locale is used when formatting the DateTime * * @type {string} */ get locale() { return this.isValid ? this.loc.locale : null; } /** * Get the numbering system of a DateTime, such 'beng'. The numbering system is used when formatting the DateTime * * @type {string} */ get numberingSystem() { return this.isValid ? this.loc.numberingSystem : null; } /** * Get the output calendar of a DateTime, such 'islamic'. The output calendar is used when formatting the DateTime * * @type {string} */ get outputCalendar() { return this.isValid ? this.loc.outputCalendar : null; } /** * Get the time zone associated with this DateTime. * @type {Zone} */ get zone() { return this._zone; } /** * Get the name of the time zone. * @type {string} */ get zoneName() { return this.isValid ? this.zone.name : null; } /** * Get the year * @example DateTime.local(2017, 5, 25).year //=> 2017 * @type {number} */ get year() { return this.isValid ? this.c.year : NaN; } /** * Get the quarter * @example DateTime.local(2017, 5, 25).quarter //=> 2 * @type {number} */ get quarter() { return this.isValid ? Math.ceil(this.c.month / 3) : NaN; } /** * Get the month (1-12). * @example DateTime.local(2017, 5, 25).month //=> 5 * @type {number} */ get month() { return this.isValid ? this.c.month : NaN; } /** * Get the day of the month (1-30ish). * @example DateTime.local(2017, 5, 25).day //=> 25 * @type {number} */ get day() { return this.isValid ? this.c.day : NaN; } /** * Get the hour of the day (0-23). * @example DateTime.local(2017, 5, 25, 9).hour //=> 9 * @type {number} */ get hour() { return this.isValid ? this.c.hour : NaN; } /** * Get the minute of the hour (0-59). * @example DateTime.local(2017, 5, 25, 9, 30).minute //=> 30 * @type {number} */ get minute() { return this.isValid ? this.c.minute : NaN; } /** * Get the second of the minute (0-59). * @example DateTime.local(2017, 5, 25, 9, 30, 52).second //=> 52 * @type {number} */ get second() { return this.isValid ? this.c.second : NaN; } /** * Get the millisecond of the second (0-999). * @example DateTime.local(2017, 5, 25, 9, 30, 52, 654).millisecond //=> 654 * @type {number} */ get millisecond() { return this.isValid ? this.c.millisecond : NaN; } /** * Get the week year * @see https://en.wikipedia.org/wiki/ISO_week_date * @example DateTime.local(2014, 12, 31).weekYear //=> 2015 * @type {number} */ get weekYear() { return this.isValid ? possiblyCachedWeekData(this).weekYear : NaN; } /** * Get the week number of the week year (1-52ish). * @see https://en.wikipedia.org/wiki/ISO_week_date * @example DateTime.local(2017, 5, 25).weekNumber //=> 21 * @type {number} */ get weekNumber() { return this.isValid ? possiblyCachedWeekData(this).weekNumber : NaN; } /** * Get the day of the week. * 1 is Monday and 7 is Sunday * @see https://en.wikipedia.org/wiki/ISO_week_date * @example DateTime.local(2014, 11, 31).weekday //=> 4 * @type {number} */ get weekday() { return this.isValid ? possiblyCachedWeekData(this).weekday : NaN; } /** * Get the ordinal (meaning the day of the year) * @example DateTime.local(2017, 5, 25).ordinal //=> 145 * @type {number|DateTime} */ get ordinal() { return this.isValid ? gregorianToOrdinal(this.c).ordinal : NaN; } /** * Get the human readable short month name, such as 'Oct'. * Defaults to the system's locale if no locale has been specified * @example DateTime.local(2017, 10, 30).monthShort //=> Oct * @type {string} */ get monthShort() { return this.isValid ? Info.months("short", { locObj: this.loc })[this.month - 1] : null; } /** * Get the human readable long month name, such as 'October'. * Defaults to the system's locale if no locale has been specified * @example DateTime.local(2017, 10, 30).monthLong //=> October * @type {string} */ get monthLong() { return this.isValid ? Info.months("long", { locObj: this.loc })[this.month - 1] : null; } /** * Get the human readable short weekday, such as 'Mon'. * Defaults to the system's locale if no locale has been specified * @example DateTime.local(2017, 10, 30).weekdayShort //=> Mon * @type {string} */ get weekdayShort() { return this.isValid ? Info.weekdays("short", { locObj: this.loc })[this.weekday - 1] : null; } /** * Get the human readable long weekday, such as 'Monday'. * Defaults to the system's locale if no locale has been specified * @example DateTime.local(2017, 10, 30).weekdayLong //=> Monday * @type {string} */ get weekdayLong() { return this.isValid ? Info.weekdays("long", { locObj: this.loc })[this.weekday - 1] : null; } /** * Get the UTC offset of this DateTime in minutes * @example DateTime.now().offset //=> -240 * @example DateTime.utc().offset //=> 0 * @type {number} */ get offset() { return this.isValid ? +this.o : NaN; } /** * Get the short human name for the zone's current offset, for example "EST" or "EDT". * Defaults to the system's locale if no locale has been specified * @type {string} */ get offsetNameShort() { if (this.isValid) { return this.zone.offsetName(this.ts, { format: "short", locale: this.locale }); } else { return null; } } /** * Get the long human name for the zone's current offset, for example "Eastern Standard Time" or "Eastern Daylight Time". * Defaults to the system's locale if no locale has been specified * @type {string} */ get offsetNameLong() { if (this.isValid) { return this.zone.offsetName(this.ts, { format: "long", locale: this.locale }); } else { return null; } } /** * Get whether this zone's offset ever changes, as in a DST. * @type {boolean} */ get isOffsetFixed() { return this.isValid ? this.zone.isUniversal : null; } /** * Get whether the DateTime is in a DST. * @type {boolean} */ get isInDST() { if (this.isOffsetFixed) { return false; } else { return this.offset > this.set({ month: 1, day: 1 }).offset || this.offset > this.set({ month: 5 }).offset; } } /** * Get those DateTimes which have the same local time as this DateTime, but a different offset from UTC * in this DateTime's zone. During DST changes local time can be ambiguous, for example * `2023-10-29T02:30:00` in `Europe/Berlin` can have offset `+01:00` or `+02:00`. * This method will return both possible DateTimes if this DateTime's local time is ambiguous. * @returns {DateTime[]} */ getPossibleOffsets() { if (!this.isValid || this.isOffsetFixed) { return [this]; } const dayMs = 864e5; const minuteMs = 6e4; const localTS = objToLocalTS(this.c); const oEarlier = this.zone.offset(localTS - dayMs); const oLater = this.zone.offset(localTS + dayMs); const o1 = this.zone.offset(localTS - oEarlier * minuteMs); const o2 = this.zone.offset(localTS - oLater * minuteMs); if (o1 === o2) { return [this]; } const ts1 = localTS - o1 * minuteMs; const ts2 = localTS - o2 * minuteMs; const c1 = tsToObj(ts1, o1); const c2 = tsToObj(ts2, o2); if (c1.hour === c2.hour && c1.minute === c2.minute && c1.second === c2.second && c1.millisecond === c2.millisecond) { return [clone2(this, { ts: ts1 }), clone2(this, { ts: ts2 })]; } return [this]; } /** * Returns true if this DateTime is in a leap year, false otherwise * @example DateTime.local(2016).isInLeapYear //=> true * @example DateTime.local(2013).isInLeapYear //=> false * @type {boolean} */ get isInLeapYear() { return isLeapYear(this.year); } /** * Returns the number of days in this DateTime's month * @example DateTime.local(2016, 2).daysInMonth //=> 29 * @example DateTime.local(2016, 3).daysInMonth //=> 31 * @type {number} */ get daysInMonth() { return daysInMonth(this.year, this.month); } /** * Returns the number of days in this DateTime's year * @example DateTime.local(2016).daysInYear //=> 366 * @example DateTime.local(2013).daysInYear //=> 365 * @type {number} */ get daysInYear() { return this.isValid ? daysInYear(this.year) : NaN; } /** * Returns the number of weeks in this DateTime's year * @see https://en.wikipedia.org/wiki/ISO_week_date * @example DateTime.local(2004).weeksInWeekYear //=> 53 * @example DateTime.local(2013).weeksInWeekYear //=> 52 * @type {number} */ get weeksInWeekYear() { return this.isValid ? weeksInWeekYear(this.weekYear) : NaN; } /** * Returns the resolved Intl options for this DateTime. * This is useful in understanding the behavior of formatting methods * @param {Object} opts - the same options as toLocaleString * @return {Object} */ resolvedLocaleOptions(opts = {}) { const { locale, numberingSystem, calendar } = Formatter.create( this.loc.clone(opts), opts ).resolvedOptions(this); return { locale, numberingSystem, outputCalendar: calendar }; } // TRANSFORM /** * "Set" the DateTime's zone to UTC. Returns a newly-constructed DateTime. * * Equivalent to {@link DateTime#setZone}('utc') * @param {number} [offset=0] - optionally, an offset from UTC in minutes * @param {Object} [opts={}] - options to pass to `setZone()` * @return {DateTime} */ toUTC(offset2 = 0, opts = {}) { return this.setZone(FixedOffsetZone.instance(offset2), opts); } /** * "Set" the DateTime's zone to the host's local zone. Returns a newly-constructed DateTime. * * Equivalent to `setZone('local')` * @return {DateTime} */ toLocal() { return this.setZone(Settings.defaultZone); } /** * "Set" the DateTime's zone to specified zone. Returns a newly-constructed DateTime. * * By default, the setter keeps the underlying time the same (as in, the same timestamp), but the new instance will report different local times and consider DSTs when making computations, as with {@link DateTime#plus}. You may wish to use {@link DateTime#toLocal} and {@link DateTime#toUTC} which provide simple convenience wrappers for commonly used zones. * @param {string|Zone} [zone='local'] - a zone identifier. As a string, that can be any IANA zone supported by the host environment, or a fixed-offset name of the form 'UTC+3', or the strings 'local' or 'utc'. You may also supply an instance of a {@link DateTime#Zone} class. * @param {Object} opts - options * @param {boolean} [opts.keepLocalTime=false] - If true, adjust the underlying time so that the local time stays the same, but in the target zone. You should rarely need this. * @return {DateTime} */ setZone(zone, { keepLocalTime = false, keepCalendarTime = false } = {}) { zone = normalizeZone(zone, Settings.defaultZone); if (zone.equals(this.zone)) { return this; } else if (!zone.isValid) { return DateTime.invalid(unsupportedZone(zone)); } else { let newTS = this.ts; if (keepLocalTime || keepCalendarTime) { const offsetGuess = zone.offset(this.ts); const asObj = this.toObject(); [newTS] = objToTS(asObj, offsetGuess, zone); } return clone2(this, { ts: newTS, zone }); } } /** * "Set" the locale, numberingSystem, or outputCalendar. Returns a newly-constructed DateTime. * @param {Object} properties - the properties to set * @example DateTime.local(2017, 5, 25).reconfigure({ locale: 'en-GB' }) * @return {DateTime} */ reconfigure({ locale, numberingSystem, outputCalendar } = {}) { const loc = this.loc.clone({ locale, numberingSystem, outputCalendar }); return clone2(this, { loc }); } /** * "Set" the locale. Returns a newly-constructed DateTime. * Just a convenient alias for reconfigure({ locale }) * @example DateTime.local(2017, 5, 25).setLocale('en-GB') * @return {DateTime} */ setLocale(locale) { return this.reconfigure({ locale }); } /** * "Set" the values of specified units. Returns a newly-constructed DateTime. * You can only set units with this method; for "setting" metadata, see {@link DateTime#reconfigure} and {@link DateTime#setZone}. * @param {Object} values - a mapping of units to numbers * @example dt.set({ year: 2017 }) * @example dt.set({ hour: 8, minute: 30 }) * @example dt.set({ weekday: 5 }) * @example dt.set({ year: 2005, ordinal: 234 }) * @return {DateTime} */ set(values) { if (!this.isValid) return this; const normalized = normalizeObject(values, normalizeUnit), settingWeekStuff = !isUndefined2(normalized.weekYear) || !isUndefined2(normalized.weekNumber) || !isUndefined2(normalized.weekday), containsOrdinal = !isUndefined2(normalized.ordinal), containsGregorYear = !isUndefined2(normalized.year), containsGregorMD = !isUndefined2(normalized.month) || !isUndefined2(normalized.day), containsGregor = containsGregorYear || containsGregorMD, definiteWeekDef = normalized.weekYear || normalized.weekNumber; if ((containsGregor || containsOrdinal) && definiteWeekDef) { throw new ConflictingSpecificationError( "Can't mix weekYear/weekNumber units with year/month/day or ordinals" ); } if (containsGregorMD && containsOrdinal) { throw new ConflictingSpecificationError("Can't mix ordinal dates with month/day"); } let mixed; if (settingWeekStuff) { mixed = weekToGregorian({ ...gregorianToWeek(this.c), ...normalized }); } else if (!isUndefined2(normalized.ordinal)) { mixed = ordinalToGregorian({ ...gregorianToOrdinal(this.c), ...normalized }); } else { mixed = { ...this.toObject(), ...normalized }; if (isUndefined2(normalized.day)) { mixed.day = Math.min(daysInMonth(mixed.year, mixed.month), mixed.day); } } const [ts, o] = objToTS(mixed, this.o, this.zone); return clone2(this, { ts, o }); } /** * Add a period of time to this DateTime and return the resulting DateTime * * Adding hours, minutes, seconds, or milliseconds increases the timestamp by the right number of milliseconds. Adding days, months, or years shifts the calendar, accounting for DSTs and leap years along the way. Thus, `dt.plus({ hours: 24 })` may result in a different time than `dt.plus({ days: 1 })` if there's a DST shift in between. * @param {Duration|Object|number} duration - The amount to add. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject() * @example DateTime.now().plus(123) //~> in 123 milliseconds * @example DateTime.now().plus({ minutes: 15 }) //~> in 15 minutes * @example DateTime.now().plus({ days: 1 }) //~> this time tomorrow * @example DateTime.now().plus({ days: -1 }) //~> this time yesterday * @example DateTime.now().plus({ hours: 3, minutes: 13 }) //~> in 3 hr, 13 min * @example DateTime.now().plus(Duration.fromObject({ hours: 3, minutes: 13 })) //~> in 3 hr, 13 min * @return {DateTime} */ plus(duration) { if (!this.isValid) return this; const dur = Duration.fromDurationLike(duration); return clone2(this, adjustTime(this, dur)); } /** * Subtract a period of time to this DateTime and return the resulting DateTime * See {@link DateTime#plus} * @param {Duration|Object|number} duration - The amount to subtract. Either a Luxon Duration, a number of milliseconds, the object argument to Duration.fromObject() @return {DateTime} */ minus(duration) { if (!this.isValid) return this; const dur = Duration.fromDurationLike(duration).negate(); return clone2(this, adjustTime(this, dur)); } /** * "Set" this DateTime to the beginning of a unit of time. * @param {string} unit - The unit to go to the beginning of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'. * @example DateTime.local(2014, 3, 3).startOf('month').toISODate(); //=> '2014-03-01' * @example DateTime.local(2014, 3, 3).startOf('year').toISODate(); //=> '2014-01-01' * @example DateTime.local(2014, 3, 3).startOf('week').toISODate(); //=> '2014-03-03', weeks always start on Mondays * @example DateTime.local(2014, 3, 3, 5, 30).startOf('day').toISOTime(); //=> '00:00.000-05:00' * @example DateTime.local(2014, 3, 3, 5, 30).startOf('hour').toISOTime(); //=> '05:00:00.000-05:00' * @return {DateTime} */ startOf(unit) { if (!this.isValid) return this; const o = {}, normalizedUnit = Duration.normalizeUnit(unit); switch (normalizedUnit) { case "years": o.month = 1; case "quarters": case "months": o.day = 1; case "weeks": case "days": o.hour = 0; case "hours": o.minute = 0; case "minutes": o.second = 0; case "seconds": o.millisecond = 0; break; } if (normalizedUnit === "weeks") { o.weekday = 1; } if (normalizedUnit === "quarters") { const q = Math.ceil(this.month / 3); o.month = (q - 1) * 3 + 1; } return this.set(o); } /** * "Set" this DateTime to the end (meaning the last millisecond) of a unit of time * @param {string} unit - The unit to go to the end of. Can be 'year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', 'second', or 'millisecond'. * @example DateTime.local(2014, 3, 3).endOf('month').toISO(); //=> '2014-03-31T23:59:59.999-05:00' * @example DateTime.local(2014, 3, 3).endOf('year').toISO(); //=> '2014-12-31T23:59:59.999-05:00' * @example DateTime.local(2014, 3, 3).endOf('week').toISO(); // => '2014-03-09T23:59:59.999-05:00', weeks start on Mondays * @example DateTime.local(2014, 3, 3, 5, 30).endOf('day').toISO(); //=> '2014-03-03T23:59:59.999-05:00' * @example DateTime.local(2014, 3, 3, 5, 30).endOf('hour').toISO(); //=> '2014-03-03T05:59:59.999-05:00' * @return {DateTime} */ endOf(unit) { return this.isValid ? this.plus({ [unit]: 1 }).startOf(unit).minus(1) : this; } // OUTPUT /** * Returns a string representation of this DateTime formatted according to the specified format string. * **You may not want this.** See {@link DateTime#toLocaleString} for a more flexible formatting tool. For a table of tokens and their interpretations, see [here](https://moment.github.io/luxon/#/formatting?id=table-of-tokens). * Defaults to en-US if no locale has been specified, regardless of the system's locale. * @param {string} fmt - the format string * @param {Object} opts - opts to override the configuration options on this DateTime * @example DateTime.now().toFormat('yyyy LLL dd') //=> '2017 Apr 22' * @example DateTime.now().setLocale('fr').toFormat('yyyy LLL dd') //=> '2017 avr. 22' * @example DateTime.now().toFormat('yyyy LLL dd', { locale: "fr" }) //=> '2017 avr. 22' * @example DateTime.now().toFormat("HH 'hours and' mm 'minutes'") //=> '20 hours and 55 minutes' * @return {string} */ toFormat(fmt, opts = {}) { return this.isValid ? Formatter.create(this.loc.redefaultToEN(opts)).formatDateTimeFromString(this, fmt) : INVALID2; } /** * Returns a localized string representing this date. Accepts the same options as the Intl.DateTimeFormat constructor and any presets defined by Luxon, such as `DateTime.DATE_FULL` or `DateTime.TIME_SIMPLE`. * The exact behavior of this method is browser-specific, but in general it will return an appropriate representation * of the DateTime in the assigned locale. * Defaults to the system's locale if no locale has been specified * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat * @param formatOpts {Object} - Intl.DateTimeFormat constructor options and configuration options * @param {Object} opts - opts to override the configuration options on this DateTime * @example DateTime.now().toLocaleString(); //=> 4/20/2017 * @example DateTime.now().setLocale('en-gb').toLocaleString(); //=> '20/04/2017' * @example DateTime.now().toLocaleString(DateTime.DATE_FULL); //=> 'April 20, 2017' * @example DateTime.now().toLocaleString(DateTime.DATE_FULL, { locale: 'fr' }); //=> '28 août 2022' * @example DateTime.now().toLocaleString(DateTime.TIME_SIMPLE); //=> '11:32 AM' * @example DateTime.now().toLocaleString(DateTime.DATETIME_SHORT); //=> '4/20/2017, 11:32 AM' * @example DateTime.now().toLocaleString({ weekday: 'long', month: 'long', day: '2-digit' }); //=> 'Thursday, April 20' * @example DateTime.now().toLocaleString({ weekday: 'short', month: 'short', day: '2-digit', hour: '2-digit', minute: '2-digit' }); //=> 'Thu, Apr 20, 11:27 AM' * @example DateTime.now().toLocaleString({ hour: '2-digit', minute: '2-digit', hourCycle: 'h23' }); //=> '11:32' * @return {string} */ toLocaleString(formatOpts = DATE_SHORT, opts = {}) { return this.isValid ? Formatter.create(this.loc.clone(opts), formatOpts).formatDateTime(this) : INVALID2; } /** * Returns an array of format "parts", meaning individual tokens along with metadata. This is allows callers to post-process individual sections of the formatted output. * Defaults to the system's locale if no locale has been specified * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat/formatToParts * @param opts {Object} - Intl.DateTimeFormat constructor options, same as `toLocaleString`. * @example DateTime.now().toLocaleParts(); //=> [ * //=> { type: 'day', value: '25' }, * //=> { type: 'literal', value: '/' }, * //=> { type: 'month', value: '05' }, * //=> { type: 'literal', value: '/' }, * //=> { type: 'year', value: '1982' } * //=> ] */ toLocaleParts(opts = {}) { return this.isValid ? Formatter.create(this.loc.clone(opts), opts).formatDateTimeParts(this) : []; } /** * Returns an ISO 8601-compliant string representation of this DateTime * @param {Object} opts - options * @param {boolean} [opts.suppressMilliseconds=false] - exclude milliseconds from the format if they're 0 * @param {boolean} [opts.suppressSeconds=false] - exclude seconds from the format if they're 0 * @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00' * @param {boolean} [opts.extendedZone=false] - add the time zone format extension * @param {string} [opts.format='extended'] - choose between the basic and extended format * @example DateTime.utc(1983, 5, 25).toISO() //=> '1982-05-25T00:00:00.000Z' * @example DateTime.now().toISO() //=> '2017-04-22T20:47:05.335-04:00' * @example DateTime.now().toISO({ includeOffset: false }) //=> '2017-04-22T20:47:05.335' * @example DateTime.now().toISO({ format: 'basic' }) //=> '20170422T204705.335-0400' * @return {string} */ toISO({ format: format2 = "extended", suppressSeconds = false, suppressMilliseconds = false, includeOffset = true, extendedZone = false } = {}) { if (!this.isValid) { return null; } const ext = format2 === "extended"; let c2 = toISODate(this, ext); c2 += "T"; c2 += toISOTime(this, ext, suppressSeconds, suppressMilliseconds, includeOffset, extendedZone); return c2; } /** * Returns an ISO 8601-compliant string representation of this DateTime's date component * @param {Object} opts - options * @param {string} [opts.format='extended'] - choose between the basic and extended format * @example DateTime.utc(1982, 5, 25).toISODate() //=> '1982-05-25' * @example DateTime.utc(1982, 5, 25).toISODate({ format: 'basic' }) //=> '19820525' * @return {string} */ toISODate({ format: format2 = "extended" } = {}) { if (!this.isValid) { return null; } return toISODate(this, format2 === "extended"); } /** * Returns an ISO 8601-compliant string representation of this DateTime's week date * @example DateTime.utc(1982, 5, 25).toISOWeekDate() //=> '1982-W21-2' * @return {string} */ toISOWeekDate() { return toTechFormat(this, "kkkk-'W'WW-c"); } /** * Returns an ISO 8601-compliant string representation of this DateTime's time component * @param {Object} opts - options * @param {boolean} [opts.suppressMilliseconds=false] - exclude milliseconds from the format if they're 0 * @param {boolean} [opts.suppressSeconds=false] - exclude seconds from the format if they're 0 * @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00' * @param {boolean} [opts.extendedZone=true] - add the time zone format extension * @param {boolean} [opts.includePrefix=false] - include the `T` prefix * @param {string} [opts.format='extended'] - choose between the basic and extended format * @example DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime() //=> '07:34:19.361Z' * @example DateTime.utc().set({ hour: 7, minute: 34, seconds: 0, milliseconds: 0 }).toISOTime({ suppressSeconds: true }) //=> '07:34Z' * @example DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime({ format: 'basic' }) //=> '073419.361Z' * @example DateTime.utc().set({ hour: 7, minute: 34 }).toISOTime({ includePrefix: true }) //=> 'T07:34:19.361Z' * @return {string} */ toISOTime({ suppressMilliseconds = false, suppressSeconds = false, includeOffset = true, includePrefix = false, extendedZone = false, format: format2 = "extended" } = {}) { if (!this.isValid) { return null; } let c2 = includePrefix ? "T" : ""; return c2 + toISOTime( this, format2 === "extended", suppressSeconds, suppressMilliseconds, includeOffset, extendedZone ); } /** * Returns an RFC 2822-compatible string representation of this DateTime * @example DateTime.utc(2014, 7, 13).toRFC2822() //=> 'Sun, 13 Jul 2014 00:00:00 +0000' * @example DateTime.local(2014, 7, 13).toRFC2822() //=> 'Sun, 13 Jul 2014 00:00:00 -0400' * @return {string} */ toRFC2822() { return toTechFormat(this, "EEE, dd LLL yyyy HH:mm:ss ZZZ", false); } /** * Returns a string representation of this DateTime appropriate for use in HTTP headers. The output is always expressed in GMT. * Specifically, the string conforms to RFC 1123. * @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1 * @example DateTime.utc(2014, 7, 13).toHTTP() //=> 'Sun, 13 Jul 2014 00:00:00 GMT' * @example DateTime.utc(2014, 7, 13, 19).toHTTP() //=> 'Sun, 13 Jul 2014 19:00:00 GMT' * @return {string} */ toHTTP() { return toTechFormat(this.toUTC(), "EEE, dd LLL yyyy HH:mm:ss 'GMT'"); } /** * Returns a string representation of this DateTime appropriate for use in SQL Date * @example DateTime.utc(2014, 7, 13).toSQLDate() //=> '2014-07-13' * @return {string} */ toSQLDate() { if (!this.isValid) { return null; } return toISODate(this, true); } /** * Returns a string representation of this DateTime appropriate for use in SQL Time * @param {Object} opts - options * @param {boolean} [opts.includeZone=false] - include the zone, such as 'America/New_York'. Overrides includeOffset. * @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00' * @param {boolean} [opts.includeOffsetSpace=true] - include the space between the time and the offset, such as '05:15:16.345 -04:00' * @example DateTime.utc().toSQL() //=> '05:15:16.345' * @example DateTime.now().toSQL() //=> '05:15:16.345 -04:00' * @example DateTime.now().toSQL({ includeOffset: false }) //=> '05:15:16.345' * @example DateTime.now().toSQL({ includeZone: false }) //=> '05:15:16.345 America/New_York' * @return {string} */ toSQLTime({ includeOffset = true, includeZone = false, includeOffsetSpace = true } = {}) { let fmt = "HH:mm:ss.SSS"; if (includeZone || includeOffset) { if (includeOffsetSpace) { fmt += " "; } if (includeZone) { fmt += "z"; } else if (includeOffset) { fmt += "ZZ"; } } return toTechFormat(this, fmt, true); } /** * Returns a string representation of this DateTime appropriate for use in SQL DateTime * @param {Object} opts - options * @param {boolean} [opts.includeZone=false] - include the zone, such as 'America/New_York'. Overrides includeOffset. * @param {boolean} [opts.includeOffset=true] - include the offset, such as 'Z' or '-04:00' * @param {boolean} [opts.includeOffsetSpace=true] - include the space between the time and the offset, such as '05:15:16.345 -04:00' * @example DateTime.utc(2014, 7, 13).toSQL() //=> '2014-07-13 00:00:00.000 Z' * @example DateTime.local(2014, 7, 13).toSQL() //=> '2014-07-13 00:00:00.000 -04:00' * @example DateTime.local(2014, 7, 13).toSQL({ includeOffset: false }) //=> '2014-07-13 00:00:00.000' * @example DateTime.local(2014, 7, 13).toSQL({ includeZone: true }) //=> '2014-07-13 00:00:00.000 America/New_York' * @return {string} */ toSQL(opts = {}) { if (!this.isValid) { return null; } return `${this.toSQLDate()} ${this.toSQLTime(opts)}`; } /** * Returns a string representation of this DateTime appropriate for debugging * @return {string} */ toString() { return this.isValid ? this.toISO() : INVALID2; } /** * Returns the epoch milliseconds of this DateTime. Alias of {@link DateTime#toMillis} * @return {number} */ valueOf() { return this.toMillis(); } /** * Returns the epoch milliseconds of this DateTime. * @return {number} */ toMillis() { return this.isValid ? this.ts : NaN; } /** * Returns the epoch seconds of this DateTime. * @return {number} */ toSeconds() { return this.isValid ? this.ts / 1e3 : NaN; } /** * Returns the epoch seconds (as a whole number) of this DateTime. * @return {number} */ toUnixInteger() { return this.isValid ? Math.floor(this.ts / 1e3) : NaN; } /** * Returns an ISO 8601 representation of this DateTime appropriate for use in JSON. * @return {string} */ toJSON() { return this.toISO(); } /** * Returns a BSON serializable equivalent to this DateTime. * @return {Date} */ toBSON() { return this.toJSDate(); } /** * Returns a JavaScript object with this DateTime's year, month, day, and so on. * @param opts - options for generating the object * @param {boolean} [opts.includeConfig=false] - include configuration attributes in the output * @example DateTime.now().toObject() //=> { year: 2017, month: 4, day: 22, hour: 20, minute: 49, second: 42, millisecond: 268 } * @return {Object} */ toObject(opts = {}) { if (!this.isValid) return {}; const base = { ...this.c }; if (opts.includeConfig) { base.outputCalendar = this.outputCalendar; base.numberingSystem = this.loc.numberingSystem; base.locale = this.loc.locale; } return base; } /** * Returns a JavaScript Date equivalent to this DateTime. * @return {Date} */ toJSDate() { return new Date(this.isValid ? this.ts : NaN); } // COMPARE /** * Return the difference between two DateTimes as a Duration. * @param {DateTime} otherDateTime - the DateTime to compare this one to * @param {string|string[]} [unit=['milliseconds']] - the unit or array of units (such as 'hours' or 'days') to include in the duration. * @param {Object} opts - options that affect the creation of the Duration * @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use * @example * var i1 = DateTime.fromISO('1982-05-25T09:45'), * i2 = DateTime.fromISO('1983-10-14T10:30'); * i2.diff(i1).toObject() //=> { milliseconds: 43807500000 } * i2.diff(i1, 'hours').toObject() //=> { hours: 12168.75 } * i2.diff(i1, ['months', 'days']).toObject() //=> { months: 16, days: 19.03125 } * i2.diff(i1, ['months', 'days', 'hours']).toObject() //=> { months: 16, days: 19, hours: 0.75 } * @return {Duration} */ diff(otherDateTime, unit = "milliseconds", opts = {}) { if (!this.isValid || !otherDateTime.isValid) { return Duration.invalid("created by diffing an invalid DateTime"); } const durOpts = { locale: this.locale, numberingSystem: this.numberingSystem, ...opts }; const units = maybeArray(unit).map(Duration.normalizeUnit), otherIsLater = otherDateTime.valueOf() > this.valueOf(), earlier = otherIsLater ? this : otherDateTime, later = otherIsLater ? otherDateTime : this, diffed = diff(earlier, later, units, durOpts); return otherIsLater ? diffed.negate() : diffed; } /** * Return the difference between this DateTime and right now. * See {@link DateTime#diff} * @param {string|string[]} [unit=['milliseconds']] - the unit or units units (such as 'hours' or 'days') to include in the duration * @param {Object} opts - options that affect the creation of the Duration * @param {string} [opts.conversionAccuracy='casual'] - the conversion system to use * @return {Duration} */ diffNow(unit = "milliseconds", opts = {}) { return this.diff(DateTime.now(), unit, opts); } /** * Return an Interval spanning between this DateTime and another DateTime * @param {DateTime} otherDateTime - the other end point of the Interval * @return {Interval} */ until(otherDateTime) { return this.isValid ? Interval.fromDateTimes(this, otherDateTime) : this; } /** * Return whether this DateTime is in the same unit of time as another DateTime. * Higher-order units must also be identical for this function to return `true`. * Note that time zones are **ignored** in this comparison, which compares the **local** calendar time. Use {@link DateTime#setZone} to convert one of the dates if needed. * @param {DateTime} otherDateTime - the other DateTime * @param {string} unit - the unit of time to check sameness on * @example DateTime.now().hasSame(otherDT, 'day'); //~> true if otherDT is in the same current calendar day * @return {boolean} */ hasSame(otherDateTime, unit) { if (!this.isValid) return false; const inputMs = otherDateTime.valueOf(); const adjustedToZone = this.setZone(otherDateTime.zone, { keepLocalTime: true }); return adjustedToZone.startOf(unit) <= inputMs && inputMs <= adjustedToZone.endOf(unit); } /** * Equality check * Two DateTimes are equal if and only if they represent the same millisecond, have the same zone and location, and are both valid. * To compare just the millisecond values, use `+dt1 === +dt2`. * @param {DateTime} other - the other DateTime * @return {boolean} */ equals(other) { return this.isValid && other.isValid && this.valueOf() === other.valueOf() && this.zone.equals(other.zone) && this.loc.equals(other.loc); } /** * Returns a string representation of a this time relative to now, such as "in two days". Can only internationalize if your * platform supports Intl.RelativeTimeFormat. Rounds down by default. * @param {Object} options - options that affect the output * @param {DateTime} [options.base=DateTime.now()] - the DateTime to use as the basis to which this time is compared. Defaults to now. * @param {string} [options.style="long"] - the style of units, must be "long", "short", or "narrow" * @param {string|string[]} options.unit - use a specific unit or array of units; if omitted, or an array, the method will pick the best unit. Use an array or one of "years", "quarters", "months", "weeks", "days", "hours", "minutes", or "seconds" * @param {boolean} [options.round=true] - whether to round the numbers in the output. * @param {number} [options.padding=0] - padding in milliseconds. This allows you to round up the result if it fits inside the threshold. Don't use in combination with {round: false} because the decimal output will include the padding. * @param {string} options.locale - override the locale of this DateTime * @param {string} options.numberingSystem - override the numberingSystem of this DateTime. The Intl system may choose not to honor this * @example DateTime.now().plus({ days: 1 }).toRelative() //=> "in 1 day" * @example DateTime.now().setLocale("es").toRelative({ days: 1 }) //=> "dentro de 1 día" * @example DateTime.now().plus({ days: 1 }).toRelative({ locale: "fr" }) //=> "dans 23 heures" * @example DateTime.now().minus({ days: 2 }).toRelative() //=> "2 days ago" * @example DateTime.now().minus({ days: 2 }).toRelative({ unit: "hours" }) //=> "48 hours ago" * @example DateTime.now().minus({ hours: 36 }).toRelative({ round: false }) //=> "1.5 days ago" */ toRelative(options = {}) { if (!this.isValid) return null; const base = options.base || DateTime.fromObject({}, { zone: this.zone }), padding = options.padding ? this < base ? -options.padding : options.padding : 0; let units = ["years", "months", "days", "hours", "minutes", "seconds"]; let unit = options.unit; if (Array.isArray(options.unit)) { units = options.unit; unit = void 0; } return diffRelative(base, this.plus(padding), { ...options, numeric: "always", units, unit }); } /** * Returns a string representation of this date relative to today, such as "yesterday" or "next month". * Only internationalizes on platforms that supports Intl.RelativeTimeFormat. * @param {Object} options - options that affect the output * @param {DateTime} [options.base=DateTime.now()] - the DateTime to use as the basis to which this time is compared. Defaults to now. * @param {string} options.locale - override the locale of this DateTime * @param {string} options.unit - use a specific unit; if omitted, the method will pick the unit. Use one of "years", "quarters", "months", "weeks", or "days" * @param {string} options.numberingSystem - override the numberingSystem of this DateTime. The Intl system may choose not to honor this * @example DateTime.now().plus({ days: 1 }).toRelativeCalendar() //=> "tomorrow" * @example DateTime.now().setLocale("es").plus({ days: 1 }).toRelative() //=> ""mañana" * @example DateTime.now().plus({ days: 1 }).toRelativeCalendar({ locale: "fr" }) //=> "demain" * @example DateTime.now().minus({ days: 2 }).toRelativeCalendar() //=> "2 days ago" */ toRelativeCalendar(options = {}) { if (!this.isValid) return null; return diffRelative(options.base || DateTime.fromObject({}, { zone: this.zone }), this, { ...options, numeric: "auto", units: ["years", "months", "days"], calendary: true }); } /** * Return the min of several date times * @param {...DateTime} dateTimes - the DateTimes from which to choose the minimum * @return {DateTime} the min DateTime, or undefined if called with no argument */ static min(...dateTimes) { if (!dateTimes.every(DateTime.isDateTime)) { throw new InvalidArgumentError("min requires all arguments be DateTimes"); } return bestBy(dateTimes, (i) => i.valueOf(), Math.min); } /** * Return the max of several date times * @param {...DateTime} dateTimes - the DateTimes from which to choose the maximum * @return {DateTime} the max DateTime, or undefined if called with no argument */ static max(...dateTimes) { if (!dateTimes.every(DateTime.isDateTime)) { throw new InvalidArgumentError("max requires all arguments be DateTimes"); } return bestBy(dateTimes, (i) => i.valueOf(), Math.max); } // MISC /** * Explain how a string would be parsed by fromFormat() * @param {string} text - the string to parse * @param {string} fmt - the format the string is expected to be in (see description) * @param {Object} options - options taken by fromFormat() * @return {Object} */ static fromFormatExplain(text, fmt, options = {}) { const { locale = null, numberingSystem = null } = options, localeToUse = Locale.fromOpts({ locale, numberingSystem, defaultToEN: true }); return explainFromTokens(localeToUse, text, fmt); } /** * @deprecated use fromFormatExplain instead */ static fromStringExplain(text, fmt, options = {}) { return DateTime.fromFormatExplain(text, fmt, options); } // FORMAT PRESETS /** * {@link DateTime#toLocaleString} format like 10/14/1983 * @type {Object} */ static get DATE_SHORT() { return DATE_SHORT; } /** * {@link DateTime#toLocaleString} format like 'Oct 14, 1983' * @type {Object} */ static get DATE_MED() { return DATE_MED; } /** * {@link DateTime#toLocaleString} format like 'Fri, Oct 14, 1983' * @type {Object} */ static get DATE_MED_WITH_WEEKDAY() { return DATE_MED_WITH_WEEKDAY; } /** * {@link DateTime#toLocaleString} format like 'October 14, 1983' * @type {Object} */ static get DATE_FULL() { return DATE_FULL; } /** * {@link DateTime#toLocaleString} format like 'Tuesday, October 14, 1983' * @type {Object} */ static get DATE_HUGE() { return DATE_HUGE; } /** * {@link DateTime#toLocaleString} format like '09:30 AM'. Only 12-hour if the locale is. * @type {Object} */ static get TIME_SIMPLE() { return TIME_SIMPLE; } /** * {@link DateTime#toLocaleString} format like '09:30:23 AM'. Only 12-hour if the locale is. * @type {Object} */ static get TIME_WITH_SECONDS() { return TIME_WITH_SECONDS; } /** * {@link DateTime#toLocaleString} format like '09:30:23 AM EDT'. Only 12-hour if the locale is. * @type {Object} */ static get TIME_WITH_SHORT_OFFSET() { return TIME_WITH_SHORT_OFFSET; } /** * {@link DateTime#toLocaleString} format like '09:30:23 AM Eastern Daylight Time'. Only 12-hour if the locale is. * @type {Object} */ static get TIME_WITH_LONG_OFFSET() { return TIME_WITH_LONG_OFFSET; } /** * {@link DateTime#toLocaleString} format like '09:30', always 24-hour. * @type {Object} */ static get TIME_24_SIMPLE() { return TIME_24_SIMPLE; } /** * {@link DateTime#toLocaleString} format like '09:30:23', always 24-hour. * @type {Object} */ static get TIME_24_WITH_SECONDS() { return TIME_24_WITH_SECONDS; } /** * {@link DateTime#toLocaleString} format like '09:30:23 EDT', always 24-hour. * @type {Object} */ static get TIME_24_WITH_SHORT_OFFSET() { return TIME_24_WITH_SHORT_OFFSET; } /** * {@link DateTime#toLocaleString} format like '09:30:23 Eastern Daylight Time', always 24-hour. * @type {Object} */ static get TIME_24_WITH_LONG_OFFSET() { return TIME_24_WITH_LONG_OFFSET; } /** * {@link DateTime#toLocaleString} format like '10/14/1983, 9:30 AM'. Only 12-hour if the locale is. * @type {Object} */ static get DATETIME_SHORT() { return DATETIME_SHORT; } /** * {@link DateTime#toLocaleString} format like '10/14/1983, 9:30:33 AM'. Only 12-hour if the locale is. * @type {Object} */ static get DATETIME_SHORT_WITH_SECONDS() { return DATETIME_SHORT_WITH_SECONDS; } /** * {@link DateTime#toLocaleString} format like 'Oct 14, 1983, 9:30 AM'. Only 12-hour if the locale is. * @type {Object} */ static get DATETIME_MED() { return DATETIME_MED; } /** * {@link DateTime#toLocaleString} format like 'Oct 14, 1983, 9:30:33 AM'. Only 12-hour if the locale is. * @type {Object} */ static get DATETIME_MED_WITH_SECONDS() { return DATETIME_MED_WITH_SECONDS; } /** * {@link DateTime#toLocaleString} format like 'Fri, 14 Oct 1983, 9:30 AM'. Only 12-hour if the locale is. * @type {Object} */ static get DATETIME_MED_WITH_WEEKDAY() { return DATETIME_MED_WITH_WEEKDAY; } /** * {@link DateTime#toLocaleString} format like 'October 14, 1983, 9:30 AM EDT'. Only 12-hour if the locale is. * @type {Object} */ static get DATETIME_FULL() { return DATETIME_FULL; } /** * {@link DateTime#toLocaleString} format like 'October 14, 1983, 9:30:33 AM EDT'. Only 12-hour if the locale is. * @type {Object} */ static get DATETIME_FULL_WITH_SECONDS() { return DATETIME_FULL_WITH_SECONDS; } /** * {@link DateTime#toLocaleString} format like 'Friday, October 14, 1983, 9:30 AM Eastern Daylight Time'. Only 12-hour if the locale is. * @type {Object} */ static get DATETIME_HUGE() { return DATETIME_HUGE; } /** * {@link DateTime#toLocaleString} format like 'Friday, October 14, 1983, 9:30:33 AM Eastern Daylight Time'. Only 12-hour if the locale is. * @type {Object} */ static get DATETIME_HUGE_WITH_SECONDS() { return DATETIME_HUGE_WITH_SECONDS; } }; function friendlyDateTime(dateTimeish) { if (DateTime.isDateTime(dateTimeish)) { return dateTimeish; } else if (dateTimeish && dateTimeish.valueOf && isNumber(dateTimeish.valueOf())) { return DateTime.fromJSDate(dateTimeish); } else if (dateTimeish && typeof dateTimeish === "object") { return DateTime.fromObject(dateTimeish); } else { throw new InvalidArgumentError( `Unknown datetime argument: ${dateTimeish}, of type ${typeof dateTimeish}` ); } } var DEFAULT_QUERY_SETTINGS = { renderNullAs: "\\-", taskCompletionTracking: false, taskCompletionUseEmojiShorthand: false, taskCompletionText: "completion", taskCompletionDateFormat: "yyyy-MM-dd", recursiveSubTaskCompletion: false, warnOnEmptyResult: true, refreshEnabled: true, refreshInterval: 2500, defaultDateFormat: "MMMM dd, yyyy", defaultDateTimeFormat: "h:mm a - MMMM dd, yyyy", maxRecursiveRenderDepth: 4, tableIdColumnName: "File", tableGroupColumnName: "Group", showResultCount: true }; var DEFAULT_EXPORT_SETTINGS = { allowHtml: true }; ({ ...DEFAULT_QUERY_SETTINGS, ...DEFAULT_EXPORT_SETTINGS, ...{ inlineQueryPrefix: "=", inlineJsQueryPrefix: "$=", inlineQueriesInCodeblocks: true, enableInlineDataview: true, enableDataviewJs: false, enableInlineDataviewJs: false, prettyRenderInlineFields: true, prettyRenderInlineFieldsInLivePreview: true, dataviewJsKeyword: "dataviewjs" } }); var Success = class { constructor(value) { this.value = value; this.successful = true; } map(f) { return new Success(f(this.value)); } flatMap(f) { return f(this.value); } mapErr(f) { return this; } bimap(succ, _fail) { return this.map(succ); } orElse(_value) { return this.value; } cast() { return this; } orElseThrow(_message) { return this.value; } }; var Failure = class { constructor(error) { this.error = error; this.successful = false; } map(_f) { return this; } flatMap(_f) { return this; } mapErr(f) { return new Failure(f(this.error)); } bimap(_succ, fail) { return this.mapErr(fail); } orElse(value) { return value; } cast() { return this; } orElseThrow(message) { if (message) throw new Error(message(this.error)); else throw new Error("" + this.error); } }; var Result; (function(Result2) { function success(value) { return new Success(value); } Result2.success = success; function failure(error) { return new Failure(error); } Result2.failure = failure; function flatMap2(first, second, f) { if (first.successful) { if (second.successful) return f(first.value, second.value); else return failure(second.error); } else { return failure(first.error); } } Result2.flatMap2 = flatMap2; function map2(first, second, f) { return flatMap2(first, second, (a2, b) => success(f(a2, b))); } Result2.map2 = map2; })(Result || (Result = {})); var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {}; var parsimmon_umd_min = { exports: {} }; parsimmon_umd_min.exports; (function(module3, exports2) { !function(n2, t) { module3.exports = t(); }("undefined" != typeof self ? self : commonjsGlobal, function() { return function(n2) { var t = {}; function r(e) { if (t[e]) return t[e].exports; var u = t[e] = { i: e, l: false, exports: {} }; return n2[e].call(u.exports, u, u.exports, r), u.l = true, u.exports; } return r.m = n2, r.c = t, r.d = function(n3, t2, e) { r.o(n3, t2) || Object.defineProperty(n3, t2, { configurable: false, enumerable: true, get: e }); }, r.r = function(n3) { Object.defineProperty(n3, "__esModule", { value: true }); }, r.n = function(n3) { var t2 = n3 && n3.__esModule ? function() { return n3.default; } : function() { return n3; }; return r.d(t2, "a", t2), t2; }, r.o = function(n3, t2) { return Object.prototype.hasOwnProperty.call(n3, t2); }, r.p = "", r(r.s = 0); }([function(n2, t, r) { function e(n3) { if (!(this instanceof e)) return new e(n3); this._ = n3; } var u = e.prototype; function o(n3, t2) { for (var r2 = 0; r2 < n3; r2++) t2(r2); } function i(n3, t2, r2) { return function(n4, t3) { o(t3.length, function(r3) { n4(t3[r3], r3, t3); }); }(function(r3, e2, u2) { t2 = n3(t2, r3, e2, u2); }, r2), t2; } function a2(n3, t2) { return i(function(t3, r2, e2, u2) { return t3.concat([n3(r2, e2, u2)]); }, [], t2); } function f(n3, t2) { var r2 = { v: 0, buf: t2 }; return o(n3, function() { var n4; r2 = { v: r2.v << 1 | (n4 = r2.buf, n4[0] >> 7), buf: function(n5) { var t3 = i(function(n6, t4, r3, e2) { return n6.concat(r3 === e2.length - 1 ? Buffer.from([t4, 0]).readUInt16BE(0) : e2.readUInt16BE(r3)); }, [], n5); return Buffer.from(a2(function(n6) { return (n6 << 1 & 65535) >> 8; }, t3)); }(r2.buf) }; }), r2; } function c2() { return "undefined" != typeof Buffer; } function s2() { if (!c2()) throw new Error("Buffer global does not exist; please use webpack if you need to parse Buffers in the browser."); } function l2(n3) { s2(); var t2 = i(function(n4, t3) { return n4 + t3; }, 0, n3); if (t2 % 8 != 0) throw new Error("The bits [" + n3.join(", ") + "] add up to " + t2 + " which is not an even number of bytes; the total should be divisible by 8"); var r2, u2 = t2 / 8, o2 = (r2 = function(n4) { return n4 > 48; }, i(function(n4, t3) { return n4 || (r2(t3) ? t3 : n4); }, null, n3)); if (o2) throw new Error(o2 + " bit range requested exceeds 48 bit (6 byte) Number max."); return new e(function(t3, r3) { var e2 = u2 + r3; return e2 > t3.length ? x3(r3, u2.toString() + " bytes") : b(e2, i(function(n4, t4) { var r4 = f(t4, n4.buf); return { coll: n4.coll.concat(r4.v), buf: r4.buf }; }, { coll: [], buf: t3.slice(r3, e2) }, n3).coll); }); } function h(n3, t2) { return new e(function(r2, e2) { return s2(), e2 + t2 > r2.length ? x3(e2, t2 + " bytes for " + n3) : b(e2 + t2, r2.slice(e2, e2 + t2)); }); } function p(n3, t2) { if ("number" != typeof (r2 = t2) || Math.floor(r2) !== r2 || t2 < 0 || t2 > 6) throw new Error(n3 + " requires integer length in range [0, 6]."); var r2; } function d(n3) { return p("uintBE", n3), h("uintBE(" + n3 + ")", n3).map(function(t2) { return t2.readUIntBE(0, n3); }); } function v(n3) { return p("uintLE", n3), h("uintLE(" + n3 + ")", n3).map(function(t2) { return t2.readUIntLE(0, n3); }); } function g(n3) { return p("intBE", n3), h("intBE(" + n3 + ")", n3).map(function(t2) { return t2.readIntBE(0, n3); }); } function m2(n3) { return p("intLE", n3), h("intLE(" + n3 + ")", n3).map(function(t2) { return t2.readIntLE(0, n3); }); } function y3(n3) { return n3 instanceof e; } function E(n3) { return "[object Array]" === {}.toString.call(n3); } function w(n3) { return c2() && Buffer.isBuffer(n3); } function b(n3, t2) { return { status: true, index: n3, value: t2, furthest: -1, expected: [] }; } function x3(n3, t2) { return E(t2) || (t2 = [t2]), { status: false, index: -1, value: null, furthest: n3, expected: t2 }; } function B(n3, t2) { if (!t2) return n3; if (n3.furthest > t2.furthest) return n3; var r2 = n3.furthest === t2.furthest ? function(n4, t3) { if (function() { if (void 0 !== e._supportsSet) return e._supportsSet; var n5 = "undefined" != typeof Set; return e._supportsSet = n5, n5; }() && Array.from) { for (var r3 = new Set(n4), u2 = 0; u2 < t3.length; u2++) r3.add(t3[u2]); var o2 = Array.from(r3); return o2.sort(), o2; } for (var i2 = {}, a3 = 0; a3 < n4.length; a3++) i2[n4[a3]] = true; for (var f2 = 0; f2 < t3.length; f2++) i2[t3[f2]] = true; var c3 = []; for (var s3 in i2) ({}).hasOwnProperty.call(i2, s3) && c3.push(s3); return c3.sort(), c3; }(n3.expected, t2.expected) : t2.expected; return { status: n3.status, index: n3.index, value: n3.value, furthest: t2.furthest, expected: r2 }; } var j = {}; function S(n3, t2) { if (w(n3)) return { offset: t2, line: -1, column: -1 }; n3 in j || (j[n3] = {}); for (var r2 = j[n3], e2 = 0, u2 = 0, o2 = 0, i2 = t2; i2 >= 0; ) { if (i2 in r2) { e2 = r2[i2].line, 0 === o2 && (o2 = r2[i2].lineStart); break; } ("\n" === n3.charAt(i2) || "\r" === n3.charAt(i2) && "\n" !== n3.charAt(i2 + 1)) && (u2++, 0 === o2 && (o2 = i2 + 1)), i2--; } var a3 = e2 + u2, f2 = t2 - o2; return r2[t2] = { line: a3, lineStart: o2 }, { offset: t2, line: a3 + 1, column: f2 + 1 }; } function _(n3) { if (!y3(n3)) throw new Error("not a parser: " + n3); } function L(n3, t2) { return "string" == typeof n3 ? n3.charAt(t2) : n3[t2]; } function O(n3) { if ("number" != typeof n3) throw new Error("not a number: " + n3); } function k(n3) { if ("function" != typeof n3) throw new Error("not a function: " + n3); } function P(n3) { if ("string" != typeof n3) throw new Error("not a string: " + n3); } var q = 2, A = 3, I = 8, F = 5 * I, M = 4 * I, z4 = " "; function R(n3, t2) { return new Array(t2 + 1).join(n3); } function U(n3, t2, r2) { var e2 = t2 - n3.length; return e2 <= 0 ? n3 : R(r2, e2) + n3; } function W(n3, t2, r2, e2) { return { from: n3 - t2 > 0 ? n3 - t2 : 0, to: n3 + r2 > e2 ? e2 : n3 + r2 }; } function D(n3, t2) { var r2, e2, u2, o2, f2, c3 = t2.index, s3 = c3.offset, l3 = 1; if (s3 === n3.length) return "Got the end of the input"; if (w(n3)) { var h2 = s3 - s3 % I, p2 = s3 - h2, d2 = W(h2, F, M + I, n3.length), v2 = a2(function(n4) { return a2(function(n5) { return U(n5.toString(16), 2, "0"); }, n4); }, function(n4, t3) { var r3 = n4.length, e3 = [], u3 = 0; if (r3 <= t3) return [n4.slice()]; for (var o3 = 0; o3 < r3; o3++) e3[u3] || e3.push([]), e3[u3].push(n4[o3]), (o3 + 1) % t3 == 0 && u3++; return e3; }(n3.slice(d2.from, d2.to).toJSON().data, I)); o2 = function(n4) { return 0 === n4.from && 1 === n4.to ? { from: n4.from, to: n4.to } : { from: n4.from / I, to: Math.floor(n4.to / I) }; }(d2), e2 = h2 / I, r2 = 3 * p2, p2 >= 4 && (r2 += 1), l3 = 2, u2 = a2(function(n4) { return n4.length <= 4 ? n4.join(" ") : n4.slice(0, 4).join(" ") + " " + n4.slice(4).join(" "); }, v2), (f2 = (8 * (o2.to > 0 ? o2.to - 1 : o2.to)).toString(16).length) < 2 && (f2 = 2); } else { var g2 = n3.split(/\r\n|[\n\r\u2028\u2029]/); r2 = c3.column - 1, e2 = c3.line - 1, o2 = W(e2, q, A, g2.length), u2 = g2.slice(o2.from, o2.to), f2 = o2.to.toString().length; } var m3 = e2 - o2.from; return w(n3) && (f2 = (8 * (o2.to > 0 ? o2.to - 1 : o2.to)).toString(16).length) < 2 && (f2 = 2), i(function(t3, e3, u3) { var i2, a3 = u3 === m3, c4 = a3 ? "> " : z4; return i2 = w(n3) ? U((8 * (o2.from + u3)).toString(16), f2, "0") : U((o2.from + u3 + 1).toString(), f2, " "), [].concat(t3, [c4 + i2 + " | " + e3], a3 ? [z4 + R(" ", f2) + " | " + U("", r2, " ") + R("^", l3)] : []); }, [], u2).join("\n"); } function N(n3, t2) { return ["\n", "-- PARSING FAILED " + R("-", 50), "\n\n", D(n3, t2), "\n\n", (r2 = t2.expected, 1 === r2.length ? "Expected:\n\n" + r2[0] : "Expected one of the following: \n\n" + r2.join(", ")), "\n"].join(""); var r2; } function G(n3) { return void 0 !== n3.flags ? n3.flags : [n3.global ? "g" : "", n3.ignoreCase ? "i" : "", n3.multiline ? "m" : "", n3.unicode ? "u" : "", n3.sticky ? "y" : ""].join(""); } function C() { for (var n3 = [].slice.call(arguments), t2 = n3.length, r2 = 0; r2 < t2; r2 += 1) _(n3[r2]); return e(function(r3, e2) { for (var u2, o2 = new Array(t2), i2 = 0; i2 < t2; i2 += 1) { if (!(u2 = B(n3[i2]._(r3, e2), u2)).status) return u2; o2[i2] = u2.value, e2 = u2.index; } return B(b(e2, o2), u2); }); } function J() { var n3 = [].slice.call(arguments); if (0 === n3.length) throw new Error("seqMap needs at least one argument"); var t2 = n3.pop(); return k(t2), C.apply(null, n3).map(function(n4) { return t2.apply(null, n4); }); } function T() { var n3 = [].slice.call(arguments), t2 = n3.length; if (0 === t2) return Y("zero alternates"); for (var r2 = 0; r2 < t2; r2 += 1) _(n3[r2]); return e(function(t3, r3) { for (var e2, u2 = 0; u2 < n3.length; u2 += 1) if ((e2 = B(n3[u2]._(t3, r3), e2)).status) return e2; return e2; }); } function V(n3, t2) { return H(n3, t2).or(X([])); } function H(n3, t2) { return _(n3), _(t2), J(n3, t2.then(n3).many(), function(n4, t3) { return [n4].concat(t3); }); } function K(n3) { P(n3); var t2 = "'" + n3 + "'"; return e(function(r2, e2) { var u2 = e2 + n3.length, o2 = r2.slice(e2, u2); return o2 === n3 ? b(u2, o2) : x3(e2, t2); }); } function Q(n3, t2) { !function(n4) { if (!(n4 instanceof RegExp)) throw new Error("not a regexp: " + n4); for (var t3 = G(n4), r3 = 0; r3 < t3.length; r3++) { var e2 = t3.charAt(r3); if ("i" !== e2 && "m" !== e2 && "u" !== e2 && "s" !== e2) throw new Error('unsupported regexp flag "' + e2 + '": ' + n4); } }(n3), arguments.length >= 2 ? O(t2) : t2 = 0; var r2 = function(n4) { return RegExp("^(?:" + n4.source + ")", G(n4)); }(n3), u2 = "" + n3; return e(function(n4, e2) { var o2 = r2.exec(n4.slice(e2)); if (o2) { if (0 <= t2 && t2 <= o2.length) { var i2 = o2[0], a3 = o2[t2]; return b(e2 + i2.length, a3); } return x3(e2, "valid match group (0 to " + o2.length + ") in " + u2); } return x3(e2, u2); }); } function X(n3) { return e(function(t2, r2) { return b(r2, n3); }); } function Y(n3) { return e(function(t2, r2) { return x3(r2, n3); }); } function Z(n3) { if (y3(n3)) return e(function(t2, r2) { var e2 = n3._(t2, r2); return e2.index = r2, e2.value = "", e2; }); if ("string" == typeof n3) return Z(K(n3)); if (n3 instanceof RegExp) return Z(Q(n3)); throw new Error("not a string, regexp, or parser: " + n3); } function $(n3) { return _(n3), e(function(t2, r2) { var e2 = n3._(t2, r2), u2 = t2.slice(r2, e2.index); return e2.status ? x3(r2, 'not "' + u2 + '"') : b(r2, null); }); } function nn(n3) { return k(n3), e(function(t2, r2) { var e2 = L(t2, r2); return r2 < t2.length && n3(e2) ? b(r2 + 1, e2) : x3(r2, "a character/byte matching " + n3); }); } function tn(n3, t2) { arguments.length < 2 && (t2 = n3, n3 = void 0); var r2 = e(function(n4, e2) { return r2._ = t2()._, r2._(n4, e2); }); return n3 ? r2.desc(n3) : r2; } function rn() { return Y("fantasy-land/empty"); } u.parse = function(n3) { if ("string" != typeof n3 && !w(n3)) throw new Error(".parse must be called with a string or Buffer as its argument"); var t2, r2 = this.skip(an)._(n3, 0); return t2 = r2.status ? { status: true, value: r2.value } : { status: false, index: S(n3, r2.furthest), expected: r2.expected }, delete j[n3], t2; }, u.tryParse = function(n3) { var t2 = this.parse(n3); if (t2.status) return t2.value; var r2 = N(n3, t2), e2 = new Error(r2); throw e2.type = "ParsimmonError", e2.result = t2, e2; }, u.assert = function(n3, t2) { return this.chain(function(r2) { return n3(r2) ? X(r2) : Y(t2); }); }, u.or = function(n3) { return T(this, n3); }, u.trim = function(n3) { return this.wrap(n3, n3); }, u.wrap = function(n3, t2) { return J(n3, this, t2, function(n4, t3) { return t3; }); }, u.thru = function(n3) { return n3(this); }, u.then = function(n3) { return _(n3), C(this, n3).map(function(n4) { return n4[1]; }); }, u.many = function() { var n3 = this; return e(function(t2, r2) { for (var e2 = [], u2 = void 0; ; ) { if (!(u2 = B(n3._(t2, r2), u2)).status) return B(b(r2, e2), u2); if (r2 === u2.index) throw new Error("infinite loop detected in .many() parser --- calling .many() on a parser which can accept zero characters is usually the cause"); r2 = u2.index, e2.push(u2.value); } }); }, u.tieWith = function(n3) { return P(n3), this.map(function(t2) { if (function(n4) { if (!E(n4)) throw new Error("not an array: " + n4); }(t2), t2.length) { P(t2[0]); for (var r2 = t2[0], e2 = 1; e2 < t2.length; e2++) P(t2[e2]), r2 += n3 + t2[e2]; return r2; } return ""; }); }, u.tie = function() { return this.tieWith(""); }, u.times = function(n3, t2) { var r2 = this; return arguments.length < 2 && (t2 = n3), O(n3), O(t2), e(function(e2, u2) { for (var o2 = [], i2 = void 0, a3 = void 0, f2 = 0; f2 < n3; f2 += 1) { if (a3 = B(i2 = r2._(e2, u2), a3), !i2.status) return a3; u2 = i2.index, o2.push(i2.value); } for (; f2 < t2 && (a3 = B(i2 = r2._(e2, u2), a3), i2.status); f2 += 1) u2 = i2.index, o2.push(i2.value); return B(b(u2, o2), a3); }); }, u.result = function(n3) { return this.map(function() { return n3; }); }, u.atMost = function(n3) { return this.times(0, n3); }, u.atLeast = function(n3) { return J(this.times(n3), this.many(), function(n4, t2) { return n4.concat(t2); }); }, u.map = function(n3) { k(n3); var t2 = this; return e(function(r2, e2) { var u2 = t2._(r2, e2); return u2.status ? B(b(u2.index, n3(u2.value)), u2) : u2; }); }, u.contramap = function(n3) { k(n3); var t2 = this; return e(function(r2, e2) { var u2 = t2.parse(n3(r2.slice(e2))); return u2.status ? b(e2 + r2.length, u2.value) : u2; }); }, u.promap = function(n3, t2) { return k(n3), k(t2), this.contramap(n3).map(t2); }, u.skip = function(n3) { return C(this, n3).map(function(n4) { return n4[0]; }); }, u.mark = function() { return J(en, this, en, function(n3, t2, r2) { return { start: n3, value: t2, end: r2 }; }); }, u.node = function(n3) { return J(en, this, en, function(t2, r2, e2) { return { name: n3, value: r2, start: t2, end: e2 }; }); }, u.sepBy = function(n3) { return V(this, n3); }, u.sepBy1 = function(n3) { return H(this, n3); }, u.lookahead = function(n3) { return this.skip(Z(n3)); }, u.notFollowedBy = function(n3) { return this.skip($(n3)); }, u.desc = function(n3) { E(n3) || (n3 = [n3]); var t2 = this; return e(function(r2, e2) { var u2 = t2._(r2, e2); return u2.status || (u2.expected = n3), u2; }); }, u.fallback = function(n3) { return this.or(X(n3)); }, u.ap = function(n3) { return J(n3, this, function(n4, t2) { return n4(t2); }); }, u.chain = function(n3) { var t2 = this; return e(function(r2, e2) { var u2 = t2._(r2, e2); return u2.status ? B(n3(u2.value)._(r2, u2.index), u2) : u2; }); }, u.concat = u.or, u.empty = rn, u.of = X, u["fantasy-land/ap"] = u.ap, u["fantasy-land/chain"] = u.chain, u["fantasy-land/concat"] = u.concat, u["fantasy-land/empty"] = u.empty, u["fantasy-land/of"] = u.of, u["fantasy-land/map"] = u.map; var en = e(function(n3, t2) { return b(t2, S(n3, t2)); }), un = e(function(n3, t2) { return t2 >= n3.length ? x3(t2, "any character/byte") : b(t2 + 1, L(n3, t2)); }), on = e(function(n3, t2) { return b(n3.length, n3.slice(t2)); }), an = e(function(n3, t2) { return t2 < n3.length ? x3(t2, "EOF") : b(t2, null); }), fn = Q(/[0-9]/).desc("a digit"), cn = Q(/[0-9]*/).desc("optional digits"), sn = Q(/[a-z]/i).desc("a letter"), ln = Q(/[a-z]*/i).desc("optional letters"), hn = Q(/\s*/).desc("optional whitespace"), pn = Q(/\s+/).desc("whitespace"), dn = K("\r"), vn = K("\n"), gn = K("\r\n"), mn = T(gn, vn, dn).desc("newline"), yn = T(mn, an); e.all = on, e.alt = T, e.any = un, e.cr = dn, e.createLanguage = function(n3) { var t2 = {}; for (var r2 in n3) ({}).hasOwnProperty.call(n3, r2) && function(r3) { t2[r3] = tn(function() { return n3[r3](t2); }); }(r2); return t2; }, e.crlf = gn, e.custom = function(n3) { return e(n3(b, x3)); }, e.digit = fn, e.digits = cn, e.empty = rn, e.end = yn, e.eof = an, e.fail = Y, e.formatError = N, e.index = en, e.isParser = y3, e.lazy = tn, e.letter = sn, e.letters = ln, e.lf = vn, e.lookahead = Z, e.makeFailure = x3, e.makeSuccess = b, e.newline = mn, e.noneOf = function(n3) { return nn(function(t2) { return n3.indexOf(t2) < 0; }).desc("none of '" + n3 + "'"); }, e.notFollowedBy = $, e.of = X, e.oneOf = function(n3) { for (var t2 = n3.split(""), r2 = 0; r2 < t2.length; r2++) t2[r2] = "'" + t2[r2] + "'"; return nn(function(t3) { return n3.indexOf(t3) >= 0; }).desc(t2); }, e.optWhitespace = hn, e.Parser = e, e.range = function(n3, t2) { return nn(function(r2) { return n3 <= r2 && r2 <= t2; }).desc(n3 + "-" + t2); }, e.regex = Q, e.regexp = Q, e.sepBy = V, e.sepBy1 = H, e.seq = C, e.seqMap = J, e.seqObj = function() { for (var n3, t2 = {}, r2 = 0, u2 = (n3 = arguments, Array.prototype.slice.call(n3)), o2 = u2.length, i2 = 0; i2 < o2; i2 += 1) { var a3 = u2[i2]; if (!y3(a3)) { if (E(a3) && 2 === a3.length && "string" == typeof a3[0] && y3(a3[1])) { var f2 = a3[0]; if (Object.prototype.hasOwnProperty.call(t2, f2)) throw new Error("seqObj: duplicate key " + f2); t2[f2] = true, r2++; continue; } throw new Error("seqObj arguments must be parsers or [string, parser] array pairs."); } } if (0 === r2) throw new Error("seqObj expects at least one named parser, found zero"); return e(function(n4, t3) { for (var r3, e2 = {}, i3 = 0; i3 < o2; i3 += 1) { var a4, f3; if (E(u2[i3]) ? (a4 = u2[i3][0], f3 = u2[i3][1]) : (a4 = null, f3 = u2[i3]), !(r3 = B(f3._(n4, t3), r3)).status) return r3; a4 && (e2[a4] = r3.value), t3 = r3.index; } return B(b(t3, e2), r3); }); }, e.string = K, e.succeed = X, e.takeWhile = function(n3) { return k(n3), e(function(t2, r2) { for (var e2 = r2; e2 < t2.length && n3(L(t2, e2)); ) e2++; return b(e2, t2.slice(r2, e2)); }); }, e.test = nn, e.whitespace = pn, e["fantasy-land/empty"] = rn, e["fantasy-land/of"] = X, e.Binary = { bitSeq: l2, bitSeqObj: function(n3) { s2(); var t2 = {}, r2 = 0, e2 = a2(function(n4) { if (E(n4)) { var e3 = n4; if (2 !== e3.length) throw new Error("[" + e3.join(", ") + "] should be length 2, got length " + e3.length); if (P(e3[0]), O(e3[1]), Object.prototype.hasOwnProperty.call(t2, e3[0])) throw new Error("duplicate key in bitSeqObj: " + e3[0]); return t2[e3[0]] = true, r2++, e3; } return O(n4), [null, n4]; }, n3); if (r2 < 1) throw new Error("bitSeqObj expects at least one named pair, got [" + n3.join(", ") + "]"); var u2 = a2(function(n4) { return n4[0]; }, e2); return l2(a2(function(n4) { return n4[1]; }, e2)).map(function(n4) { return i(function(n5, t3) { return null !== t3[0] && (n5[t3[0]] = t3[1]), n5; }, {}, a2(function(t3, r3) { return [t3, n4[r3]]; }, u2)); }); }, byte: function(n3) { if (s2(), O(n3), n3 > 255) throw new Error("Value specified to byte constructor (" + n3 + "=0x" + n3.toString(16) + ") is larger in value than a single byte."); var t2 = (n3 > 15 ? "0x" : "0x0") + n3.toString(16); return e(function(r2, e2) { var u2 = L(r2, e2); return u2 === n3 ? b(e2 + 1, u2) : x3(e2, t2); }); }, buffer: function(n3) { return h("buffer", n3).map(function(n4) { return Buffer.from(n4); }); }, encodedString: function(n3, t2) { return h("string", t2).map(function(t3) { return t3.toString(n3); }); }, uintBE: d, uint8BE: d(1), uint16BE: d(2), uint32BE: d(4), uintLE: v, uint8LE: v(1), uint16LE: v(2), uint32LE: v(4), intBE: g, int8BE: g(1), int16BE: g(2), int32BE: g(4), intLE: m2, int8LE: m2(1), int16LE: m2(2), int32LE: m2(4), floatBE: h("floatBE", 4).map(function(n3) { return n3.readFloatBE(0); }), floatLE: h("floatLE", 4).map(function(n3) { return n3.readFloatLE(0); }), doubleBE: h("doubleBE", 8).map(function(n3) { return n3.readDoubleBE(0); }), doubleLE: h("doubleLE", 8).map(function(n3) { return n3.readDoubleLE(0); }) }, n2.exports = e; }]); }); })(parsimmon_umd_min, parsimmon_umd_min.exports); var parsimmon_umd_minExports = parsimmon_umd_min.exports; var emojiRegex2 = () => { return /[#*0-9]\uFE0F?\u20E3|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26AA\u26B0\u26B1\u26BD\u26BE\u26C4\u26C8\u26CF\u26D1\u26D3\u26E9\u26F0-\u26F5\u26F7\u26F8\u26FA\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B55\u3030\u303D\u3297\u3299]\uFE0F?|[\u261D\u270C\u270D](?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?|[\u270A\u270B](?:\uD83C[\uDFFB-\uDFFF])?|[\u23E9-\u23EC\u23F0\u23F3\u25FD\u2693\u26A1\u26AB\u26C5\u26CE\u26D4\u26EA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2795-\u2797\u27B0\u27BF\u2B50]|\u26F9(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|\u2764\uFE0F?(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79))?|\uD83C(?:[\uDC04\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]\uFE0F?|[\uDF85\uDFC2\uDFC7](?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC3\uDFC4\uDFCA](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDFCB\uDFCC](?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uDDE6\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF]|\uDDE7\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF]|\uDDE8\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF]|\uDDE9\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF]|\uDDEA\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA]|\uDDEB\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7]|\uDDEC\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE]|\uDDED\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA]|\uDDEE\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9]|\uDDEF\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5]|\uDDF0\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF]|\uDDF1\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE]|\uDDF2\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF]|\uDDF3\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF]|\uDDF4\uD83C\uDDF2|\uDDF5\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE]|\uDDF6\uD83C\uDDE6|\uDDF7\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC]|\uDDF8\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF]|\uDDF9\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF]|\uDDFA\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF]|\uDDFB\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA]|\uDDFC\uD83C[\uDDEB\uDDF8]|\uDDFD\uD83C\uDDF0|\uDDFE\uD83C[\uDDEA\uDDF9]|\uDDFF\uD83C[\uDDE6\uDDF2\uDDFC]|\uDFF3\uFE0F?(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08))?|\uDFF4(?:\u200D\u2620\uFE0F?|\uDB40\uDC67\uDB40\uDC62\uDB40(?:\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDC73\uDB40\uDC63\uDB40\uDC74|\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F)?)|\uD83D(?:[\uDC08\uDC26](?:\u200D\u2B1B)?|[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3]\uFE0F?|[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD74\uDD90](?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?|[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC25\uDC27-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEDC-\uDEDF\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB\uDFF0]|\uDC15(?:\u200D\uD83E\uDDBA)?|\uDC3B(?:\u200D\u2744\uFE0F?)?|\uDC41\uFE0F?(?:\u200D\uD83D\uDDE8\uFE0F?)?|\uDC68(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE])))?))?|\uDC69(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?[\uDC68\uDC69]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?))|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFE])))?))?|\uDC6F(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDD75(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDE2E(?:\u200D\uD83D\uDCA8)?|\uDE35(?:\u200D\uD83D\uDCAB)?|\uDE36(?:\u200D\uD83C\uDF2B\uFE0F?)?)|\uD83E(?:[\uDD0C\uDD0F\uDD18-\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5\uDEC3-\uDEC5\uDEF0\uDEF2-\uDEF8](?:\uD83C[\uDFFB-\uDFFF])?|[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDDDE\uDDDF](?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD0D\uDD0E\uDD10-\uDD17\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCC\uDDD0\uDDE0-\uDDFF\uDE70-\uDE7C\uDE80-\uDE88\uDE90-\uDEBD\uDEBF-\uDEC2\uDECE-\uDEDB\uDEE0-\uDEE8]|\uDD3C(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF])?|\uDDD1(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF-\uDDB3\uDDBC\uDDBD]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?))?|\uDEF1(?:\uD83C(?:\uDFFB(?:\u200D\uD83E\uDEF2\uD83C[\uDFFC-\uDFFF])?|\uDFFC(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFD-\uDFFF])?|\uDFFD(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])?|\uDFFE(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFD\uDFFF])?|\uDFFF(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFE])?))?)/g; }; function normalizeDuration(dur) { if (dur === void 0 || dur === null) return dur; return dur.shiftToAll().normalize(); } function getFileTitle(path) { if (path.includes("/")) path = path.substring(path.lastIndexOf("/") + 1); if (path.endsWith(".md")) path = path.substring(0, path.length - 3); return path; } parsimmon_umd_minExports.alt(parsimmon_umd_minExports.regex(new RegExp(emojiRegex2(), "")), parsimmon_umd_minExports.regex(/[0-9\p{Letter}_-]+/u).map((str) => str.toLocaleLowerCase()), parsimmon_umd_minExports.whitespace.map((_) => "-"), parsimmon_umd_minExports.any.map((_) => "")).many().map((result) => result.join("")); var HEADER_CANONICALIZER = parsimmon_umd_minExports.alt(parsimmon_umd_minExports.regex(new RegExp(emojiRegex2(), "")), parsimmon_umd_minExports.regex(/[0-9\p{Letter}_-]+/u), parsimmon_umd_minExports.whitespace.map((_) => " "), parsimmon_umd_minExports.any.map((_) => " ")).many().map((result) => { return result.join("").split(/\s+/).join(" ").trim(); }); function normalizeHeaderForLink(header) { return HEADER_CANONICALIZER.tryParse(header); } function renderMinimalDuration(dur) { dur = normalizeDuration(dur); dur = Duration.fromObject(Object.fromEntries(Object.entries(dur.toObject()).filter(([, quantity]) => quantity != 0))); return dur.toHuman(); } var Values; (function(Values2) { function toString2(field, setting = DEFAULT_QUERY_SETTINGS, recursive = false) { let wrapped = wrapValue(field); if (!wrapped) return setting.renderNullAs; switch (wrapped.type) { case "null": return setting.renderNullAs; case "string": return wrapped.value; case "number": case "boolean": return "" + wrapped.value; case "html": return wrapped.value.outerHTML; case "widget": return wrapped.value.markdown(); case "link": return wrapped.value.markdown(); case "function": return ""; case "array": let result = ""; if (recursive) result += "["; result += wrapped.value.map((f) => toString2(f, setting, true)).join(", "); if (recursive) result += "]"; return result; case "object": return "{ " + Object.entries(wrapped.value).map((e) => e[0] + ": " + toString2(e[1], setting, true)).join(", ") + " }"; case "date": if (wrapped.value.second == 0 && wrapped.value.hour == 0 && wrapped.value.minute == 0) { return wrapped.value.toFormat(setting.defaultDateFormat); } return wrapped.value.toFormat(setting.defaultDateTimeFormat); case "duration": return renderMinimalDuration(wrapped.value); } } Values2.toString = toString2; function wrapValue(val) { if (isNull2(val)) return { type: "null", value: val }; else if (isNumber2(val)) return { type: "number", value: val }; else if (isString2(val)) return { type: "string", value: val }; else if (isBoolean(val)) return { type: "boolean", value: val }; else if (isDuration(val)) return { type: "duration", value: val }; else if (isDate2(val)) return { type: "date", value: val }; else if (isWidget(val)) return { type: "widget", value: val }; else if (isArray2(val)) return { type: "array", value: val }; else if (isLink(val)) return { type: "link", value: val }; else if (isFunction(val)) return { type: "function", value: val }; else if (isHtml(val)) return { type: "html", value: val }; else if (isObject2(val)) return { type: "object", value: val }; else return void 0; } Values2.wrapValue = wrapValue; function mapLeaves(val, func) { if (isObject2(val)) { let result = {}; for (let [key, value] of Object.entries(val)) result[key] = mapLeaves(value, func); return result; } else if (isArray2(val)) { let result = []; for (let value of val) result.push(mapLeaves(value, func)); return result; } else { return func(val); } } Values2.mapLeaves = mapLeaves; function compareValue(val1, val2, linkNormalizer) { var _a3, _b3; if (val1 === void 0) val1 = null; if (val2 === void 0) val2 = null; if (val1 === null && val2 === null) return 0; else if (val1 === null) return -1; else if (val2 === null) return 1; let wrap1 = wrapValue(val1); let wrap2 = wrapValue(val2); if (wrap1 === void 0 && wrap2 === void 0) return 0; else if (wrap1 === void 0) return -1; else if (wrap2 === void 0) return 1; if (wrap1.type != wrap2.type) return wrap1.type.localeCompare(wrap2.type); if (wrap1.value === wrap2.value) return 0; switch (wrap1.type) { case "string": return wrap1.value.localeCompare(wrap2.value); case "number": if (wrap1.value < wrap2.value) return -1; else if (wrap1.value == wrap2.value) return 0; return 1; case "null": return 0; case "boolean": if (wrap1.value == wrap2.value) return 0; else return wrap1.value ? 1 : -1; case "link": let link1 = wrap1.value; let link2 = wrap2.value; let normalize3 = linkNormalizer !== null && linkNormalizer !== void 0 ? linkNormalizer : (x3) => x3; let pathCompare = normalize3(link1.path).localeCompare(normalize3(link2.path)); if (pathCompare != 0) return pathCompare; let typeCompare = link1.type.localeCompare(link2.type); if (typeCompare != 0) return typeCompare; if (link1.subpath && !link2.subpath) return 1; if (!link1.subpath && link2.subpath) return -1; if (!link1.subpath && !link2.subpath) return 0; return ((_a3 = link1.subpath) !== null && _a3 !== void 0 ? _a3 : "").localeCompare((_b3 = link2.subpath) !== null && _b3 !== void 0 ? _b3 : ""); case "date": return wrap1.value < wrap2.value ? -1 : wrap1.value.equals(wrap2.value) ? 0 : 1; case "duration": return wrap1.value < wrap2.value ? -1 : wrap1.value.equals(wrap2.value) ? 0 : 1; case "array": let f1 = wrap1.value; let f2 = wrap2.value; for (let index6 = 0; index6 < Math.min(f1.length, f2.length); index6++) { let comp = compareValue(f1[index6], f2[index6]); if (comp != 0) return comp; } return f1.length - f2.length; case "object": let o1 = wrap1.value; let o2 = wrap2.value; let k1 = Array.from(Object.keys(o1)); let k2 = Array.from(Object.keys(o2)); k1.sort(); k2.sort(); let keyCompare = compareValue(k1, k2); if (keyCompare != 0) return keyCompare; for (let key of k1) { let comp = compareValue(o1[key], o2[key]); if (comp != 0) return comp; } return 0; case "widget": case "html": case "function": return 0; } } Values2.compareValue = compareValue; function typeOf(val) { var _a3; return (_a3 = wrapValue(val)) === null || _a3 === void 0 ? void 0 : _a3.type; } Values2.typeOf = typeOf; function isTruthy(field) { let wrapped = wrapValue(field); if (!wrapped) return false; switch (wrapped.type) { case "number": return wrapped.value != 0; case "string": return wrapped.value.length > 0; case "boolean": return wrapped.value; case "link": return !!wrapped.value.path; case "date": return wrapped.value.toMillis() != 0; case "duration": return wrapped.value.as("seconds") != 0; case "object": return Object.keys(wrapped.value).length > 0; case "array": return wrapped.value.length > 0; case "null": return false; case "html": case "widget": case "function": return true; } } Values2.isTruthy = isTruthy; function deepCopy(field) { if (field === null || field === void 0) return field; if (Values2.isArray(field)) { return [].concat(field.map((v) => deepCopy(v))); } else if (Values2.isObject(field)) { let result = {}; for (let [key, value] of Object.entries(field)) result[key] = deepCopy(value); return result; } else { return field; } } Values2.deepCopy = deepCopy; function isString2(val) { return typeof val == "string"; } Values2.isString = isString2; function isNumber2(val) { return typeof val == "number"; } Values2.isNumber = isNumber2; function isDate2(val) { return val instanceof DateTime; } Values2.isDate = isDate2; function isDuration(val) { return val instanceof Duration; } Values2.isDuration = isDuration; function isNull2(val) { return val === null || val === void 0; } Values2.isNull = isNull2; function isArray2(val) { return Array.isArray(val); } Values2.isArray = isArray2; function isBoolean(val) { return typeof val === "boolean"; } Values2.isBoolean = isBoolean; function isLink(val) { return val instanceof Link2; } Values2.isLink = isLink; function isWidget(val) { return val instanceof Widget; } Values2.isWidget = isWidget; function isHtml(val) { if (typeof HTMLElement !== "undefined") { return val instanceof HTMLElement; } else { return false; } } Values2.isHtml = isHtml; function isObject2(val) { return typeof val == "object" && !isHtml(val) && !isWidget(val) && !isArray2(val) && !isDuration(val) && !isDate2(val) && !isLink(val) && val !== void 0 && !isNull2(val); } Values2.isObject = isObject2; function isFunction(val) { return typeof val == "function"; } Values2.isFunction = isFunction; })(Values || (Values = {})); var Groupings; (function(Groupings2) { function isElementGroup(entry) { return Values.isObject(entry) && Object.keys(entry).length == 2 && "key" in entry && "rows" in entry; } Groupings2.isElementGroup = isElementGroup; function isGrouping(entry) { for (let element of entry) if (!isElementGroup(element)) return false; return true; } Groupings2.isGrouping = isGrouping; function count(elements) { if (isGrouping(elements)) { let result = 0; for (let subgroup of elements) result += count(subgroup.rows); return result; } else { return elements.length; } } Groupings2.count = count; })(Groupings || (Groupings = {})); var Link2 = class { /** Create a link to a specific file. */ static file(path, embed = false, display) { return new Link2({ path, embed, display, subpath: void 0, type: "file" }); } static infer(linkpath, embed = false, display) { if (linkpath.includes("#^")) { let split = linkpath.split("#^"); return Link2.block(split[0], split[1], embed, display); } else if (linkpath.includes("#")) { let split = linkpath.split("#"); return Link2.header(split[0], split[1], embed, display); } else return Link2.file(linkpath, embed, display); } /** Create a link to a specific file and header in that file. */ static header(path, header, embed, display) { return new Link2({ path, embed, display, subpath: normalizeHeaderForLink(header), type: "header" }); } /** Create a link to a specific file and block in that file. */ static block(path, blockId, embed, display) { return new Link2({ path, embed, display, subpath: blockId, type: "block" }); } static fromObject(object) { return new Link2(object); } constructor(fields) { Object.assign(this, fields); } /** Checks for link equality (i.e., that the links are pointing to the same exact location). */ equals(other) { if (other == void 0 || other == null) return false; return this.path == other.path && this.type == other.type && this.subpath == other.subpath; } /** Convert this link to it's markdown representation. */ toString() { return this.markdown(); } /** Convert this link to a raw object which is serialization-friendly. */ toObject() { return { path: this.path, type: this.type, subpath: this.subpath, display: this.display, embed: this.embed }; } /** Update this link with a new path. */ //@ts-ignore; error appeared after updating Obsidian to 0.15.4; it also updated other packages but didn't say which withPath(path) { return new Link2(Object.assign({}, this, { path })); } /** Return a new link which points to the same location but with a new display value. */ withDisplay(display) { return new Link2(Object.assign({}, this, { display })); } /** Convert a file link into a link to a specific header. */ withHeader(header) { return Link2.header(this.path, header, this.embed, this.display); } /** Convert any link into a link to its file. */ toFile() { return Link2.file(this.path, this.embed, this.display); } /** Convert this link into an embedded link. */ toEmbed() { if (this.embed) { return this; } else { let link = new Link2(this); link.embed = true; return link; } } /** Convert this link into a non-embedded link. */ fromEmbed() { if (!this.embed) { return this; } else { let link = new Link2(this); link.embed = false; return link; } } /** Convert this link to markdown so it can be rendered. */ markdown() { let result = (this.embed ? "!" : "") + "[[" + this.obsidianLink(); if (this.display) { result += "|" + this.display; } else { result += "|" + getFileTitle(this.path); if (this.type == "header" || this.type == "block") result += " > " + this.subpath; } result += "]]"; return result; } /** Convert the inner part of the link to something that Obsidian can open / understand. */ obsidianLink() { var _a3, _b3; const escaped = this.path.replace("|", "\\|"); if (this.type == "header") return escaped + "#" + ((_a3 = this.subpath) === null || _a3 === void 0 ? void 0 : _a3.replace("|", "\\|")); if (this.type == "block") return escaped + "#^" + ((_b3 = this.subpath) === null || _b3 === void 0 ? void 0 : _b3.replace("|", "\\|")); else return escaped; } /** The stripped name of the file this link points to. */ fileName() { return getFileTitle(this.path).replace(".md", ""); } }; var Widget = class { constructor($widget) { this.$widget = $widget; } }; var ListPairWidget = class extends Widget { constructor(key, value) { super("dataview:list-pair"); this.key = key; this.value = value; } markdown() { return `${Values.toString(this.key)}: ${Values.toString(this.value)}`; } }; var ExternalLinkWidget = class extends Widget { constructor(url, display) { super("dataview:external-link"); this.url = url; this.display = display; } markdown() { var _a3; return `[${(_a3 = this.display) !== null && _a3 !== void 0 ? _a3 : this.url}](${this.url})`; } }; var Widgets; (function(Widgets2) { function listPair(key, value) { return new ListPairWidget(key, value); } Widgets2.listPair = listPair; function externalLink(url, display) { return new ExternalLinkWidget(url, display); } Widgets2.externalLink = externalLink; function isListPair(widget) { return widget.$widget === "dataview:list-pair"; } Widgets2.isListPair = isListPair; function isExternalLink(widget) { return widget.$widget === "dataview:external-link"; } Widgets2.isExternalLink = isExternalLink; function isBuiltin(widget) { return isListPair(widget) || isExternalLink(widget); } Widgets2.isBuiltin = isBuiltin; })(Widgets || (Widgets = {})); var Fields; (function(Fields2) { function variable(name) { return { type: "variable", name }; } Fields2.variable = variable; function literal(value) { return { type: "literal", value }; } Fields2.literal = literal; function binaryOp(left, op, right) { return { type: "binaryop", left, op, right }; } Fields2.binaryOp = binaryOp; function index6(obj, index7) { return { type: "index", object: obj, index: index7 }; } Fields2.index = index6; function indexVariable(name) { let parts = name.split("."); let result = Fields2.variable(parts[0]); for (let index7 = 1; index7 < parts.length; index7++) { result = Fields2.index(result, Fields2.literal(parts[index7])); } return result; } Fields2.indexVariable = indexVariable; function lambda(args, value) { return { type: "lambda", arguments: args, value }; } Fields2.lambda = lambda; function func(func2, args) { return { type: "function", func: func2, arguments: args }; } Fields2.func = func; function list(values) { return { type: "list", values }; } Fields2.list = list; function object(values) { return { type: "object", values }; } Fields2.object = object; function negate(child) { return { type: "negated", child }; } Fields2.negate = negate; function isCompareOp(op) { return op == "<=" || op == "<" || op == ">" || op == ">=" || op == "!=" || op == "="; } Fields2.isCompareOp = isCompareOp; Fields2.NULL = Fields2.literal(null); })(Fields || (Fields = {})); var Sources; (function(Sources2) { function tag(tag2) { return { type: "tag", tag: tag2 }; } Sources2.tag = tag; function csv(path) { return { type: "csv", path }; } Sources2.csv = csv; function folder(prefix) { return { type: "folder", folder: prefix }; } Sources2.folder = folder; function link(file, incoming) { return { type: "link", file, direction: incoming ? "incoming" : "outgoing" }; } Sources2.link = link; function binaryOp(left, op, right) { return { type: "binaryop", left, op, right }; } Sources2.binaryOp = binaryOp; function and(left, right) { return { type: "binaryop", left, op: "&", right }; } Sources2.and = and; function or(left, right) { return { type: "binaryop", left, op: "|", right }; } Sources2.or = or; function negate(child) { return { type: "negate", child }; } Sources2.negate = negate; function empty() { return { type: "empty" }; } Sources2.empty = empty; })(Sources || (Sources = {})); var EMOJI_REGEX = new RegExp(emojiRegex2(), ""); var DURATION_TYPES = { year: Duration.fromObject({ years: 1 }), years: Duration.fromObject({ years: 1 }), yr: Duration.fromObject({ years: 1 }), yrs: Duration.fromObject({ years: 1 }), month: Duration.fromObject({ months: 1 }), months: Duration.fromObject({ months: 1 }), mo: Duration.fromObject({ months: 1 }), mos: Duration.fromObject({ months: 1 }), week: Duration.fromObject({ weeks: 1 }), weeks: Duration.fromObject({ weeks: 1 }), wk: Duration.fromObject({ weeks: 1 }), wks: Duration.fromObject({ weeks: 1 }), w: Duration.fromObject({ weeks: 1 }), day: Duration.fromObject({ days: 1 }), days: Duration.fromObject({ days: 1 }), d: Duration.fromObject({ days: 1 }), hour: Duration.fromObject({ hours: 1 }), hours: Duration.fromObject({ hours: 1 }), hr: Duration.fromObject({ hours: 1 }), hrs: Duration.fromObject({ hours: 1 }), h: Duration.fromObject({ hours: 1 }), minute: Duration.fromObject({ minutes: 1 }), minutes: Duration.fromObject({ minutes: 1 }), min: Duration.fromObject({ minutes: 1 }), mins: Duration.fromObject({ minutes: 1 }), m: Duration.fromObject({ minutes: 1 }), second: Duration.fromObject({ seconds: 1 }), seconds: Duration.fromObject({ seconds: 1 }), sec: Duration.fromObject({ seconds: 1 }), secs: Duration.fromObject({ seconds: 1 }), s: Duration.fromObject({ seconds: 1 }) }; var DATE_SHORTHANDS = { now: () => DateTime.local(), today: () => DateTime.local().startOf("day"), yesterday: () => DateTime.local().startOf("day").minus(Duration.fromObject({ days: 1 })), tomorrow: () => DateTime.local().startOf("day").plus(Duration.fromObject({ days: 1 })), sow: () => DateTime.local().startOf("week"), "start-of-week": () => DateTime.local().startOf("week"), eow: () => DateTime.local().endOf("week"), "end-of-week": () => DateTime.local().endOf("week"), soy: () => DateTime.local().startOf("year"), "start-of-year": () => DateTime.local().startOf("year"), eoy: () => DateTime.local().endOf("year"), "end-of-year": () => DateTime.local().endOf("year"), som: () => DateTime.local().startOf("month"), "start-of-month": () => DateTime.local().startOf("month"), eom: () => DateTime.local().endOf("month"), "end-of-month": () => DateTime.local().endOf("month") }; var KEYWORDS = ["FROM", "WHERE", "LIMIT", "GROUP", "FLATTEN"]; function splitOnUnescapedPipe(link) { let pipe = -1; while ((pipe = link.indexOf("|", pipe + 1)) >= 0) { if (pipe > 0 && link[pipe - 1] == "\\") continue; return [link.substring(0, pipe).replace(/\\\|/g, "|"), link.substring(pipe + 1)]; } return [link.replace(/\\\|/g, "|"), void 0]; } function parseInnerLink(rawlink) { let [link, display] = splitOnUnescapedPipe(rawlink); return Link2.infer(link, false, display); } function createBinaryParser(child, sep, combine) { return parsimmon_umd_minExports.seqMap(child, parsimmon_umd_minExports.seq(parsimmon_umd_minExports.optWhitespace, sep, parsimmon_umd_minExports.optWhitespace, child).many(), (first, rest) => { if (rest.length == 0) return first; let node = combine(first, rest[0][1], rest[0][3]); for (let index6 = 1; index6 < rest.length; index6++) { node = combine(node, rest[index6][1], rest[index6][3]); } return node; }); } function chainOpt(base, ...funcs) { return parsimmon_umd_minExports.custom((success, failure) => { return (input, i) => { let result = base._(input, i); if (!result.status) return result; for (let func of funcs) { let next = func(result.value)._(input, result.index); if (!next.status) return result; result = next; } return result; }; }); } var EXPRESSION = parsimmon_umd_minExports.createLanguage({ // A floating point number; the decimal point is optional. number: (q) => parsimmon_umd_minExports.regexp(/-?[0-9]+(\.[0-9]+)?/).map((str) => Number.parseFloat(str)).desc("number"), // A quote-surrounded string which supports escape characters ('\'). string: (q) => parsimmon_umd_minExports.string('"').then(parsimmon_umd_minExports.alt(q.escapeCharacter, parsimmon_umd_minExports.noneOf('"\\')).atLeast(0).map((chars) => chars.join(""))).skip(parsimmon_umd_minExports.string('"')).desc("string"), escapeCharacter: (_) => parsimmon_umd_minExports.string("\\").then(parsimmon_umd_minExports.any).map((escaped) => { if (escaped === '"') return '"'; if (escaped === "\\") return "\\"; else return "\\" + escaped; }), // A boolean true/false value. bool: (_) => parsimmon_umd_minExports.regexp(/true|false|True|False/).map((str) => str.toLowerCase() == "true").desc("boolean ('true' or 'false')"), // A tag of the form '#stuff/hello-there'. tag: (_) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.string("#"), parsimmon_umd_minExports.alt(parsimmon_umd_minExports.regexp(/[^\u2000-\u206F\u2E00-\u2E7F'!"#$%&()*+,.:;<=>?@^`{|}~\[\]\\\s]/).desc("text")).many(), (start, rest) => start + rest.join("")).desc("tag ('#hello/stuff')"), // A variable identifier, which is alphanumeric and must start with a letter or... emoji. identifier: (_) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.alt(parsimmon_umd_minExports.regexp(/\p{Letter}/u), parsimmon_umd_minExports.regexp(EMOJI_REGEX).desc("text")), parsimmon_umd_minExports.alt(parsimmon_umd_minExports.regexp(/[0-9\p{Letter}_-]/u), parsimmon_umd_minExports.regexp(EMOJI_REGEX).desc("text")).many(), (first, rest) => first + rest.join("")).desc("variable identifier"), // An Obsidian link of the form [[]]. link: (_) => parsimmon_umd_minExports.regexp(/\[\[([^\[\]]*?)\]\]/u, 1).map((linkInner) => parseInnerLink(linkInner)).desc("file link"), // An embeddable link which can start with '!'. This overlaps with the normal negation operator, so it is only // provided for metadata parsing. embedLink: (q) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.string("!").atMost(1), q.link, (p, l2) => { if (p.length > 0) l2.embed = true; return l2; }).desc("file link"), // Binary plus or minus operator. binaryPlusMinus: (_) => parsimmon_umd_minExports.regexp(/\+|-/).map((str) => str).desc("'+' or '-'"), // Binary times or divide operator. binaryMulDiv: (_) => parsimmon_umd_minExports.regexp(/\*|\/|%/).map((str) => str).desc("'*' or '/' or '%'"), // Binary comparison operator. binaryCompareOp: (_) => parsimmon_umd_minExports.regexp(/>=|<=|!=|>|<|=/).map((str) => str).desc("'>=' or '<=' or '!=' or '=' or '>' or '<'"), // Binary boolean combination operator. binaryBooleanOp: (_) => parsimmon_umd_minExports.regexp(/and|or|&|\|/i).map((str) => { if (str.toLowerCase() == "and") return "&"; else if (str.toLowerCase() == "or") return "|"; else return str; }).desc("'and' or 'or'"), // A date which can be YYYY-MM[-DDTHH:mm:ss]. rootDate: (_) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.regexp(/\d{4}/), parsimmon_umd_minExports.string("-"), parsimmon_umd_minExports.regexp(/\d{2}/), (year, _2, month) => { return DateTime.fromObject({ year: Number.parseInt(year), month: Number.parseInt(month) }); }).desc("date in format YYYY-MM[-DDTHH-MM-SS.MS]"), dateShorthand: (_) => parsimmon_umd_minExports.alt(...Object.keys(DATE_SHORTHANDS).sort((a2, b) => b.length - a2.length).map(parsimmon_umd_minExports.string)), date: (q) => chainOpt(q.rootDate, (ym) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.string("-"), parsimmon_umd_minExports.regexp(/\d{2}/), (_, day) => ym.set({ day: Number.parseInt(day) })), (ymd) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.string("T"), parsimmon_umd_minExports.regexp(/\d{2}/), (_, hour) => ymd.set({ hour: Number.parseInt(hour) })), (ymdh) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.string(":"), parsimmon_umd_minExports.regexp(/\d{2}/), (_, minute) => ymdh.set({ minute: Number.parseInt(minute) })), (ymdhm) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.string(":"), parsimmon_umd_minExports.regexp(/\d{2}/), (_, second) => ymdhm.set({ second: Number.parseInt(second) })), (ymdhms) => parsimmon_umd_minExports.alt( parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.string("."), parsimmon_umd_minExports.regexp(/\d{3}/), (_, millisecond) => ymdhms.set({ millisecond: Number.parseInt(millisecond) })), parsimmon_umd_minExports.succeed(ymdhms) // pass ), (dt) => parsimmon_umd_minExports.alt(parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.string("+").or(parsimmon_umd_minExports.string("-")), parsimmon_umd_minExports.regexp(/\d{1,2}(:\d{2})?/), (pm, hr) => dt.setZone("UTC" + pm + hr, { keepLocalTime: true })), parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.string("Z"), () => dt.setZone("utc", { keepLocalTime: true })), parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.string("["), parsimmon_umd_minExports.regexp(/[0-9A-Za-z+-\/]+/u), parsimmon_umd_minExports.string("]"), (_a3, zone, _b3) => dt.setZone(zone, { keepLocalTime: true })))).assert((dt) => dt.isValid, "valid date").desc("date in format YYYY-MM[-DDTHH-MM-SS.MS]"), // A date, plus various shorthand times of day it could be. datePlus: (q) => parsimmon_umd_minExports.alt(q.dateShorthand.map((d) => DATE_SHORTHANDS[d]()), q.date).desc("date in format YYYY-MM[-DDTHH-MM-SS.MS] or in shorthand"), // A duration of time. durationType: (_) => parsimmon_umd_minExports.alt(...Object.keys(DURATION_TYPES).sort((a2, b) => b.length - a2.length).map(parsimmon_umd_minExports.string)), duration: (q) => parsimmon_umd_minExports.seqMap(q.number, parsimmon_umd_minExports.optWhitespace, q.durationType, (count, _, t) => DURATION_TYPES[t].mapUnits((x3) => x3 * count)).sepBy1(parsimmon_umd_minExports.string(",").trim(parsimmon_umd_minExports.optWhitespace).or(parsimmon_umd_minExports.optWhitespace)).map((durations) => durations.reduce((p, c2) => p.plus(c2))).desc("duration like 4hr2min"), // A raw null value. rawNull: (_) => parsimmon_umd_minExports.string("null"), // Source parsing. tagSource: (q) => q.tag.map((tag) => Sources.tag(tag)), csvSource: (q) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.string("csv(").skip(parsimmon_umd_minExports.optWhitespace), q.string, parsimmon_umd_minExports.string(")"), (_1, path, _2) => Sources.csv(path)), linkIncomingSource: (q) => q.link.map((link) => Sources.link(link.path, true)), linkOutgoingSource: (q) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.string("outgoing(").skip(parsimmon_umd_minExports.optWhitespace), q.link, parsimmon_umd_minExports.string(")"), (_1, link, _2) => Sources.link(link.path, false)), folderSource: (q) => q.string.map((str) => Sources.folder(str)), parensSource: (q) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.string("("), parsimmon_umd_minExports.optWhitespace, q.source, parsimmon_umd_minExports.optWhitespace, parsimmon_umd_minExports.string(")"), (_1, _2, field, _3, _4) => field), negateSource: (q) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.alt(parsimmon_umd_minExports.string("-"), parsimmon_umd_minExports.string("!")), q.atomSource, (_, source) => Sources.negate(source)), atomSource: (q) => parsimmon_umd_minExports.alt(q.parensSource, q.negateSource, q.linkOutgoingSource, q.linkIncomingSource, q.folderSource, q.tagSource, q.csvSource), binaryOpSource: (q) => createBinaryParser(q.atomSource, q.binaryBooleanOp.map((s2) => s2), Sources.binaryOp), source: (q) => q.binaryOpSource, // Field parsing. variableField: (q) => q.identifier.chain((r) => { if (KEYWORDS.includes(r.toUpperCase())) { return parsimmon_umd_minExports.fail("Variable fields cannot be a keyword (" + KEYWORDS.join(" or ") + ")"); } else { return parsimmon_umd_minExports.succeed(Fields.variable(r)); } }).desc("variable"), numberField: (q) => q.number.map((val) => Fields.literal(val)).desc("number"), stringField: (q) => q.string.map((val) => Fields.literal(val)).desc("string"), boolField: (q) => q.bool.map((val) => Fields.literal(val)).desc("boolean"), dateField: (q) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.string("date("), parsimmon_umd_minExports.optWhitespace, q.datePlus, parsimmon_umd_minExports.optWhitespace, parsimmon_umd_minExports.string(")"), (prefix, _1, date, _2, postfix) => Fields.literal(date)).desc("date"), durationField: (q) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.string("dur("), parsimmon_umd_minExports.optWhitespace, q.duration, parsimmon_umd_minExports.optWhitespace, parsimmon_umd_minExports.string(")"), (prefix, _1, dur, _2, postfix) => Fields.literal(dur)).desc("duration"), nullField: (q) => q.rawNull.map((_) => Fields.NULL), linkField: (q) => q.link.map((f) => Fields.literal(f)), listField: (q) => q.field.sepBy(parsimmon_umd_minExports.string(",").trim(parsimmon_umd_minExports.optWhitespace)).wrap(parsimmon_umd_minExports.string("[").skip(parsimmon_umd_minExports.optWhitespace), parsimmon_umd_minExports.optWhitespace.then(parsimmon_umd_minExports.string("]"))).map((l2) => Fields.list(l2)).desc("list ('[1, 2, 3]')"), objectField: (q) => parsimmon_umd_minExports.seqMap(q.identifier.or(q.string), parsimmon_umd_minExports.string(":").trim(parsimmon_umd_minExports.optWhitespace), q.field, (name, _sep, value) => { return { name, value }; }).sepBy(parsimmon_umd_minExports.string(",").trim(parsimmon_umd_minExports.optWhitespace)).wrap(parsimmon_umd_minExports.string("{").skip(parsimmon_umd_minExports.optWhitespace), parsimmon_umd_minExports.optWhitespace.then(parsimmon_umd_minExports.string("}"))).map((vals) => { let res = {}; for (let entry of vals) res[entry.name] = entry.value; return Fields.object(res); }).desc("object ('{ a: 1, b: 2 }')"), atomInlineField: (q) => parsimmon_umd_minExports.alt(q.date, q.duration.map((d) => normalizeDuration(d)), q.string, q.tag, q.embedLink, q.bool, q.number, q.rawNull), inlineFieldList: (q) => q.atomInlineField.sepBy(parsimmon_umd_minExports.string(",").trim(parsimmon_umd_minExports.optWhitespace).lookahead(q.atomInlineField)), inlineField: (q) => parsimmon_umd_minExports.alt(parsimmon_umd_minExports.seqMap(q.atomInlineField, parsimmon_umd_minExports.string(",").trim(parsimmon_umd_minExports.optWhitespace), q.inlineFieldList, (f, _s, l2) => [f].concat(l2)), q.atomInlineField), atomField: (q) => parsimmon_umd_minExports.alt( // Place embed links above negated fields as they are the special parser case '![[thing]]' and are generally unambigious. q.embedLink.map((l2) => Fields.literal(l2)), q.negatedField, q.linkField, q.listField, q.objectField, q.lambdaField, q.parensField, q.boolField, q.numberField, q.stringField, q.dateField, q.durationField, q.nullField, q.variableField ), indexField: (q) => parsimmon_umd_minExports.seqMap(q.atomField, parsimmon_umd_minExports.alt(q.dotPostfix, q.indexPostfix, q.functionPostfix).many(), (obj, postfixes) => { let result = obj; for (let post of postfixes) { switch (post.type) { case "dot": result = Fields.index(result, Fields.literal(post.field)); break; case "index": result = Fields.index(result, post.field); break; case "function": result = Fields.func(result, post.fields); break; } } return result; }), negatedField: (q) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.string("!"), q.indexField, (_, field) => Fields.negate(field)).desc("negated field"), parensField: (q) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.string("("), parsimmon_umd_minExports.optWhitespace, q.field, parsimmon_umd_minExports.optWhitespace, parsimmon_umd_minExports.string(")"), (_1, _2, field, _3, _4) => field), lambdaField: (q) => parsimmon_umd_minExports.seqMap(q.identifier.sepBy(parsimmon_umd_minExports.string(",").trim(parsimmon_umd_minExports.optWhitespace)).wrap(parsimmon_umd_minExports.string("(").trim(parsimmon_umd_minExports.optWhitespace), parsimmon_umd_minExports.string(")").trim(parsimmon_umd_minExports.optWhitespace)), parsimmon_umd_minExports.string("=>").trim(parsimmon_umd_minExports.optWhitespace), q.field, (ident, _ignore, value) => { return { type: "lambda", arguments: ident, value }; }), dotPostfix: (q) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.string("."), q.identifier, (_, field) => { return { type: "dot", field }; }), indexPostfix: (q) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.string("["), parsimmon_umd_minExports.optWhitespace, q.field, parsimmon_umd_minExports.optWhitespace, parsimmon_umd_minExports.string("]"), (_, _2, field, _3, _4) => { return { type: "index", field }; }), functionPostfix: (q) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.string("("), parsimmon_umd_minExports.optWhitespace, q.field.sepBy(parsimmon_umd_minExports.string(",").trim(parsimmon_umd_minExports.optWhitespace)), parsimmon_umd_minExports.optWhitespace, parsimmon_umd_minExports.string(")"), (_, _1, fields, _2, _3) => { return { type: "function", fields }; }), // The precedence hierarchy of operators - multiply/divide, add/subtract, compare, and then boolean operations. binaryMulDivField: (q) => createBinaryParser(q.indexField, q.binaryMulDiv, Fields.binaryOp), binaryPlusMinusField: (q) => createBinaryParser(q.binaryMulDivField, q.binaryPlusMinus, Fields.binaryOp), binaryCompareField: (q) => createBinaryParser(q.binaryPlusMinusField, q.binaryCompareOp, Fields.binaryOp), binaryBooleanField: (q) => createBinaryParser(q.binaryCompareField, q.binaryBooleanOp, Fields.binaryOp), binaryOpField: (q) => q.binaryBooleanField, field: (q) => q.binaryOpField }); function parseField(text) { try { return Result.success(EXPRESSION.field.tryParse(text)); } catch (error) { return Result.failure("" + error); } } var QueryFields; (function(QueryFields2) { function named(name, field) { return { name, field }; } QueryFields2.named = named; function sortBy(field, dir) { return { field, direction: dir }; } QueryFields2.sortBy = sortBy; })(QueryFields || (QueryFields = {})); function captureRaw(base) { return parsimmon_umd_minExports.custom((success, failure) => { return (input, i) => { let result = base._(input, i); if (!result.status) return result; return Object.assign({}, result, { value: [result.value, input.substring(i, result.index)] }); }; }); } function stripNewlines(text) { return text.split(/[\r\n]+/).map((t) => t.trim()).join(""); } function precededByWhitespaceIfNotEof(if_eof, parser) { return parsimmon_umd_minExports.eof.map(if_eof).or(parsimmon_umd_minExports.whitespace.then(parser)); } var QUERY_LANGUAGE = parsimmon_umd_minExports.createLanguage({ // Simple atom parsing, like words, identifiers, numbers. queryType: (q) => parsimmon_umd_minExports.alt(parsimmon_umd_minExports.regexp(/TABLE|LIST|TASK|CALENDAR/i)).map((str) => str.toLowerCase()).desc("query type ('TABLE', 'LIST', 'TASK', or 'CALENDAR')"), explicitNamedField: (q) => parsimmon_umd_minExports.seqMap(EXPRESSION.field.skip(parsimmon_umd_minExports.whitespace), parsimmon_umd_minExports.regexp(/AS/i).skip(parsimmon_umd_minExports.whitespace), EXPRESSION.identifier.or(EXPRESSION.string), (field, _as, ident) => QueryFields.named(ident, field)), namedField: (q) => parsimmon_umd_minExports.alt(q.explicitNamedField, captureRaw(EXPRESSION.field).map(([value, text]) => QueryFields.named(stripNewlines(text), value))), sortField: (q) => parsimmon_umd_minExports.seqMap(EXPRESSION.field.skip(parsimmon_umd_minExports.optWhitespace), parsimmon_umd_minExports.regexp(/ASCENDING|DESCENDING|ASC|DESC/i).atMost(1), (field, dir) => { let direction = dir.length == 0 ? "ascending" : dir[0].toLowerCase(); if (direction == "desc") direction = "descending"; if (direction == "asc") direction = "ascending"; return { field, direction }; }), headerClause: (q) => q.queryType.chain((type) => { switch (type) { case "table": { return precededByWhitespaceIfNotEof(() => ({ type, fields: [], showId: true }), parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.regexp(/WITHOUT\s+ID/i).skip(parsimmon_umd_minExports.optWhitespace).atMost(1), parsimmon_umd_minExports.sepBy(q.namedField, parsimmon_umd_minExports.string(",").trim(parsimmon_umd_minExports.optWhitespace)), (withoutId, fields) => { return { type, fields, showId: withoutId.length == 0 }; })); } case "list": return precededByWhitespaceIfNotEof(() => ({ type, format: void 0, showId: true }), parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.regexp(/WITHOUT\s+ID/i).skip(parsimmon_umd_minExports.optWhitespace).atMost(1), EXPRESSION.field.atMost(1), (withoutId, format2) => { return { type, format: format2.length == 1 ? format2[0] : void 0, showId: withoutId.length == 0 }; })); case "task": return parsimmon_umd_minExports.succeed({ type }); case "calendar": return parsimmon_umd_minExports.whitespace.then(parsimmon_umd_minExports.seqMap(q.namedField, (field) => { return { type, showId: true, field }; })); default: return parsimmon_umd_minExports.fail(`Unrecognized query type '${type}'`); } }).desc("TABLE or LIST or TASK or CALENDAR"), fromClause: (q) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.regexp(/FROM/i), parsimmon_umd_minExports.whitespace, EXPRESSION.source, (_1, _2, source) => source), whereClause: (q) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.regexp(/WHERE/i), parsimmon_umd_minExports.whitespace, EXPRESSION.field, (where, _, field) => { return { type: "where", clause: field }; }).desc("WHERE "), sortByClause: (q) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.regexp(/SORT/i), parsimmon_umd_minExports.whitespace, q.sortField.sepBy1(parsimmon_umd_minExports.string(",").trim(parsimmon_umd_minExports.optWhitespace)), (sort, _1, fields) => { return { type: "sort", fields }; }).desc("SORT field [ASC/DESC]"), limitClause: (q) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.regexp(/LIMIT/i), parsimmon_umd_minExports.whitespace, EXPRESSION.field, (limit, _1, field) => { return { type: "limit", amount: field }; }).desc("LIMIT "), flattenClause: (q) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.regexp(/FLATTEN/i).skip(parsimmon_umd_minExports.whitespace), q.namedField, (_, field) => { return { type: "flatten", field }; }).desc("FLATTEN [AS ]"), groupByClause: (q) => parsimmon_umd_minExports.seqMap(parsimmon_umd_minExports.regexp(/GROUP BY/i).skip(parsimmon_umd_minExports.whitespace), q.namedField, (_, field) => { return { type: "group", field }; }).desc("GROUP BY [AS ]"), // Full query parsing. clause: (q) => parsimmon_umd_minExports.alt(q.fromClause, q.whereClause, q.sortByClause, q.limitClause, q.groupByClause, q.flattenClause), query: (q) => parsimmon_umd_minExports.seqMap(q.headerClause.trim(parsimmon_umd_minExports.optWhitespace), q.fromClause.trim(parsimmon_umd_minExports.optWhitespace).atMost(1), q.clause.trim(parsimmon_umd_minExports.optWhitespace).many(), (header, from, clauses) => { return { header, source: from.length == 0 ? Sources.folder("") : from[0], operations: clauses, settings: DEFAULT_QUERY_SETTINGS }; }) }); var getAPI2 = (app2) => { var _a3; if (app2) return (_a3 = app2.plugins.plugins.dataview) === null || _a3 === void 0 ? void 0 : _a3.api; else return window.DataviewAPI; }; var isPluginEnabled = (app2) => app2.plugins.enabledPlugins.has("dataview"); exports.DATE_SHORTHANDS = DATE_SHORTHANDS; exports.DURATION_TYPES = DURATION_TYPES; exports.EXPRESSION = EXPRESSION; exports.KEYWORDS = KEYWORDS; exports.QUERY_LANGUAGE = QUERY_LANGUAGE; exports.getAPI = getAPI2; exports.isPluginEnabled = isPluginEnabled; exports.parseField = parseField; } }); // node_modules/ngraph.events/index.js var require_ngraph = __commonJS({ "node_modules/ngraph.events/index.js"(exports, module2) { module2.exports = function eventify(subject) { validateSubject(subject); var eventsStorage = createEventsStorage(subject); subject.on = eventsStorage.on; subject.off = eventsStorage.off; subject.fire = eventsStorage.fire; return subject; }; function createEventsStorage(subject) { var registeredEvents = /* @__PURE__ */ Object.create(null); return { on: function(eventName, callback, ctx) { if (typeof callback !== "function") { throw new Error("callback is expected to be a function"); } var handlers = registeredEvents[eventName]; if (!handlers) { handlers = registeredEvents[eventName] = []; } handlers.push({ callback, ctx }); return subject; }, off: function(eventName, callback) { var wantToRemoveAll = typeof eventName === "undefined"; if (wantToRemoveAll) { registeredEvents = /* @__PURE__ */ Object.create(null); return subject; } if (registeredEvents[eventName]) { var deleteAllCallbacksForEvent = typeof callback !== "function"; if (deleteAllCallbacksForEvent) { delete registeredEvents[eventName]; } else { var callbacks = registeredEvents[eventName]; for (var i = 0; i < callbacks.length; ++i) { if (callbacks[i].callback === callback) { callbacks.splice(i, 1); } } } } return subject; }, fire: function(eventName) { var callbacks = registeredEvents[eventName]; if (!callbacks) { return subject; } var fireArguments; if (arguments.length > 1) { fireArguments = Array.prototype.splice.call(arguments, 1); } for (var i = 0; i < callbacks.length; ++i) { var callbackInfo = callbacks[i]; callbackInfo.callback.apply(callbackInfo.ctx, fireArguments); } return subject; } }; } function validateSubject(subject) { if (!subject) { throw new Error("Eventify cannot use falsy object as events subject"); } var reservedWords = ["on", "fire", "off"]; for (var i = 0; i < reservedWords.length; ++i) { if (subject.hasOwnProperty(reservedWords[i])) { throw new Error("Subject cannot be eventified, since it already has property '" + reservedWords[i] + "'"); } } } } }); // node_modules/ngraph.graph/index.js var require_ngraph2 = __commonJS({ "node_modules/ngraph.graph/index.js"(exports, module2) { module2.exports = createGraph; var eventify = require_ngraph(); function createGraph(options) { options = options || {}; if ("uniqueLinkId" in options) { console.warn( "ngraph.graph: Starting from version 0.14 `uniqueLinkId` is deprecated.\nUse `multigraph` option instead\n", "\n", "Note: there is also change in default behavior: From now on each graph\nis considered to be not a multigraph by default (each edge is unique)." ); options.multigraph = options.uniqueLinkId; } if (options.multigraph === void 0) options.multigraph = false; if (typeof Map !== "function") { throw new Error("ngraph.graph requires `Map` to be defined. Please polyfill it before using ngraph"); } var nodes = /* @__PURE__ */ new Map(); var links = /* @__PURE__ */ new Map(); var multiEdges = {}; var suspendEvents = 0; var createLink = options.multigraph ? createUniqueLink : createSingleLink, changes = [], recordLinkChange = noop2, recordNodeChange = noop2, enterModification = noop2, exitModification = noop2; var graphPart = { /** * Sometimes duck typing could be slow. Giving clients a hint about data structure * via explicit version number here: */ version: 20, /** * Adds node to the graph. If node with given id already exists in the graph * its data is extended with whatever comes in 'data' argument. * * @param nodeId the node's identifier. A string or number is preferred. * @param [data] additional data for the node being added. If node already * exists its data object is augmented with the new one. * * @return {node} The newly added node or node with given id if it already exists. */ addNode, /** * Adds a link to the graph. The function always create a new * link between two nodes. If one of the nodes does not exists * a new node is created. * * @param fromId link start node id; * @param toId link end node id; * @param [data] additional data to be set on the new link; * * @return {link} The newly created link */ addLink, /** * Removes link from the graph. If link does not exist does nothing. * * @param link - object returned by addLink() or getLinks() methods. * * @returns true if link was removed; false otherwise. */ removeLink, /** * Removes node with given id from the graph. If node does not exist in the graph * does nothing. * * @param nodeId node's identifier passed to addNode() function. * * @returns true if node was removed; false otherwise. */ removeNode, /** * Gets node with given identifier. If node does not exist undefined value is returned. * * @param nodeId requested node identifier; * * @return {node} in with requested identifier or undefined if no such node exists. */ getNode, /** * Gets number of nodes in this graph. * * @return number of nodes in the graph. */ getNodeCount, /** * Gets total number of links in the graph. */ getLinkCount, /** * Gets total number of links in the graph. */ getEdgeCount: getLinkCount, /** * Synonym for `getLinkCount()` */ getLinksCount: getLinkCount, /** * Synonym for `getNodeCount()` */ getNodesCount: getNodeCount, /** * Gets all links (inbound and outbound) from the node with given id. * If node with given id is not found null is returned. * * @param nodeId requested node identifier. * * @return Set of links from and to requested node if such node exists; * otherwise null is returned. */ getLinks, /** * Invokes callback on each node of the graph. * * @param {Function(node)} callback Function to be invoked. The function * is passed one argument: visited node. */ forEachNode, /** * Invokes callback on every linked (adjacent) node to the given one. * * @param nodeId Identifier of the requested node. * @param {Function(node, link)} callback Function to be called on all linked nodes. * The function is passed two parameters: adjacent node and link object itself. * @param oriented if true graph treated as oriented. */ forEachLinkedNode, /** * Enumerates all links in the graph * * @param {Function(link)} callback Function to be called on all links in the graph. * The function is passed one parameter: graph's link object. * * Link object contains at least the following fields: * fromId - node id where link starts; * toId - node id where link ends, * data - additional data passed to graph.addLink() method. */ forEachLink, /** * Suspend all notifications about graph changes until * endUpdate is called. */ beginUpdate: enterModification, /** * Resumes all notifications about graph changes and fires * graph 'changed' event in case there are any pending changes. */ endUpdate: exitModification, /** * Removes all nodes and links from the graph. */ clear, /** * Detects whether there is a link between two nodes. * Operation complexity is O(n) where n - number of links of a node. * NOTE: this function is synonym for getLink() * * @returns link if there is one. null otherwise. */ hasLink: getLink, /** * Detects whether there is a node with given id * * Operation complexity is O(1) * NOTE: this function is synonym for getNode() * * @returns node if there is one; Falsy value otherwise. */ hasNode: getNode, /** * Gets an edge between two nodes. * Operation complexity is O(n) where n - number of links of a node. * * @param {string} fromId link start identifier * @param {string} toId link end identifier * * @returns link if there is one; undefined otherwise. */ getLink }; eventify(graphPart); monitorSubscribers(); return graphPart; function monitorSubscribers() { var realOn = graphPart.on; graphPart.on = on; function on() { graphPart.beginUpdate = enterModification = enterModificationReal; graphPart.endUpdate = exitModification = exitModificationReal; recordLinkChange = recordLinkChangeReal; recordNodeChange = recordNodeChangeReal; graphPart.on = realOn; return realOn.apply(graphPart, arguments); } } function recordLinkChangeReal(link, changeType) { changes.push({ link, changeType }); } function recordNodeChangeReal(node, changeType) { changes.push({ node, changeType }); } function addNode(nodeId, data) { if (nodeId === void 0) { throw new Error("Invalid node identifier"); } enterModification(); var node = getNode(nodeId); if (!node) { node = new Node2(nodeId, data); recordNodeChange(node, "add"); } else { node.data = data; recordNodeChange(node, "update"); } nodes.set(nodeId, node); exitModification(); return node; } function getNode(nodeId) { return nodes.get(nodeId); } function removeNode(nodeId) { var node = getNode(nodeId); if (!node) { return false; } enterModification(); var prevLinks = node.links; if (prevLinks) { prevLinks.forEach(removeLinkInstance); node.links = null; } nodes.delete(nodeId); recordNodeChange(node, "remove"); exitModification(); return true; } function addLink(fromId, toId, data) { enterModification(); var fromNode = getNode(fromId) || addNode(fromId); var toNode = getNode(toId) || addNode(toId); var link = createLink(fromId, toId, data); var isUpdate = links.has(link.id); links.set(link.id, link); addLinkToNode(fromNode, link); if (fromId !== toId) { addLinkToNode(toNode, link); } recordLinkChange(link, isUpdate ? "update" : "add"); exitModification(); return link; } function createSingleLink(fromId, toId, data) { var linkId = makeLinkId(fromId, toId); var prevLink = links.get(linkId); if (prevLink) { prevLink.data = data; return prevLink; } return new Link2(fromId, toId, data, linkId); } function createUniqueLink(fromId, toId, data) { var linkId = makeLinkId(fromId, toId); var isMultiEdge = multiEdges.hasOwnProperty(linkId); if (isMultiEdge || getLink(fromId, toId)) { if (!isMultiEdge) { multiEdges[linkId] = 0; } var suffix = "@" + ++multiEdges[linkId]; linkId = makeLinkId(fromId + suffix, toId + suffix); } return new Link2(fromId, toId, data, linkId); } function getNodeCount() { return nodes.size; } function getLinkCount() { return links.size; } function getLinks(nodeId) { var node = getNode(nodeId); return node ? node.links : null; } function removeLink(link, otherId) { if (otherId !== void 0) { link = getLink(link, otherId); } return removeLinkInstance(link); } function removeLinkInstance(link) { if (!link) { return false; } if (!links.get(link.id)) return false; enterModification(); links.delete(link.id); var fromNode = getNode(link.fromId); var toNode = getNode(link.toId); if (fromNode) { fromNode.links.delete(link); } if (toNode) { toNode.links.delete(link); } recordLinkChange(link, "remove"); exitModification(); return true; } function getLink(fromNodeId, toNodeId) { if (fromNodeId === void 0 || toNodeId === void 0) return void 0; return links.get(makeLinkId(fromNodeId, toNodeId)); } function clear() { enterModification(); forEachNode(function(node) { removeNode(node.id); }); exitModification(); } function forEachLink(callback) { if (typeof callback === "function") { var valuesIterator = links.values(); var nextValue = valuesIterator.next(); while (!nextValue.done) { if (callback(nextValue.value)) { return true; } nextValue = valuesIterator.next(); } } } function forEachLinkedNode(nodeId, callback, oriented) { var node = getNode(nodeId); if (node && node.links && typeof callback === "function") { if (oriented) { return forEachOrientedLink(node.links, nodeId, callback); } else { return forEachNonOrientedLink(node.links, nodeId, callback); } } } function forEachNonOrientedLink(links2, nodeId, callback) { var quitFast; var valuesIterator = links2.values(); var nextValue = valuesIterator.next(); while (!nextValue.done) { var link = nextValue.value; var linkedNodeId = link.fromId === nodeId ? link.toId : link.fromId; quitFast = callback(nodes.get(linkedNodeId), link); if (quitFast) { return true; } nextValue = valuesIterator.next(); } } function forEachOrientedLink(links2, nodeId, callback) { var quitFast; var valuesIterator = links2.values(); var nextValue = valuesIterator.next(); while (!nextValue.done) { var link = nextValue.value; if (link.fromId === nodeId) { quitFast = callback(nodes.get(link.toId), link); if (quitFast) { return true; } } nextValue = valuesIterator.next(); } } function noop2() { } function enterModificationReal() { suspendEvents += 1; } function exitModificationReal() { suspendEvents -= 1; if (suspendEvents === 0 && changes.length > 0) { graphPart.fire("changed", changes); changes.length = 0; } } function forEachNode(callback) { if (typeof callback !== "function") { throw new Error("Function is expected to iterate over graph nodes. You passed " + callback); } var valuesIterator = nodes.values(); var nextValue = valuesIterator.next(); while (!nextValue.done) { if (callback(nextValue.value)) { return true; } nextValue = valuesIterator.next(); } } } function Node2(id, data) { this.id = id; this.links = null; this.data = data; } function addLinkToNode(node, link) { if (node.links) { node.links.add(link); } else { node.links = /* @__PURE__ */ new Set([link]); } } function Link2(fromId, toId, data, id) { this.fromId = fromId; this.toId = toId; this.data = data; this.id = id; } function makeLinkId(fromId, toId) { return fromId.toString() + "\u{1F449} " + toId.toString(); } } }); // node_modules/ngraph.forcelayout/lib/codeGenerators/getVariableName.js var require_getVariableName = __commonJS({ "node_modules/ngraph.forcelayout/lib/codeGenerators/getVariableName.js"(exports, module2) { module2.exports = function getVariableName(index6) { if (index6 === 0) return "x"; if (index6 === 1) return "y"; if (index6 === 2) return "z"; return "c" + (index6 + 1); }; } }); // node_modules/ngraph.forcelayout/lib/codeGenerators/createPatternBuilder.js var require_createPatternBuilder = __commonJS({ "node_modules/ngraph.forcelayout/lib/codeGenerators/createPatternBuilder.js"(exports, module2) { var getVariableName = require_getVariableName(); module2.exports = function createPatternBuilder(dimension) { return pattern; function pattern(template, config2) { let indent = config2 && config2.indent || 0; let join = config2 && config2.join !== void 0 ? config2.join : "\n"; let indentString = Array(indent + 1).join(" "); let buffer = []; for (let i = 0; i < dimension; ++i) { let variableName = getVariableName(i); let prefix = i === 0 ? "" : indentString; buffer.push(prefix + template.replace(/{var}/g, variableName)); } return buffer.join(join); } }; } }); // node_modules/ngraph.forcelayout/lib/codeGenerators/generateCreateBody.js var require_generateCreateBody = __commonJS({ "node_modules/ngraph.forcelayout/lib/codeGenerators/generateCreateBody.js"(exports, module2) { var createPatternBuilder = require_createPatternBuilder(); module2.exports = generateCreateBodyFunction; module2.exports.generateCreateBodyFunctionBody = generateCreateBodyFunctionBody; module2.exports.getVectorCode = getVectorCode; module2.exports.getBodyCode = getBodyCode; function generateCreateBodyFunction(dimension, debugSetters) { let code = generateCreateBodyFunctionBody(dimension, debugSetters); let { Body } = new Function(code)(); return Body; } function generateCreateBodyFunctionBody(dimension, debugSetters) { let code = ` ${getVectorCode(dimension, debugSetters)} ${getBodyCode(dimension, debugSetters)} return {Body: Body, Vector: Vector}; `; return code; } function getBodyCode(dimension) { let pattern = createPatternBuilder(dimension); let variableList = pattern("{var}", { join: ", " }); return ` function Body(${variableList}) { this.isPinned = false; this.pos = new Vector(${variableList}); this.force = new Vector(); this.velocity = new Vector(); this.mass = 1; this.springCount = 0; this.springLength = 0; } Body.prototype.reset = function() { this.force.reset(); this.springCount = 0; this.springLength = 0; } Body.prototype.setPosition = function (${variableList}) { ${pattern("this.pos.{var} = {var} || 0;", { indent: 2 })} };`; } function getVectorCode(dimension, debugSetters) { let pattern = createPatternBuilder(dimension); let setters = ""; if (debugSetters) { setters = `${pattern("\n var v{var};\nObject.defineProperty(this, '{var}', {\n set: function(v) { \n if (!Number.isFinite(v)) throw new Error('Cannot set non-numbers to {var}');\n v{var} = v; \n },\n get: function() { return v{var}; }\n});")}`; } let variableList = pattern("{var}", { join: ", " }); return `function Vector(${variableList}) { ${setters} if (typeof arguments[0] === 'object') { // could be another vector let v = arguments[0]; ${pattern('if (!Number.isFinite(v.{var})) throw new Error("Expected value is not a finite number at Vector constructor ({var})");', { indent: 4 })} ${pattern("this.{var} = v.{var};", { indent: 4 })} } else { ${pattern('this.{var} = typeof {var} === "number" ? {var} : 0;', { indent: 4 })} } } Vector.prototype.reset = function () { ${pattern("this.{var} = ", { join: "" })}0; };`; } } }); // node_modules/ngraph.forcelayout/lib/codeGenerators/generateQuadTree.js var require_generateQuadTree = __commonJS({ "node_modules/ngraph.forcelayout/lib/codeGenerators/generateQuadTree.js"(exports, module2) { var createPatternBuilder = require_createPatternBuilder(); var getVariableName = require_getVariableName(); module2.exports = generateQuadTreeFunction; module2.exports.generateQuadTreeFunctionBody = generateQuadTreeFunctionBody; module2.exports.getInsertStackCode = getInsertStackCode; module2.exports.getQuadNodeCode = getQuadNodeCode; module2.exports.isSamePosition = isSamePosition; module2.exports.getChildBodyCode = getChildBodyCode; module2.exports.setChildBodyCode = setChildBodyCode; function generateQuadTreeFunction(dimension) { let code = generateQuadTreeFunctionBody(dimension); return new Function(code)(); } function generateQuadTreeFunctionBody(dimension) { let pattern = createPatternBuilder(dimension); let quadCount = Math.pow(2, dimension); let code = ` ${getInsertStackCode()} ${getQuadNodeCode(dimension)} ${isSamePosition(dimension)} ${getChildBodyCode(dimension)} ${setChildBodyCode(dimension)} function createQuadTree(options, random) { options = options || {}; options.gravity = typeof options.gravity === 'number' ? options.gravity : -1; options.theta = typeof options.theta === 'number' ? options.theta : 0.8; var gravity = options.gravity; var updateQueue = []; var insertStack = new InsertStack(); var theta = options.theta; var nodesCache = []; var currentInCache = 0; var root = newNode(); return { insertBodies: insertBodies, /** * Gets root node if it is present */ getRoot: function() { return root; }, updateBodyForce: update, options: function(newOptions) { if (newOptions) { if (typeof newOptions.gravity === 'number') { gravity = newOptions.gravity; } if (typeof newOptions.theta === 'number') { theta = newOptions.theta; } return this; } return { gravity: gravity, theta: theta }; } }; function newNode() { // To avoid pressure on GC we reuse nodes. var node = nodesCache[currentInCache]; if (node) { ${assignQuads(" node.")} node.body = null; node.mass = ${pattern("node.mass_{var} = ", { join: "" })}0; ${pattern("node.min_{var} = node.max_{var} = ", { join: "" })}0; } else { node = new QuadNode(); nodesCache[currentInCache] = node; } ++currentInCache; return node; } function update(sourceBody) { var queue = updateQueue; var v; ${pattern("var d{var};", { indent: 4 })} var r; ${pattern("var f{var} = 0;", { indent: 4 })} var queueLength = 1; var shiftIdx = 0; var pushIdx = 1; queue[0] = root; while (queueLength) { var node = queue[shiftIdx]; var body = node.body; queueLength -= 1; shiftIdx += 1; var differentBody = (body !== sourceBody); if (body && differentBody) { // If the current node is a leaf node (and it is not source body), // calculate the force exerted by the current node on body, and add this // amount to body's net force. ${pattern("d{var} = body.pos.{var} - sourceBody.pos.{var};", { indent: 8 })} r = Math.sqrt(${pattern("d{var} * d{var}", { join: " + " })}); if (r === 0) { // Poor man's protection against zero distance. ${pattern("d{var} = (random.nextDouble() - 0.5) / 50;", { indent: 10 })} r = Math.sqrt(${pattern("d{var} * d{var}", { join: " + " })}); } // This is standard gravitation force calculation but we divide // by r^3 to save two operations when normalizing force vector. v = gravity * body.mass * sourceBody.mass / (r * r * r); ${pattern("f{var} += v * d{var};", { indent: 8 })} } else if (differentBody) { // Otherwise, calculate the ratio s / r, where s is the width of the region // represented by the internal node, and r is the distance between the body // and the node's center-of-mass ${pattern("d{var} = node.mass_{var} / node.mass - sourceBody.pos.{var};", { indent: 8 })} r = Math.sqrt(${pattern("d{var} * d{var}", { join: " + " })}); if (r === 0) { // Sorry about code duplication. I don't want to create many functions // right away. Just want to see performance first. ${pattern("d{var} = (random.nextDouble() - 0.5) / 50;", { indent: 10 })} r = Math.sqrt(${pattern("d{var} * d{var}", { join: " + " })}); } // If s / r < \u03B8, treat this internal node as a single body, and calculate the // force it exerts on sourceBody, and add this amount to sourceBody's net force. if ((node.max_${getVariableName(0)} - node.min_${getVariableName(0)}) / r < theta) { // in the if statement above we consider node's width only // because the region was made into square during tree creation. // Thus there is no difference between using width or height. v = gravity * node.mass * sourceBody.mass / (r * r * r); ${pattern("f{var} += v * d{var};", { indent: 10 })} } else { // Otherwise, run the procedure recursively on each of the current node's children. // I intentionally unfolded this loop, to save several CPU cycles. ${runRecursiveOnChildren()} } } } ${pattern("sourceBody.force.{var} += f{var};", { indent: 4 })} } function insertBodies(bodies) { ${pattern("var {var}min = Number.MAX_VALUE;", { indent: 4 })} ${pattern("var {var}max = Number.MIN_VALUE;", { indent: 4 })} var i = bodies.length; // To reduce quad tree depth we are looking for exact bounding box of all particles. while (i--) { var pos = bodies[i].pos; ${pattern("if (pos.{var} < {var}min) {var}min = pos.{var};", { indent: 6 })} ${pattern("if (pos.{var} > {var}max) {var}max = pos.{var};", { indent: 6 })} } // Makes the bounds square. var maxSideLength = -Infinity; ${pattern("if ({var}max - {var}min > maxSideLength) maxSideLength = {var}max - {var}min ;", { indent: 4 })} currentInCache = 0; root = newNode(); ${pattern("root.min_{var} = {var}min;", { indent: 4 })} ${pattern("root.max_{var} = {var}min + maxSideLength;", { indent: 4 })} i = bodies.length - 1; if (i >= 0) { root.body = bodies[i]; } while (i--) { insert(bodies[i], root); } } function insert(newBody) { insertStack.reset(); insertStack.push(root, newBody); while (!insertStack.isEmpty()) { var stackItem = insertStack.pop(); var node = stackItem.node; var body = stackItem.body; if (!node.body) { // This is internal node. Update the total mass of the node and center-of-mass. ${pattern("var {var} = body.pos.{var};", { indent: 8 })} node.mass += body.mass; ${pattern("node.mass_{var} += body.mass * {var};", { indent: 8 })} // Recursively insert the body in the appropriate quadrant. // But first find the appropriate quadrant. var quadIdx = 0; // Assume we are in the 0's quad. ${pattern("var min_{var} = node.min_{var};", { indent: 8 })} ${pattern("var max_{var} = (min_{var} + node.max_{var}) / 2;", { indent: 8 })} ${assignInsertionQuadIndex(8)} var child = getChild(node, quadIdx); if (!child) { // The node is internal but this quadrant is not taken. Add // subnode to it. child = newNode(); ${pattern("child.min_{var} = min_{var};", { indent: 10 })} ${pattern("child.max_{var} = max_{var};", { indent: 10 })} child.body = body; setChild(node, quadIdx, child); } else { // continue searching in this quadrant. insertStack.push(child, body); } } else { // We are trying to add to the leaf node. // We have to convert current leaf into internal node // and continue adding two nodes. var oldBody = node.body; node.body = null; // internal nodes do not cary bodies if (isSamePosition(oldBody.pos, body.pos)) { // Prevent infinite subdivision by bumping one node // anywhere in this quadrant var retriesCount = 3; do { var offset = random.nextDouble(); ${pattern("var d{var} = (node.max_{var} - node.min_{var}) * offset;", { indent: 12 })} ${pattern("oldBody.pos.{var} = node.min_{var} + d{var};", { indent: 12 })} retriesCount -= 1; // Make sure we don't bump it out of the box. If we do, next iteration should fix it } while (retriesCount > 0 && isSamePosition(oldBody.pos, body.pos)); if (retriesCount === 0 && isSamePosition(oldBody.pos, body.pos)) { // This is very bad, we ran out of precision. // if we do not return from the method we'll get into // infinite loop here. So we sacrifice correctness of layout, and keep the app running // Next layout iteration should get larger bounding box in the first step and fix this return; } } // Next iteration should subdivide node further. insertStack.push(node, oldBody); insertStack.push(node, body); } } } } return createQuadTree; `; return code; function assignInsertionQuadIndex(indentCount) { let insertionCode = []; let indent = Array(indentCount + 1).join(" "); for (let i = 0; i < dimension; ++i) { insertionCode.push(indent + `if (${getVariableName(i)} > max_${getVariableName(i)}) {`); insertionCode.push(indent + ` quadIdx = quadIdx + ${Math.pow(2, i)};`); insertionCode.push(indent + ` min_${getVariableName(i)} = max_${getVariableName(i)};`); insertionCode.push(indent + ` max_${getVariableName(i)} = node.max_${getVariableName(i)};`); insertionCode.push(indent + `}`); } return insertionCode.join("\n"); } function runRecursiveOnChildren() { let indent = Array(11).join(" "); let recursiveCode = []; for (let i = 0; i < quadCount; ++i) { recursiveCode.push(indent + `if (node.quad${i}) {`); recursiveCode.push(indent + ` queue[pushIdx] = node.quad${i};`); recursiveCode.push(indent + ` queueLength += 1;`); recursiveCode.push(indent + ` pushIdx += 1;`); recursiveCode.push(indent + `}`); } return recursiveCode.join("\n"); } function assignQuads(indent) { let quads = []; for (let i = 0; i < quadCount; ++i) { quads.push(`${indent}quad${i} = null;`); } return quads.join("\n"); } } function isSamePosition(dimension) { let pattern = createPatternBuilder(dimension); return ` function isSamePosition(point1, point2) { ${pattern("var d{var} = Math.abs(point1.{var} - point2.{var});", { indent: 2 })} return ${pattern("d{var} < 1e-8", { join: " && " })}; } `; } function setChildBodyCode(dimension) { var quadCount = Math.pow(2, dimension); return ` function setChild(node, idx, child) { ${setChildBody()} }`; function setChildBody() { let childBody = []; for (let i = 0; i < quadCount; ++i) { let prefix = i === 0 ? " " : " else "; childBody.push(`${prefix}if (idx === ${i}) node.quad${i} = child;`); } return childBody.join("\n"); } } function getChildBodyCode(dimension) { return `function getChild(node, idx) { ${getChildBody()} return null; }`; function getChildBody() { let childBody = []; let quadCount = Math.pow(2, dimension); for (let i = 0; i < quadCount; ++i) { childBody.push(` if (idx === ${i}) return node.quad${i};`); } return childBody.join("\n"); } } function getQuadNodeCode(dimension) { let pattern = createPatternBuilder(dimension); let quadCount = Math.pow(2, dimension); var quadNodeCode = ` function QuadNode() { // body stored inside this node. In quad tree only leaf nodes (by construction) // contain bodies: this.body = null; // Child nodes are stored in quads. Each quad is presented by number: // 0 | 1 // ----- // 2 | 3 ${assignQuads(" this.")} // Total mass of current node this.mass = 0; // Center of mass coordinates ${pattern("this.mass_{var} = 0;", { indent: 2 })} // bounding box coordinates ${pattern("this.min_{var} = 0;", { indent: 2 })} ${pattern("this.max_{var} = 0;", { indent: 2 })} } `; return quadNodeCode; function assignQuads(indent) { let quads = []; for (let i = 0; i < quadCount; ++i) { quads.push(`${indent}quad${i} = null;`); } return quads.join("\n"); } } function getInsertStackCode() { return ` /** * Our implementation of QuadTree is non-recursive to avoid GC hit * This data structure represent stack of elements * which we are trying to insert into quad tree. */ function InsertStack () { this.stack = []; this.popIdx = 0; } InsertStack.prototype = { isEmpty: function() { return this.popIdx === 0; }, push: function (node, body) { var item = this.stack[this.popIdx]; if (!item) { // we are trying to avoid memory pressure: create new element // only when absolutely necessary this.stack[this.popIdx] = new InsertStackElement(node, body); } else { item.node = node; item.body = body; } ++this.popIdx; }, pop: function () { if (this.popIdx > 0) { return this.stack[--this.popIdx]; } }, reset: function () { this.popIdx = 0; } }; function InsertStackElement(node, body) { this.node = node; // QuadTree node this.body = body; // physical body which needs to be inserted to node } `; } } }); // node_modules/ngraph.forcelayout/lib/codeGenerators/generateBounds.js var require_generateBounds = __commonJS({ "node_modules/ngraph.forcelayout/lib/codeGenerators/generateBounds.js"(exports, module2) { module2.exports = generateBoundsFunction; module2.exports.generateFunctionBody = generateBoundsFunctionBody; var createPatternBuilder = require_createPatternBuilder(); function generateBoundsFunction(dimension) { let code = generateBoundsFunctionBody(dimension); return new Function("bodies", "settings", "random", code); } function generateBoundsFunctionBody(dimension) { let pattern = createPatternBuilder(dimension); let code = ` var boundingBox = { ${pattern("min_{var}: 0, max_{var}: 0,", { indent: 4 })} }; return { box: boundingBox, update: updateBoundingBox, reset: resetBoundingBox, getBestNewPosition: function (neighbors) { var ${pattern("base_{var} = 0", { join: ", " })}; if (neighbors.length) { for (var i = 0; i < neighbors.length; ++i) { let neighborPos = neighbors[i].pos; ${pattern("base_{var} += neighborPos.{var};", { indent: 10 })} } ${pattern("base_{var} /= neighbors.length;", { indent: 8 })} } else { ${pattern("base_{var} = (boundingBox.min_{var} + boundingBox.max_{var}) / 2;", { indent: 8 })} } var springLength = settings.springLength; return { ${pattern("{var}: base_{var} + (random.nextDouble() - 0.5) * springLength,", { indent: 8 })} }; } }; function updateBoundingBox() { var i = bodies.length; if (i === 0) return; // No bodies - no borders. ${pattern("var max_{var} = -Infinity;", { indent: 4 })} ${pattern("var min_{var} = Infinity;", { indent: 4 })} while(i--) { // this is O(n), it could be done faster with quadtree, if we check the root node bounds var bodyPos = bodies[i].pos; ${pattern("if (bodyPos.{var} < min_{var}) min_{var} = bodyPos.{var};", { indent: 6 })} ${pattern("if (bodyPos.{var} > max_{var}) max_{var} = bodyPos.{var};", { indent: 6 })} } ${pattern("boundingBox.min_{var} = min_{var};", { indent: 4 })} ${pattern("boundingBox.max_{var} = max_{var};", { indent: 4 })} } function resetBoundingBox() { ${pattern("boundingBox.min_{var} = boundingBox.max_{var} = 0;", { indent: 4 })} } `; return code; } } }); // node_modules/ngraph.forcelayout/lib/codeGenerators/generateCreateDragForce.js var require_generateCreateDragForce = __commonJS({ "node_modules/ngraph.forcelayout/lib/codeGenerators/generateCreateDragForce.js"(exports, module2) { var createPatternBuilder = require_createPatternBuilder(); module2.exports = generateCreateDragForceFunction; module2.exports.generateCreateDragForceFunctionBody = generateCreateDragForceFunctionBody; function generateCreateDragForceFunction(dimension) { let code = generateCreateDragForceFunctionBody(dimension); return new Function("options", code); } function generateCreateDragForceFunctionBody(dimension) { let pattern = createPatternBuilder(dimension); let code = ` if (!Number.isFinite(options.dragCoefficient)) throw new Error('dragCoefficient is not a finite number'); return { update: function(body) { ${pattern("body.force.{var} -= options.dragCoefficient * body.velocity.{var};", { indent: 6 })} } }; `; return code; } } }); // node_modules/ngraph.forcelayout/lib/codeGenerators/generateCreateSpringForce.js var require_generateCreateSpringForce = __commonJS({ "node_modules/ngraph.forcelayout/lib/codeGenerators/generateCreateSpringForce.js"(exports, module2) { var createPatternBuilder = require_createPatternBuilder(); module2.exports = generateCreateSpringForceFunction; module2.exports.generateCreateSpringForceFunctionBody = generateCreateSpringForceFunctionBody; function generateCreateSpringForceFunction(dimension) { let code = generateCreateSpringForceFunctionBody(dimension); return new Function("options", "random", code); } function generateCreateSpringForceFunctionBody(dimension) { let pattern = createPatternBuilder(dimension); let code = ` if (!Number.isFinite(options.springCoefficient)) throw new Error('Spring coefficient is not a number'); if (!Number.isFinite(options.springLength)) throw new Error('Spring length is not a number'); return { /** * Updates forces acting on a spring */ update: function (spring) { var body1 = spring.from; var body2 = spring.to; var length = spring.length < 0 ? options.springLength : spring.length; ${pattern("var d{var} = body2.pos.{var} - body1.pos.{var};", { indent: 6 })} var r = Math.sqrt(${pattern("d{var} * d{var}", { join: " + " })}); if (r === 0) { ${pattern("d{var} = (random.nextDouble() - 0.5) / 50;", { indent: 8 })} r = Math.sqrt(${pattern("d{var} * d{var}", { join: " + " })}); } var d = r - length; var coefficient = ((spring.coefficient > 0) ? spring.coefficient : options.springCoefficient) * d / r; ${pattern("body1.force.{var} += coefficient * d{var}", { indent: 6 })}; body1.springCount += 1; body1.springLength += r; ${pattern("body2.force.{var} -= coefficient * d{var}", { indent: 6 })}; body2.springCount += 1; body2.springLength += r; } }; `; return code; } } }); // node_modules/ngraph.forcelayout/lib/codeGenerators/generateIntegrator.js var require_generateIntegrator = __commonJS({ "node_modules/ngraph.forcelayout/lib/codeGenerators/generateIntegrator.js"(exports, module2) { var createPatternBuilder = require_createPatternBuilder(); module2.exports = generateIntegratorFunction; module2.exports.generateIntegratorFunctionBody = generateIntegratorFunctionBody; function generateIntegratorFunction(dimension) { let code = generateIntegratorFunctionBody(dimension); return new Function("bodies", "timeStep", "adaptiveTimeStepWeight", code); } function generateIntegratorFunctionBody(dimension) { let pattern = createPatternBuilder(dimension); let code = ` var length = bodies.length; if (length === 0) return 0; ${pattern("var d{var} = 0, t{var} = 0;", { indent: 2 })} for (var i = 0; i < length; ++i) { var body = bodies[i]; if (body.isPinned) continue; if (adaptiveTimeStepWeight && body.springCount) { timeStep = (adaptiveTimeStepWeight * body.springLength/body.springCount); } var coeff = timeStep / body.mass; ${pattern("body.velocity.{var} += coeff * body.force.{var};", { indent: 4 })} ${pattern("var v{var} = body.velocity.{var};", { indent: 4 })} var v = Math.sqrt(${pattern("v{var} * v{var}", { join: " + " })}); if (v > 1) { // We normalize it so that we move within timeStep range. // for the case when v <= 1 - we let velocity to fade out. ${pattern("body.velocity.{var} = v{var} / v;", { indent: 6 })} } ${pattern("d{var} = timeStep * body.velocity.{var};", { indent: 4 })} ${pattern("body.pos.{var} += d{var};", { indent: 4 })} ${pattern("t{var} += Math.abs(d{var});", { indent: 4 })} } return (${pattern("t{var} * t{var}", { join: " + " })})/length; `; return code; } } }); // node_modules/ngraph.forcelayout/lib/spring.js var require_spring = __commonJS({ "node_modules/ngraph.forcelayout/lib/spring.js"(exports, module2) { module2.exports = Spring; function Spring(fromBody, toBody, length, springCoefficient) { this.from = fromBody; this.to = toBody; this.length = length; this.coefficient = springCoefficient; } } }); // node_modules/ngraph.merge/index.js var require_ngraph3 = __commonJS({ "node_modules/ngraph.merge/index.js"(exports, module2) { module2.exports = merge; function merge(target, options) { var key; if (!target) { target = {}; } if (options) { for (key in options) { if (options.hasOwnProperty(key)) { var targetHasIt = target.hasOwnProperty(key), optionsValueType = typeof options[key], shouldReplace = !targetHasIt || typeof target[key] !== optionsValueType; if (shouldReplace) { target[key] = options[key]; } else if (optionsValueType === "object") { target[key] = merge(target[key], options[key]); } } } } return target; } } }); // node_modules/ngraph.random/index.js var require_ngraph4 = __commonJS({ "node_modules/ngraph.random/index.js"(exports, module2) { module2.exports = random; module2.exports.random = random, module2.exports.randomIterator = randomIterator; function random(inputSeed) { var seed = typeof inputSeed === "number" ? inputSeed : +new Date(); return new Generator(seed); } function Generator(seed) { this.seed = seed; } Generator.prototype.next = next; Generator.prototype.nextDouble = nextDouble; Generator.prototype.uniform = nextDouble; Generator.prototype.gaussian = gaussian; function gaussian() { var r, x3, y3; do { x3 = this.nextDouble() * 2 - 1; y3 = this.nextDouble() * 2 - 1; r = x3 * x3 + y3 * y3; } while (r >= 1 || r === 0); return x3 * Math.sqrt(-2 * Math.log(r) / r); } Generator.prototype.levy = levy; function levy() { var beta = 3 / 2; var sigma = Math.pow( gamma(1 + beta) * Math.sin(Math.PI * beta / 2) / (gamma((1 + beta) / 2) * beta * Math.pow(2, (beta - 1) / 2)), 1 / beta ); return this.gaussian() * sigma / Math.pow(Math.abs(this.gaussian()), 1 / beta); } function gamma(z4) { return Math.sqrt(2 * Math.PI / z4) * Math.pow(1 / Math.E * (z4 + 1 / (12 * z4 - 1 / (10 * z4))), z4); } function nextDouble() { var seed = this.seed; seed = seed + 2127912214 + (seed << 12) & 4294967295; seed = (seed ^ 3345072700 ^ seed >>> 19) & 4294967295; seed = seed + 374761393 + (seed << 5) & 4294967295; seed = (seed + 3550635116 ^ seed << 9) & 4294967295; seed = seed + 4251993797 + (seed << 3) & 4294967295; seed = (seed ^ 3042594569 ^ seed >>> 16) & 4294967295; this.seed = seed; return (seed & 268435455) / 268435456; } function next(maxValue) { return Math.floor(this.nextDouble() * maxValue); } function randomIterator(array, customRandom) { var localRandom = customRandom || random(); if (typeof localRandom.next !== "function") { throw new Error("customRandom does not match expected API: next() function is missing"); } return { forEach, /** * Shuffles array randomly, in place. */ shuffle }; function shuffle() { var i, j, t; for (i = array.length - 1; i > 0; --i) { j = localRandom.next(i + 1); t = array[j]; array[j] = array[i]; array[i] = t; } return array; } function forEach(callback) { var i, j, t; for (i = array.length - 1; i > 0; --i) { j = localRandom.next(i + 1); t = array[j]; array[j] = array[i]; array[i] = t; callback(t); } if (array.length) { callback(array[0]); } } } } }); // node_modules/ngraph.forcelayout/lib/createPhysicsSimulator.js var require_createPhysicsSimulator = __commonJS({ "node_modules/ngraph.forcelayout/lib/createPhysicsSimulator.js"(exports, module2) { module2.exports = createPhysicsSimulator; var generateCreateBodyFunction = require_generateCreateBody(); var generateQuadTreeFunction = require_generateQuadTree(); var generateBoundsFunction = require_generateBounds(); var generateCreateDragForceFunction = require_generateCreateDragForce(); var generateCreateSpringForceFunction = require_generateCreateSpringForce(); var generateIntegratorFunction = require_generateIntegrator(); var dimensionalCache = {}; function createPhysicsSimulator(settings) { var Spring = require_spring(); var merge = require_ngraph3(); var eventify = require_ngraph(); if (settings) { if (settings.springCoeff !== void 0) throw new Error("springCoeff was renamed to springCoefficient"); if (settings.dragCoeff !== void 0) throw new Error("dragCoeff was renamed to dragCoefficient"); } settings = merge(settings, { /** * Ideal length for links (springs in physical model). */ springLength: 10, /** * Hook's law coefficient. 1 - solid spring. */ springCoefficient: 0.8, /** * Coulomb's law coefficient. It's used to repel nodes thus should be negative * if you make it positive nodes start attract each other :). */ gravity: -12, /** * Theta coefficient from Barnes Hut simulation. Ranged between (0, 1). * The closer it's to 1 the more nodes algorithm will have to go through. * Setting it to one makes Barnes Hut simulation no different from * brute-force forces calculation (each node is considered). */ theta: 0.8, /** * Drag force coefficient. Used to slow down system, thus should be less than 1. * The closer it is to 0 the less tight system will be. */ dragCoefficient: 0.9, // TODO: Need to rename this to something better. E.g. `dragCoefficient` /** * Default time step (dt) for forces integration */ timeStep: 0.5, /** * Adaptive time step uses average spring length to compute actual time step: * See: https://twitter.com/anvaka/status/1293067160755957760 */ adaptiveTimeStepWeight: 0, /** * This parameter defines number of dimensions of the space where simulation * is performed. */ dimensions: 2, /** * In debug mode more checks are performed, this will help you catch errors * quickly, however for production build it is recommended to turn off this flag * to speed up computation. */ debug: false }); var factory = dimensionalCache[settings.dimensions]; if (!factory) { var dimensions = settings.dimensions; factory = { Body: generateCreateBodyFunction(dimensions, settings.debug), createQuadTree: generateQuadTreeFunction(dimensions), createBounds: generateBoundsFunction(dimensions), createDragForce: generateCreateDragForceFunction(dimensions), createSpringForce: generateCreateSpringForceFunction(dimensions), integrate: generateIntegratorFunction(dimensions) }; dimensionalCache[dimensions] = factory; } var Body = factory.Body; var createQuadTree = factory.createQuadTree; var createBounds = factory.createBounds; var createDragForce = factory.createDragForce; var createSpringForce = factory.createSpringForce; var integrate = factory.integrate; var createBody = (pos) => new Body(pos); var random = require_ngraph4().random(42); var bodies = []; var springs = []; var quadTree = createQuadTree(settings, random); var bounds = createBounds(bodies, settings, random); var springForce = createSpringForce(settings, random); var dragForce = createDragForce(settings); var totalMovement = 0; var forces = []; var forceMap = /* @__PURE__ */ new Map(); var iterationNumber = 0; addForce("nbody", nbodyForce); addForce("spring", updateSpringForce); var publicApi = { /** * Array of bodies, registered with current simulator * * Note: To add new body, use addBody() method. This property is only * exposed for testing/performance purposes. */ bodies, quadTree, /** * Array of springs, registered with current simulator * * Note: To add new spring, use addSpring() method. This property is only * exposed for testing/performance purposes. */ springs, /** * Returns settings with which current simulator was initialized */ settings, /** * Adds a new force to simulation */ addForce, /** * Removes a force from the simulation. */ removeForce, /** * Returns a map of all registered forces. */ getForces, /** * Performs one step of force simulation. * * @returns {boolean} true if system is considered stable; False otherwise. */ step: function() { for (var i = 0; i < forces.length; ++i) { forces[i](iterationNumber); } var movement = integrate(bodies, settings.timeStep, settings.adaptiveTimeStepWeight); iterationNumber += 1; return movement; }, /** * Adds body to the system * * @param {ngraph.physics.primitives.Body} body physical body * * @returns {ngraph.physics.primitives.Body} added body */ addBody: function(body) { if (!body) { throw new Error("Body is required"); } bodies.push(body); return body; }, /** * Adds body to the system at given position * * @param {Object} pos position of a body * * @returns {ngraph.physics.primitives.Body} added body */ addBodyAt: function(pos) { if (!pos) { throw new Error("Body position is required"); } var body = createBody(pos); bodies.push(body); return body; }, /** * Removes body from the system * * @param {ngraph.physics.primitives.Body} body to remove * * @returns {Boolean} true if body found and removed. falsy otherwise; */ removeBody: function(body) { if (!body) { return; } var idx = bodies.indexOf(body); if (idx < 0) { return; } bodies.splice(idx, 1); if (bodies.length === 0) { bounds.reset(); } return true; }, /** * Adds a spring to this simulation. * * @returns {Object} - a handle for a spring. If you want to later remove * spring pass it to removeSpring() method. */ addSpring: function(body1, body2, springLength, springCoefficient) { if (!body1 || !body2) { throw new Error("Cannot add null spring to force simulator"); } if (typeof springLength !== "number") { springLength = -1; } var spring = new Spring(body1, body2, springLength, springCoefficient >= 0 ? springCoefficient : -1); springs.push(spring); return spring; }, /** * Returns amount of movement performed on last step() call */ getTotalMovement: function() { return totalMovement; }, /** * Removes spring from the system * * @param {Object} spring to remove. Spring is an object returned by addSpring * * @returns {Boolean} true if spring found and removed. falsy otherwise; */ removeSpring: function(spring) { if (!spring) { return; } var idx = springs.indexOf(spring); if (idx > -1) { springs.splice(idx, 1); return true; } }, getBestNewBodyPosition: function(neighbors) { return bounds.getBestNewPosition(neighbors); }, /** * Returns bounding box which covers all bodies */ getBBox: getBoundingBox, getBoundingBox, invalidateBBox: function() { console.warn("invalidateBBox() is deprecated, bounds always recomputed on `getBBox()` call"); }, // TODO: Move the force specific stuff to force gravity: function(value) { if (value !== void 0) { settings.gravity = value; quadTree.options({ gravity: value }); return this; } else { return settings.gravity; } }, theta: function(value) { if (value !== void 0) { settings.theta = value; quadTree.options({ theta: value }); return this; } else { return settings.theta; } }, /** * Returns pseudo-random number generator instance. */ random }; expose(settings, publicApi); eventify(publicApi); return publicApi; function getBoundingBox() { bounds.update(); return bounds.box; } function addForce(forceName, forceFunction) { if (forceMap.has(forceName)) throw new Error("Force " + forceName + " is already added"); forceMap.set(forceName, forceFunction); forces.push(forceFunction); } function removeForce(forceName) { var forceIndex = forces.indexOf(forceMap.get(forceName)); if (forceIndex < 0) return; forces.splice(forceIndex, 1); forceMap.delete(forceName); } function getForces() { return forceMap; } function nbodyForce() { if (bodies.length === 0) return; quadTree.insertBodies(bodies); var i = bodies.length; while (i--) { var body = bodies[i]; if (!body.isPinned) { body.reset(); quadTree.updateBodyForce(body); dragForce.update(body); } } } function updateSpringForce() { var i = springs.length; while (i--) { springForce.update(springs[i]); } } } function expose(settings, target) { for (var key in settings) { augment(settings, target, key); } } function augment(source, target, key) { if (!source.hasOwnProperty(key)) return; if (typeof target[key] === "function") { return; } var sourceIsNumber = Number.isFinite(source[key]); if (sourceIsNumber) { target[key] = function(value) { if (value !== void 0) { if (!Number.isFinite(value)) throw new Error("Value of " + key + " should be a valid number."); source[key] = value; return target; } return source[key]; }; } else { target[key] = function(value) { if (value !== void 0) { source[key] = value; return target; } return source[key]; }; } } } }); // node_modules/ngraph.forcelayout/index.js var require_ngraph5 = __commonJS({ "node_modules/ngraph.forcelayout/index.js"(exports, module2) { module2.exports = createLayout; module2.exports.simulator = require_createPhysicsSimulator(); var eventify = require_ngraph(); function createLayout(graph2, physicsSettings) { if (!graph2) { throw new Error("Graph structure cannot be undefined"); } var createSimulator = physicsSettings && physicsSettings.createSimulator || require_createPhysicsSimulator(); var physicsSimulator = createSimulator(physicsSettings); if (Array.isArray(physicsSettings)) throw new Error("Physics settings is expected to be an object"); var nodeMass = graph2.version > 19 ? defaultSetNodeMass : defaultArrayNodeMass; if (physicsSettings && typeof physicsSettings.nodeMass === "function") { nodeMass = physicsSettings.nodeMass; } var nodeBodies = /* @__PURE__ */ new Map(); var springs = {}; var bodiesCount = 0; var springTransform = physicsSimulator.settings.springTransform || noop2; initPhysics(); listenToEvents(); var wasStable = false; var api = { /** * Performs one step of iterative layout algorithm * * @returns {boolean} true if the system should be considered stable; False otherwise. * The system is stable if no further call to `step()` can improve the layout. */ step: function() { if (bodiesCount === 0) { updateStableStatus(true); return true; } var lastMove = physicsSimulator.step(); api.lastMove = lastMove; api.fire("step"); var ratio = lastMove / bodiesCount; var isStableNow = ratio <= 0.01; updateStableStatus(isStableNow); return isStableNow; }, /** * For a given `nodeId` returns position */ getNodePosition: function(nodeId) { return getInitializedBody(nodeId).pos; }, /** * Sets position of a node to a given coordinates * @param {string} nodeId node identifier * @param {number} x position of a node * @param {number} y position of a node * @param {number=} z position of node (only if applicable to body) */ setNodePosition: function(nodeId) { var body = getInitializedBody(nodeId); body.setPosition.apply(body, Array.prototype.slice.call(arguments, 1)); }, /** * @returns {Object} Link position by link id * @returns {Object.from} {x, y} coordinates of link start * @returns {Object.to} {x, y} coordinates of link end */ getLinkPosition: function(linkId) { var spring = springs[linkId]; if (spring) { return { from: spring.from.pos, to: spring.to.pos }; } }, /** * @returns {Object} area required to fit in the graph. Object contains * `x1`, `y1` - top left coordinates * `x2`, `y2` - bottom right coordinates */ getGraphRect: function() { return physicsSimulator.getBBox(); }, /** * Iterates over each body in the layout simulator and performs a callback(body, nodeId) */ forEachBody, /* * Requests layout algorithm to pin/unpin node to its current position * Pinned nodes should not be affected by layout algorithm and always * remain at their position */ pinNode: function(node, isPinned) { var body = getInitializedBody(node.id); body.isPinned = !!isPinned; }, /** * Checks whether given graph's node is currently pinned */ isNodePinned: function(node) { return getInitializedBody(node.id).isPinned; }, /** * Request to release all resources */ dispose: function() { graph2.off("changed", onGraphChanged); api.fire("disposed"); }, /** * Gets physical body for a given node id. If node is not found undefined * value is returned. */ getBody, /** * Gets spring for a given edge. * * @param {string} linkId link identifer. If two arguments are passed then * this argument is treated as formNodeId * @param {string=} toId when defined this parameter denotes head of the link * and first argument is treated as tail of the link (fromId) */ getSpring, /** * Returns length of cumulative force vector. The closer this to zero - the more stable the system is */ getForceVectorLength, /** * [Read only] Gets current physics simulator */ simulator: physicsSimulator, /** * Gets the graph that was used for layout */ graph: graph2, /** * Gets amount of movement performed during last step operation */ lastMove: 0 }; eventify(api); return api; function updateStableStatus(isStableNow) { if (wasStable !== isStableNow) { wasStable = isStableNow; onStableChanged(isStableNow); } } function forEachBody(cb) { nodeBodies.forEach(cb); } function getForceVectorLength() { var fx = 0, fy = 0; forEachBody(function(body) { fx += Math.abs(body.force.x); fy += Math.abs(body.force.y); }); return Math.sqrt(fx * fx + fy * fy); } function getSpring(fromId, toId) { var linkId; if (toId === void 0) { if (typeof fromId !== "object") { linkId = fromId; } else { linkId = fromId.id; } } else { var link = graph2.hasLink(fromId, toId); if (!link) return; linkId = link.id; } return springs[linkId]; } function getBody(nodeId) { return nodeBodies.get(nodeId); } function listenToEvents() { graph2.on("changed", onGraphChanged); } function onStableChanged(isStable) { api.fire("stable", isStable); } function onGraphChanged(changes) { for (var i = 0; i < changes.length; ++i) { var change = changes[i]; if (change.changeType === "add") { if (change.node) { initBody(change.node.id); } if (change.link) { initLink(change.link); } } else if (change.changeType === "remove") { if (change.node) { releaseNode(change.node); } if (change.link) { releaseLink(change.link); } } } bodiesCount = graph2.getNodesCount(); } function initPhysics() { bodiesCount = 0; graph2.forEachNode(function(node) { initBody(node.id); bodiesCount += 1; }); graph2.forEachLink(initLink); } function initBody(nodeId) { var body = nodeBodies.get(nodeId); if (!body) { var node = graph2.getNode(nodeId); if (!node) { throw new Error("initBody() was called with unknown node id"); } var pos = node.position; if (!pos) { var neighbors = getNeighborBodies(node); pos = physicsSimulator.getBestNewBodyPosition(neighbors); } body = physicsSimulator.addBodyAt(pos); body.id = nodeId; nodeBodies.set(nodeId, body); updateBodyMass(nodeId); if (isNodeOriginallyPinned(node)) { body.isPinned = true; } } } function releaseNode(node) { var nodeId = node.id; var body = nodeBodies.get(nodeId); if (body) { nodeBodies.delete(nodeId); physicsSimulator.removeBody(body); } } function initLink(link) { updateBodyMass(link.fromId); updateBodyMass(link.toId); var fromBody = nodeBodies.get(link.fromId), toBody = nodeBodies.get(link.toId), spring = physicsSimulator.addSpring(fromBody, toBody, link.length); springTransform(link, spring); springs[link.id] = spring; } function releaseLink(link) { var spring = springs[link.id]; if (spring) { var from = graph2.getNode(link.fromId), to = graph2.getNode(link.toId); if (from) updateBodyMass(from.id); if (to) updateBodyMass(to.id); delete springs[link.id]; physicsSimulator.removeSpring(spring); } } function getNeighborBodies(node) { var neighbors = []; if (!node.links) { return neighbors; } var maxNeighbors = Math.min(node.links.length, 2); for (var i = 0; i < maxNeighbors; ++i) { var link = node.links[i]; var otherBody = link.fromId !== node.id ? nodeBodies.get(link.fromId) : nodeBodies.get(link.toId); if (otherBody && otherBody.pos) { neighbors.push(otherBody); } } return neighbors; } function updateBodyMass(nodeId) { var body = nodeBodies.get(nodeId); body.mass = nodeMass(nodeId); if (Number.isNaN(body.mass)) { throw new Error("Node mass should be a number"); } } function isNodeOriginallyPinned(node) { return node && (node.isPinned || node.data && node.data.isPinned); } function getInitializedBody(nodeId) { var body = nodeBodies.get(nodeId); if (!body) { initBody(nodeId); body = nodeBodies.get(nodeId); } return body; } function defaultArrayNodeMass(nodeId) { var links = graph2.getLinks(nodeId); if (!links) return 1; return 1 + links.length / 3; } function defaultSetNodeMass(nodeId) { var links = graph2.getLinks(nodeId); if (!links) return 1; return 1 + links.size / 3; } } function noop2() { } } }); // src/main.ts var main_exports = {}; __export(main_exports, { default: () => Graph3dPlugin }); module.exports = __toCommonJS(main_exports); var import_obsidian20 = require("obsidian"); // src/util/State.ts var import_observable_slim = __toESM(require_observable_slim()); var _State = class { constructor(value) { this.listeners = /* @__PURE__ */ new Map(); this.onChange = (callback) => { const listenerId = this.generateListenerId(); this.listeners.set(listenerId, callback); return () => this.unsubscribe(listenerId); }; this.generateListenerId = () => { _State.listener_count++; return _State.listener_count; }; this.unsubscribe = (listenerId) => { this.listeners.delete(listenerId); }; this.notifyAll = (changeData) => { this.listeners.forEach((listener) => listener(changeData)); }; this.onValueChange = (changes) => { changes.forEach((change) => { this.notifyAll(Object.assign({}, change, { triggerStateId: this.id })); }); }; _State.stateCount++; this.id = _State.stateCount; this.val = typeof value === "object" ? import_observable_slim.default.create(value, false, this.onValueChange) : value; } get value() { return this.val; } set value(val) { const previousValue = this.val; if (typeof val !== "object") { this.val = val; } else { this.val = import_observable_slim.default.create(val, false, this.onValueChange); } this.onValueChange([ { type: "update", property: "", currentPath: "", jsonPointer: "", target: this.val, // @ts-ignore proxy: this.val.__getProxy, previousValue, newValue: this.val } ]); } /** * create a substate of this state. * * @remarks You cannot create a substate for a primitive type state. */ createSubState(key) { const subStateKeys = key.split("."); const subStateValue = subStateKeys.reduce((obj, key2) => { const val = obj[key2]; if (val !== void 0) { return val; } throw new InvalidStateKeyError(key2, this); }, this); if (typeof subStateValue !== "object") { throw new Error("SubStates of properties that are Primitives are not supported yet."); } return new _State(subStateValue == null ? void 0 : subStateValue.__getTarget); } getRawValue() { if (typeof this.val === "object") { return this.val.__getTarget; } return this.val; } }; var State = _State; State.listener_count = 0; State.stateCount = 0; var InvalidStateKeyError = class extends Error { constructor(subStateKey, state) { super(); this.message = `Key does not exist! Detailed error: "${subStateKey}" could not be found in {"value":${JSON.stringify(state.value)}} `; } }; // src/graph/Link.ts var _Link = class { constructor(source, target) { this.source = source; this.target = target; } /** * Creates a link index for an array of links * @param links * @returns */ static createLinkIndex(links) { const linkIndex = /* @__PURE__ */ new Map(); links.forEach((link, index6) => { var _a3; if (!linkIndex.has(link.source.id)) { linkIndex.set(link.source.id, /* @__PURE__ */ new Map()); } (_a3 = linkIndex.get(link.source.id)) == null ? void 0 : _a3.set(link.target.id, index6); }); return linkIndex; } static checkLinksValid(links) { links.forEach((link, index6) => { links.forEach((link2, index22) => { if (index6 !== index22 && _Link.compare(link, link2)) { throw new Error("graph duplicate links"); } }); }); } static createLinkMap(links) { const linkMap = {}; links.forEach((link) => { var _a3; if (!linkMap[link.source.id]) linkMap[link.source.id] = []; (_a3 = linkMap[link.source.id]) == null ? void 0 : _a3.push(link.target.id); }); return linkMap; } }; var Link = _Link; Link.compare = (a2, b) => { return a2.source.id === b.source.id && a2.target.id === b.target.id; }; // src/graph/Node.ts var _Node = class { constructor(name, path, val = 10, neighbors = [], links = []) { this.id = path; this.name = name; this.path = path; this.val = val; this.neighbors = neighbors; this.links = links; } // Creates an array of nodes from an array of files (from the Obsidian API) static createFromFiles(files) { return files.map((file) => { return new _Node(file.name, file.path); }); } /** * given a node, check if it is a neighbour of current node. If yes, * Links together two nodes as neighbors (node -> neighbor). * */ addNeighbor(neighbor) { if (!this.isNeighborOf(neighbor)) { if (!this.neighbors.includes(neighbor)) this.neighbors.push(neighbor); if (!neighbor.neighbors.includes(this)) neighbor.neighbors.push(this); } } // Pushes a link to the node's links array if it doesn't already exist addLink(link) { if (!this.links.some((l) => l.source === link.source && l.target === link.target)) { this.links.push(link); } } // Whether the node is a neighbor of another node isNeighborOf(node) { if (node instanceof _Node) return this.neighbors.includes(node); else return this.neighbors.some((neighbor) => neighbor.id === node); } static createNodeIndex(nodes) { const nodeIndex = /* @__PURE__ */ new Map(); nodes.forEach((node, index6) => { nodeIndex.set(node.id, index6); }); return nodeIndex; } }; var Node = _Node; Node.compare = (a2, b) => { return a2.path === b.path; }; Node.checkNodesValid = (nodes) => { const nodeSet = new Set(nodes); if (nodeSet.size !== nodes.length) { throw new Error("Duplicate nodes found"); } nodes.forEach((node) => { const neighborSet = new Set(node.neighbors); if (neighborSet.size !== node.neighbors.length) { throw new Error(`Duplicate neighbors found for node ${node.name}`); } }); }; // node_modules/is-what/dist/index.js function getType(payload) { return Object.prototype.toString.call(payload).slice(8, -1); } function isUndefined(payload) { return getType(payload) === "Undefined"; } function isNull(payload) { return getType(payload) === "Null"; } function isPlainObject(payload) { if (getType(payload) !== "Object") return false; const prototype = Object.getPrototypeOf(payload); return !!prototype && prototype.constructor === Object && prototype === Object.prototype; } function isArray(payload) { return getType(payload) === "Array"; } var isNullOrUndefined = isOneOf(isNull, isUndefined); function isOneOf(a2, b, c2, d, e) { return (value) => a2(value) || b(value) || !!c2 && c2(value) || !!d && d(value) || !!e && e(value); } // node_modules/copy-anything/dist/index.js function assignProp(carry, key, newVal, originalObject, includeNonenumerable) { const propType = {}.propertyIsEnumerable.call(originalObject, key) ? "enumerable" : "nonenumerable"; if (propType === "enumerable") carry[key] = newVal; if (includeNonenumerable && propType === "nonenumerable") { Object.defineProperty(carry, key, { value: newVal, enumerable: false, writable: true, configurable: true }); } } function copy(target, options = {}) { if (isArray(target)) { return target.map((item) => copy(item, options)); } if (!isPlainObject(target)) { return target; } const props = Object.getOwnPropertyNames(target); const symbols = Object.getOwnPropertySymbols(target); return [...props, ...symbols].reduce((carry, key) => { if (isArray(options.props) && !options.props.includes(key)) { return carry; } const val = target[key]; const newVal = copy(val, options); assignProp(carry, key, newVal, target, options.nonenumerable); return carry; }, {}); } // src/graph/Graph.ts var _Graph = class { constructor(nodes, links, nodeIndex, linkIndex) { this.getNodeByPath = (path) => { var _a3; const index6 = this.nodeIndex.get(path); if (typeof index6 === "number") { return (_a3 = this.nodes[index6]) != null ? _a3 : null; } return null; }; // Clones the graph this.clone = () => { return new _Graph( copy(this.nodes), copy(this.links), copy(this.nodeIndex), copy(this.linkIndex) ); }; /** * filter the nodes of the graph, the links will be filtered automatically. * @param predicate what nodes to keep * @param graph the graph to filter * @returns a new graph */ this.filter = (predicate, linksPredicate) => { const filteredNodes = this.nodes.filter(predicate); const filteredNodeIds = new Set(filteredNodes.map((node) => node.id)); const filteredLinks = this.links.filter((link) => { const linkIsValid = filteredNodeIds.has(link.source.id) && filteredNodeIds.has(link.target.id); return linkIsValid && (!linksPredicate || linksPredicate(link)); }); const linkMap = Link.createLinkMap(filteredLinks); return _Graph.createFromLinkMap(linkMap, filteredNodes); }; this.isAcyclic = () => { const visited = /* @__PURE__ */ new Set(); const recStack = /* @__PURE__ */ new Set(); for (const node of this.nodes) { if (this.isCyclicUtil(node.id, visited, recStack)) { return false; } } return true; }; this.isCyclicUtil = (nodeId, visited, recStack) => { if (!visited.has(nodeId)) { visited.add(nodeId); recStack.add(nodeId); const adjNodes = this.getLinksFromNode(nodeId).map( (link) => link.source.id === nodeId ? link.target.id : link.source.id ); for (const neighborId of adjNodes) { if (!visited.has(neighborId) && this.isCyclicUtil(neighborId, visited, recStack)) { return true; } else if (recStack.has(neighborId)) { return true; } } } recStack.delete(nodeId); return false; }; this.nodes = nodes; this.links = links; this.nodeIndex = nodeIndex || /* @__PURE__ */ new Map(); this.linkIndex = linkIndex || /* @__PURE__ */ new Map(); } getNodeById(id) { var _a3; const index6 = this.nodeIndex.get(id); if (typeof index6 === "number") { return (_a3 = this.nodes[index6]) != null ? _a3 : null; } return null; } // Returns a link by its source and target node ids getLinkByIds(sourceNodeId, targetNodeId) { const sourceLinkMap = this.linkIndex.get(sourceNodeId); if (sourceLinkMap) { const index6 = sourceLinkMap.get(targetNodeId); if (index6 !== void 0) { return this.links[index6]; } } return null; } getLinksFromNode(sourceNodeId) { const linkIndexes = this.linkIndex.get(sourceNodeId); if (linkIndexes) { return Array.from(linkIndexes.values()).map((index6) => this.links[index6]).filter(Boolean); } return []; } /** * given a node id, return all the links that contains this node */ getLinksWithNode(nodeId) { const links = []; this.linkIndex.forEach((targetMap, sourceId) => { if (sourceId === nodeId) { links.push( ...Array.from(targetMap.values()).map((index6) => this.links[index6]) ); } else if (targetMap.has(nodeId)) { const index6 = targetMap.get(nodeId); if (typeof index6 === "number") { links.push(this.links[index6]); } } }); return links; } static createFromLinkMap(map, nodes) { const newNodes = nodes.map((node) => new Node(node.name, node.path, node.val)); const nodeMap = /* @__PURE__ */ new Map(); newNodes.forEach((node) => nodeMap.set(node.id, node)); const links = []; Object.entries(map).forEach(([sourceId, targetIds]) => { const sourceNode = nodeMap.get(sourceId); if (!sourceNode) return; targetIds.forEach((targetId) => { const targetNode = nodeMap.get(targetId); if (!targetNode) return; const link = new Link(sourceNode, targetNode); links.push(link); sourceNode.addNeighbor(targetNode); sourceNode.addLink(link); targetNode.addLink(link); }); }); return new _Graph(newNodes, links, Node.createNodeIndex(newNodes), Link.createLinkIndex(links)); } /** * get the files from the graph */ static getFiles(app2, graph2) { return graph2.nodes.map((node) => app2.vault.getAbstractFileByPath(node.path)).filter(Boolean); } }; var Graph = _Graph; Graph.createEmpty = () => { return new _Graph([], [], /* @__PURE__ */ new Map(), /* @__PURE__ */ new Map()); }; // Creates a graph using the Obsidian API Graph.createFromApp = (app2) => { const map = getMapFromMetaCache(app2.metadataCache.resolvedLinks); const config2 = app2.vault.config; const userExcludedFolders = config2.userIgnoreFilters; const allFiles = userExcludedFolders ? app2.vault.getFiles().filter((file) => !userExcludedFolders.some((folder) => file.path.startsWith(folder))) : app2.vault.getFiles(); const nodes = Node.createFromFiles(allFiles); return _Graph.createFromLinkMap(map, nodes); }; Graph.compare = (graph1, graph2) => { if (graph1.nodes.length !== graph2.nodes.length) { return false; } if (graph1.links.length !== graph2.links.length) { return false; } for (const node1 of graph1.nodes) { const node2Index = graph2.nodeIndex.get(node1.id); if (node2Index === void 0 || graph2.nodes[node2Index].id !== node1.id) { return false; } } for (const link1 of graph1.links) { const graph2SourceLinkMap = graph2.linkIndex.get(link1.source.id); if (!graph2SourceLinkMap) { return false; } const graph2LinkIndex = graph2SourceLinkMap.get(link1.target.id); if (graph2LinkIndex === void 0) { return false; } const link2 = graph2.links[graph2LinkIndex]; if (!link2 || link2.source.id !== link1.source.id || link2.target.id !== link1.target.id) { return false; } } return true; }; var getMapFromMetaCache = (resolvedLinks) => { const result = {}; Object.keys(resolvedLinks).map((nodeId) => { var _a3; result[nodeId] = (_a3 = Object.keys(resolvedLinks[nodeId]).map((nodePath) => { return nodePath; })) != null ? _a3 : []; }); Object.keys(result).forEach((nodeId) => { var _a3, _b3; result[nodeId] = (_b3 = (_a3 = result[nodeId]) == null ? void 0 : _a3.filter((nodePath) => nodePath !== nodeId)) != null ? _b3 : []; }); return result; }; // src/util/deepCompare.ts var deepCompare = (obj1, obj2) => { if (!obj1 || !obj2) return obj1 == obj2; else if (obj1 instanceof Object && obj2 instanceof Object) { return Object.keys(obj1).length === Object.keys(obj2).length && Object.keys(obj1).every((key) => { return obj2.hasOwnProperty(key) && deepCompare( obj1[key], obj2[key] ); }); } else return obj1 == obj2; }; // src/util/AsyncQueue.ts var AsyncQueue = class { constructor() { this.queue = []; } /** * push a task to the queue. If the queue is empty, the task will be executed immediately. */ push(task) { this.queue.push(task); if (this.queue.length === 1) { this.run(); } } /** * recursively run the tasks in the queue. * Stop when the queue is empty. */ async run() { const task = this.queue[0]; if (!task) return; try { await task(); } catch (error) { console.error(`Error executing task: ${error}`); } finally { this.queue.shift(); } await this.run(); } }; // src/util/EventBus.ts var import_obsidian = require("obsidian"); var AsyncEventBus = class extends import_obsidian.Events { constructor() { super(); this.asyncQueue = new AsyncQueue(); } // eslint-disable-next-line @typescript-eslint/no-explicit-any trigger(name, ...data) { super.trigger(name, ...data); } /** * add the callback to an async queue to make sure that the callback is executed one after one */ // eslint-disable-next-line @typescript-eslint/no-explicit-any on(name, callback, ctx) { const pushToAsyncQueue = (...data) => { this.asyncQueue.push(() => callback(...data)); }; const eventRef = super.on(name, pushToAsyncQueue, ctx); return eventRef; } }; var eventBus = new AsyncEventBus(); // src/views/SettingTab.ts var import_obsidian3 = require("obsidian"); // node_modules/zod/lib/index.mjs var util; (function(util2) { util2.assertEqual = (val) => val; function assertIs(_arg) { } util2.assertIs = assertIs; function assertNever(_x3) { throw new Error(); } util2.assertNever = assertNever; util2.arrayToEnum = (items) => { const obj = {}; for (const item of items) { obj[item] = item; } return obj; }; util2.getValidEnumValues = (obj) => { const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number"); const filtered = {}; for (const k of validKeys) { filtered[k] = obj[k]; } return util2.objectValues(filtered); }; util2.objectValues = (obj) => { return util2.objectKeys(obj).map(function(e) { return obj[e]; }); }; util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => { const keys = []; for (const key in object) { if (Object.prototype.hasOwnProperty.call(object, key)) { keys.push(key); } } return keys; }; util2.find = (arr, checker) => { for (const item of arr) { if (checker(item)) return item; } return void 0; }; util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val; function joinValues(array, separator = " | ") { return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator); } util2.joinValues = joinValues; util2.jsonStringifyReplacer = (_, value) => { if (typeof value === "bigint") { return value.toString(); } return value; }; })(util || (util = {})); var objectUtil; (function(objectUtil2) { objectUtil2.mergeShapes = (first, second) => { return { ...first, ...second // second overwrites first }; }; })(objectUtil || (objectUtil = {})); var ZodParsedType = util.arrayToEnum([ "string", "nan", "number", "integer", "float", "boolean", "date", "bigint", "symbol", "function", "undefined", "null", "array", "object", "unknown", "promise", "void", "never", "map", "set" ]); var getParsedType = (data) => { const t = typeof data; switch (t) { case "undefined": return ZodParsedType.undefined; case "string": return ZodParsedType.string; case "number": return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number; case "boolean": return ZodParsedType.boolean; case "function": return ZodParsedType.function; case "bigint": return ZodParsedType.bigint; case "symbol": return ZodParsedType.symbol; case "object": if (Array.isArray(data)) { return ZodParsedType.array; } if (data === null) { return ZodParsedType.null; } if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") { return ZodParsedType.promise; } if (typeof Map !== "undefined" && data instanceof Map) { return ZodParsedType.map; } if (typeof Set !== "undefined" && data instanceof Set) { return ZodParsedType.set; } if (typeof Date !== "undefined" && data instanceof Date) { return ZodParsedType.date; } return ZodParsedType.object; default: return ZodParsedType.unknown; } }; var ZodIssueCode = util.arrayToEnum([ "invalid_type", "invalid_literal", "custom", "invalid_union", "invalid_union_discriminator", "invalid_enum_value", "unrecognized_keys", "invalid_arguments", "invalid_return_type", "invalid_date", "invalid_string", "too_small", "too_big", "invalid_intersection_types", "not_multiple_of", "not_finite" ]); var quotelessJson = (obj) => { const json = JSON.stringify(obj, null, 2); return json.replace(/"([^"]+)":/g, "$1:"); }; var ZodError = class extends Error { constructor(issues) { super(); this.issues = []; this.addIssue = (sub) => { this.issues = [...this.issues, sub]; }; this.addIssues = (subs = []) => { this.issues = [...this.issues, ...subs]; }; const actualProto = new.target.prototype; if (Object.setPrototypeOf) { Object.setPrototypeOf(this, actualProto); } else { this.__proto__ = actualProto; } this.name = "ZodError"; this.issues = issues; } get errors() { return this.issues; } format(_mapper) { const mapper = _mapper || function(issue) { return issue.message; }; const fieldErrors = { _errors: [] }; const processError = (error) => { for (const issue of error.issues) { if (issue.code === "invalid_union") { issue.unionErrors.map(processError); } else if (issue.code === "invalid_return_type") { processError(issue.returnTypeError); } else if (issue.code === "invalid_arguments") { processError(issue.argumentsError); } else if (issue.path.length === 0) { fieldErrors._errors.push(mapper(issue)); } else { let curr = fieldErrors; let i = 0; while (i < issue.path.length) { const el = issue.path[i]; const terminal = i === issue.path.length - 1; if (!terminal) { curr[el] = curr[el] || { _errors: [] }; } else { curr[el] = curr[el] || { _errors: [] }; curr[el]._errors.push(mapper(issue)); } curr = curr[el]; i++; } } } }; processError(this); return fieldErrors; } toString() { return this.message; } get message() { return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2); } get isEmpty() { return this.issues.length === 0; } flatten(mapper = (issue) => issue.message) { const fieldErrors = {}; const formErrors = []; for (const sub of this.issues) { if (sub.path.length > 0) { fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || []; fieldErrors[sub.path[0]].push(mapper(sub)); } else { formErrors.push(mapper(sub)); } } return { formErrors, fieldErrors }; } get formErrors() { return this.flatten(); } }; ZodError.create = (issues) => { const error = new ZodError(issues); return error; }; var errorMap = (issue, _ctx) => { let message; switch (issue.code) { case ZodIssueCode.invalid_type: if (issue.received === ZodParsedType.undefined) { message = "Required"; } else { message = `Expected ${issue.expected}, received ${issue.received}`; } break; case ZodIssueCode.invalid_literal: message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`; break; case ZodIssueCode.unrecognized_keys: message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`; break; case ZodIssueCode.invalid_union: message = `Invalid input`; break; case ZodIssueCode.invalid_union_discriminator: message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`; break; case ZodIssueCode.invalid_enum_value: message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`; break; case ZodIssueCode.invalid_arguments: message = `Invalid function arguments`; break; case ZodIssueCode.invalid_return_type: message = `Invalid function return type`; break; case ZodIssueCode.invalid_date: message = `Invalid date`; break; case ZodIssueCode.invalid_string: if (typeof issue.validation === "object") { if ("includes" in issue.validation) { message = `Invalid input: must include "${issue.validation.includes}"`; if (typeof issue.validation.position === "number") { message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`; } } else if ("startsWith" in issue.validation) { message = `Invalid input: must start with "${issue.validation.startsWith}"`; } else if ("endsWith" in issue.validation) { message = `Invalid input: must end with "${issue.validation.endsWith}"`; } else { util.assertNever(issue.validation); } } else if (issue.validation !== "regex") { message = `Invalid ${issue.validation}`; } else { message = "Invalid"; } break; case ZodIssueCode.too_small: if (issue.type === "array") message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`; else if (issue.type === "string") message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`; else if (issue.type === "number") message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`; else if (issue.type === "date") message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`; else message = "Invalid input"; break; case ZodIssueCode.too_big: if (issue.type === "array") message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`; else if (issue.type === "string") message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`; else if (issue.type === "number") message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`; else if (issue.type === "bigint") message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`; else if (issue.type === "date") message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`; else message = "Invalid input"; break; case ZodIssueCode.custom: message = `Invalid input`; break; case ZodIssueCode.invalid_intersection_types: message = `Intersection results could not be merged`; break; case ZodIssueCode.not_multiple_of: message = `Number must be a multiple of ${issue.multipleOf}`; break; case ZodIssueCode.not_finite: message = "Number must be finite"; break; default: message = _ctx.defaultError; util.assertNever(issue); } return { message }; }; var overrideErrorMap = errorMap; function setErrorMap(map) { overrideErrorMap = map; } function getErrorMap() { return overrideErrorMap; } var makeIssue = (params) => { const { data, path, errorMaps, issueData } = params; const fullPath = [...path, ...issueData.path || []]; const fullIssue = { ...issueData, path: fullPath }; let errorMessage = ""; const maps = errorMaps.filter((m2) => !!m2).slice().reverse(); for (const map of maps) { errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message; } return { ...issueData, path: fullPath, message: issueData.message || errorMessage }; }; var EMPTY_PATH = []; function addIssueToContext(ctx, issueData) { const issue = makeIssue({ issueData, data: ctx.data, path: ctx.path, errorMaps: [ ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), errorMap // then global default map ].filter((x3) => !!x3) }); ctx.common.issues.push(issue); } var ParseStatus = class { constructor() { this.value = "valid"; } dirty() { if (this.value === "valid") this.value = "dirty"; } abort() { if (this.value !== "aborted") this.value = "aborted"; } static mergeArray(status, results) { const arrayValue = []; for (const s of results) { if (s.status === "aborted") return INVALID; if (s.status === "dirty") status.dirty(); arrayValue.push(s.value); } return { status: status.value, value: arrayValue }; } static async mergeObjectAsync(status, pairs) { const syncPairs = []; for (const pair of pairs) { syncPairs.push({ key: await pair.key, value: await pair.value }); } return ParseStatus.mergeObjectSync(status, syncPairs); } static mergeObjectSync(status, pairs) { const finalObject = {}; for (const pair of pairs) { const { key, value } = pair; if (key.status === "aborted") return INVALID; if (value.status === "aborted") return INVALID; if (key.status === "dirty") status.dirty(); if (value.status === "dirty") status.dirty(); if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) { finalObject[key.value] = value.value; } } return { status: status.value, value: finalObject }; } }; var INVALID = Object.freeze({ status: "aborted" }); var DIRTY = (value) => ({ status: "dirty", value }); var OK = (value) => ({ status: "valid", value }); var isAborted = (x3) => x3.status === "aborted"; var isDirty = (x3) => x3.status === "dirty"; var isValid = (x3) => x3.status === "valid"; var isAsync = (x3) => typeof Promise !== "undefined" && x3 instanceof Promise; var errorUtil; (function(errorUtil2) { errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {}; errorUtil2.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message; })(errorUtil || (errorUtil = {})); var ParseInputLazyPath = class { constructor(parent, value, path, key) { this._cachedPath = []; this.parent = parent; this.data = value; this._path = path; this._key = key; } get path() { if (!this._cachedPath.length) { if (this._key instanceof Array) { this._cachedPath.push(...this._path, ...this._key); } else { this._cachedPath.push(...this._path, this._key); } } return this._cachedPath; } }; var handleResult = (ctx, result) => { if (isValid(result)) { return { success: true, data: result.value }; } else { if (!ctx.common.issues.length) { throw new Error("Validation failed but no issues detected."); } return { success: false, get error() { if (this._error) return this._error; const error = new ZodError(ctx.common.issues); this._error = error; return this._error; } }; } }; function processCreateParams(params) { if (!params) return {}; const { errorMap: errorMap2, invalid_type_error, required_error, description } = params; if (errorMap2 && (invalid_type_error || required_error)) { throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`); } if (errorMap2) return { errorMap: errorMap2, description }; const customMap = (iss, ctx) => { if (iss.code !== "invalid_type") return { message: ctx.defaultError }; if (typeof ctx.data === "undefined") { return { message: required_error !== null && required_error !== void 0 ? required_error : ctx.defaultError }; } return { message: invalid_type_error !== null && invalid_type_error !== void 0 ? invalid_type_error : ctx.defaultError }; }; return { errorMap: customMap, description }; } var ZodType = class { constructor(def) { this.spa = this.safeParseAsync; this._def = def; this.parse = this.parse.bind(this); this.safeParse = this.safeParse.bind(this); this.parseAsync = this.parseAsync.bind(this); this.safeParseAsync = this.safeParseAsync.bind(this); this.spa = this.spa.bind(this); this.refine = this.refine.bind(this); this.refinement = this.refinement.bind(this); this.superRefine = this.superRefine.bind(this); this.optional = this.optional.bind(this); this.nullable = this.nullable.bind(this); this.nullish = this.nullish.bind(this); this.array = this.array.bind(this); this.promise = this.promise.bind(this); this.or = this.or.bind(this); this.and = this.and.bind(this); this.transform = this.transform.bind(this); this.brand = this.brand.bind(this); this.default = this.default.bind(this); this.catch = this.catch.bind(this); this.describe = this.describe.bind(this); this.pipe = this.pipe.bind(this); this.readonly = this.readonly.bind(this); this.isNullable = this.isNullable.bind(this); this.isOptional = this.isOptional.bind(this); } get description() { return this._def.description; } _getType(input) { return getParsedType(input.data); } _getOrReturnCtx(input, ctx) { return ctx || { common: input.parent.common, data: input.data, parsedType: getParsedType(input.data), schemaErrorMap: this._def.errorMap, path: input.path, parent: input.parent }; } _processInputParams(input) { return { status: new ParseStatus(), ctx: { common: input.parent.common, data: input.data, parsedType: getParsedType(input.data), schemaErrorMap: this._def.errorMap, path: input.path, parent: input.parent } }; } _parseSync(input) { const result = this._parse(input); if (isAsync(result)) { throw new Error("Synchronous parse encountered promise."); } return result; } _parseAsync(input) { const result = this._parse(input); return Promise.resolve(result); } parse(data, params) { const result = this.safeParse(data, params); if (result.success) return result.data; throw result.error; } safeParse(data, params) { var _a3; const ctx = { common: { issues: [], async: (_a3 = params === null || params === void 0 ? void 0 : params.async) !== null && _a3 !== void 0 ? _a3 : false, contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap }, path: (params === null || params === void 0 ? void 0 : params.path) || [], schemaErrorMap: this._def.errorMap, parent: null, data, parsedType: getParsedType(data) }; const result = this._parseSync({ data, path: ctx.path, parent: ctx }); return handleResult(ctx, result); } async parseAsync(data, params) { const result = await this.safeParseAsync(data, params); if (result.success) return result.data; throw result.error; } async safeParseAsync(data, params) { const ctx = { common: { issues: [], contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap, async: true }, path: (params === null || params === void 0 ? void 0 : params.path) || [], schemaErrorMap: this._def.errorMap, parent: null, data, parsedType: getParsedType(data) }; const maybeAsyncResult = this._parse({ data, path: ctx.path, parent: ctx }); const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult)); return handleResult(ctx, result); } refine(check, message) { const getIssueProperties = (val) => { if (typeof message === "string" || typeof message === "undefined") { return { message }; } else if (typeof message === "function") { return message(val); } else { return message; } }; return this._refinement((val, ctx) => { const result = check(val); const setError = () => ctx.addIssue({ code: ZodIssueCode.custom, ...getIssueProperties(val) }); if (typeof Promise !== "undefined" && result instanceof Promise) { return result.then((data) => { if (!data) { setError(); return false; } else { return true; } }); } if (!result) { setError(); return false; } else { return true; } }); } refinement(check, refinementData) { return this._refinement((val, ctx) => { if (!check(val)) { ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData); return false; } else { return true; } }); } _refinement(refinement) { return new ZodEffects({ schema: this, typeName: ZodFirstPartyTypeKind.ZodEffects, effect: { type: "refinement", refinement } }); } superRefine(refinement) { return this._refinement(refinement); } optional() { return ZodOptional.create(this, this._def); } nullable() { return ZodNullable.create(this, this._def); } nullish() { return this.nullable().optional(); } array() { return ZodArray.create(this, this._def); } promise() { return ZodPromise.create(this, this._def); } or(option) { return ZodUnion.create([this, option], this._def); } and(incoming) { return ZodIntersection.create(this, incoming, this._def); } transform(transform) { return new ZodEffects({ ...processCreateParams(this._def), schema: this, typeName: ZodFirstPartyTypeKind.ZodEffects, effect: { type: "transform", transform } }); } default(def) { const defaultValueFunc = typeof def === "function" ? def : () => def; return new ZodDefault({ ...processCreateParams(this._def), innerType: this, defaultValue: defaultValueFunc, typeName: ZodFirstPartyTypeKind.ZodDefault }); } brand() { return new ZodBranded({ typeName: ZodFirstPartyTypeKind.ZodBranded, type: this, ...processCreateParams(this._def) }); } catch(def) { const catchValueFunc = typeof def === "function" ? def : () => def; return new ZodCatch({ ...processCreateParams(this._def), innerType: this, catchValue: catchValueFunc, typeName: ZodFirstPartyTypeKind.ZodCatch }); } describe(description) { const This = this.constructor; return new This({ ...this._def, description }); } pipe(target) { return ZodPipeline.create(this, target); } readonly() { return ZodReadonly.create(this); } isOptional() { return this.safeParse(void 0).success; } isNullable() { return this.safeParse(null).success; } }; var cuidRegex = /^c[^\s-]{8,}$/i; var cuid2Regex = /^[a-z][a-z0-9]*$/; var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/; var uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i; var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i; var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`; var emojiRegex; var ipv4Regex = /^(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))$/; var ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/; var datetimeRegex = (args) => { if (args.precision) { if (args.offset) { return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}(:?\\d{2})?)|Z)$`); } else { return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`); } } else if (args.precision === 0) { if (args.offset) { return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$`); } else { return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`); } } else { if (args.offset) { return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$`); } else { return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`); } } }; function isValidIP(ip, version) { if ((version === "v4" || !version) && ipv4Regex.test(ip)) { return true; } if ((version === "v6" || !version) && ipv6Regex.test(ip)) { return true; } return false; } var ZodString = class extends ZodType { _parse(input) { if (this._def.coerce) { input.data = String(input.data); } const parsedType = this._getType(input); if (parsedType !== ZodParsedType.string) { const ctx2 = this._getOrReturnCtx(input); addIssueToContext( ctx2, { code: ZodIssueCode.invalid_type, expected: ZodParsedType.string, received: ctx2.parsedType } // ); return INVALID; } const status = new ParseStatus(); let ctx = void 0; for (const check of this._def.checks) { if (check.kind === "min") { if (input.data.length < check.value) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { code: ZodIssueCode.too_small, minimum: check.value, type: "string", inclusive: true, exact: false, message: check.message }); status.dirty(); } } else if (check.kind === "max") { if (input.data.length > check.value) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { code: ZodIssueCode.too_big, maximum: check.value, type: "string", inclusive: true, exact: false, message: check.message }); status.dirty(); } } else if (check.kind === "length") { const tooBig = input.data.length > check.value; const tooSmall = input.data.length < check.value; if (tooBig || tooSmall) { ctx = this._getOrReturnCtx(input, ctx); if (tooBig) { addIssueToContext(ctx, { code: ZodIssueCode.too_big, maximum: check.value, type: "string", inclusive: true, exact: true, message: check.message }); } else if (tooSmall) { addIssueToContext(ctx, { code: ZodIssueCode.too_small, minimum: check.value, type: "string", inclusive: true, exact: true, message: check.message }); } status.dirty(); } } else if (check.kind === "email") { if (!emailRegex.test(input.data)) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { validation: "email", code: ZodIssueCode.invalid_string, message: check.message }); status.dirty(); } } else if (check.kind === "emoji") { if (!emojiRegex) { emojiRegex = new RegExp(_emojiRegex, "u"); } if (!emojiRegex.test(input.data)) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { validation: "emoji", code: ZodIssueCode.invalid_string, message: check.message }); status.dirty(); } } else if (check.kind === "uuid") { if (!uuidRegex.test(input.data)) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { validation: "uuid", code: ZodIssueCode.invalid_string, message: check.message }); status.dirty(); } } else if (check.kind === "cuid") { if (!cuidRegex.test(input.data)) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { validation: "cuid", code: ZodIssueCode.invalid_string, message: check.message }); status.dirty(); } } else if (check.kind === "cuid2") { if (!cuid2Regex.test(input.data)) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { validation: "cuid2", code: ZodIssueCode.invalid_string, message: check.message }); status.dirty(); } } else if (check.kind === "ulid") { if (!ulidRegex.test(input.data)) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { validation: "ulid", code: ZodIssueCode.invalid_string, message: check.message }); status.dirty(); } } else if (check.kind === "url") { try { new URL(input.data); } catch (_a3) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { validation: "url", code: ZodIssueCode.invalid_string, message: check.message }); status.dirty(); } } else if (check.kind === "regex") { check.regex.lastIndex = 0; const testResult = check.regex.test(input.data); if (!testResult) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { validation: "regex", code: ZodIssueCode.invalid_string, message: check.message }); status.dirty(); } } else if (check.kind === "trim") { input.data = input.data.trim(); } else if (check.kind === "includes") { if (!input.data.includes(check.value, check.position)) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { code: ZodIssueCode.invalid_string, validation: { includes: check.value, position: check.position }, message: check.message }); status.dirty(); } } else if (check.kind === "toLowerCase") { input.data = input.data.toLowerCase(); } else if (check.kind === "toUpperCase") { input.data = input.data.toUpperCase(); } else if (check.kind === "startsWith") { if (!input.data.startsWith(check.value)) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { code: ZodIssueCode.invalid_string, validation: { startsWith: check.value }, message: check.message }); status.dirty(); } } else if (check.kind === "endsWith") { if (!input.data.endsWith(check.value)) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { code: ZodIssueCode.invalid_string, validation: { endsWith: check.value }, message: check.message }); status.dirty(); } } else if (check.kind === "datetime") { const regex = datetimeRegex(check); if (!regex.test(input.data)) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { code: ZodIssueCode.invalid_string, validation: "datetime", message: check.message }); status.dirty(); } } else if (check.kind === "ip") { if (!isValidIP(input.data, check.version)) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { validation: "ip", code: ZodIssueCode.invalid_string, message: check.message }); status.dirty(); } } else { util.assertNever(check); } } return { status: status.value, value: input.data }; } _regex(regex, validation, message) { return this.refinement((data) => regex.test(data), { validation, code: ZodIssueCode.invalid_string, ...errorUtil.errToObj(message) }); } _addCheck(check) { return new ZodString({ ...this._def, checks: [...this._def.checks, check] }); } email(message) { return this._addCheck({ kind: "email", ...errorUtil.errToObj(message) }); } url(message) { return this._addCheck({ kind: "url", ...errorUtil.errToObj(message) }); } emoji(message) { return this._addCheck({ kind: "emoji", ...errorUtil.errToObj(message) }); } uuid(message) { return this._addCheck({ kind: "uuid", ...errorUtil.errToObj(message) }); } cuid(message) { return this._addCheck({ kind: "cuid", ...errorUtil.errToObj(message) }); } cuid2(message) { return this._addCheck({ kind: "cuid2", ...errorUtil.errToObj(message) }); } ulid(message) { return this._addCheck({ kind: "ulid", ...errorUtil.errToObj(message) }); } ip(options) { return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) }); } datetime(options) { var _a3; if (typeof options === "string") { return this._addCheck({ kind: "datetime", precision: null, offset: false, message: options }); } return this._addCheck({ kind: "datetime", precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision, offset: (_a3 = options === null || options === void 0 ? void 0 : options.offset) !== null && _a3 !== void 0 ? _a3 : false, ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message) }); } regex(regex, message) { return this._addCheck({ kind: "regex", regex, ...errorUtil.errToObj(message) }); } includes(value, options) { return this._addCheck({ kind: "includes", value, position: options === null || options === void 0 ? void 0 : options.position, ...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message) }); } startsWith(value, message) { return this._addCheck({ kind: "startsWith", value, ...errorUtil.errToObj(message) }); } endsWith(value, message) { return this._addCheck({ kind: "endsWith", value, ...errorUtil.errToObj(message) }); } min(minLength, message) { return this._addCheck({ kind: "min", value: minLength, ...errorUtil.errToObj(message) }); } max(maxLength, message) { return this._addCheck({ kind: "max", value: maxLength, ...errorUtil.errToObj(message) }); } length(len, message) { return this._addCheck({ kind: "length", value: len, ...errorUtil.errToObj(message) }); } /** * @deprecated Use z.string().min(1) instead. * @see {@link ZodString.min} */ nonempty(message) { return this.min(1, errorUtil.errToObj(message)); } trim() { return new ZodString({ ...this._def, checks: [...this._def.checks, { kind: "trim" }] }); } toLowerCase() { return new ZodString({ ...this._def, checks: [...this._def.checks, { kind: "toLowerCase" }] }); } toUpperCase() { return new ZodString({ ...this._def, checks: [...this._def.checks, { kind: "toUpperCase" }] }); } get isDatetime() { return !!this._def.checks.find((ch) => ch.kind === "datetime"); } get isEmail() { return !!this._def.checks.find((ch) => ch.kind === "email"); } get isURL() { return !!this._def.checks.find((ch) => ch.kind === "url"); } get isEmoji() { return !!this._def.checks.find((ch) => ch.kind === "emoji"); } get isUUID() { return !!this._def.checks.find((ch) => ch.kind === "uuid"); } get isCUID() { return !!this._def.checks.find((ch) => ch.kind === "cuid"); } get isCUID2() { return !!this._def.checks.find((ch) => ch.kind === "cuid2"); } get isULID() { return !!this._def.checks.find((ch) => ch.kind === "ulid"); } get isIP() { return !!this._def.checks.find((ch) => ch.kind === "ip"); } get minLength() { let min2 = null; for (const ch of this._def.checks) { if (ch.kind === "min") { if (min2 === null || ch.value > min2) min2 = ch.value; } } return min2; } get maxLength() { let max2 = null; for (const ch of this._def.checks) { if (ch.kind === "max") { if (max2 === null || ch.value < max2) max2 = ch.value; } } return max2; } }; ZodString.create = (params) => { var _a3; return new ZodString({ checks: [], typeName: ZodFirstPartyTypeKind.ZodString, coerce: (_a3 = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a3 !== void 0 ? _a3 : false, ...processCreateParams(params) }); }; function floatSafeRemainder(val, step) { const valDecCount = (val.toString().split(".")[1] || "").length; const stepDecCount = (step.toString().split(".")[1] || "").length; const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount; const valInt = parseInt(val.toFixed(decCount).replace(".", "")); const stepInt = parseInt(step.toFixed(decCount).replace(".", "")); return valInt % stepInt / Math.pow(10, decCount); } var ZodNumber = class extends ZodType { constructor() { super(...arguments); this.min = this.gte; this.max = this.lte; this.step = this.multipleOf; } _parse(input) { if (this._def.coerce) { input.data = Number(input.data); } const parsedType = this._getType(input); if (parsedType !== ZodParsedType.number) { const ctx2 = this._getOrReturnCtx(input); addIssueToContext(ctx2, { code: ZodIssueCode.invalid_type, expected: ZodParsedType.number, received: ctx2.parsedType }); return INVALID; } let ctx = void 0; const status = new ParseStatus(); for (const check of this._def.checks) { if (check.kind === "int") { if (!util.isInteger(input.data)) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { code: ZodIssueCode.invalid_type, expected: "integer", received: "float", message: check.message }); status.dirty(); } } else if (check.kind === "min") { const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value; if (tooSmall) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { code: ZodIssueCode.too_small, minimum: check.value, type: "number", inclusive: check.inclusive, exact: false, message: check.message }); status.dirty(); } } else if (check.kind === "max") { const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value; if (tooBig) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { code: ZodIssueCode.too_big, maximum: check.value, type: "number", inclusive: check.inclusive, exact: false, message: check.message }); status.dirty(); } } else if (check.kind === "multipleOf") { if (floatSafeRemainder(input.data, check.value) !== 0) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { code: ZodIssueCode.not_multiple_of, multipleOf: check.value, message: check.message }); status.dirty(); } } else if (check.kind === "finite") { if (!Number.isFinite(input.data)) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { code: ZodIssueCode.not_finite, message: check.message }); status.dirty(); } } else { util.assertNever(check); } } return { status: status.value, value: input.data }; } gte(value, message) { return this.setLimit("min", value, true, errorUtil.toString(message)); } gt(value, message) { return this.setLimit("min", value, false, errorUtil.toString(message)); } lte(value, message) { return this.setLimit("max", value, true, errorUtil.toString(message)); } lt(value, message) { return this.setLimit("max", value, false, errorUtil.toString(message)); } setLimit(kind, value, inclusive, message) { return new ZodNumber({ ...this._def, checks: [ ...this._def.checks, { kind, value, inclusive, message: errorUtil.toString(message) } ] }); } _addCheck(check) { return new ZodNumber({ ...this._def, checks: [...this._def.checks, check] }); } int(message) { return this._addCheck({ kind: "int", message: errorUtil.toString(message) }); } positive(message) { return this._addCheck({ kind: "min", value: 0, inclusive: false, message: errorUtil.toString(message) }); } negative(message) { return this._addCheck({ kind: "max", value: 0, inclusive: false, message: errorUtil.toString(message) }); } nonpositive(message) { return this._addCheck({ kind: "max", value: 0, inclusive: true, message: errorUtil.toString(message) }); } nonnegative(message) { return this._addCheck({ kind: "min", value: 0, inclusive: true, message: errorUtil.toString(message) }); } multipleOf(value, message) { return this._addCheck({ kind: "multipleOf", value, message: errorUtil.toString(message) }); } finite(message) { return this._addCheck({ kind: "finite", message: errorUtil.toString(message) }); } safe(message) { return this._addCheck({ kind: "min", inclusive: true, value: Number.MIN_SAFE_INTEGER, message: errorUtil.toString(message) })._addCheck({ kind: "max", inclusive: true, value: Number.MAX_SAFE_INTEGER, message: errorUtil.toString(message) }); } get minValue() { let min2 = null; for (const ch of this._def.checks) { if (ch.kind === "min") { if (min2 === null || ch.value > min2) min2 = ch.value; } } return min2; } get maxValue() { let max2 = null; for (const ch of this._def.checks) { if (ch.kind === "max") { if (max2 === null || ch.value < max2) max2 = ch.value; } } return max2; } get isInt() { return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value)); } get isFinite() { let max2 = null, min2 = null; for (const ch of this._def.checks) { if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") { return true; } else if (ch.kind === "min") { if (min2 === null || ch.value > min2) min2 = ch.value; } else if (ch.kind === "max") { if (max2 === null || ch.value < max2) max2 = ch.value; } } return Number.isFinite(min2) && Number.isFinite(max2); } }; ZodNumber.create = (params) => { return new ZodNumber({ checks: [], typeName: ZodFirstPartyTypeKind.ZodNumber, coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false, ...processCreateParams(params) }); }; var ZodBigInt = class extends ZodType { constructor() { super(...arguments); this.min = this.gte; this.max = this.lte; } _parse(input) { if (this._def.coerce) { input.data = BigInt(input.data); } const parsedType = this._getType(input); if (parsedType !== ZodParsedType.bigint) { const ctx2 = this._getOrReturnCtx(input); addIssueToContext(ctx2, { code: ZodIssueCode.invalid_type, expected: ZodParsedType.bigint, received: ctx2.parsedType }); return INVALID; } let ctx = void 0; const status = new ParseStatus(); for (const check of this._def.checks) { if (check.kind === "min") { const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value; if (tooSmall) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { code: ZodIssueCode.too_small, type: "bigint", minimum: check.value, inclusive: check.inclusive, message: check.message }); status.dirty(); } } else if (check.kind === "max") { const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value; if (tooBig) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { code: ZodIssueCode.too_big, type: "bigint", maximum: check.value, inclusive: check.inclusive, message: check.message }); status.dirty(); } } else if (check.kind === "multipleOf") { if (input.data % check.value !== BigInt(0)) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { code: ZodIssueCode.not_multiple_of, multipleOf: check.value, message: check.message }); status.dirty(); } } else { util.assertNever(check); } } return { status: status.value, value: input.data }; } gte(value, message) { return this.setLimit("min", value, true, errorUtil.toString(message)); } gt(value, message) { return this.setLimit("min", value, false, errorUtil.toString(message)); } lte(value, message) { return this.setLimit("max", value, true, errorUtil.toString(message)); } lt(value, message) { return this.setLimit("max", value, false, errorUtil.toString(message)); } setLimit(kind, value, inclusive, message) { return new ZodBigInt({ ...this._def, checks: [ ...this._def.checks, { kind, value, inclusive, message: errorUtil.toString(message) } ] }); } _addCheck(check) { return new ZodBigInt({ ...this._def, checks: [...this._def.checks, check] }); } positive(message) { return this._addCheck({ kind: "min", value: BigInt(0), inclusive: false, message: errorUtil.toString(message) }); } negative(message) { return this._addCheck({ kind: "max", value: BigInt(0), inclusive: false, message: errorUtil.toString(message) }); } nonpositive(message) { return this._addCheck({ kind: "max", value: BigInt(0), inclusive: true, message: errorUtil.toString(message) }); } nonnegative(message) { return this._addCheck({ kind: "min", value: BigInt(0), inclusive: true, message: errorUtil.toString(message) }); } multipleOf(value, message) { return this._addCheck({ kind: "multipleOf", value, message: errorUtil.toString(message) }); } get minValue() { let min2 = null; for (const ch of this._def.checks) { if (ch.kind === "min") { if (min2 === null || ch.value > min2) min2 = ch.value; } } return min2; } get maxValue() { let max2 = null; for (const ch of this._def.checks) { if (ch.kind === "max") { if (max2 === null || ch.value < max2) max2 = ch.value; } } return max2; } }; ZodBigInt.create = (params) => { var _a3; return new ZodBigInt({ checks: [], typeName: ZodFirstPartyTypeKind.ZodBigInt, coerce: (_a3 = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a3 !== void 0 ? _a3 : false, ...processCreateParams(params) }); }; var ZodBoolean = class extends ZodType { _parse(input) { if (this._def.coerce) { input.data = Boolean(input.data); } const parsedType = this._getType(input); if (parsedType !== ZodParsedType.boolean) { const ctx = this._getOrReturnCtx(input); addIssueToContext(ctx, { code: ZodIssueCode.invalid_type, expected: ZodParsedType.boolean, received: ctx.parsedType }); return INVALID; } return OK(input.data); } }; ZodBoolean.create = (params) => { return new ZodBoolean({ typeName: ZodFirstPartyTypeKind.ZodBoolean, coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false, ...processCreateParams(params) }); }; var ZodDate = class extends ZodType { _parse(input) { if (this._def.coerce) { input.data = new Date(input.data); } const parsedType = this._getType(input); if (parsedType !== ZodParsedType.date) { const ctx2 = this._getOrReturnCtx(input); addIssueToContext(ctx2, { code: ZodIssueCode.invalid_type, expected: ZodParsedType.date, received: ctx2.parsedType }); return INVALID; } if (isNaN(input.data.getTime())) { const ctx2 = this._getOrReturnCtx(input); addIssueToContext(ctx2, { code: ZodIssueCode.invalid_date }); return INVALID; } const status = new ParseStatus(); let ctx = void 0; for (const check of this._def.checks) { if (check.kind === "min") { if (input.data.getTime() < check.value) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { code: ZodIssueCode.too_small, message: check.message, inclusive: true, exact: false, minimum: check.value, type: "date" }); status.dirty(); } } else if (check.kind === "max") { if (input.data.getTime() > check.value) { ctx = this._getOrReturnCtx(input, ctx); addIssueToContext(ctx, { code: ZodIssueCode.too_big, message: check.message, inclusive: true, exact: false, maximum: check.value, type: "date" }); status.dirty(); } } else { util.assertNever(check); } } return { status: status.value, value: new Date(input.data.getTime()) }; } _addCheck(check) { return new ZodDate({ ...this._def, checks: [...this._def.checks, check] }); } min(minDate, message) { return this._addCheck({ kind: "min", value: minDate.getTime(), message: errorUtil.toString(message) }); } max(maxDate, message) { return this._addCheck({ kind: "max", value: maxDate.getTime(), message: errorUtil.toString(message) }); } get minDate() { let min2 = null; for (const ch of this._def.checks) { if (ch.kind === "min") { if (min2 === null || ch.value > min2) min2 = ch.value; } } return min2 != null ? new Date(min2) : null; } get maxDate() { let max2 = null; for (const ch of this._def.checks) { if (ch.kind === "max") { if (max2 === null || ch.value < max2) max2 = ch.value; } } return max2 != null ? new Date(max2) : null; } }; ZodDate.create = (params) => { return new ZodDate({ checks: [], coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false, typeName: ZodFirstPartyTypeKind.ZodDate, ...processCreateParams(params) }); }; var ZodSymbol = class extends ZodType { _parse(input) { const parsedType = this._getType(input); if (parsedType !== ZodParsedType.symbol) { const ctx = this._getOrReturnCtx(input); addIssueToContext(ctx, { code: ZodIssueCode.invalid_type, expected: ZodParsedType.symbol, received: ctx.parsedType }); return INVALID; } return OK(input.data); } }; ZodSymbol.create = (params) => { return new ZodSymbol({ typeName: ZodFirstPartyTypeKind.ZodSymbol, ...processCreateParams(params) }); }; var ZodUndefined = class extends ZodType { _parse(input) { const parsedType = this._getType(input); if (parsedType !== ZodParsedType.undefined) { const ctx = this._getOrReturnCtx(input); addIssueToContext(ctx, { code: ZodIssueCode.invalid_type, expected: ZodParsedType.undefined, received: ctx.parsedType }); return INVALID; } return OK(input.data); } }; ZodUndefined.create = (params) => { return new ZodUndefined({ typeName: ZodFirstPartyTypeKind.ZodUndefined, ...processCreateParams(params) }); }; var ZodNull = class extends ZodType { _parse(input) { const parsedType = this._getType(input); if (parsedType !== ZodParsedType.null) { const ctx = this._getOrReturnCtx(input); addIssueToContext(ctx, { code: ZodIssueCode.invalid_type, expected: ZodParsedType.null, received: ctx.parsedType }); return INVALID; } return OK(input.data); } }; ZodNull.create = (params) => { return new ZodNull({ typeName: ZodFirstPartyTypeKind.ZodNull, ...processCreateParams(params) }); }; var ZodAny = class extends ZodType { constructor() { super(...arguments); this._any = true; } _parse(input) { return OK(input.data); } }; ZodAny.create = (params) => { return new ZodAny({ typeName: ZodFirstPartyTypeKind.ZodAny, ...processCreateParams(params) }); }; var ZodUnknown = class extends ZodType { constructor() { super(...arguments); this._unknown = true; } _parse(input) { return OK(input.data); } }; ZodUnknown.create = (params) => { return new ZodUnknown({ typeName: ZodFirstPartyTypeKind.ZodUnknown, ...processCreateParams(params) }); }; var ZodNever = class extends ZodType { _parse(input) { const ctx = this._getOrReturnCtx(input); addIssueToContext(ctx, { code: ZodIssueCode.invalid_type, expected: ZodParsedType.never, received: ctx.parsedType }); return INVALID; } }; ZodNever.create = (params) => { return new ZodNever({ typeName: ZodFirstPartyTypeKind.ZodNever, ...processCreateParams(params) }); }; var ZodVoid = class extends ZodType { _parse(input) { const parsedType = this._getType(input); if (parsedType !== ZodParsedType.undefined) { const ctx = this._getOrReturnCtx(input); addIssueToContext(ctx, { code: ZodIssueCode.invalid_type, expected: ZodParsedType.void, received: ctx.parsedType }); return INVALID; } return OK(input.data); } }; ZodVoid.create = (params) => { return new ZodVoid({ typeName: ZodFirstPartyTypeKind.ZodVoid, ...processCreateParams(params) }); }; var ZodArray = class extends ZodType { _parse(input) { const { ctx, status } = this._processInputParams(input); const def = this._def; if (ctx.parsedType !== ZodParsedType.array) { addIssueToContext(ctx, { code: ZodIssueCode.invalid_type, expected: ZodParsedType.array, received: ctx.parsedType }); return INVALID; } if (def.exactLength !== null) { const tooBig = ctx.data.length > def.exactLength.value; const tooSmall = ctx.data.length < def.exactLength.value; if (tooBig || tooSmall) { addIssueToContext(ctx, { code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small, minimum: tooSmall ? def.exactLength.value : void 0, maximum: tooBig ? def.exactLength.value : void 0, type: "array", inclusive: true, exact: true, message: def.exactLength.message }); status.dirty(); } } if (def.minLength !== null) { if (ctx.data.length < def.minLength.value) { addIssueToContext(ctx, { code: ZodIssueCode.too_small, minimum: def.minLength.value, type: "array", inclusive: true, exact: false, message: def.minLength.message }); status.dirty(); } } if (def.maxLength !== null) { if (ctx.data.length > def.maxLength.value) { addIssueToContext(ctx, { code: ZodIssueCode.too_big, maximum: def.maxLength.value, type: "array", inclusive: true, exact: false, message: def.maxLength.message }); status.dirty(); } } if (ctx.common.async) { return Promise.all([...ctx.data].map((item, i) => { return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i)); })).then((result2) => { return ParseStatus.mergeArray(status, result2); }); } const result = [...ctx.data].map((item, i) => { return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i)); }); return ParseStatus.mergeArray(status, result); } get element() { return this._def.type; } min(minLength, message) { return new ZodArray({ ...this._def, minLength: { value: minLength, message: errorUtil.toString(message) } }); } max(maxLength, message) { return new ZodArray({ ...this._def, maxLength: { value: maxLength, message: errorUtil.toString(message) } }); } length(len, message) { return new ZodArray({ ...this._def, exactLength: { value: len, message: errorUtil.toString(message) } }); } nonempty(message) { return this.min(1, message); } }; ZodArray.create = (schema, params) => { return new ZodArray({ type: schema, minLength: null, maxLength: null, exactLength: null, typeName: ZodFirstPartyTypeKind.ZodArray, ...processCreateParams(params) }); }; function deepPartialify(schema) { if (schema instanceof ZodObject) { const newShape = {}; for (const key in schema.shape) { const fieldSchema = schema.shape[key]; newShape[key] = ZodOptional.create(deepPartialify(fieldSchema)); } return new ZodObject({ ...schema._def, shape: () => newShape }); } else if (schema instanceof ZodArray) { return new ZodArray({ ...schema._def, type: deepPartialify(schema.element) }); } else if (schema instanceof ZodOptional) { return ZodOptional.create(deepPartialify(schema.unwrap())); } else if (schema instanceof ZodNullable) { return ZodNullable.create(deepPartialify(schema.unwrap())); } else if (schema instanceof ZodTuple) { return ZodTuple.create(schema.items.map((item) => deepPartialify(item))); } else { return schema; } } var ZodObject = class extends ZodType { constructor() { super(...arguments); this._cached = null; this.nonstrict = this.passthrough; this.augment = this.extend; } _getCached() { if (this._cached !== null) return this._cached; const shape = this._def.shape(); const keys = util.objectKeys(shape); return this._cached = { shape, keys }; } _parse(input) { const parsedType = this._getType(input); if (parsedType !== ZodParsedType.object) { const ctx2 = this._getOrReturnCtx(input); addIssueToContext(ctx2, { code: ZodIssueCode.invalid_type, expected: ZodParsedType.object, received: ctx2.parsedType }); return INVALID; } const { status, ctx } = this._processInputParams(input); const { shape, keys: shapeKeys } = this._getCached(); const extraKeys = []; if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) { for (const key in ctx.data) { if (!shapeKeys.includes(key)) { extraKeys.push(key); } } } const pairs = []; for (const key of shapeKeys) { const keyValidator = shape[key]; const value = ctx.data[key]; pairs.push({ key: { status: "valid", value: key }, value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)), alwaysSet: key in ctx.data }); } if (this._def.catchall instanceof ZodNever) { const unknownKeys = this._def.unknownKeys; if (unknownKeys === "passthrough") { for (const key of extraKeys) { pairs.push({ key: { status: "valid", value: key }, value: { status: "valid", value: ctx.data[key] } }); } } else if (unknownKeys === "strict") { if (extraKeys.length > 0) { addIssueToContext(ctx, { code: ZodIssueCode.unrecognized_keys, keys: extraKeys }); status.dirty(); } } else if (unknownKeys === "strip") ; else { throw new Error(`Internal ZodObject error: invalid unknownKeys value.`); } } else { const catchall = this._def.catchall; for (const key of extraKeys) { const value = ctx.data[key]; pairs.push({ key: { status: "valid", value: key }, value: catchall._parse( new ParseInputLazyPath(ctx, value, ctx.path, key) //, ctx.child(key), value, getParsedType(value) ), alwaysSet: key in ctx.data }); } } if (ctx.common.async) { return Promise.resolve().then(async () => { const syncPairs = []; for (const pair of pairs) { const key = await pair.key; syncPairs.push({ key, value: await pair.value, alwaysSet: pair.alwaysSet }); } return syncPairs; }).then((syncPairs) => { return ParseStatus.mergeObjectSync(status, syncPairs); }); } else { return ParseStatus.mergeObjectSync(status, pairs); } } get shape() { return this._def.shape(); } strict(message) { errorUtil.errToObj; return new ZodObject({ ...this._def, unknownKeys: "strict", ...message !== void 0 ? { errorMap: (issue, ctx) => { var _a3, _b3, _c2, _d2; const defaultError = (_c2 = (_b3 = (_a3 = this._def).errorMap) === null || _b3 === void 0 ? void 0 : _b3.call(_a3, issue, ctx).message) !== null && _c2 !== void 0 ? _c2 : ctx.defaultError; if (issue.code === "unrecognized_keys") return { message: (_d2 = errorUtil.errToObj(message).message) !== null && _d2 !== void 0 ? _d2 : defaultError }; return { message: defaultError }; } } : {} }); } strip() { return new ZodObject({ ...this._def, unknownKeys: "strip" }); } passthrough() { return new ZodObject({ ...this._def, unknownKeys: "passthrough" }); } // const AugmentFactory = // (def: Def) => // ( // augmentation: Augmentation // ): ZodObject< // extendShape, Augmentation>, // Def["unknownKeys"], // Def["catchall"] // > => { // return new ZodObject({ // ...def, // shape: () => ({ // ...def.shape(), // ...augmentation, // }), // }) as any; // }; extend(augmentation) { return new ZodObject({ ...this._def, shape: () => ({ ...this._def.shape(), ...augmentation }) }); } /** * Prior to zod@1.0.12 there was a bug in the * inferred type of merged objects. Please * upgrade if you are experiencing issues. */ merge(merging) { const merged = new ZodObject({ unknownKeys: merging._def.unknownKeys, catchall: merging._def.catchall, shape: () => ({ ...this._def.shape(), ...merging._def.shape() }), typeName: ZodFirstPartyTypeKind.ZodObject }); return merged; } // merge< // Incoming extends AnyZodObject, // Augmentation extends Incoming["shape"], // NewOutput extends { // [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation // ? Augmentation[k]["_output"] // : k extends keyof Output // ? Output[k] // : never; // }, // NewInput extends { // [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation // ? Augmentation[k]["_input"] // : k extends keyof Input // ? Input[k] // : never; // } // >( // merging: Incoming // ): ZodObject< // extendShape>, // Incoming["_def"]["unknownKeys"], // Incoming["_def"]["catchall"], // NewOutput, // NewInput // > { // const merged: any = new ZodObject({ // unknownKeys: merging._def.unknownKeys, // catchall: merging._def.catchall, // shape: () => // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()), // typeName: ZodFirstPartyTypeKind.ZodObject, // }) as any; // return merged; // } setKey(key, schema) { return this.augment({ [key]: schema }); } // merge( // merging: Incoming // ): //ZodObject = (merging) => { // ZodObject< // extendShape>, // Incoming["_def"]["unknownKeys"], // Incoming["_def"]["catchall"] // > { // // const mergedShape = objectUtil.mergeShapes( // // this._def.shape(), // // merging._def.shape() // // ); // const merged: any = new ZodObject({ // unknownKeys: merging._def.unknownKeys, // catchall: merging._def.catchall, // shape: () => // objectUtil.mergeShapes(this._def.shape(), merging._def.shape()), // typeName: ZodFirstPartyTypeKind.ZodObject, // }) as any; // return merged; // } catchall(index6) { return new ZodObject({ ...this._def, catchall: index6 }); } pick(mask) { const shape = {}; util.objectKeys(mask).forEach((key) => { if (mask[key] && this.shape[key]) { shape[key] = this.shape[key]; } }); return new ZodObject({ ...this._def, shape: () => shape }); } omit(mask) { const shape = {}; util.objectKeys(this.shape).forEach((key) => { if (!mask[key]) { shape[key] = this.shape[key]; } }); return new ZodObject({ ...this._def, shape: () => shape }); } /** * @deprecated */ deepPartial() { return deepPartialify(this); } partial(mask) { const newShape = {}; util.objectKeys(this.shape).forEach((key) => { const fieldSchema = this.shape[key]; if (mask && !mask[key]) { newShape[key] = fieldSchema; } else { newShape[key] = fieldSchema.optional(); } }); return new ZodObject({ ...this._def, shape: () => newShape }); } required(mask) { const newShape = {}; util.objectKeys(this.shape).forEach((key) => { if (mask && !mask[key]) { newShape[key] = this.shape[key]; } else { const fieldSchema = this.shape[key]; let newField = fieldSchema; while (newField instanceof ZodOptional) { newField = newField._def.innerType; } newShape[key] = newField; } }); return new ZodObject({ ...this._def, shape: () => newShape }); } keyof() { return createZodEnum(util.objectKeys(this.shape)); } }; ZodObject.create = (shape, params) => { return new ZodObject({ shape: () => shape, unknownKeys: "strip", catchall: ZodNever.create(), typeName: ZodFirstPartyTypeKind.ZodObject, ...processCreateParams(params) }); }; ZodObject.strictCreate = (shape, params) => { return new ZodObject({ shape: () => shape, unknownKeys: "strict", catchall: ZodNever.create(), typeName: ZodFirstPartyTypeKind.ZodObject, ...processCreateParams(params) }); }; ZodObject.lazycreate = (shape, params) => { return new ZodObject({ shape, unknownKeys: "strip", catchall: ZodNever.create(), typeName: ZodFirstPartyTypeKind.ZodObject, ...processCreateParams(params) }); }; var ZodUnion = class extends ZodType { _parse(input) { const { ctx } = this._processInputParams(input); const options = this._def.options; function handleResults(results) { for (const result of results) { if (result.result.status === "valid") { return result.result; } } for (const result of results) { if (result.result.status === "dirty") { ctx.common.issues.push(...result.ctx.common.issues); return result.result; } } const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues)); addIssueToContext(ctx, { code: ZodIssueCode.invalid_union, unionErrors }); return INVALID; } if (ctx.common.async) { return Promise.all(options.map(async (option) => { const childCtx = { ...ctx, common: { ...ctx.common, issues: [] }, parent: null }; return { result: await option._parseAsync({ data: ctx.data, path: ctx.path, parent: childCtx }), ctx: childCtx }; })).then(handleResults); } else { let dirty = void 0; const issues = []; for (const option of options) { const childCtx = { ...ctx, common: { ...ctx.common, issues: [] }, parent: null }; const result = option._parseSync({ data: ctx.data, path: ctx.path, parent: childCtx }); if (result.status === "valid") { return result; } else if (result.status === "dirty" && !dirty) { dirty = { result, ctx: childCtx }; } if (childCtx.common.issues.length) { issues.push(childCtx.common.issues); } } if (dirty) { ctx.common.issues.push(...dirty.ctx.common.issues); return dirty.result; } const unionErrors = issues.map((issues2) => new ZodError(issues2)); addIssueToContext(ctx, { code: ZodIssueCode.invalid_union, unionErrors }); return INVALID; } } get options() { return this._def.options; } }; ZodUnion.create = (types, params) => { return new ZodUnion({ options: types, typeName: ZodFirstPartyTypeKind.ZodUnion, ...processCreateParams(params) }); }; var getDiscriminator = (type) => { if (type instanceof ZodLazy) { return getDiscriminator(type.schema); } else if (type instanceof ZodEffects) { return getDiscriminator(type.innerType()); } else if (type instanceof ZodLiteral) { return [type.value]; } else if (type instanceof ZodEnum) { return type.options; } else if (type instanceof ZodNativeEnum) { return Object.keys(type.enum); } else if (type instanceof ZodDefault) { return getDiscriminator(type._def.innerType); } else if (type instanceof ZodUndefined) { return [void 0]; } else if (type instanceof ZodNull) { return [null]; } else { return null; } }; var ZodDiscriminatedUnion = class extends ZodType { _parse(input) { const { ctx } = this._processInputParams(input); if (ctx.parsedType !== ZodParsedType.object) { addIssueToContext(ctx, { code: ZodIssueCode.invalid_type, expected: ZodParsedType.object, received: ctx.parsedType }); return INVALID; } const discriminator = this.discriminator; const discriminatorValue = ctx.data[discriminator]; const option = this.optionsMap.get(discriminatorValue); if (!option) { addIssueToContext(ctx, { code: ZodIssueCode.invalid_union_discriminator, options: Array.from(this.optionsMap.keys()), path: [discriminator] }); return INVALID; } if (ctx.common.async) { return option._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }); } else { return option._parseSync({ data: ctx.data, path: ctx.path, parent: ctx }); } } get discriminator() { return this._def.discriminator; } get options() { return this._def.options; } get optionsMap() { return this._def.optionsMap; } /** * The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor. * However, it only allows a union of objects, all of which need to share a discriminator property. This property must * have a different value for each object in the union. * @param discriminator the name of the discriminator property * @param types an array of object schemas * @param params */ static create(discriminator, options, params) { const optionsMap = /* @__PURE__ */ new Map(); for (const type of options) { const discriminatorValues = getDiscriminator(type.shape[discriminator]); if (!discriminatorValues) { throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`); } for (const value of discriminatorValues) { if (optionsMap.has(value)) { throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`); } optionsMap.set(value, type); } } return new ZodDiscriminatedUnion({ typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion, discriminator, options, optionsMap, ...processCreateParams(params) }); } }; function mergeValues(a2, b) { const aType = getParsedType(a2); const bType = getParsedType(b); if (a2 === b) { return { valid: true, data: a2 }; } else if (aType === ZodParsedType.object && bType === ZodParsedType.object) { const bKeys = util.objectKeys(b); const sharedKeys = util.objectKeys(a2).filter((key) => bKeys.indexOf(key) !== -1); const newObj = { ...a2, ...b }; for (const key of sharedKeys) { const sharedValue = mergeValues(a2[key], b[key]); if (!sharedValue.valid) { return { valid: false }; } newObj[key] = sharedValue.data; } return { valid: true, data: newObj }; } else if (aType === ZodParsedType.array && bType === ZodParsedType.array) { if (a2.length !== b.length) { return { valid: false }; } const newArray = []; for (let index6 = 0; index6 < a2.length; index6++) { const itemA = a2[index6]; const itemB = b[index6]; const sharedValue = mergeValues(itemA, itemB); if (!sharedValue.valid) { return { valid: false }; } newArray.push(sharedValue.data); } return { valid: true, data: newArray }; } else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a2 === +b) { return { valid: true, data: a2 }; } else { return { valid: false }; } } var ZodIntersection = class extends ZodType { _parse(input) { const { status, ctx } = this._processInputParams(input); const handleParsed = (parsedLeft, parsedRight) => { if (isAborted(parsedLeft) || isAborted(parsedRight)) { return INVALID; } const merged = mergeValues(parsedLeft.value, parsedRight.value); if (!merged.valid) { addIssueToContext(ctx, { code: ZodIssueCode.invalid_intersection_types }); return INVALID; } if (isDirty(parsedLeft) || isDirty(parsedRight)) { status.dirty(); } return { status: status.value, value: merged.data }; }; if (ctx.common.async) { return Promise.all([ this._def.left._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }), this._def.right._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }) ]).then(([left, right]) => handleParsed(left, right)); } else { return handleParsed(this._def.left._parseSync({ data: ctx.data, path: ctx.path, parent: ctx }), this._def.right._parseSync({ data: ctx.data, path: ctx.path, parent: ctx })); } } }; ZodIntersection.create = (left, right, params) => { return new ZodIntersection({ left, right, typeName: ZodFirstPartyTypeKind.ZodIntersection, ...processCreateParams(params) }); }; var ZodTuple = class extends ZodType { _parse(input) { const { status, ctx } = this._processInputParams(input); if (ctx.parsedType !== ZodParsedType.array) { addIssueToContext(ctx, { code: ZodIssueCode.invalid_type, expected: ZodParsedType.array, received: ctx.parsedType }); return INVALID; } if (ctx.data.length < this._def.items.length) { addIssueToContext(ctx, { code: ZodIssueCode.too_small, minimum: this._def.items.length, inclusive: true, exact: false, type: "array" }); return INVALID; } const rest = this._def.rest; if (!rest && ctx.data.length > this._def.items.length) { addIssueToContext(ctx, { code: ZodIssueCode.too_big, maximum: this._def.items.length, inclusive: true, exact: false, type: "array" }); status.dirty(); } const items = [...ctx.data].map((item, itemIndex) => { const schema = this._def.items[itemIndex] || this._def.rest; if (!schema) return null; return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex)); }).filter((x3) => !!x3); if (ctx.common.async) { return Promise.all(items).then((results) => { return ParseStatus.mergeArray(status, results); }); } else { return ParseStatus.mergeArray(status, items); } } get items() { return this._def.items; } rest(rest) { return new ZodTuple({ ...this._def, rest }); } }; ZodTuple.create = (schemas, params) => { if (!Array.isArray(schemas)) { throw new Error("You must pass an array of schemas to z.tuple([ ... ])"); } return new ZodTuple({ items: schemas, typeName: ZodFirstPartyTypeKind.ZodTuple, rest: null, ...processCreateParams(params) }); }; var ZodRecord = class extends ZodType { get keySchema() { return this._def.keyType; } get valueSchema() { return this._def.valueType; } _parse(input) { const { status, ctx } = this._processInputParams(input); if (ctx.parsedType !== ZodParsedType.object) { addIssueToContext(ctx, { code: ZodIssueCode.invalid_type, expected: ZodParsedType.object, received: ctx.parsedType }); return INVALID; } const pairs = []; const keyType = this._def.keyType; const valueType = this._def.valueType; for (const key in ctx.data) { pairs.push({ key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)), value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)) }); } if (ctx.common.async) { return ParseStatus.mergeObjectAsync(status, pairs); } else { return ParseStatus.mergeObjectSync(status, pairs); } } get element() { return this._def.valueType; } static create(first, second, third) { if (second instanceof ZodType) { return new ZodRecord({ keyType: first, valueType: second, typeName: ZodFirstPartyTypeKind.ZodRecord, ...processCreateParams(third) }); } return new ZodRecord({ keyType: ZodString.create(), valueType: first, typeName: ZodFirstPartyTypeKind.ZodRecord, ...processCreateParams(second) }); } }; var ZodMap = class extends ZodType { get keySchema() { return this._def.keyType; } get valueSchema() { return this._def.valueType; } _parse(input) { const { status, ctx } = this._processInputParams(input); if (ctx.parsedType !== ZodParsedType.map) { addIssueToContext(ctx, { code: ZodIssueCode.invalid_type, expected: ZodParsedType.map, received: ctx.parsedType }); return INVALID; } const keyType = this._def.keyType; const valueType = this._def.valueType; const pairs = [...ctx.data.entries()].map(([key, value], index6) => { return { key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index6, "key"])), value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index6, "value"])) }; }); if (ctx.common.async) { const finalMap = /* @__PURE__ */ new Map(); return Promise.resolve().then(async () => { for (const pair of pairs) { const key = await pair.key; const value = await pair.value; if (key.status === "aborted" || value.status === "aborted") { return INVALID; } if (key.status === "dirty" || value.status === "dirty") { status.dirty(); } finalMap.set(key.value, value.value); } return { status: status.value, value: finalMap }; }); } else { const finalMap = /* @__PURE__ */ new Map(); for (const pair of pairs) { const key = pair.key; const value = pair.value; if (key.status === "aborted" || value.status === "aborted") { return INVALID; } if (key.status === "dirty" || value.status === "dirty") { status.dirty(); } finalMap.set(key.value, value.value); } return { status: status.value, value: finalMap }; } } }; ZodMap.create = (keyType, valueType, params) => { return new ZodMap({ valueType, keyType, typeName: ZodFirstPartyTypeKind.ZodMap, ...processCreateParams(params) }); }; var ZodSet = class extends ZodType { _parse(input) { const { status, ctx } = this._processInputParams(input); if (ctx.parsedType !== ZodParsedType.set) { addIssueToContext(ctx, { code: ZodIssueCode.invalid_type, expected: ZodParsedType.set, received: ctx.parsedType }); return INVALID; } const def = this._def; if (def.minSize !== null) { if (ctx.data.size < def.minSize.value) { addIssueToContext(ctx, { code: ZodIssueCode.too_small, minimum: def.minSize.value, type: "set", inclusive: true, exact: false, message: def.minSize.message }); status.dirty(); } } if (def.maxSize !== null) { if (ctx.data.size > def.maxSize.value) { addIssueToContext(ctx, { code: ZodIssueCode.too_big, maximum: def.maxSize.value, type: "set", inclusive: true, exact: false, message: def.maxSize.message }); status.dirty(); } } const valueType = this._def.valueType; function finalizeSet(elements2) { const parsedSet = /* @__PURE__ */ new Set(); for (const element of elements2) { if (element.status === "aborted") return INVALID; if (element.status === "dirty") status.dirty(); parsedSet.add(element.value); } return { status: status.value, value: parsedSet }; } const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i))); if (ctx.common.async) { return Promise.all(elements).then((elements2) => finalizeSet(elements2)); } else { return finalizeSet(elements); } } min(minSize, message) { return new ZodSet({ ...this._def, minSize: { value: minSize, message: errorUtil.toString(message) } }); } max(maxSize, message) { return new ZodSet({ ...this._def, maxSize: { value: maxSize, message: errorUtil.toString(message) } }); } size(size, message) { return this.min(size, message).max(size, message); } nonempty(message) { return this.min(1, message); } }; ZodSet.create = (valueType, params) => { return new ZodSet({ valueType, minSize: null, maxSize: null, typeName: ZodFirstPartyTypeKind.ZodSet, ...processCreateParams(params) }); }; var ZodFunction = class extends ZodType { constructor() { super(...arguments); this.validate = this.implement; } _parse(input) { const { ctx } = this._processInputParams(input); if (ctx.parsedType !== ZodParsedType.function) { addIssueToContext(ctx, { code: ZodIssueCode.invalid_type, expected: ZodParsedType.function, received: ctx.parsedType }); return INVALID; } function makeArgsIssue(args, error) { return makeIssue({ data: args, path: ctx.path, errorMaps: [ ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), errorMap ].filter((x3) => !!x3), issueData: { code: ZodIssueCode.invalid_arguments, argumentsError: error } }); } function makeReturnsIssue(returns, error) { return makeIssue({ data: returns, path: ctx.path, errorMaps: [ ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), errorMap ].filter((x3) => !!x3), issueData: { code: ZodIssueCode.invalid_return_type, returnTypeError: error } }); } const params = { errorMap: ctx.common.contextualErrorMap }; const fn = ctx.data; if (this._def.returns instanceof ZodPromise) { const me = this; return OK(async function(...args) { const error = new ZodError([]); const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => { error.addIssue(makeArgsIssue(args, e)); throw error; }); const result = await Reflect.apply(fn, this, parsedArgs); const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => { error.addIssue(makeReturnsIssue(result, e)); throw error; }); return parsedReturns; }); } else { const me = this; return OK(function(...args) { const parsedArgs = me._def.args.safeParse(args, params); if (!parsedArgs.success) { throw new ZodError([makeArgsIssue(args, parsedArgs.error)]); } const result = Reflect.apply(fn, this, parsedArgs.data); const parsedReturns = me._def.returns.safeParse(result, params); if (!parsedReturns.success) { throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]); } return parsedReturns.data; }); } } parameters() { return this._def.args; } returnType() { return this._def.returns; } args(...items) { return new ZodFunction({ ...this._def, args: ZodTuple.create(items).rest(ZodUnknown.create()) }); } returns(returnType) { return new ZodFunction({ ...this._def, returns: returnType }); } implement(func) { const validatedFunc = this.parse(func); return validatedFunc; } strictImplement(func) { const validatedFunc = this.parse(func); return validatedFunc; } static create(args, returns, params) { return new ZodFunction({ args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()), returns: returns || ZodUnknown.create(), typeName: ZodFirstPartyTypeKind.ZodFunction, ...processCreateParams(params) }); } }; var ZodLazy = class extends ZodType { get schema() { return this._def.getter(); } _parse(input) { const { ctx } = this._processInputParams(input); const lazySchema = this._def.getter(); return lazySchema._parse({ data: ctx.data, path: ctx.path, parent: ctx }); } }; ZodLazy.create = (getter, params) => { return new ZodLazy({ getter, typeName: ZodFirstPartyTypeKind.ZodLazy, ...processCreateParams(params) }); }; var ZodLiteral = class extends ZodType { _parse(input) { if (input.data !== this._def.value) { const ctx = this._getOrReturnCtx(input); addIssueToContext(ctx, { received: ctx.data, code: ZodIssueCode.invalid_literal, expected: this._def.value }); return INVALID; } return { status: "valid", value: input.data }; } get value() { return this._def.value; } }; ZodLiteral.create = (value, params) => { return new ZodLiteral({ value, typeName: ZodFirstPartyTypeKind.ZodLiteral, ...processCreateParams(params) }); }; function createZodEnum(values, params) { return new ZodEnum({ values, typeName: ZodFirstPartyTypeKind.ZodEnum, ...processCreateParams(params) }); } var ZodEnum = class extends ZodType { _parse(input) { if (typeof input.data !== "string") { const ctx = this._getOrReturnCtx(input); const expectedValues = this._def.values; addIssueToContext(ctx, { expected: util.joinValues(expectedValues), received: ctx.parsedType, code: ZodIssueCode.invalid_type }); return INVALID; } if (this._def.values.indexOf(input.data) === -1) { const ctx = this._getOrReturnCtx(input); const expectedValues = this._def.values; addIssueToContext(ctx, { received: ctx.data, code: ZodIssueCode.invalid_enum_value, options: expectedValues }); return INVALID; } return OK(input.data); } get options() { return this._def.values; } get enum() { const enumValues = {}; for (const val of this._def.values) { enumValues[val] = val; } return enumValues; } get Values() { const enumValues = {}; for (const val of this._def.values) { enumValues[val] = val; } return enumValues; } get Enum() { const enumValues = {}; for (const val of this._def.values) { enumValues[val] = val; } return enumValues; } extract(values) { return ZodEnum.create(values); } exclude(values) { return ZodEnum.create(this.options.filter((opt) => !values.includes(opt))); } }; ZodEnum.create = createZodEnum; var ZodNativeEnum = class extends ZodType { _parse(input) { const nativeEnumValues = util.getValidEnumValues(this._def.values); const ctx = this._getOrReturnCtx(input); if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) { const expectedValues = util.objectValues(nativeEnumValues); addIssueToContext(ctx, { expected: util.joinValues(expectedValues), received: ctx.parsedType, code: ZodIssueCode.invalid_type }); return INVALID; } if (nativeEnumValues.indexOf(input.data) === -1) { const expectedValues = util.objectValues(nativeEnumValues); addIssueToContext(ctx, { received: ctx.data, code: ZodIssueCode.invalid_enum_value, options: expectedValues }); return INVALID; } return OK(input.data); } get enum() { return this._def.values; } }; ZodNativeEnum.create = (values, params) => { return new ZodNativeEnum({ values, typeName: ZodFirstPartyTypeKind.ZodNativeEnum, ...processCreateParams(params) }); }; var ZodPromise = class extends ZodType { unwrap() { return this._def.type; } _parse(input) { const { ctx } = this._processInputParams(input); if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) { addIssueToContext(ctx, { code: ZodIssueCode.invalid_type, expected: ZodParsedType.promise, received: ctx.parsedType }); return INVALID; } const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data); return OK(promisified.then((data) => { return this._def.type.parseAsync(data, { path: ctx.path, errorMap: ctx.common.contextualErrorMap }); })); } }; ZodPromise.create = (schema, params) => { return new ZodPromise({ type: schema, typeName: ZodFirstPartyTypeKind.ZodPromise, ...processCreateParams(params) }); }; var ZodEffects = class extends ZodType { innerType() { return this._def.schema; } sourceType() { return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema; } _parse(input) { const { status, ctx } = this._processInputParams(input); const effect = this._def.effect || null; const checkCtx = { addIssue: (arg) => { addIssueToContext(ctx, arg); if (arg.fatal) { status.abort(); } else { status.dirty(); } }, get path() { return ctx.path; } }; checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx); if (effect.type === "preprocess") { const processed = effect.transform(ctx.data, checkCtx); if (ctx.common.issues.length) { return { status: "dirty", value: ctx.data }; } if (ctx.common.async) { return Promise.resolve(processed).then((processed2) => { return this._def.schema._parseAsync({ data: processed2, path: ctx.path, parent: ctx }); }); } else { return this._def.schema._parseSync({ data: processed, path: ctx.path, parent: ctx }); } } if (effect.type === "refinement") { const executeRefinement = (acc) => { const result = effect.refinement(acc, checkCtx); if (ctx.common.async) { return Promise.resolve(result); } if (result instanceof Promise) { throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead."); } return acc; }; if (ctx.common.async === false) { const inner = this._def.schema._parseSync({ data: ctx.data, path: ctx.path, parent: ctx }); if (inner.status === "aborted") return INVALID; if (inner.status === "dirty") status.dirty(); executeRefinement(inner.value); return { status: status.value, value: inner.value }; } else { return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((inner) => { if (inner.status === "aborted") return INVALID; if (inner.status === "dirty") status.dirty(); return executeRefinement(inner.value).then(() => { return { status: status.value, value: inner.value }; }); }); } } if (effect.type === "transform") { if (ctx.common.async === false) { const base = this._def.schema._parseSync({ data: ctx.data, path: ctx.path, parent: ctx }); if (!isValid(base)) return base; const result = effect.transform(base.value, checkCtx); if (result instanceof Promise) { throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`); } return { status: status.value, value: result }; } else { return this._def.schema._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }).then((base) => { if (!isValid(base)) return base; return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({ status: status.value, value: result })); }); } } util.assertNever(effect); } }; ZodEffects.create = (schema, effect, params) => { return new ZodEffects({ schema, typeName: ZodFirstPartyTypeKind.ZodEffects, effect, ...processCreateParams(params) }); }; ZodEffects.createWithPreprocess = (preprocess, schema, params) => { return new ZodEffects({ schema, effect: { type: "preprocess", transform: preprocess }, typeName: ZodFirstPartyTypeKind.ZodEffects, ...processCreateParams(params) }); }; var ZodOptional = class extends ZodType { _parse(input) { const parsedType = this._getType(input); if (parsedType === ZodParsedType.undefined) { return OK(void 0); } return this._def.innerType._parse(input); } unwrap() { return this._def.innerType; } }; ZodOptional.create = (type, params) => { return new ZodOptional({ innerType: type, typeName: ZodFirstPartyTypeKind.ZodOptional, ...processCreateParams(params) }); }; var ZodNullable = class extends ZodType { _parse(input) { const parsedType = this._getType(input); if (parsedType === ZodParsedType.null) { return OK(null); } return this._def.innerType._parse(input); } unwrap() { return this._def.innerType; } }; ZodNullable.create = (type, params) => { return new ZodNullable({ innerType: type, typeName: ZodFirstPartyTypeKind.ZodNullable, ...processCreateParams(params) }); }; var ZodDefault = class extends ZodType { _parse(input) { const { ctx } = this._processInputParams(input); let data = ctx.data; if (ctx.parsedType === ZodParsedType.undefined) { data = this._def.defaultValue(); } return this._def.innerType._parse({ data, path: ctx.path, parent: ctx }); } removeDefault() { return this._def.innerType; } }; ZodDefault.create = (type, params) => { return new ZodDefault({ innerType: type, typeName: ZodFirstPartyTypeKind.ZodDefault, defaultValue: typeof params.default === "function" ? params.default : () => params.default, ...processCreateParams(params) }); }; var ZodCatch = class extends ZodType { _parse(input) { const { ctx } = this._processInputParams(input); const newCtx = { ...ctx, common: { ...ctx.common, issues: [] } }; const result = this._def.innerType._parse({ data: newCtx.data, path: newCtx.path, parent: { ...newCtx } }); if (isAsync(result)) { return result.then((result2) => { return { status: "valid", value: result2.status === "valid" ? result2.value : this._def.catchValue({ get error() { return new ZodError(newCtx.common.issues); }, input: newCtx.data }) }; }); } else { return { status: "valid", value: result.status === "valid" ? result.value : this._def.catchValue({ get error() { return new ZodError(newCtx.common.issues); }, input: newCtx.data }) }; } } removeCatch() { return this._def.innerType; } }; ZodCatch.create = (type, params) => { return new ZodCatch({ innerType: type, typeName: ZodFirstPartyTypeKind.ZodCatch, catchValue: typeof params.catch === "function" ? params.catch : () => params.catch, ...processCreateParams(params) }); }; var ZodNaN = class extends ZodType { _parse(input) { const parsedType = this._getType(input); if (parsedType !== ZodParsedType.nan) { const ctx = this._getOrReturnCtx(input); addIssueToContext(ctx, { code: ZodIssueCode.invalid_type, expected: ZodParsedType.nan, received: ctx.parsedType }); return INVALID; } return { status: "valid", value: input.data }; } }; ZodNaN.create = (params) => { return new ZodNaN({ typeName: ZodFirstPartyTypeKind.ZodNaN, ...processCreateParams(params) }); }; var BRAND = Symbol("zod_brand"); var ZodBranded = class extends ZodType { _parse(input) { const { ctx } = this._processInputParams(input); const data = ctx.data; return this._def.type._parse({ data, path: ctx.path, parent: ctx }); } unwrap() { return this._def.type; } }; var ZodPipeline = class extends ZodType { _parse(input) { const { status, ctx } = this._processInputParams(input); if (ctx.common.async) { const handleAsync = async () => { const inResult = await this._def.in._parseAsync({ data: ctx.data, path: ctx.path, parent: ctx }); if (inResult.status === "aborted") return INVALID; if (inResult.status === "dirty") { status.dirty(); return DIRTY(inResult.value); } else { return this._def.out._parseAsync({ data: inResult.value, path: ctx.path, parent: ctx }); } }; return handleAsync(); } else { const inResult = this._def.in._parseSync({ data: ctx.data, path: ctx.path, parent: ctx }); if (inResult.status === "aborted") return INVALID; if (inResult.status === "dirty") { status.dirty(); return { status: "dirty", value: inResult.value }; } else { return this._def.out._parseSync({ data: inResult.value, path: ctx.path, parent: ctx }); } } } static create(a2, b) { return new ZodPipeline({ in: a2, out: b, typeName: ZodFirstPartyTypeKind.ZodPipeline }); } }; var ZodReadonly = class extends ZodType { _parse(input) { const result = this._def.innerType._parse(input); if (isValid(result)) { result.value = Object.freeze(result.value); } return result; } }; ZodReadonly.create = (type, params) => { return new ZodReadonly({ innerType: type, typeName: ZodFirstPartyTypeKind.ZodReadonly, ...processCreateParams(params) }); }; var custom = (check, params = {}, fatal) => { if (check) return ZodAny.create().superRefine((data, ctx) => { var _a3, _b3; if (!check(data)) { const p = typeof params === "function" ? params(data) : typeof params === "string" ? { message: params } : params; const _fatal = (_b3 = (_a3 = p.fatal) !== null && _a3 !== void 0 ? _a3 : fatal) !== null && _b3 !== void 0 ? _b3 : true; const p2 = typeof p === "string" ? { message: p } : p; ctx.addIssue({ code: "custom", ...p2, fatal: _fatal }); } }); return ZodAny.create(); }; var late = { object: ZodObject.lazycreate }; var ZodFirstPartyTypeKind; (function(ZodFirstPartyTypeKind2) { ZodFirstPartyTypeKind2["ZodString"] = "ZodString"; ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber"; ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN"; ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt"; ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean"; ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate"; ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol"; ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined"; ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull"; ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny"; ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown"; ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever"; ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid"; ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray"; ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject"; ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion"; ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion"; ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection"; ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple"; ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord"; ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap"; ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet"; ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction"; ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy"; ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral"; ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum"; ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects"; ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum"; ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional"; ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable"; ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault"; ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch"; ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise"; ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded"; ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline"; ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly"; })(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {})); var instanceOfType = (cls, params = { message: `Input not instance of ${cls.name}` }) => custom((data) => data instanceof cls, params); var stringType = ZodString.create; var numberType = ZodNumber.create; var nanType = ZodNaN.create; var bigIntType = ZodBigInt.create; var booleanType = ZodBoolean.create; var dateType = ZodDate.create; var symbolType = ZodSymbol.create; var undefinedType = ZodUndefined.create; var nullType = ZodNull.create; var anyType = ZodAny.create; var unknownType = ZodUnknown.create; var neverType = ZodNever.create; var voidType = ZodVoid.create; var arrayType = ZodArray.create; var objectType = ZodObject.create; var strictObjectType = ZodObject.strictCreate; var unionType = ZodUnion.create; var discriminatedUnionType = ZodDiscriminatedUnion.create; var intersectionType = ZodIntersection.create; var tupleType = ZodTuple.create; var recordType = ZodRecord.create; var mapType = ZodMap.create; var setType = ZodSet.create; var functionType = ZodFunction.create; var lazyType = ZodLazy.create; var literalType = ZodLiteral.create; var enumType = ZodEnum.create; var nativeEnumType = ZodNativeEnum.create; var promiseType = ZodPromise.create; var effectsType = ZodEffects.create; var optionalType = ZodOptional.create; var nullableType = ZodNullable.create; var preprocessType = ZodEffects.createWithPreprocess; var pipelineType = ZodPipeline.create; var ostring = () => stringType().optional(); var onumber = () => numberType().optional(); var oboolean = () => booleanType().optional(); var coerce = { string: (arg) => ZodString.create({ ...arg, coerce: true }), number: (arg) => ZodNumber.create({ ...arg, coerce: true }), boolean: (arg) => ZodBoolean.create({ ...arg, coerce: true }), bigint: (arg) => ZodBigInt.create({ ...arg, coerce: true }), date: (arg) => ZodDate.create({ ...arg, coerce: true }) }; var NEVER = INVALID; var z = /* @__PURE__ */ Object.freeze({ __proto__: null, defaultErrorMap: errorMap, setErrorMap, getErrorMap, makeIssue, EMPTY_PATH, addIssueToContext, ParseStatus, INVALID, DIRTY, OK, isAborted, isDirty, isValid, isAsync, get util() { return util; }, get objectUtil() { return objectUtil; }, ZodParsedType, getParsedType, ZodType, ZodString, ZodNumber, ZodBigInt, ZodBoolean, ZodDate, ZodSymbol, ZodUndefined, ZodNull, ZodAny, ZodUnknown, ZodNever, ZodVoid, ZodArray, ZodObject, ZodUnion, ZodDiscriminatedUnion, ZodIntersection, ZodTuple, ZodRecord, ZodMap, ZodSet, ZodFunction, ZodLazy, ZodLiteral, ZodEnum, ZodNativeEnum, ZodPromise, ZodEffects, ZodTransformer: ZodEffects, ZodOptional, ZodNullable, ZodDefault, ZodCatch, ZodNaN, BRAND, ZodBranded, ZodPipeline, ZodReadonly, custom, Schema: ZodType, ZodSchema: ZodType, late, get ZodFirstPartyTypeKind() { return ZodFirstPartyTypeKind; }, coerce, any: anyType, array: arrayType, bigint: bigIntType, boolean: booleanType, date: dateType, discriminatedUnion: discriminatedUnionType, effect: effectsType, "enum": enumType, "function": functionType, "instanceof": instanceOfType, intersection: intersectionType, lazy: lazyType, literal: literalType, map: mapType, nan: nanType, nativeEnum: nativeEnumType, never: neverType, "null": nullType, nullable: nullableType, number: numberType, object: objectType, oboolean, onumber, optional: optionalType, ostring, pipeline: pipelineType, preprocess: preprocessType, promise: promiseType, record: recordType, set: setType, strictObject: strictObjectType, string: stringType, symbol: symbolType, transformer: effectsType, tuple: tupleType, "undefined": undefinedType, union: unionType, unknown: unknownType, "void": voidType, NEVER, ZodIssueCode, quotelessJson, ZodError }); // src/SettingsSchemas.ts var nodeSize = { min: 1, max: 10, step: 0.1, default: 3 // 3 }; var linkThickness = { min: 1, max: 3, step: 0.1, default: 2 // 3 }; var linkDistance = { min: 10, max: 200, step: 1, default: 100 // 50 }; var nodeRepulsion = { min: 2500, max: 3e3, step: 100, default: 2800 // 28 }; var distanceFromFocal = { min: 100, max: 500, step: 10, default: 300 }; var GraphType = /* @__PURE__ */ ((GraphType2) => { GraphType2["global"] = "global"; GraphType2["local"] = "local"; GraphType2["postProcessor"] = "postProcessor"; return GraphType2; })(GraphType || {}); var SearchEngineType = /* @__PURE__ */ ((SearchEngineType2) => { SearchEngineType2["dataview"] = "dataview"; SearchEngineType2["default"] = "default"; SearchEngineType2["builtIn"] = "builtIn"; return SearchEngineType2; })(SearchEngineType || {}); var DagOrientation = /* @__PURE__ */ ((DagOrientation2) => { DagOrientation2["td"] = "td"; DagOrientation2["bu"] = "bu"; DagOrientation2["lr"] = "lr"; DagOrientation2["rl"] = "rl"; DagOrientation2["zout"] = "zout"; DagOrientation2["zin"] = "zin"; DagOrientation2["radialout"] = "radialout"; DagOrientation2["radialin"] = "radialin"; DagOrientation2["null"] = "null"; return DagOrientation2; })(DagOrientation || {}); var CommandClickNodeAction = /* @__PURE__ */ ((CommandClickNodeAction2) => { CommandClickNodeAction2["openNodeInNewTab"] = "openNodeInNewTab"; CommandClickNodeAction2["focusNode"] = "focusNode"; return CommandClickNodeAction2; })(CommandClickNodeAction || {}); var defaultGlobalGraphSetting = { filter: { searchQuery: "", showOrphans: true, showAttachments: false }, groups: [], display: { nodeSize: nodeSize.default, linkThickness: linkThickness.default, linkDistance: linkDistance.default, nodeRepulsion: nodeRepulsion.default, distanceFromFocal: 300, // node hover color is red nodeHoverColor: "#ff0000", // node hover neighbour color is green nodeHoverNeighbourColor: "#00ff00", // link hover color is blue linkHoverColor: "#0000ff", showExtension: false, showFullPath: false, showCenterCoordinates: true, showLinkArrow: true, dontMoveWhenDrag: false, dagOrientation: "null" /* null */ } }; var defaultLocalGraphSetting = { filter: { searchQuery: "", showOrphans: true, showAttachments: false, depth: 1, linkType: "both" }, groups: [], display: { nodeSize: nodeSize.default, linkThickness: linkThickness.default, linkDistance: linkDistance.default, nodeRepulsion: nodeRepulsion.default, distanceFromFocal: 300, // node hover color is red nodeHoverColor: "#ff0000", // node hover neighbour color is green nodeHoverNeighbourColor: "#00ff00", // link hover color is blue linkHoverColor: "#0000ff", showExtension: false, showFullPath: false, showCenterCoordinates: true, showLinkArrow: true, dontMoveWhenDrag: false, dagOrientation: "null" /* null */ } }; var BaseDisplaySettingsSchema = z.object({ nodeSize: z.number().default(defaultGlobalGraphSetting.display.nodeSize), linkThickness: z.number().default(defaultGlobalGraphSetting.display.linkThickness), linkDistance: z.number().default(defaultGlobalGraphSetting.display.linkDistance), nodeRepulsion: z.number().default(defaultGlobalGraphSetting.display.nodeRepulsion), distanceFromFocal: z.number().default(defaultGlobalGraphSetting.display.distanceFromFocal), nodeHoverColor: z.string().default(defaultGlobalGraphSetting.display.nodeHoverColor), nodeHoverNeighbourColor: z.string().default(defaultGlobalGraphSetting.display.nodeHoverNeighbourColor), linkHoverColor: z.string().default(defaultGlobalGraphSetting.display.linkHoverColor), showExtension: z.boolean().default(defaultGlobalGraphSetting.display.showExtension), showFullPath: z.boolean().default(defaultGlobalGraphSetting.display.showFullPath), showCenterCoordinates: z.boolean().default(defaultGlobalGraphSetting.display.showCenterCoordinates), showLinkArrow: z.boolean().default(defaultGlobalGraphSetting.display.showLinkArrow), dontMoveWhenDrag: z.boolean().default(defaultGlobalGraphSetting.display.dontMoveWhenDrag), dagOrientation: z.undefined().or(z.nativeEnum(DagOrientation)).default("null" /* null */) }); var LocalDisplaySettingsSchema = z.object({ ...BaseDisplaySettingsSchema.shape }); var LocalFilterSettingSchema = z.object({ searchQuery: z.string(), showOrphans: z.boolean(), showAttachments: z.boolean(), depth: z.number(), linkType: z.literal("inlinks").or(z.literal("outlinks")).or(z.literal("both")) }); var BaseFilterSettingsSchema = z.object({ searchQuery: z.string(), showOrphans: z.boolean(), showAttachments: z.boolean() }); var GroupSettingsSchema = z.array( z.object({ query: z.string(), color: z.string() }) ); var GlobalGraphSettingsSchema = z.object({ filter: BaseFilterSettingsSchema, groups: GroupSettingsSchema, display: BaseDisplaySettingsSchema }); var LocalGraphSettingsSchema = z.object({ filter: LocalFilterSettingSchema, groups: GroupSettingsSchema, display: LocalDisplaySettingsSchema }); var SavedSettingSchema = z.object({ title: z.string(), id: z.string(), setting: GlobalGraphSettingsSchema.or(LocalGraphSettingsSchema), type: z.nativeEnum(GraphType) }); var SettingSchema = z.object({ savedSettings: z.array(SavedSettingSchema), temporaryLocalGraphSetting: LocalGraphSettingsSchema, temporaryGlobalGraphSetting: GlobalGraphSettingsSchema, pluginSetting: z.object({ maxNodeNumber: z.number(), searchEngine: z.nativeEnum(SearchEngineType), rightClickToPan: z.boolean().default(false), commandLeftClickNode: z.nativeEnum(CommandClickNodeAction).default("openNodeInNewTab" /* openNodeInNewTab */), commandRightClickNode: z.nativeEnum(CommandClickNodeAction).default("focusNode" /* focusNode */) }) }); // src/util/createNotice.ts var import_obsidian2 = require("obsidian"); var createNotice = (message, duration) => new import_obsidian2.Notice(`3D graph: ${message}`, duration); // src/SettingManager.ts var corruptedMessage = "The setting is corrupted. You will not be able to save the setting. Please backup your data.json, remove it and reload the plugin. Then migrate your old setting back."; var MySettingManager = class { /** * @remarks don't forget to call `loadSettings` after creating this class */ constructor(plugin) { this.setting = new State(DEFAULT_SETTING); this.asyncQueue = new AsyncQueue(); /** * whether the setting is loaded successfully */ this.isLoaded = false; this.plugin = plugin; } /** * this function will update the setting and save it to the json file. But it is still a sync function. * You should always use this function to update setting */ updateSettings(updateFunc) { updateFunc(this.setting); this.asyncQueue.push(this.saveSettings.bind(this)); return this.setting.value; } getSettings() { return this.setting.value; } /** * load the settings from the json file */ async loadSettings() { const loadedData = await this.plugin.loadData(); if (!loadedData) { this.setting.value = DEFAULT_SETTING; this.isLoaded = true; await this.saveSettings(); return this.setting.value; } const result = SettingSchema.safeParse(loadedData); if (!result.success) { createNotice(corruptedMessage); console.warn("parsed loaded data failed", result.error.flatten()); this.isLoaded = false; this.setting.value = DEFAULT_SETTING; return this.setting.value; } this.setting.value = result.data; return this.setting.value; } /** * save the settings to the json file */ async saveSettings() { if (!this.isLoaded) { const result = SettingSchema.safeParse(this.setting.value); if (!result.success) { createNotice(corruptedMessage); console.warn("parsed loaded data failed", result.error.flatten()); return; } this.isLoaded = true; } await this.plugin.saveData(this.setting.value); } static getNewSetting(type) { if (type === "global" /* global */) { return defaultGlobalGraphSetting; } else { return defaultLocalGraphSetting; } } }; var DEFAULT_SETTING = { savedSettings: [], temporaryLocalGraphSetting: MySettingManager.getNewSetting("local" /* local */), temporaryGlobalGraphSetting: MySettingManager.getNewSetting( "global" /* global */ ), pluginSetting: { maxNodeNumber: 1e3, searchEngine: "default" /* default */, rightClickToPan: false, commandLeftClickNode: "openNodeInNewTab" /* openNodeInNewTab */, commandRightClickNode: "focusNode" /* focusNode */ } }; // src/views/SettingTab.ts var DEFAULT_NUMBER = DEFAULT_SETTING.pluginSetting.maxNodeNumber; var SettingTab = class extends import_obsidian3.PluginSettingTab { constructor(app2, plugin) { super(app2, plugin); this.plugin = plugin; } async display() { const pluginSetting = this.plugin.settingManager.getSettings().pluginSetting; const { containerEl } = this; containerEl.empty(); containerEl.addClasses(["graph-3d-setting-tab"]); new import_obsidian3.Setting(containerEl).setName("Maximum node number in graph").setDesc( "The maximum number of nodes in the graph. Graphs that has more than this number will not be rendered so that your computer is protected from hanging." ).addText((text) => { var _a3; text.setPlaceholder(`${DEFAULT_NUMBER}`).setValue(String((_a3 = pluginSetting.maxNodeNumber) != null ? _a3 : DEFAULT_NUMBER)).onChange(async (value) => { if (isNaN(Number(value)) || Number(value) === 0) { text.inputEl.setCustomValidity("Please enter a non-zero number"); this.plugin.settingManager.updateSettings((setting) => { setting.value.pluginSetting.maxNodeNumber = DEFAULT_NUMBER; }); } else { text.inputEl.setCustomValidity(""); this.plugin.settingManager.updateSettings((setting) => { setting.value.pluginSetting.maxNodeNumber = Number(value); }); this.plugin.activeGraphViews.forEach((view) => view.refreshGraph()); } text.inputEl.reportValidity(); }); text.inputEl.setAttribute("type", "number"); text.inputEl.setAttribute("min", "10"); return text; }); new import_obsidian3.Setting(containerEl).setName("Search Engine").setDesc("Search engine determine how to parse the query string and return results.").addDropdown((dropdown) => { dropdown.addOptions({ ["default" /* default */]: "default" /* default */ }).setValue(pluginSetting.searchEngine).onChange(async (value) => { this.plugin.settingManager.updateSettings((setting) => { setting.value.pluginSetting.searchEngine = value; }); this.plugin.fileManager.setSearchEngine(); this.plugin.activeGraphViews.forEach((view) => view.settingManager.resetSettings()); }); }); containerEl.createEl("h2", { text: "Controls" }); new import_obsidian3.Setting(containerEl).setName("Right click to pan").setDesc( "If true, right click will pan the graph. Otherwise, Cmd + left click will pan the graph." ).addToggle((toggle) => { toggle.setValue(pluginSetting.rightClickToPan).onChange(async (value) => { this.plugin.settingManager.updateSettings((setting) => { setting.value.pluginSetting.rightClickToPan = value; }); this.plugin.activeGraphViews.forEach((view) => view.refreshGraph()); }); }); new import_obsidian3.Setting(containerEl).setName("Command + left click node").setDesc("What to do when command + left click a node").addDropdown((dropdown) => { dropdown.addOptions({ ["openNodeInNewTab" /* openNodeInNewTab */]: "Open node in new tab", ["focusNode" /* focusNode */]: "Focus on node" }).setValue(pluginSetting.commandLeftClickNode).onChange(async (value) => { this.plugin.settingManager.updateSettings((setting) => { setting.value.pluginSetting.commandLeftClickNode = value; }); this.plugin.activeGraphViews.forEach((view) => view.refreshGraph()); }); }); new import_obsidian3.Setting(containerEl).setName("Command + right click node").setDesc("What to do when command + right click a node").addDropdown((dropdown) => { dropdown.addOptions({ ["openNodeInNewTab" /* openNodeInNewTab */]: "Open node in new tab", ["focusNode" /* focusNode */]: "Focus on node" }).setValue(pluginSetting.commandRightClickNode).onChange(async (value) => { this.plugin.settingManager.updateSettings((setting) => { setting.value.pluginSetting.commandRightClickNode = value; }); this.plugin.activeGraphViews.forEach((view) => view.refreshGraph()); }); }); } }; // src/config.ts var config = { icon: "orbit", viewType: { local: "3d-graph-view-local", global: "3d-graph-view-global" }, displayText: { local: "Local 3D Graph", global: "Global 3D Graph" } }; // src/BasicSearchEngine.ts var BasicSearchEngine = class { constructor(plugin) { this.useBuiltInSearchInput = true; this.plugin = plugin; } parseQueryToConfig(query) { throw new Error("Method not implemented."); } searchFiles(config2) { throw new Error("Method not implemented."); } }; // src/DvSearchEngine.ts var import_obsidian_dataview = __toESM(require_lib()); var DvSearchEngine = class { constructor(plugin) { this.useBuiltInSearchInput = false; this.plugin = plugin; } checkDvEnabled() { const dv = (0, import_obsidian_dataview.getAPI)(this.plugin.app); if (!dv) { createNotice( "Dataview is not enabled but you are using dataview search engine. Please update it in your plugin setting." ); throw new Error("Dataview is not enabled"); } } parseQueryToConfig(query) { this.checkDvEnabled(); throw new Error("Method not implemented."); } searchFiles(config2) { this.checkDvEnabled(); throw new Error("Method not implemented."); } }; // src/Interfaces.ts var ISearchEngine = class { }; var IActiveSearchEngine = class extends ISearchEngine { }; // src/util/waitFor.ts function waitFor(callback, { timeout: timeout2 = 3e4, interval: interval2 = 100 }) { const startTime = Date.now(); return new Promise((resolve) => { const intervalId = setInterval(() => { if (callback()) { clearInterval(intervalId); resolve(); } if (Date.now() - startTime >= timeout2) { clearInterval(intervalId); resolve(); } }, interval2); }); } function waitForStable(accessor, { timeout: timeout2 = 3e4, minDelay = 100, interval: interval2 = 100, rehitCount = 3 }) { let previousValue = accessor(); let hitCount = 0; const startTime = Date.now(); return new Promise((resolve) => { const intervalId = setInterval(() => { const currentValue = accessor(); if (Date.now() - startTime >= timeout2) { clearInterval(intervalId); resolve(void 0); } if (currentValue === previousValue) { hitCount += 1; } else { hitCount = 0; previousValue = currentValue; } if (hitCount >= rehitCount && currentValue === previousValue && Date.now() - startTime >= minDelay) { clearInterval(intervalId); resolve(currentValue); } }, interval2); }); } // src/PassiveSearchEngine.ts var getFilesFromSearchResult = (rawSearchResult) => { return Array.from(rawSearchResult.keys()); }; var getResultFromSearchView = async (searchView) => { await waitForStable(() => { return searchView.dom.resultDomLookup.size; }, {}); return searchView.dom.resultDomLookup; }; var DefaultSearchEngine = class { constructor(plugin) { this.useBuiltInSearchInput = true; this.plugin = plugin; } /** * given a search result container element, add a mutation observer to it */ addMutationObserver(searchResultContainerEl, view, mutationCallback, data) { let files = []; const asyncQueue = new AsyncQueue(); const observer = new MutationObserver(async (mutations) => { if (!this.plugin.cacheIsReady) return; files = getFilesFromSearchResult(await getResultFromSearchView(view)); if (asyncQueue.queue.length === 0) asyncQueue.push(async () => { await waitForStable( () => { return files.length; }, { timeout: 3e3, minDelay: 200, interval: 100 } ); mutationCallback(files); }); }); observer.observe(searchResultContainerEl, { childList: true, subtree: true }); } }; // src/FileManager.ts var MyFileManager = class { constructor(plugin) { this.plugin = plugin; this.setSearchEngine(); } /** * this will set the search engine base on the setting */ setSearchEngine() { const searchEngine = this.plugin.settingManager.getSettings().pluginSetting.searchEngine; if (searchEngine === "default" /* default */) this.searchEngine = new DefaultSearchEngine(this.plugin); else if (searchEngine === "dataview" /* dataview */) this.searchEngine = new DvSearchEngine(this.plugin); else this.searchEngine = new BasicSearchEngine(this.plugin); } getFiles() { return this.plugin.app.vault.getFiles(); } getMarkdownFiles() { return this.plugin.app.vault.getMarkdownFiles(); } getAllFilesAndFolders() { return this.plugin.app.vault.getAllLoadedFiles(); } searchFiles(query) { if (this.searchEngine instanceof IActiveSearchEngine) { return this.searchEngine.searchFiles(this.searchEngine.parseQueryToConfig(query)); } throw new Error("passive search engine cannot search files"); } }; // src/util/ObsidianTheme.ts var ObsidianTheme = class { // some others missing, but not needed currently constructor(root2) { this.backgroundPrimary = getComputedStyle(root2).getPropertyValue("--background-primary").trim(); this.backgroundPrimaryAlt = getComputedStyle(root2).getPropertyValue("--background-primary-alt").trim(); this.backgroundSecondary = getComputedStyle(root2).getPropertyValue("--background-secondary").trim(); this.backgroundSecondaryAlt = getComputedStyle(root2).getPropertyValue("--background-secondary-alt").trim(); this.backgroundModifierBorder = getComputedStyle(root2).getPropertyValue("--background-modifier-border").trim(); this.backgroundModifierSuccess = getComputedStyle(root2).getPropertyValue("--background-modifier-success").trim(); this.backgroundModifierError = getComputedStyle(root2).getPropertyValue("--background-modifier-error").trim(); this.colorAccent = getComputedStyle(root2).getPropertyValue("--color-accent").trim(); this.textNormal = getComputedStyle(root2).getPropertyValue("--text-normal").trim(); this.textMuted = getComputedStyle(root2).getPropertyValue("--text-muted").trim(); this.textFaint = getComputedStyle(root2).getPropertyValue("--text-faint").trim(); this.textAccent = getComputedStyle(root2).getPropertyValue("--text-accent").trim(); this.interactiveAccentHover = getComputedStyle(root2).getPropertyValue("--interactive-accent-hover").trim(); this.graphNode = getComputedStyle(root2).getPropertyValue("--graph-node").trim(); this.graphLine = getComputedStyle(root2).getPropertyValue("--graph-line").trim(); } }; // node_modules/3d-force-graph/node_modules/three/build/three.module.js var REVISION = "158"; var CullFaceNone = 0; var CullFaceBack = 1; var CullFaceFront = 2; var PCFShadowMap = 1; var PCFSoftShadowMap = 2; var VSMShadowMap = 3; var FrontSide = 0; var BackSide = 1; var DoubleSide = 2; var NoBlending = 0; var NormalBlending = 1; var AdditiveBlending = 2; var SubtractiveBlending = 3; var MultiplyBlending = 4; var CustomBlending = 5; var AddEquation = 100; var SubtractEquation = 101; var ReverseSubtractEquation = 102; var MinEquation = 103; var MaxEquation = 104; var ZeroFactor = 200; var OneFactor = 201; var SrcColorFactor = 202; var OneMinusSrcColorFactor = 203; var SrcAlphaFactor = 204; var OneMinusSrcAlphaFactor = 205; var DstAlphaFactor = 206; var OneMinusDstAlphaFactor = 207; var DstColorFactor = 208; var OneMinusDstColorFactor = 209; var SrcAlphaSaturateFactor = 210; var ConstantColorFactor = 211; var OneMinusConstantColorFactor = 212; var ConstantAlphaFactor = 213; var OneMinusConstantAlphaFactor = 214; var NeverDepth = 0; var AlwaysDepth = 1; var LessDepth = 2; var LessEqualDepth = 3; var EqualDepth = 4; var GreaterEqualDepth = 5; var GreaterDepth = 6; var NotEqualDepth = 7; var MultiplyOperation = 0; var MixOperation = 1; var AddOperation = 2; var NoToneMapping = 0; var LinearToneMapping = 1; var ReinhardToneMapping = 2; var CineonToneMapping = 3; var ACESFilmicToneMapping = 4; var CustomToneMapping = 5; var UVMapping = 300; var CubeReflectionMapping = 301; var CubeRefractionMapping = 302; var EquirectangularReflectionMapping = 303; var EquirectangularRefractionMapping = 304; var CubeUVReflectionMapping = 306; var RepeatWrapping = 1e3; var ClampToEdgeWrapping = 1001; var MirroredRepeatWrapping = 1002; var NearestFilter = 1003; var NearestMipmapNearestFilter = 1004; var NearestMipmapLinearFilter = 1005; var LinearFilter = 1006; var LinearMipmapNearestFilter = 1007; var LinearMipmapLinearFilter = 1008; var UnsignedByteType = 1009; var ByteType = 1010; var ShortType = 1011; var UnsignedShortType = 1012; var IntType = 1013; var UnsignedIntType = 1014; var FloatType = 1015; var HalfFloatType = 1016; var UnsignedShort4444Type = 1017; var UnsignedShort5551Type = 1018; var UnsignedInt248Type = 1020; var AlphaFormat = 1021; var RGBAFormat = 1023; var LuminanceFormat = 1024; var LuminanceAlphaFormat = 1025; var DepthFormat = 1026; var DepthStencilFormat = 1027; var RedFormat = 1028; var RedIntegerFormat = 1029; var RGFormat = 1030; var RGIntegerFormat = 1031; var RGBAIntegerFormat = 1033; var RGB_S3TC_DXT1_Format = 33776; var RGBA_S3TC_DXT1_Format = 33777; var RGBA_S3TC_DXT3_Format = 33778; var RGBA_S3TC_DXT5_Format = 33779; var RGB_PVRTC_4BPPV1_Format = 35840; var RGB_PVRTC_2BPPV1_Format = 35841; var RGBA_PVRTC_4BPPV1_Format = 35842; var RGBA_PVRTC_2BPPV1_Format = 35843; var RGB_ETC1_Format = 36196; var RGB_ETC2_Format = 37492; var RGBA_ETC2_EAC_Format = 37496; var RGBA_ASTC_4x4_Format = 37808; var RGBA_ASTC_5x4_Format = 37809; var RGBA_ASTC_5x5_Format = 37810; var RGBA_ASTC_6x5_Format = 37811; var RGBA_ASTC_6x6_Format = 37812; var RGBA_ASTC_8x5_Format = 37813; var RGBA_ASTC_8x6_Format = 37814; var RGBA_ASTC_8x8_Format = 37815; var RGBA_ASTC_10x5_Format = 37816; var RGBA_ASTC_10x6_Format = 37817; var RGBA_ASTC_10x8_Format = 37818; var RGBA_ASTC_10x10_Format = 37819; var RGBA_ASTC_12x10_Format = 37820; var RGBA_ASTC_12x12_Format = 37821; var RGBA_BPTC_Format = 36492; var RGB_BPTC_SIGNED_Format = 36494; var RGB_BPTC_UNSIGNED_Format = 36495; var RED_RGTC1_Format = 36283; var SIGNED_RED_RGTC1_Format = 36284; var RED_GREEN_RGTC2_Format = 36285; var SIGNED_RED_GREEN_RGTC2_Format = 36286; var InterpolateDiscrete = 2300; var InterpolateLinear = 2301; var InterpolateSmooth = 2302; var ZeroCurvatureEnding = 2400; var ZeroSlopeEnding = 2401; var WrapAroundEnding = 2402; var LinearEncoding = 3e3; var sRGBEncoding = 3001; var BasicDepthPacking = 3200; var RGBADepthPacking = 3201; var TangentSpaceNormalMap = 0; var ObjectSpaceNormalMap = 1; var NoColorSpace = ""; var SRGBColorSpace = "srgb"; var LinearSRGBColorSpace = "srgb-linear"; var DisplayP3ColorSpace = "display-p3"; var LinearDisplayP3ColorSpace = "display-p3-linear"; var LinearTransfer = "linear"; var SRGBTransfer = "srgb"; var Rec709Primaries = "rec709"; var P3Primaries = "p3"; var KeepStencilOp = 7680; var AlwaysStencilFunc = 519; var NeverCompare = 512; var LessCompare = 513; var EqualCompare = 514; var LessEqualCompare = 515; var GreaterCompare = 516; var NotEqualCompare = 517; var GreaterEqualCompare = 518; var AlwaysCompare = 519; var StaticDrawUsage = 35044; var GLSL3 = "300 es"; var _SRGBAFormat = 1035; var WebGLCoordinateSystem = 2e3; var WebGPUCoordinateSystem = 2001; var EventDispatcher = class { addEventListener(type, listener) { if (this._listeners === void 0) this._listeners = {}; const listeners = this._listeners; if (listeners[type] === void 0) { listeners[type] = []; } if (listeners[type].indexOf(listener) === -1) { listeners[type].push(listener); } } hasEventListener(type, listener) { if (this._listeners === void 0) return false; const listeners = this._listeners; return listeners[type] !== void 0 && listeners[type].indexOf(listener) !== -1; } removeEventListener(type, listener) { if (this._listeners === void 0) return; const listeners = this._listeners; const listenerArray = listeners[type]; if (listenerArray !== void 0) { const index6 = listenerArray.indexOf(listener); if (index6 !== -1) { listenerArray.splice(index6, 1); } } } dispatchEvent(event) { if (this._listeners === void 0) return; const listeners = this._listeners; const listenerArray = listeners[event.type]; if (listenerArray !== void 0) { event.target = this; const array = listenerArray.slice(0); for (let i = 0, l = array.length; i < l; i++) { array[i].call(this, event); } event.target = null; } } }; var _lut = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a", "0b", "0c", "0d", "0e", "0f", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1a", "1b", "1c", "1d", "1e", "1f", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2a", "2b", "2c", "2d", "2e", "2f", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3a", "3b", "3c", "3d", "3e", "3f", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", "4f", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5a", "5b", "5c", "5d", "5e", "5f", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6a", "6b", "6c", "6d", "6e", "6f", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7a", "7b", "7c", "7d", "7e", "7f", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8a", "8b", "8c", "8d", "8e", "8f", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9a", "9b", "9c", "9d", "9e", "9f", "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "aa", "ab", "ac", "ad", "ae", "af", "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "ba", "bb", "bc", "bd", "be", "bf", "c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "ca", "cb", "cc", "cd", "ce", "cf", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "da", "db", "dc", "dd", "de", "df", "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "ea", "eb", "ec", "ed", "ee", "ef", "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe", "ff"]; var DEG2RAD = Math.PI / 180; var RAD2DEG = 180 / Math.PI; function generateUUID() { const d0 = Math.random() * 4294967295 | 0; const d1 = Math.random() * 4294967295 | 0; const d2 = Math.random() * 4294967295 | 0; const d3 = Math.random() * 4294967295 | 0; const uuid = _lut[d0 & 255] + _lut[d0 >> 8 & 255] + _lut[d0 >> 16 & 255] + _lut[d0 >> 24 & 255] + "-" + _lut[d1 & 255] + _lut[d1 >> 8 & 255] + "-" + _lut[d1 >> 16 & 15 | 64] + _lut[d1 >> 24 & 255] + "-" + _lut[d2 & 63 | 128] + _lut[d2 >> 8 & 255] + "-" + _lut[d2 >> 16 & 255] + _lut[d2 >> 24 & 255] + _lut[d3 & 255] + _lut[d3 >> 8 & 255] + _lut[d3 >> 16 & 255] + _lut[d3 >> 24 & 255]; return uuid.toLowerCase(); } function clamp(value, min2, max2) { return Math.max(min2, Math.min(max2, value)); } function euclideanModulo(n, m2) { return (n % m2 + m2) % m2; } function lerp(x3, y3, t) { return (1 - t) * x3 + t * y3; } function isPowerOfTwo(value) { return (value & value - 1) === 0 && value !== 0; } function floorPowerOfTwo(value) { return Math.pow(2, Math.floor(Math.log(value) / Math.LN2)); } function denormalize(value, array) { switch (array.constructor) { case Float32Array: return value; case Uint32Array: return value / 4294967295; case Uint16Array: return value / 65535; case Uint8Array: return value / 255; case Int32Array: return Math.max(value / 2147483647, -1); case Int16Array: return Math.max(value / 32767, -1); case Int8Array: return Math.max(value / 127, -1); default: throw new Error("Invalid component type."); } } function normalize(value, array) { switch (array.constructor) { case Float32Array: return value; case Uint32Array: return Math.round(value * 4294967295); case Uint16Array: return Math.round(value * 65535); case Uint8Array: return Math.round(value * 255); case Int32Array: return Math.round(value * 2147483647); case Int16Array: return Math.round(value * 32767); case Int8Array: return Math.round(value * 127); default: throw new Error("Invalid component type."); } } var Vector2 = class { constructor(x3 = 0, y3 = 0) { Vector2.prototype.isVector2 = true; this.x = x3; this.y = y3; } get width() { return this.x; } set width(value) { this.x = value; } get height() { return this.y; } set height(value) { this.y = value; } set(x3, y3) { this.x = x3; this.y = y3; return this; } setScalar(scalar) { this.x = scalar; this.y = scalar; return this; } setX(x3) { this.x = x3; return this; } setY(y3) { this.y = y3; return this; } setComponent(index6, value) { switch (index6) { case 0: this.x = value; break; case 1: this.y = value; break; default: throw new Error("index is out of range: " + index6); } return this; } getComponent(index6) { switch (index6) { case 0: return this.x; case 1: return this.y; default: throw new Error("index is out of range: " + index6); } } clone() { return new this.constructor(this.x, this.y); } copy(v) { this.x = v.x; this.y = v.y; return this; } add(v) { this.x += v.x; this.y += v.y; return this; } addScalar(s) { this.x += s; this.y += s; return this; } addVectors(a2, b) { this.x = a2.x + b.x; this.y = a2.y + b.y; return this; } addScaledVector(v, s) { this.x += v.x * s; this.y += v.y * s; return this; } sub(v) { this.x -= v.x; this.y -= v.y; return this; } subScalar(s) { this.x -= s; this.y -= s; return this; } subVectors(a2, b) { this.x = a2.x - b.x; this.y = a2.y - b.y; return this; } multiply(v) { this.x *= v.x; this.y *= v.y; return this; } multiplyScalar(scalar) { this.x *= scalar; this.y *= scalar; return this; } divide(v) { this.x /= v.x; this.y /= v.y; return this; } divideScalar(scalar) { return this.multiplyScalar(1 / scalar); } applyMatrix3(m2) { const x3 = this.x, y3 = this.y; const e = m2.elements; this.x = e[0] * x3 + e[3] * y3 + e[6]; this.y = e[1] * x3 + e[4] * y3 + e[7]; return this; } min(v) { this.x = Math.min(this.x, v.x); this.y = Math.min(this.y, v.y); return this; } max(v) { this.x = Math.max(this.x, v.x); this.y = Math.max(this.y, v.y); return this; } clamp(min2, max2) { this.x = Math.max(min2.x, Math.min(max2.x, this.x)); this.y = Math.max(min2.y, Math.min(max2.y, this.y)); return this; } clampScalar(minVal, maxVal) { this.x = Math.max(minVal, Math.min(maxVal, this.x)); this.y = Math.max(minVal, Math.min(maxVal, this.y)); return this; } clampLength(min2, max2) { const length = this.length(); return this.divideScalar(length || 1).multiplyScalar(Math.max(min2, Math.min(max2, length))); } floor() { this.x = Math.floor(this.x); this.y = Math.floor(this.y); return this; } ceil() { this.x = Math.ceil(this.x); this.y = Math.ceil(this.y); return this; } round() { this.x = Math.round(this.x); this.y = Math.round(this.y); return this; } roundToZero() { this.x = Math.trunc(this.x); this.y = Math.trunc(this.y); return this; } negate() { this.x = -this.x; this.y = -this.y; return this; } dot(v) { return this.x * v.x + this.y * v.y; } cross(v) { return this.x * v.y - this.y * v.x; } lengthSq() { return this.x * this.x + this.y * this.y; } length() { return Math.sqrt(this.x * this.x + this.y * this.y); } manhattanLength() { return Math.abs(this.x) + Math.abs(this.y); } normalize() { return this.divideScalar(this.length() || 1); } angle() { const angle = Math.atan2(-this.y, -this.x) + Math.PI; return angle; } angleTo(v) { const denominator = Math.sqrt(this.lengthSq() * v.lengthSq()); if (denominator === 0) return Math.PI / 2; const theta = this.dot(v) / denominator; return Math.acos(clamp(theta, -1, 1)); } distanceTo(v) { return Math.sqrt(this.distanceToSquared(v)); } distanceToSquared(v) { const dx = this.x - v.x, dy = this.y - v.y; return dx * dx + dy * dy; } manhattanDistanceTo(v) { return Math.abs(this.x - v.x) + Math.abs(this.y - v.y); } setLength(length) { return this.normalize().multiplyScalar(length); } lerp(v, alpha) { this.x += (v.x - this.x) * alpha; this.y += (v.y - this.y) * alpha; return this; } lerpVectors(v1, v2, alpha) { this.x = v1.x + (v2.x - v1.x) * alpha; this.y = v1.y + (v2.y - v1.y) * alpha; return this; } equals(v) { return v.x === this.x && v.y === this.y; } fromArray(array, offset = 0) { this.x = array[offset]; this.y = array[offset + 1]; return this; } toArray(array = [], offset = 0) { array[offset] = this.x; array[offset + 1] = this.y; return array; } fromBufferAttribute(attribute, index6) { this.x = attribute.getX(index6); this.y = attribute.getY(index6); return this; } rotateAround(center, angle) { const c2 = Math.cos(angle), s = Math.sin(angle); const x3 = this.x - center.x; const y3 = this.y - center.y; this.x = x3 * c2 - y3 * s + center.x; this.y = x3 * s + y3 * c2 + center.y; return this; } random() { this.x = Math.random(); this.y = Math.random(); return this; } *[Symbol.iterator]() { yield this.x; yield this.y; } }; var Matrix3 = class { constructor(n11, n12, n13, n21, n22, n23, n31, n32, n33) { Matrix3.prototype.isMatrix3 = true; this.elements = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ]; if (n11 !== void 0) { this.set(n11, n12, n13, n21, n22, n23, n31, n32, n33); } } set(n11, n12, n13, n21, n22, n23, n31, n32, n33) { const te = this.elements; te[0] = n11; te[1] = n21; te[2] = n31; te[3] = n12; te[4] = n22; te[5] = n32; te[6] = n13; te[7] = n23; te[8] = n33; return this; } identity() { this.set( 1, 0, 0, 0, 1, 0, 0, 0, 1 ); return this; } copy(m2) { const te = this.elements; const me = m2.elements; te[0] = me[0]; te[1] = me[1]; te[2] = me[2]; te[3] = me[3]; te[4] = me[4]; te[5] = me[5]; te[6] = me[6]; te[7] = me[7]; te[8] = me[8]; return this; } extractBasis(xAxis, yAxis, zAxis) { xAxis.setFromMatrix3Column(this, 0); yAxis.setFromMatrix3Column(this, 1); zAxis.setFromMatrix3Column(this, 2); return this; } setFromMatrix4(m2) { const me = m2.elements; this.set( me[0], me[4], me[8], me[1], me[5], me[9], me[2], me[6], me[10] ); return this; } multiply(m2) { return this.multiplyMatrices(this, m2); } premultiply(m2) { return this.multiplyMatrices(m2, this); } multiplyMatrices(a2, b) { const ae = a2.elements; const be = b.elements; const te = this.elements; const a11 = ae[0], a12 = ae[3], a13 = ae[6]; const a21 = ae[1], a22 = ae[4], a23 = ae[7]; const a31 = ae[2], a32 = ae[5], a33 = ae[8]; const b11 = be[0], b12 = be[3], b13 = be[6]; const b21 = be[1], b22 = be[4], b23 = be[7]; const b31 = be[2], b32 = be[5], b33 = be[8]; te[0] = a11 * b11 + a12 * b21 + a13 * b31; te[3] = a11 * b12 + a12 * b22 + a13 * b32; te[6] = a11 * b13 + a12 * b23 + a13 * b33; te[1] = a21 * b11 + a22 * b21 + a23 * b31; te[4] = a21 * b12 + a22 * b22 + a23 * b32; te[7] = a21 * b13 + a22 * b23 + a23 * b33; te[2] = a31 * b11 + a32 * b21 + a33 * b31; te[5] = a31 * b12 + a32 * b22 + a33 * b32; te[8] = a31 * b13 + a32 * b23 + a33 * b33; return this; } multiplyScalar(s) { const te = this.elements; te[0] *= s; te[3] *= s; te[6] *= s; te[1] *= s; te[4] *= s; te[7] *= s; te[2] *= s; te[5] *= s; te[8] *= s; return this; } determinant() { const te = this.elements; const a2 = te[0], b = te[1], c2 = te[2], d = te[3], e = te[4], f = te[5], g = te[6], h = te[7], i = te[8]; return a2 * e * i - a2 * f * h - b * d * i + b * f * g + c2 * d * h - c2 * e * g; } invert() { const te = this.elements, n11 = te[0], n21 = te[1], n31 = te[2], n12 = te[3], n22 = te[4], n32 = te[5], n13 = te[6], n23 = te[7], n33 = te[8], t11 = n33 * n22 - n32 * n23, t12 = n32 * n13 - n33 * n12, t13 = n23 * n12 - n22 * n13, det = n11 * t11 + n21 * t12 + n31 * t13; if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0); const detInv = 1 / det; te[0] = t11 * detInv; te[1] = (n31 * n23 - n33 * n21) * detInv; te[2] = (n32 * n21 - n31 * n22) * detInv; te[3] = t12 * detInv; te[4] = (n33 * n11 - n31 * n13) * detInv; te[5] = (n31 * n12 - n32 * n11) * detInv; te[6] = t13 * detInv; te[7] = (n21 * n13 - n23 * n11) * detInv; te[8] = (n22 * n11 - n21 * n12) * detInv; return this; } transpose() { let tmp2; const m2 = this.elements; tmp2 = m2[1]; m2[1] = m2[3]; m2[3] = tmp2; tmp2 = m2[2]; m2[2] = m2[6]; m2[6] = tmp2; tmp2 = m2[5]; m2[5] = m2[7]; m2[7] = tmp2; return this; } getNormalMatrix(matrix4) { return this.setFromMatrix4(matrix4).invert().transpose(); } transposeIntoArray(r) { const m2 = this.elements; r[0] = m2[0]; r[1] = m2[3]; r[2] = m2[6]; r[3] = m2[1]; r[4] = m2[4]; r[5] = m2[7]; r[6] = m2[2]; r[7] = m2[5]; r[8] = m2[8]; return this; } setUvTransform(tx, ty, sx, sy, rotation, cx, cy) { const c2 = Math.cos(rotation); const s = Math.sin(rotation); this.set( sx * c2, sx * s, -sx * (c2 * cx + s * cy) + cx + tx, -sy * s, sy * c2, -sy * (-s * cx + c2 * cy) + cy + ty, 0, 0, 1 ); return this; } // scale(sx, sy) { this.premultiply(_m3.makeScale(sx, sy)); return this; } rotate(theta) { this.premultiply(_m3.makeRotation(-theta)); return this; } translate(tx, ty) { this.premultiply(_m3.makeTranslation(tx, ty)); return this; } // for 2D Transforms makeTranslation(x3, y3) { if (x3.isVector2) { this.set( 1, 0, x3.x, 0, 1, x3.y, 0, 0, 1 ); } else { this.set( 1, 0, x3, 0, 1, y3, 0, 0, 1 ); } return this; } makeRotation(theta) { const c2 = Math.cos(theta); const s = Math.sin(theta); this.set( c2, -s, 0, s, c2, 0, 0, 0, 1 ); return this; } makeScale(x3, y3) { this.set( x3, 0, 0, 0, y3, 0, 0, 0, 1 ); return this; } // equals(matrix) { const te = this.elements; const me = matrix.elements; for (let i = 0; i < 9; i++) { if (te[i] !== me[i]) return false; } return true; } fromArray(array, offset = 0) { for (let i = 0; i < 9; i++) { this.elements[i] = array[i + offset]; } return this; } toArray(array = [], offset = 0) { const te = this.elements; array[offset] = te[0]; array[offset + 1] = te[1]; array[offset + 2] = te[2]; array[offset + 3] = te[3]; array[offset + 4] = te[4]; array[offset + 5] = te[5]; array[offset + 6] = te[6]; array[offset + 7] = te[7]; array[offset + 8] = te[8]; return array; } clone() { return new this.constructor().fromArray(this.elements); } }; var _m3 = /* @__PURE__ */ new Matrix3(); function arrayNeedsUint32(array) { for (let i = array.length - 1; i >= 0; --i) { if (array[i] >= 65535) return true; } return false; } function createElementNS(name) { return document.createElementNS("http://www.w3.org/1999/xhtml", name); } function createCanvasElement() { const canvas = createElementNS("canvas"); canvas.style.display = "block"; return canvas; } var _cache = {}; function warnOnce(message) { if (message in _cache) return; _cache[message] = true; console.warn(message); } var LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 = /* @__PURE__ */ new Matrix3().set( 0.8224621, 0.177538, 0, 0.0331941, 0.9668058, 0, 0.0170827, 0.0723974, 0.9105199 ); var LINEAR_DISPLAY_P3_TO_LINEAR_SRGB = /* @__PURE__ */ new Matrix3().set( 1.2249401, -0.2249404, 0, -0.0420569, 1.0420571, 0, -0.0196376, -0.0786361, 1.0982735 ); var COLOR_SPACES = { [LinearSRGBColorSpace]: { transfer: LinearTransfer, primaries: Rec709Primaries, toReference: (color) => color, fromReference: (color) => color }, [SRGBColorSpace]: { transfer: SRGBTransfer, primaries: Rec709Primaries, toReference: (color) => color.convertSRGBToLinear(), fromReference: (color) => color.convertLinearToSRGB() }, [LinearDisplayP3ColorSpace]: { transfer: LinearTransfer, primaries: P3Primaries, toReference: (color) => color.applyMatrix3(LINEAR_DISPLAY_P3_TO_LINEAR_SRGB), fromReference: (color) => color.applyMatrix3(LINEAR_SRGB_TO_LINEAR_DISPLAY_P3) }, [DisplayP3ColorSpace]: { transfer: SRGBTransfer, primaries: P3Primaries, toReference: (color) => color.convertSRGBToLinear().applyMatrix3(LINEAR_DISPLAY_P3_TO_LINEAR_SRGB), fromReference: (color) => color.applyMatrix3(LINEAR_SRGB_TO_LINEAR_DISPLAY_P3).convertLinearToSRGB() } }; var SUPPORTED_WORKING_COLOR_SPACES = /* @__PURE__ */ new Set([LinearSRGBColorSpace, LinearDisplayP3ColorSpace]); var ColorManagement = { enabled: true, _workingColorSpace: LinearSRGBColorSpace, get legacyMode() { console.warn("THREE.ColorManagement: .legacyMode=false renamed to .enabled=true in r150."); return !this.enabled; }, set legacyMode(legacyMode) { console.warn("THREE.ColorManagement: .legacyMode=false renamed to .enabled=true in r150."); this.enabled = !legacyMode; }, get workingColorSpace() { return this._workingColorSpace; }, set workingColorSpace(colorSpace) { if (!SUPPORTED_WORKING_COLOR_SPACES.has(colorSpace)) { throw new Error(`Unsupported working color space, "${colorSpace}".`); } this._workingColorSpace = colorSpace; }, convert: function(color, sourceColorSpace, targetColorSpace) { if (this.enabled === false || sourceColorSpace === targetColorSpace || !sourceColorSpace || !targetColorSpace) { return color; } const sourceToReference = COLOR_SPACES[sourceColorSpace].toReference; const targetFromReference = COLOR_SPACES[targetColorSpace].fromReference; return targetFromReference(sourceToReference(color)); }, fromWorkingColorSpace: function(color, targetColorSpace) { return this.convert(color, this._workingColorSpace, targetColorSpace); }, toWorkingColorSpace: function(color, sourceColorSpace) { return this.convert(color, sourceColorSpace, this._workingColorSpace); }, getPrimaries: function(colorSpace) { return COLOR_SPACES[colorSpace].primaries; }, getTransfer: function(colorSpace) { if (colorSpace === NoColorSpace) return LinearTransfer; return COLOR_SPACES[colorSpace].transfer; } }; function SRGBToLinear(c2) { return c2 < 0.04045 ? c2 * 0.0773993808 : Math.pow(c2 * 0.9478672986 + 0.0521327014, 2.4); } function LinearToSRGB(c2) { return c2 < 31308e-7 ? c2 * 12.92 : 1.055 * Math.pow(c2, 0.41666) - 0.055; } var _canvas; var ImageUtils = class { static getDataURL(image) { if (/^data:/i.test(image.src)) { return image.src; } if (typeof HTMLCanvasElement === "undefined") { return image.src; } let canvas; if (image instanceof HTMLCanvasElement) { canvas = image; } else { if (_canvas === void 0) _canvas = createElementNS("canvas"); _canvas.width = image.width; _canvas.height = image.height; const context = _canvas.getContext("2d"); if (image instanceof ImageData) { context.putImageData(image, 0, 0); } else { context.drawImage(image, 0, 0, image.width, image.height); } canvas = _canvas; } if (canvas.width > 2048 || canvas.height > 2048) { console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons", image); return canvas.toDataURL("image/jpeg", 0.6); } else { return canvas.toDataURL("image/png"); } } static sRGBToLinear(image) { if (typeof HTMLImageElement !== "undefined" && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== "undefined" && image instanceof HTMLCanvasElement || typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap) { const canvas = createElementNS("canvas"); canvas.width = image.width; canvas.height = image.height; const context = canvas.getContext("2d"); context.drawImage(image, 0, 0, image.width, image.height); const imageData = context.getImageData(0, 0, image.width, image.height); const data = imageData.data; for (let i = 0; i < data.length; i++) { data[i] = SRGBToLinear(data[i] / 255) * 255; } context.putImageData(imageData, 0, 0); return canvas; } else if (image.data) { const data = image.data.slice(0); for (let i = 0; i < data.length; i++) { if (data instanceof Uint8Array || data instanceof Uint8ClampedArray) { data[i] = Math.floor(SRGBToLinear(data[i] / 255) * 255); } else { data[i] = SRGBToLinear(data[i]); } } return { data, width: image.width, height: image.height }; } else { console.warn("THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."); return image; } } }; var _sourceId = 0; var Source = class { constructor(data = null) { this.isSource = true; Object.defineProperty(this, "id", { value: _sourceId++ }); this.uuid = generateUUID(); this.data = data; this.version = 0; } set needsUpdate(value) { if (value === true) this.version++; } toJSON(meta) { const isRootObject = meta === void 0 || typeof meta === "string"; if (!isRootObject && meta.images[this.uuid] !== void 0) { return meta.images[this.uuid]; } const output = { uuid: this.uuid, url: "" }; const data = this.data; if (data !== null) { let url; if (Array.isArray(data)) { url = []; for (let i = 0, l = data.length; i < l; i++) { if (data[i].isDataTexture) { url.push(serializeImage(data[i].image)); } else { url.push(serializeImage(data[i])); } } } else { url = serializeImage(data); } output.url = url; } if (!isRootObject) { meta.images[this.uuid] = output; } return output; } }; function serializeImage(image) { if (typeof HTMLImageElement !== "undefined" && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== "undefined" && image instanceof HTMLCanvasElement || typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap) { return ImageUtils.getDataURL(image); } else { if (image.data) { return { data: Array.from(image.data), width: image.width, height: image.height, type: image.data.constructor.name }; } else { console.warn("THREE.Texture: Unable to serialize Texture."); return {}; } } } var _textureId = 0; var Texture = class extends EventDispatcher { constructor(image = Texture.DEFAULT_IMAGE, mapping = Texture.DEFAULT_MAPPING, wrapS = ClampToEdgeWrapping, wrapT = ClampToEdgeWrapping, magFilter = LinearFilter, minFilter = LinearMipmapLinearFilter, format2 = RGBAFormat, type = UnsignedByteType, anisotropy = Texture.DEFAULT_ANISOTROPY, colorSpace = NoColorSpace) { super(); this.isTexture = true; Object.defineProperty(this, "id", { value: _textureId++ }); this.uuid = generateUUID(); this.name = ""; this.source = new Source(image); this.mipmaps = []; this.mapping = mapping; this.channel = 0; this.wrapS = wrapS; this.wrapT = wrapT; this.magFilter = magFilter; this.minFilter = minFilter; this.anisotropy = anisotropy; this.format = format2; this.internalFormat = null; this.type = type; this.offset = new Vector2(0, 0); this.repeat = new Vector2(1, 1); this.center = new Vector2(0, 0); this.rotation = 0; this.matrixAutoUpdate = true; this.matrix = new Matrix3(); this.generateMipmaps = true; this.premultiplyAlpha = false; this.flipY = true; this.unpackAlignment = 4; if (typeof colorSpace === "string") { this.colorSpace = colorSpace; } else { warnOnce("THREE.Texture: Property .encoding has been replaced by .colorSpace."); this.colorSpace = colorSpace === sRGBEncoding ? SRGBColorSpace : NoColorSpace; } this.userData = {}; this.version = 0; this.onUpdate = null; this.isRenderTargetTexture = false; this.needsPMREMUpdate = false; } get image() { return this.source.data; } set image(value = null) { this.source.data = value; } updateMatrix() { this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y); } clone() { return new this.constructor().copy(this); } copy(source) { this.name = source.name; this.source = source.source; this.mipmaps = source.mipmaps.slice(0); this.mapping = source.mapping; this.channel = source.channel; this.wrapS = source.wrapS; this.wrapT = source.wrapT; this.magFilter = source.magFilter; this.minFilter = source.minFilter; this.anisotropy = source.anisotropy; this.format = source.format; this.internalFormat = source.internalFormat; this.type = source.type; this.offset.copy(source.offset); this.repeat.copy(source.repeat); this.center.copy(source.center); this.rotation = source.rotation; this.matrixAutoUpdate = source.matrixAutoUpdate; this.matrix.copy(source.matrix); this.generateMipmaps = source.generateMipmaps; this.premultiplyAlpha = source.premultiplyAlpha; this.flipY = source.flipY; this.unpackAlignment = source.unpackAlignment; this.colorSpace = source.colorSpace; this.userData = JSON.parse(JSON.stringify(source.userData)); this.needsUpdate = true; return this; } toJSON(meta) { const isRootObject = meta === void 0 || typeof meta === "string"; if (!isRootObject && meta.textures[this.uuid] !== void 0) { return meta.textures[this.uuid]; } const output = { metadata: { version: 4.6, type: "Texture", generator: "Texture.toJSON" }, uuid: this.uuid, name: this.name, image: this.source.toJSON(meta).uuid, mapping: this.mapping, channel: this.channel, repeat: [this.repeat.x, this.repeat.y], offset: [this.offset.x, this.offset.y], center: [this.center.x, this.center.y], rotation: this.rotation, wrap: [this.wrapS, this.wrapT], format: this.format, internalFormat: this.internalFormat, type: this.type, colorSpace: this.colorSpace, minFilter: this.minFilter, magFilter: this.magFilter, anisotropy: this.anisotropy, flipY: this.flipY, generateMipmaps: this.generateMipmaps, premultiplyAlpha: this.premultiplyAlpha, unpackAlignment: this.unpackAlignment }; if (Object.keys(this.userData).length > 0) output.userData = this.userData; if (!isRootObject) { meta.textures[this.uuid] = output; } return output; } dispose() { this.dispatchEvent({ type: "dispose" }); } transformUv(uv) { if (this.mapping !== UVMapping) return uv; uv.applyMatrix3(this.matrix); if (uv.x < 0 || uv.x > 1) { switch (this.wrapS) { case RepeatWrapping: uv.x = uv.x - Math.floor(uv.x); break; case ClampToEdgeWrapping: uv.x = uv.x < 0 ? 0 : 1; break; case MirroredRepeatWrapping: if (Math.abs(Math.floor(uv.x) % 2) === 1) { uv.x = Math.ceil(uv.x) - uv.x; } else { uv.x = uv.x - Math.floor(uv.x); } break; } } if (uv.y < 0 || uv.y > 1) { switch (this.wrapT) { case RepeatWrapping: uv.y = uv.y - Math.floor(uv.y); break; case ClampToEdgeWrapping: uv.y = uv.y < 0 ? 0 : 1; break; case MirroredRepeatWrapping: if (Math.abs(Math.floor(uv.y) % 2) === 1) { uv.y = Math.ceil(uv.y) - uv.y; } else { uv.y = uv.y - Math.floor(uv.y); } break; } } if (this.flipY) { uv.y = 1 - uv.y; } return uv; } set needsUpdate(value) { if (value === true) { this.version++; this.source.needsUpdate = true; } } get encoding() { warnOnce("THREE.Texture: Property .encoding has been replaced by .colorSpace."); return this.colorSpace === SRGBColorSpace ? sRGBEncoding : LinearEncoding; } set encoding(encoding) { warnOnce("THREE.Texture: Property .encoding has been replaced by .colorSpace."); this.colorSpace = encoding === sRGBEncoding ? SRGBColorSpace : NoColorSpace; } }; Texture.DEFAULT_IMAGE = null; Texture.DEFAULT_MAPPING = UVMapping; Texture.DEFAULT_ANISOTROPY = 1; var Vector4 = class { constructor(x3 = 0, y3 = 0, z4 = 0, w = 1) { Vector4.prototype.isVector4 = true; this.x = x3; this.y = y3; this.z = z4; this.w = w; } get width() { return this.z; } set width(value) { this.z = value; } get height() { return this.w; } set height(value) { this.w = value; } set(x3, y3, z4, w) { this.x = x3; this.y = y3; this.z = z4; this.w = w; return this; } setScalar(scalar) { this.x = scalar; this.y = scalar; this.z = scalar; this.w = scalar; return this; } setX(x3) { this.x = x3; return this; } setY(y3) { this.y = y3; return this; } setZ(z4) { this.z = z4; return this; } setW(w) { this.w = w; return this; } setComponent(index6, value) { switch (index6) { case 0: this.x = value; break; case 1: this.y = value; break; case 2: this.z = value; break; case 3: this.w = value; break; default: throw new Error("index is out of range: " + index6); } return this; } getComponent(index6) { switch (index6) { case 0: return this.x; case 1: return this.y; case 2: return this.z; case 3: return this.w; default: throw new Error("index is out of range: " + index6); } } clone() { return new this.constructor(this.x, this.y, this.z, this.w); } copy(v) { this.x = v.x; this.y = v.y; this.z = v.z; this.w = v.w !== void 0 ? v.w : 1; return this; } add(v) { this.x += v.x; this.y += v.y; this.z += v.z; this.w += v.w; return this; } addScalar(s) { this.x += s; this.y += s; this.z += s; this.w += s; return this; } addVectors(a2, b) { this.x = a2.x + b.x; this.y = a2.y + b.y; this.z = a2.z + b.z; this.w = a2.w + b.w; return this; } addScaledVector(v, s) { this.x += v.x * s; this.y += v.y * s; this.z += v.z * s; this.w += v.w * s; return this; } sub(v) { this.x -= v.x; this.y -= v.y; this.z -= v.z; this.w -= v.w; return this; } subScalar(s) { this.x -= s; this.y -= s; this.z -= s; this.w -= s; return this; } subVectors(a2, b) { this.x = a2.x - b.x; this.y = a2.y - b.y; this.z = a2.z - b.z; this.w = a2.w - b.w; return this; } multiply(v) { this.x *= v.x; this.y *= v.y; this.z *= v.z; this.w *= v.w; return this; } multiplyScalar(scalar) { this.x *= scalar; this.y *= scalar; this.z *= scalar; this.w *= scalar; return this; } applyMatrix4(m2) { const x3 = this.x, y3 = this.y, z4 = this.z, w = this.w; const e = m2.elements; this.x = e[0] * x3 + e[4] * y3 + e[8] * z4 + e[12] * w; this.y = e[1] * x3 + e[5] * y3 + e[9] * z4 + e[13] * w; this.z = e[2] * x3 + e[6] * y3 + e[10] * z4 + e[14] * w; this.w = e[3] * x3 + e[7] * y3 + e[11] * z4 + e[15] * w; return this; } divideScalar(scalar) { return this.multiplyScalar(1 / scalar); } setAxisAngleFromQuaternion(q) { this.w = 2 * Math.acos(q.w); const s = Math.sqrt(1 - q.w * q.w); if (s < 1e-4) { this.x = 1; this.y = 0; this.z = 0; } else { this.x = q.x / s; this.y = q.y / s; this.z = q.z / s; } return this; } setAxisAngleFromRotationMatrix(m2) { let angle, x3, y3, z4; const epsilon = 0.01, epsilon2 = 0.1, te = m2.elements, m11 = te[0], m12 = te[4], m13 = te[8], m21 = te[1], m22 = te[5], m23 = te[9], m31 = te[2], m32 = te[6], m33 = te[10]; if (Math.abs(m12 - m21) < epsilon && Math.abs(m13 - m31) < epsilon && Math.abs(m23 - m32) < epsilon) { if (Math.abs(m12 + m21) < epsilon2 && Math.abs(m13 + m31) < epsilon2 && Math.abs(m23 + m32) < epsilon2 && Math.abs(m11 + m22 + m33 - 3) < epsilon2) { this.set(1, 0, 0, 0); return this; } angle = Math.PI; const xx = (m11 + 1) / 2; const yy = (m22 + 1) / 2; const zz = (m33 + 1) / 2; const xy = (m12 + m21) / 4; const xz = (m13 + m31) / 4; const yz = (m23 + m32) / 4; if (xx > yy && xx > zz) { if (xx < epsilon) { x3 = 0; y3 = 0.707106781; z4 = 0.707106781; } else { x3 = Math.sqrt(xx); y3 = xy / x3; z4 = xz / x3; } } else if (yy > zz) { if (yy < epsilon) { x3 = 0.707106781; y3 = 0; z4 = 0.707106781; } else { y3 = Math.sqrt(yy); x3 = xy / y3; z4 = yz / y3; } } else { if (zz < epsilon) { x3 = 0.707106781; y3 = 0.707106781; z4 = 0; } else { z4 = Math.sqrt(zz); x3 = xz / z4; y3 = yz / z4; } } this.set(x3, y3, z4, angle); return this; } let s = Math.sqrt((m32 - m23) * (m32 - m23) + (m13 - m31) * (m13 - m31) + (m21 - m12) * (m21 - m12)); if (Math.abs(s) < 1e-3) s = 1; this.x = (m32 - m23) / s; this.y = (m13 - m31) / s; this.z = (m21 - m12) / s; this.w = Math.acos((m11 + m22 + m33 - 1) / 2); return this; } min(v) { this.x = Math.min(this.x, v.x); this.y = Math.min(this.y, v.y); this.z = Math.min(this.z, v.z); this.w = Math.min(this.w, v.w); return this; } max(v) { this.x = Math.max(this.x, v.x); this.y = Math.max(this.y, v.y); this.z = Math.max(this.z, v.z); this.w = Math.max(this.w, v.w); return this; } clamp(min2, max2) { this.x = Math.max(min2.x, Math.min(max2.x, this.x)); this.y = Math.max(min2.y, Math.min(max2.y, this.y)); this.z = Math.max(min2.z, Math.min(max2.z, this.z)); this.w = Math.max(min2.w, Math.min(max2.w, this.w)); return this; } clampScalar(minVal, maxVal) { this.x = Math.max(minVal, Math.min(maxVal, this.x)); this.y = Math.max(minVal, Math.min(maxVal, this.y)); this.z = Math.max(minVal, Math.min(maxVal, this.z)); this.w = Math.max(minVal, Math.min(maxVal, this.w)); return this; } clampLength(min2, max2) { const length = this.length(); return this.divideScalar(length || 1).multiplyScalar(Math.max(min2, Math.min(max2, length))); } floor() { this.x = Math.floor(this.x); this.y = Math.floor(this.y); this.z = Math.floor(this.z); this.w = Math.floor(this.w); return this; } ceil() { this.x = Math.ceil(this.x); this.y = Math.ceil(this.y); this.z = Math.ceil(this.z); this.w = Math.ceil(this.w); return this; } round() { this.x = Math.round(this.x); this.y = Math.round(this.y); this.z = Math.round(this.z); this.w = Math.round(this.w); return this; } roundToZero() { this.x = Math.trunc(this.x); this.y = Math.trunc(this.y); this.z = Math.trunc(this.z); this.w = Math.trunc(this.w); return this; } negate() { this.x = -this.x; this.y = -this.y; this.z = -this.z; this.w = -this.w; return this; } dot(v) { return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w; } lengthSq() { return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w; } length() { return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w); } manhattanLength() { return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w); } normalize() { return this.divideScalar(this.length() || 1); } setLength(length) { return this.normalize().multiplyScalar(length); } lerp(v, alpha) { this.x += (v.x - this.x) * alpha; this.y += (v.y - this.y) * alpha; this.z += (v.z - this.z) * alpha; this.w += (v.w - this.w) * alpha; return this; } lerpVectors(v1, v2, alpha) { this.x = v1.x + (v2.x - v1.x) * alpha; this.y = v1.y + (v2.y - v1.y) * alpha; this.z = v1.z + (v2.z - v1.z) * alpha; this.w = v1.w + (v2.w - v1.w) * alpha; return this; } equals(v) { return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w; } fromArray(array, offset = 0) { this.x = array[offset]; this.y = array[offset + 1]; this.z = array[offset + 2]; this.w = array[offset + 3]; return this; } toArray(array = [], offset = 0) { array[offset] = this.x; array[offset + 1] = this.y; array[offset + 2] = this.z; array[offset + 3] = this.w; return array; } fromBufferAttribute(attribute, index6) { this.x = attribute.getX(index6); this.y = attribute.getY(index6); this.z = attribute.getZ(index6); this.w = attribute.getW(index6); return this; } random() { this.x = Math.random(); this.y = Math.random(); this.z = Math.random(); this.w = Math.random(); return this; } *[Symbol.iterator]() { yield this.x; yield this.y; yield this.z; yield this.w; } }; var RenderTarget = class extends EventDispatcher { constructor(width = 1, height = 1, options = {}) { super(); this.isRenderTarget = true; this.width = width; this.height = height; this.depth = 1; this.scissor = new Vector4(0, 0, width, height); this.scissorTest = false; this.viewport = new Vector4(0, 0, width, height); const image = { width, height, depth: 1 }; if (options.encoding !== void 0) { warnOnce("THREE.WebGLRenderTarget: option.encoding has been replaced by option.colorSpace."); options.colorSpace = options.encoding === sRGBEncoding ? SRGBColorSpace : NoColorSpace; } options = Object.assign({ generateMipmaps: false, internalFormat: null, minFilter: LinearFilter, depthBuffer: true, stencilBuffer: false, depthTexture: null, samples: 0 }, options); this.texture = new Texture(image, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace); this.texture.isRenderTargetTexture = true; this.texture.flipY = false; this.texture.generateMipmaps = options.generateMipmaps; this.texture.internalFormat = options.internalFormat; this.depthBuffer = options.depthBuffer; this.stencilBuffer = options.stencilBuffer; this.depthTexture = options.depthTexture; this.samples = options.samples; } setSize(width, height, depth = 1) { if (this.width !== width || this.height !== height || this.depth !== depth) { this.width = width; this.height = height; this.depth = depth; this.texture.image.width = width; this.texture.image.height = height; this.texture.image.depth = depth; this.dispose(); } this.viewport.set(0, 0, width, height); this.scissor.set(0, 0, width, height); } clone() { return new this.constructor().copy(this); } copy(source) { this.width = source.width; this.height = source.height; this.depth = source.depth; this.scissor.copy(source.scissor); this.scissorTest = source.scissorTest; this.viewport.copy(source.viewport); this.texture = source.texture.clone(); this.texture.isRenderTargetTexture = true; const image = Object.assign({}, source.texture.image); this.texture.source = new Source(image); this.depthBuffer = source.depthBuffer; this.stencilBuffer = source.stencilBuffer; if (source.depthTexture !== null) this.depthTexture = source.depthTexture.clone(); this.samples = source.samples; return this; } dispose() { this.dispatchEvent({ type: "dispose" }); } }; var WebGLRenderTarget = class extends RenderTarget { constructor(width = 1, height = 1, options = {}) { super(width, height, options); this.isWebGLRenderTarget = true; } }; var DataArrayTexture = class extends Texture { constructor(data = null, width = 1, height = 1, depth = 1) { super(null); this.isDataArrayTexture = true; this.image = { data, width, height, depth }; this.magFilter = NearestFilter; this.minFilter = NearestFilter; this.wrapR = ClampToEdgeWrapping; this.generateMipmaps = false; this.flipY = false; this.unpackAlignment = 1; } }; var Data3DTexture = class extends Texture { constructor(data = null, width = 1, height = 1, depth = 1) { super(null); this.isData3DTexture = true; this.image = { data, width, height, depth }; this.magFilter = NearestFilter; this.minFilter = NearestFilter; this.wrapR = ClampToEdgeWrapping; this.generateMipmaps = false; this.flipY = false; this.unpackAlignment = 1; } }; var Quaternion = class { constructor(x3 = 0, y3 = 0, z4 = 0, w = 1) { this.isQuaternion = true; this._x = x3; this._y = y3; this._z = z4; this._w = w; } static slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) { let x0 = src0[srcOffset0 + 0], y0 = src0[srcOffset0 + 1], z0 = src0[srcOffset0 + 2], w0 = src0[srcOffset0 + 3]; const x1 = src1[srcOffset1 + 0], y1 = src1[srcOffset1 + 1], z1 = src1[srcOffset1 + 2], w1 = src1[srcOffset1 + 3]; if (t === 0) { dst[dstOffset + 0] = x0; dst[dstOffset + 1] = y0; dst[dstOffset + 2] = z0; dst[dstOffset + 3] = w0; return; } if (t === 1) { dst[dstOffset + 0] = x1; dst[dstOffset + 1] = y1; dst[dstOffset + 2] = z1; dst[dstOffset + 3] = w1; return; } if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) { let s = 1 - t; const cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1, dir = cos >= 0 ? 1 : -1, sqrSin = 1 - cos * cos; if (sqrSin > Number.EPSILON) { const sin = Math.sqrt(sqrSin), len = Math.atan2(sin, cos * dir); s = Math.sin(s * len) / sin; t = Math.sin(t * len) / sin; } const tDir = t * dir; x0 = x0 * s + x1 * tDir; y0 = y0 * s + y1 * tDir; z0 = z0 * s + z1 * tDir; w0 = w0 * s + w1 * tDir; if (s === 1 - t) { const f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0); x0 *= f; y0 *= f; z0 *= f; w0 *= f; } } dst[dstOffset] = x0; dst[dstOffset + 1] = y0; dst[dstOffset + 2] = z0; dst[dstOffset + 3] = w0; } static multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) { const x0 = src0[srcOffset0]; const y0 = src0[srcOffset0 + 1]; const z0 = src0[srcOffset0 + 2]; const w0 = src0[srcOffset0 + 3]; const x1 = src1[srcOffset1]; const y1 = src1[srcOffset1 + 1]; const z1 = src1[srcOffset1 + 2]; const w1 = src1[srcOffset1 + 3]; dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1; dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1; dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1; dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1; return dst; } get x() { return this._x; } set x(value) { this._x = value; this._onChangeCallback(); } get y() { return this._y; } set y(value) { this._y = value; this._onChangeCallback(); } get z() { return this._z; } set z(value) { this._z = value; this._onChangeCallback(); } get w() { return this._w; } set w(value) { this._w = value; this._onChangeCallback(); } set(x3, y3, z4, w) { this._x = x3; this._y = y3; this._z = z4; this._w = w; this._onChangeCallback(); return this; } clone() { return new this.constructor(this._x, this._y, this._z, this._w); } copy(quaternion) { this._x = quaternion.x; this._y = quaternion.y; this._z = quaternion.z; this._w = quaternion.w; this._onChangeCallback(); return this; } setFromEuler(euler, update4) { const x3 = euler._x, y3 = euler._y, z4 = euler._z, order = euler._order; const cos = Math.cos; const sin = Math.sin; const c1 = cos(x3 / 2); const c2 = cos(y3 / 2); const c3 = cos(z4 / 2); const s1 = sin(x3 / 2); const s2 = sin(y3 / 2); const s3 = sin(z4 / 2); switch (order) { case "XYZ": this._x = s1 * c2 * c3 + c1 * s2 * s3; this._y = c1 * s2 * c3 - s1 * c2 * s3; this._z = c1 * c2 * s3 + s1 * s2 * c3; this._w = c1 * c2 * c3 - s1 * s2 * s3; break; case "YXZ": this._x = s1 * c2 * c3 + c1 * s2 * s3; this._y = c1 * s2 * c3 - s1 * c2 * s3; this._z = c1 * c2 * s3 - s1 * s2 * c3; this._w = c1 * c2 * c3 + s1 * s2 * s3; break; case "ZXY": this._x = s1 * c2 * c3 - c1 * s2 * s3; this._y = c1 * s2 * c3 + s1 * c2 * s3; this._z = c1 * c2 * s3 + s1 * s2 * c3; this._w = c1 * c2 * c3 - s1 * s2 * s3; break; case "ZYX": this._x = s1 * c2 * c3 - c1 * s2 * s3; this._y = c1 * s2 * c3 + s1 * c2 * s3; this._z = c1 * c2 * s3 - s1 * s2 * c3; this._w = c1 * c2 * c3 + s1 * s2 * s3; break; case "YZX": this._x = s1 * c2 * c3 + c1 * s2 * s3; this._y = c1 * s2 * c3 + s1 * c2 * s3; this._z = c1 * c2 * s3 - s1 * s2 * c3; this._w = c1 * c2 * c3 - s1 * s2 * s3; break; case "XZY": this._x = s1 * c2 * c3 - c1 * s2 * s3; this._y = c1 * s2 * c3 - s1 * c2 * s3; this._z = c1 * c2 * s3 + s1 * s2 * c3; this._w = c1 * c2 * c3 + s1 * s2 * s3; break; default: console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: " + order); } if (update4 !== false) this._onChangeCallback(); return this; } setFromAxisAngle(axis, angle) { const halfAngle = angle / 2, s = Math.sin(halfAngle); this._x = axis.x * s; this._y = axis.y * s; this._z = axis.z * s; this._w = Math.cos(halfAngle); this._onChangeCallback(); return this; } setFromRotationMatrix(m2) { const te = m2.elements, m11 = te[0], m12 = te[4], m13 = te[8], m21 = te[1], m22 = te[5], m23 = te[9], m31 = te[2], m32 = te[6], m33 = te[10], trace = m11 + m22 + m33; if (trace > 0) { const s = 0.5 / Math.sqrt(trace + 1); this._w = 0.25 / s; this._x = (m32 - m23) * s; this._y = (m13 - m31) * s; this._z = (m21 - m12) * s; } else if (m11 > m22 && m11 > m33) { const s = 2 * Math.sqrt(1 + m11 - m22 - m33); this._w = (m32 - m23) / s; this._x = 0.25 * s; this._y = (m12 + m21) / s; this._z = (m13 + m31) / s; } else if (m22 > m33) { const s = 2 * Math.sqrt(1 + m22 - m11 - m33); this._w = (m13 - m31) / s; this._x = (m12 + m21) / s; this._y = 0.25 * s; this._z = (m23 + m32) / s; } else { const s = 2 * Math.sqrt(1 + m33 - m11 - m22); this._w = (m21 - m12) / s; this._x = (m13 + m31) / s; this._y = (m23 + m32) / s; this._z = 0.25 * s; } this._onChangeCallback(); return this; } setFromUnitVectors(vFrom, vTo) { let r = vFrom.dot(vTo) + 1; if (r < Number.EPSILON) { r = 0; if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) { this._x = -vFrom.y; this._y = vFrom.x; this._z = 0; this._w = r; } else { this._x = 0; this._y = -vFrom.z; this._z = vFrom.y; this._w = r; } } else { this._x = vFrom.y * vTo.z - vFrom.z * vTo.y; this._y = vFrom.z * vTo.x - vFrom.x * vTo.z; this._z = vFrom.x * vTo.y - vFrom.y * vTo.x; this._w = r; } return this.normalize(); } angleTo(q) { return 2 * Math.acos(Math.abs(clamp(this.dot(q), -1, 1))); } rotateTowards(q, step) { const angle = this.angleTo(q); if (angle === 0) return this; const t = Math.min(1, step / angle); this.slerp(q, t); return this; } identity() { return this.set(0, 0, 0, 1); } invert() { return this.conjugate(); } conjugate() { this._x *= -1; this._y *= -1; this._z *= -1; this._onChangeCallback(); return this; } dot(v) { return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w; } lengthSq() { return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w; } length() { return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w); } normalize() { let l = this.length(); if (l === 0) { this._x = 0; this._y = 0; this._z = 0; this._w = 1; } else { l = 1 / l; this._x = this._x * l; this._y = this._y * l; this._z = this._z * l; this._w = this._w * l; } this._onChangeCallback(); return this; } multiply(q) { return this.multiplyQuaternions(this, q); } premultiply(q) { return this.multiplyQuaternions(q, this); } multiplyQuaternions(a2, b) { const qax = a2._x, qay = a2._y, qaz = a2._z, qaw = a2._w; const qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w; this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby; this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz; this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx; this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz; this._onChangeCallback(); return this; } slerp(qb, t) { if (t === 0) return this; if (t === 1) return this.copy(qb); const x3 = this._x, y3 = this._y, z4 = this._z, w = this._w; let cosHalfTheta = w * qb._w + x3 * qb._x + y3 * qb._y + z4 * qb._z; if (cosHalfTheta < 0) { this._w = -qb._w; this._x = -qb._x; this._y = -qb._y; this._z = -qb._z; cosHalfTheta = -cosHalfTheta; } else { this.copy(qb); } if (cosHalfTheta >= 1) { this._w = w; this._x = x3; this._y = y3; this._z = z4; return this; } const sqrSinHalfTheta = 1 - cosHalfTheta * cosHalfTheta; if (sqrSinHalfTheta <= Number.EPSILON) { const s = 1 - t; this._w = s * w + t * this._w; this._x = s * x3 + t * this._x; this._y = s * y3 + t * this._y; this._z = s * z4 + t * this._z; this.normalize(); this._onChangeCallback(); return this; } const sinHalfTheta = Math.sqrt(sqrSinHalfTheta); const halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta); const ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta, ratioB = Math.sin(t * halfTheta) / sinHalfTheta; this._w = w * ratioA + this._w * ratioB; this._x = x3 * ratioA + this._x * ratioB; this._y = y3 * ratioA + this._y * ratioB; this._z = z4 * ratioA + this._z * ratioB; this._onChangeCallback(); return this; } slerpQuaternions(qa, qb, t) { return this.copy(qa).slerp(qb, t); } random() { const u1 = Math.random(); const sqrt1u1 = Math.sqrt(1 - u1); const sqrtu1 = Math.sqrt(u1); const u2 = 2 * Math.PI * Math.random(); const u3 = 2 * Math.PI * Math.random(); return this.set( sqrt1u1 * Math.cos(u2), sqrtu1 * Math.sin(u3), sqrtu1 * Math.cos(u3), sqrt1u1 * Math.sin(u2) ); } equals(quaternion) { return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w; } fromArray(array, offset = 0) { this._x = array[offset]; this._y = array[offset + 1]; this._z = array[offset + 2]; this._w = array[offset + 3]; this._onChangeCallback(); return this; } toArray(array = [], offset = 0) { array[offset] = this._x; array[offset + 1] = this._y; array[offset + 2] = this._z; array[offset + 3] = this._w; return array; } fromBufferAttribute(attribute, index6) { this._x = attribute.getX(index6); this._y = attribute.getY(index6); this._z = attribute.getZ(index6); this._w = attribute.getW(index6); return this; } toJSON() { return this.toArray(); } _onChange(callback) { this._onChangeCallback = callback; return this; } _onChangeCallback() { } *[Symbol.iterator]() { yield this._x; yield this._y; yield this._z; yield this._w; } }; var Vector3 = class { constructor(x3 = 0, y3 = 0, z4 = 0) { Vector3.prototype.isVector3 = true; this.x = x3; this.y = y3; this.z = z4; } set(x3, y3, z4) { if (z4 === void 0) z4 = this.z; this.x = x3; this.y = y3; this.z = z4; return this; } setScalar(scalar) { this.x = scalar; this.y = scalar; this.z = scalar; return this; } setX(x3) { this.x = x3; return this; } setY(y3) { this.y = y3; return this; } setZ(z4) { this.z = z4; return this; } setComponent(index6, value) { switch (index6) { case 0: this.x = value; break; case 1: this.y = value; break; case 2: this.z = value; break; default: throw new Error("index is out of range: " + index6); } return this; } getComponent(index6) { switch (index6) { case 0: return this.x; case 1: return this.y; case 2: return this.z; default: throw new Error("index is out of range: " + index6); } } clone() { return new this.constructor(this.x, this.y, this.z); } copy(v) { this.x = v.x; this.y = v.y; this.z = v.z; return this; } add(v) { this.x += v.x; this.y += v.y; this.z += v.z; return this; } addScalar(s) { this.x += s; this.y += s; this.z += s; return this; } addVectors(a2, b) { this.x = a2.x + b.x; this.y = a2.y + b.y; this.z = a2.z + b.z; return this; } addScaledVector(v, s) { this.x += v.x * s; this.y += v.y * s; this.z += v.z * s; return this; } sub(v) { this.x -= v.x; this.y -= v.y; this.z -= v.z; return this; } subScalar(s) { this.x -= s; this.y -= s; this.z -= s; return this; } subVectors(a2, b) { this.x = a2.x - b.x; this.y = a2.y - b.y; this.z = a2.z - b.z; return this; } multiply(v) { this.x *= v.x; this.y *= v.y; this.z *= v.z; return this; } multiplyScalar(scalar) { this.x *= scalar; this.y *= scalar; this.z *= scalar; return this; } multiplyVectors(a2, b) { this.x = a2.x * b.x; this.y = a2.y * b.y; this.z = a2.z * b.z; return this; } applyEuler(euler) { return this.applyQuaternion(_quaternion$4.setFromEuler(euler)); } applyAxisAngle(axis, angle) { return this.applyQuaternion(_quaternion$4.setFromAxisAngle(axis, angle)); } applyMatrix3(m2) { const x3 = this.x, y3 = this.y, z4 = this.z; const e = m2.elements; this.x = e[0] * x3 + e[3] * y3 + e[6] * z4; this.y = e[1] * x3 + e[4] * y3 + e[7] * z4; this.z = e[2] * x3 + e[5] * y3 + e[8] * z4; return this; } applyNormalMatrix(m2) { return this.applyMatrix3(m2).normalize(); } applyMatrix4(m2) { const x3 = this.x, y3 = this.y, z4 = this.z; const e = m2.elements; const w = 1 / (e[3] * x3 + e[7] * y3 + e[11] * z4 + e[15]); this.x = (e[0] * x3 + e[4] * y3 + e[8] * z4 + e[12]) * w; this.y = (e[1] * x3 + e[5] * y3 + e[9] * z4 + e[13]) * w; this.z = (e[2] * x3 + e[6] * y3 + e[10] * z4 + e[14]) * w; return this; } applyQuaternion(q) { const vx = this.x, vy = this.y, vz = this.z; const qx = q.x, qy = q.y, qz = q.z, qw = q.w; const tx = 2 * (qy * vz - qz * vy); const ty = 2 * (qz * vx - qx * vz); const tz = 2 * (qx * vy - qy * vx); this.x = vx + qw * tx + qy * tz - qz * ty; this.y = vy + qw * ty + qz * tx - qx * tz; this.z = vz + qw * tz + qx * ty - qy * tx; return this; } project(camera3) { return this.applyMatrix4(camera3.matrixWorldInverse).applyMatrix4(camera3.projectionMatrix); } unproject(camera3) { return this.applyMatrix4(camera3.projectionMatrixInverse).applyMatrix4(camera3.matrixWorld); } transformDirection(m2) { const x3 = this.x, y3 = this.y, z4 = this.z; const e = m2.elements; this.x = e[0] * x3 + e[4] * y3 + e[8] * z4; this.y = e[1] * x3 + e[5] * y3 + e[9] * z4; this.z = e[2] * x3 + e[6] * y3 + e[10] * z4; return this.normalize(); } divide(v) { this.x /= v.x; this.y /= v.y; this.z /= v.z; return this; } divideScalar(scalar) { return this.multiplyScalar(1 / scalar); } min(v) { this.x = Math.min(this.x, v.x); this.y = Math.min(this.y, v.y); this.z = Math.min(this.z, v.z); return this; } max(v) { this.x = Math.max(this.x, v.x); this.y = Math.max(this.y, v.y); this.z = Math.max(this.z, v.z); return this; } clamp(min2, max2) { this.x = Math.max(min2.x, Math.min(max2.x, this.x)); this.y = Math.max(min2.y, Math.min(max2.y, this.y)); this.z = Math.max(min2.z, Math.min(max2.z, this.z)); return this; } clampScalar(minVal, maxVal) { this.x = Math.max(minVal, Math.min(maxVal, this.x)); this.y = Math.max(minVal, Math.min(maxVal, this.y)); this.z = Math.max(minVal, Math.min(maxVal, this.z)); return this; } clampLength(min2, max2) { const length = this.length(); return this.divideScalar(length || 1).multiplyScalar(Math.max(min2, Math.min(max2, length))); } floor() { this.x = Math.floor(this.x); this.y = Math.floor(this.y); this.z = Math.floor(this.z); return this; } ceil() { this.x = Math.ceil(this.x); this.y = Math.ceil(this.y); this.z = Math.ceil(this.z); return this; } round() { this.x = Math.round(this.x); this.y = Math.round(this.y); this.z = Math.round(this.z); return this; } roundToZero() { this.x = Math.trunc(this.x); this.y = Math.trunc(this.y); this.z = Math.trunc(this.z); return this; } negate() { this.x = -this.x; this.y = -this.y; this.z = -this.z; return this; } dot(v) { return this.x * v.x + this.y * v.y + this.z * v.z; } // TODO lengthSquared? lengthSq() { return this.x * this.x + this.y * this.y + this.z * this.z; } length() { return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); } manhattanLength() { return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z); } normalize() { return this.divideScalar(this.length() || 1); } setLength(length) { return this.normalize().multiplyScalar(length); } lerp(v, alpha) { this.x += (v.x - this.x) * alpha; this.y += (v.y - this.y) * alpha; this.z += (v.z - this.z) * alpha; return this; } lerpVectors(v1, v2, alpha) { this.x = v1.x + (v2.x - v1.x) * alpha; this.y = v1.y + (v2.y - v1.y) * alpha; this.z = v1.z + (v2.z - v1.z) * alpha; return this; } cross(v) { return this.crossVectors(this, v); } crossVectors(a2, b) { const ax = a2.x, ay = a2.y, az = a2.z; const bx = b.x, by = b.y, bz = b.z; this.x = ay * bz - az * by; this.y = az * bx - ax * bz; this.z = ax * by - ay * bx; return this; } projectOnVector(v) { const denominator = v.lengthSq(); if (denominator === 0) return this.set(0, 0, 0); const scalar = v.dot(this) / denominator; return this.copy(v).multiplyScalar(scalar); } projectOnPlane(planeNormal) { _vector$b.copy(this).projectOnVector(planeNormal); return this.sub(_vector$b); } reflect(normal) { return this.sub(_vector$b.copy(normal).multiplyScalar(2 * this.dot(normal))); } angleTo(v) { const denominator = Math.sqrt(this.lengthSq() * v.lengthSq()); if (denominator === 0) return Math.PI / 2; const theta = this.dot(v) / denominator; return Math.acos(clamp(theta, -1, 1)); } distanceTo(v) { return Math.sqrt(this.distanceToSquared(v)); } distanceToSquared(v) { const dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z; return dx * dx + dy * dy + dz * dz; } manhattanDistanceTo(v) { return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z); } setFromSpherical(s) { return this.setFromSphericalCoords(s.radius, s.phi, s.theta); } setFromSphericalCoords(radius, phi, theta) { const sinPhiRadius = Math.sin(phi) * radius; this.x = sinPhiRadius * Math.sin(theta); this.y = Math.cos(phi) * radius; this.z = sinPhiRadius * Math.cos(theta); return this; } setFromCylindrical(c2) { return this.setFromCylindricalCoords(c2.radius, c2.theta, c2.y); } setFromCylindricalCoords(radius, theta, y3) { this.x = radius * Math.sin(theta); this.y = y3; this.z = radius * Math.cos(theta); return this; } setFromMatrixPosition(m2) { const e = m2.elements; this.x = e[12]; this.y = e[13]; this.z = e[14]; return this; } setFromMatrixScale(m2) { const sx = this.setFromMatrixColumn(m2, 0).length(); const sy = this.setFromMatrixColumn(m2, 1).length(); const sz = this.setFromMatrixColumn(m2, 2).length(); this.x = sx; this.y = sy; this.z = sz; return this; } setFromMatrixColumn(m2, index6) { return this.fromArray(m2.elements, index6 * 4); } setFromMatrix3Column(m2, index6) { return this.fromArray(m2.elements, index6 * 3); } setFromEuler(e) { this.x = e._x; this.y = e._y; this.z = e._z; return this; } setFromColor(c2) { this.x = c2.r; this.y = c2.g; this.z = c2.b; return this; } equals(v) { return v.x === this.x && v.y === this.y && v.z === this.z; } fromArray(array, offset = 0) { this.x = array[offset]; this.y = array[offset + 1]; this.z = array[offset + 2]; return this; } toArray(array = [], offset = 0) { array[offset] = this.x; array[offset + 1] = this.y; array[offset + 2] = this.z; return array; } fromBufferAttribute(attribute, index6) { this.x = attribute.getX(index6); this.y = attribute.getY(index6); this.z = attribute.getZ(index6); return this; } random() { this.x = Math.random(); this.y = Math.random(); this.z = Math.random(); return this; } randomDirection() { const u = (Math.random() - 0.5) * 2; const t = Math.random() * Math.PI * 2; const f = Math.sqrt(1 - u ** 2); this.x = f * Math.cos(t); this.y = f * Math.sin(t); this.z = u; return this; } *[Symbol.iterator]() { yield this.x; yield this.y; yield this.z; } }; var _vector$b = /* @__PURE__ */ new Vector3(); var _quaternion$4 = /* @__PURE__ */ new Quaternion(); var Box3 = class { constructor(min2 = new Vector3(Infinity, Infinity, Infinity), max2 = new Vector3(-Infinity, -Infinity, -Infinity)) { this.isBox3 = true; this.min = min2; this.max = max2; } set(min2, max2) { this.min.copy(min2); this.max.copy(max2); return this; } setFromArray(array) { this.makeEmpty(); for (let i = 0, il = array.length; i < il; i += 3) { this.expandByPoint(_vector$a.fromArray(array, i)); } return this; } setFromBufferAttribute(attribute) { this.makeEmpty(); for (let i = 0, il = attribute.count; i < il; i++) { this.expandByPoint(_vector$a.fromBufferAttribute(attribute, i)); } return this; } setFromPoints(points) { this.makeEmpty(); for (let i = 0, il = points.length; i < il; i++) { this.expandByPoint(points[i]); } return this; } setFromCenterAndSize(center, size) { const halfSize = _vector$a.copy(size).multiplyScalar(0.5); this.min.copy(center).sub(halfSize); this.max.copy(center).add(halfSize); return this; } setFromObject(object, precise = false) { this.makeEmpty(); return this.expandByObject(object, precise); } clone() { return new this.constructor().copy(this); } copy(box) { this.min.copy(box.min); this.max.copy(box.max); return this; } makeEmpty() { this.min.x = this.min.y = this.min.z = Infinity; this.max.x = this.max.y = this.max.z = -Infinity; return this; } isEmpty() { return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z; } getCenter(target) { return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5); } getSize(target) { return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min); } expandByPoint(point) { this.min.min(point); this.max.max(point); return this; } expandByVector(vector) { this.min.sub(vector); this.max.add(vector); return this; } expandByScalar(scalar) { this.min.addScalar(-scalar); this.max.addScalar(scalar); return this; } expandByObject(object, precise = false) { object.updateWorldMatrix(false, false); const geometry = object.geometry; if (geometry !== void 0) { const positionAttribute = geometry.getAttribute("position"); if (precise === true && positionAttribute !== void 0 && object.isInstancedMesh !== true) { for (let i = 0, l = positionAttribute.count; i < l; i++) { if (object.isMesh === true) { object.getVertexPosition(i, _vector$a); } else { _vector$a.fromBufferAttribute(positionAttribute, i); } _vector$a.applyMatrix4(object.matrixWorld); this.expandByPoint(_vector$a); } } else { if (object.boundingBox !== void 0) { if (object.boundingBox === null) { object.computeBoundingBox(); } _box$3.copy(object.boundingBox); } else { if (geometry.boundingBox === null) { geometry.computeBoundingBox(); } _box$3.copy(geometry.boundingBox); } _box$3.applyMatrix4(object.matrixWorld); this.union(_box$3); } } const children = object.children; for (let i = 0, l = children.length; i < l; i++) { this.expandByObject(children[i], precise); } return this; } containsPoint(point) { return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y || point.z < this.min.z || point.z > this.max.z ? false : true; } containsBox(box) { return this.min.x <= box.min.x && box.max.x <= this.max.x && this.min.y <= box.min.y && box.max.y <= this.max.y && this.min.z <= box.min.z && box.max.z <= this.max.z; } getParameter(point, target) { return target.set( (point.x - this.min.x) / (this.max.x - this.min.x), (point.y - this.min.y) / (this.max.y - this.min.y), (point.z - this.min.z) / (this.max.z - this.min.z) ); } intersectsBox(box) { return box.max.x < this.min.x || box.min.x > this.max.x || box.max.y < this.min.y || box.min.y > this.max.y || box.max.z < this.min.z || box.min.z > this.max.z ? false : true; } intersectsSphere(sphere) { this.clampPoint(sphere.center, _vector$a); return _vector$a.distanceToSquared(sphere.center) <= sphere.radius * sphere.radius; } intersectsPlane(plane) { let min2, max2; if (plane.normal.x > 0) { min2 = plane.normal.x * this.min.x; max2 = plane.normal.x * this.max.x; } else { min2 = plane.normal.x * this.max.x; max2 = plane.normal.x * this.min.x; } if (plane.normal.y > 0) { min2 += plane.normal.y * this.min.y; max2 += plane.normal.y * this.max.y; } else { min2 += plane.normal.y * this.max.y; max2 += plane.normal.y * this.min.y; } if (plane.normal.z > 0) { min2 += plane.normal.z * this.min.z; max2 += plane.normal.z * this.max.z; } else { min2 += plane.normal.z * this.max.z; max2 += plane.normal.z * this.min.z; } return min2 <= -plane.constant && max2 >= -plane.constant; } intersectsTriangle(triangle) { if (this.isEmpty()) { return false; } this.getCenter(_center); _extents.subVectors(this.max, _center); _v0$2.subVectors(triangle.a, _center); _v1$7.subVectors(triangle.b, _center); _v2$4.subVectors(triangle.c, _center); _f0.subVectors(_v1$7, _v0$2); _f1.subVectors(_v2$4, _v1$7); _f2.subVectors(_v0$2, _v2$4); let axes = [ 0, -_f0.z, _f0.y, 0, -_f1.z, _f1.y, 0, -_f2.z, _f2.y, _f0.z, 0, -_f0.x, _f1.z, 0, -_f1.x, _f2.z, 0, -_f2.x, -_f0.y, _f0.x, 0, -_f1.y, _f1.x, 0, -_f2.y, _f2.x, 0 ]; if (!satForAxes(axes, _v0$2, _v1$7, _v2$4, _extents)) { return false; } axes = [1, 0, 0, 0, 1, 0, 0, 0, 1]; if (!satForAxes(axes, _v0$2, _v1$7, _v2$4, _extents)) { return false; } _triangleNormal.crossVectors(_f0, _f1); axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z]; return satForAxes(axes, _v0$2, _v1$7, _v2$4, _extents); } clampPoint(point, target) { return target.copy(point).clamp(this.min, this.max); } distanceToPoint(point) { return this.clampPoint(point, _vector$a).distanceTo(point); } getBoundingSphere(target) { if (this.isEmpty()) { target.makeEmpty(); } else { this.getCenter(target.center); target.radius = this.getSize(_vector$a).length() * 0.5; } return target; } intersect(box) { this.min.max(box.min); this.max.min(box.max); if (this.isEmpty()) this.makeEmpty(); return this; } union(box) { this.min.min(box.min); this.max.max(box.max); return this; } applyMatrix4(matrix) { if (this.isEmpty()) return this; _points[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); _points[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); _points[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); _points[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); _points[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); _points[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); _points[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); _points[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); this.setFromPoints(_points); return this; } translate(offset) { this.min.add(offset); this.max.add(offset); return this; } equals(box) { return box.min.equals(this.min) && box.max.equals(this.max); } }; var _points = [ /* @__PURE__ */ new Vector3(), /* @__PURE__ */ new Vector3(), /* @__PURE__ */ new Vector3(), /* @__PURE__ */ new Vector3(), /* @__PURE__ */ new Vector3(), /* @__PURE__ */ new Vector3(), /* @__PURE__ */ new Vector3(), /* @__PURE__ */ new Vector3() ]; var _vector$a = /* @__PURE__ */ new Vector3(); var _box$3 = /* @__PURE__ */ new Box3(); var _v0$2 = /* @__PURE__ */ new Vector3(); var _v1$7 = /* @__PURE__ */ new Vector3(); var _v2$4 = /* @__PURE__ */ new Vector3(); var _f0 = /* @__PURE__ */ new Vector3(); var _f1 = /* @__PURE__ */ new Vector3(); var _f2 = /* @__PURE__ */ new Vector3(); var _center = /* @__PURE__ */ new Vector3(); var _extents = /* @__PURE__ */ new Vector3(); var _triangleNormal = /* @__PURE__ */ new Vector3(); var _testAxis = /* @__PURE__ */ new Vector3(); function satForAxes(axes, v0, v1, v2, extents) { for (let i = 0, j = axes.length - 3; i <= j; i += 3) { _testAxis.fromArray(axes, i); const r = extents.x * Math.abs(_testAxis.x) + extents.y * Math.abs(_testAxis.y) + extents.z * Math.abs(_testAxis.z); const p0 = v0.dot(_testAxis); const p1 = v1.dot(_testAxis); const p2 = v2.dot(_testAxis); if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) { return false; } } return true; } var _box$2 = /* @__PURE__ */ new Box3(); var _v1$6 = /* @__PURE__ */ new Vector3(); var _v2$3 = /* @__PURE__ */ new Vector3(); var Sphere = class { constructor(center = new Vector3(), radius = -1) { this.center = center; this.radius = radius; } set(center, radius) { this.center.copy(center); this.radius = radius; return this; } setFromPoints(points, optionalCenter) { const center = this.center; if (optionalCenter !== void 0) { center.copy(optionalCenter); } else { _box$2.setFromPoints(points).getCenter(center); } let maxRadiusSq = 0; for (let i = 0, il = points.length; i < il; i++) { maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i])); } this.radius = Math.sqrt(maxRadiusSq); return this; } copy(sphere) { this.center.copy(sphere.center); this.radius = sphere.radius; return this; } isEmpty() { return this.radius < 0; } makeEmpty() { this.center.set(0, 0, 0); this.radius = -1; return this; } containsPoint(point) { return point.distanceToSquared(this.center) <= this.radius * this.radius; } distanceToPoint(point) { return point.distanceTo(this.center) - this.radius; } intersectsSphere(sphere) { const radiusSum = this.radius + sphere.radius; return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum; } intersectsBox(box) { return box.intersectsSphere(this); } intersectsPlane(plane) { return Math.abs(plane.distanceToPoint(this.center)) <= this.radius; } clampPoint(point, target) { const deltaLengthSq = this.center.distanceToSquared(point); target.copy(point); if (deltaLengthSq > this.radius * this.radius) { target.sub(this.center).normalize(); target.multiplyScalar(this.radius).add(this.center); } return target; } getBoundingBox(target) { if (this.isEmpty()) { target.makeEmpty(); return target; } target.set(this.center, this.center); target.expandByScalar(this.radius); return target; } applyMatrix4(matrix) { this.center.applyMatrix4(matrix); this.radius = this.radius * matrix.getMaxScaleOnAxis(); return this; } translate(offset) { this.center.add(offset); return this; } expandByPoint(point) { if (this.isEmpty()) { this.center.copy(point); this.radius = 0; return this; } _v1$6.subVectors(point, this.center); const lengthSq = _v1$6.lengthSq(); if (lengthSq > this.radius * this.radius) { const length = Math.sqrt(lengthSq); const delta = (length - this.radius) * 0.5; this.center.addScaledVector(_v1$6, delta / length); this.radius += delta; } return this; } union(sphere) { if (sphere.isEmpty()) { return this; } if (this.isEmpty()) { this.copy(sphere); return this; } if (this.center.equals(sphere.center) === true) { this.radius = Math.max(this.radius, sphere.radius); } else { _v2$3.subVectors(sphere.center, this.center).setLength(sphere.radius); this.expandByPoint(_v1$6.copy(sphere.center).add(_v2$3)); this.expandByPoint(_v1$6.copy(sphere.center).sub(_v2$3)); } return this; } equals(sphere) { return sphere.center.equals(this.center) && sphere.radius === this.radius; } clone() { return new this.constructor().copy(this); } }; var _vector$9 = /* @__PURE__ */ new Vector3(); var _segCenter = /* @__PURE__ */ new Vector3(); var _segDir = /* @__PURE__ */ new Vector3(); var _diff = /* @__PURE__ */ new Vector3(); var _edge1 = /* @__PURE__ */ new Vector3(); var _edge2 = /* @__PURE__ */ new Vector3(); var _normal$1 = /* @__PURE__ */ new Vector3(); var Ray = class { constructor(origin3 = new Vector3(), direction = new Vector3(0, 0, -1)) { this.origin = origin3; this.direction = direction; } set(origin3, direction) { this.origin.copy(origin3); this.direction.copy(direction); return this; } copy(ray) { this.origin.copy(ray.origin); this.direction.copy(ray.direction); return this; } at(t, target) { return target.copy(this.origin).addScaledVector(this.direction, t); } lookAt(v) { this.direction.copy(v).sub(this.origin).normalize(); return this; } recast(t) { this.origin.copy(this.at(t, _vector$9)); return this; } closestPointToPoint(point, target) { target.subVectors(point, this.origin); const directionDistance = target.dot(this.direction); if (directionDistance < 0) { return target.copy(this.origin); } return target.copy(this.origin).addScaledVector(this.direction, directionDistance); } distanceToPoint(point) { return Math.sqrt(this.distanceSqToPoint(point)); } distanceSqToPoint(point) { const directionDistance = _vector$9.subVectors(point, this.origin).dot(this.direction); if (directionDistance < 0) { return this.origin.distanceToSquared(point); } _vector$9.copy(this.origin).addScaledVector(this.direction, directionDistance); return _vector$9.distanceToSquared(point); } distanceSqToSegment(v0, v1, optionalPointOnRay, optionalPointOnSegment) { _segCenter.copy(v0).add(v1).multiplyScalar(0.5); _segDir.copy(v1).sub(v0).normalize(); _diff.copy(this.origin).sub(_segCenter); const segExtent = v0.distanceTo(v1) * 0.5; const a01 = -this.direction.dot(_segDir); const b0 = _diff.dot(this.direction); const b1 = -_diff.dot(_segDir); const c2 = _diff.lengthSq(); const det = Math.abs(1 - a01 * a01); let s0, s1, sqrDist, extDet; if (det > 0) { s0 = a01 * b1 - b0; s1 = a01 * b0 - b1; extDet = segExtent * det; if (s0 >= 0) { if (s1 >= -extDet) { if (s1 <= extDet) { const invDet = 1 / det; s0 *= invDet; s1 *= invDet; sqrDist = s0 * (s0 + a01 * s1 + 2 * b0) + s1 * (a01 * s0 + s1 + 2 * b1) + c2; } else { s1 = segExtent; s0 = Math.max(0, -(a01 * s1 + b0)); sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c2; } } else { s1 = -segExtent; s0 = Math.max(0, -(a01 * s1 + b0)); sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c2; } } else { if (s1 <= -extDet) { s0 = Math.max(0, -(-a01 * segExtent + b0)); s1 = s0 > 0 ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent); sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c2; } else if (s1 <= extDet) { s0 = 0; s1 = Math.min(Math.max(-segExtent, -b1), segExtent); sqrDist = s1 * (s1 + 2 * b1) + c2; } else { s0 = Math.max(0, -(a01 * segExtent + b0)); s1 = s0 > 0 ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent); sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c2; } } } else { s1 = a01 > 0 ? -segExtent : segExtent; s0 = Math.max(0, -(a01 * s1 + b0)); sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c2; } if (optionalPointOnRay) { optionalPointOnRay.copy(this.origin).addScaledVector(this.direction, s0); } if (optionalPointOnSegment) { optionalPointOnSegment.copy(_segCenter).addScaledVector(_segDir, s1); } return sqrDist; } intersectSphere(sphere, target) { _vector$9.subVectors(sphere.center, this.origin); const tca = _vector$9.dot(this.direction); const d2 = _vector$9.dot(_vector$9) - tca * tca; const radius2 = sphere.radius * sphere.radius; if (d2 > radius2) return null; const thc = Math.sqrt(radius2 - d2); const t0 = tca - thc; const t1 = tca + thc; if (t1 < 0) return null; if (t0 < 0) return this.at(t1, target); return this.at(t0, target); } intersectsSphere(sphere) { return this.distanceSqToPoint(sphere.center) <= sphere.radius * sphere.radius; } distanceToPlane(plane) { const denominator = plane.normal.dot(this.direction); if (denominator === 0) { if (plane.distanceToPoint(this.origin) === 0) { return 0; } return null; } const t = -(this.origin.dot(plane.normal) + plane.constant) / denominator; return t >= 0 ? t : null; } intersectPlane(plane, target) { const t = this.distanceToPlane(plane); if (t === null) { return null; } return this.at(t, target); } intersectsPlane(plane) { const distToPoint = plane.distanceToPoint(this.origin); if (distToPoint === 0) { return true; } const denominator = plane.normal.dot(this.direction); if (denominator * distToPoint < 0) { return true; } return false; } intersectBox(box, target) { let tmin, tmax, tymin, tymax, tzmin, tzmax; const invdirx = 1 / this.direction.x, invdiry = 1 / this.direction.y, invdirz = 1 / this.direction.z; const origin3 = this.origin; if (invdirx >= 0) { tmin = (box.min.x - origin3.x) * invdirx; tmax = (box.max.x - origin3.x) * invdirx; } else { tmin = (box.max.x - origin3.x) * invdirx; tmax = (box.min.x - origin3.x) * invdirx; } if (invdiry >= 0) { tymin = (box.min.y - origin3.y) * invdiry; tymax = (box.max.y - origin3.y) * invdiry; } else { tymin = (box.max.y - origin3.y) * invdiry; tymax = (box.min.y - origin3.y) * invdiry; } if (tmin > tymax || tymin > tmax) return null; if (tymin > tmin || isNaN(tmin)) tmin = tymin; if (tymax < tmax || isNaN(tmax)) tmax = tymax; if (invdirz >= 0) { tzmin = (box.min.z - origin3.z) * invdirz; tzmax = (box.max.z - origin3.z) * invdirz; } else { tzmin = (box.max.z - origin3.z) * invdirz; tzmax = (box.min.z - origin3.z) * invdirz; } if (tmin > tzmax || tzmin > tmax) return null; if (tzmin > tmin || tmin !== tmin) tmin = tzmin; if (tzmax < tmax || tmax !== tmax) tmax = tzmax; if (tmax < 0) return null; return this.at(tmin >= 0 ? tmin : tmax, target); } intersectsBox(box) { return this.intersectBox(box, _vector$9) !== null; } intersectTriangle(a2, b, c2, backfaceCulling, target) { _edge1.subVectors(b, a2); _edge2.subVectors(c2, a2); _normal$1.crossVectors(_edge1, _edge2); let DdN = this.direction.dot(_normal$1); let sign; if (DdN > 0) { if (backfaceCulling) return null; sign = 1; } else if (DdN < 0) { sign = -1; DdN = -DdN; } else { return null; } _diff.subVectors(this.origin, a2); const DdQxE2 = sign * this.direction.dot(_edge2.crossVectors(_diff, _edge2)); if (DdQxE2 < 0) { return null; } const DdE1xQ = sign * this.direction.dot(_edge1.cross(_diff)); if (DdE1xQ < 0) { return null; } if (DdQxE2 + DdE1xQ > DdN) { return null; } const QdN = -sign * _diff.dot(_normal$1); if (QdN < 0) { return null; } return this.at(QdN / DdN, target); } applyMatrix4(matrix4) { this.origin.applyMatrix4(matrix4); this.direction.transformDirection(matrix4); return this; } equals(ray) { return ray.origin.equals(this.origin) && ray.direction.equals(this.direction); } clone() { return new this.constructor().copy(this); } }; var Matrix4 = class { constructor(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) { Matrix4.prototype.isMatrix4 = true; this.elements = [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]; if (n11 !== void 0) { this.set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44); } } set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) { const te = this.elements; te[0] = n11; te[4] = n12; te[8] = n13; te[12] = n14; te[1] = n21; te[5] = n22; te[9] = n23; te[13] = n24; te[2] = n31; te[6] = n32; te[10] = n33; te[14] = n34; te[3] = n41; te[7] = n42; te[11] = n43; te[15] = n44; return this; } identity() { this.set( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ); return this; } clone() { return new Matrix4().fromArray(this.elements); } copy(m2) { const te = this.elements; const me = m2.elements; te[0] = me[0]; te[1] = me[1]; te[2] = me[2]; te[3] = me[3]; te[4] = me[4]; te[5] = me[5]; te[6] = me[6]; te[7] = me[7]; te[8] = me[8]; te[9] = me[9]; te[10] = me[10]; te[11] = me[11]; te[12] = me[12]; te[13] = me[13]; te[14] = me[14]; te[15] = me[15]; return this; } copyPosition(m2) { const te = this.elements, me = m2.elements; te[12] = me[12]; te[13] = me[13]; te[14] = me[14]; return this; } setFromMatrix3(m2) { const me = m2.elements; this.set( me[0], me[3], me[6], 0, me[1], me[4], me[7], 0, me[2], me[5], me[8], 0, 0, 0, 0, 1 ); return this; } extractBasis(xAxis, yAxis, zAxis) { xAxis.setFromMatrixColumn(this, 0); yAxis.setFromMatrixColumn(this, 1); zAxis.setFromMatrixColumn(this, 2); return this; } makeBasis(xAxis, yAxis, zAxis) { this.set( xAxis.x, yAxis.x, zAxis.x, 0, xAxis.y, yAxis.y, zAxis.y, 0, xAxis.z, yAxis.z, zAxis.z, 0, 0, 0, 0, 1 ); return this; } extractRotation(m2) { const te = this.elements; const me = m2.elements; const scaleX = 1 / _v1$5.setFromMatrixColumn(m2, 0).length(); const scaleY = 1 / _v1$5.setFromMatrixColumn(m2, 1).length(); const scaleZ = 1 / _v1$5.setFromMatrixColumn(m2, 2).length(); te[0] = me[0] * scaleX; te[1] = me[1] * scaleX; te[2] = me[2] * scaleX; te[3] = 0; te[4] = me[4] * scaleY; te[5] = me[5] * scaleY; te[6] = me[6] * scaleY; te[7] = 0; te[8] = me[8] * scaleZ; te[9] = me[9] * scaleZ; te[10] = me[10] * scaleZ; te[11] = 0; te[12] = 0; te[13] = 0; te[14] = 0; te[15] = 1; return this; } makeRotationFromEuler(euler) { const te = this.elements; const x3 = euler.x, y3 = euler.y, z4 = euler.z; const a2 = Math.cos(x3), b = Math.sin(x3); const c2 = Math.cos(y3), d = Math.sin(y3); const e = Math.cos(z4), f = Math.sin(z4); if (euler.order === "XYZ") { const ae = a2 * e, af = a2 * f, be = b * e, bf = b * f; te[0] = c2 * e; te[4] = -c2 * f; te[8] = d; te[1] = af + be * d; te[5] = ae - bf * d; te[9] = -b * c2; te[2] = bf - ae * d; te[6] = be + af * d; te[10] = a2 * c2; } else if (euler.order === "YXZ") { const ce = c2 * e, cf = c2 * f, de = d * e, df = d * f; te[0] = ce + df * b; te[4] = de * b - cf; te[8] = a2 * d; te[1] = a2 * f; te[5] = a2 * e; te[9] = -b; te[2] = cf * b - de; te[6] = df + ce * b; te[10] = a2 * c2; } else if (euler.order === "ZXY") { const ce = c2 * e, cf = c2 * f, de = d * e, df = d * f; te[0] = ce - df * b; te[4] = -a2 * f; te[8] = de + cf * b; te[1] = cf + de * b; te[5] = a2 * e; te[9] = df - ce * b; te[2] = -a2 * d; te[6] = b; te[10] = a2 * c2; } else if (euler.order === "ZYX") { const ae = a2 * e, af = a2 * f, be = b * e, bf = b * f; te[0] = c2 * e; te[4] = be * d - af; te[8] = ae * d + bf; te[1] = c2 * f; te[5] = bf * d + ae; te[9] = af * d - be; te[2] = -d; te[6] = b * c2; te[10] = a2 * c2; } else if (euler.order === "YZX") { const ac = a2 * c2, ad = a2 * d, bc = b * c2, bd = b * d; te[0] = c2 * e; te[4] = bd - ac * f; te[8] = bc * f + ad; te[1] = f; te[5] = a2 * e; te[9] = -b * e; te[2] = -d * e; te[6] = ad * f + bc; te[10] = ac - bd * f; } else if (euler.order === "XZY") { const ac = a2 * c2, ad = a2 * d, bc = b * c2, bd = b * d; te[0] = c2 * e; te[4] = -f; te[8] = d * e; te[1] = ac * f + bd; te[5] = a2 * e; te[9] = ad * f - bc; te[2] = bc * f - ad; te[6] = b * e; te[10] = bd * f + ac; } te[3] = 0; te[7] = 0; te[11] = 0; te[12] = 0; te[13] = 0; te[14] = 0; te[15] = 1; return this; } makeRotationFromQuaternion(q) { return this.compose(_zero, q, _one); } lookAt(eye, target, up) { const te = this.elements; _z.subVectors(eye, target); if (_z.lengthSq() === 0) { _z.z = 1; } _z.normalize(); _x.crossVectors(up, _z); if (_x.lengthSq() === 0) { if (Math.abs(up.z) === 1) { _z.x += 1e-4; } else { _z.z += 1e-4; } _z.normalize(); _x.crossVectors(up, _z); } _x.normalize(); _y.crossVectors(_z, _x); te[0] = _x.x; te[4] = _y.x; te[8] = _z.x; te[1] = _x.y; te[5] = _y.y; te[9] = _z.y; te[2] = _x.z; te[6] = _y.z; te[10] = _z.z; return this; } multiply(m2) { return this.multiplyMatrices(this, m2); } premultiply(m2) { return this.multiplyMatrices(m2, this); } multiplyMatrices(a2, b) { const ae = a2.elements; const be = b.elements; const te = this.elements; const a11 = ae[0], a12 = ae[4], a13 = ae[8], a14 = ae[12]; const a21 = ae[1], a22 = ae[5], a23 = ae[9], a24 = ae[13]; const a31 = ae[2], a32 = ae[6], a33 = ae[10], a34 = ae[14]; const a41 = ae[3], a42 = ae[7], a43 = ae[11], a44 = ae[15]; const b11 = be[0], b12 = be[4], b13 = be[8], b14 = be[12]; const b21 = be[1], b22 = be[5], b23 = be[9], b24 = be[13]; const b31 = be[2], b32 = be[6], b33 = be[10], b34 = be[14]; const b41 = be[3], b42 = be[7], b43 = be[11], b44 = be[15]; te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41; te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42; te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43; te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44; te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41; te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42; te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43; te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44; te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41; te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42; te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43; te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44; te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41; te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42; te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43; te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44; return this; } multiplyScalar(s) { const te = this.elements; te[0] *= s; te[4] *= s; te[8] *= s; te[12] *= s; te[1] *= s; te[5] *= s; te[9] *= s; te[13] *= s; te[2] *= s; te[6] *= s; te[10] *= s; te[14] *= s; te[3] *= s; te[7] *= s; te[11] *= s; te[15] *= s; return this; } determinant() { const te = this.elements; const n11 = te[0], n12 = te[4], n13 = te[8], n14 = te[12]; const n21 = te[1], n22 = te[5], n23 = te[9], n24 = te[13]; const n31 = te[2], n32 = te[6], n33 = te[10], n34 = te[14]; const n41 = te[3], n42 = te[7], n43 = te[11], n44 = te[15]; return n41 * (+n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34) + n42 * (+n11 * n23 * n34 - n11 * n24 * n33 + n14 * n21 * n33 - n13 * n21 * n34 + n13 * n24 * n31 - n14 * n23 * n31) + n43 * (+n11 * n24 * n32 - n11 * n22 * n34 - n14 * n21 * n32 + n12 * n21 * n34 + n14 * n22 * n31 - n12 * n24 * n31) + n44 * (-n13 * n22 * n31 - n11 * n23 * n32 + n11 * n22 * n33 + n13 * n21 * n32 - n12 * n21 * n33 + n12 * n23 * n31); } transpose() { const te = this.elements; let tmp2; tmp2 = te[1]; te[1] = te[4]; te[4] = tmp2; tmp2 = te[2]; te[2] = te[8]; te[8] = tmp2; tmp2 = te[6]; te[6] = te[9]; te[9] = tmp2; tmp2 = te[3]; te[3] = te[12]; te[12] = tmp2; tmp2 = te[7]; te[7] = te[13]; te[13] = tmp2; tmp2 = te[11]; te[11] = te[14]; te[14] = tmp2; return this; } setPosition(x3, y3, z4) { const te = this.elements; if (x3.isVector3) { te[12] = x3.x; te[13] = x3.y; te[14] = x3.z; } else { te[12] = x3; te[13] = y3; te[14] = z4; } return this; } invert() { const te = this.elements, n11 = te[0], n21 = te[1], n31 = te[2], n41 = te[3], n12 = te[4], n22 = te[5], n32 = te[6], n42 = te[7], n13 = te[8], n23 = te[9], n33 = te[10], n43 = te[11], n14 = te[12], n24 = te[13], n34 = te[14], n44 = te[15], t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44, t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44, t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44, t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34; const det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14; if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); const detInv = 1 / det; te[0] = t11 * detInv; te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv; te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv; te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv; te[4] = t12 * detInv; te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv; te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv; te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv; te[8] = t13 * detInv; te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv; te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv; te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv; te[12] = t14 * detInv; te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv; te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv; te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv; return this; } scale(v) { const te = this.elements; const x3 = v.x, y3 = v.y, z4 = v.z; te[0] *= x3; te[4] *= y3; te[8] *= z4; te[1] *= x3; te[5] *= y3; te[9] *= z4; te[2] *= x3; te[6] *= y3; te[10] *= z4; te[3] *= x3; te[7] *= y3; te[11] *= z4; return this; } getMaxScaleOnAxis() { const te = this.elements; const scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2]; const scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6]; const scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10]; return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq)); } makeTranslation(x3, y3, z4) { if (x3.isVector3) { this.set( 1, 0, 0, x3.x, 0, 1, 0, x3.y, 0, 0, 1, x3.z, 0, 0, 0, 1 ); } else { this.set( 1, 0, 0, x3, 0, 1, 0, y3, 0, 0, 1, z4, 0, 0, 0, 1 ); } return this; } makeRotationX(theta) { const c2 = Math.cos(theta), s = Math.sin(theta); this.set( 1, 0, 0, 0, 0, c2, -s, 0, 0, s, c2, 0, 0, 0, 0, 1 ); return this; } makeRotationY(theta) { const c2 = Math.cos(theta), s = Math.sin(theta); this.set( c2, 0, s, 0, 0, 1, 0, 0, -s, 0, c2, 0, 0, 0, 0, 1 ); return this; } makeRotationZ(theta) { const c2 = Math.cos(theta), s = Math.sin(theta); this.set( c2, -s, 0, 0, s, c2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ); return this; } makeRotationAxis(axis, angle) { const c2 = Math.cos(angle); const s = Math.sin(angle); const t = 1 - c2; const x3 = axis.x, y3 = axis.y, z4 = axis.z; const tx = t * x3, ty = t * y3; this.set( tx * x3 + c2, tx * y3 - s * z4, tx * z4 + s * y3, 0, tx * y3 + s * z4, ty * y3 + c2, ty * z4 - s * x3, 0, tx * z4 - s * y3, ty * z4 + s * x3, t * z4 * z4 + c2, 0, 0, 0, 0, 1 ); return this; } makeScale(x3, y3, z4) { this.set( x3, 0, 0, 0, 0, y3, 0, 0, 0, 0, z4, 0, 0, 0, 0, 1 ); return this; } makeShear(xy, xz, yx, yz, zx, zy) { this.set( 1, yx, zx, 0, xy, 1, zy, 0, xz, yz, 1, 0, 0, 0, 0, 1 ); return this; } compose(position, quaternion, scale) { const te = this.elements; const x3 = quaternion._x, y3 = quaternion._y, z4 = quaternion._z, w = quaternion._w; const x22 = x3 + x3, y22 = y3 + y3, z22 = z4 + z4; const xx = x3 * x22, xy = x3 * y22, xz = x3 * z22; const yy = y3 * y22, yz = y3 * z22, zz = z4 * z22; const wx = w * x22, wy = w * y22, wz = w * z22; const sx = scale.x, sy = scale.y, sz = scale.z; te[0] = (1 - (yy + zz)) * sx; te[1] = (xy + wz) * sx; te[2] = (xz - wy) * sx; te[3] = 0; te[4] = (xy - wz) * sy; te[5] = (1 - (xx + zz)) * sy; te[6] = (yz + wx) * sy; te[7] = 0; te[8] = (xz + wy) * sz; te[9] = (yz - wx) * sz; te[10] = (1 - (xx + yy)) * sz; te[11] = 0; te[12] = position.x; te[13] = position.y; te[14] = position.z; te[15] = 1; return this; } decompose(position, quaternion, scale) { const te = this.elements; let sx = _v1$5.set(te[0], te[1], te[2]).length(); const sy = _v1$5.set(te[4], te[5], te[6]).length(); const sz = _v1$5.set(te[8], te[9], te[10]).length(); const det = this.determinant(); if (det < 0) sx = -sx; position.x = te[12]; position.y = te[13]; position.z = te[14]; _m1$2.copy(this); const invSX = 1 / sx; const invSY = 1 / sy; const invSZ = 1 / sz; _m1$2.elements[0] *= invSX; _m1$2.elements[1] *= invSX; _m1$2.elements[2] *= invSX; _m1$2.elements[4] *= invSY; _m1$2.elements[5] *= invSY; _m1$2.elements[6] *= invSY; _m1$2.elements[8] *= invSZ; _m1$2.elements[9] *= invSZ; _m1$2.elements[10] *= invSZ; quaternion.setFromRotationMatrix(_m1$2); scale.x = sx; scale.y = sy; scale.z = sz; return this; } makePerspective(left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem) { const te = this.elements; const x3 = 2 * near / (right - left); const y3 = 2 * near / (top - bottom); const a2 = (right + left) / (right - left); const b = (top + bottom) / (top - bottom); let c2, d; if (coordinateSystem === WebGLCoordinateSystem) { c2 = -(far + near) / (far - near); d = -2 * far * near / (far - near); } else if (coordinateSystem === WebGPUCoordinateSystem) { c2 = -far / (far - near); d = -far * near / (far - near); } else { throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: " + coordinateSystem); } te[0] = x3; te[4] = 0; te[8] = a2; te[12] = 0; te[1] = 0; te[5] = y3; te[9] = b; te[13] = 0; te[2] = 0; te[6] = 0; te[10] = c2; te[14] = d; te[3] = 0; te[7] = 0; te[11] = -1; te[15] = 0; return this; } makeOrthographic(left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem) { const te = this.elements; const w = 1 / (right - left); const h = 1 / (top - bottom); const p = 1 / (far - near); const x3 = (right + left) * w; const y3 = (top + bottom) * h; let z4, zInv; if (coordinateSystem === WebGLCoordinateSystem) { z4 = (far + near) * p; zInv = -2 * p; } else if (coordinateSystem === WebGPUCoordinateSystem) { z4 = near * p; zInv = -1 * p; } else { throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: " + coordinateSystem); } te[0] = 2 * w; te[4] = 0; te[8] = 0; te[12] = -x3; te[1] = 0; te[5] = 2 * h; te[9] = 0; te[13] = -y3; te[2] = 0; te[6] = 0; te[10] = zInv; te[14] = -z4; te[3] = 0; te[7] = 0; te[11] = 0; te[15] = 1; return this; } equals(matrix) { const te = this.elements; const me = matrix.elements; for (let i = 0; i < 16; i++) { if (te[i] !== me[i]) return false; } return true; } fromArray(array, offset = 0) { for (let i = 0; i < 16; i++) { this.elements[i] = array[i + offset]; } return this; } toArray(array = [], offset = 0) { const te = this.elements; array[offset] = te[0]; array[offset + 1] = te[1]; array[offset + 2] = te[2]; array[offset + 3] = te[3]; array[offset + 4] = te[4]; array[offset + 5] = te[5]; array[offset + 6] = te[6]; array[offset + 7] = te[7]; array[offset + 8] = te[8]; array[offset + 9] = te[9]; array[offset + 10] = te[10]; array[offset + 11] = te[11]; array[offset + 12] = te[12]; array[offset + 13] = te[13]; array[offset + 14] = te[14]; array[offset + 15] = te[15]; return array; } }; var _v1$5 = /* @__PURE__ */ new Vector3(); var _m1$2 = /* @__PURE__ */ new Matrix4(); var _zero = /* @__PURE__ */ new Vector3(0, 0, 0); var _one = /* @__PURE__ */ new Vector3(1, 1, 1); var _x = /* @__PURE__ */ new Vector3(); var _y = /* @__PURE__ */ new Vector3(); var _z = /* @__PURE__ */ new Vector3(); var _matrix = /* @__PURE__ */ new Matrix4(); var _quaternion$3 = /* @__PURE__ */ new Quaternion(); var Euler = class { constructor(x3 = 0, y3 = 0, z4 = 0, order = Euler.DEFAULT_ORDER) { this.isEuler = true; this._x = x3; this._y = y3; this._z = z4; this._order = order; } get x() { return this._x; } set x(value) { this._x = value; this._onChangeCallback(); } get y() { return this._y; } set y(value) { this._y = value; this._onChangeCallback(); } get z() { return this._z; } set z(value) { this._z = value; this._onChangeCallback(); } get order() { return this._order; } set order(value) { this._order = value; this._onChangeCallback(); } set(x3, y3, z4, order = this._order) { this._x = x3; this._y = y3; this._z = z4; this._order = order; this._onChangeCallback(); return this; } clone() { return new this.constructor(this._x, this._y, this._z, this._order); } copy(euler) { this._x = euler._x; this._y = euler._y; this._z = euler._z; this._order = euler._order; this._onChangeCallback(); return this; } setFromRotationMatrix(m2, order = this._order, update4 = true) { const te = m2.elements; const m11 = te[0], m12 = te[4], m13 = te[8]; const m21 = te[1], m22 = te[5], m23 = te[9]; const m31 = te[2], m32 = te[6], m33 = te[10]; switch (order) { case "XYZ": this._y = Math.asin(clamp(m13, -1, 1)); if (Math.abs(m13) < 0.9999999) { this._x = Math.atan2(-m23, m33); this._z = Math.atan2(-m12, m11); } else { this._x = Math.atan2(m32, m22); this._z = 0; } break; case "YXZ": this._x = Math.asin(-clamp(m23, -1, 1)); if (Math.abs(m23) < 0.9999999) { this._y = Math.atan2(m13, m33); this._z = Math.atan2(m21, m22); } else { this._y = Math.atan2(-m31, m11); this._z = 0; } break; case "ZXY": this._x = Math.asin(clamp(m32, -1, 1)); if (Math.abs(m32) < 0.9999999) { this._y = Math.atan2(-m31, m33); this._z = Math.atan2(-m12, m22); } else { this._y = 0; this._z = Math.atan2(m21, m11); } break; case "ZYX": this._y = Math.asin(-clamp(m31, -1, 1)); if (Math.abs(m31) < 0.9999999) { this._x = Math.atan2(m32, m33); this._z = Math.atan2(m21, m11); } else { this._x = 0; this._z = Math.atan2(-m12, m22); } break; case "YZX": this._z = Math.asin(clamp(m21, -1, 1)); if (Math.abs(m21) < 0.9999999) { this._x = Math.atan2(-m23, m22); this._y = Math.atan2(-m31, m11); } else { this._x = 0; this._y = Math.atan2(m13, m33); } break; case "XZY": this._z = Math.asin(-clamp(m12, -1, 1)); if (Math.abs(m12) < 0.9999999) { this._x = Math.atan2(m32, m22); this._y = Math.atan2(m13, m11); } else { this._x = Math.atan2(-m23, m33); this._y = 0; } break; default: console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: " + order); } this._order = order; if (update4 === true) this._onChangeCallback(); return this; } setFromQuaternion(q, order, update4) { _matrix.makeRotationFromQuaternion(q); return this.setFromRotationMatrix(_matrix, order, update4); } setFromVector3(v, order = this._order) { return this.set(v.x, v.y, v.z, order); } reorder(newOrder) { _quaternion$3.setFromEuler(this); return this.setFromQuaternion(_quaternion$3, newOrder); } equals(euler) { return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order; } fromArray(array) { this._x = array[0]; this._y = array[1]; this._z = array[2]; if (array[3] !== void 0) this._order = array[3]; this._onChangeCallback(); return this; } toArray(array = [], offset = 0) { array[offset] = this._x; array[offset + 1] = this._y; array[offset + 2] = this._z; array[offset + 3] = this._order; return array; } _onChange(callback) { this._onChangeCallback = callback; return this; } _onChangeCallback() { } *[Symbol.iterator]() { yield this._x; yield this._y; yield this._z; yield this._order; } }; Euler.DEFAULT_ORDER = "XYZ"; var Layers = class { constructor() { this.mask = 1 | 0; } set(channel) { this.mask = (1 << channel | 0) >>> 0; } enable(channel) { this.mask |= 1 << channel | 0; } enableAll() { this.mask = 4294967295 | 0; } toggle(channel) { this.mask ^= 1 << channel | 0; } disable(channel) { this.mask &= ~(1 << channel | 0); } disableAll() { this.mask = 0; } test(layers) { return (this.mask & layers.mask) !== 0; } isEnabled(channel) { return (this.mask & (1 << channel | 0)) !== 0; } }; var _object3DId = 0; var _v1$4 = /* @__PURE__ */ new Vector3(); var _q1 = /* @__PURE__ */ new Quaternion(); var _m1$1 = /* @__PURE__ */ new Matrix4(); var _target = /* @__PURE__ */ new Vector3(); var _position$3 = /* @__PURE__ */ new Vector3(); var _scale$2 = /* @__PURE__ */ new Vector3(); var _quaternion$2 = /* @__PURE__ */ new Quaternion(); var _xAxis = /* @__PURE__ */ new Vector3(1, 0, 0); var _yAxis = /* @__PURE__ */ new Vector3(0, 1, 0); var _zAxis = /* @__PURE__ */ new Vector3(0, 0, 1); var _addedEvent = { type: "added" }; var _removedEvent = { type: "removed" }; var Object3D = class extends EventDispatcher { constructor() { super(); this.isObject3D = true; Object.defineProperty(this, "id", { value: _object3DId++ }); this.uuid = generateUUID(); this.name = ""; this.type = "Object3D"; this.parent = null; this.children = []; this.up = Object3D.DEFAULT_UP.clone(); const position = new Vector3(); const rotation = new Euler(); const quaternion = new Quaternion(); const scale = new Vector3(1, 1, 1); function onRotationChange() { quaternion.setFromEuler(rotation, false); } function onQuaternionChange() { rotation.setFromQuaternion(quaternion, void 0, false); } rotation._onChange(onRotationChange); quaternion._onChange(onQuaternionChange); Object.defineProperties(this, { position: { configurable: true, enumerable: true, value: position }, rotation: { configurable: true, enumerable: true, value: rotation }, quaternion: { configurable: true, enumerable: true, value: quaternion }, scale: { configurable: true, enumerable: true, value: scale }, modelViewMatrix: { value: new Matrix4() }, normalMatrix: { value: new Matrix3() } }); this.matrix = new Matrix4(); this.matrixWorld = new Matrix4(); this.matrixAutoUpdate = Object3D.DEFAULT_MATRIX_AUTO_UPDATE; this.matrixWorldNeedsUpdate = false; this.matrixWorldAutoUpdate = Object3D.DEFAULT_MATRIX_WORLD_AUTO_UPDATE; this.layers = new Layers(); this.visible = true; this.castShadow = false; this.receiveShadow = false; this.frustumCulled = true; this.renderOrder = 0; this.animations = []; this.userData = {}; } onBeforeRender() { } onAfterRender() { } applyMatrix4(matrix) { if (this.matrixAutoUpdate) this.updateMatrix(); this.matrix.premultiply(matrix); this.matrix.decompose(this.position, this.quaternion, this.scale); } applyQuaternion(q) { this.quaternion.premultiply(q); return this; } setRotationFromAxisAngle(axis, angle) { this.quaternion.setFromAxisAngle(axis, angle); } setRotationFromEuler(euler) { this.quaternion.setFromEuler(euler, true); } setRotationFromMatrix(m2) { this.quaternion.setFromRotationMatrix(m2); } setRotationFromQuaternion(q) { this.quaternion.copy(q); } rotateOnAxis(axis, angle) { _q1.setFromAxisAngle(axis, angle); this.quaternion.multiply(_q1); return this; } rotateOnWorldAxis(axis, angle) { _q1.setFromAxisAngle(axis, angle); this.quaternion.premultiply(_q1); return this; } rotateX(angle) { return this.rotateOnAxis(_xAxis, angle); } rotateY(angle) { return this.rotateOnAxis(_yAxis, angle); } rotateZ(angle) { return this.rotateOnAxis(_zAxis, angle); } translateOnAxis(axis, distance) { _v1$4.copy(axis).applyQuaternion(this.quaternion); this.position.add(_v1$4.multiplyScalar(distance)); return this; } translateX(distance) { return this.translateOnAxis(_xAxis, distance); } translateY(distance) { return this.translateOnAxis(_yAxis, distance); } translateZ(distance) { return this.translateOnAxis(_zAxis, distance); } localToWorld(vector) { this.updateWorldMatrix(true, false); return vector.applyMatrix4(this.matrixWorld); } worldToLocal(vector) { this.updateWorldMatrix(true, false); return vector.applyMatrix4(_m1$1.copy(this.matrixWorld).invert()); } lookAt(x3, y3, z4) { if (x3.isVector3) { _target.copy(x3); } else { _target.set(x3, y3, z4); } const parent = this.parent; this.updateWorldMatrix(true, false); _position$3.setFromMatrixPosition(this.matrixWorld); if (this.isCamera || this.isLight) { _m1$1.lookAt(_position$3, _target, this.up); } else { _m1$1.lookAt(_target, _position$3, this.up); } this.quaternion.setFromRotationMatrix(_m1$1); if (parent) { _m1$1.extractRotation(parent.matrixWorld); _q1.setFromRotationMatrix(_m1$1); this.quaternion.premultiply(_q1.invert()); } } add(object) { if (arguments.length > 1) { for (let i = 0; i < arguments.length; i++) { this.add(arguments[i]); } return this; } if (object === this) { console.error("THREE.Object3D.add: object can't be added as a child of itself.", object); return this; } if (object && object.isObject3D) { if (object.parent !== null) { object.parent.remove(object); } object.parent = this; this.children.push(object); object.dispatchEvent(_addedEvent); } else { console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.", object); } return this; } remove(object) { if (arguments.length > 1) { for (let i = 0; i < arguments.length; i++) { this.remove(arguments[i]); } return this; } const index6 = this.children.indexOf(object); if (index6 !== -1) { object.parent = null; this.children.splice(index6, 1); object.dispatchEvent(_removedEvent); } return this; } removeFromParent() { const parent = this.parent; if (parent !== null) { parent.remove(this); } return this; } clear() { return this.remove(...this.children); } attach(object) { this.updateWorldMatrix(true, false); _m1$1.copy(this.matrixWorld).invert(); if (object.parent !== null) { object.parent.updateWorldMatrix(true, false); _m1$1.multiply(object.parent.matrixWorld); } object.applyMatrix4(_m1$1); this.add(object); object.updateWorldMatrix(false, true); return this; } getObjectById(id) { return this.getObjectByProperty("id", id); } getObjectByName(name) { return this.getObjectByProperty("name", name); } getObjectByProperty(name, value) { if (this[name] === value) return this; for (let i = 0, l = this.children.length; i < l; i++) { const child = this.children[i]; const object = child.getObjectByProperty(name, value); if (object !== void 0) { return object; } } return void 0; } getObjectsByProperty(name, value) { let result = []; if (this[name] === value) result.push(this); for (let i = 0, l = this.children.length; i < l; i++) { const childResult = this.children[i].getObjectsByProperty(name, value); if (childResult.length > 0) { result = result.concat(childResult); } } return result; } getWorldPosition(target) { this.updateWorldMatrix(true, false); return target.setFromMatrixPosition(this.matrixWorld); } getWorldQuaternion(target) { this.updateWorldMatrix(true, false); this.matrixWorld.decompose(_position$3, target, _scale$2); return target; } getWorldScale(target) { this.updateWorldMatrix(true, false); this.matrixWorld.decompose(_position$3, _quaternion$2, target); return target; } getWorldDirection(target) { this.updateWorldMatrix(true, false); const e = this.matrixWorld.elements; return target.set(e[8], e[9], e[10]).normalize(); } raycast() { } traverse(callback) { callback(this); const children = this.children; for (let i = 0, l = children.length; i < l; i++) { children[i].traverse(callback); } } traverseVisible(callback) { if (this.visible === false) return; callback(this); const children = this.children; for (let i = 0, l = children.length; i < l; i++) { children[i].traverseVisible(callback); } } traverseAncestors(callback) { const parent = this.parent; if (parent !== null) { callback(parent); parent.traverseAncestors(callback); } } updateMatrix() { this.matrix.compose(this.position, this.quaternion, this.scale); this.matrixWorldNeedsUpdate = true; } updateMatrixWorld(force) { if (this.matrixAutoUpdate) this.updateMatrix(); if (this.matrixWorldNeedsUpdate || force) { if (this.parent === null) { this.matrixWorld.copy(this.matrix); } else { this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix); } this.matrixWorldNeedsUpdate = false; force = true; } const children = this.children; for (let i = 0, l = children.length; i < l; i++) { const child = children[i]; if (child.matrixWorldAutoUpdate === true || force === true) { child.updateMatrixWorld(force); } } } updateWorldMatrix(updateParents, updateChildren) { const parent = this.parent; if (updateParents === true && parent !== null && parent.matrixWorldAutoUpdate === true) { parent.updateWorldMatrix(true, false); } if (this.matrixAutoUpdate) this.updateMatrix(); if (this.parent === null) { this.matrixWorld.copy(this.matrix); } else { this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix); } if (updateChildren === true) { const children = this.children; for (let i = 0, l = children.length; i < l; i++) { const child = children[i]; if (child.matrixWorldAutoUpdate === true) { child.updateWorldMatrix(false, true); } } } } toJSON(meta) { const isRootObject = meta === void 0 || typeof meta === "string"; const output = {}; if (isRootObject) { meta = { geometries: {}, materials: {}, textures: {}, images: {}, shapes: {}, skeletons: {}, animations: {}, nodes: {} }; output.metadata = { version: 4.6, type: "Object", generator: "Object3D.toJSON" }; } const object = {}; object.uuid = this.uuid; object.type = this.type; if (this.name !== "") object.name = this.name; if (this.castShadow === true) object.castShadow = true; if (this.receiveShadow === true) object.receiveShadow = true; if (this.visible === false) object.visible = false; if (this.frustumCulled === false) object.frustumCulled = false; if (this.renderOrder !== 0) object.renderOrder = this.renderOrder; if (Object.keys(this.userData).length > 0) object.userData = this.userData; object.layers = this.layers.mask; object.matrix = this.matrix.toArray(); object.up = this.up.toArray(); if (this.matrixAutoUpdate === false) object.matrixAutoUpdate = false; if (this.isInstancedMesh) { object.type = "InstancedMesh"; object.count = this.count; object.instanceMatrix = this.instanceMatrix.toJSON(); if (this.instanceColor !== null) object.instanceColor = this.instanceColor.toJSON(); } function serialize(library, element) { if (library[element.uuid] === void 0) { library[element.uuid] = element.toJSON(meta); } return element.uuid; } if (this.isScene) { if (this.background) { if (this.background.isColor) { object.background = this.background.toJSON(); } else if (this.background.isTexture) { object.background = this.background.toJSON(meta).uuid; } } if (this.environment && this.environment.isTexture && this.environment.isRenderTargetTexture !== true) { object.environment = this.environment.toJSON(meta).uuid; } } else if (this.isMesh || this.isLine || this.isPoints) { object.geometry = serialize(meta.geometries, this.geometry); const parameters = this.geometry.parameters; if (parameters !== void 0 && parameters.shapes !== void 0) { const shapes = parameters.shapes; if (Array.isArray(shapes)) { for (let i = 0, l = shapes.length; i < l; i++) { const shape = shapes[i]; serialize(meta.shapes, shape); } } else { serialize(meta.shapes, shapes); } } } if (this.isSkinnedMesh) { object.bindMode = this.bindMode; object.bindMatrix = this.bindMatrix.toArray(); if (this.skeleton !== void 0) { serialize(meta.skeletons, this.skeleton); object.skeleton = this.skeleton.uuid; } } if (this.material !== void 0) { if (Array.isArray(this.material)) { const uuids = []; for (let i = 0, l = this.material.length; i < l; i++) { uuids.push(serialize(meta.materials, this.material[i])); } object.material = uuids; } else { object.material = serialize(meta.materials, this.material); } } if (this.children.length > 0) { object.children = []; for (let i = 0; i < this.children.length; i++) { object.children.push(this.children[i].toJSON(meta).object); } } if (this.animations.length > 0) { object.animations = []; for (let i = 0; i < this.animations.length; i++) { const animation = this.animations[i]; object.animations.push(serialize(meta.animations, animation)); } } if (isRootObject) { const geometries = extractFromCache(meta.geometries); const materials = extractFromCache(meta.materials); const textures = extractFromCache(meta.textures); const images = extractFromCache(meta.images); const shapes = extractFromCache(meta.shapes); const skeletons = extractFromCache(meta.skeletons); const animations = extractFromCache(meta.animations); const nodes = extractFromCache(meta.nodes); if (geometries.length > 0) output.geometries = geometries; if (materials.length > 0) output.materials = materials; if (textures.length > 0) output.textures = textures; if (images.length > 0) output.images = images; if (shapes.length > 0) output.shapes = shapes; if (skeletons.length > 0) output.skeletons = skeletons; if (animations.length > 0) output.animations = animations; if (nodes.length > 0) output.nodes = nodes; } output.object = object; return output; function extractFromCache(cache) { const values = []; for (const key in cache) { const data = cache[key]; delete data.metadata; values.push(data); } return values; } } clone(recursive) { return new this.constructor().copy(this, recursive); } copy(source, recursive = true) { this.name = source.name; this.up.copy(source.up); this.position.copy(source.position); this.rotation.order = source.rotation.order; this.quaternion.copy(source.quaternion); this.scale.copy(source.scale); this.matrix.copy(source.matrix); this.matrixWorld.copy(source.matrixWorld); this.matrixAutoUpdate = source.matrixAutoUpdate; this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate; this.matrixWorldAutoUpdate = source.matrixWorldAutoUpdate; this.layers.mask = source.layers.mask; this.visible = source.visible; this.castShadow = source.castShadow; this.receiveShadow = source.receiveShadow; this.frustumCulled = source.frustumCulled; this.renderOrder = source.renderOrder; this.animations = source.animations.slice(); this.userData = JSON.parse(JSON.stringify(source.userData)); if (recursive === true) { for (let i = 0; i < source.children.length; i++) { const child = source.children[i]; this.add(child.clone()); } } return this; } }; Object3D.DEFAULT_UP = /* @__PURE__ */ new Vector3(0, 1, 0); Object3D.DEFAULT_MATRIX_AUTO_UPDATE = true; Object3D.DEFAULT_MATRIX_WORLD_AUTO_UPDATE = true; var _v0$1 = /* @__PURE__ */ new Vector3(); var _v1$3 = /* @__PURE__ */ new Vector3(); var _v2$2 = /* @__PURE__ */ new Vector3(); var _v3$1 = /* @__PURE__ */ new Vector3(); var _vab = /* @__PURE__ */ new Vector3(); var _vac = /* @__PURE__ */ new Vector3(); var _vbc = /* @__PURE__ */ new Vector3(); var _vap = /* @__PURE__ */ new Vector3(); var _vbp = /* @__PURE__ */ new Vector3(); var _vcp = /* @__PURE__ */ new Vector3(); var warnedGetUV = false; var Triangle = class { constructor(a2 = new Vector3(), b = new Vector3(), c2 = new Vector3()) { this.a = a2; this.b = b; this.c = c2; } static getNormal(a2, b, c2, target) { target.subVectors(c2, b); _v0$1.subVectors(a2, b); target.cross(_v0$1); const targetLengthSq = target.lengthSq(); if (targetLengthSq > 0) { return target.multiplyScalar(1 / Math.sqrt(targetLengthSq)); } return target.set(0, 0, 0); } // static/instance method to calculate barycentric coordinates // based on: http://www.blackpawn.com/texts/pointinpoly/default.html static getBarycoord(point, a2, b, c2, target) { _v0$1.subVectors(c2, a2); _v1$3.subVectors(b, a2); _v2$2.subVectors(point, a2); const dot00 = _v0$1.dot(_v0$1); const dot01 = _v0$1.dot(_v1$3); const dot02 = _v0$1.dot(_v2$2); const dot11 = _v1$3.dot(_v1$3); const dot12 = _v1$3.dot(_v2$2); const denom = dot00 * dot11 - dot01 * dot01; if (denom === 0) { return target.set(-2, -1, -1); } const invDenom = 1 / denom; const u = (dot11 * dot02 - dot01 * dot12) * invDenom; const v = (dot00 * dot12 - dot01 * dot02) * invDenom; return target.set(1 - u - v, v, u); } static containsPoint(point, a2, b, c2) { this.getBarycoord(point, a2, b, c2, _v3$1); return _v3$1.x >= 0 && _v3$1.y >= 0 && _v3$1.x + _v3$1.y <= 1; } static getUV(point, p1, p2, p3, uv1, uv2, uv3, target) { if (warnedGetUV === false) { console.warn("THREE.Triangle.getUV() has been renamed to THREE.Triangle.getInterpolation()."); warnedGetUV = true; } return this.getInterpolation(point, p1, p2, p3, uv1, uv2, uv3, target); } static getInterpolation(point, p1, p2, p3, v1, v2, v3, target) { this.getBarycoord(point, p1, p2, p3, _v3$1); target.setScalar(0); target.addScaledVector(v1, _v3$1.x); target.addScaledVector(v2, _v3$1.y); target.addScaledVector(v3, _v3$1.z); return target; } static isFrontFacing(a2, b, c2, direction) { _v0$1.subVectors(c2, b); _v1$3.subVectors(a2, b); return _v0$1.cross(_v1$3).dot(direction) < 0 ? true : false; } set(a2, b, c2) { this.a.copy(a2); this.b.copy(b); this.c.copy(c2); return this; } setFromPointsAndIndices(points, i0, i1, i2) { this.a.copy(points[i0]); this.b.copy(points[i1]); this.c.copy(points[i2]); return this; } setFromAttributeAndIndices(attribute, i0, i1, i2) { this.a.fromBufferAttribute(attribute, i0); this.b.fromBufferAttribute(attribute, i1); this.c.fromBufferAttribute(attribute, i2); return this; } clone() { return new this.constructor().copy(this); } copy(triangle) { this.a.copy(triangle.a); this.b.copy(triangle.b); this.c.copy(triangle.c); return this; } getArea() { _v0$1.subVectors(this.c, this.b); _v1$3.subVectors(this.a, this.b); return _v0$1.cross(_v1$3).length() * 0.5; } getMidpoint(target) { return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3); } getNormal(target) { return Triangle.getNormal(this.a, this.b, this.c, target); } getPlane(target) { return target.setFromCoplanarPoints(this.a, this.b, this.c); } getBarycoord(point, target) { return Triangle.getBarycoord(point, this.a, this.b, this.c, target); } getUV(point, uv1, uv2, uv3, target) { if (warnedGetUV === false) { console.warn("THREE.Triangle.getUV() has been renamed to THREE.Triangle.getInterpolation()."); warnedGetUV = true; } return Triangle.getInterpolation(point, this.a, this.b, this.c, uv1, uv2, uv3, target); } getInterpolation(point, v1, v2, v3, target) { return Triangle.getInterpolation(point, this.a, this.b, this.c, v1, v2, v3, target); } containsPoint(point) { return Triangle.containsPoint(point, this.a, this.b, this.c); } isFrontFacing(direction) { return Triangle.isFrontFacing(this.a, this.b, this.c, direction); } intersectsBox(box) { return box.intersectsTriangle(this); } closestPointToPoint(p, target) { const a2 = this.a, b = this.b, c2 = this.c; let v, w; _vab.subVectors(b, a2); _vac.subVectors(c2, a2); _vap.subVectors(p, a2); const d1 = _vab.dot(_vap); const d2 = _vac.dot(_vap); if (d1 <= 0 && d2 <= 0) { return target.copy(a2); } _vbp.subVectors(p, b); const d3 = _vab.dot(_vbp); const d4 = _vac.dot(_vbp); if (d3 >= 0 && d4 <= d3) { return target.copy(b); } const vc = d1 * d4 - d3 * d2; if (vc <= 0 && d1 >= 0 && d3 <= 0) { v = d1 / (d1 - d3); return target.copy(a2).addScaledVector(_vab, v); } _vcp.subVectors(p, c2); const d5 = _vab.dot(_vcp); const d6 = _vac.dot(_vcp); if (d6 >= 0 && d5 <= d6) { return target.copy(c2); } const vb = d5 * d2 - d1 * d6; if (vb <= 0 && d2 >= 0 && d6 <= 0) { w = d2 / (d2 - d6); return target.copy(a2).addScaledVector(_vac, w); } const va = d3 * d6 - d5 * d4; if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) { _vbc.subVectors(c2, b); w = (d4 - d3) / (d4 - d3 + (d5 - d6)); return target.copy(b).addScaledVector(_vbc, w); } const denom = 1 / (va + vb + vc); v = vb * denom; w = vc * denom; return target.copy(a2).addScaledVector(_vab, v).addScaledVector(_vac, w); } equals(triangle) { return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c); } }; var _colorKeywords = { "aliceblue": 15792383, "antiquewhite": 16444375, "aqua": 65535, "aquamarine": 8388564, "azure": 15794175, "beige": 16119260, "bisque": 16770244, "black": 0, "blanchedalmond": 16772045, "blue": 255, "blueviolet": 9055202, "brown": 10824234, "burlywood": 14596231, "cadetblue": 6266528, "chartreuse": 8388352, "chocolate": 13789470, "coral": 16744272, "cornflowerblue": 6591981, "cornsilk": 16775388, "crimson": 14423100, "cyan": 65535, "darkblue": 139, "darkcyan": 35723, "darkgoldenrod": 12092939, "darkgray": 11119017, "darkgreen": 25600, "darkgrey": 11119017, "darkkhaki": 12433259, "darkmagenta": 9109643, "darkolivegreen": 5597999, "darkorange": 16747520, "darkorchid": 10040012, "darkred": 9109504, "darksalmon": 15308410, "darkseagreen": 9419919, "darkslateblue": 4734347, "darkslategray": 3100495, "darkslategrey": 3100495, "darkturquoise": 52945, "darkviolet": 9699539, "deeppink": 16716947, "deepskyblue": 49151, "dimgray": 6908265, "dimgrey": 6908265, "dodgerblue": 2003199, "firebrick": 11674146, "floralwhite": 16775920, "forestgreen": 2263842, "fuchsia": 16711935, "gainsboro": 14474460, "ghostwhite": 16316671, "gold": 16766720, "goldenrod": 14329120, "gray": 8421504, "green": 32768, "greenyellow": 11403055, "grey": 8421504, "honeydew": 15794160, "hotpink": 16738740, "indianred": 13458524, "indigo": 4915330, "ivory": 16777200, "khaki": 15787660, "lavender": 15132410, "lavenderblush": 16773365, "lawngreen": 8190976, "lemonchiffon": 16775885, "lightblue": 11393254, "lightcoral": 15761536, "lightcyan": 14745599, "lightgoldenrodyellow": 16448210, "lightgray": 13882323, "lightgreen": 9498256, "lightgrey": 13882323, "lightpink": 16758465, "lightsalmon": 16752762, "lightseagreen": 2142890, "lightskyblue": 8900346, "lightslategray": 7833753, "lightslategrey": 7833753, "lightsteelblue": 11584734, "lightyellow": 16777184, "lime": 65280, "limegreen": 3329330, "linen": 16445670, "magenta": 16711935, "maroon": 8388608, "mediumaquamarine": 6737322, "mediumblue": 205, "mediumorchid": 12211667, "mediumpurple": 9662683, "mediumseagreen": 3978097, "mediumslateblue": 8087790, "mediumspringgreen": 64154, "mediumturquoise": 4772300, "mediumvioletred": 13047173, "midnightblue": 1644912, "mintcream": 16121850, "mistyrose": 16770273, "moccasin": 16770229, "navajowhite": 16768685, "navy": 128, "oldlace": 16643558, "olive": 8421376, "olivedrab": 7048739, "orange": 16753920, "orangered": 16729344, "orchid": 14315734, "palegoldenrod": 15657130, "palegreen": 10025880, "paleturquoise": 11529966, "palevioletred": 14381203, "papayawhip": 16773077, "peachpuff": 16767673, "peru": 13468991, "pink": 16761035, "plum": 14524637, "powderblue": 11591910, "purple": 8388736, "rebeccapurple": 6697881, "red": 16711680, "rosybrown": 12357519, "royalblue": 4286945, "saddlebrown": 9127187, "salmon": 16416882, "sandybrown": 16032864, "seagreen": 3050327, "seashell": 16774638, "sienna": 10506797, "silver": 12632256, "skyblue": 8900331, "slateblue": 6970061, "slategray": 7372944, "slategrey": 7372944, "snow": 16775930, "springgreen": 65407, "steelblue": 4620980, "tan": 13808780, "teal": 32896, "thistle": 14204888, "tomato": 16737095, "turquoise": 4251856, "violet": 15631086, "wheat": 16113331, "white": 16777215, "whitesmoke": 16119285, "yellow": 16776960, "yellowgreen": 10145074 }; var _hslA = { h: 0, s: 0, l: 0 }; var _hslB = { h: 0, s: 0, l: 0 }; function hue2rgb(p, q, t) { if (t < 0) t += 1; if (t > 1) t -= 1; if (t < 1 / 6) return p + (q - p) * 6 * t; if (t < 1 / 2) return q; if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t); return p; } var Color = class { constructor(r, g, b) { this.isColor = true; this.r = 1; this.g = 1; this.b = 1; return this.set(r, g, b); } set(r, g, b) { if (g === void 0 && b === void 0) { const value = r; if (value && value.isColor) { this.copy(value); } else if (typeof value === "number") { this.setHex(value); } else if (typeof value === "string") { this.setStyle(value); } } else { this.setRGB(r, g, b); } return this; } setScalar(scalar) { this.r = scalar; this.g = scalar; this.b = scalar; return this; } setHex(hex, colorSpace = SRGBColorSpace) { hex = Math.floor(hex); this.r = (hex >> 16 & 255) / 255; this.g = (hex >> 8 & 255) / 255; this.b = (hex & 255) / 255; ColorManagement.toWorkingColorSpace(this, colorSpace); return this; } setRGB(r, g, b, colorSpace = ColorManagement.workingColorSpace) { this.r = r; this.g = g; this.b = b; ColorManagement.toWorkingColorSpace(this, colorSpace); return this; } setHSL(h, s, l, colorSpace = ColorManagement.workingColorSpace) { h = euclideanModulo(h, 1); s = clamp(s, 0, 1); l = clamp(l, 0, 1); if (s === 0) { this.r = this.g = this.b = l; } else { const p = l <= 0.5 ? l * (1 + s) : l + s - l * s; const q = 2 * l - p; this.r = hue2rgb(q, p, h + 1 / 3); this.g = hue2rgb(q, p, h); this.b = hue2rgb(q, p, h - 1 / 3); } ColorManagement.toWorkingColorSpace(this, colorSpace); return this; } setStyle(style, colorSpace = SRGBColorSpace) { function handleAlpha(string) { if (string === void 0) return; if (parseFloat(string) < 1) { console.warn("THREE.Color: Alpha component of " + style + " will be ignored."); } } let m2; if (m2 = /^(\w+)\(([^\)]*)\)/.exec(style)) { let color; const name = m2[1]; const components = m2[2]; switch (name) { case "rgb": case "rgba": if (color = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) { handleAlpha(color[4]); return this.setRGB( Math.min(255, parseInt(color[1], 10)) / 255, Math.min(255, parseInt(color[2], 10)) / 255, Math.min(255, parseInt(color[3], 10)) / 255, colorSpace ); } if (color = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) { handleAlpha(color[4]); return this.setRGB( Math.min(100, parseInt(color[1], 10)) / 100, Math.min(100, parseInt(color[2], 10)) / 100, Math.min(100, parseInt(color[3], 10)) / 100, colorSpace ); } break; case "hsl": case "hsla": if (color = /^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) { handleAlpha(color[4]); return this.setHSL( parseFloat(color[1]) / 360, parseFloat(color[2]) / 100, parseFloat(color[3]) / 100, colorSpace ); } break; default: console.warn("THREE.Color: Unknown color model " + style); } } else if (m2 = /^\#([A-Fa-f\d]+)$/.exec(style)) { const hex = m2[1]; const size = hex.length; if (size === 3) { return this.setRGB( parseInt(hex.charAt(0), 16) / 15, parseInt(hex.charAt(1), 16) / 15, parseInt(hex.charAt(2), 16) / 15, colorSpace ); } else if (size === 6) { return this.setHex(parseInt(hex, 16), colorSpace); } else { console.warn("THREE.Color: Invalid hex color " + style); } } else if (style && style.length > 0) { return this.setColorName(style, colorSpace); } return this; } setColorName(style, colorSpace = SRGBColorSpace) { const hex = _colorKeywords[style.toLowerCase()]; if (hex !== void 0) { this.setHex(hex, colorSpace); } else { console.warn("THREE.Color: Unknown color " + style); } return this; } clone() { return new this.constructor(this.r, this.g, this.b); } copy(color) { this.r = color.r; this.g = color.g; this.b = color.b; return this; } copySRGBToLinear(color) { this.r = SRGBToLinear(color.r); this.g = SRGBToLinear(color.g); this.b = SRGBToLinear(color.b); return this; } copyLinearToSRGB(color) { this.r = LinearToSRGB(color.r); this.g = LinearToSRGB(color.g); this.b = LinearToSRGB(color.b); return this; } convertSRGBToLinear() { this.copySRGBToLinear(this); return this; } convertLinearToSRGB() { this.copyLinearToSRGB(this); return this; } getHex(colorSpace = SRGBColorSpace) { ColorManagement.fromWorkingColorSpace(_color.copy(this), colorSpace); return Math.round(clamp(_color.r * 255, 0, 255)) * 65536 + Math.round(clamp(_color.g * 255, 0, 255)) * 256 + Math.round(clamp(_color.b * 255, 0, 255)); } getHexString(colorSpace = SRGBColorSpace) { return ("000000" + this.getHex(colorSpace).toString(16)).slice(-6); } getHSL(target, colorSpace = ColorManagement.workingColorSpace) { ColorManagement.fromWorkingColorSpace(_color.copy(this), colorSpace); const r = _color.r, g = _color.g, b = _color.b; const max2 = Math.max(r, g, b); const min2 = Math.min(r, g, b); let hue, saturation; const lightness = (min2 + max2) / 2; if (min2 === max2) { hue = 0; saturation = 0; } else { const delta = max2 - min2; saturation = lightness <= 0.5 ? delta / (max2 + min2) : delta / (2 - max2 - min2); switch (max2) { case r: hue = (g - b) / delta + (g < b ? 6 : 0); break; case g: hue = (b - r) / delta + 2; break; case b: hue = (r - g) / delta + 4; break; } hue /= 6; } target.h = hue; target.s = saturation; target.l = lightness; return target; } getRGB(target, colorSpace = ColorManagement.workingColorSpace) { ColorManagement.fromWorkingColorSpace(_color.copy(this), colorSpace); target.r = _color.r; target.g = _color.g; target.b = _color.b; return target; } getStyle(colorSpace = SRGBColorSpace) { ColorManagement.fromWorkingColorSpace(_color.copy(this), colorSpace); const r = _color.r, g = _color.g, b = _color.b; if (colorSpace !== SRGBColorSpace) { return `color(${colorSpace} ${r.toFixed(3)} ${g.toFixed(3)} ${b.toFixed(3)})`; } return `rgb(${Math.round(r * 255)},${Math.round(g * 255)},${Math.round(b * 255)})`; } offsetHSL(h, s, l) { this.getHSL(_hslA); return this.setHSL(_hslA.h + h, _hslA.s + s, _hslA.l + l); } add(color) { this.r += color.r; this.g += color.g; this.b += color.b; return this; } addColors(color1, color2) { this.r = color1.r + color2.r; this.g = color1.g + color2.g; this.b = color1.b + color2.b; return this; } addScalar(s) { this.r += s; this.g += s; this.b += s; return this; } sub(color) { this.r = Math.max(0, this.r - color.r); this.g = Math.max(0, this.g - color.g); this.b = Math.max(0, this.b - color.b); return this; } multiply(color) { this.r *= color.r; this.g *= color.g; this.b *= color.b; return this; } multiplyScalar(s) { this.r *= s; this.g *= s; this.b *= s; return this; } lerp(color, alpha) { this.r += (color.r - this.r) * alpha; this.g += (color.g - this.g) * alpha; this.b += (color.b - this.b) * alpha; return this; } lerpColors(color1, color2, alpha) { this.r = color1.r + (color2.r - color1.r) * alpha; this.g = color1.g + (color2.g - color1.g) * alpha; this.b = color1.b + (color2.b - color1.b) * alpha; return this; } lerpHSL(color, alpha) { this.getHSL(_hslA); color.getHSL(_hslB); const h = lerp(_hslA.h, _hslB.h, alpha); const s = lerp(_hslA.s, _hslB.s, alpha); const l = lerp(_hslA.l, _hslB.l, alpha); this.setHSL(h, s, l); return this; } setFromVector3(v) { this.r = v.x; this.g = v.y; this.b = v.z; return this; } applyMatrix3(m2) { const r = this.r, g = this.g, b = this.b; const e = m2.elements; this.r = e[0] * r + e[3] * g + e[6] * b; this.g = e[1] * r + e[4] * g + e[7] * b; this.b = e[2] * r + e[5] * g + e[8] * b; return this; } equals(c2) { return c2.r === this.r && c2.g === this.g && c2.b === this.b; } fromArray(array, offset = 0) { this.r = array[offset]; this.g = array[offset + 1]; this.b = array[offset + 2]; return this; } toArray(array = [], offset = 0) { array[offset] = this.r; array[offset + 1] = this.g; array[offset + 2] = this.b; return array; } fromBufferAttribute(attribute, index6) { this.r = attribute.getX(index6); this.g = attribute.getY(index6); this.b = attribute.getZ(index6); return this; } toJSON() { return this.getHex(); } *[Symbol.iterator]() { yield this.r; yield this.g; yield this.b; } }; var _color = /* @__PURE__ */ new Color(); Color.NAMES = _colorKeywords; var _materialId = 0; var Material = class extends EventDispatcher { constructor() { super(); this.isMaterial = true; Object.defineProperty(this, "id", { value: _materialId++ }); this.uuid = generateUUID(); this.name = ""; this.type = "Material"; this.blending = NormalBlending; this.side = FrontSide; this.vertexColors = false; this.opacity = 1; this.transparent = false; this.alphaHash = false; this.blendSrc = SrcAlphaFactor; this.blendDst = OneMinusSrcAlphaFactor; this.blendEquation = AddEquation; this.blendSrcAlpha = null; this.blendDstAlpha = null; this.blendEquationAlpha = null; this.blendColor = new Color(0, 0, 0); this.blendAlpha = 0; this.depthFunc = LessEqualDepth; this.depthTest = true; this.depthWrite = true; this.stencilWriteMask = 255; this.stencilFunc = AlwaysStencilFunc; this.stencilRef = 0; this.stencilFuncMask = 255; this.stencilFail = KeepStencilOp; this.stencilZFail = KeepStencilOp; this.stencilZPass = KeepStencilOp; this.stencilWrite = false; this.clippingPlanes = null; this.clipIntersection = false; this.clipShadows = false; this.shadowSide = null; this.colorWrite = true; this.precision = null; this.polygonOffset = false; this.polygonOffsetFactor = 0; this.polygonOffsetUnits = 0; this.dithering = false; this.alphaToCoverage = false; this.premultipliedAlpha = false; this.forceSinglePass = false; this.visible = true; this.toneMapped = true; this.userData = {}; this.version = 0; this._alphaTest = 0; } get alphaTest() { return this._alphaTest; } set alphaTest(value) { if (this._alphaTest > 0 !== value > 0) { this.version++; } this._alphaTest = value; } onBuild() { } onBeforeRender() { } onBeforeCompile() { } customProgramCacheKey() { return this.onBeforeCompile.toString(); } setValues(values) { if (values === void 0) return; for (const key in values) { const newValue = values[key]; if (newValue === void 0) { console.warn(`THREE.Material: parameter '${key}' has value of undefined.`); continue; } const currentValue = this[key]; if (currentValue === void 0) { console.warn(`THREE.Material: '${key}' is not a property of THREE.${this.type}.`); continue; } if (currentValue && currentValue.isColor) { currentValue.set(newValue); } else if (currentValue && currentValue.isVector3 && (newValue && newValue.isVector3)) { currentValue.copy(newValue); } else { this[key] = newValue; } } } toJSON(meta) { const isRootObject = meta === void 0 || typeof meta === "string"; if (isRootObject) { meta = { textures: {}, images: {} }; } const data = { metadata: { version: 4.6, type: "Material", generator: "Material.toJSON" } }; data.uuid = this.uuid; data.type = this.type; if (this.name !== "") data.name = this.name; if (this.color && this.color.isColor) data.color = this.color.getHex(); if (this.roughness !== void 0) data.roughness = this.roughness; if (this.metalness !== void 0) data.metalness = this.metalness; if (this.sheen !== void 0) data.sheen = this.sheen; if (this.sheenColor && this.sheenColor.isColor) data.sheenColor = this.sheenColor.getHex(); if (this.sheenRoughness !== void 0) data.sheenRoughness = this.sheenRoughness; if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex(); if (this.emissiveIntensity && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity; if (this.specular && this.specular.isColor) data.specular = this.specular.getHex(); if (this.specularIntensity !== void 0) data.specularIntensity = this.specularIntensity; if (this.specularColor && this.specularColor.isColor) data.specularColor = this.specularColor.getHex(); if (this.shininess !== void 0) data.shininess = this.shininess; if (this.clearcoat !== void 0) data.clearcoat = this.clearcoat; if (this.clearcoatRoughness !== void 0) data.clearcoatRoughness = this.clearcoatRoughness; if (this.clearcoatMap && this.clearcoatMap.isTexture) { data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid; } if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) { data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid; } if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) { data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid; data.clearcoatNormalScale = this.clearcoatNormalScale.toArray(); } if (this.iridescence !== void 0) data.iridescence = this.iridescence; if (this.iridescenceIOR !== void 0) data.iridescenceIOR = this.iridescenceIOR; if (this.iridescenceThicknessRange !== void 0) data.iridescenceThicknessRange = this.iridescenceThicknessRange; if (this.iridescenceMap && this.iridescenceMap.isTexture) { data.iridescenceMap = this.iridescenceMap.toJSON(meta).uuid; } if (this.iridescenceThicknessMap && this.iridescenceThicknessMap.isTexture) { data.iridescenceThicknessMap = this.iridescenceThicknessMap.toJSON(meta).uuid; } if (this.anisotropy !== void 0) data.anisotropy = this.anisotropy; if (this.anisotropyRotation !== void 0) data.anisotropyRotation = this.anisotropyRotation; if (this.anisotropyMap && this.anisotropyMap.isTexture) { data.anisotropyMap = this.anisotropyMap.toJSON(meta).uuid; } if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid; if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid; if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid; if (this.lightMap && this.lightMap.isTexture) { data.lightMap = this.lightMap.toJSON(meta).uuid; data.lightMapIntensity = this.lightMapIntensity; } if (this.aoMap && this.aoMap.isTexture) { data.aoMap = this.aoMap.toJSON(meta).uuid; data.aoMapIntensity = this.aoMapIntensity; } if (this.bumpMap && this.bumpMap.isTexture) { data.bumpMap = this.bumpMap.toJSON(meta).uuid; data.bumpScale = this.bumpScale; } if (this.normalMap && this.normalMap.isTexture) { data.normalMap = this.normalMap.toJSON(meta).uuid; data.normalMapType = this.normalMapType; data.normalScale = this.normalScale.toArray(); } if (this.displacementMap && this.displacementMap.isTexture) { data.displacementMap = this.displacementMap.toJSON(meta).uuid; data.displacementScale = this.displacementScale; data.displacementBias = this.displacementBias; } if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid; if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid; if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid; if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid; if (this.specularIntensityMap && this.specularIntensityMap.isTexture) data.specularIntensityMap = this.specularIntensityMap.toJSON(meta).uuid; if (this.specularColorMap && this.specularColorMap.isTexture) data.specularColorMap = this.specularColorMap.toJSON(meta).uuid; if (this.envMap && this.envMap.isTexture) { data.envMap = this.envMap.toJSON(meta).uuid; if (this.combine !== void 0) data.combine = this.combine; } if (this.envMapIntensity !== void 0) data.envMapIntensity = this.envMapIntensity; if (this.reflectivity !== void 0) data.reflectivity = this.reflectivity; if (this.refractionRatio !== void 0) data.refractionRatio = this.refractionRatio; if (this.gradientMap && this.gradientMap.isTexture) { data.gradientMap = this.gradientMap.toJSON(meta).uuid; } if (this.transmission !== void 0) data.transmission = this.transmission; if (this.transmissionMap && this.transmissionMap.isTexture) data.transmissionMap = this.transmissionMap.toJSON(meta).uuid; if (this.thickness !== void 0) data.thickness = this.thickness; if (this.thicknessMap && this.thicknessMap.isTexture) data.thicknessMap = this.thicknessMap.toJSON(meta).uuid; if (this.attenuationDistance !== void 0 && this.attenuationDistance !== Infinity) data.attenuationDistance = this.attenuationDistance; if (this.attenuationColor !== void 0) data.attenuationColor = this.attenuationColor.getHex(); if (this.size !== void 0) data.size = this.size; if (this.shadowSide !== null) data.shadowSide = this.shadowSide; if (this.sizeAttenuation !== void 0) data.sizeAttenuation = this.sizeAttenuation; if (this.blending !== NormalBlending) data.blending = this.blending; if (this.side !== FrontSide) data.side = this.side; if (this.vertexColors === true) data.vertexColors = true; if (this.opacity < 1) data.opacity = this.opacity; if (this.transparent === true) data.transparent = true; if (this.blendSrc !== SrcAlphaFactor) data.blendSrc = this.blendSrc; if (this.blendDst !== OneMinusSrcAlphaFactor) data.blendDst = this.blendDst; if (this.blendEquation !== AddEquation) data.blendEquation = this.blendEquation; if (this.blendSrcAlpha !== null) data.blendSrcAlpha = this.blendSrcAlpha; if (this.blendDstAlpha !== null) data.blendDstAlpha = this.blendDstAlpha; if (this.blendEquationAlpha !== null) data.blendEquationAlpha = this.blendEquationAlpha; if (this.blendColor && this.blendColor.isColor) data.blendColor = this.blendColor.getHex(); if (this.blendAlpha !== 0) data.blendAlpha = this.blendAlpha; if (this.depthFunc !== LessEqualDepth) data.depthFunc = this.depthFunc; if (this.depthTest === false) data.depthTest = this.depthTest; if (this.depthWrite === false) data.depthWrite = this.depthWrite; if (this.colorWrite === false) data.colorWrite = this.colorWrite; if (this.stencilWriteMask !== 255) data.stencilWriteMask = this.stencilWriteMask; if (this.stencilFunc !== AlwaysStencilFunc) data.stencilFunc = this.stencilFunc; if (this.stencilRef !== 0) data.stencilRef = this.stencilRef; if (this.stencilFuncMask !== 255) data.stencilFuncMask = this.stencilFuncMask; if (this.stencilFail !== KeepStencilOp) data.stencilFail = this.stencilFail; if (this.stencilZFail !== KeepStencilOp) data.stencilZFail = this.stencilZFail; if (this.stencilZPass !== KeepStencilOp) data.stencilZPass = this.stencilZPass; if (this.stencilWrite === true) data.stencilWrite = this.stencilWrite; if (this.rotation !== void 0 && this.rotation !== 0) data.rotation = this.rotation; if (this.polygonOffset === true) data.polygonOffset = true; if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor; if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits; if (this.linewidth !== void 0 && this.linewidth !== 1) data.linewidth = this.linewidth; if (this.dashSize !== void 0) data.dashSize = this.dashSize; if (this.gapSize !== void 0) data.gapSize = this.gapSize; if (this.scale !== void 0) data.scale = this.scale; if (this.dithering === true) data.dithering = true; if (this.alphaTest > 0) data.alphaTest = this.alphaTest; if (this.alphaHash === true) data.alphaHash = true; if (this.alphaToCoverage === true) data.alphaToCoverage = true; if (this.premultipliedAlpha === true) data.premultipliedAlpha = true; if (this.forceSinglePass === true) data.forceSinglePass = true; if (this.wireframe === true) data.wireframe = true; if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth; if (this.wireframeLinecap !== "round") data.wireframeLinecap = this.wireframeLinecap; if (this.wireframeLinejoin !== "round") data.wireframeLinejoin = this.wireframeLinejoin; if (this.flatShading === true) data.flatShading = true; if (this.visible === false) data.visible = false; if (this.toneMapped === false) data.toneMapped = false; if (this.fog === false) data.fog = false; if (Object.keys(this.userData).length > 0) data.userData = this.userData; function extractFromCache(cache) { const values = []; for (const key in cache) { const data2 = cache[key]; delete data2.metadata; values.push(data2); } return values; } if (isRootObject) { const textures = extractFromCache(meta.textures); const images = extractFromCache(meta.images); if (textures.length > 0) data.textures = textures; if (images.length > 0) data.images = images; } return data; } clone() { return new this.constructor().copy(this); } copy(source) { this.name = source.name; this.blending = source.blending; this.side = source.side; this.vertexColors = source.vertexColors; this.opacity = source.opacity; this.transparent = source.transparent; this.blendSrc = source.blendSrc; this.blendDst = source.blendDst; this.blendEquation = source.blendEquation; this.blendSrcAlpha = source.blendSrcAlpha; this.blendDstAlpha = source.blendDstAlpha; this.blendEquationAlpha = source.blendEquationAlpha; this.blendColor.copy(source.blendColor); this.blendAlpha = source.blendAlpha; this.depthFunc = source.depthFunc; this.depthTest = source.depthTest; this.depthWrite = source.depthWrite; this.stencilWriteMask = source.stencilWriteMask; this.stencilFunc = source.stencilFunc; this.stencilRef = source.stencilRef; this.stencilFuncMask = source.stencilFuncMask; this.stencilFail = source.stencilFail; this.stencilZFail = source.stencilZFail; this.stencilZPass = source.stencilZPass; this.stencilWrite = source.stencilWrite; const srcPlanes = source.clippingPlanes; let dstPlanes = null; if (srcPlanes !== null) { const n = srcPlanes.length; dstPlanes = new Array(n); for (let i = 0; i !== n; ++i) { dstPlanes[i] = srcPlanes[i].clone(); } } this.clippingPlanes = dstPlanes; this.clipIntersection = source.clipIntersection; this.clipShadows = source.clipShadows; this.shadowSide = source.shadowSide; this.colorWrite = source.colorWrite; this.precision = source.precision; this.polygonOffset = source.polygonOffset; this.polygonOffsetFactor = source.polygonOffsetFactor; this.polygonOffsetUnits = source.polygonOffsetUnits; this.dithering = source.dithering; this.alphaTest = source.alphaTest; this.alphaHash = source.alphaHash; this.alphaToCoverage = source.alphaToCoverage; this.premultipliedAlpha = source.premultipliedAlpha; this.forceSinglePass = source.forceSinglePass; this.visible = source.visible; this.toneMapped = source.toneMapped; this.userData = JSON.parse(JSON.stringify(source.userData)); return this; } dispose() { this.dispatchEvent({ type: "dispose" }); } set needsUpdate(value) { if (value === true) this.version++; } }; var MeshBasicMaterial = class extends Material { constructor(parameters) { super(); this.isMeshBasicMaterial = true; this.type = "MeshBasicMaterial"; this.color = new Color(16777215); this.map = null; this.lightMap = null; this.lightMapIntensity = 1; this.aoMap = null; this.aoMapIntensity = 1; this.specularMap = null; this.alphaMap = null; this.envMap = null; this.combine = MultiplyOperation; this.reflectivity = 1; this.refractionRatio = 0.98; this.wireframe = false; this.wireframeLinewidth = 1; this.wireframeLinecap = "round"; this.wireframeLinejoin = "round"; this.fog = true; this.setValues(parameters); } copy(source) { super.copy(source); this.color.copy(source.color); this.map = source.map; this.lightMap = source.lightMap; this.lightMapIntensity = source.lightMapIntensity; this.aoMap = source.aoMap; this.aoMapIntensity = source.aoMapIntensity; this.specularMap = source.specularMap; this.alphaMap = source.alphaMap; this.envMap = source.envMap; this.combine = source.combine; this.reflectivity = source.reflectivity; this.refractionRatio = source.refractionRatio; this.wireframe = source.wireframe; this.wireframeLinewidth = source.wireframeLinewidth; this.wireframeLinecap = source.wireframeLinecap; this.wireframeLinejoin = source.wireframeLinejoin; this.fog = source.fog; return this; } }; var _vector$8 = /* @__PURE__ */ new Vector3(); var _vector2$1 = /* @__PURE__ */ new Vector2(); var BufferAttribute = class { constructor(array, itemSize, normalized = false) { if (Array.isArray(array)) { throw new TypeError("THREE.BufferAttribute: array should be a Typed Array."); } this.isBufferAttribute = true; this.name = ""; this.array = array; this.itemSize = itemSize; this.count = array !== void 0 ? array.length / itemSize : 0; this.normalized = normalized; this.usage = StaticDrawUsage; this.updateRange = { offset: 0, count: -1 }; this.gpuType = FloatType; this.version = 0; } onUploadCallback() { } set needsUpdate(value) { if (value === true) this.version++; } setUsage(value) { this.usage = value; return this; } copy(source) { this.name = source.name; this.array = new source.array.constructor(source.array); this.itemSize = source.itemSize; this.count = source.count; this.normalized = source.normalized; this.usage = source.usage; this.gpuType = source.gpuType; return this; } copyAt(index1, attribute, index22) { index1 *= this.itemSize; index22 *= attribute.itemSize; for (let i = 0, l = this.itemSize; i < l; i++) { this.array[index1 + i] = attribute.array[index22 + i]; } return this; } copyArray(array) { this.array.set(array); return this; } applyMatrix3(m2) { if (this.itemSize === 2) { for (let i = 0, l = this.count; i < l; i++) { _vector2$1.fromBufferAttribute(this, i); _vector2$1.applyMatrix3(m2); this.setXY(i, _vector2$1.x, _vector2$1.y); } } else if (this.itemSize === 3) { for (let i = 0, l = this.count; i < l; i++) { _vector$8.fromBufferAttribute(this, i); _vector$8.applyMatrix3(m2); this.setXYZ(i, _vector$8.x, _vector$8.y, _vector$8.z); } } return this; } applyMatrix4(m2) { for (let i = 0, l = this.count; i < l; i++) { _vector$8.fromBufferAttribute(this, i); _vector$8.applyMatrix4(m2); this.setXYZ(i, _vector$8.x, _vector$8.y, _vector$8.z); } return this; } applyNormalMatrix(m2) { for (let i = 0, l = this.count; i < l; i++) { _vector$8.fromBufferAttribute(this, i); _vector$8.applyNormalMatrix(m2); this.setXYZ(i, _vector$8.x, _vector$8.y, _vector$8.z); } return this; } transformDirection(m2) { for (let i = 0, l = this.count; i < l; i++) { _vector$8.fromBufferAttribute(this, i); _vector$8.transformDirection(m2); this.setXYZ(i, _vector$8.x, _vector$8.y, _vector$8.z); } return this; } set(value, offset = 0) { this.array.set(value, offset); return this; } getComponent(index6, component) { let value = this.array[index6 * this.itemSize + component]; if (this.normalized) value = denormalize(value, this.array); return value; } setComponent(index6, component, value) { if (this.normalized) value = normalize(value, this.array); this.array[index6 * this.itemSize + component] = value; return this; } getX(index6) { let x3 = this.array[index6 * this.itemSize]; if (this.normalized) x3 = denormalize(x3, this.array); return x3; } setX(index6, x3) { if (this.normalized) x3 = normalize(x3, this.array); this.array[index6 * this.itemSize] = x3; return this; } getY(index6) { let y3 = this.array[index6 * this.itemSize + 1]; if (this.normalized) y3 = denormalize(y3, this.array); return y3; } setY(index6, y3) { if (this.normalized) y3 = normalize(y3, this.array); this.array[index6 * this.itemSize + 1] = y3; return this; } getZ(index6) { let z4 = this.array[index6 * this.itemSize + 2]; if (this.normalized) z4 = denormalize(z4, this.array); return z4; } setZ(index6, z4) { if (this.normalized) z4 = normalize(z4, this.array); this.array[index6 * this.itemSize + 2] = z4; return this; } getW(index6) { let w = this.array[index6 * this.itemSize + 3]; if (this.normalized) w = denormalize(w, this.array); return w; } setW(index6, w) { if (this.normalized) w = normalize(w, this.array); this.array[index6 * this.itemSize + 3] = w; return this; } setXY(index6, x3, y3) { index6 *= this.itemSize; if (this.normalized) { x3 = normalize(x3, this.array); y3 = normalize(y3, this.array); } this.array[index6 + 0] = x3; this.array[index6 + 1] = y3; return this; } setXYZ(index6, x3, y3, z4) { index6 *= this.itemSize; if (this.normalized) { x3 = normalize(x3, this.array); y3 = normalize(y3, this.array); z4 = normalize(z4, this.array); } this.array[index6 + 0] = x3; this.array[index6 + 1] = y3; this.array[index6 + 2] = z4; return this; } setXYZW(index6, x3, y3, z4, w) { index6 *= this.itemSize; if (this.normalized) { x3 = normalize(x3, this.array); y3 = normalize(y3, this.array); z4 = normalize(z4, this.array); w = normalize(w, this.array); } this.array[index6 + 0] = x3; this.array[index6 + 1] = y3; this.array[index6 + 2] = z4; this.array[index6 + 3] = w; return this; } onUpload(callback) { this.onUploadCallback = callback; return this; } clone() { return new this.constructor(this.array, this.itemSize).copy(this); } toJSON() { const data = { itemSize: this.itemSize, type: this.array.constructor.name, array: Array.from(this.array), normalized: this.normalized }; if (this.name !== "") data.name = this.name; if (this.usage !== StaticDrawUsage) data.usage = this.usage; if (this.updateRange.offset !== 0 || this.updateRange.count !== -1) data.updateRange = this.updateRange; return data; } }; var Uint16BufferAttribute = class extends BufferAttribute { constructor(array, itemSize, normalized) { super(new Uint16Array(array), itemSize, normalized); } }; var Uint32BufferAttribute = class extends BufferAttribute { constructor(array, itemSize, normalized) { super(new Uint32Array(array), itemSize, normalized); } }; var Float32BufferAttribute = class extends BufferAttribute { constructor(array, itemSize, normalized) { super(new Float32Array(array), itemSize, normalized); } }; var _id$2 = 0; var _m1 = /* @__PURE__ */ new Matrix4(); var _obj = /* @__PURE__ */ new Object3D(); var _offset = /* @__PURE__ */ new Vector3(); var _box$1 = /* @__PURE__ */ new Box3(); var _boxMorphTargets = /* @__PURE__ */ new Box3(); var _vector$7 = /* @__PURE__ */ new Vector3(); var BufferGeometry = class extends EventDispatcher { constructor() { super(); this.isBufferGeometry = true; Object.defineProperty(this, "id", { value: _id$2++ }); this.uuid = generateUUID(); this.name = ""; this.type = "BufferGeometry"; this.index = null; this.attributes = {}; this.morphAttributes = {}; this.morphTargetsRelative = false; this.groups = []; this.boundingBox = null; this.boundingSphere = null; this.drawRange = { start: 0, count: Infinity }; this.userData = {}; } getIndex() { return this.index; } setIndex(index6) { if (Array.isArray(index6)) { this.index = new (arrayNeedsUint32(index6) ? Uint32BufferAttribute : Uint16BufferAttribute)(index6, 1); } else { this.index = index6; } return this; } getAttribute(name) { return this.attributes[name]; } setAttribute(name, attribute) { this.attributes[name] = attribute; return this; } deleteAttribute(name) { delete this.attributes[name]; return this; } hasAttribute(name) { return this.attributes[name] !== void 0; } addGroup(start, count, materialIndex = 0) { this.groups.push({ start, count, materialIndex }); } clearGroups() { this.groups = []; } setDrawRange(start, count) { this.drawRange.start = start; this.drawRange.count = count; } applyMatrix4(matrix) { const position = this.attributes.position; if (position !== void 0) { position.applyMatrix4(matrix); position.needsUpdate = true; } const normal = this.attributes.normal; if (normal !== void 0) { const normalMatrix = new Matrix3().getNormalMatrix(matrix); normal.applyNormalMatrix(normalMatrix); normal.needsUpdate = true; } const tangent = this.attributes.tangent; if (tangent !== void 0) { tangent.transformDirection(matrix); tangent.needsUpdate = true; } if (this.boundingBox !== null) { this.computeBoundingBox(); } if (this.boundingSphere !== null) { this.computeBoundingSphere(); } return this; } applyQuaternion(q) { _m1.makeRotationFromQuaternion(q); this.applyMatrix4(_m1); return this; } rotateX(angle) { _m1.makeRotationX(angle); this.applyMatrix4(_m1); return this; } rotateY(angle) { _m1.makeRotationY(angle); this.applyMatrix4(_m1); return this; } rotateZ(angle) { _m1.makeRotationZ(angle); this.applyMatrix4(_m1); return this; } translate(x3, y3, z4) { _m1.makeTranslation(x3, y3, z4); this.applyMatrix4(_m1); return this; } scale(x3, y3, z4) { _m1.makeScale(x3, y3, z4); this.applyMatrix4(_m1); return this; } lookAt(vector) { _obj.lookAt(vector); _obj.updateMatrix(); this.applyMatrix4(_obj.matrix); return this; } center() { this.computeBoundingBox(); this.boundingBox.getCenter(_offset).negate(); this.translate(_offset.x, _offset.y, _offset.z); return this; } setFromPoints(points) { const position = []; for (let i = 0, l = points.length; i < l; i++) { const point = points[i]; position.push(point.x, point.y, point.z || 0); } this.setAttribute("position", new Float32BufferAttribute(position, 3)); return this; } computeBoundingBox() { if (this.boundingBox === null) { this.boundingBox = new Box3(); } const position = this.attributes.position; const morphAttributesPosition = this.morphAttributes.position; if (position && position.isGLBufferAttribute) { console.error('THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this); this.boundingBox.set( new Vector3(-Infinity, -Infinity, -Infinity), new Vector3(Infinity, Infinity, Infinity) ); return; } if (position !== void 0) { this.boundingBox.setFromBufferAttribute(position); if (morphAttributesPosition) { for (let i = 0, il = morphAttributesPosition.length; i < il; i++) { const morphAttribute = morphAttributesPosition[i]; _box$1.setFromBufferAttribute(morphAttribute); if (this.morphTargetsRelative) { _vector$7.addVectors(this.boundingBox.min, _box$1.min); this.boundingBox.expandByPoint(_vector$7); _vector$7.addVectors(this.boundingBox.max, _box$1.max); this.boundingBox.expandByPoint(_vector$7); } else { this.boundingBox.expandByPoint(_box$1.min); this.boundingBox.expandByPoint(_box$1.max); } } } } else { this.boundingBox.makeEmpty(); } if (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) { console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this); } } computeBoundingSphere() { if (this.boundingSphere === null) { this.boundingSphere = new Sphere(); } const position = this.attributes.position; const morphAttributesPosition = this.morphAttributes.position; if (position && position.isGLBufferAttribute) { console.error('THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this); this.boundingSphere.set(new Vector3(), Infinity); return; } if (position) { const center = this.boundingSphere.center; _box$1.setFromBufferAttribute(position); if (morphAttributesPosition) { for (let i = 0, il = morphAttributesPosition.length; i < il; i++) { const morphAttribute = morphAttributesPosition[i]; _boxMorphTargets.setFromBufferAttribute(morphAttribute); if (this.morphTargetsRelative) { _vector$7.addVectors(_box$1.min, _boxMorphTargets.min); _box$1.expandByPoint(_vector$7); _vector$7.addVectors(_box$1.max, _boxMorphTargets.max); _box$1.expandByPoint(_vector$7); } else { _box$1.expandByPoint(_boxMorphTargets.min); _box$1.expandByPoint(_boxMorphTargets.max); } } } _box$1.getCenter(center); let maxRadiusSq = 0; for (let i = 0, il = position.count; i < il; i++) { _vector$7.fromBufferAttribute(position, i); maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$7)); } if (morphAttributesPosition) { for (let i = 0, il = morphAttributesPosition.length; i < il; i++) { const morphAttribute = morphAttributesPosition[i]; const morphTargetsRelative = this.morphTargetsRelative; for (let j = 0, jl = morphAttribute.count; j < jl; j++) { _vector$7.fromBufferAttribute(morphAttribute, j); if (morphTargetsRelative) { _offset.fromBufferAttribute(position, j); _vector$7.add(_offset); } maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$7)); } } } this.boundingSphere.radius = Math.sqrt(maxRadiusSq); if (isNaN(this.boundingSphere.radius)) { console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this); } } } computeTangents() { const index6 = this.index; const attributes = this.attributes; if (index6 === null || attributes.position === void 0 || attributes.normal === void 0 || attributes.uv === void 0) { console.error("THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)"); return; } const indices = index6.array; const positions = attributes.position.array; const normals = attributes.normal.array; const uvs = attributes.uv.array; const nVertices = positions.length / 3; if (this.hasAttribute("tangent") === false) { this.setAttribute("tangent", new BufferAttribute(new Float32Array(4 * nVertices), 4)); } const tangents = this.getAttribute("tangent").array; const tan1 = [], tan2 = []; for (let i = 0; i < nVertices; i++) { tan1[i] = new Vector3(); tan2[i] = new Vector3(); } const vA = new Vector3(), vB = new Vector3(), vC = new Vector3(), uvA = new Vector2(), uvB = new Vector2(), uvC = new Vector2(), sdir = new Vector3(), tdir = new Vector3(); function handleTriangle(a2, b, c2) { vA.fromArray(positions, a2 * 3); vB.fromArray(positions, b * 3); vC.fromArray(positions, c2 * 3); uvA.fromArray(uvs, a2 * 2); uvB.fromArray(uvs, b * 2); uvC.fromArray(uvs, c2 * 2); vB.sub(vA); vC.sub(vA); uvB.sub(uvA); uvC.sub(uvA); const r = 1 / (uvB.x * uvC.y - uvC.x * uvB.y); if (!isFinite(r)) return; sdir.copy(vB).multiplyScalar(uvC.y).addScaledVector(vC, -uvB.y).multiplyScalar(r); tdir.copy(vC).multiplyScalar(uvB.x).addScaledVector(vB, -uvC.x).multiplyScalar(r); tan1[a2].add(sdir); tan1[b].add(sdir); tan1[c2].add(sdir); tan2[a2].add(tdir); tan2[b].add(tdir); tan2[c2].add(tdir); } let groups = this.groups; if (groups.length === 0) { groups = [{ start: 0, count: indices.length }]; } for (let i = 0, il = groups.length; i < il; ++i) { const group = groups[i]; const start = group.start; const count = group.count; for (let j = start, jl = start + count; j < jl; j += 3) { handleTriangle( indices[j + 0], indices[j + 1], indices[j + 2] ); } } const tmp2 = new Vector3(), tmp22 = new Vector3(); const n = new Vector3(), n2 = new Vector3(); function handleVertex(v) { n.fromArray(normals, v * 3); n2.copy(n); const t = tan1[v]; tmp2.copy(t); tmp2.sub(n.multiplyScalar(n.dot(t))).normalize(); tmp22.crossVectors(n2, t); const test = tmp22.dot(tan2[v]); const w = test < 0 ? -1 : 1; tangents[v * 4] = tmp2.x; tangents[v * 4 + 1] = tmp2.y; tangents[v * 4 + 2] = tmp2.z; tangents[v * 4 + 3] = w; } for (let i = 0, il = groups.length; i < il; ++i) { const group = groups[i]; const start = group.start; const count = group.count; for (let j = start, jl = start + count; j < jl; j += 3) { handleVertex(indices[j + 0]); handleVertex(indices[j + 1]); handleVertex(indices[j + 2]); } } } computeVertexNormals() { const index6 = this.index; const positionAttribute = this.getAttribute("position"); if (positionAttribute !== void 0) { let normalAttribute = this.getAttribute("normal"); if (normalAttribute === void 0) { normalAttribute = new BufferAttribute(new Float32Array(positionAttribute.count * 3), 3); this.setAttribute("normal", normalAttribute); } else { for (let i = 0, il = normalAttribute.count; i < il; i++) { normalAttribute.setXYZ(i, 0, 0, 0); } } const pA = new Vector3(), pB = new Vector3(), pC = new Vector3(); const nA = new Vector3(), nB = new Vector3(), nC = new Vector3(); const cb = new Vector3(), ab = new Vector3(); if (index6) { for (let i = 0, il = index6.count; i < il; i += 3) { const vA = index6.getX(i + 0); const vB = index6.getX(i + 1); const vC = index6.getX(i + 2); pA.fromBufferAttribute(positionAttribute, vA); pB.fromBufferAttribute(positionAttribute, vB); pC.fromBufferAttribute(positionAttribute, vC); cb.subVectors(pC, pB); ab.subVectors(pA, pB); cb.cross(ab); nA.fromBufferAttribute(normalAttribute, vA); nB.fromBufferAttribute(normalAttribute, vB); nC.fromBufferAttribute(normalAttribute, vC); nA.add(cb); nB.add(cb); nC.add(cb); normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z); normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z); normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z); } } else { for (let i = 0, il = positionAttribute.count; i < il; i += 3) { pA.fromBufferAttribute(positionAttribute, i + 0); pB.fromBufferAttribute(positionAttribute, i + 1); pC.fromBufferAttribute(positionAttribute, i + 2); cb.subVectors(pC, pB); ab.subVectors(pA, pB); cb.cross(ab); normalAttribute.setXYZ(i + 0, cb.x, cb.y, cb.z); normalAttribute.setXYZ(i + 1, cb.x, cb.y, cb.z); normalAttribute.setXYZ(i + 2, cb.x, cb.y, cb.z); } } this.normalizeNormals(); normalAttribute.needsUpdate = true; } } normalizeNormals() { const normals = this.attributes.normal; for (let i = 0, il = normals.count; i < il; i++) { _vector$7.fromBufferAttribute(normals, i); _vector$7.normalize(); normals.setXYZ(i, _vector$7.x, _vector$7.y, _vector$7.z); } } toNonIndexed() { function convertBufferAttribute(attribute, indices2) { const array = attribute.array; const itemSize = attribute.itemSize; const normalized = attribute.normalized; const array2 = new array.constructor(indices2.length * itemSize); let index6 = 0, index22 = 0; for (let i = 0, l = indices2.length; i < l; i++) { if (attribute.isInterleavedBufferAttribute) { index6 = indices2[i] * attribute.data.stride + attribute.offset; } else { index6 = indices2[i] * itemSize; } for (let j = 0; j < itemSize; j++) { array2[index22++] = array[index6++]; } } return new BufferAttribute(array2, itemSize, normalized); } if (this.index === null) { console.warn("THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."); return this; } const geometry2 = new BufferGeometry(); const indices = this.index.array; const attributes = this.attributes; for (const name in attributes) { const attribute = attributes[name]; const newAttribute = convertBufferAttribute(attribute, indices); geometry2.setAttribute(name, newAttribute); } const morphAttributes = this.morphAttributes; for (const name in morphAttributes) { const morphArray = []; const morphAttribute = morphAttributes[name]; for (let i = 0, il = morphAttribute.length; i < il; i++) { const attribute = morphAttribute[i]; const newAttribute = convertBufferAttribute(attribute, indices); morphArray.push(newAttribute); } geometry2.morphAttributes[name] = morphArray; } geometry2.morphTargetsRelative = this.morphTargetsRelative; const groups = this.groups; for (let i = 0, l = groups.length; i < l; i++) { const group = groups[i]; geometry2.addGroup(group.start, group.count, group.materialIndex); } return geometry2; } toJSON() { const data = { metadata: { version: 4.6, type: "BufferGeometry", generator: "BufferGeometry.toJSON" } }; data.uuid = this.uuid; data.type = this.type; if (this.name !== "") data.name = this.name; if (Object.keys(this.userData).length > 0) data.userData = this.userData; if (this.parameters !== void 0) { const parameters = this.parameters; for (const key in parameters) { if (parameters[key] !== void 0) data[key] = parameters[key]; } return data; } data.data = { attributes: {} }; const index6 = this.index; if (index6 !== null) { data.data.index = { type: index6.array.constructor.name, array: Array.prototype.slice.call(index6.array) }; } const attributes = this.attributes; for (const key in attributes) { const attribute = attributes[key]; data.data.attributes[key] = attribute.toJSON(data.data); } const morphAttributes = {}; let hasMorphAttributes = false; for (const key in this.morphAttributes) { const attributeArray = this.morphAttributes[key]; const array = []; for (let i = 0, il = attributeArray.length; i < il; i++) { const attribute = attributeArray[i]; array.push(attribute.toJSON(data.data)); } if (array.length > 0) { morphAttributes[key] = array; hasMorphAttributes = true; } } if (hasMorphAttributes) { data.data.morphAttributes = morphAttributes; data.data.morphTargetsRelative = this.morphTargetsRelative; } const groups = this.groups; if (groups.length > 0) { data.data.groups = JSON.parse(JSON.stringify(groups)); } const boundingSphere = this.boundingSphere; if (boundingSphere !== null) { data.data.boundingSphere = { center: boundingSphere.center.toArray(), radius: boundingSphere.radius }; } return data; } clone() { return new this.constructor().copy(this); } copy(source) { this.index = null; this.attributes = {}; this.morphAttributes = {}; this.groups = []; this.boundingBox = null; this.boundingSphere = null; const data = {}; this.name = source.name; const index6 = source.index; if (index6 !== null) { this.setIndex(index6.clone(data)); } const attributes = source.attributes; for (const name in attributes) { const attribute = attributes[name]; this.setAttribute(name, attribute.clone(data)); } const morphAttributes = source.morphAttributes; for (const name in morphAttributes) { const array = []; const morphAttribute = morphAttributes[name]; for (let i = 0, l = morphAttribute.length; i < l; i++) { array.push(morphAttribute[i].clone(data)); } this.morphAttributes[name] = array; } this.morphTargetsRelative = source.morphTargetsRelative; const groups = source.groups; for (let i = 0, l = groups.length; i < l; i++) { const group = groups[i]; this.addGroup(group.start, group.count, group.materialIndex); } const boundingBox = source.boundingBox; if (boundingBox !== null) { this.boundingBox = boundingBox.clone(); } const boundingSphere = source.boundingSphere; if (boundingSphere !== null) { this.boundingSphere = boundingSphere.clone(); } this.drawRange.start = source.drawRange.start; this.drawRange.count = source.drawRange.count; this.userData = source.userData; return this; } dispose() { this.dispatchEvent({ type: "dispose" }); } }; var _inverseMatrix$3 = /* @__PURE__ */ new Matrix4(); var _ray$3 = /* @__PURE__ */ new Ray(); var _sphere$5 = /* @__PURE__ */ new Sphere(); var _sphereHitAt = /* @__PURE__ */ new Vector3(); var _vA$1 = /* @__PURE__ */ new Vector3(); var _vB$1 = /* @__PURE__ */ new Vector3(); var _vC$1 = /* @__PURE__ */ new Vector3(); var _tempA = /* @__PURE__ */ new Vector3(); var _morphA = /* @__PURE__ */ new Vector3(); var _uvA$1 = /* @__PURE__ */ new Vector2(); var _uvB$1 = /* @__PURE__ */ new Vector2(); var _uvC$1 = /* @__PURE__ */ new Vector2(); var _normalA = /* @__PURE__ */ new Vector3(); var _normalB = /* @__PURE__ */ new Vector3(); var _normalC = /* @__PURE__ */ new Vector3(); var _intersectionPoint = /* @__PURE__ */ new Vector3(); var _intersectionPointWorld = /* @__PURE__ */ new Vector3(); var Mesh = class extends Object3D { constructor(geometry = new BufferGeometry(), material = new MeshBasicMaterial()) { super(); this.isMesh = true; this.type = "Mesh"; this.geometry = geometry; this.material = material; this.updateMorphTargets(); } copy(source, recursive) { super.copy(source, recursive); if (source.morphTargetInfluences !== void 0) { this.morphTargetInfluences = source.morphTargetInfluences.slice(); } if (source.morphTargetDictionary !== void 0) { this.morphTargetDictionary = Object.assign({}, source.morphTargetDictionary); } this.material = Array.isArray(source.material) ? source.material.slice() : source.material; this.geometry = source.geometry; return this; } updateMorphTargets() { const geometry = this.geometry; const morphAttributes = geometry.morphAttributes; const keys = Object.keys(morphAttributes); if (keys.length > 0) { const morphAttribute = morphAttributes[keys[0]]; if (morphAttribute !== void 0) { this.morphTargetInfluences = []; this.morphTargetDictionary = {}; for (let m2 = 0, ml = morphAttribute.length; m2 < ml; m2++) { const name = morphAttribute[m2].name || String(m2); this.morphTargetInfluences.push(0); this.morphTargetDictionary[name] = m2; } } } } getVertexPosition(index6, target) { const geometry = this.geometry; const position = geometry.attributes.position; const morphPosition = geometry.morphAttributes.position; const morphTargetsRelative = geometry.morphTargetsRelative; target.fromBufferAttribute(position, index6); const morphInfluences = this.morphTargetInfluences; if (morphPosition && morphInfluences) { _morphA.set(0, 0, 0); for (let i = 0, il = morphPosition.length; i < il; i++) { const influence = morphInfluences[i]; const morphAttribute = morphPosition[i]; if (influence === 0) continue; _tempA.fromBufferAttribute(morphAttribute, index6); if (morphTargetsRelative) { _morphA.addScaledVector(_tempA, influence); } else { _morphA.addScaledVector(_tempA.sub(target), influence); } } target.add(_morphA); } return target; } raycast(raycaster, intersects) { const geometry = this.geometry; const material = this.material; const matrixWorld = this.matrixWorld; if (material === void 0) return; if (geometry.boundingSphere === null) geometry.computeBoundingSphere(); _sphere$5.copy(geometry.boundingSphere); _sphere$5.applyMatrix4(matrixWorld); _ray$3.copy(raycaster.ray).recast(raycaster.near); if (_sphere$5.containsPoint(_ray$3.origin) === false) { if (_ray$3.intersectSphere(_sphere$5, _sphereHitAt) === null) return; if (_ray$3.origin.distanceToSquared(_sphereHitAt) > (raycaster.far - raycaster.near) ** 2) return; } _inverseMatrix$3.copy(matrixWorld).invert(); _ray$3.copy(raycaster.ray).applyMatrix4(_inverseMatrix$3); if (geometry.boundingBox !== null) { if (_ray$3.intersectsBox(geometry.boundingBox) === false) return; } this._computeIntersections(raycaster, intersects, _ray$3); } _computeIntersections(raycaster, intersects, rayLocalSpace) { let intersection; const geometry = this.geometry; const material = this.material; const index6 = geometry.index; const position = geometry.attributes.position; const uv = geometry.attributes.uv; const uv1 = geometry.attributes.uv1; const normal = geometry.attributes.normal; const groups = geometry.groups; const drawRange = geometry.drawRange; if (index6 !== null) { if (Array.isArray(material)) { for (let i = 0, il = groups.length; i < il; i++) { const group = groups[i]; const groupMaterial = material[group.materialIndex]; const start = Math.max(group.start, drawRange.start); const end = Math.min(index6.count, Math.min(group.start + group.count, drawRange.start + drawRange.count)); for (let j = start, jl = end; j < jl; j += 3) { const a2 = index6.getX(j); const b = index6.getX(j + 1); const c2 = index6.getX(j + 2); intersection = checkGeometryIntersection(this, groupMaterial, raycaster, rayLocalSpace, uv, uv1, normal, a2, b, c2); if (intersection) { intersection.faceIndex = Math.floor(j / 3); intersection.face.materialIndex = group.materialIndex; intersects.push(intersection); } } } } else { const start = Math.max(0, drawRange.start); const end = Math.min(index6.count, drawRange.start + drawRange.count); for (let i = start, il = end; i < il; i += 3) { const a2 = index6.getX(i); const b = index6.getX(i + 1); const c2 = index6.getX(i + 2); intersection = checkGeometryIntersection(this, material, raycaster, rayLocalSpace, uv, uv1, normal, a2, b, c2); if (intersection) { intersection.faceIndex = Math.floor(i / 3); intersects.push(intersection); } } } } else if (position !== void 0) { if (Array.isArray(material)) { for (let i = 0, il = groups.length; i < il; i++) { const group = groups[i]; const groupMaterial = material[group.materialIndex]; const start = Math.max(group.start, drawRange.start); const end = Math.min(position.count, Math.min(group.start + group.count, drawRange.start + drawRange.count)); for (let j = start, jl = end; j < jl; j += 3) { const a2 = j; const b = j + 1; const c2 = j + 2; intersection = checkGeometryIntersection(this, groupMaterial, raycaster, rayLocalSpace, uv, uv1, normal, a2, b, c2); if (intersection) { intersection.faceIndex = Math.floor(j / 3); intersection.face.materialIndex = group.materialIndex; intersects.push(intersection); } } } } else { const start = Math.max(0, drawRange.start); const end = Math.min(position.count, drawRange.start + drawRange.count); for (let i = start, il = end; i < il; i += 3) { const a2 = i; const b = i + 1; const c2 = i + 2; intersection = checkGeometryIntersection(this, material, raycaster, rayLocalSpace, uv, uv1, normal, a2, b, c2); if (intersection) { intersection.faceIndex = Math.floor(i / 3); intersects.push(intersection); } } } } } }; function checkIntersection(object, material, raycaster, ray, pA, pB, pC, point) { let intersect; if (material.side === BackSide) { intersect = ray.intersectTriangle(pC, pB, pA, true, point); } else { intersect = ray.intersectTriangle(pA, pB, pC, material.side === FrontSide, point); } if (intersect === null) return null; _intersectionPointWorld.copy(point); _intersectionPointWorld.applyMatrix4(object.matrixWorld); const distance = raycaster.ray.origin.distanceTo(_intersectionPointWorld); if (distance < raycaster.near || distance > raycaster.far) return null; return { distance, point: _intersectionPointWorld.clone(), object }; } function checkGeometryIntersection(object, material, raycaster, ray, uv, uv1, normal, a2, b, c2) { object.getVertexPosition(a2, _vA$1); object.getVertexPosition(b, _vB$1); object.getVertexPosition(c2, _vC$1); const intersection = checkIntersection(object, material, raycaster, ray, _vA$1, _vB$1, _vC$1, _intersectionPoint); if (intersection) { if (uv) { _uvA$1.fromBufferAttribute(uv, a2); _uvB$1.fromBufferAttribute(uv, b); _uvC$1.fromBufferAttribute(uv, c2); intersection.uv = Triangle.getInterpolation(_intersectionPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()); } if (uv1) { _uvA$1.fromBufferAttribute(uv1, a2); _uvB$1.fromBufferAttribute(uv1, b); _uvC$1.fromBufferAttribute(uv1, c2); intersection.uv1 = Triangle.getInterpolation(_intersectionPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()); intersection.uv2 = intersection.uv1; } if (normal) { _normalA.fromBufferAttribute(normal, a2); _normalB.fromBufferAttribute(normal, b); _normalC.fromBufferAttribute(normal, c2); intersection.normal = Triangle.getInterpolation(_intersectionPoint, _vA$1, _vB$1, _vC$1, _normalA, _normalB, _normalC, new Vector3()); if (intersection.normal.dot(ray.direction) > 0) { intersection.normal.multiplyScalar(-1); } } const face = { a: a2, b, c: c2, normal: new Vector3(), materialIndex: 0 }; Triangle.getNormal(_vA$1, _vB$1, _vC$1, face.normal); intersection.face = face; } return intersection; } var BoxGeometry = class extends BufferGeometry { constructor(width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1) { super(); this.type = "BoxGeometry"; this.parameters = { width, height, depth, widthSegments, heightSegments, depthSegments }; const scope = this; widthSegments = Math.floor(widthSegments); heightSegments = Math.floor(heightSegments); depthSegments = Math.floor(depthSegments); const indices = []; const vertices = []; const normals = []; const uvs = []; let numberOfVertices = 0; let groupStart = 0; buildPlane("z", "y", "x", -1, -1, depth, height, width, depthSegments, heightSegments, 0); buildPlane("z", "y", "x", 1, -1, depth, height, -width, depthSegments, heightSegments, 1); buildPlane("x", "z", "y", 1, 1, width, depth, height, widthSegments, depthSegments, 2); buildPlane("x", "z", "y", 1, -1, width, depth, -height, widthSegments, depthSegments, 3); buildPlane("x", "y", "z", 1, -1, width, height, depth, widthSegments, heightSegments, 4); buildPlane("x", "y", "z", -1, -1, width, height, -depth, widthSegments, heightSegments, 5); this.setIndex(indices); this.setAttribute("position", new Float32BufferAttribute(vertices, 3)); this.setAttribute("normal", new Float32BufferAttribute(normals, 3)); this.setAttribute("uv", new Float32BufferAttribute(uvs, 2)); function buildPlane(u, v, w, udir, vdir, width2, height2, depth2, gridX, gridY, materialIndex) { const segmentWidth = width2 / gridX; const segmentHeight = height2 / gridY; const widthHalf = width2 / 2; const heightHalf = height2 / 2; const depthHalf = depth2 / 2; const gridX1 = gridX + 1; const gridY1 = gridY + 1; let vertexCounter = 0; let groupCount = 0; const vector = new Vector3(); for (let iy = 0; iy < gridY1; iy++) { const y3 = iy * segmentHeight - heightHalf; for (let ix = 0; ix < gridX1; ix++) { const x3 = ix * segmentWidth - widthHalf; vector[u] = x3 * udir; vector[v] = y3 * vdir; vector[w] = depthHalf; vertices.push(vector.x, vector.y, vector.z); vector[u] = 0; vector[v] = 0; vector[w] = depth2 > 0 ? 1 : -1; normals.push(vector.x, vector.y, vector.z); uvs.push(ix / gridX); uvs.push(1 - iy / gridY); vertexCounter += 1; } } for (let iy = 0; iy < gridY; iy++) { for (let ix = 0; ix < gridX; ix++) { const a2 = numberOfVertices + ix + gridX1 * iy; const b = numberOfVertices + ix + gridX1 * (iy + 1); const c2 = numberOfVertices + (ix + 1) + gridX1 * (iy + 1); const d = numberOfVertices + (ix + 1) + gridX1 * iy; indices.push(a2, b, d); indices.push(b, c2, d); groupCount += 6; } } scope.addGroup(groupStart, groupCount, materialIndex); groupStart += groupCount; numberOfVertices += vertexCounter; } } copy(source) { super.copy(source); this.parameters = Object.assign({}, source.parameters); return this; } static fromJSON(data) { return new BoxGeometry(data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments); } }; function cloneUniforms(src) { const dst = {}; for (const u in src) { dst[u] = {}; for (const p in src[u]) { const property = src[u][p]; if (property && (property.isColor || property.isMatrix3 || property.isMatrix4 || property.isVector2 || property.isVector3 || property.isVector4 || property.isTexture || property.isQuaternion)) { if (property.isRenderTargetTexture) { console.warn("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms()."); dst[u][p] = null; } else { dst[u][p] = property.clone(); } } else if (Array.isArray(property)) { dst[u][p] = property.slice(); } else { dst[u][p] = property; } } } return dst; } function mergeUniforms(uniforms) { const merged = {}; for (let u = 0; u < uniforms.length; u++) { const tmp2 = cloneUniforms(uniforms[u]); for (const p in tmp2) { merged[p] = tmp2[p]; } } return merged; } function cloneUniformsGroups(src) { const dst = []; for (let u = 0; u < src.length; u++) { dst.push(src[u].clone()); } return dst; } function getUnlitUniformColorSpace(renderer3) { if (renderer3.getRenderTarget() === null) { return renderer3.outputColorSpace; } return ColorManagement.workingColorSpace; } var UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms }; var default_vertex = "void main() {\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}"; var default_fragment = "void main() {\n gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}"; var ShaderMaterial = class extends Material { constructor(parameters) { super(); this.isShaderMaterial = true; this.type = "ShaderMaterial"; this.defines = {}; this.uniforms = {}; this.uniformsGroups = []; this.vertexShader = default_vertex; this.fragmentShader = default_fragment; this.linewidth = 1; this.wireframe = false; this.wireframeLinewidth = 1; this.fog = false; this.lights = false; this.clipping = false; this.forceSinglePass = true; this.extensions = { derivatives: false, // set to use derivatives fragDepth: false, // set to use fragment depth values drawBuffers: false, // set to use draw buffers shaderTextureLOD: false // set to use shader texture LOD }; this.defaultAttributeValues = { "color": [1, 1, 1], "uv": [0, 0], "uv1": [0, 0] }; this.index0AttributeName = void 0; this.uniformsNeedUpdate = false; this.glslVersion = null; if (parameters !== void 0) { this.setValues(parameters); } } copy(source) { super.copy(source); this.fragmentShader = source.fragmentShader; this.vertexShader = source.vertexShader; this.uniforms = cloneUniforms(source.uniforms); this.uniformsGroups = cloneUniformsGroups(source.uniformsGroups); this.defines = Object.assign({}, source.defines); this.wireframe = source.wireframe; this.wireframeLinewidth = source.wireframeLinewidth; this.fog = source.fog; this.lights = source.lights; this.clipping = source.clipping; this.extensions = Object.assign({}, source.extensions); this.glslVersion = source.glslVersion; return this; } toJSON(meta) { const data = super.toJSON(meta); data.glslVersion = this.glslVersion; data.uniforms = {}; for (const name in this.uniforms) { const uniform = this.uniforms[name]; const value = uniform.value; if (value && value.isTexture) { data.uniforms[name] = { type: "t", value: value.toJSON(meta).uuid }; } else if (value && value.isColor) { data.uniforms[name] = { type: "c", value: value.getHex() }; } else if (value && value.isVector2) { data.uniforms[name] = { type: "v2", value: value.toArray() }; } else if (value && value.isVector3) { data.uniforms[name] = { type: "v3", value: value.toArray() }; } else if (value && value.isVector4) { data.uniforms[name] = { type: "v4", value: value.toArray() }; } else if (value && value.isMatrix3) { data.uniforms[name] = { type: "m3", value: value.toArray() }; } else if (value && value.isMatrix4) { data.uniforms[name] = { type: "m4", value: value.toArray() }; } else { data.uniforms[name] = { value }; } } if (Object.keys(this.defines).length > 0) data.defines = this.defines; data.vertexShader = this.vertexShader; data.fragmentShader = this.fragmentShader; data.lights = this.lights; data.clipping = this.clipping; const extensions = {}; for (const key in this.extensions) { if (this.extensions[key] === true) extensions[key] = true; } if (Object.keys(extensions).length > 0) data.extensions = extensions; return data; } }; var Camera = class extends Object3D { constructor() { super(); this.isCamera = true; this.type = "Camera"; this.matrixWorldInverse = new Matrix4(); this.projectionMatrix = new Matrix4(); this.projectionMatrixInverse = new Matrix4(); this.coordinateSystem = WebGLCoordinateSystem; } copy(source, recursive) { super.copy(source, recursive); this.matrixWorldInverse.copy(source.matrixWorldInverse); this.projectionMatrix.copy(source.projectionMatrix); this.projectionMatrixInverse.copy(source.projectionMatrixInverse); this.coordinateSystem = source.coordinateSystem; return this; } getWorldDirection(target) { return super.getWorldDirection(target).negate(); } updateMatrixWorld(force) { super.updateMatrixWorld(force); this.matrixWorldInverse.copy(this.matrixWorld).invert(); } updateWorldMatrix(updateParents, updateChildren) { super.updateWorldMatrix(updateParents, updateChildren); this.matrixWorldInverse.copy(this.matrixWorld).invert(); } clone() { return new this.constructor().copy(this); } }; var PerspectiveCamera = class extends Camera { constructor(fov3 = 50, aspect3 = 1, near = 0.1, far = 2e3) { super(); this.isPerspectiveCamera = true; this.type = "PerspectiveCamera"; this.fov = fov3; this.zoom = 1; this.near = near; this.far = far; this.focus = 10; this.aspect = aspect3; this.view = null; this.filmGauge = 35; this.filmOffset = 0; this.updateProjectionMatrix(); } copy(source, recursive) { super.copy(source, recursive); this.fov = source.fov; this.zoom = source.zoom; this.near = source.near; this.far = source.far; this.focus = source.focus; this.aspect = source.aspect; this.view = source.view === null ? null : Object.assign({}, source.view); this.filmGauge = source.filmGauge; this.filmOffset = source.filmOffset; return this; } /** * Sets the FOV by focal length in respect to the current .filmGauge. * * The default film gauge is 35, so that the focal length can be specified for * a 35mm (full frame) camera. * * Values for focal length and film gauge must have the same unit. */ setFocalLength(focalLength) { const vExtentSlope = 0.5 * this.getFilmHeight() / focalLength; this.fov = RAD2DEG * 2 * Math.atan(vExtentSlope); this.updateProjectionMatrix(); } /** * Calculates the focal length from the current .fov and .filmGauge. */ getFocalLength() { const vExtentSlope = Math.tan(DEG2RAD * 0.5 * this.fov); return 0.5 * this.getFilmHeight() / vExtentSlope; } getEffectiveFOV() { return RAD2DEG * 2 * Math.atan( Math.tan(DEG2RAD * 0.5 * this.fov) / this.zoom ); } getFilmWidth() { return this.filmGauge * Math.min(this.aspect, 1); } getFilmHeight() { return this.filmGauge / Math.max(this.aspect, 1); } /** * Sets an offset in a larger frustum. This is useful for multi-window or * multi-monitor/multi-machine setups. * * For example, if you have 3x2 monitors and each monitor is 1920x1080 and * the monitors are in grid like this * * +---+---+---+ * | A | B | C | * +---+---+---+ * | D | E | F | * +---+---+---+ * * then for each monitor you would call it like this * * const w = 1920; * const h = 1080; * const fullWidth = w * 3; * const fullHeight = h * 2; * * --A-- * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h ); * --B-- * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h ); * --C-- * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h ); * --D-- * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h ); * --E-- * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h ); * --F-- * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h ); * * Note there is no reason monitors have to be the same size or in a grid. */ setViewOffset(fullWidth, fullHeight, x3, y3, width, height) { this.aspect = fullWidth / fullHeight; if (this.view === null) { this.view = { enabled: true, fullWidth: 1, fullHeight: 1, offsetX: 0, offsetY: 0, width: 1, height: 1 }; } this.view.enabled = true; this.view.fullWidth = fullWidth; this.view.fullHeight = fullHeight; this.view.offsetX = x3; this.view.offsetY = y3; this.view.width = width; this.view.height = height; this.updateProjectionMatrix(); } clearViewOffset() { if (this.view !== null) { this.view.enabled = false; } this.updateProjectionMatrix(); } updateProjectionMatrix() { const near = this.near; let top = near * Math.tan(DEG2RAD * 0.5 * this.fov) / this.zoom; let height = 2 * top; let width = this.aspect * height; let left = -0.5 * width; const view = this.view; if (this.view !== null && this.view.enabled) { const fullWidth = view.fullWidth, fullHeight = view.fullHeight; left += view.offsetX * width / fullWidth; top -= view.offsetY * height / fullHeight; width *= view.width / fullWidth; height *= view.height / fullHeight; } const skew = this.filmOffset; if (skew !== 0) left += near * skew / this.getFilmWidth(); this.projectionMatrix.makePerspective(left, left + width, top, top - height, near, this.far, this.coordinateSystem); this.projectionMatrixInverse.copy(this.projectionMatrix).invert(); } toJSON(meta) { const data = super.toJSON(meta); data.object.fov = this.fov; data.object.zoom = this.zoom; data.object.near = this.near; data.object.far = this.far; data.object.focus = this.focus; data.object.aspect = this.aspect; if (this.view !== null) data.object.view = Object.assign({}, this.view); data.object.filmGauge = this.filmGauge; data.object.filmOffset = this.filmOffset; return data; } }; var fov = -90; var aspect = 1; var CubeCamera = class extends Object3D { constructor(near, far, renderTarget) { super(); this.type = "CubeCamera"; this.renderTarget = renderTarget; this.coordinateSystem = null; this.activeMipmapLevel = 0; const cameraPX = new PerspectiveCamera(fov, aspect, near, far); cameraPX.layers = this.layers; this.add(cameraPX); const cameraNX = new PerspectiveCamera(fov, aspect, near, far); cameraNX.layers = this.layers; this.add(cameraNX); const cameraPY = new PerspectiveCamera(fov, aspect, near, far); cameraPY.layers = this.layers; this.add(cameraPY); const cameraNY = new PerspectiveCamera(fov, aspect, near, far); cameraNY.layers = this.layers; this.add(cameraNY); const cameraPZ = new PerspectiveCamera(fov, aspect, near, far); cameraPZ.layers = this.layers; this.add(cameraPZ); const cameraNZ = new PerspectiveCamera(fov, aspect, near, far); cameraNZ.layers = this.layers; this.add(cameraNZ); } updateCoordinateSystem() { const coordinateSystem = this.coordinateSystem; const cameras = this.children.concat(); const [cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ] = cameras; for (const camera3 of cameras) this.remove(camera3); if (coordinateSystem === WebGLCoordinateSystem) { cameraPX.up.set(0, 1, 0); cameraPX.lookAt(1, 0, 0); cameraNX.up.set(0, 1, 0); cameraNX.lookAt(-1, 0, 0); cameraPY.up.set(0, 0, -1); cameraPY.lookAt(0, 1, 0); cameraNY.up.set(0, 0, 1); cameraNY.lookAt(0, -1, 0); cameraPZ.up.set(0, 1, 0); cameraPZ.lookAt(0, 0, 1); cameraNZ.up.set(0, 1, 0); cameraNZ.lookAt(0, 0, -1); } else if (coordinateSystem === WebGPUCoordinateSystem) { cameraPX.up.set(0, -1, 0); cameraPX.lookAt(-1, 0, 0); cameraNX.up.set(0, -1, 0); cameraNX.lookAt(1, 0, 0); cameraPY.up.set(0, 0, 1); cameraPY.lookAt(0, 1, 0); cameraNY.up.set(0, 0, -1); cameraNY.lookAt(0, -1, 0); cameraPZ.up.set(0, -1, 0); cameraPZ.lookAt(0, 0, 1); cameraNZ.up.set(0, -1, 0); cameraNZ.lookAt(0, 0, -1); } else { throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: " + coordinateSystem); } for (const camera3 of cameras) { this.add(camera3); camera3.updateMatrixWorld(); } } update(renderer3, scene3) { if (this.parent === null) this.updateMatrixWorld(); const { renderTarget, activeMipmapLevel } = this; if (this.coordinateSystem !== renderer3.coordinateSystem) { this.coordinateSystem = renderer3.coordinateSystem; this.updateCoordinateSystem(); } const [cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ] = this.children; const currentRenderTarget = renderer3.getRenderTarget(); const currentActiveCubeFace = renderer3.getActiveCubeFace(); const currentActiveMipmapLevel = renderer3.getActiveMipmapLevel(); const currentXrEnabled = renderer3.xr.enabled; renderer3.xr.enabled = false; const generateMipmaps = renderTarget.texture.generateMipmaps; renderTarget.texture.generateMipmaps = false; renderer3.setRenderTarget(renderTarget, 0, activeMipmapLevel); renderer3.render(scene3, cameraPX); renderer3.setRenderTarget(renderTarget, 1, activeMipmapLevel); renderer3.render(scene3, cameraNX); renderer3.setRenderTarget(renderTarget, 2, activeMipmapLevel); renderer3.render(scene3, cameraPY); renderer3.setRenderTarget(renderTarget, 3, activeMipmapLevel); renderer3.render(scene3, cameraNY); renderer3.setRenderTarget(renderTarget, 4, activeMipmapLevel); renderer3.render(scene3, cameraPZ); renderTarget.texture.generateMipmaps = generateMipmaps; renderer3.setRenderTarget(renderTarget, 5, activeMipmapLevel); renderer3.render(scene3, cameraNZ); renderer3.setRenderTarget(currentRenderTarget, currentActiveCubeFace, currentActiveMipmapLevel); renderer3.xr.enabled = currentXrEnabled; renderTarget.texture.needsPMREMUpdate = true; } }; var CubeTexture = class extends Texture { constructor(images, mapping, wrapS, wrapT, magFilter, minFilter, format2, type, anisotropy, colorSpace) { images = images !== void 0 ? images : []; mapping = mapping !== void 0 ? mapping : CubeReflectionMapping; super(images, mapping, wrapS, wrapT, magFilter, minFilter, format2, type, anisotropy, colorSpace); this.isCubeTexture = true; this.flipY = false; } get images() { return this.image; } set images(value) { this.image = value; } }; var WebGLCubeRenderTarget = class extends WebGLRenderTarget { constructor(size = 1, options = {}) { super(size, size, options); this.isWebGLCubeRenderTarget = true; const image = { width: size, height: size, depth: 1 }; const images = [image, image, image, image, image, image]; if (options.encoding !== void 0) { warnOnce("THREE.WebGLCubeRenderTarget: option.encoding has been replaced by option.colorSpace."); options.colorSpace = options.encoding === sRGBEncoding ? SRGBColorSpace : NoColorSpace; } this.texture = new CubeTexture(images, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace); this.texture.isRenderTargetTexture = true; this.texture.generateMipmaps = options.generateMipmaps !== void 0 ? options.generateMipmaps : false; this.texture.minFilter = options.minFilter !== void 0 ? options.minFilter : LinearFilter; } fromEquirectangularTexture(renderer3, texture) { this.texture.type = texture.type; this.texture.colorSpace = texture.colorSpace; this.texture.generateMipmaps = texture.generateMipmaps; this.texture.minFilter = texture.minFilter; this.texture.magFilter = texture.magFilter; const shader = { uniforms: { tEquirect: { value: null } }, vertexShader: ( /* glsl */ ` varying vec3 vWorldDirection; vec3 transformDirection( in vec3 dir, in mat4 matrix ) { return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz ); } void main() { vWorldDirection = transformDirection( position, modelMatrix ); #include #include } ` ), fragmentShader: ( /* glsl */ ` uniform sampler2D tEquirect; varying vec3 vWorldDirection; #include void main() { vec3 direction = normalize( vWorldDirection ); vec2 sampleUV = equirectUv( direction ); gl_FragColor = texture2D( tEquirect, sampleUV ); } ` ) }; const geometry = new BoxGeometry(5, 5, 5); const material = new ShaderMaterial({ name: "CubemapFromEquirect", uniforms: cloneUniforms(shader.uniforms), vertexShader: shader.vertexShader, fragmentShader: shader.fragmentShader, side: BackSide, blending: NoBlending }); material.uniforms.tEquirect.value = texture; const mesh = new Mesh(geometry, material); const currentMinFilter = texture.minFilter; if (texture.minFilter === LinearMipmapLinearFilter) texture.minFilter = LinearFilter; const camera3 = new CubeCamera(1, 10, this); camera3.update(renderer3, mesh); texture.minFilter = currentMinFilter; mesh.geometry.dispose(); mesh.material.dispose(); return this; } clear(renderer3, color, depth, stencil) { const currentRenderTarget = renderer3.getRenderTarget(); for (let i = 0; i < 6; i++) { renderer3.setRenderTarget(this, i); renderer3.clear(color, depth, stencil); } renderer3.setRenderTarget(currentRenderTarget); } }; var _vector1 = /* @__PURE__ */ new Vector3(); var _vector2 = /* @__PURE__ */ new Vector3(); var _normalMatrix = /* @__PURE__ */ new Matrix3(); var Plane = class { constructor(normal = new Vector3(1, 0, 0), constant = 0) { this.isPlane = true; this.normal = normal; this.constant = constant; } set(normal, constant) { this.normal.copy(normal); this.constant = constant; return this; } setComponents(x3, y3, z4, w) { this.normal.set(x3, y3, z4); this.constant = w; return this; } setFromNormalAndCoplanarPoint(normal, point) { this.normal.copy(normal); this.constant = -point.dot(this.normal); return this; } setFromCoplanarPoints(a2, b, c2) { const normal = _vector1.subVectors(c2, b).cross(_vector2.subVectors(a2, b)).normalize(); this.setFromNormalAndCoplanarPoint(normal, a2); return this; } copy(plane) { this.normal.copy(plane.normal); this.constant = plane.constant; return this; } normalize() { const inverseNormalLength = 1 / this.normal.length(); this.normal.multiplyScalar(inverseNormalLength); this.constant *= inverseNormalLength; return this; } negate() { this.constant *= -1; this.normal.negate(); return this; } distanceToPoint(point) { return this.normal.dot(point) + this.constant; } distanceToSphere(sphere) { return this.distanceToPoint(sphere.center) - sphere.radius; } projectPoint(point, target) { return target.copy(point).addScaledVector(this.normal, -this.distanceToPoint(point)); } intersectLine(line, target) { const direction = line.delta(_vector1); const denominator = this.normal.dot(direction); if (denominator === 0) { if (this.distanceToPoint(line.start) === 0) { return target.copy(line.start); } return null; } const t = -(line.start.dot(this.normal) + this.constant) / denominator; if (t < 0 || t > 1) { return null; } return target.copy(line.start).addScaledVector(direction, t); } intersectsLine(line) { const startSign = this.distanceToPoint(line.start); const endSign = this.distanceToPoint(line.end); return startSign < 0 && endSign > 0 || endSign < 0 && startSign > 0; } intersectsBox(box) { return box.intersectsPlane(this); } intersectsSphere(sphere) { return sphere.intersectsPlane(this); } coplanarPoint(target) { return target.copy(this.normal).multiplyScalar(-this.constant); } applyMatrix4(matrix, optionalNormalMatrix) { const normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix(matrix); const referencePoint = this.coplanarPoint(_vector1).applyMatrix4(matrix); const normal = this.normal.applyMatrix3(normalMatrix).normalize(); this.constant = -referencePoint.dot(normal); return this; } translate(offset) { this.constant -= offset.dot(this.normal); return this; } equals(plane) { return plane.normal.equals(this.normal) && plane.constant === this.constant; } clone() { return new this.constructor().copy(this); } }; var _sphere$4 = /* @__PURE__ */ new Sphere(); var _vector$6 = /* @__PURE__ */ new Vector3(); var Frustum = class { constructor(p0 = new Plane(), p1 = new Plane(), p2 = new Plane(), p3 = new Plane(), p4 = new Plane(), p5 = new Plane()) { this.planes = [p0, p1, p2, p3, p4, p5]; } set(p0, p1, p2, p3, p4, p5) { const planes = this.planes; planes[0].copy(p0); planes[1].copy(p1); planes[2].copy(p2); planes[3].copy(p3); planes[4].copy(p4); planes[5].copy(p5); return this; } copy(frustum) { const planes = this.planes; for (let i = 0; i < 6; i++) { planes[i].copy(frustum.planes[i]); } return this; } setFromProjectionMatrix(m2, coordinateSystem = WebGLCoordinateSystem) { const planes = this.planes; const me = m2.elements; const me0 = me[0], me1 = me[1], me2 = me[2], me3 = me[3]; const me4 = me[4], me5 = me[5], me6 = me[6], me7 = me[7]; const me8 = me[8], me9 = me[9], me10 = me[10], me11 = me[11]; const me12 = me[12], me13 = me[13], me14 = me[14], me15 = me[15]; planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize(); planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize(); planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize(); planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize(); planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize(); if (coordinateSystem === WebGLCoordinateSystem) { planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize(); } else if (coordinateSystem === WebGPUCoordinateSystem) { planes[5].setComponents(me2, me6, me10, me14).normalize(); } else { throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: " + coordinateSystem); } return this; } intersectsObject(object) { if (object.boundingSphere !== void 0) { if (object.boundingSphere === null) object.computeBoundingSphere(); _sphere$4.copy(object.boundingSphere).applyMatrix4(object.matrixWorld); } else { const geometry = object.geometry; if (geometry.boundingSphere === null) geometry.computeBoundingSphere(); _sphere$4.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld); } return this.intersectsSphere(_sphere$4); } intersectsSprite(sprite) { _sphere$4.center.set(0, 0, 0); _sphere$4.radius = 0.7071067811865476; _sphere$4.applyMatrix4(sprite.matrixWorld); return this.intersectsSphere(_sphere$4); } intersectsSphere(sphere) { const planes = this.planes; const center = sphere.center; const negRadius = -sphere.radius; for (let i = 0; i < 6; i++) { const distance = planes[i].distanceToPoint(center); if (distance < negRadius) { return false; } } return true; } intersectsBox(box) { const planes = this.planes; for (let i = 0; i < 6; i++) { const plane = planes[i]; _vector$6.x = plane.normal.x > 0 ? box.max.x : box.min.x; _vector$6.y = plane.normal.y > 0 ? box.max.y : box.min.y; _vector$6.z = plane.normal.z > 0 ? box.max.z : box.min.z; if (plane.distanceToPoint(_vector$6) < 0) { return false; } } return true; } containsPoint(point) { const planes = this.planes; for (let i = 0; i < 6; i++) { if (planes[i].distanceToPoint(point) < 0) { return false; } } return true; } clone() { return new this.constructor().copy(this); } }; function WebGLAnimation() { let context = null; let isAnimating = false; let animationLoop = null; let requestId = null; function onAnimationFrame(time, frame2) { animationLoop(time, frame2); requestId = context.requestAnimationFrame(onAnimationFrame); } return { start: function() { if (isAnimating === true) return; if (animationLoop === null) return; requestId = context.requestAnimationFrame(onAnimationFrame); isAnimating = true; }, stop: function() { context.cancelAnimationFrame(requestId); isAnimating = false; }, setAnimationLoop: function(callback) { animationLoop = callback; }, setContext: function(value) { context = value; } }; } function WebGLAttributes(gl, capabilities) { const isWebGL2 = capabilities.isWebGL2; const buffers = /* @__PURE__ */ new WeakMap(); function createBuffer(attribute, bufferType) { const array = attribute.array; const usage = attribute.usage; const buffer = gl.createBuffer(); gl.bindBuffer(bufferType, buffer); gl.bufferData(bufferType, array, usage); attribute.onUploadCallback(); let type; if (array instanceof Float32Array) { type = gl.FLOAT; } else if (array instanceof Uint16Array) { if (attribute.isFloat16BufferAttribute) { if (isWebGL2) { type = gl.HALF_FLOAT; } else { throw new Error("THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2."); } } else { type = gl.UNSIGNED_SHORT; } } else if (array instanceof Int16Array) { type = gl.SHORT; } else if (array instanceof Uint32Array) { type = gl.UNSIGNED_INT; } else if (array instanceof Int32Array) { type = gl.INT; } else if (array instanceof Int8Array) { type = gl.BYTE; } else if (array instanceof Uint8Array) { type = gl.UNSIGNED_BYTE; } else if (array instanceof Uint8ClampedArray) { type = gl.UNSIGNED_BYTE; } else { throw new Error("THREE.WebGLAttributes: Unsupported buffer data format: " + array); } return { buffer, type, bytesPerElement: array.BYTES_PER_ELEMENT, version: attribute.version }; } function updateBuffer(buffer, attribute, bufferType) { const array = attribute.array; const updateRange = attribute.updateRange; gl.bindBuffer(bufferType, buffer); if (updateRange.count === -1) { gl.bufferSubData(bufferType, 0, array); } else { if (isWebGL2) { gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array, updateRange.offset, updateRange.count ); } else { gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array.subarray(updateRange.offset, updateRange.offset + updateRange.count) ); } updateRange.count = -1; } attribute.onUploadCallback(); } function get2(attribute) { if (attribute.isInterleavedBufferAttribute) attribute = attribute.data; return buffers.get(attribute); } function remove2(attribute) { if (attribute.isInterleavedBufferAttribute) attribute = attribute.data; const data = buffers.get(attribute); if (data) { gl.deleteBuffer(data.buffer); buffers.delete(attribute); } } function update4(attribute, bufferType) { if (attribute.isGLBufferAttribute) { const cached = buffers.get(attribute); if (!cached || cached.version < attribute.version) { buffers.set(attribute, { buffer: attribute.buffer, type: attribute.type, bytesPerElement: attribute.elementSize, version: attribute.version }); } return; } if (attribute.isInterleavedBufferAttribute) attribute = attribute.data; const data = buffers.get(attribute); if (data === void 0) { buffers.set(attribute, createBuffer(attribute, bufferType)); } else if (data.version < attribute.version) { updateBuffer(data.buffer, attribute, bufferType); data.version = attribute.version; } } return { get: get2, remove: remove2, update: update4 }; } var PlaneGeometry = class extends BufferGeometry { constructor(width = 1, height = 1, widthSegments = 1, heightSegments = 1) { super(); this.type = "PlaneGeometry"; this.parameters = { width, height, widthSegments, heightSegments }; const width_half = width / 2; const height_half = height / 2; const gridX = Math.floor(widthSegments); const gridY = Math.floor(heightSegments); const gridX1 = gridX + 1; const gridY1 = gridY + 1; const segment_width = width / gridX; const segment_height = height / gridY; const indices = []; const vertices = []; const normals = []; const uvs = []; for (let iy = 0; iy < gridY1; iy++) { const y3 = iy * segment_height - height_half; for (let ix = 0; ix < gridX1; ix++) { const x3 = ix * segment_width - width_half; vertices.push(x3, -y3, 0); normals.push(0, 0, 1); uvs.push(ix / gridX); uvs.push(1 - iy / gridY); } } for (let iy = 0; iy < gridY; iy++) { for (let ix = 0; ix < gridX; ix++) { const a2 = ix + gridX1 * iy; const b = ix + gridX1 * (iy + 1); const c2 = ix + 1 + gridX1 * (iy + 1); const d = ix + 1 + gridX1 * iy; indices.push(a2, b, d); indices.push(b, c2, d); } } this.setIndex(indices); this.setAttribute("position", new Float32BufferAttribute(vertices, 3)); this.setAttribute("normal", new Float32BufferAttribute(normals, 3)); this.setAttribute("uv", new Float32BufferAttribute(uvs, 2)); } copy(source) { super.copy(source); this.parameters = Object.assign({}, source.parameters); return this; } static fromJSON(data) { return new PlaneGeometry(data.width, data.height, data.widthSegments, data.heightSegments); } }; var alphahash_fragment = "#ifdef USE_ALPHAHASH\n if ( diffuseColor.a < getAlphaHashThreshold( vPosition ) ) discard;\n#endif"; var alphahash_pars_fragment = "#ifdef USE_ALPHAHASH\n const float ALPHA_HASH_SCALE = 0.05;\n float hash2D( vec2 value ) {\n return fract( 1.0e4 * sin( 17.0 * value.x + 0.1 * value.y ) * ( 0.1 + abs( sin( 13.0 * value.y + value.x ) ) ) );\n }\n float hash3D( vec3 value ) {\n return hash2D( vec2( hash2D( value.xy ), value.z ) );\n }\n float getAlphaHashThreshold( vec3 position ) {\n float maxDeriv = max(\n length( dFdx( position.xyz ) ),\n length( dFdy( position.xyz ) )\n );\n float pixScale = 1.0 / ( ALPHA_HASH_SCALE * maxDeriv );\n vec2 pixScales = vec2(\n exp2( floor( log2( pixScale ) ) ),\n exp2( ceil( log2( pixScale ) ) )\n );\n vec2 alpha = vec2(\n hash3D( floor( pixScales.x * position.xyz ) ),\n hash3D( floor( pixScales.y * position.xyz ) )\n );\n float lerpFactor = fract( log2( pixScale ) );\n float x = ( 1.0 - lerpFactor ) * alpha.x + lerpFactor * alpha.y;\n float a = min( lerpFactor, 1.0 - lerpFactor );\n vec3 cases = vec3(\n x * x / ( 2.0 * a * ( 1.0 - a ) ),\n ( x - 0.5 * a ) / ( 1.0 - a ),\n 1.0 - ( ( 1.0 - x ) * ( 1.0 - x ) / ( 2.0 * a * ( 1.0 - a ) ) )\n );\n float threshold = ( x < ( 1.0 - a ) )\n ? ( ( x < a ) ? cases.x : cases.y )\n : cases.z;\n return clamp( threshold , 1.0e-6, 1.0 );\n }\n#endif"; var alphamap_fragment = "#ifdef USE_ALPHAMAP\n diffuseColor.a *= texture2D( alphaMap, vAlphaMapUv ).g;\n#endif"; var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n uniform sampler2D alphaMap;\n#endif"; var alphatest_fragment = "#ifdef USE_ALPHATEST\n if ( diffuseColor.a < alphaTest ) discard;\n#endif"; var alphatest_pars_fragment = "#ifdef USE_ALPHATEST\n uniform float alphaTest;\n#endif"; var aomap_fragment = "#ifdef USE_AOMAP\n float ambientOcclusion = ( texture2D( aoMap, vAoMapUv ).r - 1.0 ) * aoMapIntensity + 1.0;\n reflectedLight.indirectDiffuse *= ambientOcclusion;\n #if defined( USE_CLEARCOAT ) \n clearcoatSpecularIndirect *= ambientOcclusion;\n #endif\n #if defined( USE_SHEEN ) \n sheenSpecularIndirect *= ambientOcclusion;\n #endif\n #if defined( USE_ENVMAP ) && defined( STANDARD )\n float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );\n reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );\n #endif\n#endif"; var aomap_pars_fragment = "#ifdef USE_AOMAP\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n#endif"; var begin_vertex = "vec3 transformed = vec3( position );\n#ifdef USE_ALPHAHASH\n vPosition = vec3( position );\n#endif"; var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n vec3 objectTangent = vec3( tangent.xyz );\n#endif"; var bsdfs = "float G_BlinnPhong_Implicit( ) {\n return 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float shininess ) {\n vec3 halfDir = normalize( lightDir + viewDir );\n float dotNH = saturate( dot( normal, halfDir ) );\n float dotVH = saturate( dot( viewDir, halfDir ) );\n vec3 F = F_Schlick( specularColor, 1.0, dotVH );\n float G = G_BlinnPhong_Implicit( );\n float D = D_BlinnPhong( shininess, dotNH );\n return F * ( G * D );\n} // validated"; var iridescence_fragment = "#ifdef USE_IRIDESCENCE\n const mat3 XYZ_TO_REC709 = mat3(\n 3.2404542, -0.9692660, 0.0556434,\n -1.5371385, 1.8760108, -0.2040259,\n -0.4985314, 0.0415560, 1.0572252\n );\n vec3 Fresnel0ToIor( vec3 fresnel0 ) {\n vec3 sqrtF0 = sqrt( fresnel0 );\n return ( vec3( 1.0 ) + sqrtF0 ) / ( vec3( 1.0 ) - sqrtF0 );\n }\n vec3 IorToFresnel0( vec3 transmittedIor, float incidentIor ) {\n return pow2( ( transmittedIor - vec3( incidentIor ) ) / ( transmittedIor + vec3( incidentIor ) ) );\n }\n float IorToFresnel0( float transmittedIor, float incidentIor ) {\n return pow2( ( transmittedIor - incidentIor ) / ( transmittedIor + incidentIor ));\n }\n vec3 evalSensitivity( float OPD, vec3 shift ) {\n float phase = 2.0 * PI * OPD * 1.0e-9;\n vec3 val = vec3( 5.4856e-13, 4.4201e-13, 5.2481e-13 );\n vec3 pos = vec3( 1.6810e+06, 1.7953e+06, 2.2084e+06 );\n vec3 var = vec3( 4.3278e+09, 9.3046e+09, 6.6121e+09 );\n vec3 xyz = val * sqrt( 2.0 * PI * var ) * cos( pos * phase + shift ) * exp( - pow2( phase ) * var );\n xyz.x += 9.7470e-14 * sqrt( 2.0 * PI * 4.5282e+09 ) * cos( 2.2399e+06 * phase + shift[ 0 ] ) * exp( - 4.5282e+09 * pow2( phase ) );\n xyz /= 1.0685e-7;\n vec3 rgb = XYZ_TO_REC709 * xyz;\n return rgb;\n }\n vec3 evalIridescence( float outsideIOR, float eta2, float cosTheta1, float thinFilmThickness, vec3 baseF0 ) {\n vec3 I;\n float iridescenceIOR = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) );\n float sinTheta2Sq = pow2( outsideIOR / iridescenceIOR ) * ( 1.0 - pow2( cosTheta1 ) );\n float cosTheta2Sq = 1.0 - sinTheta2Sq;\n if ( cosTheta2Sq < 0.0 ) {\n return vec3( 1.0 );\n }\n float cosTheta2 = sqrt( cosTheta2Sq );\n float R0 = IorToFresnel0( iridescenceIOR, outsideIOR );\n float R12 = F_Schlick( R0, 1.0, cosTheta1 );\n float T121 = 1.0 - R12;\n float phi12 = 0.0;\n if ( iridescenceIOR < outsideIOR ) phi12 = PI;\n float phi21 = PI - phi12;\n vec3 baseIOR = Fresnel0ToIor( clamp( baseF0, 0.0, 0.9999 ) ); vec3 R1 = IorToFresnel0( baseIOR, iridescenceIOR );\n vec3 R23 = F_Schlick( R1, 1.0, cosTheta2 );\n vec3 phi23 = vec3( 0.0 );\n if ( baseIOR[ 0 ] < iridescenceIOR ) phi23[ 0 ] = PI;\n if ( baseIOR[ 1 ] < iridescenceIOR ) phi23[ 1 ] = PI;\n if ( baseIOR[ 2 ] < iridescenceIOR ) phi23[ 2 ] = PI;\n float OPD = 2.0 * iridescenceIOR * thinFilmThickness * cosTheta2;\n vec3 phi = vec3( phi21 ) + phi23;\n vec3 R123 = clamp( R12 * R23, 1e-5, 0.9999 );\n vec3 r123 = sqrt( R123 );\n vec3 Rs = pow2( T121 ) * R23 / ( vec3( 1.0 ) - R123 );\n vec3 C0 = R12 + Rs;\n I = C0;\n vec3 Cm = Rs - T121;\n for ( int m = 1; m <= 2; ++ m ) {\n Cm *= r123;\n vec3 Sm = 2.0 * evalSensitivity( float( m ) * OPD, float( m ) * phi );\n I += Cm * Sm;\n }\n return max( I, vec3( 0.0 ) );\n }\n#endif"; var bumpmap_pars_fragment = "#ifdef USE_BUMPMAP\n uniform sampler2D bumpMap;\n uniform float bumpScale;\n vec2 dHdxy_fwd() {\n vec2 dSTdx = dFdx( vBumpMapUv );\n vec2 dSTdy = dFdy( vBumpMapUv );\n float Hll = bumpScale * texture2D( bumpMap, vBumpMapUv ).x;\n float dBx = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdx ).x - Hll;\n float dBy = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdy ).x - Hll;\n return vec2( dBx, dBy );\n }\n vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {\n vec3 vSigmaX = normalize( dFdx( surf_pos.xyz ) );\n vec3 vSigmaY = normalize( dFdy( surf_pos.xyz ) );\n vec3 vN = surf_norm;\n vec3 R1 = cross( vSigmaY, vN );\n vec3 R2 = cross( vN, vSigmaX );\n float fDet = dot( vSigmaX, R1 ) * faceDirection;\n vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n return normalize( abs( fDet ) * surf_norm - vGrad );\n }\n#endif"; var clipping_planes_fragment = "#if NUM_CLIPPING_PLANES > 0\n vec4 plane;\n #pragma unroll_loop_start\n for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n if ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;\n }\n #pragma unroll_loop_end\n #if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n #pragma unroll_loop_start\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;\n }\n #pragma unroll_loop_end\n if ( clipped ) discard;\n #endif\n#endif"; var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n varying vec3 vClipPosition;\n uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif"; var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n varying vec3 vClipPosition;\n#endif"; var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n vClipPosition = - mvPosition.xyz;\n#endif"; var color_fragment = "#if defined( USE_COLOR_ALPHA )\n diffuseColor *= vColor;\n#elif defined( USE_COLOR )\n diffuseColor.rgb *= vColor;\n#endif"; var color_pars_fragment = "#if defined( USE_COLOR_ALPHA )\n varying vec4 vColor;\n#elif defined( USE_COLOR )\n varying vec3 vColor;\n#endif"; var color_pars_vertex = "#if defined( USE_COLOR_ALPHA )\n varying vec4 vColor;\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n varying vec3 vColor;\n#endif"; var color_vertex = "#if defined( USE_COLOR_ALPHA )\n vColor = vec4( 1.0 );\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n vColor = vec3( 1.0 );\n#endif\n#ifdef USE_COLOR\n vColor *= color;\n#endif\n#ifdef USE_INSTANCING_COLOR\n vColor.xyz *= instanceColor.xyz;\n#endif"; var common = "#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement( a ) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nvec3 pow2( const in vec3 x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }\nfloat average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); }\nhighp float rand( const in vec2 uv ) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n return fract( sin( sn ) * c );\n}\n#ifdef HIGH_PRECISION\n float precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n float precisionSafeLength( vec3 v ) {\n float maxComponent = max3( abs( v ) );\n return length( v / maxComponent ) * maxComponent;\n }\n#endif\nstruct IncidentLight {\n vec3 color;\n vec3 direction;\n bool visible;\n};\nstruct ReflectedLight {\n vec3 directDiffuse;\n vec3 directSpecular;\n vec3 indirectDiffuse;\n vec3 indirectSpecular;\n};\n#ifdef USE_ALPHAHASH\n varying vec3 vPosition;\n#endif\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nmat3 transposeMat3( const in mat3 m ) {\n mat3 tmp;\n tmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n tmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n tmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n return tmp;\n}\nfloat luminance( const in vec3 rgb ) {\n const vec3 weights = vec3( 0.2126729, 0.7151522, 0.0721750 );\n return dot( weights, rgb );\n}\nbool isPerspectiveMatrix( mat4 m ) {\n return m[ 2 ][ 3 ] == - 1.0;\n}\nvec2 equirectUv( in vec3 dir ) {\n float u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;\n float v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n return vec2( u, v );\n}\nvec3 BRDF_Lambert( const in vec3 diffuseColor ) {\n return RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {\n float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n}\nfloat F_Schlick( const in float f0, const in float f90, const in float dotVH ) {\n float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n} // validated"; var cube_uv_reflection_fragment = "#ifdef ENVMAP_TYPE_CUBE_UV\n #define cubeUV_minMipLevel 4.0\n #define cubeUV_minTileSize 16.0\n float getFace( vec3 direction ) {\n vec3 absDirection = abs( direction );\n float face = - 1.0;\n if ( absDirection.x > absDirection.z ) {\n if ( absDirection.x > absDirection.y )\n face = direction.x > 0.0 ? 0.0 : 3.0;\n else\n face = direction.y > 0.0 ? 1.0 : 4.0;\n } else {\n if ( absDirection.z > absDirection.y )\n face = direction.z > 0.0 ? 2.0 : 5.0;\n else\n face = direction.y > 0.0 ? 1.0 : 4.0;\n }\n return face;\n }\n vec2 getUV( vec3 direction, float face ) {\n vec2 uv;\n if ( face == 0.0 ) {\n uv = vec2( direction.z, direction.y ) / abs( direction.x );\n } else if ( face == 1.0 ) {\n uv = vec2( - direction.x, - direction.z ) / abs( direction.y );\n } else if ( face == 2.0 ) {\n uv = vec2( - direction.x, direction.y ) / abs( direction.z );\n } else if ( face == 3.0 ) {\n uv = vec2( - direction.z, direction.y ) / abs( direction.x );\n } else if ( face == 4.0 ) {\n uv = vec2( - direction.x, direction.z ) / abs( direction.y );\n } else {\n uv = vec2( direction.x, direction.y ) / abs( direction.z );\n }\n return 0.5 * ( uv + 1.0 );\n }\n vec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {\n float face = getFace( direction );\n float filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );\n mipInt = max( mipInt, cubeUV_minMipLevel );\n float faceSize = exp2( mipInt );\n highp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0;\n if ( face > 2.0 ) {\n uv.y += faceSize;\n face -= 3.0;\n }\n uv.x += face * faceSize;\n uv.x += filterInt * 3.0 * cubeUV_minTileSize;\n uv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize );\n uv.x *= CUBEUV_TEXEL_WIDTH;\n uv.y *= CUBEUV_TEXEL_HEIGHT;\n #ifdef texture2DGradEXT\n return texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb;\n #else\n return texture2D( envMap, uv ).rgb;\n #endif\n }\n #define cubeUV_r0 1.0\n #define cubeUV_v0 0.339\n #define cubeUV_m0 - 2.0\n #define cubeUV_r1 0.8\n #define cubeUV_v1 0.276\n #define cubeUV_m1 - 1.0\n #define cubeUV_r4 0.4\n #define cubeUV_v4 0.046\n #define cubeUV_m4 2.0\n #define cubeUV_r5 0.305\n #define cubeUV_v5 0.016\n #define cubeUV_m5 3.0\n #define cubeUV_r6 0.21\n #define cubeUV_v6 0.0038\n #define cubeUV_m6 4.0\n float roughnessToMip( float roughness ) {\n float mip = 0.0;\n if ( roughness >= cubeUV_r1 ) {\n mip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0;\n } else if ( roughness >= cubeUV_r4 ) {\n mip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1;\n } else if ( roughness >= cubeUV_r5 ) {\n mip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4;\n } else if ( roughness >= cubeUV_r6 ) {\n mip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5;\n } else {\n mip = - 2.0 * log2( 1.16 * roughness ); }\n return mip;\n }\n vec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {\n float mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP );\n float mipF = fract( mip );\n float mipInt = floor( mip );\n vec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );\n if ( mipF == 0.0 ) {\n return vec4( color0, 1.0 );\n } else {\n vec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );\n return vec4( mix( color0, color1, mipF ), 1.0 );\n }\n }\n#endif"; var defaultnormal_vertex = "vec3 transformedNormal = objectNormal;\n#ifdef USE_INSTANCING\n mat3 m = mat3( instanceMatrix );\n transformedNormal /= vec3( dot( m[ 0 ], m[ 0 ] ), dot( m[ 1 ], m[ 1 ] ), dot( m[ 2 ], m[ 2 ] ) );\n transformedNormal = m * transformedNormal;\n#endif\ntransformedNormal = normalMatrix * transformedNormal;\n#ifdef FLIP_SIDED\n transformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n vec3 transformedTangent = ( modelViewMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n #ifdef FLIP_SIDED\n transformedTangent = - transformedTangent;\n #endif\n#endif"; var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n uniform sampler2D displacementMap;\n uniform float displacementScale;\n uniform float displacementBias;\n#endif"; var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n transformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias );\n#endif"; var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n vec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );\n totalEmissiveRadiance *= emissiveColor.rgb;\n#endif"; var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n uniform sampler2D emissiveMap;\n#endif"; var colorspace_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );"; var colorspace_pars_fragment = "\nconst mat3 LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 = mat3(\n vec3( 0.8224621, 0.177538, 0.0 ),\n vec3( 0.0331941, 0.9668058, 0.0 ),\n vec3( 0.0170827, 0.0723974, 0.9105199 )\n);\nconst mat3 LINEAR_DISPLAY_P3_TO_LINEAR_SRGB = mat3(\n vec3( 1.2249401, - 0.2249404, 0.0 ),\n vec3( - 0.0420569, 1.0420571, 0.0 ),\n vec3( - 0.0196376, - 0.0786361, 1.0982735 )\n);\nvec4 LinearSRGBToLinearDisplayP3( in vec4 value ) {\n return vec4( value.rgb * LINEAR_SRGB_TO_LINEAR_DISPLAY_P3, value.a );\n}\nvec4 LinearDisplayP3ToLinearSRGB( in vec4 value ) {\n return vec4( value.rgb * LINEAR_DISPLAY_P3_TO_LINEAR_SRGB, value.a );\n}\nvec4 LinearTransferOETF( in vec4 value ) {\n return value;\n}\nvec4 sRGBTransferOETF( in vec4 value ) {\n return vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );\n}\nvec4 LinearToLinear( in vec4 value ) {\n return value;\n}\nvec4 LinearTosRGB( in vec4 value ) {\n return sRGBTransferOETF( value );\n}"; var envmap_fragment = "#ifdef USE_ENVMAP\n #ifdef ENV_WORLDPOS\n vec3 cameraToFrag;\n if ( isOrthographic ) {\n cameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n } else {\n cameraToFrag = normalize( vWorldPosition - cameraPosition );\n }\n vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n #ifdef ENVMAP_MODE_REFLECTION\n vec3 reflectVec = reflect( cameraToFrag, worldNormal );\n #else\n vec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n #endif\n #else\n vec3 reflectVec = vReflect;\n #endif\n #ifdef ENVMAP_TYPE_CUBE\n vec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n #else\n vec4 envColor = vec4( 0.0 );\n #endif\n #ifdef ENVMAP_BLENDING_MULTIPLY\n outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n #elif defined( ENVMAP_BLENDING_MIX )\n outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n #elif defined( ENVMAP_BLENDING_ADD )\n outgoingLight += envColor.xyz * specularStrength * reflectivity;\n #endif\n#endif"; var envmap_common_pars_fragment = "#ifdef USE_ENVMAP\n uniform float envMapIntensity;\n uniform float flipEnvMap;\n #ifdef ENVMAP_TYPE_CUBE\n uniform samplerCube envMap;\n #else\n uniform sampler2D envMap;\n #endif\n \n#endif"; var envmap_pars_fragment = "#ifdef USE_ENVMAP\n uniform float reflectivity;\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\n #define ENV_WORLDPOS\n #endif\n #ifdef ENV_WORLDPOS\n varying vec3 vWorldPosition;\n uniform float refractionRatio;\n #else\n varying vec3 vReflect;\n #endif\n#endif"; var envmap_pars_vertex = "#ifdef USE_ENVMAP\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\n #define ENV_WORLDPOS\n #endif\n #ifdef ENV_WORLDPOS\n \n varying vec3 vWorldPosition;\n #else\n varying vec3 vReflect;\n uniform float refractionRatio;\n #endif\n#endif"; var envmap_vertex = "#ifdef USE_ENVMAP\n #ifdef ENV_WORLDPOS\n vWorldPosition = worldPosition.xyz;\n #else\n vec3 cameraToVertex;\n if ( isOrthographic ) {\n cameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n } else {\n cameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n }\n vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n #ifdef ENVMAP_MODE_REFLECTION\n vReflect = reflect( cameraToVertex, worldNormal );\n #else\n vReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n #endif\n #endif\n#endif"; var fog_vertex = "#ifdef USE_FOG\n vFogDepth = - mvPosition.z;\n#endif"; var fog_pars_vertex = "#ifdef USE_FOG\n varying float vFogDepth;\n#endif"; var fog_fragment = "#ifdef USE_FOG\n #ifdef FOG_EXP2\n float fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );\n #else\n float fogFactor = smoothstep( fogNear, fogFar, vFogDepth );\n #endif\n gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif"; var fog_pars_fragment = "#ifdef USE_FOG\n uniform vec3 fogColor;\n varying float vFogDepth;\n #ifdef FOG_EXP2\n uniform float fogDensity;\n #else\n uniform float fogNear;\n uniform float fogFar;\n #endif\n#endif"; var gradientmap_pars_fragment = "#ifdef USE_GRADIENTMAP\n uniform sampler2D gradientMap;\n#endif\nvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n float dotNL = dot( normal, lightDirection );\n vec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n #ifdef USE_GRADIENTMAP\n return vec3( texture2D( gradientMap, coord ).r );\n #else\n vec2 fw = fwidth( coord ) * 0.5;\n return mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) );\n #endif\n}"; var lightmap_fragment = "#ifdef USE_LIGHTMAP\n vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n reflectedLight.indirectDiffuse += lightMapIrradiance;\n#endif"; var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n#endif"; var lights_lambert_fragment = "LambertMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularStrength = specularStrength;"; var lights_lambert_pars_fragment = "varying vec3 vViewPosition;\nstruct LambertMaterial {\n vec3 diffuseColor;\n float specularStrength;\n};\nvoid RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {\n float dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n vec3 irradiance = dotNL * directLight.color;\n reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct RE_Direct_Lambert\n#define RE_IndirectDiffuse RE_IndirectDiffuse_Lambert"; var lights_pars_begin = "uniform bool receiveShadow;\nuniform vec3 ambientLightColor;\n#if defined( USE_LIGHT_PROBES )\n uniform vec3 lightProbe[ 9 ];\n#endif\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\n float x = normal.x, y = normal.y, z = normal.z;\n vec3 result = shCoefficients[ 0 ] * 0.886227;\n result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\n result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\n result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\n result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\n result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\n result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\n result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\n result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\n return result;\n}\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {\n vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n vec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n return irradiance;\n}\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n vec3 irradiance = ambientLightColor;\n return irradiance;\n}\nfloat getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n #if defined ( LEGACY_LIGHTS )\n if ( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n return pow( saturate( - lightDistance / cutoffDistance + 1.0 ), decayExponent );\n }\n return 1.0;\n #else\n float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n if ( cutoffDistance > 0.0 ) {\n distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n }\n return distanceFalloff;\n #endif\n}\nfloat getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {\n return smoothstep( coneCosine, penumbraCosine, angleCosine );\n}\n#if NUM_DIR_LIGHTS > 0\n struct DirectionalLight {\n vec3 direction;\n vec3 color;\n };\n uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n void getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) {\n light.color = directionalLight.color;\n light.direction = directionalLight.direction;\n light.visible = true;\n }\n#endif\n#if NUM_POINT_LIGHTS > 0\n struct PointLight {\n vec3 position;\n vec3 color;\n float distance;\n float decay;\n };\n uniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n void getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) {\n vec3 lVector = pointLight.position - geometryPosition;\n light.direction = normalize( lVector );\n float lightDistance = length( lVector );\n light.color = pointLight.color;\n light.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );\n light.visible = ( light.color != vec3( 0.0 ) );\n }\n#endif\n#if NUM_SPOT_LIGHTS > 0\n struct SpotLight {\n vec3 position;\n vec3 direction;\n vec3 color;\n float distance;\n float decay;\n float coneCos;\n float penumbraCos;\n };\n uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n void getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) {\n vec3 lVector = spotLight.position - geometryPosition;\n light.direction = normalize( lVector );\n float angleCos = dot( light.direction, spotLight.direction );\n float spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n if ( spotAttenuation > 0.0 ) {\n float lightDistance = length( lVector );\n light.color = spotLight.color * spotAttenuation;\n light.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );\n light.visible = ( light.color != vec3( 0.0 ) );\n } else {\n light.color = vec3( 0.0 );\n light.visible = false;\n }\n }\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n struct RectAreaLight {\n vec3 color;\n vec3 position;\n vec3 halfWidth;\n vec3 halfHeight;\n };\n uniform sampler2D ltc_1; uniform sampler2D ltc_2;\n uniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n struct HemisphereLight {\n vec3 direction;\n vec3 skyColor;\n vec3 groundColor;\n };\n uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {\n float dotNL = dot( normal, hemiLight.direction );\n float hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n return irradiance;\n }\n#endif"; var envmap_physical_pars_fragment = "#ifdef USE_ENVMAP\n vec3 getIBLIrradiance( const in vec3 normal ) {\n #ifdef ENVMAP_TYPE_CUBE_UV\n vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n vec4 envMapColor = textureCubeUV( envMap, worldNormal, 1.0 );\n return PI * envMapColor.rgb * envMapIntensity;\n #else\n return vec3( 0.0 );\n #endif\n }\n vec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {\n #ifdef ENVMAP_TYPE_CUBE_UV\n vec3 reflectVec = reflect( - viewDir, normal );\n reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n reflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n vec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );\n return envMapColor.rgb * envMapIntensity;\n #else\n return vec3( 0.0 );\n #endif\n }\n #ifdef USE_ANISOTROPY\n vec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {\n #ifdef ENVMAP_TYPE_CUBE_UV\n vec3 bentNormal = cross( bitangent, viewDir );\n bentNormal = normalize( cross( bentNormal, bitangent ) );\n bentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );\n return getIBLRadiance( viewDir, bentNormal, roughness );\n #else\n return vec3( 0.0 );\n #endif\n }\n #endif\n#endif"; var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;"; var lights_toon_pars_fragment = "varying vec3 vViewPosition;\nstruct ToonMaterial {\n vec3 diffuseColor;\n};\nvoid RE_Direct_Toon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n vec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color;\n reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct RE_Direct_Toon\n#define RE_IndirectDiffuse RE_IndirectDiffuse_Toon"; var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;"; var lights_phong_pars_fragment = "varying vec3 vViewPosition;\nstruct BlinnPhongMaterial {\n vec3 diffuseColor;\n vec3 specularColor;\n float specularShininess;\n float specularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n float dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n vec3 irradiance = dotNL * directLight.color;\n reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct RE_Direct_BlinnPhong\n#define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong"; var lights_physical_fragment = "PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nvec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\nmaterial.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;\nmaterial.roughness = min( material.roughness, 1.0 );\n#ifdef IOR\n material.ior = ior;\n #ifdef USE_SPECULAR\n float specularIntensityFactor = specularIntensity;\n vec3 specularColorFactor = specularColor;\n #ifdef USE_SPECULAR_COLORMAP\n specularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb;\n #endif\n #ifdef USE_SPECULAR_INTENSITYMAP\n specularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a;\n #endif\n material.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );\n #else\n float specularIntensityFactor = 1.0;\n vec3 specularColorFactor = vec3( 1.0 );\n material.specularF90 = 1.0;\n #endif\n material.specularColor = mix( min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor );\n#else\n material.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );\n material.specularF90 = 1.0;\n#endif\n#ifdef USE_CLEARCOAT\n material.clearcoat = clearcoat;\n material.clearcoatRoughness = clearcoatRoughness;\n material.clearcoatF0 = vec3( 0.04 );\n material.clearcoatF90 = 1.0;\n #ifdef USE_CLEARCOATMAP\n material.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x;\n #endif\n #ifdef USE_CLEARCOAT_ROUGHNESSMAP\n material.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y;\n #endif\n material.clearcoat = saturate( material.clearcoat ); material.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );\n material.clearcoatRoughness += geometryRoughness;\n material.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\n#endif\n#ifdef USE_IRIDESCENCE\n material.iridescence = iridescence;\n material.iridescenceIOR = iridescenceIOR;\n #ifdef USE_IRIDESCENCEMAP\n material.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r;\n #endif\n #ifdef USE_IRIDESCENCE_THICKNESSMAP\n material.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum;\n #else\n material.iridescenceThickness = iridescenceThicknessMaximum;\n #endif\n#endif\n#ifdef USE_SHEEN\n material.sheenColor = sheenColor;\n #ifdef USE_SHEEN_COLORMAP\n material.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb;\n #endif\n material.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );\n #ifdef USE_SHEEN_ROUGHNESSMAP\n material.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a;\n #endif\n#endif\n#ifdef USE_ANISOTROPY\n #ifdef USE_ANISOTROPYMAP\n mat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x );\n vec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb;\n vec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b;\n #else\n vec2 anisotropyV = anisotropyVector;\n #endif\n material.anisotropy = length( anisotropyV );\n anisotropyV /= material.anisotropy;\n material.anisotropy = saturate( material.anisotropy );\n material.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) );\n material.anisotropyT = tbn[ 0 ] * anisotropyV.x - tbn[ 1 ] * anisotropyV.y;\n material.anisotropyB = tbn[ 1 ] * anisotropyV.x + tbn[ 0 ] * anisotropyV.y;\n#endif"; var lights_physical_pars_fragment = "struct PhysicalMaterial {\n vec3 diffuseColor;\n float roughness;\n vec3 specularColor;\n float specularF90;\n #ifdef USE_CLEARCOAT\n float clearcoat;\n float clearcoatRoughness;\n vec3 clearcoatF0;\n float clearcoatF90;\n #endif\n #ifdef USE_IRIDESCENCE\n float iridescence;\n float iridescenceIOR;\n float iridescenceThickness;\n vec3 iridescenceFresnel;\n vec3 iridescenceF0;\n #endif\n #ifdef USE_SHEEN\n vec3 sheenColor;\n float sheenRoughness;\n #endif\n #ifdef IOR\n float ior;\n #endif\n #ifdef USE_TRANSMISSION\n float transmission;\n float transmissionAlpha;\n float thickness;\n float attenuationDistance;\n vec3 attenuationColor;\n #endif\n #ifdef USE_ANISOTROPY\n float anisotropy;\n float alphaT;\n vec3 anisotropyT;\n vec3 anisotropyB;\n #endif\n};\nvec3 clearcoatSpecularDirect = vec3( 0.0 );\nvec3 clearcoatSpecularIndirect = vec3( 0.0 );\nvec3 sheenSpecularDirect = vec3( 0.0 );\nvec3 sheenSpecularIndirect = vec3(0.0 );\nvec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) {\n float x = clamp( 1.0 - dotVH, 0.0, 1.0 );\n float x2 = x * x;\n float x5 = clamp( x * x2 * x2, 0.0, 0.9999 );\n return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );\n}\nfloat V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n float a2 = pow2( alpha );\n float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n return 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n float a2 = pow2( alpha );\n float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n return RECIPROCAL_PI * a2 / pow2( denom );\n}\n#ifdef USE_ANISOTROPY\n float V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) {\n float gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) );\n float gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) );\n float v = 0.5 / ( gv + gl );\n return saturate(v);\n }\n float D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) {\n float a2 = alphaT * alphaB;\n highp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH );\n highp float v2 = dot( v, v );\n float w2 = a2 / v2;\n return RECIPROCAL_PI * a2 * pow2 ( w2 );\n }\n#endif\n#ifdef USE_CLEARCOAT\n vec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) {\n vec3 f0 = material.clearcoatF0;\n float f90 = material.clearcoatF90;\n float roughness = material.clearcoatRoughness;\n float alpha = pow2( roughness );\n vec3 halfDir = normalize( lightDir + viewDir );\n float dotNL = saturate( dot( normal, lightDir ) );\n float dotNV = saturate( dot( normal, viewDir ) );\n float dotNH = saturate( dot( normal, halfDir ) );\n float dotVH = saturate( dot( viewDir, halfDir ) );\n vec3 F = F_Schlick( f0, f90, dotVH );\n float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n float D = D_GGX( alpha, dotNH );\n return F * ( V * D );\n }\n#endif\nvec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {\n vec3 f0 = material.specularColor;\n float f90 = material.specularF90;\n float roughness = material.roughness;\n float alpha = pow2( roughness );\n vec3 halfDir = normalize( lightDir + viewDir );\n float dotNL = saturate( dot( normal, lightDir ) );\n float dotNV = saturate( dot( normal, viewDir ) );\n float dotNH = saturate( dot( normal, halfDir ) );\n float dotVH = saturate( dot( viewDir, halfDir ) );\n vec3 F = F_Schlick( f0, f90, dotVH );\n #ifdef USE_IRIDESCENCE\n F = mix( F, material.iridescenceFresnel, material.iridescence );\n #endif\n #ifdef USE_ANISOTROPY\n float dotTL = dot( material.anisotropyT, lightDir );\n float dotTV = dot( material.anisotropyT, viewDir );\n float dotTH = dot( material.anisotropyT, halfDir );\n float dotBL = dot( material.anisotropyB, lightDir );\n float dotBV = dot( material.anisotropyB, viewDir );\n float dotBH = dot( material.anisotropyB, halfDir );\n float V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL );\n float D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH );\n #else\n float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n float D = D_GGX( alpha, dotNH );\n #endif\n return F * ( V * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n const float LUT_SIZE = 64.0;\n const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n const float LUT_BIAS = 0.5 / LUT_SIZE;\n float dotNV = saturate( dot( N, V ) );\n vec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n uv = uv * LUT_SCALE + LUT_BIAS;\n return uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n float l = length( f );\n return max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n float x = dot( v1, v2 );\n float y = abs( x );\n float a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n float b = 3.4175940 + ( 4.1616724 + y ) * y;\n float v = a / b;\n float theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n return cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n vec3 lightNormal = cross( v1, v2 );\n if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n vec3 T1, T2;\n T1 = normalize( V - N * dot( V, N ) );\n T2 = - cross( N, T1 );\n mat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n vec3 coords[ 4 ];\n coords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n coords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n coords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n coords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n coords[ 0 ] = normalize( coords[ 0 ] );\n coords[ 1 ] = normalize( coords[ 1 ] );\n coords[ 2 ] = normalize( coords[ 2 ] );\n coords[ 3 ] = normalize( coords[ 3 ] );\n vec3 vectorFormFactor = vec3( 0.0 );\n vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n float result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n return vec3( result );\n}\n#if defined( USE_SHEEN )\nfloat D_Charlie( float roughness, float dotNH ) {\n float alpha = pow2( roughness );\n float invAlpha = 1.0 / alpha;\n float cos2h = dotNH * dotNH;\n float sin2h = max( 1.0 - cos2h, 0.0078125 );\n return ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );\n}\nfloat V_Neubelt( float dotNV, float dotNL ) {\n return saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );\n}\nvec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {\n vec3 halfDir = normalize( lightDir + viewDir );\n float dotNL = saturate( dot( normal, lightDir ) );\n float dotNV = saturate( dot( normal, viewDir ) );\n float dotNH = saturate( dot( normal, halfDir ) );\n float D = D_Charlie( sheenRoughness, dotNH );\n float V = V_Neubelt( dotNV, dotNL );\n return sheenColor * ( D * V );\n}\n#endif\nfloat IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n float dotNV = saturate( dot( normal, viewDir ) );\n float r2 = roughness * roughness;\n float a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95;\n float b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72;\n float DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) );\n return saturate( DG * RECIPROCAL_PI );\n}\nvec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n float dotNV = saturate( dot( normal, viewDir ) );\n const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n vec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw;\n return fab;\n}\nvec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {\n vec2 fab = DFGApprox( normal, viewDir, roughness );\n return specularColor * fab.x + specularF90 * fab.y;\n}\n#ifdef USE_IRIDESCENCE\nvoid computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#else\nvoid computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#endif\n vec2 fab = DFGApprox( normal, viewDir, roughness );\n #ifdef USE_IRIDESCENCE\n vec3 Fr = mix( specularColor, iridescenceF0, iridescence );\n #else\n vec3 Fr = specularColor;\n #endif\n vec3 FssEss = Fr * fab.x + specularF90 * fab.y;\n float Ess = fab.x + fab.y;\n float Ems = 1.0 - Ess;\n vec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619; vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n singleScatter += FssEss;\n multiScatter += Fms * Ems;\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n void RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n vec3 normal = geometryNormal;\n vec3 viewDir = geometryViewDir;\n vec3 position = geometryPosition;\n vec3 lightPos = rectAreaLight.position;\n vec3 halfWidth = rectAreaLight.halfWidth;\n vec3 halfHeight = rectAreaLight.halfHeight;\n vec3 lightColor = rectAreaLight.color;\n float roughness = material.roughness;\n vec3 rectCoords[ 4 ];\n rectCoords[ 0 ] = lightPos + halfWidth - halfHeight; rectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n rectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n rectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n vec2 uv = LTC_Uv( normal, viewDir, roughness );\n vec4 t1 = texture2D( ltc_1, uv );\n vec4 t2 = texture2D( ltc_2, uv );\n mat3 mInv = mat3(\n vec3( t1.x, 0, t1.y ),\n vec3( 0, 1, 0 ),\n vec3( t1.z, 0, t1.w )\n );\n vec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\n reflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n reflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n }\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n float dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n vec3 irradiance = dotNL * directLight.color;\n #ifdef USE_CLEARCOAT\n float dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) );\n vec3 ccIrradiance = dotNLcc * directLight.color;\n clearcoatSpecularDirect += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );\n #endif\n #ifdef USE_SHEEN\n sheenSpecularDirect += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness );\n #endif\n reflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometryViewDir, geometryNormal, material );\n reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n #ifdef USE_CLEARCOAT\n clearcoatSpecularIndirect += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n #endif\n #ifdef USE_SHEEN\n sheenSpecularIndirect += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );\n #endif\n vec3 singleScattering = vec3( 0.0 );\n vec3 multiScattering = vec3( 0.0 );\n vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n #ifdef USE_IRIDESCENCE\n computeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnel, material.roughness, singleScattering, multiScattering );\n #else\n computeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering );\n #endif\n vec3 totalScattering = singleScattering + multiScattering;\n vec3 diffuse = material.diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );\n reflectedLight.indirectSpecular += radiance * singleScattering;\n reflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;\n reflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n}\n#define RE_Direct RE_Direct_Physical\n#define RE_Direct_RectArea RE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse RE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular RE_IndirectSpecular_Physical\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}"; var lights_fragment_begin = "\nvec3 geometryPosition = - vViewPosition;\nvec3 geometryNormal = normal;\nvec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\nvec3 geometryClearcoatNormal = vec3( 0.0 );\n#ifdef USE_CLEARCOAT\n geometryClearcoatNormal = clearcoatNormal;\n#endif\n#ifdef USE_IRIDESCENCE\n float dotNVi = saturate( dot( normal, geometryViewDir ) );\n if ( material.iridescenceThickness == 0.0 ) {\n material.iridescence = 0.0;\n } else {\n material.iridescence = saturate( material.iridescence );\n }\n if ( material.iridescence > 0.0 ) {\n material.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );\n material.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );\n }\n#endif\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n PointLight pointLight;\n #if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n PointLightShadow pointLightShadow;\n #endif\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n pointLight = pointLights[ i ];\n getPointLightInfo( pointLight, geometryPosition, directLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n pointLightShadow = pointLightShadows[ i ];\n directLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n #endif\n RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n }\n #pragma unroll_loop_end\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n SpotLight spotLight;\n vec4 spotColor;\n vec3 spotLightCoord;\n bool inSpotLightMap;\n #if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n SpotLightShadow spotLightShadow;\n #endif\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n spotLight = spotLights[ i ];\n getSpotLightInfo( spotLight, geometryPosition, directLight );\n #if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n #define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX\n #elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n #define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS\n #else\n #define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n #endif\n #if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )\n spotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;\n inSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );\n spotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );\n directLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;\n #endif\n #undef SPOT_LIGHT_MAP_INDEX\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n spotLightShadow = spotLightShadows[ i ];\n directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n }\n #pragma unroll_loop_end\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n DirectionalLight directionalLight;\n #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n DirectionalLightShadow directionalLightShadow;\n #endif\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n directionalLight = directionalLights[ i ];\n getDirectionalLightInfo( directionalLight, directLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n directionalLightShadow = directionalLightShadows[ i ];\n directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n }\n #pragma unroll_loop_end\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n RectAreaLight rectAreaLight;\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n rectAreaLight = rectAreaLights[ i ];\n RE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n }\n #pragma unroll_loop_end\n#endif\n#if defined( RE_IndirectDiffuse )\n vec3 iblIrradiance = vec3( 0.0 );\n vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n #if defined( USE_LIGHT_PROBES )\n irradiance += getLightProbeIrradiance( lightProbe, geometryNormal );\n #endif\n #if ( NUM_HEMI_LIGHTS > 0 )\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );\n }\n #pragma unroll_loop_end\n #endif\n#endif\n#if defined( RE_IndirectSpecular )\n vec3 radiance = vec3( 0.0 );\n vec3 clearcoatRadiance = vec3( 0.0 );\n#endif"; var lights_fragment_maps = "#if defined( RE_IndirectDiffuse )\n #ifdef USE_LIGHTMAP\n vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n irradiance += lightMapIrradiance;\n #endif\n #if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n iblIrradiance += getIBLIrradiance( geometryNormal );\n #endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n #ifdef USE_ANISOTROPY\n radiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );\n #else\n radiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness );\n #endif\n #ifdef USE_CLEARCOAT\n clearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );\n #endif\n#endif"; var lights_fragment_end = "#if defined( RE_IndirectDiffuse )\n RE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n#endif"; var logdepthbuf_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n gl_FragDepthEXT = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif"; var logdepthbuf_pars_fragment = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n uniform float logDepthBufFC;\n varying float vFragDepth;\n varying float vIsPerspective;\n#endif"; var logdepthbuf_pars_vertex = "#ifdef USE_LOGDEPTHBUF\n #ifdef USE_LOGDEPTHBUF_EXT\n varying float vFragDepth;\n varying float vIsPerspective;\n #else\n uniform float logDepthBufFC;\n #endif\n#endif"; var logdepthbuf_vertex = "#ifdef USE_LOGDEPTHBUF\n #ifdef USE_LOGDEPTHBUF_EXT\n vFragDepth = 1.0 + gl_Position.w;\n vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n #else\n if ( isPerspectiveMatrix( projectionMatrix ) ) {\n gl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0;\n gl_Position.z *= gl_Position.w;\n }\n #endif\n#endif"; var map_fragment = "#ifdef USE_MAP\n vec4 sampledDiffuseColor = texture2D( map, vMapUv );\n #ifdef DECODE_VIDEO_TEXTURE\n sampledDiffuseColor = vec4( mix( pow( sampledDiffuseColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), sampledDiffuseColor.rgb * 0.0773993808, vec3( lessThanEqual( sampledDiffuseColor.rgb, vec3( 0.04045 ) ) ) ), sampledDiffuseColor.w );\n \n #endif\n diffuseColor *= sampledDiffuseColor;\n#endif"; var map_pars_fragment = "#ifdef USE_MAP\n uniform sampler2D map;\n#endif"; var map_particle_fragment = "#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n #if defined( USE_POINTS_UV )\n vec2 uv = vUv;\n #else\n vec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n #endif\n#endif\n#ifdef USE_MAP\n diffuseColor *= texture2D( map, uv );\n#endif\n#ifdef USE_ALPHAMAP\n diffuseColor.a *= texture2D( alphaMap, uv ).g;\n#endif"; var map_particle_pars_fragment = "#if defined( USE_POINTS_UV )\n varying vec2 vUv;\n#else\n #if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n uniform mat3 uvTransform;\n #endif\n#endif\n#ifdef USE_MAP\n uniform sampler2D map;\n#endif\n#ifdef USE_ALPHAMAP\n uniform sampler2D alphaMap;\n#endif"; var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n vec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv );\n metalnessFactor *= texelMetalness.b;\n#endif"; var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n uniform sampler2D metalnessMap;\n#endif"; var morphcolor_vertex = "#if defined( USE_MORPHCOLORS ) && defined( MORPHTARGETS_TEXTURE )\n vColor *= morphTargetBaseInfluence;\n for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n #if defined( USE_COLOR_ALPHA )\n if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ];\n #elif defined( USE_COLOR )\n if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];\n #endif\n }\n#endif"; var morphnormal_vertex = "#ifdef USE_MORPHNORMALS\n objectNormal *= morphTargetBaseInfluence;\n #ifdef MORPHTARGETS_TEXTURE\n for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n if ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];\n }\n #else\n objectNormal += morphNormal0 * morphTargetInfluences[ 0 ];\n objectNormal += morphNormal1 * morphTargetInfluences[ 1 ];\n objectNormal += morphNormal2 * morphTargetInfluences[ 2 ];\n objectNormal += morphNormal3 * morphTargetInfluences[ 3 ];\n #endif\n#endif"; var morphtarget_pars_vertex = "#ifdef USE_MORPHTARGETS\n uniform float morphTargetBaseInfluence;\n #ifdef MORPHTARGETS_TEXTURE\n uniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];\n uniform sampler2DArray morphTargetsTexture;\n uniform ivec2 morphTargetsTextureSize;\n vec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {\n int texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;\n int y = texelIndex / morphTargetsTextureSize.x;\n int x = texelIndex - y * morphTargetsTextureSize.x;\n ivec3 morphUV = ivec3( x, y, morphTargetIndex );\n return texelFetch( morphTargetsTexture, morphUV, 0 );\n }\n #else\n #ifndef USE_MORPHNORMALS\n uniform float morphTargetInfluences[ 8 ];\n #else\n uniform float morphTargetInfluences[ 4 ];\n #endif\n #endif\n#endif"; var morphtarget_vertex = "#ifdef USE_MORPHTARGETS\n transformed *= morphTargetBaseInfluence;\n #ifdef MORPHTARGETS_TEXTURE\n for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n if ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];\n }\n #else\n transformed += morphTarget0 * morphTargetInfluences[ 0 ];\n transformed += morphTarget1 * morphTargetInfluences[ 1 ];\n transformed += morphTarget2 * morphTargetInfluences[ 2 ];\n transformed += morphTarget3 * morphTargetInfluences[ 3 ];\n #ifndef USE_MORPHNORMALS\n transformed += morphTarget4 * morphTargetInfluences[ 4 ];\n transformed += morphTarget5 * morphTargetInfluences[ 5 ];\n transformed += morphTarget6 * morphTargetInfluences[ 6 ];\n transformed += morphTarget7 * morphTargetInfluences[ 7 ];\n #endif\n #endif\n#endif"; var normal_fragment_begin = "float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;\n#ifdef FLAT_SHADED\n vec3 fdx = dFdx( vViewPosition );\n vec3 fdy = dFdy( vViewPosition );\n vec3 normal = normalize( cross( fdx, fdy ) );\n#else\n vec3 normal = normalize( vNormal );\n #ifdef DOUBLE_SIDED\n normal *= faceDirection;\n #endif\n#endif\n#if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY )\n #ifdef USE_TANGENT\n mat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\n #else\n mat3 tbn = getTangentFrame( - vViewPosition, normal,\n #if defined( USE_NORMALMAP )\n vNormalMapUv\n #elif defined( USE_CLEARCOAT_NORMALMAP )\n vClearcoatNormalMapUv\n #else\n vUv\n #endif\n );\n #endif\n #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )\n tbn[0] *= faceDirection;\n tbn[1] *= faceDirection;\n #endif\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n #ifdef USE_TANGENT\n mat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\n #else\n mat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv );\n #endif\n #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )\n tbn2[0] *= faceDirection;\n tbn2[1] *= faceDirection;\n #endif\n#endif\nvec3 nonPerturbedNormal = normal;"; var normal_fragment_maps = "#ifdef USE_NORMALMAP_OBJECTSPACE\n normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n #ifdef FLIP_SIDED\n normal = - normal;\n #endif\n #ifdef DOUBLE_SIDED\n normal = normal * faceDirection;\n #endif\n normal = normalize( normalMatrix * normal );\n#elif defined( USE_NORMALMAP_TANGENTSPACE )\n vec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n mapN.xy *= normalScale;\n normal = normalize( tbn * mapN );\n#elif defined( USE_BUMPMAP )\n normal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );\n#endif"; var normal_pars_fragment = "#ifndef FLAT_SHADED\n varying vec3 vNormal;\n #ifdef USE_TANGENT\n varying vec3 vTangent;\n varying vec3 vBitangent;\n #endif\n#endif"; var normal_pars_vertex = "#ifndef FLAT_SHADED\n varying vec3 vNormal;\n #ifdef USE_TANGENT\n varying vec3 vTangent;\n varying vec3 vBitangent;\n #endif\n#endif"; var normal_vertex = "#ifndef FLAT_SHADED\n vNormal = normalize( transformedNormal );\n #ifdef USE_TANGENT\n vTangent = normalize( transformedTangent );\n vBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n #endif\n#endif"; var normalmap_pars_fragment = "#ifdef USE_NORMALMAP\n uniform sampler2D normalMap;\n uniform vec2 normalScale;\n#endif\n#ifdef USE_NORMALMAP_OBJECTSPACE\n uniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) )\n mat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {\n vec3 q0 = dFdx( eye_pos.xyz );\n vec3 q1 = dFdy( eye_pos.xyz );\n vec2 st0 = dFdx( uv.st );\n vec2 st1 = dFdy( uv.st );\n vec3 N = surf_norm;\n vec3 q1perp = cross( q1, N );\n vec3 q0perp = cross( N, q0 );\n vec3 T = q1perp * st0.x + q0perp * st1.x;\n vec3 B = q1perp * st0.y + q0perp * st1.y;\n float det = max( dot( T, T ), dot( B, B ) );\n float scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det );\n return mat3( T * scale, B * scale, N );\n }\n#endif"; var clearcoat_normal_fragment_begin = "#ifdef USE_CLEARCOAT\n vec3 clearcoatNormal = nonPerturbedNormal;\n#endif"; var clearcoat_normal_fragment_maps = "#ifdef USE_CLEARCOAT_NORMALMAP\n vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0;\n clearcoatMapN.xy *= clearcoatNormalScale;\n clearcoatNormal = normalize( tbn2 * clearcoatMapN );\n#endif"; var clearcoat_pars_fragment = "#ifdef USE_CLEARCOATMAP\n uniform sampler2D clearcoatMap;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n uniform sampler2D clearcoatNormalMap;\n uniform vec2 clearcoatNormalScale;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n uniform sampler2D clearcoatRoughnessMap;\n#endif"; var iridescence_pars_fragment = "#ifdef USE_IRIDESCENCEMAP\n uniform sampler2D iridescenceMap;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n uniform sampler2D iridescenceThicknessMap;\n#endif"; var opaque_fragment = "#ifdef OPAQUE\ndiffuseColor.a = 1.0;\n#endif\n#ifdef USE_TRANSMISSION\ndiffuseColor.a *= material.transmissionAlpha;\n#endif\ngl_FragColor = vec4( outgoingLight, diffuseColor.a );"; var packing = "vec3 packNormalToRGB( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n return 2.0 * rgb.xyz - 1.0;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;\nconst vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\nconst vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );\nconst float ShiftRight8 = 1. / 256.;\nvec4 packDepthToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * PackFactors ), v );\n r.yzw -= r.xyz * ShiftRight8; return r * PackUpscale;\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n return dot( v, UnpackFactors );\n}\nvec2 packDepthToRG( in highp float v ) {\n return packDepthToRGBA( v ).yx;\n}\nfloat unpackRGToDepth( const in highp vec2 v ) {\n return unpackRGBAToDepth( vec4( v.xy, 0.0, 0.0 ) );\n}\nvec4 pack2HalfToRGBA( vec2 v ) {\n vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );\n return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );\n}\nvec2 unpackRGBATo2Half( vec4 v ) {\n return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n return ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) {\n return depth * ( near - far ) - near;\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n return ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) {\n return ( near * far ) / ( ( far - near ) * depth - far );\n}"; var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n gl_FragColor.rgb *= gl_FragColor.a;\n#endif"; var project_vertex = "vec4 mvPosition = vec4( transformed, 1.0 );\n#ifdef USE_INSTANCING\n mvPosition = instanceMatrix * mvPosition;\n#endif\nmvPosition = modelViewMatrix * mvPosition;\ngl_Position = projectionMatrix * mvPosition;"; var dithering_fragment = "#ifdef DITHERING\n gl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif"; var dithering_pars_fragment = "#ifdef DITHERING\n vec3 dithering( vec3 color ) {\n float grid_position = rand( gl_FragCoord.xy );\n vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n dither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n return color + dither_shift_RGB;\n }\n#endif"; var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n vec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv );\n roughnessFactor *= texelRoughness.g;\n#endif"; var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n uniform sampler2D roughnessMap;\n#endif"; var shadowmap_pars_fragment = "#if NUM_SPOT_LIGHT_COORDS > 0\n varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n#endif\n#if NUM_SPOT_LIGHT_MAPS > 0\n uniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ];\n#endif\n#ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHT_SHADOWS > 0\n uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n struct DirectionalLightShadow {\n float shadowBias;\n float shadowNormalBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n #endif\n #if NUM_SPOT_LIGHT_SHADOWS > 0\n uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n struct SpotLightShadow {\n float shadowBias;\n float shadowNormalBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n #endif\n #if NUM_POINT_LIGHT_SHADOWS > 0\n uniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n struct PointLightShadow {\n float shadowBias;\n float shadowNormalBias;\n float shadowRadius;\n vec2 shadowMapSize;\n float shadowCameraNear;\n float shadowCameraFar;\n };\n uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n #endif\n float texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n return step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n }\n vec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {\n return unpackRGBATo2Half( texture2D( shadow, uv ) );\n }\n float VSMShadow (sampler2D shadow, vec2 uv, float compare ){\n float occlusion = 1.0;\n vec2 distribution = texture2DDistribution( shadow, uv );\n float hard_shadow = step( compare , distribution.x );\n if (hard_shadow != 1.0 ) {\n float distance = compare - distribution.x ;\n float variance = max( 0.00000, distribution.y * distribution.y );\n float softness_probability = variance / (variance + distance * distance ); softness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 ); occlusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );\n }\n return occlusion;\n }\n float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n float shadow = 1.0;\n shadowCoord.xyz /= shadowCoord.w;\n shadowCoord.z += shadowBias;\n bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;\n bool frustumTest = inFrustum && shadowCoord.z <= 1.0;\n if ( frustumTest ) {\n #if defined( SHADOWMAP_TYPE_PCF )\n vec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n float dx0 = - texelSize.x * shadowRadius;\n float dy0 = - texelSize.y * shadowRadius;\n float dx1 = + texelSize.x * shadowRadius;\n float dy1 = + texelSize.y * shadowRadius;\n float dx2 = dx0 / 2.0;\n float dy2 = dy0 / 2.0;\n float dx3 = dx1 / 2.0;\n float dy3 = dy1 / 2.0;\n shadow = (\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n ) * ( 1.0 / 17.0 );\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n vec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n float dx = texelSize.x;\n float dy = texelSize.y;\n vec2 uv = shadowCoord.xy;\n vec2 f = fract( uv * shadowMapSize + 0.5 );\n uv -= f * texelSize;\n shadow = (\n texture2DCompare( shadowMap, uv, shadowCoord.z ) +\n texture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +\n texture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +\n mix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ),\n texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),\n f.x ) +\n mix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ),\n texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),\n f.x ) +\n mix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ),\n texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),\n f.y ) +\n mix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ),\n texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),\n f.y ) +\n mix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ),\n texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),\n f.x ),\n mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ),\n texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),\n f.x ),\n f.y )\n ) * ( 1.0 / 9.0 );\n #elif defined( SHADOWMAP_TYPE_VSM )\n shadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );\n #else\n shadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n #endif\n }\n return shadow;\n }\n vec2 cubeToUV( vec3 v, float texelSizeY ) {\n vec3 absV = abs( v );\n float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n absV *= scaleToCube;\n v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n vec2 planar = v.xy;\n float almostATexel = 1.5 * texelSizeY;\n float almostOne = 1.0 - almostATexel;\n if ( absV.z >= almostOne ) {\n if ( v.z > 0.0 )\n planar.x = 4.0 - v.x;\n } else if ( absV.x >= almostOne ) {\n float signX = sign( v.x );\n planar.x = v.z * signX + 2.0 * signX;\n } else if ( absV.y >= almostOne ) {\n float signY = sign( v.y );\n planar.x = v.x + 2.0 * signY + 2.0;\n planar.y = v.z * signY - 2.0;\n }\n return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n }\n float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n vec3 lightToPosition = shadowCoord.xyz;\n float dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear ); dp += shadowBias;\n vec3 bd3D = normalize( lightToPosition );\n #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )\n vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n return (\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n ) * ( 1.0 / 9.0 );\n #else\n return texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n #endif\n }\n#endif"; var shadowmap_pars_vertex = "#if NUM_SPOT_LIGHT_COORDS > 0\n uniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ];\n varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n#endif\n#ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHT_SHADOWS > 0\n uniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];\n varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n struct DirectionalLightShadow {\n float shadowBias;\n float shadowNormalBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n #endif\n #if NUM_SPOT_LIGHT_SHADOWS > 0\n struct SpotLightShadow {\n float shadowBias;\n float shadowNormalBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n #endif\n #if NUM_POINT_LIGHT_SHADOWS > 0\n uniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];\n varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n struct PointLightShadow {\n float shadowBias;\n float shadowNormalBias;\n float shadowRadius;\n vec2 shadowMapSize;\n float shadowCameraNear;\n float shadowCameraFar;\n };\n uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n #endif\n#endif"; var shadowmap_vertex = "#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )\n vec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n vec4 shadowWorldPosition;\n#endif\n#if defined( USE_SHADOWMAP )\n #if NUM_DIR_LIGHT_SHADOWS > 0\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );\n vDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;\n }\n #pragma unroll_loop_end\n #endif\n #if NUM_POINT_LIGHT_SHADOWS > 0\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );\n vPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;\n }\n #pragma unroll_loop_end\n #endif\n#endif\n#if NUM_SPOT_LIGHT_COORDS > 0\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {\n shadowWorldPosition = worldPosition;\n #if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n shadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;\n #endif\n vSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;\n }\n #pragma unroll_loop_end\n#endif"; var shadowmask_pars_fragment = "float getShadowMask() {\n float shadow = 1.0;\n #ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHT_SHADOWS > 0\n DirectionalLightShadow directionalLight;\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n directionalLight = directionalLightShadows[ i ];\n shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n }\n #pragma unroll_loop_end\n #endif\n #if NUM_SPOT_LIGHT_SHADOWS > 0\n SpotLightShadow spotLight;\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n spotLight = spotLightShadows[ i ];\n shadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n }\n #pragma unroll_loop_end\n #endif\n #if NUM_POINT_LIGHT_SHADOWS > 0\n PointLightShadow pointLight;\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n pointLight = pointLightShadows[ i ];\n shadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n }\n #pragma unroll_loop_end\n #endif\n #endif\n return shadow;\n}"; var skinbase_vertex = "#ifdef USE_SKINNING\n mat4 boneMatX = getBoneMatrix( skinIndex.x );\n mat4 boneMatY = getBoneMatrix( skinIndex.y );\n mat4 boneMatZ = getBoneMatrix( skinIndex.z );\n mat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif"; var skinning_pars_vertex = "#ifdef USE_SKINNING\n uniform mat4 bindMatrix;\n uniform mat4 bindMatrixInverse;\n uniform highp sampler2D boneTexture;\n uniform int boneTextureSize;\n mat4 getBoneMatrix( const in float i ) {\n float j = i * 4.0;\n float x = mod( j, float( boneTextureSize ) );\n float y = floor( j / float( boneTextureSize ) );\n float dx = 1.0 / float( boneTextureSize );\n float dy = 1.0 / float( boneTextureSize );\n y = dy * ( y + 0.5 );\n vec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n vec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n vec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n vec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n mat4 bone = mat4( v1, v2, v3, v4 );\n return bone;\n }\n#endif"; var skinning_vertex = "#ifdef USE_SKINNING\n vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n vec4 skinned = vec4( 0.0 );\n skinned += boneMatX * skinVertex * skinWeight.x;\n skinned += boneMatY * skinVertex * skinWeight.y;\n skinned += boneMatZ * skinVertex * skinWeight.z;\n skinned += boneMatW * skinVertex * skinWeight.w;\n transformed = ( bindMatrixInverse * skinned ).xyz;\n#endif"; var skinnormal_vertex = "#ifdef USE_SKINNING\n mat4 skinMatrix = mat4( 0.0 );\n skinMatrix += skinWeight.x * boneMatX;\n skinMatrix += skinWeight.y * boneMatY;\n skinMatrix += skinWeight.z * boneMatZ;\n skinMatrix += skinWeight.w * boneMatW;\n skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n #ifdef USE_TANGENT\n objectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n #endif\n#endif"; var specularmap_fragment = "float specularStrength;\n#ifdef USE_SPECULARMAP\n vec4 texelSpecular = texture2D( specularMap, vSpecularMapUv );\n specularStrength = texelSpecular.r;\n#else\n specularStrength = 1.0;\n#endif"; var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n uniform sampler2D specularMap;\n#endif"; var tonemapping_fragment = "#if defined( TONE_MAPPING )\n gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif"; var tonemapping_pars_fragment = "#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nvec3 LinearToneMapping( vec3 color ) {\n return saturate( toneMappingExposure * color );\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n color *= toneMappingExposure;\n return saturate( color / ( vec3( 1.0 ) + color ) );\n}\nvec3 OptimizedCineonToneMapping( vec3 color ) {\n color *= toneMappingExposure;\n color = max( vec3( 0.0 ), color - 0.004 );\n return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 RRTAndODTFit( vec3 v ) {\n vec3 a = v * ( v + 0.0245786 ) - 0.000090537;\n vec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;\n return a / b;\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n const mat3 ACESInputMat = mat3(\n vec3( 0.59719, 0.07600, 0.02840 ), vec3( 0.35458, 0.90834, 0.13383 ),\n vec3( 0.04823, 0.01566, 0.83777 )\n );\n const mat3 ACESOutputMat = mat3(\n vec3( 1.60475, -0.10208, -0.00327 ), vec3( -0.53108, 1.10813, -0.07276 ),\n vec3( -0.07367, -0.00605, 1.07602 )\n );\n color *= toneMappingExposure / 0.6;\n color = ACESInputMat * color;\n color = RRTAndODTFit( color );\n color = ACESOutputMat * color;\n return saturate( color );\n}\nvec3 CustomToneMapping( vec3 color ) { return color; }"; var transmission_fragment = "#ifdef USE_TRANSMISSION\n material.transmission = transmission;\n material.transmissionAlpha = 1.0;\n material.thickness = thickness;\n material.attenuationDistance = attenuationDistance;\n material.attenuationColor = attenuationColor;\n #ifdef USE_TRANSMISSIONMAP\n material.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r;\n #endif\n #ifdef USE_THICKNESSMAP\n material.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g;\n #endif\n vec3 pos = vWorldPosition;\n vec3 v = normalize( cameraPosition - pos );\n vec3 n = inverseTransformDirection( normal, viewMatrix );\n vec4 transmitted = getIBLVolumeRefraction(\n n, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,\n pos, modelMatrix, viewMatrix, projectionMatrix, material.ior, material.thickness,\n material.attenuationColor, material.attenuationDistance );\n material.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );\n totalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission );\n#endif"; var transmission_pars_fragment = "#ifdef USE_TRANSMISSION\n uniform float transmission;\n uniform float thickness;\n uniform float attenuationDistance;\n uniform vec3 attenuationColor;\n #ifdef USE_TRANSMISSIONMAP\n uniform sampler2D transmissionMap;\n #endif\n #ifdef USE_THICKNESSMAP\n uniform sampler2D thicknessMap;\n #endif\n uniform vec2 transmissionSamplerSize;\n uniform sampler2D transmissionSamplerMap;\n uniform mat4 modelMatrix;\n uniform mat4 projectionMatrix;\n varying vec3 vWorldPosition;\n float w0( float a ) {\n return ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 );\n }\n float w1( float a ) {\n return ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 );\n }\n float w2( float a ){\n return ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 );\n }\n float w3( float a ) {\n return ( 1.0 / 6.0 ) * ( a * a * a );\n }\n float g0( float a ) {\n return w0( a ) + w1( a );\n }\n float g1( float a ) {\n return w2( a ) + w3( a );\n }\n float h0( float a ) {\n return - 1.0 + w1( a ) / ( w0( a ) + w1( a ) );\n }\n float h1( float a ) {\n return 1.0 + w3( a ) / ( w2( a ) + w3( a ) );\n }\n vec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) {\n uv = uv * texelSize.zw + 0.5;\n vec2 iuv = floor( uv );\n vec2 fuv = fract( uv );\n float g0x = g0( fuv.x );\n float g1x = g1( fuv.x );\n float h0x = h0( fuv.x );\n float h1x = h1( fuv.x );\n float h0y = h0( fuv.y );\n float h1y = h1( fuv.y );\n vec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\n vec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\n vec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\n vec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\n return g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) +\n g1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) );\n }\n vec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) {\n vec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) );\n vec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) );\n vec2 fLodSizeInv = 1.0 / fLodSize;\n vec2 cLodSizeInv = 1.0 / cLodSize;\n vec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) );\n vec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) );\n return mix( fSample, cSample, fract( lod ) );\n }\n vec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {\n vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );\n vec3 modelScale;\n modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );\n modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );\n modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );\n return normalize( refractionVector ) * thickness * modelScale;\n }\n float applyIorToRoughness( const in float roughness, const in float ior ) {\n return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );\n }\n vec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {\n float lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );\n return textureBicubic( transmissionSamplerMap, fragCoord.xy, lod );\n }\n vec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {\n if ( isinf( attenuationDistance ) ) {\n return vec3( 1.0 );\n } else {\n vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;\n vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance ); return transmittance;\n }\n }\n vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,\n const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,\n const in mat4 viewMatrix, const in mat4 projMatrix, const in float ior, const in float thickness,\n const in vec3 attenuationColor, const in float attenuationDistance ) {\n vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );\n vec3 refractedRayExit = position + transmissionRay;\n vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n vec2 refractionCoords = ndcPos.xy / ndcPos.w;\n refractionCoords += 1.0;\n refractionCoords /= 2.0;\n vec4 transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );\n vec3 transmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );\n vec3 attenuatedColor = transmittance * transmittedLight.rgb;\n vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );\n float transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0;\n return vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor );\n }\n#endif"; var uv_pars_fragment = "#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n varying vec2 vUv;\n#endif\n#ifdef USE_MAP\n varying vec2 vMapUv;\n#endif\n#ifdef USE_ALPHAMAP\n varying vec2 vAlphaMapUv;\n#endif\n#ifdef USE_LIGHTMAP\n varying vec2 vLightMapUv;\n#endif\n#ifdef USE_AOMAP\n varying vec2 vAoMapUv;\n#endif\n#ifdef USE_BUMPMAP\n varying vec2 vBumpMapUv;\n#endif\n#ifdef USE_NORMALMAP\n varying vec2 vNormalMapUv;\n#endif\n#ifdef USE_EMISSIVEMAP\n varying vec2 vEmissiveMapUv;\n#endif\n#ifdef USE_METALNESSMAP\n varying vec2 vMetalnessMapUv;\n#endif\n#ifdef USE_ROUGHNESSMAP\n varying vec2 vRoughnessMapUv;\n#endif\n#ifdef USE_ANISOTROPYMAP\n varying vec2 vAnisotropyMapUv;\n#endif\n#ifdef USE_CLEARCOATMAP\n varying vec2 vClearcoatMapUv;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n varying vec2 vClearcoatNormalMapUv;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n varying vec2 vClearcoatRoughnessMapUv;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n varying vec2 vIridescenceMapUv;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n varying vec2 vIridescenceThicknessMapUv;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n varying vec2 vSheenColorMapUv;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n varying vec2 vSheenRoughnessMapUv;\n#endif\n#ifdef USE_SPECULARMAP\n varying vec2 vSpecularMapUv;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n varying vec2 vSpecularColorMapUv;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n varying vec2 vSpecularIntensityMapUv;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n uniform mat3 transmissionMapTransform;\n varying vec2 vTransmissionMapUv;\n#endif\n#ifdef USE_THICKNESSMAP\n uniform mat3 thicknessMapTransform;\n varying vec2 vThicknessMapUv;\n#endif"; var uv_pars_vertex = "#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n varying vec2 vUv;\n#endif\n#ifdef USE_MAP\n uniform mat3 mapTransform;\n varying vec2 vMapUv;\n#endif\n#ifdef USE_ALPHAMAP\n uniform mat3 alphaMapTransform;\n varying vec2 vAlphaMapUv;\n#endif\n#ifdef USE_LIGHTMAP\n uniform mat3 lightMapTransform;\n varying vec2 vLightMapUv;\n#endif\n#ifdef USE_AOMAP\n uniform mat3 aoMapTransform;\n varying vec2 vAoMapUv;\n#endif\n#ifdef USE_BUMPMAP\n uniform mat3 bumpMapTransform;\n varying vec2 vBumpMapUv;\n#endif\n#ifdef USE_NORMALMAP\n uniform mat3 normalMapTransform;\n varying vec2 vNormalMapUv;\n#endif\n#ifdef USE_DISPLACEMENTMAP\n uniform mat3 displacementMapTransform;\n varying vec2 vDisplacementMapUv;\n#endif\n#ifdef USE_EMISSIVEMAP\n uniform mat3 emissiveMapTransform;\n varying vec2 vEmissiveMapUv;\n#endif\n#ifdef USE_METALNESSMAP\n uniform mat3 metalnessMapTransform;\n varying vec2 vMetalnessMapUv;\n#endif\n#ifdef USE_ROUGHNESSMAP\n uniform mat3 roughnessMapTransform;\n varying vec2 vRoughnessMapUv;\n#endif\n#ifdef USE_ANISOTROPYMAP\n uniform mat3 anisotropyMapTransform;\n varying vec2 vAnisotropyMapUv;\n#endif\n#ifdef USE_CLEARCOATMAP\n uniform mat3 clearcoatMapTransform;\n varying vec2 vClearcoatMapUv;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n uniform mat3 clearcoatNormalMapTransform;\n varying vec2 vClearcoatNormalMapUv;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n uniform mat3 clearcoatRoughnessMapTransform;\n varying vec2 vClearcoatRoughnessMapUv;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n uniform mat3 sheenColorMapTransform;\n varying vec2 vSheenColorMapUv;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n uniform mat3 sheenRoughnessMapTransform;\n varying vec2 vSheenRoughnessMapUv;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n uniform mat3 iridescenceMapTransform;\n varying vec2 vIridescenceMapUv;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n uniform mat3 iridescenceThicknessMapTransform;\n varying vec2 vIridescenceThicknessMapUv;\n#endif\n#ifdef USE_SPECULARMAP\n uniform mat3 specularMapTransform;\n varying vec2 vSpecularMapUv;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n uniform mat3 specularColorMapTransform;\n varying vec2 vSpecularColorMapUv;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n uniform mat3 specularIntensityMapTransform;\n varying vec2 vSpecularIntensityMapUv;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n uniform mat3 transmissionMapTransform;\n varying vec2 vTransmissionMapUv;\n#endif\n#ifdef USE_THICKNESSMAP\n uniform mat3 thicknessMapTransform;\n varying vec2 vThicknessMapUv;\n#endif"; var uv_vertex = "#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n vUv = vec3( uv, 1 ).xy;\n#endif\n#ifdef USE_MAP\n vMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ALPHAMAP\n vAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_LIGHTMAP\n vLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_AOMAP\n vAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_BUMPMAP\n vBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_NORMALMAP\n vNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_DISPLACEMENTMAP\n vDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_EMISSIVEMAP\n vEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_METALNESSMAP\n vMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ROUGHNESSMAP\n vRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ANISOTROPYMAP\n vAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOATMAP\n vClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n vClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n vClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n vIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n vIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n vSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n vSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULARMAP\n vSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n vSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n vSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n vTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_THICKNESSMAP\n vThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy;\n#endif"; var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0\n vec4 worldPosition = vec4( transformed, 1.0 );\n #ifdef USE_INSTANCING\n worldPosition = instanceMatrix * worldPosition;\n #endif\n worldPosition = modelMatrix * worldPosition;\n#endif"; var vertex$h = "varying vec2 vUv;\nuniform mat3 uvTransform;\nvoid main() {\n vUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n gl_Position = vec4( position.xy, 1.0, 1.0 );\n}"; var fragment$h = "uniform sampler2D t2D;\nuniform float backgroundIntensity;\nvarying vec2 vUv;\nvoid main() {\n vec4 texColor = texture2D( t2D, vUv );\n #ifdef DECODE_VIDEO_TEXTURE\n texColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w );\n #endif\n texColor.rgb *= backgroundIntensity;\n gl_FragColor = texColor;\n #include \n #include \n}"; var vertex$g = "varying vec3 vWorldDirection;\n#include \nvoid main() {\n vWorldDirection = transformDirection( position, modelMatrix );\n #include \n #include \n gl_Position.z = gl_Position.w;\n}"; var fragment$g = "#ifdef ENVMAP_TYPE_CUBE\n uniform samplerCube envMap;\n#elif defined( ENVMAP_TYPE_CUBE_UV )\n uniform sampler2D envMap;\n#endif\nuniform float flipEnvMap;\nuniform float backgroundBlurriness;\nuniform float backgroundIntensity;\nvarying vec3 vWorldDirection;\n#include \nvoid main() {\n #ifdef ENVMAP_TYPE_CUBE\n vec4 texColor = textureCube( envMap, vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) );\n #elif defined( ENVMAP_TYPE_CUBE_UV )\n vec4 texColor = textureCubeUV( envMap, vWorldDirection, backgroundBlurriness );\n #else\n vec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n #endif\n texColor.rgb *= backgroundIntensity;\n gl_FragColor = texColor;\n #include \n #include \n}"; var vertex$f = "varying vec3 vWorldDirection;\n#include \nvoid main() {\n vWorldDirection = transformDirection( position, modelMatrix );\n #include \n #include \n gl_Position.z = gl_Position.w;\n}"; var fragment$f = "uniform samplerCube tCube;\nuniform float tFlip;\nuniform float opacity;\nvarying vec3 vWorldDirection;\nvoid main() {\n vec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );\n gl_FragColor = texColor;\n gl_FragColor.a *= opacity;\n #include \n #include \n}"; var vertex$e = "#include \n#include \n#include \n#include \n#include \n#include \n#include \nvarying vec2 vHighPrecisionZW;\nvoid main() {\n #include \n #include \n #ifdef USE_DISPLACEMENTMAP\n #include \n #include \n #include \n #endif\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n vHighPrecisionZW = gl_Position.zw;\n}"; var fragment$e = "#if DEPTH_PACKING == 3200\n uniform float opacity;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvarying vec2 vHighPrecisionZW;\nvoid main() {\n #include \n vec4 diffuseColor = vec4( 1.0 );\n #if DEPTH_PACKING == 3200\n diffuseColor.a = opacity;\n #endif\n #include \n #include \n #include \n #include \n #include \n float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;\n #if DEPTH_PACKING == 3200\n gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );\n #elif DEPTH_PACKING == 3201\n gl_FragColor = packDepthToRGBA( fragCoordZ );\n #endif\n}"; var vertex$d = "#define DISTANCE\nvarying vec3 vWorldPosition;\n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n #include \n #ifdef USE_DISPLACEMENTMAP\n #include \n #include \n #include \n #endif\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n vWorldPosition = worldPosition.xyz;\n}"; var fragment$d = "#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main () {\n #include \n vec4 diffuseColor = vec4( 1.0 );\n #include \n #include \n #include \n #include \n float dist = length( vWorldPosition - referencePosition );\n dist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n dist = saturate( dist );\n gl_FragColor = packDepthToRGBA( dist );\n}"; var vertex$c = "varying vec3 vWorldDirection;\n#include \nvoid main() {\n vWorldDirection = transformDirection( position, modelMatrix );\n #include \n #include \n}"; var fragment$c = "uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include \nvoid main() {\n vec3 direction = normalize( vWorldDirection );\n vec2 sampleUV = equirectUv( direction );\n gl_FragColor = texture2D( tEquirect, sampleUV );\n #include \n #include \n}"; var vertex$b = "uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n vLineDistance = scale * lineDistance;\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n}"; var fragment$b = "uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n if ( mod( vLineDistance, totalSize ) > dashSize ) {\n discard;\n }\n vec3 outgoingLight = vec3( 0.0 );\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include \n #include \n #include \n outgoingLight = diffuseColor.rgb;\n #include \n #include \n #include \n #include \n #include \n}"; var vertex$a = "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n #include \n #include \n #if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )\n #include \n #include \n #include \n #include \n #include \n #endif\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n}"; var fragment$a = "uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n vec4 diffuseColor = vec4( diffuse, opacity );\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n #ifdef USE_LIGHTMAP\n vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n reflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI;\n #else\n reflectedLight.indirectDiffuse += vec3( 1.0 );\n #endif\n #include \n reflectedLight.indirectDiffuse *= diffuseColor.rgb;\n vec3 outgoingLight = reflectedLight.indirectDiffuse;\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n}"; var vertex$9 = "#define LAMBERT\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n vViewPosition = - mvPosition.xyz;\n #include \n #include \n #include \n #include \n}"; var fragment$9 = "#define LAMBERT\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n vec4 diffuseColor = vec4( diffuse, opacity );\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n}"; var vertex$8 = "#define MATCAP\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n vViewPosition = - mvPosition.xyz;\n}"; var fragment$8 = "#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity;\nuniform sampler2D matcap;\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n vec4 diffuseColor = vec4( diffuse, opacity );\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n vec3 viewDir = normalize( vViewPosition );\n vec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );\n vec3 y = cross( viewDir, x );\n vec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;\n #ifdef USE_MATCAP\n vec4 matcapColor = texture2D( matcap, uv );\n #else\n vec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 );\n #endif\n vec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;\n #include \n #include \n #include \n #include \n #include \n #include \n}"; var vertex$7 = "#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n varying vec3 vViewPosition;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n vViewPosition = - mvPosition.xyz;\n#endif\n}"; var fragment$7 = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n varying vec3 vViewPosition;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n #include \n #include \n #include \n gl_FragColor = vec4( packNormalToRGB( normal ), opacity );\n #ifdef OPAQUE\n gl_FragColor.a = 1.0;\n #endif\n}"; var vertex$6 = "#define PHONG\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n vViewPosition = - mvPosition.xyz;\n #include \n #include \n #include \n #include \n}"; var fragment$6 = "#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n vec4 diffuseColor = vec4( diffuse, opacity );\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n}"; var vertex$5 = "#define STANDARD\nvarying vec3 vViewPosition;\n#ifdef USE_TRANSMISSION\n varying vec3 vWorldPosition;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n vViewPosition = - mvPosition.xyz;\n #include \n #include \n #include \n#ifdef USE_TRANSMISSION\n vWorldPosition = worldPosition.xyz;\n#endif\n}"; var fragment$5 = "#define STANDARD\n#ifdef PHYSICAL\n #define IOR\n #define USE_SPECULAR\n#endif\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef IOR\n uniform float ior;\n#endif\n#ifdef USE_SPECULAR\n uniform float specularIntensity;\n uniform vec3 specularColor;\n #ifdef USE_SPECULAR_COLORMAP\n uniform sampler2D specularColorMap;\n #endif\n #ifdef USE_SPECULAR_INTENSITYMAP\n uniform sampler2D specularIntensityMap;\n #endif\n#endif\n#ifdef USE_CLEARCOAT\n uniform float clearcoat;\n uniform float clearcoatRoughness;\n#endif\n#ifdef USE_IRIDESCENCE\n uniform float iridescence;\n uniform float iridescenceIOR;\n uniform float iridescenceThicknessMinimum;\n uniform float iridescenceThicknessMaximum;\n#endif\n#ifdef USE_SHEEN\n uniform vec3 sheenColor;\n uniform float sheenRoughness;\n #ifdef USE_SHEEN_COLORMAP\n uniform sampler2D sheenColorMap;\n #endif\n #ifdef USE_SHEEN_ROUGHNESSMAP\n uniform sampler2D sheenRoughnessMap;\n #endif\n#endif\n#ifdef USE_ANISOTROPY\n uniform vec2 anisotropyVector;\n #ifdef USE_ANISOTROPYMAP\n uniform sampler2D anisotropyMap;\n #endif\n#endif\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n vec4 diffuseColor = vec4( diffuse, opacity );\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n #include \n vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;\n #ifdef USE_SHEEN\n float sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );\n outgoingLight = outgoingLight * sheenEnergyComp + sheenSpecularDirect + sheenSpecularIndirect;\n #endif\n #ifdef USE_CLEARCOAT\n float dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );\n vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );\n outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + ( clearcoatSpecularDirect + clearcoatSpecularIndirect ) * material.clearcoat;\n #endif\n #include \n #include \n #include \n #include \n #include \n #include \n}"; var vertex$4 = "#define TOON\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n vViewPosition = - mvPosition.xyz;\n #include \n #include \n #include \n}"; var fragment$4 = "#define TOON\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n vec4 diffuseColor = vec4( diffuse, opacity );\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n #include \n #include \n #include \n #include \n #include \n #include \n}"; var vertex$3 = "uniform float size;\nuniform float scale;\n#include \n#include \n#include \n#include \n#include \n#include \n#ifdef USE_POINTS_UV\n varying vec2 vUv;\n uniform mat3 uvTransform;\n#endif\nvoid main() {\n #ifdef USE_POINTS_UV\n vUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n #endif\n #include \n #include \n #include \n #include \n #include \n gl_PointSize = size;\n #ifdef USE_SIZEATTENUATION\n bool isPerspective = isPerspectiveMatrix( projectionMatrix );\n if ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );\n #endif\n #include \n #include \n #include \n #include \n}"; var fragment$3 = "uniform vec3 diffuse;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n vec3 outgoingLight = vec3( 0.0 );\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include \n #include \n #include \n #include \n #include \n outgoingLight = diffuseColor.rgb;\n #include \n #include \n #include \n #include \n #include \n}"; var vertex$2 = "#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n}"; var fragment$2 = "uniform vec3 color;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n gl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n #include \n #include \n #include \n}"; var vertex$1 = "uniform float rotation;\nuniform vec2 center;\n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n vec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n vec2 scale;\n scale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n scale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n #ifndef USE_SIZEATTENUATION\n bool isPerspective = isPerspectiveMatrix( projectionMatrix );\n if ( isPerspective ) scale *= - mvPosition.z;\n #endif\n vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n vec2 rotatedPosition;\n rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n mvPosition.xy += rotatedPosition;\n gl_Position = projectionMatrix * mvPosition;\n #include \n #include \n #include \n}"; var fragment$1 = "uniform vec3 diffuse;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n vec3 outgoingLight = vec3( 0.0 );\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include \n #include \n #include \n #include \n #include \n outgoingLight = diffuseColor.rgb;\n #include \n #include \n #include \n #include \n}"; var ShaderChunk = { alphahash_fragment, alphahash_pars_fragment, alphamap_fragment, alphamap_pars_fragment, alphatest_fragment, alphatest_pars_fragment, aomap_fragment, aomap_pars_fragment, begin_vertex, beginnormal_vertex, bsdfs, iridescence_fragment, bumpmap_pars_fragment, clipping_planes_fragment, clipping_planes_pars_fragment, clipping_planes_pars_vertex, clipping_planes_vertex, color_fragment, color_pars_fragment, color_pars_vertex, color_vertex, common, cube_uv_reflection_fragment, defaultnormal_vertex, displacementmap_pars_vertex, displacementmap_vertex, emissivemap_fragment, emissivemap_pars_fragment, colorspace_fragment, colorspace_pars_fragment, envmap_fragment, envmap_common_pars_fragment, envmap_pars_fragment, envmap_pars_vertex, envmap_physical_pars_fragment, envmap_vertex, fog_vertex, fog_pars_vertex, fog_fragment, fog_pars_fragment, gradientmap_pars_fragment, lightmap_fragment, lightmap_pars_fragment, lights_lambert_fragment, lights_lambert_pars_fragment, lights_pars_begin, lights_toon_fragment, lights_toon_pars_fragment, lights_phong_fragment, lights_phong_pars_fragment, lights_physical_fragment, lights_physical_pars_fragment, lights_fragment_begin, lights_fragment_maps, lights_fragment_end, logdepthbuf_fragment, logdepthbuf_pars_fragment, logdepthbuf_pars_vertex, logdepthbuf_vertex, map_fragment, map_pars_fragment, map_particle_fragment, map_particle_pars_fragment, metalnessmap_fragment, metalnessmap_pars_fragment, morphcolor_vertex, morphnormal_vertex, morphtarget_pars_vertex, morphtarget_vertex, normal_fragment_begin, normal_fragment_maps, normal_pars_fragment, normal_pars_vertex, normal_vertex, normalmap_pars_fragment, clearcoat_normal_fragment_begin, clearcoat_normal_fragment_maps, clearcoat_pars_fragment, iridescence_pars_fragment, opaque_fragment, packing, premultiplied_alpha_fragment, project_vertex, dithering_fragment, dithering_pars_fragment, roughnessmap_fragment, roughnessmap_pars_fragment, shadowmap_pars_fragment, shadowmap_pars_vertex, shadowmap_vertex, shadowmask_pars_fragment, skinbase_vertex, skinning_pars_vertex, skinning_vertex, skinnormal_vertex, specularmap_fragment, specularmap_pars_fragment, tonemapping_fragment, tonemapping_pars_fragment, transmission_fragment, transmission_pars_fragment, uv_pars_fragment, uv_pars_vertex, uv_vertex, worldpos_vertex, background_vert: vertex$h, background_frag: fragment$h, backgroundCube_vert: vertex$g, backgroundCube_frag: fragment$g, cube_vert: vertex$f, cube_frag: fragment$f, depth_vert: vertex$e, depth_frag: fragment$e, distanceRGBA_vert: vertex$d, distanceRGBA_frag: fragment$d, equirect_vert: vertex$c, equirect_frag: fragment$c, linedashed_vert: vertex$b, linedashed_frag: fragment$b, meshbasic_vert: vertex$a, meshbasic_frag: fragment$a, meshlambert_vert: vertex$9, meshlambert_frag: fragment$9, meshmatcap_vert: vertex$8, meshmatcap_frag: fragment$8, meshnormal_vert: vertex$7, meshnormal_frag: fragment$7, meshphong_vert: vertex$6, meshphong_frag: fragment$6, meshphysical_vert: vertex$5, meshphysical_frag: fragment$5, meshtoon_vert: vertex$4, meshtoon_frag: fragment$4, points_vert: vertex$3, points_frag: fragment$3, shadow_vert: vertex$2, shadow_frag: fragment$2, sprite_vert: vertex$1, sprite_frag: fragment$1 }; var UniformsLib = { common: { diffuse: { value: /* @__PURE__ */ new Color(16777215) }, opacity: { value: 1 }, map: { value: null }, mapTransform: { value: /* @__PURE__ */ new Matrix3() }, alphaMap: { value: null }, alphaMapTransform: { value: /* @__PURE__ */ new Matrix3() }, alphaTest: { value: 0 } }, specularmap: { specularMap: { value: null }, specularMapTransform: { value: /* @__PURE__ */ new Matrix3() } }, envmap: { envMap: { value: null }, flipEnvMap: { value: -1 }, reflectivity: { value: 1 }, // basic, lambert, phong ior: { value: 1.5 }, // physical refractionRatio: { value: 0.98 } // basic, lambert, phong }, aomap: { aoMap: { value: null }, aoMapIntensity: { value: 1 }, aoMapTransform: { value: /* @__PURE__ */ new Matrix3() } }, lightmap: { lightMap: { value: null }, lightMapIntensity: { value: 1 }, lightMapTransform: { value: /* @__PURE__ */ new Matrix3() } }, bumpmap: { bumpMap: { value: null }, bumpMapTransform: { value: /* @__PURE__ */ new Matrix3() }, bumpScale: { value: 1 } }, normalmap: { normalMap: { value: null }, normalMapTransform: { value: /* @__PURE__ */ new Matrix3() }, normalScale: { value: /* @__PURE__ */ new Vector2(1, 1) } }, displacementmap: { displacementMap: { value: null }, displacementMapTransform: { value: /* @__PURE__ */ new Matrix3() }, displacementScale: { value: 1 }, displacementBias: { value: 0 } }, emissivemap: { emissiveMap: { value: null }, emissiveMapTransform: { value: /* @__PURE__ */ new Matrix3() } }, metalnessmap: { metalnessMap: { value: null }, metalnessMapTransform: { value: /* @__PURE__ */ new Matrix3() } }, roughnessmap: { roughnessMap: { value: null }, roughnessMapTransform: { value: /* @__PURE__ */ new Matrix3() } }, gradientmap: { gradientMap: { value: null } }, fog: { fogDensity: { value: 25e-5 }, fogNear: { value: 1 }, fogFar: { value: 2e3 }, fogColor: { value: /* @__PURE__ */ new Color(16777215) } }, lights: { ambientLightColor: { value: [] }, lightProbe: { value: [] }, directionalLights: { value: [], properties: { direction: {}, color: {} } }, directionalLightShadows: { value: [], properties: { shadowBias: {}, shadowNormalBias: {}, shadowRadius: {}, shadowMapSize: {} } }, directionalShadowMap: { value: [] }, directionalShadowMatrix: { value: [] }, spotLights: { value: [], properties: { color: {}, position: {}, direction: {}, distance: {}, coneCos: {}, penumbraCos: {}, decay: {} } }, spotLightShadows: { value: [], properties: { shadowBias: {}, shadowNormalBias: {}, shadowRadius: {}, shadowMapSize: {} } }, spotLightMap: { value: [] }, spotShadowMap: { value: [] }, spotLightMatrix: { value: [] }, pointLights: { value: [], properties: { color: {}, position: {}, decay: {}, distance: {} } }, pointLightShadows: { value: [], properties: { shadowBias: {}, shadowNormalBias: {}, shadowRadius: {}, shadowMapSize: {}, shadowCameraNear: {}, shadowCameraFar: {} } }, pointShadowMap: { value: [] }, pointShadowMatrix: { value: [] }, hemisphereLights: { value: [], properties: { direction: {}, skyColor: {}, groundColor: {} } }, // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src rectAreaLights: { value: [], properties: { color: {}, position: {}, width: {}, height: {} } }, ltc_1: { value: null }, ltc_2: { value: null } }, points: { diffuse: { value: /* @__PURE__ */ new Color(16777215) }, opacity: { value: 1 }, size: { value: 1 }, scale: { value: 1 }, map: { value: null }, alphaMap: { value: null }, alphaMapTransform: { value: /* @__PURE__ */ new Matrix3() }, alphaTest: { value: 0 }, uvTransform: { value: /* @__PURE__ */ new Matrix3() } }, sprite: { diffuse: { value: /* @__PURE__ */ new Color(16777215) }, opacity: { value: 1 }, center: { value: /* @__PURE__ */ new Vector2(0.5, 0.5) }, rotation: { value: 0 }, map: { value: null }, mapTransform: { value: /* @__PURE__ */ new Matrix3() }, alphaMap: { value: null }, alphaMapTransform: { value: /* @__PURE__ */ new Matrix3() }, alphaTest: { value: 0 } } }; var ShaderLib = { basic: { uniforms: /* @__PURE__ */ mergeUniforms([ UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.fog ]), vertexShader: ShaderChunk.meshbasic_vert, fragmentShader: ShaderChunk.meshbasic_frag }, lambert: { uniforms: /* @__PURE__ */ mergeUniforms([ UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, { emissive: { value: /* @__PURE__ */ new Color(0) } } ]), vertexShader: ShaderChunk.meshlambert_vert, fragmentShader: ShaderChunk.meshlambert_frag }, phong: { uniforms: /* @__PURE__ */ mergeUniforms([ UniformsLib.common, UniformsLib.specularmap, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, UniformsLib.lights, { emissive: { value: /* @__PURE__ */ new Color(0) }, specular: { value: /* @__PURE__ */ new Color(1118481) }, shininess: { value: 30 } } ]), vertexShader: ShaderChunk.meshphong_vert, fragmentShader: ShaderChunk.meshphong_frag }, standard: { uniforms: /* @__PURE__ */ mergeUniforms([ UniformsLib.common, UniformsLib.envmap, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.roughnessmap, UniformsLib.metalnessmap, UniformsLib.fog, UniformsLib.lights, { emissive: { value: /* @__PURE__ */ new Color(0) }, roughness: { value: 1 }, metalness: { value: 0 }, envMapIntensity: { value: 1 } // temporary } ]), vertexShader: ShaderChunk.meshphysical_vert, fragmentShader: ShaderChunk.meshphysical_frag }, toon: { uniforms: /* @__PURE__ */ mergeUniforms([ UniformsLib.common, UniformsLib.aomap, UniformsLib.lightmap, UniformsLib.emissivemap, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.gradientmap, UniformsLib.fog, UniformsLib.lights, { emissive: { value: /* @__PURE__ */ new Color(0) } } ]), vertexShader: ShaderChunk.meshtoon_vert, fragmentShader: ShaderChunk.meshtoon_frag }, matcap: { uniforms: /* @__PURE__ */ mergeUniforms([ UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, UniformsLib.fog, { matcap: { value: null } } ]), vertexShader: ShaderChunk.meshmatcap_vert, fragmentShader: ShaderChunk.meshmatcap_frag }, points: { uniforms: /* @__PURE__ */ mergeUniforms([ UniformsLib.points, UniformsLib.fog ]), vertexShader: ShaderChunk.points_vert, fragmentShader: ShaderChunk.points_frag }, dashed: { uniforms: /* @__PURE__ */ mergeUniforms([ UniformsLib.common, UniformsLib.fog, { scale: { value: 1 }, dashSize: { value: 1 }, totalSize: { value: 2 } } ]), vertexShader: ShaderChunk.linedashed_vert, fragmentShader: ShaderChunk.linedashed_frag }, depth: { uniforms: /* @__PURE__ */ mergeUniforms([ UniformsLib.common, UniformsLib.displacementmap ]), vertexShader: ShaderChunk.depth_vert, fragmentShader: ShaderChunk.depth_frag }, normal: { uniforms: /* @__PURE__ */ mergeUniforms([ UniformsLib.common, UniformsLib.bumpmap, UniformsLib.normalmap, UniformsLib.displacementmap, { opacity: { value: 1 } } ]), vertexShader: ShaderChunk.meshnormal_vert, fragmentShader: ShaderChunk.meshnormal_frag }, sprite: { uniforms: /* @__PURE__ */ mergeUniforms([ UniformsLib.sprite, UniformsLib.fog ]), vertexShader: ShaderChunk.sprite_vert, fragmentShader: ShaderChunk.sprite_frag }, background: { uniforms: { uvTransform: { value: /* @__PURE__ */ new Matrix3() }, t2D: { value: null }, backgroundIntensity: { value: 1 } }, vertexShader: ShaderChunk.background_vert, fragmentShader: ShaderChunk.background_frag }, backgroundCube: { uniforms: { envMap: { value: null }, flipEnvMap: { value: -1 }, backgroundBlurriness: { value: 0 }, backgroundIntensity: { value: 1 } }, vertexShader: ShaderChunk.backgroundCube_vert, fragmentShader: ShaderChunk.backgroundCube_frag }, cube: { uniforms: { tCube: { value: null }, tFlip: { value: -1 }, opacity: { value: 1 } }, vertexShader: ShaderChunk.cube_vert, fragmentShader: ShaderChunk.cube_frag }, equirect: { uniforms: { tEquirect: { value: null } }, vertexShader: ShaderChunk.equirect_vert, fragmentShader: ShaderChunk.equirect_frag }, distanceRGBA: { uniforms: /* @__PURE__ */ mergeUniforms([ UniformsLib.common, UniformsLib.displacementmap, { referencePosition: { value: /* @__PURE__ */ new Vector3() }, nearDistance: { value: 1 }, farDistance: { value: 1e3 } } ]), vertexShader: ShaderChunk.distanceRGBA_vert, fragmentShader: ShaderChunk.distanceRGBA_frag }, shadow: { uniforms: /* @__PURE__ */ mergeUniforms([ UniformsLib.lights, UniformsLib.fog, { color: { value: /* @__PURE__ */ new Color(0) }, opacity: { value: 1 } } ]), vertexShader: ShaderChunk.shadow_vert, fragmentShader: ShaderChunk.shadow_frag } }; ShaderLib.physical = { uniforms: /* @__PURE__ */ mergeUniforms([ ShaderLib.standard.uniforms, { clearcoat: { value: 0 }, clearcoatMap: { value: null }, clearcoatMapTransform: { value: /* @__PURE__ */ new Matrix3() }, clearcoatNormalMap: { value: null }, clearcoatNormalMapTransform: { value: /* @__PURE__ */ new Matrix3() }, clearcoatNormalScale: { value: /* @__PURE__ */ new Vector2(1, 1) }, clearcoatRoughness: { value: 0 }, clearcoatRoughnessMap: { value: null }, clearcoatRoughnessMapTransform: { value: /* @__PURE__ */ new Matrix3() }, iridescence: { value: 0 }, iridescenceMap: { value: null }, iridescenceMapTransform: { value: /* @__PURE__ */ new Matrix3() }, iridescenceIOR: { value: 1.3 }, iridescenceThicknessMinimum: { value: 100 }, iridescenceThicknessMaximum: { value: 400 }, iridescenceThicknessMap: { value: null }, iridescenceThicknessMapTransform: { value: /* @__PURE__ */ new Matrix3() }, sheen: { value: 0 }, sheenColor: { value: /* @__PURE__ */ new Color(0) }, sheenColorMap: { value: null }, sheenColorMapTransform: { value: /* @__PURE__ */ new Matrix3() }, sheenRoughness: { value: 1 }, sheenRoughnessMap: { value: null }, sheenRoughnessMapTransform: { value: /* @__PURE__ */ new Matrix3() }, transmission: { value: 0 }, transmissionMap: { value: null }, transmissionMapTransform: { value: /* @__PURE__ */ new Matrix3() }, transmissionSamplerSize: { value: /* @__PURE__ */ new Vector2() }, transmissionSamplerMap: { value: null }, thickness: { value: 0 }, thicknessMap: { value: null }, thicknessMapTransform: { value: /* @__PURE__ */ new Matrix3() }, attenuationDistance: { value: 0 }, attenuationColor: { value: /* @__PURE__ */ new Color(0) }, specularColor: { value: /* @__PURE__ */ new Color(1, 1, 1) }, specularColorMap: { value: null }, specularColorMapTransform: { value: /* @__PURE__ */ new Matrix3() }, specularIntensity: { value: 1 }, specularIntensityMap: { value: null }, specularIntensityMapTransform: { value: /* @__PURE__ */ new Matrix3() }, anisotropyVector: { value: /* @__PURE__ */ new Vector2() }, anisotropyMap: { value: null }, anisotropyMapTransform: { value: /* @__PURE__ */ new Matrix3() } } ]), vertexShader: ShaderChunk.meshphysical_vert, fragmentShader: ShaderChunk.meshphysical_frag }; var _rgb = { r: 0, b: 0, g: 0 }; function WebGLBackground(renderer3, cubemaps, cubeuvmaps, state, objects, alpha, premultipliedAlpha) { const clearColor = new Color(0); let clearAlpha = alpha === true ? 0 : 1; let planeMesh; let boxMesh; let currentBackground = null; let currentBackgroundVersion = 0; let currentTonemapping = null; function render(renderList, scene3) { let forceClear = false; let background = scene3.isScene === true ? scene3.background : null; if (background && background.isTexture) { const usePMREM = scene3.backgroundBlurriness > 0; background = (usePMREM ? cubeuvmaps : cubemaps).get(background); } if (background === null) { setClear(clearColor, clearAlpha); } else if (background && background.isColor) { setClear(background, 1); forceClear = true; } const environmentBlendMode = renderer3.xr.getEnvironmentBlendMode(); if (environmentBlendMode === "additive") { state.buffers.color.setClear(0, 0, 0, 1, premultipliedAlpha); } else if (environmentBlendMode === "alpha-blend") { state.buffers.color.setClear(0, 0, 0, 0, premultipliedAlpha); } if (renderer3.autoClear || forceClear) { renderer3.clear(renderer3.autoClearColor, renderer3.autoClearDepth, renderer3.autoClearStencil); } if (background && (background.isCubeTexture || background.mapping === CubeUVReflectionMapping)) { if (boxMesh === void 0) { boxMesh = new Mesh( new BoxGeometry(1, 1, 1), new ShaderMaterial({ name: "BackgroundCubeMaterial", uniforms: cloneUniforms(ShaderLib.backgroundCube.uniforms), vertexShader: ShaderLib.backgroundCube.vertexShader, fragmentShader: ShaderLib.backgroundCube.fragmentShader, side: BackSide, depthTest: false, depthWrite: false, fog: false }) ); boxMesh.geometry.deleteAttribute("normal"); boxMesh.geometry.deleteAttribute("uv"); boxMesh.onBeforeRender = function(renderer4, scene4, camera3) { this.matrixWorld.copyPosition(camera3.matrixWorld); }; Object.defineProperty(boxMesh.material, "envMap", { get: function() { return this.uniforms.envMap.value; } }); objects.update(boxMesh); } boxMesh.material.uniforms.envMap.value = background; boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background.isRenderTargetTexture === false ? -1 : 1; boxMesh.material.uniforms.backgroundBlurriness.value = scene3.backgroundBlurriness; boxMesh.material.uniforms.backgroundIntensity.value = scene3.backgroundIntensity; boxMesh.material.toneMapped = ColorManagement.getTransfer(background.colorSpace) !== SRGBTransfer; if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer3.toneMapping) { boxMesh.material.needsUpdate = true; currentBackground = background; currentBackgroundVersion = background.version; currentTonemapping = renderer3.toneMapping; } boxMesh.layers.enableAll(); renderList.unshift(boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null); } else if (background && background.isTexture) { if (planeMesh === void 0) { planeMesh = new Mesh( new PlaneGeometry(2, 2), new ShaderMaterial({ name: "BackgroundMaterial", uniforms: cloneUniforms(ShaderLib.background.uniforms), vertexShader: ShaderLib.background.vertexShader, fragmentShader: ShaderLib.background.fragmentShader, side: FrontSide, depthTest: false, depthWrite: false, fog: false }) ); planeMesh.geometry.deleteAttribute("normal"); Object.defineProperty(planeMesh.material, "map", { get: function() { return this.uniforms.t2D.value; } }); objects.update(planeMesh); } planeMesh.material.uniforms.t2D.value = background; planeMesh.material.uniforms.backgroundIntensity.value = scene3.backgroundIntensity; planeMesh.material.toneMapped = ColorManagement.getTransfer(background.colorSpace) !== SRGBTransfer; if (background.matrixAutoUpdate === true) { background.updateMatrix(); } planeMesh.material.uniforms.uvTransform.value.copy(background.matrix); if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer3.toneMapping) { planeMesh.material.needsUpdate = true; currentBackground = background; currentBackgroundVersion = background.version; currentTonemapping = renderer3.toneMapping; } planeMesh.layers.enableAll(); renderList.unshift(planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null); } } function setClear(color, alpha2) { color.getRGB(_rgb, getUnlitUniformColorSpace(renderer3)); state.buffers.color.setClear(_rgb.r, _rgb.g, _rgb.b, alpha2, premultipliedAlpha); } return { getClearColor: function() { return clearColor; }, setClearColor: function(color, alpha2 = 1) { clearColor.set(color); clearAlpha = alpha2; setClear(clearColor, clearAlpha); }, getClearAlpha: function() { return clearAlpha; }, setClearAlpha: function(alpha2) { clearAlpha = alpha2; setClear(clearColor, clearAlpha); }, render }; } function WebGLBindingStates(gl, extensions, attributes, capabilities) { const maxVertexAttributes = gl.getParameter(gl.MAX_VERTEX_ATTRIBS); const extension = capabilities.isWebGL2 ? null : extensions.get("OES_vertex_array_object"); const vaoAvailable = capabilities.isWebGL2 || extension !== null; const bindingStates = {}; const defaultState = createBindingState(null); let currentState = defaultState; let forceUpdate = false; function setup(object, material, program, geometry, index6) { let updateBuffers = false; if (vaoAvailable) { const state = getBindingState(geometry, program, material); if (currentState !== state) { currentState = state; bindVertexArrayObject(currentState.object); } updateBuffers = needsUpdate(object, geometry, program, index6); if (updateBuffers) saveCache(object, geometry, program, index6); } else { const wireframe = material.wireframe === true; if (currentState.geometry !== geometry.id || currentState.program !== program.id || currentState.wireframe !== wireframe) { currentState.geometry = geometry.id; currentState.program = program.id; currentState.wireframe = wireframe; updateBuffers = true; } } if (index6 !== null) { attributes.update(index6, gl.ELEMENT_ARRAY_BUFFER); } if (updateBuffers || forceUpdate) { forceUpdate = false; setupVertexAttributes(object, material, program, geometry); if (index6 !== null) { gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, attributes.get(index6).buffer); } } } function createVertexArrayObject() { if (capabilities.isWebGL2) return gl.createVertexArray(); return extension.createVertexArrayOES(); } function bindVertexArrayObject(vao) { if (capabilities.isWebGL2) return gl.bindVertexArray(vao); return extension.bindVertexArrayOES(vao); } function deleteVertexArrayObject(vao) { if (capabilities.isWebGL2) return gl.deleteVertexArray(vao); return extension.deleteVertexArrayOES(vao); } function getBindingState(geometry, program, material) { const wireframe = material.wireframe === true; let programMap = bindingStates[geometry.id]; if (programMap === void 0) { programMap = {}; bindingStates[geometry.id] = programMap; } let stateMap = programMap[program.id]; if (stateMap === void 0) { stateMap = {}; programMap[program.id] = stateMap; } let state = stateMap[wireframe]; if (state === void 0) { state = createBindingState(createVertexArrayObject()); stateMap[wireframe] = state; } return state; } function createBindingState(vao) { const newAttributes = []; const enabledAttributes = []; const attributeDivisors = []; for (let i = 0; i < maxVertexAttributes; i++) { newAttributes[i] = 0; enabledAttributes[i] = 0; attributeDivisors[i] = 0; } return { // for backward compatibility on non-VAO support browser geometry: null, program: null, wireframe: false, newAttributes, enabledAttributes, attributeDivisors, object: vao, attributes: {}, index: null }; } function needsUpdate(object, geometry, program, index6) { const cachedAttributes = currentState.attributes; const geometryAttributes = geometry.attributes; let attributesNum = 0; const programAttributes = program.getAttributes(); for (const name in programAttributes) { const programAttribute = programAttributes[name]; if (programAttribute.location >= 0) { const cachedAttribute = cachedAttributes[name]; let geometryAttribute = geometryAttributes[name]; if (geometryAttribute === void 0) { if (name === "instanceMatrix" && object.instanceMatrix) geometryAttribute = object.instanceMatrix; if (name === "instanceColor" && object.instanceColor) geometryAttribute = object.instanceColor; } if (cachedAttribute === void 0) return true; if (cachedAttribute.attribute !== geometryAttribute) return true; if (geometryAttribute && cachedAttribute.data !== geometryAttribute.data) return true; attributesNum++; } } if (currentState.attributesNum !== attributesNum) return true; if (currentState.index !== index6) return true; return false; } function saveCache(object, geometry, program, index6) { const cache = {}; const attributes2 = geometry.attributes; let attributesNum = 0; const programAttributes = program.getAttributes(); for (const name in programAttributes) { const programAttribute = programAttributes[name]; if (programAttribute.location >= 0) { let attribute = attributes2[name]; if (attribute === void 0) { if (name === "instanceMatrix" && object.instanceMatrix) attribute = object.instanceMatrix; if (name === "instanceColor" && object.instanceColor) attribute = object.instanceColor; } const data = {}; data.attribute = attribute; if (attribute && attribute.data) { data.data = attribute.data; } cache[name] = data; attributesNum++; } } currentState.attributes = cache; currentState.attributesNum = attributesNum; currentState.index = index6; } function initAttributes() { const newAttributes = currentState.newAttributes; for (let i = 0, il = newAttributes.length; i < il; i++) { newAttributes[i] = 0; } } function enableAttribute(attribute) { enableAttributeAndDivisor(attribute, 0); } function enableAttributeAndDivisor(attribute, meshPerAttribute) { const newAttributes = currentState.newAttributes; const enabledAttributes = currentState.enabledAttributes; const attributeDivisors = currentState.attributeDivisors; newAttributes[attribute] = 1; if (enabledAttributes[attribute] === 0) { gl.enableVertexAttribArray(attribute); enabledAttributes[attribute] = 1; } if (attributeDivisors[attribute] !== meshPerAttribute) { const extension2 = capabilities.isWebGL2 ? gl : extensions.get("ANGLE_instanced_arrays"); extension2[capabilities.isWebGL2 ? "vertexAttribDivisor" : "vertexAttribDivisorANGLE"](attribute, meshPerAttribute); attributeDivisors[attribute] = meshPerAttribute; } } function disableUnusedAttributes() { const newAttributes = currentState.newAttributes; const enabledAttributes = currentState.enabledAttributes; for (let i = 0, il = enabledAttributes.length; i < il; i++) { if (enabledAttributes[i] !== newAttributes[i]) { gl.disableVertexAttribArray(i); enabledAttributes[i] = 0; } } } function vertexAttribPointer(index6, size, type, normalized, stride, offset, integer) { if (integer === true) { gl.vertexAttribIPointer(index6, size, type, stride, offset); } else { gl.vertexAttribPointer(index6, size, type, normalized, stride, offset); } } function setupVertexAttributes(object, material, program, geometry) { if (capabilities.isWebGL2 === false && (object.isInstancedMesh || geometry.isInstancedBufferGeometry)) { if (extensions.get("ANGLE_instanced_arrays") === null) return; } initAttributes(); const geometryAttributes = geometry.attributes; const programAttributes = program.getAttributes(); const materialDefaultAttributeValues = material.defaultAttributeValues; for (const name in programAttributes) { const programAttribute = programAttributes[name]; if (programAttribute.location >= 0) { let geometryAttribute = geometryAttributes[name]; if (geometryAttribute === void 0) { if (name === "instanceMatrix" && object.instanceMatrix) geometryAttribute = object.instanceMatrix; if (name === "instanceColor" && object.instanceColor) geometryAttribute = object.instanceColor; } if (geometryAttribute !== void 0) { const normalized = geometryAttribute.normalized; const size = geometryAttribute.itemSize; const attribute = attributes.get(geometryAttribute); if (attribute === void 0) continue; const buffer = attribute.buffer; const type = attribute.type; const bytesPerElement = attribute.bytesPerElement; const integer = capabilities.isWebGL2 === true && (type === gl.INT || type === gl.UNSIGNED_INT || geometryAttribute.gpuType === IntType); if (geometryAttribute.isInterleavedBufferAttribute) { const data = geometryAttribute.data; const stride = data.stride; const offset = geometryAttribute.offset; if (data.isInstancedInterleavedBuffer) { for (let i = 0; i < programAttribute.locationSize; i++) { enableAttributeAndDivisor(programAttribute.location + i, data.meshPerAttribute); } if (object.isInstancedMesh !== true && geometry._maxInstanceCount === void 0) { geometry._maxInstanceCount = data.meshPerAttribute * data.count; } } else { for (let i = 0; i < programAttribute.locationSize; i++) { enableAttribute(programAttribute.location + i); } } gl.bindBuffer(gl.ARRAY_BUFFER, buffer); for (let i = 0; i < programAttribute.locationSize; i++) { vertexAttribPointer( programAttribute.location + i, size / programAttribute.locationSize, type, normalized, stride * bytesPerElement, (offset + size / programAttribute.locationSize * i) * bytesPerElement, integer ); } } else { if (geometryAttribute.isInstancedBufferAttribute) { for (let i = 0; i < programAttribute.locationSize; i++) { enableAttributeAndDivisor(programAttribute.location + i, geometryAttribute.meshPerAttribute); } if (object.isInstancedMesh !== true && geometry._maxInstanceCount === void 0) { geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count; } } else { for (let i = 0; i < programAttribute.locationSize; i++) { enableAttribute(programAttribute.location + i); } } gl.bindBuffer(gl.ARRAY_BUFFER, buffer); for (let i = 0; i < programAttribute.locationSize; i++) { vertexAttribPointer( programAttribute.location + i, size / programAttribute.locationSize, type, normalized, size * bytesPerElement, size / programAttribute.locationSize * i * bytesPerElement, integer ); } } } else if (materialDefaultAttributeValues !== void 0) { const value = materialDefaultAttributeValues[name]; if (value !== void 0) { switch (value.length) { case 2: gl.vertexAttrib2fv(programAttribute.location, value); break; case 3: gl.vertexAttrib3fv(programAttribute.location, value); break; case 4: gl.vertexAttrib4fv(programAttribute.location, value); break; default: gl.vertexAttrib1fv(programAttribute.location, value); } } } } } disableUnusedAttributes(); } function dispose() { reset(); for (const geometryId in bindingStates) { const programMap = bindingStates[geometryId]; for (const programId in programMap) { const stateMap = programMap[programId]; for (const wireframe in stateMap) { deleteVertexArrayObject(stateMap[wireframe].object); delete stateMap[wireframe]; } delete programMap[programId]; } delete bindingStates[geometryId]; } } function releaseStatesOfGeometry(geometry) { if (bindingStates[geometry.id] === void 0) return; const programMap = bindingStates[geometry.id]; for (const programId in programMap) { const stateMap = programMap[programId]; for (const wireframe in stateMap) { deleteVertexArrayObject(stateMap[wireframe].object); delete stateMap[wireframe]; } delete programMap[programId]; } delete bindingStates[geometry.id]; } function releaseStatesOfProgram(program) { for (const geometryId in bindingStates) { const programMap = bindingStates[geometryId]; if (programMap[program.id] === void 0) continue; const stateMap = programMap[program.id]; for (const wireframe in stateMap) { deleteVertexArrayObject(stateMap[wireframe].object); delete stateMap[wireframe]; } delete programMap[program.id]; } } function reset() { resetDefaultState(); forceUpdate = true; if (currentState === defaultState) return; currentState = defaultState; bindVertexArrayObject(currentState.object); } function resetDefaultState() { defaultState.geometry = null; defaultState.program = null; defaultState.wireframe = false; } return { setup, reset, resetDefaultState, dispose, releaseStatesOfGeometry, releaseStatesOfProgram, initAttributes, enableAttribute, disableUnusedAttributes }; } function WebGLBufferRenderer(gl, extensions, info, capabilities) { const isWebGL2 = capabilities.isWebGL2; let mode; function setMode(value) { mode = value; } function render(start, count) { gl.drawArrays(mode, start, count); info.update(count, mode, 1); } function renderInstances(start, count, primcount) { if (primcount === 0) return; let extension, methodName; if (isWebGL2) { extension = gl; methodName = "drawArraysInstanced"; } else { extension = extensions.get("ANGLE_instanced_arrays"); methodName = "drawArraysInstancedANGLE"; if (extension === null) { console.error("THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays."); return; } } extension[methodName](mode, start, count, primcount); info.update(count, mode, primcount); } this.setMode = setMode; this.render = render; this.renderInstances = renderInstances; } function WebGLCapabilities(gl, extensions, parameters) { let maxAnisotropy; function getMaxAnisotropy() { if (maxAnisotropy !== void 0) return maxAnisotropy; if (extensions.has("EXT_texture_filter_anisotropic") === true) { const extension = extensions.get("EXT_texture_filter_anisotropic"); maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT); } else { maxAnisotropy = 0; } return maxAnisotropy; } function getMaxPrecision(precision2) { if (precision2 === "highp") { if (gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.HIGH_FLOAT).precision > 0 && gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT).precision > 0) { return "highp"; } precision2 = "mediump"; } if (precision2 === "mediump") { if (gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.MEDIUM_FLOAT).precision > 0 && gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT).precision > 0) { return "mediump"; } } return "lowp"; } const isWebGL2 = typeof WebGL2RenderingContext !== "undefined" && gl.constructor.name === "WebGL2RenderingContext"; let precision = parameters.precision !== void 0 ? parameters.precision : "highp"; const maxPrecision = getMaxPrecision(precision); if (maxPrecision !== precision) { console.warn("THREE.WebGLRenderer:", precision, "not supported, using", maxPrecision, "instead."); precision = maxPrecision; } const drawBuffers = isWebGL2 || extensions.has("WEBGL_draw_buffers"); const logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true; const maxTextures = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS); const maxVertexTextures = gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS); const maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE); const maxCubemapSize = gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE); const maxAttributes = gl.getParameter(gl.MAX_VERTEX_ATTRIBS); const maxVertexUniforms = gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS); const maxVaryings = gl.getParameter(gl.MAX_VARYING_VECTORS); const maxFragmentUniforms = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS); const vertexTextures = maxVertexTextures > 0; const floatFragmentTextures = isWebGL2 || extensions.has("OES_texture_float"); const floatVertexTextures = vertexTextures && floatFragmentTextures; const maxSamples = isWebGL2 ? gl.getParameter(gl.MAX_SAMPLES) : 0; return { isWebGL2, drawBuffers, getMaxAnisotropy, getMaxPrecision, precision, logarithmicDepthBuffer, maxTextures, maxVertexTextures, maxTextureSize, maxCubemapSize, maxAttributes, maxVertexUniforms, maxVaryings, maxFragmentUniforms, vertexTextures, floatFragmentTextures, floatVertexTextures, maxSamples }; } function WebGLClipping(properties) { const scope = this; let globalState = null, numGlobalPlanes = 0, localClippingEnabled = false, renderingShadows = false; const plane = new Plane(), viewNormalMatrix = new Matrix3(), uniform = { value: null, needsUpdate: false }; this.uniform = uniform; this.numPlanes = 0; this.numIntersection = 0; this.init = function(planes, enableLocalClipping) { const enabled = planes.length !== 0 || enableLocalClipping || // enable state of previous frame - the clipping code has to // run another frame in order to reset the state: numGlobalPlanes !== 0 || localClippingEnabled; localClippingEnabled = enableLocalClipping; numGlobalPlanes = planes.length; return enabled; }; this.beginShadows = function() { renderingShadows = true; projectPlanes(null); }; this.endShadows = function() { renderingShadows = false; }; this.setGlobalState = function(planes, camera3) { globalState = projectPlanes(planes, camera3, 0); }; this.setState = function(material, camera3, useCache) { const planes = material.clippingPlanes, clipIntersection = material.clipIntersection, clipShadows = material.clipShadows; const materialProperties = properties.get(material); if (!localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && !clipShadows) { if (renderingShadows) { projectPlanes(null); } else { resetGlobalState(); } } else { const nGlobal = renderingShadows ? 0 : numGlobalPlanes, lGlobal = nGlobal * 4; let dstArray = materialProperties.clippingState || null; uniform.value = dstArray; dstArray = projectPlanes(planes, camera3, lGlobal, useCache); for (let i = 0; i !== lGlobal; ++i) { dstArray[i] = globalState[i]; } materialProperties.clippingState = dstArray; this.numIntersection = clipIntersection ? this.numPlanes : 0; this.numPlanes += nGlobal; } }; function resetGlobalState() { if (uniform.value !== globalState) { uniform.value = globalState; uniform.needsUpdate = numGlobalPlanes > 0; } scope.numPlanes = numGlobalPlanes; scope.numIntersection = 0; } function projectPlanes(planes, camera3, dstOffset, skipTransform) { const nPlanes = planes !== null ? planes.length : 0; let dstArray = null; if (nPlanes !== 0) { dstArray = uniform.value; if (skipTransform !== true || dstArray === null) { const flatSize = dstOffset + nPlanes * 4, viewMatrix = camera3.matrixWorldInverse; viewNormalMatrix.getNormalMatrix(viewMatrix); if (dstArray === null || dstArray.length < flatSize) { dstArray = new Float32Array(flatSize); } for (let i = 0, i4 = dstOffset; i !== nPlanes; ++i, i4 += 4) { plane.copy(planes[i]).applyMatrix4(viewMatrix, viewNormalMatrix); plane.normal.toArray(dstArray, i4); dstArray[i4 + 3] = plane.constant; } } uniform.value = dstArray; uniform.needsUpdate = true; } scope.numPlanes = nPlanes; scope.numIntersection = 0; return dstArray; } } function WebGLCubeMaps(renderer3) { let cubemaps = /* @__PURE__ */ new WeakMap(); function mapTextureMapping(texture, mapping) { if (mapping === EquirectangularReflectionMapping) { texture.mapping = CubeReflectionMapping; } else if (mapping === EquirectangularRefractionMapping) { texture.mapping = CubeRefractionMapping; } return texture; } function get2(texture) { if (texture && texture.isTexture && texture.isRenderTargetTexture === false) { const mapping = texture.mapping; if (mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping) { if (cubemaps.has(texture)) { const cubemap = cubemaps.get(texture).texture; return mapTextureMapping(cubemap, texture.mapping); } else { const image = texture.image; if (image && image.height > 0) { const renderTarget = new WebGLCubeRenderTarget(image.height / 2); renderTarget.fromEquirectangularTexture(renderer3, texture); cubemaps.set(texture, renderTarget); texture.addEventListener("dispose", onTextureDispose); return mapTextureMapping(renderTarget.texture, texture.mapping); } else { return null; } } } } return texture; } function onTextureDispose(event) { const texture = event.target; texture.removeEventListener("dispose", onTextureDispose); const cubemap = cubemaps.get(texture); if (cubemap !== void 0) { cubemaps.delete(texture); cubemap.dispose(); } } function dispose() { cubemaps = /* @__PURE__ */ new WeakMap(); } return { get: get2, dispose }; } var OrthographicCamera = class extends Camera { constructor(left = -1, right = 1, top = 1, bottom = -1, near = 0.1, far = 2e3) { super(); this.isOrthographicCamera = true; this.type = "OrthographicCamera"; this.zoom = 1; this.view = null; this.left = left; this.right = right; this.top = top; this.bottom = bottom; this.near = near; this.far = far; this.updateProjectionMatrix(); } copy(source, recursive) { super.copy(source, recursive); this.left = source.left; this.right = source.right; this.top = source.top; this.bottom = source.bottom; this.near = source.near; this.far = source.far; this.zoom = source.zoom; this.view = source.view === null ? null : Object.assign({}, source.view); return this; } setViewOffset(fullWidth, fullHeight, x3, y3, width, height) { if (this.view === null) { this.view = { enabled: true, fullWidth: 1, fullHeight: 1, offsetX: 0, offsetY: 0, width: 1, height: 1 }; } this.view.enabled = true; this.view.fullWidth = fullWidth; this.view.fullHeight = fullHeight; this.view.offsetX = x3; this.view.offsetY = y3; this.view.width = width; this.view.height = height; this.updateProjectionMatrix(); } clearViewOffset() { if (this.view !== null) { this.view.enabled = false; } this.updateProjectionMatrix(); } updateProjectionMatrix() { const dx = (this.right - this.left) / (2 * this.zoom); const dy = (this.top - this.bottom) / (2 * this.zoom); const cx = (this.right + this.left) / 2; const cy = (this.top + this.bottom) / 2; let left = cx - dx; let right = cx + dx; let top = cy + dy; let bottom = cy - dy; if (this.view !== null && this.view.enabled) { const scaleW = (this.right - this.left) / this.view.fullWidth / this.zoom; const scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom; left += scaleW * this.view.offsetX; right = left + scaleW * this.view.width; top -= scaleH * this.view.offsetY; bottom = top - scaleH * this.view.height; } this.projectionMatrix.makeOrthographic(left, right, top, bottom, this.near, this.far, this.coordinateSystem); this.projectionMatrixInverse.copy(this.projectionMatrix).invert(); } toJSON(meta) { const data = super.toJSON(meta); data.object.zoom = this.zoom; data.object.left = this.left; data.object.right = this.right; data.object.top = this.top; data.object.bottom = this.bottom; data.object.near = this.near; data.object.far = this.far; if (this.view !== null) data.object.view = Object.assign({}, this.view); return data; } }; var LOD_MIN = 4; var EXTRA_LOD_SIGMA = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582]; var MAX_SAMPLES = 20; var _flatCamera = /* @__PURE__ */ new OrthographicCamera(); var _clearColor = /* @__PURE__ */ new Color(); var _oldTarget = null; var _oldActiveCubeFace = 0; var _oldActiveMipmapLevel = 0; var PHI = (1 + Math.sqrt(5)) / 2; var INV_PHI = 1 / PHI; var _axisDirections = [ /* @__PURE__ */ new Vector3(1, 1, 1), /* @__PURE__ */ new Vector3(-1, 1, 1), /* @__PURE__ */ new Vector3(1, 1, -1), /* @__PURE__ */ new Vector3(-1, 1, -1), /* @__PURE__ */ new Vector3(0, PHI, INV_PHI), /* @__PURE__ */ new Vector3(0, PHI, -INV_PHI), /* @__PURE__ */ new Vector3(INV_PHI, 0, PHI), /* @__PURE__ */ new Vector3(-INV_PHI, 0, PHI), /* @__PURE__ */ new Vector3(PHI, INV_PHI, 0), /* @__PURE__ */ new Vector3(-PHI, INV_PHI, 0) ]; var PMREMGenerator = class { constructor(renderer3) { this._renderer = renderer3; this._pingPongRenderTarget = null; this._lodMax = 0; this._cubeSize = 0; this._lodPlanes = []; this._sizeLods = []; this._sigmas = []; this._blurMaterial = null; this._cubemapMaterial = null; this._equirectMaterial = null; this._compileMaterial(this._blurMaterial); } /** * Generates a PMREM from a supplied Scene, which can be faster than using an * image if networking bandwidth is low. Optional sigma specifies a blur radius * in radians to be applied to the scene before PMREM generation. Optional near * and far planes ensure the scene is rendered in its entirety (the cubeCamera * is placed at the origin). */ fromScene(scene3, sigma = 0, near = 0.1, far = 100) { _oldTarget = this._renderer.getRenderTarget(); _oldActiveCubeFace = this._renderer.getActiveCubeFace(); _oldActiveMipmapLevel = this._renderer.getActiveMipmapLevel(); this._setSize(256); const cubeUVRenderTarget = this._allocateTargets(); cubeUVRenderTarget.depthBuffer = true; this._sceneToCubeUV(scene3, near, far, cubeUVRenderTarget); if (sigma > 0) { this._blur(cubeUVRenderTarget, 0, 0, sigma); } this._applyPMREM(cubeUVRenderTarget); this._cleanup(cubeUVRenderTarget); return cubeUVRenderTarget; } /** * Generates a PMREM from an equirectangular texture, which can be either LDR * or HDR. The ideal input image size is 1k (1024 x 512), * as this matches best with the 256 x 256 cubemap output. */ fromEquirectangular(equirectangular, renderTarget = null) { return this._fromTexture(equirectangular, renderTarget); } /** * Generates a PMREM from an cubemap texture, which can be either LDR * or HDR. The ideal input cube size is 256 x 256, * as this matches best with the 256 x 256 cubemap output. */ fromCubemap(cubemap, renderTarget = null) { return this._fromTexture(cubemap, renderTarget); } /** * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during * your texture's network fetch for increased concurrency. */ compileCubemapShader() { if (this._cubemapMaterial === null) { this._cubemapMaterial = _getCubemapMaterial(); this._compileMaterial(this._cubemapMaterial); } } /** * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during * your texture's network fetch for increased concurrency. */ compileEquirectangularShader() { if (this._equirectMaterial === null) { this._equirectMaterial = _getEquirectMaterial(); this._compileMaterial(this._equirectMaterial); } } /** * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class, * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on * one of them will cause any others to also become unusable. */ dispose() { this._dispose(); if (this._cubemapMaterial !== null) this._cubemapMaterial.dispose(); if (this._equirectMaterial !== null) this._equirectMaterial.dispose(); } // private interface _setSize(cubeSize) { this._lodMax = Math.floor(Math.log2(cubeSize)); this._cubeSize = Math.pow(2, this._lodMax); } _dispose() { if (this._blurMaterial !== null) this._blurMaterial.dispose(); if (this._pingPongRenderTarget !== null) this._pingPongRenderTarget.dispose(); for (let i = 0; i < this._lodPlanes.length; i++) { this._lodPlanes[i].dispose(); } } _cleanup(outputTarget) { this._renderer.setRenderTarget(_oldTarget, _oldActiveCubeFace, _oldActiveMipmapLevel); outputTarget.scissorTest = false; _setViewport(outputTarget, 0, 0, outputTarget.width, outputTarget.height); } _fromTexture(texture, renderTarget) { if (texture.mapping === CubeReflectionMapping || texture.mapping === CubeRefractionMapping) { this._setSize(texture.image.length === 0 ? 16 : texture.image[0].width || texture.image[0].image.width); } else { this._setSize(texture.image.width / 4); } _oldTarget = this._renderer.getRenderTarget(); _oldActiveCubeFace = this._renderer.getActiveCubeFace(); _oldActiveMipmapLevel = this._renderer.getActiveMipmapLevel(); const cubeUVRenderTarget = renderTarget || this._allocateTargets(); this._textureToCubeUV(texture, cubeUVRenderTarget); this._applyPMREM(cubeUVRenderTarget); this._cleanup(cubeUVRenderTarget); return cubeUVRenderTarget; } _allocateTargets() { const width = 3 * Math.max(this._cubeSize, 16 * 7); const height = 4 * this._cubeSize; const params = { magFilter: LinearFilter, minFilter: LinearFilter, generateMipmaps: false, type: HalfFloatType, format: RGBAFormat, colorSpace: LinearSRGBColorSpace, depthBuffer: false }; const cubeUVRenderTarget = _createRenderTarget(width, height, params); if (this._pingPongRenderTarget === null || this._pingPongRenderTarget.width !== width || this._pingPongRenderTarget.height !== height) { if (this._pingPongRenderTarget !== null) { this._dispose(); } this._pingPongRenderTarget = _createRenderTarget(width, height, params); const { _lodMax } = this; ({ sizeLods: this._sizeLods, lodPlanes: this._lodPlanes, sigmas: this._sigmas } = _createPlanes(_lodMax)); this._blurMaterial = _getBlurShader(_lodMax, width, height); } return cubeUVRenderTarget; } _compileMaterial(material) { const tmpMesh = new Mesh(this._lodPlanes[0], material); this._renderer.compile(tmpMesh, _flatCamera); } _sceneToCubeUV(scene3, near, far, cubeUVRenderTarget) { const fov3 = 90; const aspect3 = 1; const cubeCamera = new PerspectiveCamera(fov3, aspect3, near, far); const upSign = [1, -1, 1, 1, 1, 1]; const forwardSign = [1, 1, 1, -1, -1, -1]; const renderer3 = this._renderer; const originalAutoClear = renderer3.autoClear; const toneMapping = renderer3.toneMapping; renderer3.getClearColor(_clearColor); renderer3.toneMapping = NoToneMapping; renderer3.autoClear = false; const backgroundMaterial = new MeshBasicMaterial({ name: "PMREM.Background", side: BackSide, depthWrite: false, depthTest: false }); const backgroundBox = new Mesh(new BoxGeometry(), backgroundMaterial); let useSolidColor = false; const background = scene3.background; if (background) { if (background.isColor) { backgroundMaterial.color.copy(background); scene3.background = null; useSolidColor = true; } } else { backgroundMaterial.color.copy(_clearColor); useSolidColor = true; } for (let i = 0; i < 6; i++) { const col = i % 3; if (col === 0) { cubeCamera.up.set(0, upSign[i], 0); cubeCamera.lookAt(forwardSign[i], 0, 0); } else if (col === 1) { cubeCamera.up.set(0, 0, upSign[i]); cubeCamera.lookAt(0, forwardSign[i], 0); } else { cubeCamera.up.set(0, upSign[i], 0); cubeCamera.lookAt(0, 0, forwardSign[i]); } const size = this._cubeSize; _setViewport(cubeUVRenderTarget, col * size, i > 2 ? size : 0, size, size); renderer3.setRenderTarget(cubeUVRenderTarget); if (useSolidColor) { renderer3.render(backgroundBox, cubeCamera); } renderer3.render(scene3, cubeCamera); } backgroundBox.geometry.dispose(); backgroundBox.material.dispose(); renderer3.toneMapping = toneMapping; renderer3.autoClear = originalAutoClear; scene3.background = background; } _textureToCubeUV(texture, cubeUVRenderTarget) { const renderer3 = this._renderer; const isCubeTexture = texture.mapping === CubeReflectionMapping || texture.mapping === CubeRefractionMapping; if (isCubeTexture) { if (this._cubemapMaterial === null) { this._cubemapMaterial = _getCubemapMaterial(); } this._cubemapMaterial.uniforms.flipEnvMap.value = texture.isRenderTargetTexture === false ? -1 : 1; } else { if (this._equirectMaterial === null) { this._equirectMaterial = _getEquirectMaterial(); } } const material = isCubeTexture ? this._cubemapMaterial : this._equirectMaterial; const mesh = new Mesh(this._lodPlanes[0], material); const uniforms = material.uniforms; uniforms["envMap"].value = texture; const size = this._cubeSize; _setViewport(cubeUVRenderTarget, 0, 0, 3 * size, 2 * size); renderer3.setRenderTarget(cubeUVRenderTarget); renderer3.render(mesh, _flatCamera); } _applyPMREM(cubeUVRenderTarget) { const renderer3 = this._renderer; const autoClear = renderer3.autoClear; renderer3.autoClear = false; for (let i = 1; i < this._lodPlanes.length; i++) { const sigma = Math.sqrt(this._sigmas[i] * this._sigmas[i] - this._sigmas[i - 1] * this._sigmas[i - 1]); const poleAxis = _axisDirections[(i - 1) % _axisDirections.length]; this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis); } renderer3.autoClear = autoClear; } /** * This is a two-pass Gaussian blur for a cubemap. Normally this is done * vertically and horizontally, but this breaks down on a cube. Here we apply * the blur latitudinally (around the poles), and then longitudinally (towards * the poles) to approximate the orthogonally-separable blur. It is least * accurate at the poles, but still does a decent job. */ _blur(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) { const pingPongRenderTarget = this._pingPongRenderTarget; this._halfBlur( cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, "latitudinal", poleAxis ); this._halfBlur( pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, "longitudinal", poleAxis ); } _halfBlur(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) { const renderer3 = this._renderer; const blurMaterial = this._blurMaterial; if (direction !== "latitudinal" && direction !== "longitudinal") { console.error( "blur direction must be either latitudinal or longitudinal!" ); } const STANDARD_DEVIATIONS = 3; const blurMesh = new Mesh(this._lodPlanes[lodOut], blurMaterial); const blurUniforms = blurMaterial.uniforms; const pixels = this._sizeLods[lodIn] - 1; const radiansPerPixel = isFinite(sigmaRadians) ? Math.PI / (2 * pixels) : 2 * Math.PI / (2 * MAX_SAMPLES - 1); const sigmaPixels = sigmaRadians / radiansPerPixel; const samples = isFinite(sigmaRadians) ? 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels) : MAX_SAMPLES; if (samples > MAX_SAMPLES) { console.warn(`sigmaRadians, ${sigmaRadians}, is too large and will clip, as it requested ${samples} samples when the maximum is set to ${MAX_SAMPLES}`); } const weights = []; let sum = 0; for (let i = 0; i < MAX_SAMPLES; ++i) { const x4 = i / sigmaPixels; const weight = Math.exp(-x4 * x4 / 2); weights.push(weight); if (i === 0) { sum += weight; } else if (i < samples) { sum += 2 * weight; } } for (let i = 0; i < weights.length; i++) { weights[i] = weights[i] / sum; } blurUniforms["envMap"].value = targetIn.texture; blurUniforms["samples"].value = samples; blurUniforms["weights"].value = weights; blurUniforms["latitudinal"].value = direction === "latitudinal"; if (poleAxis) { blurUniforms["poleAxis"].value = poleAxis; } const { _lodMax } = this; blurUniforms["dTheta"].value = radiansPerPixel; blurUniforms["mipInt"].value = _lodMax - lodIn; const outputSize = this._sizeLods[lodOut]; const x3 = 3 * outputSize * (lodOut > _lodMax - LOD_MIN ? lodOut - _lodMax + LOD_MIN : 0); const y3 = 4 * (this._cubeSize - outputSize); _setViewport(targetOut, x3, y3, 3 * outputSize, 2 * outputSize); renderer3.setRenderTarget(targetOut); renderer3.render(blurMesh, _flatCamera); } }; function _createPlanes(lodMax) { const lodPlanes = []; const sizeLods = []; const sigmas = []; let lod = lodMax; const totalLods = lodMax - LOD_MIN + 1 + EXTRA_LOD_SIGMA.length; for (let i = 0; i < totalLods; i++) { const sizeLod = Math.pow(2, lod); sizeLods.push(sizeLod); let sigma = 1 / sizeLod; if (i > lodMax - LOD_MIN) { sigma = EXTRA_LOD_SIGMA[i - lodMax + LOD_MIN - 1]; } else if (i === 0) { sigma = 0; } sigmas.push(sigma); const texelSize = 1 / (sizeLod - 2); const min2 = -texelSize; const max2 = 1 + texelSize; const uv1 = [min2, min2, max2, min2, max2, max2, min2, min2, max2, max2, min2, max2]; const cubeFaces = 6; const vertices = 6; const positionSize = 3; const uvSize = 2; const faceIndexSize = 1; const position = new Float32Array(positionSize * vertices * cubeFaces); const uv = new Float32Array(uvSize * vertices * cubeFaces); const faceIndex = new Float32Array(faceIndexSize * vertices * cubeFaces); for (let face = 0; face < cubeFaces; face++) { const x3 = face % 3 * 2 / 3 - 1; const y3 = face > 2 ? 0 : -1; const coordinates = [ x3, y3, 0, x3 + 2 / 3, y3, 0, x3 + 2 / 3, y3 + 1, 0, x3, y3, 0, x3 + 2 / 3, y3 + 1, 0, x3, y3 + 1, 0 ]; position.set(coordinates, positionSize * vertices * face); uv.set(uv1, uvSize * vertices * face); const fill = [face, face, face, face, face, face]; faceIndex.set(fill, faceIndexSize * vertices * face); } const planes = new BufferGeometry(); planes.setAttribute("position", new BufferAttribute(position, positionSize)); planes.setAttribute("uv", new BufferAttribute(uv, uvSize)); planes.setAttribute("faceIndex", new BufferAttribute(faceIndex, faceIndexSize)); lodPlanes.push(planes); if (lod > LOD_MIN) { lod--; } } return { lodPlanes, sizeLods, sigmas }; } function _createRenderTarget(width, height, params) { const cubeUVRenderTarget = new WebGLRenderTarget(width, height, params); cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping; cubeUVRenderTarget.texture.name = "PMREM.cubeUv"; cubeUVRenderTarget.scissorTest = true; return cubeUVRenderTarget; } function _setViewport(target, x3, y3, width, height) { target.viewport.set(x3, y3, width, height); target.scissor.set(x3, y3, width, height); } function _getBlurShader(lodMax, width, height) { const weights = new Float32Array(MAX_SAMPLES); const poleAxis = new Vector3(0, 1, 0); const shaderMaterial = new ShaderMaterial({ name: "SphericalGaussianBlur", defines: { "n": MAX_SAMPLES, "CUBEUV_TEXEL_WIDTH": 1 / width, "CUBEUV_TEXEL_HEIGHT": 1 / height, "CUBEUV_MAX_MIP": `${lodMax}.0` }, uniforms: { "envMap": { value: null }, "samples": { value: 1 }, "weights": { value: weights }, "latitudinal": { value: false }, "dTheta": { value: 0 }, "mipInt": { value: 0 }, "poleAxis": { value: poleAxis } }, vertexShader: _getCommonVertexShader(), fragmentShader: ( /* glsl */ ` precision mediump float; precision mediump int; varying vec3 vOutputDirection; uniform sampler2D envMap; uniform int samples; uniform float weights[ n ]; uniform bool latitudinal; uniform float dTheta; uniform float mipInt; uniform vec3 poleAxis; #define ENVMAP_TYPE_CUBE_UV #include vec3 getSample( float theta, vec3 axis ) { float cosTheta = cos( theta ); // Rodrigues' axis-angle rotation vec3 sampleDirection = vOutputDirection * cosTheta + cross( axis, vOutputDirection ) * sin( theta ) + axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta ); return bilinearCubeUV( envMap, sampleDirection, mipInt ); } void main() { vec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection ); if ( all( equal( axis, vec3( 0.0 ) ) ) ) { axis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x ); } axis = normalize( axis ); gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 ); gl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis ); for ( int i = 1; i < n; i++ ) { if ( i >= samples ) { break; } float theta = dTheta * float( i ); gl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis ); gl_FragColor.rgb += weights[ i ] * getSample( theta, axis ); } } ` ), blending: NoBlending, depthTest: false, depthWrite: false }); return shaderMaterial; } function _getEquirectMaterial() { return new ShaderMaterial({ name: "EquirectangularToCubeUV", uniforms: { "envMap": { value: null } }, vertexShader: _getCommonVertexShader(), fragmentShader: ( /* glsl */ ` precision mediump float; precision mediump int; varying vec3 vOutputDirection; uniform sampler2D envMap; #include void main() { vec3 outputDirection = normalize( vOutputDirection ); vec2 uv = equirectUv( outputDirection ); gl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 ); } ` ), blending: NoBlending, depthTest: false, depthWrite: false }); } function _getCubemapMaterial() { return new ShaderMaterial({ name: "CubemapToCubeUV", uniforms: { "envMap": { value: null }, "flipEnvMap": { value: -1 } }, vertexShader: _getCommonVertexShader(), fragmentShader: ( /* glsl */ ` precision mediump float; precision mediump int; uniform float flipEnvMap; varying vec3 vOutputDirection; uniform samplerCube envMap; void main() { gl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) ); } ` ), blending: NoBlending, depthTest: false, depthWrite: false }); } function _getCommonVertexShader() { return ( /* glsl */ ` precision mediump float; precision mediump int; attribute float faceIndex; varying vec3 vOutputDirection; // RH coordinate system; PMREM face-indexing convention vec3 getDirection( vec2 uv, float face ) { uv = 2.0 * uv - 1.0; vec3 direction = vec3( uv, 1.0 ); if ( face == 0.0 ) { direction = direction.zyx; // ( 1, v, u ) pos x } else if ( face == 1.0 ) { direction = direction.xzy; direction.xz *= -1.0; // ( -u, 1, -v ) pos y } else if ( face == 2.0 ) { direction.x *= -1.0; // ( -u, v, 1 ) pos z } else if ( face == 3.0 ) { direction = direction.zyx; direction.xz *= -1.0; // ( -1, v, -u ) neg x } else if ( face == 4.0 ) { direction = direction.xzy; direction.xy *= -1.0; // ( -u, -1, v ) neg y } else if ( face == 5.0 ) { direction.z *= -1.0; // ( u, v, -1 ) neg z } return direction; } void main() { vOutputDirection = getDirection( uv, faceIndex ); gl_Position = vec4( position, 1.0 ); } ` ); } function WebGLCubeUVMaps(renderer3) { let cubeUVmaps = /* @__PURE__ */ new WeakMap(); let pmremGenerator = null; function get2(texture) { if (texture && texture.isTexture) { const mapping = texture.mapping; const isEquirectMap = mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping; const isCubeMap = mapping === CubeReflectionMapping || mapping === CubeRefractionMapping; if (isEquirectMap || isCubeMap) { if (texture.isRenderTargetTexture && texture.needsPMREMUpdate === true) { texture.needsPMREMUpdate = false; let renderTarget = cubeUVmaps.get(texture); if (pmremGenerator === null) pmremGenerator = new PMREMGenerator(renderer3); renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular(texture, renderTarget) : pmremGenerator.fromCubemap(texture, renderTarget); cubeUVmaps.set(texture, renderTarget); return renderTarget.texture; } else { if (cubeUVmaps.has(texture)) { return cubeUVmaps.get(texture).texture; } else { const image = texture.image; if (isEquirectMap && image && image.height > 0 || isCubeMap && image && isCubeTextureComplete(image)) { if (pmremGenerator === null) pmremGenerator = new PMREMGenerator(renderer3); const renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular(texture) : pmremGenerator.fromCubemap(texture); cubeUVmaps.set(texture, renderTarget); texture.addEventListener("dispose", onTextureDispose); return renderTarget.texture; } else { return null; } } } } } return texture; } function isCubeTextureComplete(image) { let count = 0; const length = 6; for (let i = 0; i < length; i++) { if (image[i] !== void 0) count++; } return count === length; } function onTextureDispose(event) { const texture = event.target; texture.removeEventListener("dispose", onTextureDispose); const cubemapUV = cubeUVmaps.get(texture); if (cubemapUV !== void 0) { cubeUVmaps.delete(texture); cubemapUV.dispose(); } } function dispose() { cubeUVmaps = /* @__PURE__ */ new WeakMap(); if (pmremGenerator !== null) { pmremGenerator.dispose(); pmremGenerator = null; } } return { get: get2, dispose }; } function WebGLExtensions(gl) { const extensions = {}; function getExtension(name) { if (extensions[name] !== void 0) { return extensions[name]; } let extension; switch (name) { case "WEBGL_depth_texture": extension = gl.getExtension("WEBGL_depth_texture") || gl.getExtension("MOZ_WEBGL_depth_texture") || gl.getExtension("WEBKIT_WEBGL_depth_texture"); break; case "EXT_texture_filter_anisotropic": extension = gl.getExtension("EXT_texture_filter_anisotropic") || gl.getExtension("MOZ_EXT_texture_filter_anisotropic") || gl.getExtension("WEBKIT_EXT_texture_filter_anisotropic"); break; case "WEBGL_compressed_texture_s3tc": extension = gl.getExtension("WEBGL_compressed_texture_s3tc") || gl.getExtension("MOZ_WEBGL_compressed_texture_s3tc") || gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc"); break; case "WEBGL_compressed_texture_pvrtc": extension = gl.getExtension("WEBGL_compressed_texture_pvrtc") || gl.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"); break; default: extension = gl.getExtension(name); } extensions[name] = extension; return extension; } return { has: function(name) { return getExtension(name) !== null; }, init: function(capabilities) { if (capabilities.isWebGL2) { getExtension("EXT_color_buffer_float"); } else { getExtension("WEBGL_depth_texture"); getExtension("OES_texture_float"); getExtension("OES_texture_half_float"); getExtension("OES_texture_half_float_linear"); getExtension("OES_standard_derivatives"); getExtension("OES_element_index_uint"); getExtension("OES_vertex_array_object"); getExtension("ANGLE_instanced_arrays"); } getExtension("OES_texture_float_linear"); getExtension("EXT_color_buffer_half_float"); getExtension("WEBGL_multisampled_render_to_texture"); }, get: function(name) { const extension = getExtension(name); if (extension === null) { console.warn("THREE.WebGLRenderer: " + name + " extension not supported."); } return extension; } }; } function WebGLGeometries(gl, attributes, info, bindingStates) { const geometries = {}; const wireframeAttributes = /* @__PURE__ */ new WeakMap(); function onGeometryDispose(event) { const geometry = event.target; if (geometry.index !== null) { attributes.remove(geometry.index); } for (const name in geometry.attributes) { attributes.remove(geometry.attributes[name]); } for (const name in geometry.morphAttributes) { const array = geometry.morphAttributes[name]; for (let i = 0, l = array.length; i < l; i++) { attributes.remove(array[i]); } } geometry.removeEventListener("dispose", onGeometryDispose); delete geometries[geometry.id]; const attribute = wireframeAttributes.get(geometry); if (attribute) { attributes.remove(attribute); wireframeAttributes.delete(geometry); } bindingStates.releaseStatesOfGeometry(geometry); if (geometry.isInstancedBufferGeometry === true) { delete geometry._maxInstanceCount; } info.memory.geometries--; } function get2(object, geometry) { if (geometries[geometry.id] === true) return geometry; geometry.addEventListener("dispose", onGeometryDispose); geometries[geometry.id] = true; info.memory.geometries++; return geometry; } function update4(geometry) { const geometryAttributes = geometry.attributes; for (const name in geometryAttributes) { attributes.update(geometryAttributes[name], gl.ARRAY_BUFFER); } const morphAttributes = geometry.morphAttributes; for (const name in morphAttributes) { const array = morphAttributes[name]; for (let i = 0, l = array.length; i < l; i++) { attributes.update(array[i], gl.ARRAY_BUFFER); } } } function updateWireframeAttribute(geometry) { const indices = []; const geometryIndex = geometry.index; const geometryPosition = geometry.attributes.position; let version = 0; if (geometryIndex !== null) { const array = geometryIndex.array; version = geometryIndex.version; for (let i = 0, l = array.length; i < l; i += 3) { const a2 = array[i + 0]; const b = array[i + 1]; const c2 = array[i + 2]; indices.push(a2, b, b, c2, c2, a2); } } else if (geometryPosition !== void 0) { const array = geometryPosition.array; version = geometryPosition.version; for (let i = 0, l = array.length / 3 - 1; i < l; i += 3) { const a2 = i + 0; const b = i + 1; const c2 = i + 2; indices.push(a2, b, b, c2, c2, a2); } } else { return; } const attribute = new (arrayNeedsUint32(indices) ? Uint32BufferAttribute : Uint16BufferAttribute)(indices, 1); attribute.version = version; const previousAttribute = wireframeAttributes.get(geometry); if (previousAttribute) attributes.remove(previousAttribute); wireframeAttributes.set(geometry, attribute); } function getWireframeAttribute(geometry) { const currentAttribute = wireframeAttributes.get(geometry); if (currentAttribute) { const geometryIndex = geometry.index; if (geometryIndex !== null) { if (currentAttribute.version < geometryIndex.version) { updateWireframeAttribute(geometry); } } } else { updateWireframeAttribute(geometry); } return wireframeAttributes.get(geometry); } return { get: get2, update: update4, getWireframeAttribute }; } function WebGLIndexedBufferRenderer(gl, extensions, info, capabilities) { const isWebGL2 = capabilities.isWebGL2; let mode; function setMode(value) { mode = value; } let type, bytesPerElement; function setIndex(value) { type = value.type; bytesPerElement = value.bytesPerElement; } function render(start, count) { gl.drawElements(mode, count, type, start * bytesPerElement); info.update(count, mode, 1); } function renderInstances(start, count, primcount) { if (primcount === 0) return; let extension, methodName; if (isWebGL2) { extension = gl; methodName = "drawElementsInstanced"; } else { extension = extensions.get("ANGLE_instanced_arrays"); methodName = "drawElementsInstancedANGLE"; if (extension === null) { console.error("THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays."); return; } } extension[methodName](mode, count, type, start * bytesPerElement, primcount); info.update(count, mode, primcount); } this.setMode = setMode; this.setIndex = setIndex; this.render = render; this.renderInstances = renderInstances; } function WebGLInfo(gl) { const memory = { geometries: 0, textures: 0 }; const render = { frame: 0, calls: 0, triangles: 0, points: 0, lines: 0 }; function update4(count, mode, instanceCount) { render.calls++; switch (mode) { case gl.TRIANGLES: render.triangles += instanceCount * (count / 3); break; case gl.LINES: render.lines += instanceCount * (count / 2); break; case gl.LINE_STRIP: render.lines += instanceCount * (count - 1); break; case gl.LINE_LOOP: render.lines += instanceCount * count; break; case gl.POINTS: render.points += instanceCount * count; break; default: console.error("THREE.WebGLInfo: Unknown draw mode:", mode); break; } } function reset() { render.calls = 0; render.triangles = 0; render.points = 0; render.lines = 0; } return { memory, render, programs: null, autoReset: true, reset, update: update4 }; } function numericalSort(a2, b) { return a2[0] - b[0]; } function absNumericalSort(a2, b) { return Math.abs(b[1]) - Math.abs(a2[1]); } function WebGLMorphtargets(gl, capabilities, textures) { const influencesList = {}; const morphInfluences = new Float32Array(8); const morphTextures = /* @__PURE__ */ new WeakMap(); const morph = new Vector4(); const workInfluences = []; for (let i = 0; i < 8; i++) { workInfluences[i] = [i, 0]; } function update4(object, geometry, program) { const objectInfluences = object.morphTargetInfluences; if (capabilities.isWebGL2 === true) { const morphAttribute = geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color; const morphTargetsCount = morphAttribute !== void 0 ? morphAttribute.length : 0; let entry = morphTextures.get(geometry); if (entry === void 0 || entry.count !== morphTargetsCount) { let disposeTexture = function() { texture.dispose(); morphTextures.delete(geometry); geometry.removeEventListener("dispose", disposeTexture); }; if (entry !== void 0) entry.texture.dispose(); const hasMorphPosition = geometry.morphAttributes.position !== void 0; const hasMorphNormals = geometry.morphAttributes.normal !== void 0; const hasMorphColors = geometry.morphAttributes.color !== void 0; const morphTargets = geometry.morphAttributes.position || []; const morphNormals = geometry.morphAttributes.normal || []; const morphColors = geometry.morphAttributes.color || []; let vertexDataCount = 0; if (hasMorphPosition === true) vertexDataCount = 1; if (hasMorphNormals === true) vertexDataCount = 2; if (hasMorphColors === true) vertexDataCount = 3; let width = geometry.attributes.position.count * vertexDataCount; let height = 1; if (width > capabilities.maxTextureSize) { height = Math.ceil(width / capabilities.maxTextureSize); width = capabilities.maxTextureSize; } const buffer = new Float32Array(width * height * 4 * morphTargetsCount); const texture = new DataArrayTexture(buffer, width, height, morphTargetsCount); texture.type = FloatType; texture.needsUpdate = true; const vertexDataStride = vertexDataCount * 4; for (let i = 0; i < morphTargetsCount; i++) { const morphTarget = morphTargets[i]; const morphNormal = morphNormals[i]; const morphColor = morphColors[i]; const offset = width * height * 4 * i; for (let j = 0; j < morphTarget.count; j++) { const stride = j * vertexDataStride; if (hasMorphPosition === true) { morph.fromBufferAttribute(morphTarget, j); buffer[offset + stride + 0] = morph.x; buffer[offset + stride + 1] = morph.y; buffer[offset + stride + 2] = morph.z; buffer[offset + stride + 3] = 0; } if (hasMorphNormals === true) { morph.fromBufferAttribute(morphNormal, j); buffer[offset + stride + 4] = morph.x; buffer[offset + stride + 5] = morph.y; buffer[offset + stride + 6] = morph.z; buffer[offset + stride + 7] = 0; } if (hasMorphColors === true) { morph.fromBufferAttribute(morphColor, j); buffer[offset + stride + 8] = morph.x; buffer[offset + stride + 9] = morph.y; buffer[offset + stride + 10] = morph.z; buffer[offset + stride + 11] = morphColor.itemSize === 4 ? morph.w : 1; } } } entry = { count: morphTargetsCount, texture, size: new Vector2(width, height) }; morphTextures.set(geometry, entry); geometry.addEventListener("dispose", disposeTexture); } let morphInfluencesSum = 0; for (let i = 0; i < objectInfluences.length; i++) { morphInfluencesSum += objectInfluences[i]; } const morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum; program.getUniforms().setValue(gl, "morphTargetBaseInfluence", morphBaseInfluence); program.getUniforms().setValue(gl, "morphTargetInfluences", objectInfluences); program.getUniforms().setValue(gl, "morphTargetsTexture", entry.texture, textures); program.getUniforms().setValue(gl, "morphTargetsTextureSize", entry.size); } else { const length = objectInfluences === void 0 ? 0 : objectInfluences.length; let influences = influencesList[geometry.id]; if (influences === void 0 || influences.length !== length) { influences = []; for (let i = 0; i < length; i++) { influences[i] = [i, 0]; } influencesList[geometry.id] = influences; } for (let i = 0; i < length; i++) { const influence = influences[i]; influence[0] = i; influence[1] = objectInfluences[i]; } influences.sort(absNumericalSort); for (let i = 0; i < 8; i++) { if (i < length && influences[i][1]) { workInfluences[i][0] = influences[i][0]; workInfluences[i][1] = influences[i][1]; } else { workInfluences[i][0] = Number.MAX_SAFE_INTEGER; workInfluences[i][1] = 0; } } workInfluences.sort(numericalSort); const morphTargets = geometry.morphAttributes.position; const morphNormals = geometry.morphAttributes.normal; let morphInfluencesSum = 0; for (let i = 0; i < 8; i++) { const influence = workInfluences[i]; const index6 = influence[0]; const value = influence[1]; if (index6 !== Number.MAX_SAFE_INTEGER && value) { if (morphTargets && geometry.getAttribute("morphTarget" + i) !== morphTargets[index6]) { geometry.setAttribute("morphTarget" + i, morphTargets[index6]); } if (morphNormals && geometry.getAttribute("morphNormal" + i) !== morphNormals[index6]) { geometry.setAttribute("morphNormal" + i, morphNormals[index6]); } morphInfluences[i] = value; morphInfluencesSum += value; } else { if (morphTargets && geometry.hasAttribute("morphTarget" + i) === true) { geometry.deleteAttribute("morphTarget" + i); } if (morphNormals && geometry.hasAttribute("morphNormal" + i) === true) { geometry.deleteAttribute("morphNormal" + i); } morphInfluences[i] = 0; } } const morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum; program.getUniforms().setValue(gl, "morphTargetBaseInfluence", morphBaseInfluence); program.getUniforms().setValue(gl, "morphTargetInfluences", morphInfluences); } } return { update: update4 }; } function WebGLObjects(gl, geometries, attributes, info) { let updateMap = /* @__PURE__ */ new WeakMap(); function update4(object) { const frame2 = info.render.frame; const geometry = object.geometry; const buffergeometry = geometries.get(object, geometry); if (updateMap.get(buffergeometry) !== frame2) { geometries.update(buffergeometry); updateMap.set(buffergeometry, frame2); } if (object.isInstancedMesh) { if (object.hasEventListener("dispose", onInstancedMeshDispose) === false) { object.addEventListener("dispose", onInstancedMeshDispose); } if (updateMap.get(object) !== frame2) { attributes.update(object.instanceMatrix, gl.ARRAY_BUFFER); if (object.instanceColor !== null) { attributes.update(object.instanceColor, gl.ARRAY_BUFFER); } updateMap.set(object, frame2); } } if (object.isSkinnedMesh) { const skeleton = object.skeleton; if (updateMap.get(skeleton) !== frame2) { skeleton.update(); updateMap.set(skeleton, frame2); } } return buffergeometry; } function dispose() { updateMap = /* @__PURE__ */ new WeakMap(); } function onInstancedMeshDispose(event) { const instancedMesh = event.target; instancedMesh.removeEventListener("dispose", onInstancedMeshDispose); attributes.remove(instancedMesh.instanceMatrix); if (instancedMesh.instanceColor !== null) attributes.remove(instancedMesh.instanceColor); } return { update: update4, dispose }; } var emptyTexture = /* @__PURE__ */ new Texture(); var emptyArrayTexture = /* @__PURE__ */ new DataArrayTexture(); var empty3dTexture = /* @__PURE__ */ new Data3DTexture(); var emptyCubeTexture = /* @__PURE__ */ new CubeTexture(); var arrayCacheF32 = []; var arrayCacheI32 = []; var mat4array = new Float32Array(16); var mat3array = new Float32Array(9); var mat2array = new Float32Array(4); function flatten(array, nBlocks, blockSize) { const firstElem = array[0]; if (firstElem <= 0 || firstElem > 0) return array; const n = nBlocks * blockSize; let r = arrayCacheF32[n]; if (r === void 0) { r = new Float32Array(n); arrayCacheF32[n] = r; } if (nBlocks !== 0) { firstElem.toArray(r, 0); for (let i = 1, offset = 0; i !== nBlocks; ++i) { offset += blockSize; array[i].toArray(r, offset); } } return r; } function arraysEqual(a2, b) { if (a2.length !== b.length) return false; for (let i = 0, l = a2.length; i < l; i++) { if (a2[i] !== b[i]) return false; } return true; } function copyArray(a2, b) { for (let i = 0, l = b.length; i < l; i++) { a2[i] = b[i]; } } function allocTexUnits(textures, n) { let r = arrayCacheI32[n]; if (r === void 0) { r = new Int32Array(n); arrayCacheI32[n] = r; } for (let i = 0; i !== n; ++i) { r[i] = textures.allocateTextureUnit(); } return r; } function setValueV1f(gl, v) { const cache = this.cache; if (cache[0] === v) return; gl.uniform1f(this.addr, v); cache[0] = v; } function setValueV2f(gl, v) { const cache = this.cache; if (v.x !== void 0) { if (cache[0] !== v.x || cache[1] !== v.y) { gl.uniform2f(this.addr, v.x, v.y); cache[0] = v.x; cache[1] = v.y; } } else { if (arraysEqual(cache, v)) return; gl.uniform2fv(this.addr, v); copyArray(cache, v); } } function setValueV3f(gl, v) { const cache = this.cache; if (v.x !== void 0) { if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) { gl.uniform3f(this.addr, v.x, v.y, v.z); cache[0] = v.x; cache[1] = v.y; cache[2] = v.z; } } else if (v.r !== void 0) { if (cache[0] !== v.r || cache[1] !== v.g || cache[2] !== v.b) { gl.uniform3f(this.addr, v.r, v.g, v.b); cache[0] = v.r; cache[1] = v.g; cache[2] = v.b; } } else { if (arraysEqual(cache, v)) return; gl.uniform3fv(this.addr, v); copyArray(cache, v); } } function setValueV4f(gl, v) { const cache = this.cache; if (v.x !== void 0) { if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) { gl.uniform4f(this.addr, v.x, v.y, v.z, v.w); cache[0] = v.x; cache[1] = v.y; cache[2] = v.z; cache[3] = v.w; } } else { if (arraysEqual(cache, v)) return; gl.uniform4fv(this.addr, v); copyArray(cache, v); } } function setValueM2(gl, v) { const cache = this.cache; const elements = v.elements; if (elements === void 0) { if (arraysEqual(cache, v)) return; gl.uniformMatrix2fv(this.addr, false, v); copyArray(cache, v); } else { if (arraysEqual(cache, elements)) return; mat2array.set(elements); gl.uniformMatrix2fv(this.addr, false, mat2array); copyArray(cache, elements); } } function setValueM3(gl, v) { const cache = this.cache; const elements = v.elements; if (elements === void 0) { if (arraysEqual(cache, v)) return; gl.uniformMatrix3fv(this.addr, false, v); copyArray(cache, v); } else { if (arraysEqual(cache, elements)) return; mat3array.set(elements); gl.uniformMatrix3fv(this.addr, false, mat3array); copyArray(cache, elements); } } function setValueM4(gl, v) { const cache = this.cache; const elements = v.elements; if (elements === void 0) { if (arraysEqual(cache, v)) return; gl.uniformMatrix4fv(this.addr, false, v); copyArray(cache, v); } else { if (arraysEqual(cache, elements)) return; mat4array.set(elements); gl.uniformMatrix4fv(this.addr, false, mat4array); copyArray(cache, elements); } } function setValueV1i(gl, v) { const cache = this.cache; if (cache[0] === v) return; gl.uniform1i(this.addr, v); cache[0] = v; } function setValueV2i(gl, v) { const cache = this.cache; if (v.x !== void 0) { if (cache[0] !== v.x || cache[1] !== v.y) { gl.uniform2i(this.addr, v.x, v.y); cache[0] = v.x; cache[1] = v.y; } } else { if (arraysEqual(cache, v)) return; gl.uniform2iv(this.addr, v); copyArray(cache, v); } } function setValueV3i(gl, v) { const cache = this.cache; if (v.x !== void 0) { if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) { gl.uniform3i(this.addr, v.x, v.y, v.z); cache[0] = v.x; cache[1] = v.y; cache[2] = v.z; } } else { if (arraysEqual(cache, v)) return; gl.uniform3iv(this.addr, v); copyArray(cache, v); } } function setValueV4i(gl, v) { const cache = this.cache; if (v.x !== void 0) { if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) { gl.uniform4i(this.addr, v.x, v.y, v.z, v.w); cache[0] = v.x; cache[1] = v.y; cache[2] = v.z; cache[3] = v.w; } } else { if (arraysEqual(cache, v)) return; gl.uniform4iv(this.addr, v); copyArray(cache, v); } } function setValueV1ui(gl, v) { const cache = this.cache; if (cache[0] === v) return; gl.uniform1ui(this.addr, v); cache[0] = v; } function setValueV2ui(gl, v) { const cache = this.cache; if (v.x !== void 0) { if (cache[0] !== v.x || cache[1] !== v.y) { gl.uniform2ui(this.addr, v.x, v.y); cache[0] = v.x; cache[1] = v.y; } } else { if (arraysEqual(cache, v)) return; gl.uniform2uiv(this.addr, v); copyArray(cache, v); } } function setValueV3ui(gl, v) { const cache = this.cache; if (v.x !== void 0) { if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) { gl.uniform3ui(this.addr, v.x, v.y, v.z); cache[0] = v.x; cache[1] = v.y; cache[2] = v.z; } } else { if (arraysEqual(cache, v)) return; gl.uniform3uiv(this.addr, v); copyArray(cache, v); } } function setValueV4ui(gl, v) { const cache = this.cache; if (v.x !== void 0) { if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) { gl.uniform4ui(this.addr, v.x, v.y, v.z, v.w); cache[0] = v.x; cache[1] = v.y; cache[2] = v.z; cache[3] = v.w; } } else { if (arraysEqual(cache, v)) return; gl.uniform4uiv(this.addr, v); copyArray(cache, v); } } function setValueT1(gl, v, textures) { const cache = this.cache; const unit = textures.allocateTextureUnit(); if (cache[0] !== unit) { gl.uniform1i(this.addr, unit); cache[0] = unit; } textures.setTexture2D(v || emptyTexture, unit); } function setValueT3D1(gl, v, textures) { const cache = this.cache; const unit = textures.allocateTextureUnit(); if (cache[0] !== unit) { gl.uniform1i(this.addr, unit); cache[0] = unit; } textures.setTexture3D(v || empty3dTexture, unit); } function setValueT6(gl, v, textures) { const cache = this.cache; const unit = textures.allocateTextureUnit(); if (cache[0] !== unit) { gl.uniform1i(this.addr, unit); cache[0] = unit; } textures.setTextureCube(v || emptyCubeTexture, unit); } function setValueT2DArray1(gl, v, textures) { const cache = this.cache; const unit = textures.allocateTextureUnit(); if (cache[0] !== unit) { gl.uniform1i(this.addr, unit); cache[0] = unit; } textures.setTexture2DArray(v || emptyArrayTexture, unit); } function getSingularSetter(type) { switch (type) { case 5126: return setValueV1f; case 35664: return setValueV2f; case 35665: return setValueV3f; case 35666: return setValueV4f; case 35674: return setValueM2; case 35675: return setValueM3; case 35676: return setValueM4; case 5124: case 35670: return setValueV1i; case 35667: case 35671: return setValueV2i; case 35668: case 35672: return setValueV3i; case 35669: case 35673: return setValueV4i; case 5125: return setValueV1ui; case 36294: return setValueV2ui; case 36295: return setValueV3ui; case 36296: return setValueV4ui; case 35678: case 36198: case 36298: case 36306: case 35682: return setValueT1; case 35679: case 36299: case 36307: return setValueT3D1; case 35680: case 36300: case 36308: case 36293: return setValueT6; case 36289: case 36303: case 36311: case 36292: return setValueT2DArray1; } } function setValueV1fArray(gl, v) { gl.uniform1fv(this.addr, v); } function setValueV2fArray(gl, v) { const data = flatten(v, this.size, 2); gl.uniform2fv(this.addr, data); } function setValueV3fArray(gl, v) { const data = flatten(v, this.size, 3); gl.uniform3fv(this.addr, data); } function setValueV4fArray(gl, v) { const data = flatten(v, this.size, 4); gl.uniform4fv(this.addr, data); } function setValueM2Array(gl, v) { const data = flatten(v, this.size, 4); gl.uniformMatrix2fv(this.addr, false, data); } function setValueM3Array(gl, v) { const data = flatten(v, this.size, 9); gl.uniformMatrix3fv(this.addr, false, data); } function setValueM4Array(gl, v) { const data = flatten(v, this.size, 16); gl.uniformMatrix4fv(this.addr, false, data); } function setValueV1iArray(gl, v) { gl.uniform1iv(this.addr, v); } function setValueV2iArray(gl, v) { gl.uniform2iv(this.addr, v); } function setValueV3iArray(gl, v) { gl.uniform3iv(this.addr, v); } function setValueV4iArray(gl, v) { gl.uniform4iv(this.addr, v); } function setValueV1uiArray(gl, v) { gl.uniform1uiv(this.addr, v); } function setValueV2uiArray(gl, v) { gl.uniform2uiv(this.addr, v); } function setValueV3uiArray(gl, v) { gl.uniform3uiv(this.addr, v); } function setValueV4uiArray(gl, v) { gl.uniform4uiv(this.addr, v); } function setValueT1Array(gl, v, textures) { const cache = this.cache; const n = v.length; const units = allocTexUnits(textures, n); if (!arraysEqual(cache, units)) { gl.uniform1iv(this.addr, units); copyArray(cache, units); } for (let i = 0; i !== n; ++i) { textures.setTexture2D(v[i] || emptyTexture, units[i]); } } function setValueT3DArray(gl, v, textures) { const cache = this.cache; const n = v.length; const units = allocTexUnits(textures, n); if (!arraysEqual(cache, units)) { gl.uniform1iv(this.addr, units); copyArray(cache, units); } for (let i = 0; i !== n; ++i) { textures.setTexture3D(v[i] || empty3dTexture, units[i]); } } function setValueT6Array(gl, v, textures) { const cache = this.cache; const n = v.length; const units = allocTexUnits(textures, n); if (!arraysEqual(cache, units)) { gl.uniform1iv(this.addr, units); copyArray(cache, units); } for (let i = 0; i !== n; ++i) { textures.setTextureCube(v[i] || emptyCubeTexture, units[i]); } } function setValueT2DArrayArray(gl, v, textures) { const cache = this.cache; const n = v.length; const units = allocTexUnits(textures, n); if (!arraysEqual(cache, units)) { gl.uniform1iv(this.addr, units); copyArray(cache, units); } for (let i = 0; i !== n; ++i) { textures.setTexture2DArray(v[i] || emptyArrayTexture, units[i]); } } function getPureArraySetter(type) { switch (type) { case 5126: return setValueV1fArray; case 35664: return setValueV2fArray; case 35665: return setValueV3fArray; case 35666: return setValueV4fArray; case 35674: return setValueM2Array; case 35675: return setValueM3Array; case 35676: return setValueM4Array; case 5124: case 35670: return setValueV1iArray; case 35667: case 35671: return setValueV2iArray; case 35668: case 35672: return setValueV3iArray; case 35669: case 35673: return setValueV4iArray; case 5125: return setValueV1uiArray; case 36294: return setValueV2uiArray; case 36295: return setValueV3uiArray; case 36296: return setValueV4uiArray; case 35678: case 36198: case 36298: case 36306: case 35682: return setValueT1Array; case 35679: case 36299: case 36307: return setValueT3DArray; case 35680: case 36300: case 36308: case 36293: return setValueT6Array; case 36289: case 36303: case 36311: case 36292: return setValueT2DArrayArray; } } var SingleUniform = class { constructor(id, activeInfo, addr) { this.id = id; this.addr = addr; this.cache = []; this.setValue = getSingularSetter(activeInfo.type); } }; var PureArrayUniform = class { constructor(id, activeInfo, addr) { this.id = id; this.addr = addr; this.cache = []; this.size = activeInfo.size; this.setValue = getPureArraySetter(activeInfo.type); } }; var StructuredUniform = class { constructor(id) { this.id = id; this.seq = []; this.map = {}; } setValue(gl, value, textures) { const seq = this.seq; for (let i = 0, n = seq.length; i !== n; ++i) { const u = seq[i]; u.setValue(gl, value[u.id], textures); } } }; var RePathPart = /(\w+)(\])?(\[|\.)?/g; function addUniform(container, uniformObject) { container.seq.push(uniformObject); container.map[uniformObject.id] = uniformObject; } function parseUniform(activeInfo, addr, container) { const path = activeInfo.name, pathLength = path.length; RePathPart.lastIndex = 0; while (true) { const match = RePathPart.exec(path), matchEnd = RePathPart.lastIndex; let id = match[1]; const idIsIndex = match[2] === "]", subscript = match[3]; if (idIsIndex) id = id | 0; if (subscript === void 0 || subscript === "[" && matchEnd + 2 === pathLength) { addUniform(container, subscript === void 0 ? new SingleUniform(id, activeInfo, addr) : new PureArrayUniform(id, activeInfo, addr)); break; } else { const map = container.map; let next = map[id]; if (next === void 0) { next = new StructuredUniform(id); addUniform(container, next); } container = next; } } } var WebGLUniforms = class { constructor(gl, program) { this.seq = []; this.map = {}; const n = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS); for (let i = 0; i < n; ++i) { const info = gl.getActiveUniform(program, i), addr = gl.getUniformLocation(program, info.name); parseUniform(info, addr, this); } } setValue(gl, name, value, textures) { const u = this.map[name]; if (u !== void 0) u.setValue(gl, value, textures); } setOptional(gl, object, name) { const v = object[name]; if (v !== void 0) this.setValue(gl, name, v); } static upload(gl, seq, values, textures) { for (let i = 0, n = seq.length; i !== n; ++i) { const u = seq[i], v = values[u.id]; if (v.needsUpdate !== false) { u.setValue(gl, v.value, textures); } } } static seqWithValue(seq, values) { const r = []; for (let i = 0, n = seq.length; i !== n; ++i) { const u = seq[i]; if (u.id in values) r.push(u); } return r; } }; function WebGLShader(gl, type, string) { const shader = gl.createShader(type); gl.shaderSource(shader, string); gl.compileShader(shader); return shader; } var COMPLETION_STATUS_KHR = 37297; var programIdCount = 0; function handleSource(string, errorLine) { const lines = string.split("\n"); const lines2 = []; const from = Math.max(errorLine - 6, 0); const to = Math.min(errorLine + 6, lines.length); for (let i = from; i < to; i++) { const line = i + 1; lines2.push(`${line === errorLine ? ">" : " "} ${line}: ${lines[i]}`); } return lines2.join("\n"); } function getEncodingComponents(colorSpace) { const workingPrimaries = ColorManagement.getPrimaries(ColorManagement.workingColorSpace); const encodingPrimaries = ColorManagement.getPrimaries(colorSpace); let gamutMapping; if (workingPrimaries === encodingPrimaries) { gamutMapping = ""; } else if (workingPrimaries === P3Primaries && encodingPrimaries === Rec709Primaries) { gamutMapping = "LinearDisplayP3ToLinearSRGB"; } else if (workingPrimaries === Rec709Primaries && encodingPrimaries === P3Primaries) { gamutMapping = "LinearSRGBToLinearDisplayP3"; } switch (colorSpace) { case LinearSRGBColorSpace: case LinearDisplayP3ColorSpace: return [gamutMapping, "LinearTransferOETF"]; case SRGBColorSpace: case DisplayP3ColorSpace: return [gamutMapping, "sRGBTransferOETF"]; default: console.warn("THREE.WebGLProgram: Unsupported color space:", colorSpace); return [gamutMapping, "LinearTransferOETF"]; } } function getShaderErrors(gl, shader, type) { const status = gl.getShaderParameter(shader, gl.COMPILE_STATUS); const errors = gl.getShaderInfoLog(shader).trim(); if (status && errors === "") return ""; const errorMatches = /ERROR: 0:(\d+)/.exec(errors); if (errorMatches) { const errorLine = parseInt(errorMatches[1]); return type.toUpperCase() + "\n\n" + errors + "\n\n" + handleSource(gl.getShaderSource(shader), errorLine); } else { return errors; } } function getTexelEncodingFunction(functionName, colorSpace) { const components = getEncodingComponents(colorSpace); return `vec4 ${functionName}( vec4 value ) { return ${components[0]}( ${components[1]}( value ) ); }`; } function getToneMappingFunction(functionName, toneMapping) { let toneMappingName; switch (toneMapping) { case LinearToneMapping: toneMappingName = "Linear"; break; case ReinhardToneMapping: toneMappingName = "Reinhard"; break; case CineonToneMapping: toneMappingName = "OptimizedCineon"; break; case ACESFilmicToneMapping: toneMappingName = "ACESFilmic"; break; case CustomToneMapping: toneMappingName = "Custom"; break; default: console.warn("THREE.WebGLProgram: Unsupported toneMapping:", toneMapping); toneMappingName = "Linear"; } return "vec3 " + functionName + "( vec3 color ) { return " + toneMappingName + "ToneMapping( color ); }"; } function generateExtensions(parameters) { const chunks = [ parameters.extensionDerivatives || !!parameters.envMapCubeUVHeight || parameters.bumpMap || parameters.normalMapTangentSpace || parameters.clearcoatNormalMap || parameters.flatShading || parameters.shaderID === "physical" ? "#extension GL_OES_standard_derivatives : enable" : "", (parameters.extensionFragDepth || parameters.logarithmicDepthBuffer) && parameters.rendererExtensionFragDepth ? "#extension GL_EXT_frag_depth : enable" : "", parameters.extensionDrawBuffers && parameters.rendererExtensionDrawBuffers ? "#extension GL_EXT_draw_buffers : require" : "", (parameters.extensionShaderTextureLOD || parameters.envMap || parameters.transmission) && parameters.rendererExtensionShaderTextureLod ? "#extension GL_EXT_shader_texture_lod : enable" : "" ]; return chunks.filter(filterEmptyLine).join("\n"); } function generateDefines(defines) { const chunks = []; for (const name in defines) { const value = defines[name]; if (value === false) continue; chunks.push("#define " + name + " " + value); } return chunks.join("\n"); } function fetchAttributeLocations(gl, program) { const attributes = {}; const n = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES); for (let i = 0; i < n; i++) { const info = gl.getActiveAttrib(program, i); const name = info.name; let locationSize = 1; if (info.type === gl.FLOAT_MAT2) locationSize = 2; if (info.type === gl.FLOAT_MAT3) locationSize = 3; if (info.type === gl.FLOAT_MAT4) locationSize = 4; attributes[name] = { type: info.type, location: gl.getAttribLocation(program, name), locationSize }; } return attributes; } function filterEmptyLine(string) { return string !== ""; } function replaceLightNums(string, parameters) { const numSpotLightCoords = parameters.numSpotLightShadows + parameters.numSpotLightMaps - parameters.numSpotLightShadowsWithMaps; return string.replace(/NUM_DIR_LIGHTS/g, parameters.numDirLights).replace(/NUM_SPOT_LIGHTS/g, parameters.numSpotLights).replace(/NUM_SPOT_LIGHT_MAPS/g, parameters.numSpotLightMaps).replace(/NUM_SPOT_LIGHT_COORDS/g, numSpotLightCoords).replace(/NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g, parameters.numPointLights).replace(/NUM_HEMI_LIGHTS/g, parameters.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g, parameters.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS/g, parameters.numSpotLightShadowsWithMaps).replace(/NUM_SPOT_LIGHT_SHADOWS/g, parameters.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g, parameters.numPointLightShadows); } function replaceClippingPlaneNums(string, parameters) { return string.replace(/NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, parameters.numClippingPlanes - parameters.numClipIntersection); } var includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm; function resolveIncludes(string) { return string.replace(includePattern, includeReplacer); } var shaderChunkMap = /* @__PURE__ */ new Map([ ["encodings_fragment", "colorspace_fragment"], // @deprecated, r154 ["encodings_pars_fragment", "colorspace_pars_fragment"], // @deprecated, r154 ["output_fragment", "opaque_fragment"] // @deprecated, r154 ]); function includeReplacer(match, include) { let string = ShaderChunk[include]; if (string === void 0) { const newInclude = shaderChunkMap.get(include); if (newInclude !== void 0) { string = ShaderChunk[newInclude]; console.warn('THREE.WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.', include, newInclude); } else { throw new Error("Can not resolve #include <" + include + ">"); } } return resolveIncludes(string); } var unrollLoopPattern = /#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g; function unrollLoops(string) { return string.replace(unrollLoopPattern, loopReplacer); } function loopReplacer(match, start, end, snippet) { let string = ""; for (let i = parseInt(start); i < parseInt(end); i++) { string += snippet.replace(/\[\s*i\s*\]/g, "[ " + i + " ]").replace(/UNROLLED_LOOP_INDEX/g, i); } return string; } function generatePrecision(parameters) { let precisionstring = "precision " + parameters.precision + " float;\nprecision " + parameters.precision + " int;"; if (parameters.precision === "highp") { precisionstring += "\n#define HIGH_PRECISION"; } else if (parameters.precision === "mediump") { precisionstring += "\n#define MEDIUM_PRECISION"; } else if (parameters.precision === "lowp") { precisionstring += "\n#define LOW_PRECISION"; } return precisionstring; } function generateShadowMapTypeDefine(parameters) { let shadowMapTypeDefine = "SHADOWMAP_TYPE_BASIC"; if (parameters.shadowMapType === PCFShadowMap) { shadowMapTypeDefine = "SHADOWMAP_TYPE_PCF"; } else if (parameters.shadowMapType === PCFSoftShadowMap) { shadowMapTypeDefine = "SHADOWMAP_TYPE_PCF_SOFT"; } else if (parameters.shadowMapType === VSMShadowMap) { shadowMapTypeDefine = "SHADOWMAP_TYPE_VSM"; } return shadowMapTypeDefine; } function generateEnvMapTypeDefine(parameters) { let envMapTypeDefine = "ENVMAP_TYPE_CUBE"; if (parameters.envMap) { switch (parameters.envMapMode) { case CubeReflectionMapping: case CubeRefractionMapping: envMapTypeDefine = "ENVMAP_TYPE_CUBE"; break; case CubeUVReflectionMapping: envMapTypeDefine = "ENVMAP_TYPE_CUBE_UV"; break; } } return envMapTypeDefine; } function generateEnvMapModeDefine(parameters) { let envMapModeDefine = "ENVMAP_MODE_REFLECTION"; if (parameters.envMap) { switch (parameters.envMapMode) { case CubeRefractionMapping: envMapModeDefine = "ENVMAP_MODE_REFRACTION"; break; } } return envMapModeDefine; } function generateEnvMapBlendingDefine(parameters) { let envMapBlendingDefine = "ENVMAP_BLENDING_NONE"; if (parameters.envMap) { switch (parameters.combine) { case MultiplyOperation: envMapBlendingDefine = "ENVMAP_BLENDING_MULTIPLY"; break; case MixOperation: envMapBlendingDefine = "ENVMAP_BLENDING_MIX"; break; case AddOperation: envMapBlendingDefine = "ENVMAP_BLENDING_ADD"; break; } } return envMapBlendingDefine; } function generateCubeUVSize(parameters) { const imageHeight = parameters.envMapCubeUVHeight; if (imageHeight === null) return null; const maxMip = Math.log2(imageHeight) - 2; const texelHeight = 1 / imageHeight; const texelWidth = 1 / (3 * Math.max(Math.pow(2, maxMip), 7 * 16)); return { texelWidth, texelHeight, maxMip }; } function WebGLProgram(renderer3, cacheKey, parameters, bindingStates) { const gl = renderer3.getContext(); const defines = parameters.defines; let vertexShader = parameters.vertexShader; let fragmentShader = parameters.fragmentShader; const shadowMapTypeDefine = generateShadowMapTypeDefine(parameters); const envMapTypeDefine = generateEnvMapTypeDefine(parameters); const envMapModeDefine = generateEnvMapModeDefine(parameters); const envMapBlendingDefine = generateEnvMapBlendingDefine(parameters); const envMapCubeUVSize = generateCubeUVSize(parameters); const customExtensions = parameters.isWebGL2 ? "" : generateExtensions(parameters); const customDefines = generateDefines(defines); const program = gl.createProgram(); let prefixVertex, prefixFragment; let versionString = parameters.glslVersion ? "#version " + parameters.glslVersion + "\n" : ""; if (parameters.isRawShaderMaterial) { prefixVertex = [ "#define SHADER_TYPE " + parameters.shaderType, "#define SHADER_NAME " + parameters.shaderName, customDefines ].filter(filterEmptyLine).join("\n"); if (prefixVertex.length > 0) { prefixVertex += "\n"; } prefixFragment = [ customExtensions, "#define SHADER_TYPE " + parameters.shaderType, "#define SHADER_NAME " + parameters.shaderName, customDefines ].filter(filterEmptyLine).join("\n"); if (prefixFragment.length > 0) { prefixFragment += "\n"; } } else { prefixVertex = [ generatePrecision(parameters), "#define SHADER_TYPE " + parameters.shaderType, "#define SHADER_NAME " + parameters.shaderName, customDefines, parameters.instancing ? "#define USE_INSTANCING" : "", parameters.instancingColor ? "#define USE_INSTANCING_COLOR" : "", parameters.useFog && parameters.fog ? "#define USE_FOG" : "", parameters.useFog && parameters.fogExp2 ? "#define FOG_EXP2" : "", parameters.map ? "#define USE_MAP" : "", parameters.envMap ? "#define USE_ENVMAP" : "", parameters.envMap ? "#define " + envMapModeDefine : "", parameters.lightMap ? "#define USE_LIGHTMAP" : "", parameters.aoMap ? "#define USE_AOMAP" : "", parameters.bumpMap ? "#define USE_BUMPMAP" : "", parameters.normalMap ? "#define USE_NORMALMAP" : "", parameters.normalMapObjectSpace ? "#define USE_NORMALMAP_OBJECTSPACE" : "", parameters.normalMapTangentSpace ? "#define USE_NORMALMAP_TANGENTSPACE" : "", parameters.displacementMap ? "#define USE_DISPLACEMENTMAP" : "", parameters.emissiveMap ? "#define USE_EMISSIVEMAP" : "", parameters.anisotropy ? "#define USE_ANISOTROPY" : "", parameters.anisotropyMap ? "#define USE_ANISOTROPYMAP" : "", parameters.clearcoatMap ? "#define USE_CLEARCOATMAP" : "", parameters.clearcoatRoughnessMap ? "#define USE_CLEARCOAT_ROUGHNESSMAP" : "", parameters.clearcoatNormalMap ? "#define USE_CLEARCOAT_NORMALMAP" : "", parameters.iridescenceMap ? "#define USE_IRIDESCENCEMAP" : "", parameters.iridescenceThicknessMap ? "#define USE_IRIDESCENCE_THICKNESSMAP" : "", parameters.specularMap ? "#define USE_SPECULARMAP" : "", parameters.specularColorMap ? "#define USE_SPECULAR_COLORMAP" : "", parameters.specularIntensityMap ? "#define USE_SPECULAR_INTENSITYMAP" : "", parameters.roughnessMap ? "#define USE_ROUGHNESSMAP" : "", parameters.metalnessMap ? "#define USE_METALNESSMAP" : "", parameters.alphaMap ? "#define USE_ALPHAMAP" : "", parameters.alphaHash ? "#define USE_ALPHAHASH" : "", parameters.transmission ? "#define USE_TRANSMISSION" : "", parameters.transmissionMap ? "#define USE_TRANSMISSIONMAP" : "", parameters.thicknessMap ? "#define USE_THICKNESSMAP" : "", parameters.sheenColorMap ? "#define USE_SHEEN_COLORMAP" : "", parameters.sheenRoughnessMap ? "#define USE_SHEEN_ROUGHNESSMAP" : "", // parameters.mapUv ? "#define MAP_UV " + parameters.mapUv : "", parameters.alphaMapUv ? "#define ALPHAMAP_UV " + parameters.alphaMapUv : "", parameters.lightMapUv ? "#define LIGHTMAP_UV " + parameters.lightMapUv : "", parameters.aoMapUv ? "#define AOMAP_UV " + parameters.aoMapUv : "", parameters.emissiveMapUv ? "#define EMISSIVEMAP_UV " + parameters.emissiveMapUv : "", parameters.bumpMapUv ? "#define BUMPMAP_UV " + parameters.bumpMapUv : "", parameters.normalMapUv ? "#define NORMALMAP_UV " + parameters.normalMapUv : "", parameters.displacementMapUv ? "#define DISPLACEMENTMAP_UV " + parameters.displacementMapUv : "", parameters.metalnessMapUv ? "#define METALNESSMAP_UV " + parameters.metalnessMapUv : "", parameters.roughnessMapUv ? "#define ROUGHNESSMAP_UV " + parameters.roughnessMapUv : "", parameters.anisotropyMapUv ? "#define ANISOTROPYMAP_UV " + parameters.anisotropyMapUv : "", parameters.clearcoatMapUv ? "#define CLEARCOATMAP_UV " + parameters.clearcoatMapUv : "", parameters.clearcoatNormalMapUv ? "#define CLEARCOAT_NORMALMAP_UV " + parameters.clearcoatNormalMapUv : "", parameters.clearcoatRoughnessMapUv ? "#define CLEARCOAT_ROUGHNESSMAP_UV " + parameters.clearcoatRoughnessMapUv : "", parameters.iridescenceMapUv ? "#define IRIDESCENCEMAP_UV " + parameters.iridescenceMapUv : "", parameters.iridescenceThicknessMapUv ? "#define IRIDESCENCE_THICKNESSMAP_UV " + parameters.iridescenceThicknessMapUv : "", parameters.sheenColorMapUv ? "#define SHEEN_COLORMAP_UV " + parameters.sheenColorMapUv : "", parameters.sheenRoughnessMapUv ? "#define SHEEN_ROUGHNESSMAP_UV " + parameters.sheenRoughnessMapUv : "", parameters.specularMapUv ? "#define SPECULARMAP_UV " + parameters.specularMapUv : "", parameters.specularColorMapUv ? "#define SPECULAR_COLORMAP_UV " + parameters.specularColorMapUv : "", parameters.specularIntensityMapUv ? "#define SPECULAR_INTENSITYMAP_UV " + parameters.specularIntensityMapUv : "", parameters.transmissionMapUv ? "#define TRANSMISSIONMAP_UV " + parameters.transmissionMapUv : "", parameters.thicknessMapUv ? "#define THICKNESSMAP_UV " + parameters.thicknessMapUv : "", // parameters.vertexTangents && parameters.flatShading === false ? "#define USE_TANGENT" : "", parameters.vertexColors ? "#define USE_COLOR" : "", parameters.vertexAlphas ? "#define USE_COLOR_ALPHA" : "", parameters.vertexUv1s ? "#define USE_UV1" : "", parameters.vertexUv2s ? "#define USE_UV2" : "", parameters.vertexUv3s ? "#define USE_UV3" : "", parameters.pointsUvs ? "#define USE_POINTS_UV" : "", parameters.flatShading ? "#define FLAT_SHADED" : "", parameters.skinning ? "#define USE_SKINNING" : "", parameters.morphTargets ? "#define USE_MORPHTARGETS" : "", parameters.morphNormals && parameters.flatShading === false ? "#define USE_MORPHNORMALS" : "", parameters.morphColors && parameters.isWebGL2 ? "#define USE_MORPHCOLORS" : "", parameters.morphTargetsCount > 0 && parameters.isWebGL2 ? "#define MORPHTARGETS_TEXTURE" : "", parameters.morphTargetsCount > 0 && parameters.isWebGL2 ? "#define MORPHTARGETS_TEXTURE_STRIDE " + parameters.morphTextureStride : "", parameters.morphTargetsCount > 0 && parameters.isWebGL2 ? "#define MORPHTARGETS_COUNT " + parameters.morphTargetsCount : "", parameters.doubleSided ? "#define DOUBLE_SIDED" : "", parameters.flipSided ? "#define FLIP_SIDED" : "", parameters.shadowMapEnabled ? "#define USE_SHADOWMAP" : "", parameters.shadowMapEnabled ? "#define " + shadowMapTypeDefine : "", parameters.sizeAttenuation ? "#define USE_SIZEATTENUATION" : "", parameters.numLightProbes > 0 ? "#define USE_LIGHT_PROBES" : "", parameters.useLegacyLights ? "#define LEGACY_LIGHTS" : "", parameters.logarithmicDepthBuffer ? "#define USE_LOGDEPTHBUF" : "", parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ? "#define USE_LOGDEPTHBUF_EXT" : "", "uniform mat4 modelMatrix;", "uniform mat4 modelViewMatrix;", "uniform mat4 projectionMatrix;", "uniform mat4 viewMatrix;", "uniform mat3 normalMatrix;", "uniform vec3 cameraPosition;", "uniform bool isOrthographic;", "#ifdef USE_INSTANCING", " attribute mat4 instanceMatrix;", "#endif", "#ifdef USE_INSTANCING_COLOR", " attribute vec3 instanceColor;", "#endif", "attribute vec3 position;", "attribute vec3 normal;", "attribute vec2 uv;", "#ifdef USE_UV1", " attribute vec2 uv1;", "#endif", "#ifdef USE_UV2", " attribute vec2 uv2;", "#endif", "#ifdef USE_UV3", " attribute vec2 uv3;", "#endif", "#ifdef USE_TANGENT", " attribute vec4 tangent;", "#endif", "#if defined( USE_COLOR_ALPHA )", " attribute vec4 color;", "#elif defined( USE_COLOR )", " attribute vec3 color;", "#endif", "#if ( defined( USE_MORPHTARGETS ) && ! defined( MORPHTARGETS_TEXTURE ) )", " attribute vec3 morphTarget0;", " attribute vec3 morphTarget1;", " attribute vec3 morphTarget2;", " attribute vec3 morphTarget3;", " #ifdef USE_MORPHNORMALS", " attribute vec3 morphNormal0;", " attribute vec3 morphNormal1;", " attribute vec3 morphNormal2;", " attribute vec3 morphNormal3;", " #else", " attribute vec3 morphTarget4;", " attribute vec3 morphTarget5;", " attribute vec3 morphTarget6;", " attribute vec3 morphTarget7;", " #endif", "#endif", "#ifdef USE_SKINNING", " attribute vec4 skinIndex;", " attribute vec4 skinWeight;", "#endif", "\n" ].filter(filterEmptyLine).join("\n"); prefixFragment = [ customExtensions, generatePrecision(parameters), "#define SHADER_TYPE " + parameters.shaderType, "#define SHADER_NAME " + parameters.shaderName, customDefines, parameters.useFog && parameters.fog ? "#define USE_FOG" : "", parameters.useFog && parameters.fogExp2 ? "#define FOG_EXP2" : "", parameters.map ? "#define USE_MAP" : "", parameters.matcap ? "#define USE_MATCAP" : "", parameters.envMap ? "#define USE_ENVMAP" : "", parameters.envMap ? "#define " + envMapTypeDefine : "", parameters.envMap ? "#define " + envMapModeDefine : "", parameters.envMap ? "#define " + envMapBlendingDefine : "", envMapCubeUVSize ? "#define CUBEUV_TEXEL_WIDTH " + envMapCubeUVSize.texelWidth : "", envMapCubeUVSize ? "#define CUBEUV_TEXEL_HEIGHT " + envMapCubeUVSize.texelHeight : "", envMapCubeUVSize ? "#define CUBEUV_MAX_MIP " + envMapCubeUVSize.maxMip + ".0" : "", parameters.lightMap ? "#define USE_LIGHTMAP" : "", parameters.aoMap ? "#define USE_AOMAP" : "", parameters.bumpMap ? "#define USE_BUMPMAP" : "", parameters.normalMap ? "#define USE_NORMALMAP" : "", parameters.normalMapObjectSpace ? "#define USE_NORMALMAP_OBJECTSPACE" : "", parameters.normalMapTangentSpace ? "#define USE_NORMALMAP_TANGENTSPACE" : "", parameters.emissiveMap ? "#define USE_EMISSIVEMAP" : "", parameters.anisotropy ? "#define USE_ANISOTROPY" : "", parameters.anisotropyMap ? "#define USE_ANISOTROPYMAP" : "", parameters.clearcoat ? "#define USE_CLEARCOAT" : "", parameters.clearcoatMap ? "#define USE_CLEARCOATMAP" : "", parameters.clearcoatRoughnessMap ? "#define USE_CLEARCOAT_ROUGHNESSMAP" : "", parameters.clearcoatNormalMap ? "#define USE_CLEARCOAT_NORMALMAP" : "", parameters.iridescence ? "#define USE_IRIDESCENCE" : "", parameters.iridescenceMap ? "#define USE_IRIDESCENCEMAP" : "", parameters.iridescenceThicknessMap ? "#define USE_IRIDESCENCE_THICKNESSMAP" : "", parameters.specularMap ? "#define USE_SPECULARMAP" : "", parameters.specularColorMap ? "#define USE_SPECULAR_COLORMAP" : "", parameters.specularIntensityMap ? "#define USE_SPECULAR_INTENSITYMAP" : "", parameters.roughnessMap ? "#define USE_ROUGHNESSMAP" : "", parameters.metalnessMap ? "#define USE_METALNESSMAP" : "", parameters.alphaMap ? "#define USE_ALPHAMAP" : "", parameters.alphaTest ? "#define USE_ALPHATEST" : "", parameters.alphaHash ? "#define USE_ALPHAHASH" : "", parameters.sheen ? "#define USE_SHEEN" : "", parameters.sheenColorMap ? "#define USE_SHEEN_COLORMAP" : "", parameters.sheenRoughnessMap ? "#define USE_SHEEN_ROUGHNESSMAP" : "", parameters.transmission ? "#define USE_TRANSMISSION" : "", parameters.transmissionMap ? "#define USE_TRANSMISSIONMAP" : "", parameters.thicknessMap ? "#define USE_THICKNESSMAP" : "", parameters.vertexTangents && parameters.flatShading === false ? "#define USE_TANGENT" : "", parameters.vertexColors || parameters.instancingColor ? "#define USE_COLOR" : "", parameters.vertexAlphas ? "#define USE_COLOR_ALPHA" : "", parameters.vertexUv1s ? "#define USE_UV1" : "", parameters.vertexUv2s ? "#define USE_UV2" : "", parameters.vertexUv3s ? "#define USE_UV3" : "", parameters.pointsUvs ? "#define USE_POINTS_UV" : "", parameters.gradientMap ? "#define USE_GRADIENTMAP" : "", parameters.flatShading ? "#define FLAT_SHADED" : "", parameters.doubleSided ? "#define DOUBLE_SIDED" : "", parameters.flipSided ? "#define FLIP_SIDED" : "", parameters.shadowMapEnabled ? "#define USE_SHADOWMAP" : "", parameters.shadowMapEnabled ? "#define " + shadowMapTypeDefine : "", parameters.premultipliedAlpha ? "#define PREMULTIPLIED_ALPHA" : "", parameters.numLightProbes > 0 ? "#define USE_LIGHT_PROBES" : "", parameters.useLegacyLights ? "#define LEGACY_LIGHTS" : "", parameters.decodeVideoTexture ? "#define DECODE_VIDEO_TEXTURE" : "", parameters.logarithmicDepthBuffer ? "#define USE_LOGDEPTHBUF" : "", parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ? "#define USE_LOGDEPTHBUF_EXT" : "", "uniform mat4 viewMatrix;", "uniform vec3 cameraPosition;", "uniform bool isOrthographic;", parameters.toneMapping !== NoToneMapping ? "#define TONE_MAPPING" : "", parameters.toneMapping !== NoToneMapping ? ShaderChunk["tonemapping_pars_fragment"] : "", // this code is required here because it is used by the toneMapping() function defined below parameters.toneMapping !== NoToneMapping ? getToneMappingFunction("toneMapping", parameters.toneMapping) : "", parameters.dithering ? "#define DITHERING" : "", parameters.opaque ? "#define OPAQUE" : "", ShaderChunk["colorspace_pars_fragment"], // this code is required here because it is used by the various encoding/decoding function defined below getTexelEncodingFunction("linearToOutputTexel", parameters.outputColorSpace), parameters.useDepthPacking ? "#define DEPTH_PACKING " + parameters.depthPacking : "", "\n" ].filter(filterEmptyLine).join("\n"); } vertexShader = resolveIncludes(vertexShader); vertexShader = replaceLightNums(vertexShader, parameters); vertexShader = replaceClippingPlaneNums(vertexShader, parameters); fragmentShader = resolveIncludes(fragmentShader); fragmentShader = replaceLightNums(fragmentShader, parameters); fragmentShader = replaceClippingPlaneNums(fragmentShader, parameters); vertexShader = unrollLoops(vertexShader); fragmentShader = unrollLoops(fragmentShader); if (parameters.isWebGL2 && parameters.isRawShaderMaterial !== true) { versionString = "#version 300 es\n"; prefixVertex = [ "precision mediump sampler2DArray;", "#define attribute in", "#define varying out", "#define texture2D texture" ].join("\n") + "\n" + prefixVertex; prefixFragment = [ "precision mediump sampler2DArray;", "#define varying in", parameters.glslVersion === GLSL3 ? "" : "layout(location = 0) out highp vec4 pc_fragColor;", parameters.glslVersion === GLSL3 ? "" : "#define gl_FragColor pc_fragColor", "#define gl_FragDepthEXT gl_FragDepth", "#define texture2D texture", "#define textureCube texture", "#define texture2DProj textureProj", "#define texture2DLodEXT textureLod", "#define texture2DProjLodEXT textureProjLod", "#define textureCubeLodEXT textureLod", "#define texture2DGradEXT textureGrad", "#define texture2DProjGradEXT textureProjGrad", "#define textureCubeGradEXT textureGrad" ].join("\n") + "\n" + prefixFragment; } const vertexGlsl = versionString + prefixVertex + vertexShader; const fragmentGlsl = versionString + prefixFragment + fragmentShader; const glVertexShader = WebGLShader(gl, gl.VERTEX_SHADER, vertexGlsl); const glFragmentShader = WebGLShader(gl, gl.FRAGMENT_SHADER, fragmentGlsl); gl.attachShader(program, glVertexShader); gl.attachShader(program, glFragmentShader); if (parameters.index0AttributeName !== void 0) { gl.bindAttribLocation(program, 0, parameters.index0AttributeName); } else if (parameters.morphTargets === true) { gl.bindAttribLocation(program, 0, "position"); } gl.linkProgram(program); function onFirstUse(self2) { if (renderer3.debug.checkShaderErrors) { const programLog = gl.getProgramInfoLog(program).trim(); const vertexLog = gl.getShaderInfoLog(glVertexShader).trim(); const fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim(); let runnable = true; let haveDiagnostics = true; if (gl.getProgramParameter(program, gl.LINK_STATUS) === false) { runnable = false; if (typeof renderer3.debug.onShaderError === "function") { renderer3.debug.onShaderError(gl, program, glVertexShader, glFragmentShader); } else { const vertexErrors = getShaderErrors(gl, glVertexShader, "vertex"); const fragmentErrors = getShaderErrors(gl, glFragmentShader, "fragment"); console.error( "THREE.WebGLProgram: Shader Error " + gl.getError() + " - VALIDATE_STATUS " + gl.getProgramParameter(program, gl.VALIDATE_STATUS) + "\n\nProgram Info Log: " + programLog + "\n" + vertexErrors + "\n" + fragmentErrors ); } } else if (programLog !== "") { console.warn("THREE.WebGLProgram: Program Info Log:", programLog); } else if (vertexLog === "" || fragmentLog === "") { haveDiagnostics = false; } if (haveDiagnostics) { self2.diagnostics = { runnable, programLog, vertexShader: { log: vertexLog, prefix: prefixVertex }, fragmentShader: { log: fragmentLog, prefix: prefixFragment } }; } } gl.deleteShader(glVertexShader); gl.deleteShader(glFragmentShader); cachedUniforms = new WebGLUniforms(gl, program); cachedAttributes = fetchAttributeLocations(gl, program); } let cachedUniforms; this.getUniforms = function() { if (cachedUniforms === void 0) { onFirstUse(this); } return cachedUniforms; }; let cachedAttributes; this.getAttributes = function() { if (cachedAttributes === void 0) { onFirstUse(this); } return cachedAttributes; }; let programReady = parameters.rendererExtensionParallelShaderCompile === false; this.isReady = function() { if (programReady === false) { programReady = gl.getProgramParameter(program, COMPLETION_STATUS_KHR); } return programReady; }; this.destroy = function() { bindingStates.releaseStatesOfProgram(this); gl.deleteProgram(program); this.program = void 0; }; this.type = parameters.shaderType; this.name = parameters.shaderName; this.id = programIdCount++; this.cacheKey = cacheKey; this.usedTimes = 1; this.program = program; this.vertexShader = glVertexShader; this.fragmentShader = glFragmentShader; return this; } var _id$1 = 0; var WebGLShaderCache = class { constructor() { this.shaderCache = /* @__PURE__ */ new Map(); this.materialCache = /* @__PURE__ */ new Map(); } update(material) { const vertexShader = material.vertexShader; const fragmentShader = material.fragmentShader; const vertexShaderStage = this._getShaderStage(vertexShader); const fragmentShaderStage = this._getShaderStage(fragmentShader); const materialShaders = this._getShaderCacheForMaterial(material); if (materialShaders.has(vertexShaderStage) === false) { materialShaders.add(vertexShaderStage); vertexShaderStage.usedTimes++; } if (materialShaders.has(fragmentShaderStage) === false) { materialShaders.add(fragmentShaderStage); fragmentShaderStage.usedTimes++; } return this; } remove(material) { const materialShaders = this.materialCache.get(material); for (const shaderStage of materialShaders) { shaderStage.usedTimes--; if (shaderStage.usedTimes === 0) this.shaderCache.delete(shaderStage.code); } this.materialCache.delete(material); return this; } getVertexShaderID(material) { return this._getShaderStage(material.vertexShader).id; } getFragmentShaderID(material) { return this._getShaderStage(material.fragmentShader).id; } dispose() { this.shaderCache.clear(); this.materialCache.clear(); } _getShaderCacheForMaterial(material) { const cache = this.materialCache; let set2 = cache.get(material); if (set2 === void 0) { set2 = /* @__PURE__ */ new Set(); cache.set(material, set2); } return set2; } _getShaderStage(code) { const cache = this.shaderCache; let stage = cache.get(code); if (stage === void 0) { stage = new WebGLShaderStage(code); cache.set(code, stage); } return stage; } }; var WebGLShaderStage = class { constructor(code) { this.id = _id$1++; this.code = code; this.usedTimes = 0; } }; function WebGLPrograms(renderer3, cubemaps, cubeuvmaps, extensions, capabilities, bindingStates, clipping) { const _programLayers = new Layers(); const _customShaders = new WebGLShaderCache(); const programs = []; const IS_WEBGL2 = capabilities.isWebGL2; const logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer; const SUPPORTS_VERTEX_TEXTURES = capabilities.vertexTextures; let precision = capabilities.precision; const shaderIDs = { MeshDepthMaterial: "depth", MeshDistanceMaterial: "distanceRGBA", MeshNormalMaterial: "normal", MeshBasicMaterial: "basic", MeshLambertMaterial: "lambert", MeshPhongMaterial: "phong", MeshToonMaterial: "toon", MeshStandardMaterial: "physical", MeshPhysicalMaterial: "physical", MeshMatcapMaterial: "matcap", LineBasicMaterial: "basic", LineDashedMaterial: "dashed", PointsMaterial: "points", ShadowMaterial: "shadow", SpriteMaterial: "sprite" }; function getChannel(value) { if (value === 0) return "uv"; return `uv${value}`; } function getParameters(material, lights, shadows, scene3, object) { const fog = scene3.fog; const geometry = object.geometry; const environment = material.isMeshStandardMaterial ? scene3.environment : null; const envMap = (material.isMeshStandardMaterial ? cubeuvmaps : cubemaps).get(material.envMap || environment); const envMapCubeUVHeight = !!envMap && envMap.mapping === CubeUVReflectionMapping ? envMap.image.height : null; const shaderID = shaderIDs[material.type]; if (material.precision !== null) { precision = capabilities.getMaxPrecision(material.precision); if (precision !== material.precision) { console.warn("THREE.WebGLProgram.getParameters:", material.precision, "not supported, using", precision, "instead."); } } const morphAttribute = geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color; const morphTargetsCount = morphAttribute !== void 0 ? morphAttribute.length : 0; let morphTextureStride = 0; if (geometry.morphAttributes.position !== void 0) morphTextureStride = 1; if (geometry.morphAttributes.normal !== void 0) morphTextureStride = 2; if (geometry.morphAttributes.color !== void 0) morphTextureStride = 3; let vertexShader, fragmentShader; let customVertexShaderID, customFragmentShaderID; if (shaderID) { const shader = ShaderLib[shaderID]; vertexShader = shader.vertexShader; fragmentShader = shader.fragmentShader; } else { vertexShader = material.vertexShader; fragmentShader = material.fragmentShader; _customShaders.update(material); customVertexShaderID = _customShaders.getVertexShaderID(material); customFragmentShaderID = _customShaders.getFragmentShaderID(material); } const currentRenderTarget = renderer3.getRenderTarget(); const IS_INSTANCEDMESH = object.isInstancedMesh === true; const HAS_MAP = !!material.map; const HAS_MATCAP = !!material.matcap; const HAS_ENVMAP = !!envMap; const HAS_AOMAP = !!material.aoMap; const HAS_LIGHTMAP = !!material.lightMap; const HAS_BUMPMAP = !!material.bumpMap; const HAS_NORMALMAP = !!material.normalMap; const HAS_DISPLACEMENTMAP = !!material.displacementMap; const HAS_EMISSIVEMAP = !!material.emissiveMap; const HAS_METALNESSMAP = !!material.metalnessMap; const HAS_ROUGHNESSMAP = !!material.roughnessMap; const HAS_ANISOTROPY = material.anisotropy > 0; const HAS_CLEARCOAT = material.clearcoat > 0; const HAS_IRIDESCENCE = material.iridescence > 0; const HAS_SHEEN = material.sheen > 0; const HAS_TRANSMISSION = material.transmission > 0; const HAS_ANISOTROPYMAP = HAS_ANISOTROPY && !!material.anisotropyMap; const HAS_CLEARCOATMAP = HAS_CLEARCOAT && !!material.clearcoatMap; const HAS_CLEARCOAT_NORMALMAP = HAS_CLEARCOAT && !!material.clearcoatNormalMap; const HAS_CLEARCOAT_ROUGHNESSMAP = HAS_CLEARCOAT && !!material.clearcoatRoughnessMap; const HAS_IRIDESCENCEMAP = HAS_IRIDESCENCE && !!material.iridescenceMap; const HAS_IRIDESCENCE_THICKNESSMAP = HAS_IRIDESCENCE && !!material.iridescenceThicknessMap; const HAS_SHEEN_COLORMAP = HAS_SHEEN && !!material.sheenColorMap; const HAS_SHEEN_ROUGHNESSMAP = HAS_SHEEN && !!material.sheenRoughnessMap; const HAS_SPECULARMAP = !!material.specularMap; const HAS_SPECULAR_COLORMAP = !!material.specularColorMap; const HAS_SPECULAR_INTENSITYMAP = !!material.specularIntensityMap; const HAS_TRANSMISSIONMAP = HAS_TRANSMISSION && !!material.transmissionMap; const HAS_THICKNESSMAP = HAS_TRANSMISSION && !!material.thicknessMap; const HAS_GRADIENTMAP = !!material.gradientMap; const HAS_ALPHAMAP = !!material.alphaMap; const HAS_ALPHATEST = material.alphaTest > 0; const HAS_ALPHAHASH = !!material.alphaHash; const HAS_EXTENSIONS = !!material.extensions; const HAS_ATTRIBUTE_UV1 = !!geometry.attributes.uv1; const HAS_ATTRIBUTE_UV2 = !!geometry.attributes.uv2; const HAS_ATTRIBUTE_UV3 = !!geometry.attributes.uv3; let toneMapping = NoToneMapping; if (material.toneMapped) { if (currentRenderTarget === null || currentRenderTarget.isXRRenderTarget === true) { toneMapping = renderer3.toneMapping; } } const parameters = { isWebGL2: IS_WEBGL2, shaderID, shaderType: material.type, shaderName: material.name, vertexShader, fragmentShader, defines: material.defines, customVertexShaderID, customFragmentShaderID, isRawShaderMaterial: material.isRawShaderMaterial === true, glslVersion: material.glslVersion, precision, instancing: IS_INSTANCEDMESH, instancingColor: IS_INSTANCEDMESH && object.instanceColor !== null, supportsVertexTextures: SUPPORTS_VERTEX_TEXTURES, outputColorSpace: currentRenderTarget === null ? renderer3.outputColorSpace : currentRenderTarget.isXRRenderTarget === true ? currentRenderTarget.texture.colorSpace : LinearSRGBColorSpace, map: HAS_MAP, matcap: HAS_MATCAP, envMap: HAS_ENVMAP, envMapMode: HAS_ENVMAP && envMap.mapping, envMapCubeUVHeight, aoMap: HAS_AOMAP, lightMap: HAS_LIGHTMAP, bumpMap: HAS_BUMPMAP, normalMap: HAS_NORMALMAP, displacementMap: SUPPORTS_VERTEX_TEXTURES && HAS_DISPLACEMENTMAP, emissiveMap: HAS_EMISSIVEMAP, normalMapObjectSpace: HAS_NORMALMAP && material.normalMapType === ObjectSpaceNormalMap, normalMapTangentSpace: HAS_NORMALMAP && material.normalMapType === TangentSpaceNormalMap, metalnessMap: HAS_METALNESSMAP, roughnessMap: HAS_ROUGHNESSMAP, anisotropy: HAS_ANISOTROPY, anisotropyMap: HAS_ANISOTROPYMAP, clearcoat: HAS_CLEARCOAT, clearcoatMap: HAS_CLEARCOATMAP, clearcoatNormalMap: HAS_CLEARCOAT_NORMALMAP, clearcoatRoughnessMap: HAS_CLEARCOAT_ROUGHNESSMAP, iridescence: HAS_IRIDESCENCE, iridescenceMap: HAS_IRIDESCENCEMAP, iridescenceThicknessMap: HAS_IRIDESCENCE_THICKNESSMAP, sheen: HAS_SHEEN, sheenColorMap: HAS_SHEEN_COLORMAP, sheenRoughnessMap: HAS_SHEEN_ROUGHNESSMAP, specularMap: HAS_SPECULARMAP, specularColorMap: HAS_SPECULAR_COLORMAP, specularIntensityMap: HAS_SPECULAR_INTENSITYMAP, transmission: HAS_TRANSMISSION, transmissionMap: HAS_TRANSMISSIONMAP, thicknessMap: HAS_THICKNESSMAP, gradientMap: HAS_GRADIENTMAP, opaque: material.transparent === false && material.blending === NormalBlending, alphaMap: HAS_ALPHAMAP, alphaTest: HAS_ALPHATEST, alphaHash: HAS_ALPHAHASH, combine: material.combine, // mapUv: HAS_MAP && getChannel(material.map.channel), aoMapUv: HAS_AOMAP && getChannel(material.aoMap.channel), lightMapUv: HAS_LIGHTMAP && getChannel(material.lightMap.channel), bumpMapUv: HAS_BUMPMAP && getChannel(material.bumpMap.channel), normalMapUv: HAS_NORMALMAP && getChannel(material.normalMap.channel), displacementMapUv: HAS_DISPLACEMENTMAP && getChannel(material.displacementMap.channel), emissiveMapUv: HAS_EMISSIVEMAP && getChannel(material.emissiveMap.channel), metalnessMapUv: HAS_METALNESSMAP && getChannel(material.metalnessMap.channel), roughnessMapUv: HAS_ROUGHNESSMAP && getChannel(material.roughnessMap.channel), anisotropyMapUv: HAS_ANISOTROPYMAP && getChannel(material.anisotropyMap.channel), clearcoatMapUv: HAS_CLEARCOATMAP && getChannel(material.clearcoatMap.channel), clearcoatNormalMapUv: HAS_CLEARCOAT_NORMALMAP && getChannel(material.clearcoatNormalMap.channel), clearcoatRoughnessMapUv: HAS_CLEARCOAT_ROUGHNESSMAP && getChannel(material.clearcoatRoughnessMap.channel), iridescenceMapUv: HAS_IRIDESCENCEMAP && getChannel(material.iridescenceMap.channel), iridescenceThicknessMapUv: HAS_IRIDESCENCE_THICKNESSMAP && getChannel(material.iridescenceThicknessMap.channel), sheenColorMapUv: HAS_SHEEN_COLORMAP && getChannel(material.sheenColorMap.channel), sheenRoughnessMapUv: HAS_SHEEN_ROUGHNESSMAP && getChannel(material.sheenRoughnessMap.channel), specularMapUv: HAS_SPECULARMAP && getChannel(material.specularMap.channel), specularColorMapUv: HAS_SPECULAR_COLORMAP && getChannel(material.specularColorMap.channel), specularIntensityMapUv: HAS_SPECULAR_INTENSITYMAP && getChannel(material.specularIntensityMap.channel), transmissionMapUv: HAS_TRANSMISSIONMAP && getChannel(material.transmissionMap.channel), thicknessMapUv: HAS_THICKNESSMAP && getChannel(material.thicknessMap.channel), alphaMapUv: HAS_ALPHAMAP && getChannel(material.alphaMap.channel), // vertexTangents: !!geometry.attributes.tangent && (HAS_NORMALMAP || HAS_ANISOTROPY), vertexColors: material.vertexColors, vertexAlphas: material.vertexColors === true && !!geometry.attributes.color && geometry.attributes.color.itemSize === 4, vertexUv1s: HAS_ATTRIBUTE_UV1, vertexUv2s: HAS_ATTRIBUTE_UV2, vertexUv3s: HAS_ATTRIBUTE_UV3, pointsUvs: object.isPoints === true && !!geometry.attributes.uv && (HAS_MAP || HAS_ALPHAMAP), fog: !!fog, useFog: material.fog === true, fogExp2: fog && fog.isFogExp2, flatShading: material.flatShading === true, sizeAttenuation: material.sizeAttenuation === true, logarithmicDepthBuffer, skinning: object.isSkinnedMesh === true, morphTargets: geometry.morphAttributes.position !== void 0, morphNormals: geometry.morphAttributes.normal !== void 0, morphColors: geometry.morphAttributes.color !== void 0, morphTargetsCount, morphTextureStride, numDirLights: lights.directional.length, numPointLights: lights.point.length, numSpotLights: lights.spot.length, numSpotLightMaps: lights.spotLightMap.length, numRectAreaLights: lights.rectArea.length, numHemiLights: lights.hemi.length, numDirLightShadows: lights.directionalShadowMap.length, numPointLightShadows: lights.pointShadowMap.length, numSpotLightShadows: lights.spotShadowMap.length, numSpotLightShadowsWithMaps: lights.numSpotLightShadowsWithMaps, numLightProbes: lights.numLightProbes, numClippingPlanes: clipping.numPlanes, numClipIntersection: clipping.numIntersection, dithering: material.dithering, shadowMapEnabled: renderer3.shadowMap.enabled && shadows.length > 0, shadowMapType: renderer3.shadowMap.type, toneMapping, useLegacyLights: renderer3._useLegacyLights, decodeVideoTexture: HAS_MAP && material.map.isVideoTexture === true && ColorManagement.getTransfer(material.map.colorSpace) === SRGBTransfer, premultipliedAlpha: material.premultipliedAlpha, doubleSided: material.side === DoubleSide, flipSided: material.side === BackSide, useDepthPacking: material.depthPacking >= 0, depthPacking: material.depthPacking || 0, index0AttributeName: material.index0AttributeName, extensionDerivatives: HAS_EXTENSIONS && material.extensions.derivatives === true, extensionFragDepth: HAS_EXTENSIONS && material.extensions.fragDepth === true, extensionDrawBuffers: HAS_EXTENSIONS && material.extensions.drawBuffers === true, extensionShaderTextureLOD: HAS_EXTENSIONS && material.extensions.shaderTextureLOD === true, rendererExtensionFragDepth: IS_WEBGL2 || extensions.has("EXT_frag_depth"), rendererExtensionDrawBuffers: IS_WEBGL2 || extensions.has("WEBGL_draw_buffers"), rendererExtensionShaderTextureLod: IS_WEBGL2 || extensions.has("EXT_shader_texture_lod"), rendererExtensionParallelShaderCompile: extensions.has("KHR_parallel_shader_compile"), customProgramCacheKey: material.customProgramCacheKey() }; return parameters; } function getProgramCacheKey(parameters) { const array = []; if (parameters.shaderID) { array.push(parameters.shaderID); } else { array.push(parameters.customVertexShaderID); array.push(parameters.customFragmentShaderID); } if (parameters.defines !== void 0) { for (const name in parameters.defines) { array.push(name); array.push(parameters.defines[name]); } } if (parameters.isRawShaderMaterial === false) { getProgramCacheKeyParameters(array, parameters); getProgramCacheKeyBooleans(array, parameters); array.push(renderer3.outputColorSpace); } array.push(parameters.customProgramCacheKey); return array.join(); } function getProgramCacheKeyParameters(array, parameters) { array.push(parameters.precision); array.push(parameters.outputColorSpace); array.push(parameters.envMapMode); array.push(parameters.envMapCubeUVHeight); array.push(parameters.mapUv); array.push(parameters.alphaMapUv); array.push(parameters.lightMapUv); array.push(parameters.aoMapUv); array.push(parameters.bumpMapUv); array.push(parameters.normalMapUv); array.push(parameters.displacementMapUv); array.push(parameters.emissiveMapUv); array.push(parameters.metalnessMapUv); array.push(parameters.roughnessMapUv); array.push(parameters.anisotropyMapUv); array.push(parameters.clearcoatMapUv); array.push(parameters.clearcoatNormalMapUv); array.push(parameters.clearcoatRoughnessMapUv); array.push(parameters.iridescenceMapUv); array.push(parameters.iridescenceThicknessMapUv); array.push(parameters.sheenColorMapUv); array.push(parameters.sheenRoughnessMapUv); array.push(parameters.specularMapUv); array.push(parameters.specularColorMapUv); array.push(parameters.specularIntensityMapUv); array.push(parameters.transmissionMapUv); array.push(parameters.thicknessMapUv); array.push(parameters.combine); array.push(parameters.fogExp2); array.push(parameters.sizeAttenuation); array.push(parameters.morphTargetsCount); array.push(parameters.morphAttributeCount); array.push(parameters.numDirLights); array.push(parameters.numPointLights); array.push(parameters.numSpotLights); array.push(parameters.numSpotLightMaps); array.push(parameters.numHemiLights); array.push(parameters.numRectAreaLights); array.push(parameters.numDirLightShadows); array.push(parameters.numPointLightShadows); array.push(parameters.numSpotLightShadows); array.push(parameters.numSpotLightShadowsWithMaps); array.push(parameters.numLightProbes); array.push(parameters.shadowMapType); array.push(parameters.toneMapping); array.push(parameters.numClippingPlanes); array.push(parameters.numClipIntersection); array.push(parameters.depthPacking); } function getProgramCacheKeyBooleans(array, parameters) { _programLayers.disableAll(); if (parameters.isWebGL2) _programLayers.enable(0); if (parameters.supportsVertexTextures) _programLayers.enable(1); if (parameters.instancing) _programLayers.enable(2); if (parameters.instancingColor) _programLayers.enable(3); if (parameters.matcap) _programLayers.enable(4); if (parameters.envMap) _programLayers.enable(5); if (parameters.normalMapObjectSpace) _programLayers.enable(6); if (parameters.normalMapTangentSpace) _programLayers.enable(7); if (parameters.clearcoat) _programLayers.enable(8); if (parameters.iridescence) _programLayers.enable(9); if (parameters.alphaTest) _programLayers.enable(10); if (parameters.vertexColors) _programLayers.enable(11); if (parameters.vertexAlphas) _programLayers.enable(12); if (parameters.vertexUv1s) _programLayers.enable(13); if (parameters.vertexUv2s) _programLayers.enable(14); if (parameters.vertexUv3s) _programLayers.enable(15); if (parameters.vertexTangents) _programLayers.enable(16); if (parameters.anisotropy) _programLayers.enable(17); if (parameters.alphaHash) _programLayers.enable(18); array.push(_programLayers.mask); _programLayers.disableAll(); if (parameters.fog) _programLayers.enable(0); if (parameters.useFog) _programLayers.enable(1); if (parameters.flatShading) _programLayers.enable(2); if (parameters.logarithmicDepthBuffer) _programLayers.enable(3); if (parameters.skinning) _programLayers.enable(4); if (parameters.morphTargets) _programLayers.enable(5); if (parameters.morphNormals) _programLayers.enable(6); if (parameters.morphColors) _programLayers.enable(7); if (parameters.premultipliedAlpha) _programLayers.enable(8); if (parameters.shadowMapEnabled) _programLayers.enable(9); if (parameters.useLegacyLights) _programLayers.enable(10); if (parameters.doubleSided) _programLayers.enable(11); if (parameters.flipSided) _programLayers.enable(12); if (parameters.useDepthPacking) _programLayers.enable(13); if (parameters.dithering) _programLayers.enable(14); if (parameters.transmission) _programLayers.enable(15); if (parameters.sheen) _programLayers.enable(16); if (parameters.opaque) _programLayers.enable(17); if (parameters.pointsUvs) _programLayers.enable(18); if (parameters.decodeVideoTexture) _programLayers.enable(19); array.push(_programLayers.mask); } function getUniforms(material) { const shaderID = shaderIDs[material.type]; let uniforms; if (shaderID) { const shader = ShaderLib[shaderID]; uniforms = UniformsUtils.clone(shader.uniforms); } else { uniforms = material.uniforms; } return uniforms; } function acquireProgram(parameters, cacheKey) { let program; for (let p = 0, pl = programs.length; p < pl; p++) { const preexistingProgram = programs[p]; if (preexistingProgram.cacheKey === cacheKey) { program = preexistingProgram; ++program.usedTimes; break; } } if (program === void 0) { program = new WebGLProgram(renderer3, cacheKey, parameters, bindingStates); programs.push(program); } return program; } function releaseProgram(program) { if (--program.usedTimes === 0) { const i = programs.indexOf(program); programs[i] = programs[programs.length - 1]; programs.pop(); program.destroy(); } } function releaseShaderCache(material) { _customShaders.remove(material); } function dispose() { _customShaders.dispose(); } return { getParameters, getProgramCacheKey, getUniforms, acquireProgram, releaseProgram, releaseShaderCache, // Exposed for resource monitoring & error feedback via renderer.info: programs, dispose }; } function WebGLProperties() { let properties = /* @__PURE__ */ new WeakMap(); function get2(object) { let map = properties.get(object); if (map === void 0) { map = {}; properties.set(object, map); } return map; } function remove2(object) { properties.delete(object); } function update4(object, key, value) { properties.get(object)[key] = value; } function dispose() { properties = /* @__PURE__ */ new WeakMap(); } return { get: get2, remove: remove2, update: update4, dispose }; } function painterSortStable(a2, b) { if (a2.groupOrder !== b.groupOrder) { return a2.groupOrder - b.groupOrder; } else if (a2.renderOrder !== b.renderOrder) { return a2.renderOrder - b.renderOrder; } else if (a2.material.id !== b.material.id) { return a2.material.id - b.material.id; } else if (a2.z !== b.z) { return a2.z - b.z; } else { return a2.id - b.id; } } function reversePainterSortStable(a2, b) { if (a2.groupOrder !== b.groupOrder) { return a2.groupOrder - b.groupOrder; } else if (a2.renderOrder !== b.renderOrder) { return a2.renderOrder - b.renderOrder; } else if (a2.z !== b.z) { return b.z - a2.z; } else { return a2.id - b.id; } } function WebGLRenderList() { const renderItems = []; let renderItemsIndex = 0; const opaque = []; const transmissive = []; const transparent = []; function init4() { renderItemsIndex = 0; opaque.length = 0; transmissive.length = 0; transparent.length = 0; } function getNextRenderItem(object, geometry, material, groupOrder, z4, group) { let renderItem = renderItems[renderItemsIndex]; if (renderItem === void 0) { renderItem = { id: object.id, object, geometry, material, groupOrder, renderOrder: object.renderOrder, z: z4, group }; renderItems[renderItemsIndex] = renderItem; } else { renderItem.id = object.id; renderItem.object = object; renderItem.geometry = geometry; renderItem.material = material; renderItem.groupOrder = groupOrder; renderItem.renderOrder = object.renderOrder; renderItem.z = z4; renderItem.group = group; } renderItemsIndex++; return renderItem; } function push(object, geometry, material, groupOrder, z4, group) { const renderItem = getNextRenderItem(object, geometry, material, groupOrder, z4, group); if (material.transmission > 0) { transmissive.push(renderItem); } else if (material.transparent === true) { transparent.push(renderItem); } else { opaque.push(renderItem); } } function unshift(object, geometry, material, groupOrder, z4, group) { const renderItem = getNextRenderItem(object, geometry, material, groupOrder, z4, group); if (material.transmission > 0) { transmissive.unshift(renderItem); } else if (material.transparent === true) { transparent.unshift(renderItem); } else { opaque.unshift(renderItem); } } function sort(customOpaqueSort, customTransparentSort) { if (opaque.length > 1) opaque.sort(customOpaqueSort || painterSortStable); if (transmissive.length > 1) transmissive.sort(customTransparentSort || reversePainterSortStable); if (transparent.length > 1) transparent.sort(customTransparentSort || reversePainterSortStable); } function finish() { for (let i = renderItemsIndex, il = renderItems.length; i < il; i++) { const renderItem = renderItems[i]; if (renderItem.id === null) break; renderItem.id = null; renderItem.object = null; renderItem.geometry = null; renderItem.material = null; renderItem.group = null; } } return { opaque, transmissive, transparent, init: init4, push, unshift, finish, sort }; } function WebGLRenderLists() { let lists = /* @__PURE__ */ new WeakMap(); function get2(scene3, renderCallDepth) { const listArray = lists.get(scene3); let list; if (listArray === void 0) { list = new WebGLRenderList(); lists.set(scene3, [list]); } else { if (renderCallDepth >= listArray.length) { list = new WebGLRenderList(); listArray.push(list); } else { list = listArray[renderCallDepth]; } } return list; } function dispose() { lists = /* @__PURE__ */ new WeakMap(); } return { get: get2, dispose }; } function UniformsCache() { const lights = {}; return { get: function(light) { if (lights[light.id] !== void 0) { return lights[light.id]; } let uniforms; switch (light.type) { case "DirectionalLight": uniforms = { direction: new Vector3(), color: new Color() }; break; case "SpotLight": uniforms = { position: new Vector3(), direction: new Vector3(), color: new Color(), distance: 0, coneCos: 0, penumbraCos: 0, decay: 0 }; break; case "PointLight": uniforms = { position: new Vector3(), color: new Color(), distance: 0, decay: 0 }; break; case "HemisphereLight": uniforms = { direction: new Vector3(), skyColor: new Color(), groundColor: new Color() }; break; case "RectAreaLight": uniforms = { color: new Color(), position: new Vector3(), halfWidth: new Vector3(), halfHeight: new Vector3() }; break; } lights[light.id] = uniforms; return uniforms; } }; } function ShadowUniformsCache() { const lights = {}; return { get: function(light) { if (lights[light.id] !== void 0) { return lights[light.id]; } let uniforms; switch (light.type) { case "DirectionalLight": uniforms = { shadowBias: 0, shadowNormalBias: 0, shadowRadius: 1, shadowMapSize: new Vector2() }; break; case "SpotLight": uniforms = { shadowBias: 0, shadowNormalBias: 0, shadowRadius: 1, shadowMapSize: new Vector2() }; break; case "PointLight": uniforms = { shadowBias: 0, shadowNormalBias: 0, shadowRadius: 1, shadowMapSize: new Vector2(), shadowCameraNear: 1, shadowCameraFar: 1e3 }; break; } lights[light.id] = uniforms; return uniforms; } }; } var nextVersion = 0; function shadowCastingAndTexturingLightsFirst(lightA, lightB) { return (lightB.castShadow ? 2 : 0) - (lightA.castShadow ? 2 : 0) + (lightB.map ? 1 : 0) - (lightA.map ? 1 : 0); } function WebGLLights(extensions, capabilities) { const cache = new UniformsCache(); const shadowCache = ShadowUniformsCache(); const state = { version: 0, hash: { directionalLength: -1, pointLength: -1, spotLength: -1, rectAreaLength: -1, hemiLength: -1, numDirectionalShadows: -1, numPointShadows: -1, numSpotShadows: -1, numSpotMaps: -1, numLightProbes: -1 }, ambient: [0, 0, 0], probe: [], directional: [], directionalShadow: [], directionalShadowMap: [], directionalShadowMatrix: [], spot: [], spotLightMap: [], spotShadow: [], spotShadowMap: [], spotLightMatrix: [], rectArea: [], rectAreaLTC1: null, rectAreaLTC2: null, point: [], pointShadow: [], pointShadowMap: [], pointShadowMatrix: [], hemi: [], numSpotLightShadowsWithMaps: 0, numLightProbes: 0 }; for (let i = 0; i < 9; i++) state.probe.push(new Vector3()); const vector3 = new Vector3(); const matrix4 = new Matrix4(); const matrix42 = new Matrix4(); function setup(lights, useLegacyLights) { let r = 0, g = 0, b = 0; for (let i = 0; i < 9; i++) state.probe[i].set(0, 0, 0); let directionalLength = 0; let pointLength = 0; let spotLength = 0; let rectAreaLength = 0; let hemiLength = 0; let numDirectionalShadows = 0; let numPointShadows = 0; let numSpotShadows = 0; let numSpotMaps = 0; let numSpotShadowsWithMaps = 0; let numLightProbes = 0; lights.sort(shadowCastingAndTexturingLightsFirst); const scaleFactor = useLegacyLights === true ? Math.PI : 1; for (let i = 0, l = lights.length; i < l; i++) { const light = lights[i]; const color = light.color; const intensity = light.intensity; const distance = light.distance; const shadowMap = light.shadow && light.shadow.map ? light.shadow.map.texture : null; if (light.isAmbientLight) { r += color.r * intensity * scaleFactor; g += color.g * intensity * scaleFactor; b += color.b * intensity * scaleFactor; } else if (light.isLightProbe) { for (let j = 0; j < 9; j++) { state.probe[j].addScaledVector(light.sh.coefficients[j], intensity); } numLightProbes++; } else if (light.isDirectionalLight) { const uniforms = cache.get(light); uniforms.color.copy(light.color).multiplyScalar(light.intensity * scaleFactor); if (light.castShadow) { const shadow = light.shadow; const shadowUniforms = shadowCache.get(light); shadowUniforms.shadowBias = shadow.bias; shadowUniforms.shadowNormalBias = shadow.normalBias; shadowUniforms.shadowRadius = shadow.radius; shadowUniforms.shadowMapSize = shadow.mapSize; state.directionalShadow[directionalLength] = shadowUniforms; state.directionalShadowMap[directionalLength] = shadowMap; state.directionalShadowMatrix[directionalLength] = light.shadow.matrix; numDirectionalShadows++; } state.directional[directionalLength] = uniforms; directionalLength++; } else if (light.isSpotLight) { const uniforms = cache.get(light); uniforms.position.setFromMatrixPosition(light.matrixWorld); uniforms.color.copy(color).multiplyScalar(intensity * scaleFactor); uniforms.distance = distance; uniforms.coneCos = Math.cos(light.angle); uniforms.penumbraCos = Math.cos(light.angle * (1 - light.penumbra)); uniforms.decay = light.decay; state.spot[spotLength] = uniforms; const shadow = light.shadow; if (light.map) { state.spotLightMap[numSpotMaps] = light.map; numSpotMaps++; shadow.updateMatrices(light); if (light.castShadow) numSpotShadowsWithMaps++; } state.spotLightMatrix[spotLength] = shadow.matrix; if (light.castShadow) { const shadowUniforms = shadowCache.get(light); shadowUniforms.shadowBias = shadow.bias; shadowUniforms.shadowNormalBias = shadow.normalBias; shadowUniforms.shadowRadius = shadow.radius; shadowUniforms.shadowMapSize = shadow.mapSize; state.spotShadow[spotLength] = shadowUniforms; state.spotShadowMap[spotLength] = shadowMap; numSpotShadows++; } spotLength++; } else if (light.isRectAreaLight) { const uniforms = cache.get(light); uniforms.color.copy(color).multiplyScalar(intensity); uniforms.halfWidth.set(light.width * 0.5, 0, 0); uniforms.halfHeight.set(0, light.height * 0.5, 0); state.rectArea[rectAreaLength] = uniforms; rectAreaLength++; } else if (light.isPointLight) { const uniforms = cache.get(light); uniforms.color.copy(light.color).multiplyScalar(light.intensity * scaleFactor); uniforms.distance = light.distance; uniforms.decay = light.decay; if (light.castShadow) { const shadow = light.shadow; const shadowUniforms = shadowCache.get(light); shadowUniforms.shadowBias = shadow.bias; shadowUniforms.shadowNormalBias = shadow.normalBias; shadowUniforms.shadowRadius = shadow.radius; shadowUniforms.shadowMapSize = shadow.mapSize; shadowUniforms.shadowCameraNear = shadow.camera.near; shadowUniforms.shadowCameraFar = shadow.camera.far; state.pointShadow[pointLength] = shadowUniforms; state.pointShadowMap[pointLength] = shadowMap; state.pointShadowMatrix[pointLength] = light.shadow.matrix; numPointShadows++; } state.point[pointLength] = uniforms; pointLength++; } else if (light.isHemisphereLight) { const uniforms = cache.get(light); uniforms.skyColor.copy(light.color).multiplyScalar(intensity * scaleFactor); uniforms.groundColor.copy(light.groundColor).multiplyScalar(intensity * scaleFactor); state.hemi[hemiLength] = uniforms; hemiLength++; } } if (rectAreaLength > 0) { if (capabilities.isWebGL2) { state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1; state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2; } else { if (extensions.has("OES_texture_float_linear") === true) { state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1; state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2; } else if (extensions.has("OES_texture_half_float_linear") === true) { state.rectAreaLTC1 = UniformsLib.LTC_HALF_1; state.rectAreaLTC2 = UniformsLib.LTC_HALF_2; } else { console.error("THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions."); } } } state.ambient[0] = r; state.ambient[1] = g; state.ambient[2] = b; const hash = state.hash; if (hash.directionalLength !== directionalLength || hash.pointLength !== pointLength || hash.spotLength !== spotLength || hash.rectAreaLength !== rectAreaLength || hash.hemiLength !== hemiLength || hash.numDirectionalShadows !== numDirectionalShadows || hash.numPointShadows !== numPointShadows || hash.numSpotShadows !== numSpotShadows || hash.numSpotMaps !== numSpotMaps || hash.numLightProbes !== numLightProbes) { state.directional.length = directionalLength; state.spot.length = spotLength; state.rectArea.length = rectAreaLength; state.point.length = pointLength; state.hemi.length = hemiLength; state.directionalShadow.length = numDirectionalShadows; state.directionalShadowMap.length = numDirectionalShadows; state.pointShadow.length = numPointShadows; state.pointShadowMap.length = numPointShadows; state.spotShadow.length = numSpotShadows; state.spotShadowMap.length = numSpotShadows; state.directionalShadowMatrix.length = numDirectionalShadows; state.pointShadowMatrix.length = numPointShadows; state.spotLightMatrix.length = numSpotShadows + numSpotMaps - numSpotShadowsWithMaps; state.spotLightMap.length = numSpotMaps; state.numSpotLightShadowsWithMaps = numSpotShadowsWithMaps; state.numLightProbes = numLightProbes; hash.directionalLength = directionalLength; hash.pointLength = pointLength; hash.spotLength = spotLength; hash.rectAreaLength = rectAreaLength; hash.hemiLength = hemiLength; hash.numDirectionalShadows = numDirectionalShadows; hash.numPointShadows = numPointShadows; hash.numSpotShadows = numSpotShadows; hash.numSpotMaps = numSpotMaps; hash.numLightProbes = numLightProbes; state.version = nextVersion++; } } function setupView(lights, camera3) { let directionalLength = 0; let pointLength = 0; let spotLength = 0; let rectAreaLength = 0; let hemiLength = 0; const viewMatrix = camera3.matrixWorldInverse; for (let i = 0, l = lights.length; i < l; i++) { const light = lights[i]; if (light.isDirectionalLight) { const uniforms = state.directional[directionalLength]; uniforms.direction.setFromMatrixPosition(light.matrixWorld); vector3.setFromMatrixPosition(light.target.matrixWorld); uniforms.direction.sub(vector3); uniforms.direction.transformDirection(viewMatrix); directionalLength++; } else if (light.isSpotLight) { const uniforms = state.spot[spotLength]; uniforms.position.setFromMatrixPosition(light.matrixWorld); uniforms.position.applyMatrix4(viewMatrix); uniforms.direction.setFromMatrixPosition(light.matrixWorld); vector3.setFromMatrixPosition(light.target.matrixWorld); uniforms.direction.sub(vector3); uniforms.direction.transformDirection(viewMatrix); spotLength++; } else if (light.isRectAreaLight) { const uniforms = state.rectArea[rectAreaLength]; uniforms.position.setFromMatrixPosition(light.matrixWorld); uniforms.position.applyMatrix4(viewMatrix); matrix42.identity(); matrix4.copy(light.matrixWorld); matrix4.premultiply(viewMatrix); matrix42.extractRotation(matrix4); uniforms.halfWidth.set(light.width * 0.5, 0, 0); uniforms.halfHeight.set(0, light.height * 0.5, 0); uniforms.halfWidth.applyMatrix4(matrix42); uniforms.halfHeight.applyMatrix4(matrix42); rectAreaLength++; } else if (light.isPointLight) { const uniforms = state.point[pointLength]; uniforms.position.setFromMatrixPosition(light.matrixWorld); uniforms.position.applyMatrix4(viewMatrix); pointLength++; } else if (light.isHemisphereLight) { const uniforms = state.hemi[hemiLength]; uniforms.direction.setFromMatrixPosition(light.matrixWorld); uniforms.direction.transformDirection(viewMatrix); hemiLength++; } } } return { setup, setupView, state }; } function WebGLRenderState(extensions, capabilities) { const lights = new WebGLLights(extensions, capabilities); const lightsArray = []; const shadowsArray = []; function init4() { lightsArray.length = 0; shadowsArray.length = 0; } function pushLight(light) { lightsArray.push(light); } function pushShadow(shadowLight) { shadowsArray.push(shadowLight); } function setupLights(useLegacyLights) { lights.setup(lightsArray, useLegacyLights); } function setupLightsView(camera3) { lights.setupView(lightsArray, camera3); } const state = { lightsArray, shadowsArray, lights }; return { init: init4, state, setupLights, setupLightsView, pushLight, pushShadow }; } function WebGLRenderStates(extensions, capabilities) { let renderStates = /* @__PURE__ */ new WeakMap(); function get2(scene3, renderCallDepth = 0) { const renderStateArray = renderStates.get(scene3); let renderState; if (renderStateArray === void 0) { renderState = new WebGLRenderState(extensions, capabilities); renderStates.set(scene3, [renderState]); } else { if (renderCallDepth >= renderStateArray.length) { renderState = new WebGLRenderState(extensions, capabilities); renderStateArray.push(renderState); } else { renderState = renderStateArray[renderCallDepth]; } } return renderState; } function dispose() { renderStates = /* @__PURE__ */ new WeakMap(); } return { get: get2, dispose }; } var MeshDepthMaterial = class extends Material { constructor(parameters) { super(); this.isMeshDepthMaterial = true; this.type = "MeshDepthMaterial"; this.depthPacking = BasicDepthPacking; this.map = null; this.alphaMap = null; this.displacementMap = null; this.displacementScale = 1; this.displacementBias = 0; this.wireframe = false; this.wireframeLinewidth = 1; this.setValues(parameters); } copy(source) { super.copy(source); this.depthPacking = source.depthPacking; this.map = source.map; this.alphaMap = source.alphaMap; this.displacementMap = source.displacementMap; this.displacementScale = source.displacementScale; this.displacementBias = source.displacementBias; this.wireframe = source.wireframe; this.wireframeLinewidth = source.wireframeLinewidth; return this; } }; var MeshDistanceMaterial = class extends Material { constructor(parameters) { super(); this.isMeshDistanceMaterial = true; this.type = "MeshDistanceMaterial"; this.map = null; this.alphaMap = null; this.displacementMap = null; this.displacementScale = 1; this.displacementBias = 0; this.setValues(parameters); } copy(source) { super.copy(source); this.map = source.map; this.alphaMap = source.alphaMap; this.displacementMap = source.displacementMap; this.displacementScale = source.displacementScale; this.displacementBias = source.displacementBias; return this; } }; var vertex = "void main() {\n gl_Position = vec4( position, 1.0 );\n}"; var fragment = "uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include \nvoid main() {\n const float samples = float( VSM_SAMPLES );\n float mean = 0.0;\n float squared_mean = 0.0;\n float uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );\n float uvStart = samples <= 1.0 ? 0.0 : - 1.0;\n for ( float i = 0.0; i < samples; i ++ ) {\n float uvOffset = uvStart + i * uvStride;\n #ifdef HORIZONTAL_PASS\n vec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ) );\n mean += distribution.x;\n squared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n #else\n float depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ) );\n mean += depth;\n squared_mean += depth * depth;\n #endif\n }\n mean = mean / samples;\n squared_mean = squared_mean / samples;\n float std_dev = sqrt( squared_mean - mean * mean );\n gl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}"; function WebGLShadowMap(_renderer, _objects, _capabilities) { let _frustum = new Frustum(); const _shadowMapSize = new Vector2(), _viewportSize = new Vector2(), _viewport = new Vector4(), _depthMaterial = new MeshDepthMaterial({ depthPacking: RGBADepthPacking }), _distanceMaterial = new MeshDistanceMaterial(), _materialCache = {}, _maxTextureSize = _capabilities.maxTextureSize; const shadowSide = { [FrontSide]: BackSide, [BackSide]: FrontSide, [DoubleSide]: DoubleSide }; const shadowMaterialVertical = new ShaderMaterial({ defines: { VSM_SAMPLES: 8 }, uniforms: { shadow_pass: { value: null }, resolution: { value: new Vector2() }, radius: { value: 4 } }, vertexShader: vertex, fragmentShader: fragment }); const shadowMaterialHorizontal = shadowMaterialVertical.clone(); shadowMaterialHorizontal.defines.HORIZONTAL_PASS = 1; const fullScreenTri = new BufferGeometry(); fullScreenTri.setAttribute( "position", new BufferAttribute( new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]), 3 ) ); const fullScreenMesh = new Mesh(fullScreenTri, shadowMaterialVertical); const scope = this; this.enabled = false; this.autoUpdate = true; this.needsUpdate = false; this.type = PCFShadowMap; let _previousType = this.type; this.render = function(lights, scene3, camera3) { if (scope.enabled === false) return; if (scope.autoUpdate === false && scope.needsUpdate === false) return; if (lights.length === 0) return; const currentRenderTarget = _renderer.getRenderTarget(); const activeCubeFace = _renderer.getActiveCubeFace(); const activeMipmapLevel = _renderer.getActiveMipmapLevel(); const _state = _renderer.state; _state.setBlending(NoBlending); _state.buffers.color.setClear(1, 1, 1, 1); _state.buffers.depth.setTest(true); _state.setScissorTest(false); const toVSM = _previousType !== VSMShadowMap && this.type === VSMShadowMap; const fromVSM = _previousType === VSMShadowMap && this.type !== VSMShadowMap; for (let i = 0, il = lights.length; i < il; i++) { const light = lights[i]; const shadow = light.shadow; if (shadow === void 0) { console.warn("THREE.WebGLShadowMap:", light, "has no shadow."); continue; } if (shadow.autoUpdate === false && shadow.needsUpdate === false) continue; _shadowMapSize.copy(shadow.mapSize); const shadowFrameExtents = shadow.getFrameExtents(); _shadowMapSize.multiply(shadowFrameExtents); _viewportSize.copy(shadow.mapSize); if (_shadowMapSize.x > _maxTextureSize || _shadowMapSize.y > _maxTextureSize) { if (_shadowMapSize.x > _maxTextureSize) { _viewportSize.x = Math.floor(_maxTextureSize / shadowFrameExtents.x); _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x; shadow.mapSize.x = _viewportSize.x; } if (_shadowMapSize.y > _maxTextureSize) { _viewportSize.y = Math.floor(_maxTextureSize / shadowFrameExtents.y); _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y; shadow.mapSize.y = _viewportSize.y; } } if (shadow.map === null || toVSM === true || fromVSM === true) { const pars = this.type !== VSMShadowMap ? { minFilter: NearestFilter, magFilter: NearestFilter } : {}; if (shadow.map !== null) { shadow.map.dispose(); } shadow.map = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y, pars); shadow.map.texture.name = light.name + ".shadowMap"; shadow.camera.updateProjectionMatrix(); } _renderer.setRenderTarget(shadow.map); _renderer.clear(); const viewportCount = shadow.getViewportCount(); for (let vp = 0; vp < viewportCount; vp++) { const viewport = shadow.getViewport(vp); _viewport.set( _viewportSize.x * viewport.x, _viewportSize.y * viewport.y, _viewportSize.x * viewport.z, _viewportSize.y * viewport.w ); _state.viewport(_viewport); shadow.updateMatrices(light, vp); _frustum = shadow.getFrustum(); renderObject(scene3, camera3, shadow.camera, light, this.type); } if (shadow.isPointLightShadow !== true && this.type === VSMShadowMap) { VSMPass(shadow, camera3); } shadow.needsUpdate = false; } _previousType = this.type; scope.needsUpdate = false; _renderer.setRenderTarget(currentRenderTarget, activeCubeFace, activeMipmapLevel); }; function VSMPass(shadow, camera3) { const geometry = _objects.update(fullScreenMesh); if (shadowMaterialVertical.defines.VSM_SAMPLES !== shadow.blurSamples) { shadowMaterialVertical.defines.VSM_SAMPLES = shadow.blurSamples; shadowMaterialHorizontal.defines.VSM_SAMPLES = shadow.blurSamples; shadowMaterialVertical.needsUpdate = true; shadowMaterialHorizontal.needsUpdate = true; } if (shadow.mapPass === null) { shadow.mapPass = new WebGLRenderTarget(_shadowMapSize.x, _shadowMapSize.y); } shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture; shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize; shadowMaterialVertical.uniforms.radius.value = shadow.radius; _renderer.setRenderTarget(shadow.mapPass); _renderer.clear(); _renderer.renderBufferDirect(camera3, null, geometry, shadowMaterialVertical, fullScreenMesh, null); shadowMaterialHorizontal.uniforms.shadow_pass.value = shadow.mapPass.texture; shadowMaterialHorizontal.uniforms.resolution.value = shadow.mapSize; shadowMaterialHorizontal.uniforms.radius.value = shadow.radius; _renderer.setRenderTarget(shadow.map); _renderer.clear(); _renderer.renderBufferDirect(camera3, null, geometry, shadowMaterialHorizontal, fullScreenMesh, null); } function getDepthMaterial(object, material, light, type) { let result = null; const customMaterial = light.isPointLight === true ? object.customDistanceMaterial : object.customDepthMaterial; if (customMaterial !== void 0) { result = customMaterial; } else { result = light.isPointLight === true ? _distanceMaterial : _depthMaterial; if (_renderer.localClippingEnabled && material.clipShadows === true && Array.isArray(material.clippingPlanes) && material.clippingPlanes.length !== 0 || material.displacementMap && material.displacementScale !== 0 || material.alphaMap && material.alphaTest > 0 || material.map && material.alphaTest > 0) { const keyA = result.uuid, keyB = material.uuid; let materialsForVariant = _materialCache[keyA]; if (materialsForVariant === void 0) { materialsForVariant = {}; _materialCache[keyA] = materialsForVariant; } let cachedMaterial = materialsForVariant[keyB]; if (cachedMaterial === void 0) { cachedMaterial = result.clone(); materialsForVariant[keyB] = cachedMaterial; } result = cachedMaterial; } } result.visible = material.visible; result.wireframe = material.wireframe; if (type === VSMShadowMap) { result.side = material.shadowSide !== null ? material.shadowSide : material.side; } else { result.side = material.shadowSide !== null ? material.shadowSide : shadowSide[material.side]; } result.alphaMap = material.alphaMap; result.alphaTest = material.alphaTest; result.map = material.map; result.clipShadows = material.clipShadows; result.clippingPlanes = material.clippingPlanes; result.clipIntersection = material.clipIntersection; result.displacementMap = material.displacementMap; result.displacementScale = material.displacementScale; result.displacementBias = material.displacementBias; result.wireframeLinewidth = material.wireframeLinewidth; result.linewidth = material.linewidth; if (light.isPointLight === true && result.isMeshDistanceMaterial === true) { const materialProperties = _renderer.properties.get(result); materialProperties.light = light; } return result; } function renderObject(object, camera3, shadowCamera, light, type) { if (object.visible === false) return; const visible = object.layers.test(camera3.layers); if (visible && (object.isMesh || object.isLine || object.isPoints)) { if ((object.castShadow || object.receiveShadow && type === VSMShadowMap) && (!object.frustumCulled || _frustum.intersectsObject(object))) { object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse, object.matrixWorld); const geometry = _objects.update(object); const material = object.material; if (Array.isArray(material)) { const groups = geometry.groups; for (let k = 0, kl = groups.length; k < kl; k++) { const group = groups[k]; const groupMaterial = material[group.materialIndex]; if (groupMaterial && groupMaterial.visible) { const depthMaterial = getDepthMaterial(object, groupMaterial, light, type); _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group); } } } else if (material.visible) { const depthMaterial = getDepthMaterial(object, material, light, type); _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, null); } } } const children = object.children; for (let i = 0, l = children.length; i < l; i++) { renderObject(children[i], camera3, shadowCamera, light, type); } } } function WebGLState(gl, extensions, capabilities) { const isWebGL2 = capabilities.isWebGL2; function ColorBuffer() { let locked = false; const color = new Vector4(); let currentColorMask = null; const currentColorClear = new Vector4(0, 0, 0, 0); return { setMask: function(colorMask) { if (currentColorMask !== colorMask && !locked) { gl.colorMask(colorMask, colorMask, colorMask, colorMask); currentColorMask = colorMask; } }, setLocked: function(lock) { locked = lock; }, setClear: function(r, g, b, a2, premultipliedAlpha) { if (premultipliedAlpha === true) { r *= a2; g *= a2; b *= a2; } color.set(r, g, b, a2); if (currentColorClear.equals(color) === false) { gl.clearColor(r, g, b, a2); currentColorClear.copy(color); } }, reset: function() { locked = false; currentColorMask = null; currentColorClear.set(-1, 0, 0, 0); } }; } function DepthBuffer() { let locked = false; let currentDepthMask = null; let currentDepthFunc = null; let currentDepthClear = null; return { setTest: function(depthTest) { if (depthTest) { enable(gl.DEPTH_TEST); } else { disable(gl.DEPTH_TEST); } }, setMask: function(depthMask) { if (currentDepthMask !== depthMask && !locked) { gl.depthMask(depthMask); currentDepthMask = depthMask; } }, setFunc: function(depthFunc) { if (currentDepthFunc !== depthFunc) { switch (depthFunc) { case NeverDepth: gl.depthFunc(gl.NEVER); break; case AlwaysDepth: gl.depthFunc(gl.ALWAYS); break; case LessDepth: gl.depthFunc(gl.LESS); break; case LessEqualDepth: gl.depthFunc(gl.LEQUAL); break; case EqualDepth: gl.depthFunc(gl.EQUAL); break; case GreaterEqualDepth: gl.depthFunc(gl.GEQUAL); break; case GreaterDepth: gl.depthFunc(gl.GREATER); break; case NotEqualDepth: gl.depthFunc(gl.NOTEQUAL); break; default: gl.depthFunc(gl.LEQUAL); } currentDepthFunc = depthFunc; } }, setLocked: function(lock) { locked = lock; }, setClear: function(depth) { if (currentDepthClear !== depth) { gl.clearDepth(depth); currentDepthClear = depth; } }, reset: function() { locked = false; currentDepthMask = null; currentDepthFunc = null; currentDepthClear = null; } }; } function StencilBuffer() { let locked = false; let currentStencilMask = null; let currentStencilFunc = null; let currentStencilRef = null; let currentStencilFuncMask = null; let currentStencilFail = null; let currentStencilZFail = null; let currentStencilZPass = null; let currentStencilClear = null; return { setTest: function(stencilTest) { if (!locked) { if (stencilTest) { enable(gl.STENCIL_TEST); } else { disable(gl.STENCIL_TEST); } } }, setMask: function(stencilMask) { if (currentStencilMask !== stencilMask && !locked) { gl.stencilMask(stencilMask); currentStencilMask = stencilMask; } }, setFunc: function(stencilFunc, stencilRef, stencilMask) { if (currentStencilFunc !== stencilFunc || currentStencilRef !== stencilRef || currentStencilFuncMask !== stencilMask) { gl.stencilFunc(stencilFunc, stencilRef, stencilMask); currentStencilFunc = stencilFunc; currentStencilRef = stencilRef; currentStencilFuncMask = stencilMask; } }, setOp: function(stencilFail, stencilZFail, stencilZPass) { if (currentStencilFail !== stencilFail || currentStencilZFail !== stencilZFail || currentStencilZPass !== stencilZPass) { gl.stencilOp(stencilFail, stencilZFail, stencilZPass); currentStencilFail = stencilFail; currentStencilZFail = stencilZFail; currentStencilZPass = stencilZPass; } }, setLocked: function(lock) { locked = lock; }, setClear: function(stencil) { if (currentStencilClear !== stencil) { gl.clearStencil(stencil); currentStencilClear = stencil; } }, reset: function() { locked = false; currentStencilMask = null; currentStencilFunc = null; currentStencilRef = null; currentStencilFuncMask = null; currentStencilFail = null; currentStencilZFail = null; currentStencilZPass = null; currentStencilClear = null; } }; } const colorBuffer = new ColorBuffer(); const depthBuffer = new DepthBuffer(); const stencilBuffer = new StencilBuffer(); const uboBindings = /* @__PURE__ */ new WeakMap(); const uboProgramMap = /* @__PURE__ */ new WeakMap(); let enabledCapabilities = {}; let currentBoundFramebuffers = {}; let currentDrawbuffers = /* @__PURE__ */ new WeakMap(); let defaultDrawbuffers = []; let currentProgram = null; let currentBlendingEnabled = false; let currentBlending = null; let currentBlendEquation = null; let currentBlendSrc = null; let currentBlendDst = null; let currentBlendEquationAlpha = null; let currentBlendSrcAlpha = null; let currentBlendDstAlpha = null; let currentBlendColor = new Color(0, 0, 0); let currentBlendAlpha = 0; let currentPremultipledAlpha = false; let currentFlipSided = null; let currentCullFace = null; let currentLineWidth = null; let currentPolygonOffsetFactor = null; let currentPolygonOffsetUnits = null; const maxTextures = gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS); let lineWidthAvailable = false; let version = 0; const glVersion = gl.getParameter(gl.VERSION); if (glVersion.indexOf("WebGL") !== -1) { version = parseFloat(/^WebGL (\d)/.exec(glVersion)[1]); lineWidthAvailable = version >= 1; } else if (glVersion.indexOf("OpenGL ES") !== -1) { version = parseFloat(/^OpenGL ES (\d)/.exec(glVersion)[1]); lineWidthAvailable = version >= 2; } let currentTextureSlot = null; let currentBoundTextures = {}; const scissorParam = gl.getParameter(gl.SCISSOR_BOX); const viewportParam = gl.getParameter(gl.VIEWPORT); const currentScissor = new Vector4().fromArray(scissorParam); const currentViewport = new Vector4().fromArray(viewportParam); function createTexture(type, target, count, dimensions) { const data = new Uint8Array(4); const texture = gl.createTexture(); gl.bindTexture(type, texture); gl.texParameteri(type, gl.TEXTURE_MIN_FILTER, gl.NEAREST); gl.texParameteri(type, gl.TEXTURE_MAG_FILTER, gl.NEAREST); for (let i = 0; i < count; i++) { if (isWebGL2 && (type === gl.TEXTURE_3D || type === gl.TEXTURE_2D_ARRAY)) { gl.texImage3D(target, 0, gl.RGBA, 1, 1, dimensions, 0, gl.RGBA, gl.UNSIGNED_BYTE, data); } else { gl.texImage2D(target + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data); } } return texture; } const emptyTextures = {}; emptyTextures[gl.TEXTURE_2D] = createTexture(gl.TEXTURE_2D, gl.TEXTURE_2D, 1); emptyTextures[gl.TEXTURE_CUBE_MAP] = createTexture(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_CUBE_MAP_POSITIVE_X, 6); if (isWebGL2) { emptyTextures[gl.TEXTURE_2D_ARRAY] = createTexture(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_2D_ARRAY, 1, 1); emptyTextures[gl.TEXTURE_3D] = createTexture(gl.TEXTURE_3D, gl.TEXTURE_3D, 1, 1); } colorBuffer.setClear(0, 0, 0, 1); depthBuffer.setClear(1); stencilBuffer.setClear(0); enable(gl.DEPTH_TEST); depthBuffer.setFunc(LessEqualDepth); setFlipSided(false); setCullFace(CullFaceBack); enable(gl.CULL_FACE); setBlending(NoBlending); function enable(id) { if (enabledCapabilities[id] !== true) { gl.enable(id); enabledCapabilities[id] = true; } } function disable(id) { if (enabledCapabilities[id] !== false) { gl.disable(id); enabledCapabilities[id] = false; } } function bindFramebuffer(target, framebuffer) { if (currentBoundFramebuffers[target] !== framebuffer) { gl.bindFramebuffer(target, framebuffer); currentBoundFramebuffers[target] = framebuffer; if (isWebGL2) { if (target === gl.DRAW_FRAMEBUFFER) { currentBoundFramebuffers[gl.FRAMEBUFFER] = framebuffer; } if (target === gl.FRAMEBUFFER) { currentBoundFramebuffers[gl.DRAW_FRAMEBUFFER] = framebuffer; } } return true; } return false; } function drawBuffers(renderTarget, framebuffer) { let drawBuffers2 = defaultDrawbuffers; let needsUpdate = false; if (renderTarget) { drawBuffers2 = currentDrawbuffers.get(framebuffer); if (drawBuffers2 === void 0) { drawBuffers2 = []; currentDrawbuffers.set(framebuffer, drawBuffers2); } if (renderTarget.isWebGLMultipleRenderTargets) { const textures = renderTarget.texture; if (drawBuffers2.length !== textures.length || drawBuffers2[0] !== gl.COLOR_ATTACHMENT0) { for (let i = 0, il = textures.length; i < il; i++) { drawBuffers2[i] = gl.COLOR_ATTACHMENT0 + i; } drawBuffers2.length = textures.length; needsUpdate = true; } } else { if (drawBuffers2[0] !== gl.COLOR_ATTACHMENT0) { drawBuffers2[0] = gl.COLOR_ATTACHMENT0; needsUpdate = true; } } } else { if (drawBuffers2[0] !== gl.BACK) { drawBuffers2[0] = gl.BACK; needsUpdate = true; } } if (needsUpdate) { if (capabilities.isWebGL2) { gl.drawBuffers(drawBuffers2); } else { extensions.get("WEBGL_draw_buffers").drawBuffersWEBGL(drawBuffers2); } } } function useProgram(program) { if (currentProgram !== program) { gl.useProgram(program); currentProgram = program; return true; } return false; } const equationToGL = { [AddEquation]: gl.FUNC_ADD, [SubtractEquation]: gl.FUNC_SUBTRACT, [ReverseSubtractEquation]: gl.FUNC_REVERSE_SUBTRACT }; if (isWebGL2) { equationToGL[MinEquation] = gl.MIN; equationToGL[MaxEquation] = gl.MAX; } else { const extension = extensions.get("EXT_blend_minmax"); if (extension !== null) { equationToGL[MinEquation] = extension.MIN_EXT; equationToGL[MaxEquation] = extension.MAX_EXT; } } const factorToGL = { [ZeroFactor]: gl.ZERO, [OneFactor]: gl.ONE, [SrcColorFactor]: gl.SRC_COLOR, [SrcAlphaFactor]: gl.SRC_ALPHA, [SrcAlphaSaturateFactor]: gl.SRC_ALPHA_SATURATE, [DstColorFactor]: gl.DST_COLOR, [DstAlphaFactor]: gl.DST_ALPHA, [OneMinusSrcColorFactor]: gl.ONE_MINUS_SRC_COLOR, [OneMinusSrcAlphaFactor]: gl.ONE_MINUS_SRC_ALPHA, [OneMinusDstColorFactor]: gl.ONE_MINUS_DST_COLOR, [OneMinusDstAlphaFactor]: gl.ONE_MINUS_DST_ALPHA, [ConstantColorFactor]: gl.CONSTANT_COLOR, [OneMinusConstantColorFactor]: gl.ONE_MINUS_CONSTANT_COLOR, [ConstantAlphaFactor]: gl.CONSTANT_ALPHA, [OneMinusConstantAlphaFactor]: gl.ONE_MINUS_CONSTANT_ALPHA }; function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, blendColor, blendAlpha, premultipliedAlpha) { if (blending === NoBlending) { if (currentBlendingEnabled === true) { disable(gl.BLEND); currentBlendingEnabled = false; } return; } if (currentBlendingEnabled === false) { enable(gl.BLEND); currentBlendingEnabled = true; } if (blending !== CustomBlending) { if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) { if (currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation) { gl.blendEquation(gl.FUNC_ADD); currentBlendEquation = AddEquation; currentBlendEquationAlpha = AddEquation; } if (premultipliedAlpha) { switch (blending) { case NormalBlending: gl.blendFuncSeparate(gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA); break; case AdditiveBlending: gl.blendFunc(gl.ONE, gl.ONE); break; case SubtractiveBlending: gl.blendFuncSeparate(gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ZERO, gl.ONE); break; case MultiplyBlending: gl.blendFuncSeparate(gl.ZERO, gl.SRC_COLOR, gl.ZERO, gl.SRC_ALPHA); break; default: console.error("THREE.WebGLState: Invalid blending: ", blending); break; } } else { switch (blending) { case NormalBlending: gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA); break; case AdditiveBlending: gl.blendFunc(gl.SRC_ALPHA, gl.ONE); break; case SubtractiveBlending: gl.blendFuncSeparate(gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ZERO, gl.ONE); break; case MultiplyBlending: gl.blendFunc(gl.ZERO, gl.SRC_COLOR); break; default: console.error("THREE.WebGLState: Invalid blending: ", blending); break; } } currentBlendSrc = null; currentBlendDst = null; currentBlendSrcAlpha = null; currentBlendDstAlpha = null; currentBlendColor.set(0, 0, 0); currentBlendAlpha = 0; currentBlending = blending; currentPremultipledAlpha = premultipliedAlpha; } return; } blendEquationAlpha = blendEquationAlpha || blendEquation; blendSrcAlpha = blendSrcAlpha || blendSrc; blendDstAlpha = blendDstAlpha || blendDst; if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha) { gl.blendEquationSeparate(equationToGL[blendEquation], equationToGL[blendEquationAlpha]); currentBlendEquation = blendEquation; currentBlendEquationAlpha = blendEquationAlpha; } if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha) { gl.blendFuncSeparate(factorToGL[blendSrc], factorToGL[blendDst], factorToGL[blendSrcAlpha], factorToGL[blendDstAlpha]); currentBlendSrc = blendSrc; currentBlendDst = blendDst; currentBlendSrcAlpha = blendSrcAlpha; currentBlendDstAlpha = blendDstAlpha; } if (blendColor.equals(currentBlendColor) === false || blendAlpha !== currentBlendAlpha) { gl.blendColor(blendColor.r, blendColor.g, blendColor.b, blendAlpha); currentBlendColor.copy(blendColor); currentBlendAlpha = blendAlpha; } currentBlending = blending; currentPremultipledAlpha = false; } function setMaterial(material, frontFaceCW) { material.side === DoubleSide ? disable(gl.CULL_FACE) : enable(gl.CULL_FACE); let flipSided = material.side === BackSide; if (frontFaceCW) flipSided = !flipSided; setFlipSided(flipSided); material.blending === NormalBlending && material.transparent === false ? setBlending(NoBlending) : setBlending(material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.blendColor, material.blendAlpha, material.premultipliedAlpha); depthBuffer.setFunc(material.depthFunc); depthBuffer.setTest(material.depthTest); depthBuffer.setMask(material.depthWrite); colorBuffer.setMask(material.colorWrite); const stencilWrite = material.stencilWrite; stencilBuffer.setTest(stencilWrite); if (stencilWrite) { stencilBuffer.setMask(material.stencilWriteMask); stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask); stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass); } setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits); material.alphaToCoverage === true ? enable(gl.SAMPLE_ALPHA_TO_COVERAGE) : disable(gl.SAMPLE_ALPHA_TO_COVERAGE); } function setFlipSided(flipSided) { if (currentFlipSided !== flipSided) { if (flipSided) { gl.frontFace(gl.CW); } else { gl.frontFace(gl.CCW); } currentFlipSided = flipSided; } } function setCullFace(cullFace) { if (cullFace !== CullFaceNone) { enable(gl.CULL_FACE); if (cullFace !== currentCullFace) { if (cullFace === CullFaceBack) { gl.cullFace(gl.BACK); } else if (cullFace === CullFaceFront) { gl.cullFace(gl.FRONT); } else { gl.cullFace(gl.FRONT_AND_BACK); } } } else { disable(gl.CULL_FACE); } currentCullFace = cullFace; } function setLineWidth(width) { if (width !== currentLineWidth) { if (lineWidthAvailable) gl.lineWidth(width); currentLineWidth = width; } } function setPolygonOffset(polygonOffset, factor, units) { if (polygonOffset) { enable(gl.POLYGON_OFFSET_FILL); if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) { gl.polygonOffset(factor, units); currentPolygonOffsetFactor = factor; currentPolygonOffsetUnits = units; } } else { disable(gl.POLYGON_OFFSET_FILL); } } function setScissorTest(scissorTest) { if (scissorTest) { enable(gl.SCISSOR_TEST); } else { disable(gl.SCISSOR_TEST); } } function activeTexture(webglSlot) { if (webglSlot === void 0) webglSlot = gl.TEXTURE0 + maxTextures - 1; if (currentTextureSlot !== webglSlot) { gl.activeTexture(webglSlot); currentTextureSlot = webglSlot; } } function bindTexture(webglType, webglTexture, webglSlot) { if (webglSlot === void 0) { if (currentTextureSlot === null) { webglSlot = gl.TEXTURE0 + maxTextures - 1; } else { webglSlot = currentTextureSlot; } } let boundTexture = currentBoundTextures[webglSlot]; if (boundTexture === void 0) { boundTexture = { type: void 0, texture: void 0 }; currentBoundTextures[webglSlot] = boundTexture; } if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) { if (currentTextureSlot !== webglSlot) { gl.activeTexture(webglSlot); currentTextureSlot = webglSlot; } gl.bindTexture(webglType, webglTexture || emptyTextures[webglType]); boundTexture.type = webglType; boundTexture.texture = webglTexture; } } function unbindTexture() { const boundTexture = currentBoundTextures[currentTextureSlot]; if (boundTexture !== void 0 && boundTexture.type !== void 0) { gl.bindTexture(boundTexture.type, null); boundTexture.type = void 0; boundTexture.texture = void 0; } } function compressedTexImage2D() { try { gl.compressedTexImage2D.apply(gl, arguments); } catch (error) { console.error("THREE.WebGLState:", error); } } function compressedTexImage3D() { try { gl.compressedTexImage3D.apply(gl, arguments); } catch (error) { console.error("THREE.WebGLState:", error); } } function texSubImage2D() { try { gl.texSubImage2D.apply(gl, arguments); } catch (error) { console.error("THREE.WebGLState:", error); } } function texSubImage3D() { try { gl.texSubImage3D.apply(gl, arguments); } catch (error) { console.error("THREE.WebGLState:", error); } } function compressedTexSubImage2D() { try { gl.compressedTexSubImage2D.apply(gl, arguments); } catch (error) { console.error("THREE.WebGLState:", error); } } function compressedTexSubImage3D() { try { gl.compressedTexSubImage3D.apply(gl, arguments); } catch (error) { console.error("THREE.WebGLState:", error); } } function texStorage2D() { try { gl.texStorage2D.apply(gl, arguments); } catch (error) { console.error("THREE.WebGLState:", error); } } function texStorage3D() { try { gl.texStorage3D.apply(gl, arguments); } catch (error) { console.error("THREE.WebGLState:", error); } } function texImage2D() { try { gl.texImage2D.apply(gl, arguments); } catch (error) { console.error("THREE.WebGLState:", error); } } function texImage3D() { try { gl.texImage3D.apply(gl, arguments); } catch (error) { console.error("THREE.WebGLState:", error); } } function scissor(scissor2) { if (currentScissor.equals(scissor2) === false) { gl.scissor(scissor2.x, scissor2.y, scissor2.z, scissor2.w); currentScissor.copy(scissor2); } } function viewport(viewport2) { if (currentViewport.equals(viewport2) === false) { gl.viewport(viewport2.x, viewport2.y, viewport2.z, viewport2.w); currentViewport.copy(viewport2); } } function updateUBOMapping(uniformsGroup, program) { let mapping = uboProgramMap.get(program); if (mapping === void 0) { mapping = /* @__PURE__ */ new WeakMap(); uboProgramMap.set(program, mapping); } let blockIndex = mapping.get(uniformsGroup); if (blockIndex === void 0) { blockIndex = gl.getUniformBlockIndex(program, uniformsGroup.name); mapping.set(uniformsGroup, blockIndex); } } function uniformBlockBinding(uniformsGroup, program) { const mapping = uboProgramMap.get(program); const blockIndex = mapping.get(uniformsGroup); if (uboBindings.get(program) !== blockIndex) { gl.uniformBlockBinding(program, blockIndex, uniformsGroup.__bindingPointIndex); uboBindings.set(program, blockIndex); } } function reset() { gl.disable(gl.BLEND); gl.disable(gl.CULL_FACE); gl.disable(gl.DEPTH_TEST); gl.disable(gl.POLYGON_OFFSET_FILL); gl.disable(gl.SCISSOR_TEST); gl.disable(gl.STENCIL_TEST); gl.disable(gl.SAMPLE_ALPHA_TO_COVERAGE); gl.blendEquation(gl.FUNC_ADD); gl.blendFunc(gl.ONE, gl.ZERO); gl.blendFuncSeparate(gl.ONE, gl.ZERO, gl.ONE, gl.ZERO); gl.blendColor(0, 0, 0, 0); gl.colorMask(true, true, true, true); gl.clearColor(0, 0, 0, 0); gl.depthMask(true); gl.depthFunc(gl.LESS); gl.clearDepth(1); gl.stencilMask(4294967295); gl.stencilFunc(gl.ALWAYS, 0, 4294967295); gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP); gl.clearStencil(0); gl.cullFace(gl.BACK); gl.frontFace(gl.CCW); gl.polygonOffset(0, 0); gl.activeTexture(gl.TEXTURE0); gl.bindFramebuffer(gl.FRAMEBUFFER, null); if (isWebGL2 === true) { gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, null); gl.bindFramebuffer(gl.READ_FRAMEBUFFER, null); } gl.useProgram(null); gl.lineWidth(1); gl.scissor(0, 0, gl.canvas.width, gl.canvas.height); gl.viewport(0, 0, gl.canvas.width, gl.canvas.height); enabledCapabilities = {}; currentTextureSlot = null; currentBoundTextures = {}; currentBoundFramebuffers = {}; currentDrawbuffers = /* @__PURE__ */ new WeakMap(); defaultDrawbuffers = []; currentProgram = null; currentBlendingEnabled = false; currentBlending = null; currentBlendEquation = null; currentBlendSrc = null; currentBlendDst = null; currentBlendEquationAlpha = null; currentBlendSrcAlpha = null; currentBlendDstAlpha = null; currentBlendColor = new Color(0, 0, 0); currentBlendAlpha = 0; currentPremultipledAlpha = false; currentFlipSided = null; currentCullFace = null; currentLineWidth = null; currentPolygonOffsetFactor = null; currentPolygonOffsetUnits = null; currentScissor.set(0, 0, gl.canvas.width, gl.canvas.height); currentViewport.set(0, 0, gl.canvas.width, gl.canvas.height); colorBuffer.reset(); depthBuffer.reset(); stencilBuffer.reset(); } return { buffers: { color: colorBuffer, depth: depthBuffer, stencil: stencilBuffer }, enable, disable, bindFramebuffer, drawBuffers, useProgram, setBlending, setMaterial, setFlipSided, setCullFace, setLineWidth, setPolygonOffset, setScissorTest, activeTexture, bindTexture, unbindTexture, compressedTexImage2D, compressedTexImage3D, texImage2D, texImage3D, updateUBOMapping, uniformBlockBinding, texStorage2D, texStorage3D, texSubImage2D, texSubImage3D, compressedTexSubImage2D, compressedTexSubImage3D, scissor, viewport, reset }; } function WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info) { const isWebGL2 = capabilities.isWebGL2; const maxTextures = capabilities.maxTextures; const maxCubemapSize = capabilities.maxCubemapSize; const maxTextureSize = capabilities.maxTextureSize; const maxSamples = capabilities.maxSamples; const multisampledRTTExt = extensions.has("WEBGL_multisampled_render_to_texture") ? extensions.get("WEBGL_multisampled_render_to_texture") : null; const supportsInvalidateFramebuffer = typeof navigator === "undefined" ? false : /OculusBrowser/g.test(navigator.userAgent); const _videoTextures = /* @__PURE__ */ new WeakMap(); let _canvas3; const _sources = /* @__PURE__ */ new WeakMap(); let useOffscreenCanvas = false; try { useOffscreenCanvas = typeof OffscreenCanvas !== "undefined" && new OffscreenCanvas(1, 1).getContext("2d") !== null; } catch (err) { } function createCanvas(width, height) { return useOffscreenCanvas ? ( // eslint-disable-next-line compat/compat new OffscreenCanvas(width, height) ) : createElementNS("canvas"); } function resizeImage(image, needsPowerOfTwo, needsNewCanvas, maxSize) { let scale = 1; if (image.width > maxSize || image.height > maxSize) { scale = maxSize / Math.max(image.width, image.height); } if (scale < 1 || needsPowerOfTwo === true) { if (typeof HTMLImageElement !== "undefined" && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== "undefined" && image instanceof HTMLCanvasElement || typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap) { const floor = needsPowerOfTwo ? floorPowerOfTwo : Math.floor; const width = floor(scale * image.width); const height = floor(scale * image.height); if (_canvas3 === void 0) _canvas3 = createCanvas(width, height); const canvas = needsNewCanvas ? createCanvas(width, height) : _canvas3; canvas.width = width; canvas.height = height; const context = canvas.getContext("2d"); context.drawImage(image, 0, 0, width, height); console.warn("THREE.WebGLRenderer: Texture has been resized from (" + image.width + "x" + image.height + ") to (" + width + "x" + height + ")."); return canvas; } else { if ("data" in image) { console.warn("THREE.WebGLRenderer: Image in DataTexture is too big (" + image.width + "x" + image.height + ")."); } return image; } } return image; } function isPowerOfTwo$1(image) { return isPowerOfTwo(image.width) && isPowerOfTwo(image.height); } function textureNeedsPowerOfTwo(texture) { if (isWebGL2) return false; return texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping || texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter; } function textureNeedsGenerateMipmaps(texture, supportsMips) { return texture.generateMipmaps && supportsMips && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter; } function generateMipmap(target) { _gl.generateMipmap(target); } function getInternalFormat(internalFormatName, glFormat, glType, colorSpace, forceLinearTransfer = false) { if (isWebGL2 === false) return glFormat; if (internalFormatName !== null) { if (_gl[internalFormatName] !== void 0) return _gl[internalFormatName]; console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '" + internalFormatName + "'"); } let internalFormat = glFormat; if (glFormat === _gl.RED) { if (glType === _gl.FLOAT) internalFormat = _gl.R32F; if (glType === _gl.HALF_FLOAT) internalFormat = _gl.R16F; if (glType === _gl.UNSIGNED_BYTE) internalFormat = _gl.R8; } if (glFormat === _gl.RED_INTEGER) { if (glType === _gl.UNSIGNED_BYTE) internalFormat = _gl.R8UI; if (glType === _gl.UNSIGNED_SHORT) internalFormat = _gl.R16UI; if (glType === _gl.UNSIGNED_INT) internalFormat = _gl.R32UI; if (glType === _gl.BYTE) internalFormat = _gl.R8I; if (glType === _gl.SHORT) internalFormat = _gl.R16I; if (glType === _gl.INT) internalFormat = _gl.R32I; } if (glFormat === _gl.RG) { if (glType === _gl.FLOAT) internalFormat = _gl.RG32F; if (glType === _gl.HALF_FLOAT) internalFormat = _gl.RG16F; if (glType === _gl.UNSIGNED_BYTE) internalFormat = _gl.RG8; } if (glFormat === _gl.RGBA) { const transfer = forceLinearTransfer ? LinearTransfer : ColorManagement.getTransfer(colorSpace); if (glType === _gl.FLOAT) internalFormat = _gl.RGBA32F; if (glType === _gl.HALF_FLOAT) internalFormat = _gl.RGBA16F; if (glType === _gl.UNSIGNED_BYTE) internalFormat = transfer === SRGBTransfer ? _gl.SRGB8_ALPHA8 : _gl.RGBA8; if (glType === _gl.UNSIGNED_SHORT_4_4_4_4) internalFormat = _gl.RGBA4; if (glType === _gl.UNSIGNED_SHORT_5_5_5_1) internalFormat = _gl.RGB5_A1; } if (internalFormat === _gl.R16F || internalFormat === _gl.R32F || internalFormat === _gl.RG16F || internalFormat === _gl.RG32F || internalFormat === _gl.RGBA16F || internalFormat === _gl.RGBA32F) { extensions.get("EXT_color_buffer_float"); } return internalFormat; } function getMipLevels(texture, image, supportsMips) { if (textureNeedsGenerateMipmaps(texture, supportsMips) === true || texture.isFramebufferTexture && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter) { return Math.log2(Math.max(image.width, image.height)) + 1; } else if (texture.mipmaps !== void 0 && texture.mipmaps.length > 0) { return texture.mipmaps.length; } else if (texture.isCompressedTexture && Array.isArray(texture.image)) { return image.mipmaps.length; } else { return 1; } } function filterFallback(f) { if (f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter) { return _gl.NEAREST; } return _gl.LINEAR; } function onTextureDispose(event) { const texture = event.target; texture.removeEventListener("dispose", onTextureDispose); deallocateTexture(texture); if (texture.isVideoTexture) { _videoTextures.delete(texture); } } function onRenderTargetDispose(event) { const renderTarget = event.target; renderTarget.removeEventListener("dispose", onRenderTargetDispose); deallocateRenderTarget(renderTarget); } function deallocateTexture(texture) { const textureProperties = properties.get(texture); if (textureProperties.__webglInit === void 0) return; const source = texture.source; const webglTextures = _sources.get(source); if (webglTextures) { const webglTexture = webglTextures[textureProperties.__cacheKey]; webglTexture.usedTimes--; if (webglTexture.usedTimes === 0) { deleteTexture(texture); } if (Object.keys(webglTextures).length === 0) { _sources.delete(source); } } properties.remove(texture); } function deleteTexture(texture) { const textureProperties = properties.get(texture); _gl.deleteTexture(textureProperties.__webglTexture); const source = texture.source; const webglTextures = _sources.get(source); delete webglTextures[textureProperties.__cacheKey]; info.memory.textures--; } function deallocateRenderTarget(renderTarget) { const texture = renderTarget.texture; const renderTargetProperties = properties.get(renderTarget); const textureProperties = properties.get(texture); if (textureProperties.__webglTexture !== void 0) { _gl.deleteTexture(textureProperties.__webglTexture); info.memory.textures--; } if (renderTarget.depthTexture) { renderTarget.depthTexture.dispose(); } if (renderTarget.isWebGLCubeRenderTarget) { for (let i = 0; i < 6; i++) { if (Array.isArray(renderTargetProperties.__webglFramebuffer[i])) { for (let level = 0; level < renderTargetProperties.__webglFramebuffer[i].length; level++) _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i][level]); } else { _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]); } if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]); } } else { if (Array.isArray(renderTargetProperties.__webglFramebuffer)) { for (let level = 0; level < renderTargetProperties.__webglFramebuffer.length; level++) _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[level]); } else { _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer); } if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer); if (renderTargetProperties.__webglMultisampledFramebuffer) _gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer); if (renderTargetProperties.__webglColorRenderbuffer) { for (let i = 0; i < renderTargetProperties.__webglColorRenderbuffer.length; i++) { if (renderTargetProperties.__webglColorRenderbuffer[i]) _gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer[i]); } } if (renderTargetProperties.__webglDepthRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer); } if (renderTarget.isWebGLMultipleRenderTargets) { for (let i = 0, il = texture.length; i < il; i++) { const attachmentProperties = properties.get(texture[i]); if (attachmentProperties.__webglTexture) { _gl.deleteTexture(attachmentProperties.__webglTexture); info.memory.textures--; } properties.remove(texture[i]); } } properties.remove(texture); properties.remove(renderTarget); } let textureUnits = 0; function resetTextureUnits() { textureUnits = 0; } function allocateTextureUnit() { const textureUnit = textureUnits; if (textureUnit >= maxTextures) { console.warn("THREE.WebGLTextures: Trying to use " + textureUnit + " texture units while this GPU supports only " + maxTextures); } textureUnits += 1; return textureUnit; } function getTextureCacheKey(texture) { const array = []; array.push(texture.wrapS); array.push(texture.wrapT); array.push(texture.wrapR || 0); array.push(texture.magFilter); array.push(texture.minFilter); array.push(texture.anisotropy); array.push(texture.internalFormat); array.push(texture.format); array.push(texture.type); array.push(texture.generateMipmaps); array.push(texture.premultiplyAlpha); array.push(texture.flipY); array.push(texture.unpackAlignment); array.push(texture.colorSpace); return array.join(); } function setTexture2D(texture, slot) { const textureProperties = properties.get(texture); if (texture.isVideoTexture) updateVideoTexture(texture); if (texture.isRenderTargetTexture === false && texture.version > 0 && textureProperties.__version !== texture.version) { const image = texture.image; if (image === null) { console.warn("THREE.WebGLRenderer: Texture marked for update but no image data found."); } else if (image.complete === false) { console.warn("THREE.WebGLRenderer: Texture marked for update but image is incomplete"); } else { uploadTexture(textureProperties, texture, slot); return; } } state.bindTexture(_gl.TEXTURE_2D, textureProperties.__webglTexture, _gl.TEXTURE0 + slot); } function setTexture2DArray(texture, slot) { const textureProperties = properties.get(texture); if (texture.version > 0 && textureProperties.__version !== texture.version) { uploadTexture(textureProperties, texture, slot); return; } state.bindTexture(_gl.TEXTURE_2D_ARRAY, textureProperties.__webglTexture, _gl.TEXTURE0 + slot); } function setTexture3D(texture, slot) { const textureProperties = properties.get(texture); if (texture.version > 0 && textureProperties.__version !== texture.version) { uploadTexture(textureProperties, texture, slot); return; } state.bindTexture(_gl.TEXTURE_3D, textureProperties.__webglTexture, _gl.TEXTURE0 + slot); } function setTextureCube(texture, slot) { const textureProperties = properties.get(texture); if (texture.version > 0 && textureProperties.__version !== texture.version) { uploadCubeTexture(textureProperties, texture, slot); return; } state.bindTexture(_gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture, _gl.TEXTURE0 + slot); } const wrappingToGL = { [RepeatWrapping]: _gl.REPEAT, [ClampToEdgeWrapping]: _gl.CLAMP_TO_EDGE, [MirroredRepeatWrapping]: _gl.MIRRORED_REPEAT }; const filterToGL = { [NearestFilter]: _gl.NEAREST, [NearestMipmapNearestFilter]: _gl.NEAREST_MIPMAP_NEAREST, [NearestMipmapLinearFilter]: _gl.NEAREST_MIPMAP_LINEAR, [LinearFilter]: _gl.LINEAR, [LinearMipmapNearestFilter]: _gl.LINEAR_MIPMAP_NEAREST, [LinearMipmapLinearFilter]: _gl.LINEAR_MIPMAP_LINEAR }; const compareToGL = { [NeverCompare]: _gl.NEVER, [AlwaysCompare]: _gl.ALWAYS, [LessCompare]: _gl.LESS, [LessEqualCompare]: _gl.LEQUAL, [EqualCompare]: _gl.EQUAL, [GreaterEqualCompare]: _gl.GEQUAL, [GreaterCompare]: _gl.GREATER, [NotEqualCompare]: _gl.NOTEQUAL }; function setTextureParameters(textureType, texture, supportsMips) { if (supportsMips) { _gl.texParameteri(textureType, _gl.TEXTURE_WRAP_S, wrappingToGL[texture.wrapS]); _gl.texParameteri(textureType, _gl.TEXTURE_WRAP_T, wrappingToGL[texture.wrapT]); if (textureType === _gl.TEXTURE_3D || textureType === _gl.TEXTURE_2D_ARRAY) { _gl.texParameteri(textureType, _gl.TEXTURE_WRAP_R, wrappingToGL[texture.wrapR]); } _gl.texParameteri(textureType, _gl.TEXTURE_MAG_FILTER, filterToGL[texture.magFilter]); _gl.texParameteri(textureType, _gl.TEXTURE_MIN_FILTER, filterToGL[texture.minFilter]); } else { _gl.texParameteri(textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE); _gl.texParameteri(textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE); if (textureType === _gl.TEXTURE_3D || textureType === _gl.TEXTURE_2D_ARRAY) { _gl.texParameteri(textureType, _gl.TEXTURE_WRAP_R, _gl.CLAMP_TO_EDGE); } if (texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping) { console.warn("THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping."); } _gl.texParameteri(textureType, _gl.TEXTURE_MAG_FILTER, filterFallback(texture.magFilter)); _gl.texParameteri(textureType, _gl.TEXTURE_MIN_FILTER, filterFallback(texture.minFilter)); if (texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter) { console.warn("THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter."); } } if (texture.compareFunction) { _gl.texParameteri(textureType, _gl.TEXTURE_COMPARE_MODE, _gl.COMPARE_REF_TO_TEXTURE); _gl.texParameteri(textureType, _gl.TEXTURE_COMPARE_FUNC, compareToGL[texture.compareFunction]); } if (extensions.has("EXT_texture_filter_anisotropic") === true) { const extension = extensions.get("EXT_texture_filter_anisotropic"); if (texture.magFilter === NearestFilter) return; if (texture.minFilter !== NearestMipmapLinearFilter && texture.minFilter !== LinearMipmapLinearFilter) return; if (texture.type === FloatType && extensions.has("OES_texture_float_linear") === false) return; if (isWebGL2 === false && (texture.type === HalfFloatType && extensions.has("OES_texture_half_float_linear") === false)) return; if (texture.anisotropy > 1 || properties.get(texture).__currentAnisotropy) { _gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, capabilities.getMaxAnisotropy())); properties.get(texture).__currentAnisotropy = texture.anisotropy; } } } function initTexture(textureProperties, texture) { let forceUpload = false; if (textureProperties.__webglInit === void 0) { textureProperties.__webglInit = true; texture.addEventListener("dispose", onTextureDispose); } const source = texture.source; let webglTextures = _sources.get(source); if (webglTextures === void 0) { webglTextures = {}; _sources.set(source, webglTextures); } const textureCacheKey = getTextureCacheKey(texture); if (textureCacheKey !== textureProperties.__cacheKey) { if (webglTextures[textureCacheKey] === void 0) { webglTextures[textureCacheKey] = { texture: _gl.createTexture(), usedTimes: 0 }; info.memory.textures++; forceUpload = true; } webglTextures[textureCacheKey].usedTimes++; const webglTexture = webglTextures[textureProperties.__cacheKey]; if (webglTexture !== void 0) { webglTextures[textureProperties.__cacheKey].usedTimes--; if (webglTexture.usedTimes === 0) { deleteTexture(texture); } } textureProperties.__cacheKey = textureCacheKey; textureProperties.__webglTexture = webglTextures[textureCacheKey].texture; } return forceUpload; } function uploadTexture(textureProperties, texture, slot) { let textureType = _gl.TEXTURE_2D; if (texture.isDataArrayTexture || texture.isCompressedArrayTexture) textureType = _gl.TEXTURE_2D_ARRAY; if (texture.isData3DTexture) textureType = _gl.TEXTURE_3D; const forceUpload = initTexture(textureProperties, texture); const source = texture.source; state.bindTexture(textureType, textureProperties.__webglTexture, _gl.TEXTURE0 + slot); const sourceProperties = properties.get(source); if (source.version !== sourceProperties.__version || forceUpload === true) { state.activeTexture(_gl.TEXTURE0 + slot); const workingPrimaries = ColorManagement.getPrimaries(ColorManagement.workingColorSpace); const texturePrimaries = texture.colorSpace === NoColorSpace ? null : ColorManagement.getPrimaries(texture.colorSpace); const unpackConversion = texture.colorSpace === NoColorSpace || workingPrimaries === texturePrimaries ? _gl.NONE : _gl.BROWSER_DEFAULT_WEBGL; _gl.pixelStorei(_gl.UNPACK_FLIP_Y_WEBGL, texture.flipY); _gl.pixelStorei(_gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha); _gl.pixelStorei(_gl.UNPACK_ALIGNMENT, texture.unpackAlignment); _gl.pixelStorei(_gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, unpackConversion); const needsPowerOfTwo = textureNeedsPowerOfTwo(texture) && isPowerOfTwo$1(texture.image) === false; let image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize); image = verifyColorSpace(texture, image); const supportsMips = isPowerOfTwo$1(image) || isWebGL2, glFormat = utils.convert(texture.format, texture.colorSpace); let glType = utils.convert(texture.type), glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.colorSpace, texture.isVideoTexture); setTextureParameters(textureType, texture, supportsMips); let mipmap; const mipmaps = texture.mipmaps; const useTexStorage = isWebGL2 && texture.isVideoTexture !== true; const allocateMemory = sourceProperties.__version === void 0 || forceUpload === true; const levels = getMipLevels(texture, image, supportsMips); if (texture.isDepthTexture) { glInternalFormat = _gl.DEPTH_COMPONENT; if (isWebGL2) { if (texture.type === FloatType) { glInternalFormat = _gl.DEPTH_COMPONENT32F; } else if (texture.type === UnsignedIntType) { glInternalFormat = _gl.DEPTH_COMPONENT24; } else if (texture.type === UnsignedInt248Type) { glInternalFormat = _gl.DEPTH24_STENCIL8; } else { glInternalFormat = _gl.DEPTH_COMPONENT16; } } else { if (texture.type === FloatType) { console.error("WebGLRenderer: Floating point depth texture requires WebGL2."); } } if (texture.format === DepthFormat && glInternalFormat === _gl.DEPTH_COMPONENT) { if (texture.type !== UnsignedShortType && texture.type !== UnsignedIntType) { console.warn("THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture."); texture.type = UnsignedIntType; glType = utils.convert(texture.type); } } if (texture.format === DepthStencilFormat && glInternalFormat === _gl.DEPTH_COMPONENT) { glInternalFormat = _gl.DEPTH_STENCIL; if (texture.type !== UnsignedInt248Type) { console.warn("THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture."); texture.type = UnsignedInt248Type; glType = utils.convert(texture.type); } } if (allocateMemory) { if (useTexStorage) { state.texStorage2D(_gl.TEXTURE_2D, 1, glInternalFormat, image.width, image.height); } else { state.texImage2D(_gl.TEXTURE_2D, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null); } } } else if (texture.isDataTexture) { if (mipmaps.length > 0 && supportsMips) { if (useTexStorage && allocateMemory) { state.texStorage2D(_gl.TEXTURE_2D, levels, glInternalFormat, mipmaps[0].width, mipmaps[0].height); } for (let i = 0, il = mipmaps.length; i < il; i++) { mipmap = mipmaps[i]; if (useTexStorage) { state.texSubImage2D(_gl.TEXTURE_2D, i, 0, 0, mipmap.width, mipmap.height, glFormat, glType, mipmap.data); } else { state.texImage2D(_gl.TEXTURE_2D, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data); } } texture.generateMipmaps = false; } else { if (useTexStorage) { if (allocateMemory) { state.texStorage2D(_gl.TEXTURE_2D, levels, glInternalFormat, image.width, image.height); } state.texSubImage2D(_gl.TEXTURE_2D, 0, 0, 0, image.width, image.height, glFormat, glType, image.data); } else { state.texImage2D(_gl.TEXTURE_2D, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data); } } } else if (texture.isCompressedTexture) { if (texture.isCompressedArrayTexture) { if (useTexStorage && allocateMemory) { state.texStorage3D(_gl.TEXTURE_2D_ARRAY, levels, glInternalFormat, mipmaps[0].width, mipmaps[0].height, image.depth); } for (let i = 0, il = mipmaps.length; i < il; i++) { mipmap = mipmaps[i]; if (texture.format !== RGBAFormat) { if (glFormat !== null) { if (useTexStorage) { state.compressedTexSubImage3D(_gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, mipmap.data, 0, 0); } else { state.compressedTexImage3D(_gl.TEXTURE_2D_ARRAY, i, glInternalFormat, mipmap.width, mipmap.height, image.depth, 0, mipmap.data, 0, 0); } } else { console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"); } } else { if (useTexStorage) { state.texSubImage3D(_gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, glType, mipmap.data); } else { state.texImage3D(_gl.TEXTURE_2D_ARRAY, i, glInternalFormat, mipmap.width, mipmap.height, image.depth, 0, glFormat, glType, mipmap.data); } } } } else { if (useTexStorage && allocateMemory) { state.texStorage2D(_gl.TEXTURE_2D, levels, glInternalFormat, mipmaps[0].width, mipmaps[0].height); } for (let i = 0, il = mipmaps.length; i < il; i++) { mipmap = mipmaps[i]; if (texture.format !== RGBAFormat) { if (glFormat !== null) { if (useTexStorage) { state.compressedTexSubImage2D(_gl.TEXTURE_2D, i, 0, 0, mipmap.width, mipmap.height, glFormat, mipmap.data); } else { state.compressedTexImage2D(_gl.TEXTURE_2D, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data); } } else { console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"); } } else { if (useTexStorage) { state.texSubImage2D(_gl.TEXTURE_2D, i, 0, 0, mipmap.width, mipmap.height, glFormat, glType, mipmap.data); } else { state.texImage2D(_gl.TEXTURE_2D, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data); } } } } } else if (texture.isDataArrayTexture) { if (useTexStorage) { if (allocateMemory) { state.texStorage3D(_gl.TEXTURE_2D_ARRAY, levels, glInternalFormat, image.width, image.height, image.depth); } state.texSubImage3D(_gl.TEXTURE_2D_ARRAY, 0, 0, 0, 0, image.width, image.height, image.depth, glFormat, glType, image.data); } else { state.texImage3D(_gl.TEXTURE_2D_ARRAY, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data); } } else if (texture.isData3DTexture) { if (useTexStorage) { if (allocateMemory) { state.texStorage3D(_gl.TEXTURE_3D, levels, glInternalFormat, image.width, image.height, image.depth); } state.texSubImage3D(_gl.TEXTURE_3D, 0, 0, 0, 0, image.width, image.height, image.depth, glFormat, glType, image.data); } else { state.texImage3D(_gl.TEXTURE_3D, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data); } } else if (texture.isFramebufferTexture) { if (allocateMemory) { if (useTexStorage) { state.texStorage2D(_gl.TEXTURE_2D, levels, glInternalFormat, image.width, image.height); } else { let width = image.width, height = image.height; for (let i = 0; i < levels; i++) { state.texImage2D(_gl.TEXTURE_2D, i, glInternalFormat, width, height, 0, glFormat, glType, null); width >>= 1; height >>= 1; } } } } else { if (mipmaps.length > 0 && supportsMips) { if (useTexStorage && allocateMemory) { state.texStorage2D(_gl.TEXTURE_2D, levels, glInternalFormat, mipmaps[0].width, mipmaps[0].height); } for (let i = 0, il = mipmaps.length; i < il; i++) { mipmap = mipmaps[i]; if (useTexStorage) { state.texSubImage2D(_gl.TEXTURE_2D, i, 0, 0, glFormat, glType, mipmap); } else { state.texImage2D(_gl.TEXTURE_2D, i, glInternalFormat, glFormat, glType, mipmap); } } texture.generateMipmaps = false; } else { if (useTexStorage) { if (allocateMemory) { state.texStorage2D(_gl.TEXTURE_2D, levels, glInternalFormat, image.width, image.height); } state.texSubImage2D(_gl.TEXTURE_2D, 0, 0, 0, glFormat, glType, image); } else { state.texImage2D(_gl.TEXTURE_2D, 0, glInternalFormat, glFormat, glType, image); } } } if (textureNeedsGenerateMipmaps(texture, supportsMips)) { generateMipmap(textureType); } sourceProperties.__version = source.version; if (texture.onUpdate) texture.onUpdate(texture); } textureProperties.__version = texture.version; } function uploadCubeTexture(textureProperties, texture, slot) { if (texture.image.length !== 6) return; const forceUpload = initTexture(textureProperties, texture); const source = texture.source; state.bindTexture(_gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture, _gl.TEXTURE0 + slot); const sourceProperties = properties.get(source); if (source.version !== sourceProperties.__version || forceUpload === true) { state.activeTexture(_gl.TEXTURE0 + slot); const workingPrimaries = ColorManagement.getPrimaries(ColorManagement.workingColorSpace); const texturePrimaries = texture.colorSpace === NoColorSpace ? null : ColorManagement.getPrimaries(texture.colorSpace); const unpackConversion = texture.colorSpace === NoColorSpace || workingPrimaries === texturePrimaries ? _gl.NONE : _gl.BROWSER_DEFAULT_WEBGL; _gl.pixelStorei(_gl.UNPACK_FLIP_Y_WEBGL, texture.flipY); _gl.pixelStorei(_gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha); _gl.pixelStorei(_gl.UNPACK_ALIGNMENT, texture.unpackAlignment); _gl.pixelStorei(_gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, unpackConversion); const isCompressed = texture.isCompressedTexture || texture.image[0].isCompressedTexture; const isDataTexture = texture.image[0] && texture.image[0].isDataTexture; const cubeImage = []; for (let i = 0; i < 6; i++) { if (!isCompressed && !isDataTexture) { cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize); } else { cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i]; } cubeImage[i] = verifyColorSpace(texture, cubeImage[i]); } const image = cubeImage[0], supportsMips = isPowerOfTwo$1(image) || isWebGL2, glFormat = utils.convert(texture.format, texture.colorSpace), glType = utils.convert(texture.type), glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.colorSpace); const useTexStorage = isWebGL2 && texture.isVideoTexture !== true; const allocateMemory = sourceProperties.__version === void 0 || forceUpload === true; let levels = getMipLevels(texture, image, supportsMips); setTextureParameters(_gl.TEXTURE_CUBE_MAP, texture, supportsMips); let mipmaps; if (isCompressed) { if (useTexStorage && allocateMemory) { state.texStorage2D(_gl.TEXTURE_CUBE_MAP, levels, glInternalFormat, image.width, image.height); } for (let i = 0; i < 6; i++) { mipmaps = cubeImage[i].mipmaps; for (let j = 0; j < mipmaps.length; j++) { const mipmap = mipmaps[j]; if (texture.format !== RGBAFormat) { if (glFormat !== null) { if (useTexStorage) { state.compressedTexSubImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, 0, 0, mipmap.width, mipmap.height, glFormat, mipmap.data); } else { state.compressedTexImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data); } } else { console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()"); } } else { if (useTexStorage) { state.texSubImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, 0, 0, mipmap.width, mipmap.height, glFormat, glType, mipmap.data); } else { state.texImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data); } } } } } else { mipmaps = texture.mipmaps; if (useTexStorage && allocateMemory) { if (mipmaps.length > 0) levels++; state.texStorage2D(_gl.TEXTURE_CUBE_MAP, levels, glInternalFormat, cubeImage[0].width, cubeImage[0].height); } for (let i = 0; i < 6; i++) { if (isDataTexture) { if (useTexStorage) { state.texSubImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 0, 0, cubeImage[i].width, cubeImage[i].height, glFormat, glType, cubeImage[i].data); } else { state.texImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glInternalFormat, cubeImage[i].width, cubeImage[i].height, 0, glFormat, glType, cubeImage[i].data); } for (let j = 0; j < mipmaps.length; j++) { const mipmap = mipmaps[j]; const mipmapImage = mipmap.image[i].image; if (useTexStorage) { state.texSubImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, 0, 0, mipmapImage.width, mipmapImage.height, glFormat, glType, mipmapImage.data); } else { state.texImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data); } } } else { if (useTexStorage) { state.texSubImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 0, 0, glFormat, glType, cubeImage[i]); } else { state.texImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glInternalFormat, glFormat, glType, cubeImage[i]); } for (let j = 0; j < mipmaps.length; j++) { const mipmap = mipmaps[j]; if (useTexStorage) { state.texSubImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, 0, 0, glFormat, glType, mipmap.image[i]); } else { state.texImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, glInternalFormat, glFormat, glType, mipmap.image[i]); } } } } } if (textureNeedsGenerateMipmaps(texture, supportsMips)) { generateMipmap(_gl.TEXTURE_CUBE_MAP); } sourceProperties.__version = source.version; if (texture.onUpdate) texture.onUpdate(texture); } textureProperties.__version = texture.version; } function setupFrameBufferTexture(framebuffer, renderTarget, texture, attachment, textureTarget, level) { const glFormat = utils.convert(texture.format, texture.colorSpace); const glType = utils.convert(texture.type); const glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.colorSpace); const renderTargetProperties = properties.get(renderTarget); if (!renderTargetProperties.__hasExternalTextures) { const width = Math.max(1, renderTarget.width >> level); const height = Math.max(1, renderTarget.height >> level); if (textureTarget === _gl.TEXTURE_3D || textureTarget === _gl.TEXTURE_2D_ARRAY) { state.texImage3D(textureTarget, level, glInternalFormat, width, height, renderTarget.depth, 0, glFormat, glType, null); } else { state.texImage2D(textureTarget, level, glInternalFormat, width, height, 0, glFormat, glType, null); } } state.bindFramebuffer(_gl.FRAMEBUFFER, framebuffer); if (useMultisampledRTT(renderTarget)) { multisampledRTTExt.framebufferTexture2DMultisampleEXT(_gl.FRAMEBUFFER, attachment, textureTarget, properties.get(texture).__webglTexture, 0, getRenderTargetSamples(renderTarget)); } else if (textureTarget === _gl.TEXTURE_2D || textureTarget >= _gl.TEXTURE_CUBE_MAP_POSITIVE_X && textureTarget <= _gl.TEXTURE_CUBE_MAP_NEGATIVE_Z) { _gl.framebufferTexture2D(_gl.FRAMEBUFFER, attachment, textureTarget, properties.get(texture).__webglTexture, level); } state.bindFramebuffer(_gl.FRAMEBUFFER, null); } function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) { _gl.bindRenderbuffer(_gl.RENDERBUFFER, renderbuffer); if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) { let glInternalFormat = isWebGL2 === true ? _gl.DEPTH_COMPONENT24 : _gl.DEPTH_COMPONENT16; if (isMultisample || useMultisampledRTT(renderTarget)) { const depthTexture = renderTarget.depthTexture; if (depthTexture && depthTexture.isDepthTexture) { if (depthTexture.type === FloatType) { glInternalFormat = _gl.DEPTH_COMPONENT32F; } else if (depthTexture.type === UnsignedIntType) { glInternalFormat = _gl.DEPTH_COMPONENT24; } } const samples = getRenderTargetSamples(renderTarget); if (useMultisampledRTT(renderTarget)) { multisampledRTTExt.renderbufferStorageMultisampleEXT(_gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height); } else { _gl.renderbufferStorageMultisample(_gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height); } } else { _gl.renderbufferStorage(_gl.RENDERBUFFER, glInternalFormat, renderTarget.width, renderTarget.height); } _gl.framebufferRenderbuffer(_gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer); } else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) { const samples = getRenderTargetSamples(renderTarget); if (isMultisample && useMultisampledRTT(renderTarget) === false) { _gl.renderbufferStorageMultisample(_gl.RENDERBUFFER, samples, _gl.DEPTH24_STENCIL8, renderTarget.width, renderTarget.height); } else if (useMultisampledRTT(renderTarget)) { multisampledRTTExt.renderbufferStorageMultisampleEXT(_gl.RENDERBUFFER, samples, _gl.DEPTH24_STENCIL8, renderTarget.width, renderTarget.height); } else { _gl.renderbufferStorage(_gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height); } _gl.framebufferRenderbuffer(_gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer); } else { const textures = renderTarget.isWebGLMultipleRenderTargets === true ? renderTarget.texture : [renderTarget.texture]; for (let i = 0; i < textures.length; i++) { const texture = textures[i]; const glFormat = utils.convert(texture.format, texture.colorSpace); const glType = utils.convert(texture.type); const glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.colorSpace); const samples = getRenderTargetSamples(renderTarget); if (isMultisample && useMultisampledRTT(renderTarget) === false) { _gl.renderbufferStorageMultisample(_gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height); } else if (useMultisampledRTT(renderTarget)) { multisampledRTTExt.renderbufferStorageMultisampleEXT(_gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height); } else { _gl.renderbufferStorage(_gl.RENDERBUFFER, glInternalFormat, renderTarget.width, renderTarget.height); } } } _gl.bindRenderbuffer(_gl.RENDERBUFFER, null); } function setupDepthTexture(framebuffer, renderTarget) { const isCube = renderTarget && renderTarget.isWebGLCubeRenderTarget; if (isCube) throw new Error("Depth Texture with cube render targets is not supported"); state.bindFramebuffer(_gl.FRAMEBUFFER, framebuffer); if (!(renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture)) { throw new Error("renderTarget.depthTexture must be an instance of THREE.DepthTexture"); } if (!properties.get(renderTarget.depthTexture).__webglTexture || renderTarget.depthTexture.image.width !== renderTarget.width || renderTarget.depthTexture.image.height !== renderTarget.height) { renderTarget.depthTexture.image.width = renderTarget.width; renderTarget.depthTexture.image.height = renderTarget.height; renderTarget.depthTexture.needsUpdate = true; } setTexture2D(renderTarget.depthTexture, 0); const webglDepthTexture = properties.get(renderTarget.depthTexture).__webglTexture; const samples = getRenderTargetSamples(renderTarget); if (renderTarget.depthTexture.format === DepthFormat) { if (useMultisampledRTT(renderTarget)) { multisampledRTTExt.framebufferTexture2DMultisampleEXT(_gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0, samples); } else { _gl.framebufferTexture2D(_gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0); } } else if (renderTarget.depthTexture.format === DepthStencilFormat) { if (useMultisampledRTT(renderTarget)) { multisampledRTTExt.framebufferTexture2DMultisampleEXT(_gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0, samples); } else { _gl.framebufferTexture2D(_gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0); } } else { throw new Error("Unknown depthTexture format"); } } function setupDepthRenderbuffer(renderTarget) { const renderTargetProperties = properties.get(renderTarget); const isCube = renderTarget.isWebGLCubeRenderTarget === true; if (renderTarget.depthTexture && !renderTargetProperties.__autoAllocateDepthBuffer) { if (isCube) throw new Error("target.depthTexture not supported in Cube render targets"); setupDepthTexture(renderTargetProperties.__webglFramebuffer, renderTarget); } else { if (isCube) { renderTargetProperties.__webglDepthbuffer = []; for (let i = 0; i < 6; i++) { state.bindFramebuffer(_gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[i]); renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer(); setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false); } } else { state.bindFramebuffer(_gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer); renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer(); setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false); } } state.bindFramebuffer(_gl.FRAMEBUFFER, null); } function rebindTextures(renderTarget, colorTexture, depthTexture) { const renderTargetProperties = properties.get(renderTarget); if (colorTexture !== void 0) { setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, renderTarget.texture, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, 0); } if (depthTexture !== void 0) { setupDepthRenderbuffer(renderTarget); } } function setupRenderTarget(renderTarget) { const texture = renderTarget.texture; const renderTargetProperties = properties.get(renderTarget); const textureProperties = properties.get(texture); renderTarget.addEventListener("dispose", onRenderTargetDispose); if (renderTarget.isWebGLMultipleRenderTargets !== true) { if (textureProperties.__webglTexture === void 0) { textureProperties.__webglTexture = _gl.createTexture(); } textureProperties.__version = texture.version; info.memory.textures++; } const isCube = renderTarget.isWebGLCubeRenderTarget === true; const isMultipleRenderTargets = renderTarget.isWebGLMultipleRenderTargets === true; const supportsMips = isPowerOfTwo$1(renderTarget) || isWebGL2; if (isCube) { renderTargetProperties.__webglFramebuffer = []; for (let i = 0; i < 6; i++) { if (isWebGL2 && texture.mipmaps && texture.mipmaps.length > 0) { renderTargetProperties.__webglFramebuffer[i] = []; for (let level = 0; level < texture.mipmaps.length; level++) { renderTargetProperties.__webglFramebuffer[i][level] = _gl.createFramebuffer(); } } else { renderTargetProperties.__webglFramebuffer[i] = _gl.createFramebuffer(); } } } else { if (isWebGL2 && texture.mipmaps && texture.mipmaps.length > 0) { renderTargetProperties.__webglFramebuffer = []; for (let level = 0; level < texture.mipmaps.length; level++) { renderTargetProperties.__webglFramebuffer[level] = _gl.createFramebuffer(); } } else { renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer(); } if (isMultipleRenderTargets) { if (capabilities.drawBuffers) { const textures = renderTarget.texture; for (let i = 0, il = textures.length; i < il; i++) { const attachmentProperties = properties.get(textures[i]); if (attachmentProperties.__webglTexture === void 0) { attachmentProperties.__webglTexture = _gl.createTexture(); info.memory.textures++; } } } else { console.warn("THREE.WebGLRenderer: WebGLMultipleRenderTargets can only be used with WebGL2 or WEBGL_draw_buffers extension."); } } if (isWebGL2 && renderTarget.samples > 0 && useMultisampledRTT(renderTarget) === false) { const textures = isMultipleRenderTargets ? texture : [texture]; renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer(); renderTargetProperties.__webglColorRenderbuffer = []; state.bindFramebuffer(_gl.FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer); for (let i = 0; i < textures.length; i++) { const texture2 = textures[i]; renderTargetProperties.__webglColorRenderbuffer[i] = _gl.createRenderbuffer(); _gl.bindRenderbuffer(_gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer[i]); const glFormat = utils.convert(texture2.format, texture2.colorSpace); const glType = utils.convert(texture2.type); const glInternalFormat = getInternalFormat(texture2.internalFormat, glFormat, glType, texture2.colorSpace, renderTarget.isXRRenderTarget === true); const samples = getRenderTargetSamples(renderTarget); _gl.renderbufferStorageMultisample(_gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height); _gl.framebufferRenderbuffer(_gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer[i]); } _gl.bindRenderbuffer(_gl.RENDERBUFFER, null); if (renderTarget.depthBuffer) { renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer(); setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true); } state.bindFramebuffer(_gl.FRAMEBUFFER, null); } } if (isCube) { state.bindTexture(_gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture); setTextureParameters(_gl.TEXTURE_CUBE_MAP, texture, supportsMips); for (let i = 0; i < 6; i++) { if (isWebGL2 && texture.mipmaps && texture.mipmaps.length > 0) { for (let level = 0; level < texture.mipmaps.length; level++) { setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[i][level], renderTarget, texture, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, level); } } else { setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[i], renderTarget, texture, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0); } } if (textureNeedsGenerateMipmaps(texture, supportsMips)) { generateMipmap(_gl.TEXTURE_CUBE_MAP); } state.unbindTexture(); } else if (isMultipleRenderTargets) { const textures = renderTarget.texture; for (let i = 0, il = textures.length; i < il; i++) { const attachment = textures[i]; const attachmentProperties = properties.get(attachment); state.bindTexture(_gl.TEXTURE_2D, attachmentProperties.__webglTexture); setTextureParameters(_gl.TEXTURE_2D, attachment, supportsMips); setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, attachment, _gl.COLOR_ATTACHMENT0 + i, _gl.TEXTURE_2D, 0); if (textureNeedsGenerateMipmaps(attachment, supportsMips)) { generateMipmap(_gl.TEXTURE_2D); } } state.unbindTexture(); } else { let glTextureType = _gl.TEXTURE_2D; if (renderTarget.isWebGL3DRenderTarget || renderTarget.isWebGLArrayRenderTarget) { if (isWebGL2) { glTextureType = renderTarget.isWebGL3DRenderTarget ? _gl.TEXTURE_3D : _gl.TEXTURE_2D_ARRAY; } else { console.error("THREE.WebGLTextures: THREE.Data3DTexture and THREE.DataArrayTexture only supported with WebGL2."); } } state.bindTexture(glTextureType, textureProperties.__webglTexture); setTextureParameters(glTextureType, texture, supportsMips); if (isWebGL2 && texture.mipmaps && texture.mipmaps.length > 0) { for (let level = 0; level < texture.mipmaps.length; level++) { setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[level], renderTarget, texture, _gl.COLOR_ATTACHMENT0, glTextureType, level); } } else { setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, texture, _gl.COLOR_ATTACHMENT0, glTextureType, 0); } if (textureNeedsGenerateMipmaps(texture, supportsMips)) { generateMipmap(glTextureType); } state.unbindTexture(); } if (renderTarget.depthBuffer) { setupDepthRenderbuffer(renderTarget); } } function updateRenderTargetMipmap(renderTarget) { const supportsMips = isPowerOfTwo$1(renderTarget) || isWebGL2; const textures = renderTarget.isWebGLMultipleRenderTargets === true ? renderTarget.texture : [renderTarget.texture]; for (let i = 0, il = textures.length; i < il; i++) { const texture = textures[i]; if (textureNeedsGenerateMipmaps(texture, supportsMips)) { const target = renderTarget.isWebGLCubeRenderTarget ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D; const webglTexture = properties.get(texture).__webglTexture; state.bindTexture(target, webglTexture); generateMipmap(target); state.unbindTexture(); } } } function updateMultisampleRenderTarget(renderTarget) { if (isWebGL2 && renderTarget.samples > 0 && useMultisampledRTT(renderTarget) === false) { const textures = renderTarget.isWebGLMultipleRenderTargets ? renderTarget.texture : [renderTarget.texture]; const width = renderTarget.width; const height = renderTarget.height; let mask = _gl.COLOR_BUFFER_BIT; const invalidationArray = []; const depthStyle = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT; const renderTargetProperties = properties.get(renderTarget); const isMultipleRenderTargets = renderTarget.isWebGLMultipleRenderTargets === true; if (isMultipleRenderTargets) { for (let i = 0; i < textures.length; i++) { state.bindFramebuffer(_gl.FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer); _gl.framebufferRenderbuffer(_gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.RENDERBUFFER, null); state.bindFramebuffer(_gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer); _gl.framebufferTexture2D(_gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.TEXTURE_2D, null, 0); } } state.bindFramebuffer(_gl.READ_FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer); state.bindFramebuffer(_gl.DRAW_FRAMEBUFFER, renderTargetProperties.__webglFramebuffer); for (let i = 0; i < textures.length; i++) { invalidationArray.push(_gl.COLOR_ATTACHMENT0 + i); if (renderTarget.depthBuffer) { invalidationArray.push(depthStyle); } const ignoreDepthValues = renderTargetProperties.__ignoreDepthValues !== void 0 ? renderTargetProperties.__ignoreDepthValues : false; if (ignoreDepthValues === false) { if (renderTarget.depthBuffer) mask |= _gl.DEPTH_BUFFER_BIT; if (renderTarget.stencilBuffer) mask |= _gl.STENCIL_BUFFER_BIT; } if (isMultipleRenderTargets) { _gl.framebufferRenderbuffer(_gl.READ_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer[i]); } if (ignoreDepthValues === true) { _gl.invalidateFramebuffer(_gl.READ_FRAMEBUFFER, [depthStyle]); _gl.invalidateFramebuffer(_gl.DRAW_FRAMEBUFFER, [depthStyle]); } if (isMultipleRenderTargets) { const webglTexture = properties.get(textures[i]).__webglTexture; _gl.framebufferTexture2D(_gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, webglTexture, 0); } _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, _gl.NEAREST); if (supportsInvalidateFramebuffer) { _gl.invalidateFramebuffer(_gl.READ_FRAMEBUFFER, invalidationArray); } } state.bindFramebuffer(_gl.READ_FRAMEBUFFER, null); state.bindFramebuffer(_gl.DRAW_FRAMEBUFFER, null); if (isMultipleRenderTargets) { for (let i = 0; i < textures.length; i++) { state.bindFramebuffer(_gl.FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer); _gl.framebufferRenderbuffer(_gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer[i]); const webglTexture = properties.get(textures[i]).__webglTexture; state.bindFramebuffer(_gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer); _gl.framebufferTexture2D(_gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.TEXTURE_2D, webglTexture, 0); } } state.bindFramebuffer(_gl.DRAW_FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer); } } function getRenderTargetSamples(renderTarget) { return Math.min(maxSamples, renderTarget.samples); } function useMultisampledRTT(renderTarget) { const renderTargetProperties = properties.get(renderTarget); return isWebGL2 && renderTarget.samples > 0 && extensions.has("WEBGL_multisampled_render_to_texture") === true && renderTargetProperties.__useRenderToTexture !== false; } function updateVideoTexture(texture) { const frame2 = info.render.frame; if (_videoTextures.get(texture) !== frame2) { _videoTextures.set(texture, frame2); texture.update(); } } function verifyColorSpace(texture, image) { const colorSpace = texture.colorSpace; const format2 = texture.format; const type = texture.type; if (texture.isCompressedTexture === true || texture.isVideoTexture === true || texture.format === _SRGBAFormat) return image; if (colorSpace !== LinearSRGBColorSpace && colorSpace !== NoColorSpace) { if (ColorManagement.getTransfer(colorSpace) === SRGBTransfer) { if (isWebGL2 === false) { if (extensions.has("EXT_sRGB") === true && format2 === RGBAFormat) { texture.format = _SRGBAFormat; texture.minFilter = LinearFilter; texture.generateMipmaps = false; } else { image = ImageUtils.sRGBToLinear(image); } } else { if (format2 !== RGBAFormat || type !== UnsignedByteType) { console.warn("THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."); } } } else { console.error("THREE.WebGLTextures: Unsupported texture color space:", colorSpace); } } return image; } this.allocateTextureUnit = allocateTextureUnit; this.resetTextureUnits = resetTextureUnits; this.setTexture2D = setTexture2D; this.setTexture2DArray = setTexture2DArray; this.setTexture3D = setTexture3D; this.setTextureCube = setTextureCube; this.rebindTextures = rebindTextures; this.setupRenderTarget = setupRenderTarget; this.updateRenderTargetMipmap = updateRenderTargetMipmap; this.updateMultisampleRenderTarget = updateMultisampleRenderTarget; this.setupDepthRenderbuffer = setupDepthRenderbuffer; this.setupFrameBufferTexture = setupFrameBufferTexture; this.useMultisampledRTT = useMultisampledRTT; } function WebGLUtils(gl, extensions, capabilities) { const isWebGL2 = capabilities.isWebGL2; function convert(p, colorSpace = NoColorSpace) { let extension; const transfer = ColorManagement.getTransfer(colorSpace); if (p === UnsignedByteType) return gl.UNSIGNED_BYTE; if (p === UnsignedShort4444Type) return gl.UNSIGNED_SHORT_4_4_4_4; if (p === UnsignedShort5551Type) return gl.UNSIGNED_SHORT_5_5_5_1; if (p === ByteType) return gl.BYTE; if (p === ShortType) return gl.SHORT; if (p === UnsignedShortType) return gl.UNSIGNED_SHORT; if (p === IntType) return gl.INT; if (p === UnsignedIntType) return gl.UNSIGNED_INT; if (p === FloatType) return gl.FLOAT; if (p === HalfFloatType) { if (isWebGL2) return gl.HALF_FLOAT; extension = extensions.get("OES_texture_half_float"); if (extension !== null) { return extension.HALF_FLOAT_OES; } else { return null; } } if (p === AlphaFormat) return gl.ALPHA; if (p === RGBAFormat) return gl.RGBA; if (p === LuminanceFormat) return gl.LUMINANCE; if (p === LuminanceAlphaFormat) return gl.LUMINANCE_ALPHA; if (p === DepthFormat) return gl.DEPTH_COMPONENT; if (p === DepthStencilFormat) return gl.DEPTH_STENCIL; if (p === _SRGBAFormat) { extension = extensions.get("EXT_sRGB"); if (extension !== null) { return extension.SRGB_ALPHA_EXT; } else { return null; } } if (p === RedFormat) return gl.RED; if (p === RedIntegerFormat) return gl.RED_INTEGER; if (p === RGFormat) return gl.RG; if (p === RGIntegerFormat) return gl.RG_INTEGER; if (p === RGBAIntegerFormat) return gl.RGBA_INTEGER; if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) { if (transfer === SRGBTransfer) { extension = extensions.get("WEBGL_compressed_texture_s3tc_srgb"); if (extension !== null) { if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_SRGB_S3TC_DXT1_EXT; if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT; if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT; if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT; } else { return null; } } else { extension = extensions.get("WEBGL_compressed_texture_s3tc"); if (extension !== null) { if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT; if (p === RGBA_S3TC_DXT1_Format) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT; if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT; if (p === RGBA_S3TC_DXT5_Format) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT; } else { return null; } } } if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format || p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) { extension = extensions.get("WEBGL_compressed_texture_pvrtc"); if (extension !== null) { if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG; if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG; if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; } else { return null; } } if (p === RGB_ETC1_Format) { extension = extensions.get("WEBGL_compressed_texture_etc1"); if (extension !== null) { return extension.COMPRESSED_RGB_ETC1_WEBGL; } else { return null; } } if (p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format) { extension = extensions.get("WEBGL_compressed_texture_etc"); if (extension !== null) { if (p === RGB_ETC2_Format) return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ETC2 : extension.COMPRESSED_RGB8_ETC2; if (p === RGBA_ETC2_EAC_Format) return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC : extension.COMPRESSED_RGBA8_ETC2_EAC; } else { return null; } } if (p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format || p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format || p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format || p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format || p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format) { extension = extensions.get("WEBGL_compressed_texture_astc"); if (extension !== null) { if (p === RGBA_ASTC_4x4_Format) return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR : extension.COMPRESSED_RGBA_ASTC_4x4_KHR; if (p === RGBA_ASTC_5x4_Format) return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR : extension.COMPRESSED_RGBA_ASTC_5x4_KHR; if (p === RGBA_ASTC_5x5_Format) return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR : extension.COMPRESSED_RGBA_ASTC_5x5_KHR; if (p === RGBA_ASTC_6x5_Format) return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR : extension.COMPRESSED_RGBA_ASTC_6x5_KHR; if (p === RGBA_ASTC_6x6_Format) return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR : extension.COMPRESSED_RGBA_ASTC_6x6_KHR; if (p === RGBA_ASTC_8x5_Format) return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR : extension.COMPRESSED_RGBA_ASTC_8x5_KHR; if (p === RGBA_ASTC_8x6_Format) return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR : extension.COMPRESSED_RGBA_ASTC_8x6_KHR; if (p === RGBA_ASTC_8x8_Format) return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR : extension.COMPRESSED_RGBA_ASTC_8x8_KHR; if (p === RGBA_ASTC_10x5_Format) return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR : extension.COMPRESSED_RGBA_ASTC_10x5_KHR; if (p === RGBA_ASTC_10x6_Format) return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR : extension.COMPRESSED_RGBA_ASTC_10x6_KHR; if (p === RGBA_ASTC_10x8_Format) return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR : extension.COMPRESSED_RGBA_ASTC_10x8_KHR; if (p === RGBA_ASTC_10x10_Format) return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR : extension.COMPRESSED_RGBA_ASTC_10x10_KHR; if (p === RGBA_ASTC_12x10_Format) return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR : extension.COMPRESSED_RGBA_ASTC_12x10_KHR; if (p === RGBA_ASTC_12x12_Format) return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR : extension.COMPRESSED_RGBA_ASTC_12x12_KHR; } else { return null; } } if (p === RGBA_BPTC_Format || p === RGB_BPTC_SIGNED_Format || p === RGB_BPTC_UNSIGNED_Format) { extension = extensions.get("EXT_texture_compression_bptc"); if (extension !== null) { if (p === RGBA_BPTC_Format) return transfer === SRGBTransfer ? extension.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT : extension.COMPRESSED_RGBA_BPTC_UNORM_EXT; if (p === RGB_BPTC_SIGNED_Format) return extension.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT; if (p === RGB_BPTC_UNSIGNED_Format) return extension.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT; } else { return null; } } if (p === RED_RGTC1_Format || p === SIGNED_RED_RGTC1_Format || p === RED_GREEN_RGTC2_Format || p === SIGNED_RED_GREEN_RGTC2_Format) { extension = extensions.get("EXT_texture_compression_rgtc"); if (extension !== null) { if (p === RGBA_BPTC_Format) return extension.COMPRESSED_RED_RGTC1_EXT; if (p === SIGNED_RED_RGTC1_Format) return extension.COMPRESSED_SIGNED_RED_RGTC1_EXT; if (p === RED_GREEN_RGTC2_Format) return extension.COMPRESSED_RED_GREEN_RGTC2_EXT; if (p === SIGNED_RED_GREEN_RGTC2_Format) return extension.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT; } else { return null; } } if (p === UnsignedInt248Type) { if (isWebGL2) return gl.UNSIGNED_INT_24_8; extension = extensions.get("WEBGL_depth_texture"); if (extension !== null) { return extension.UNSIGNED_INT_24_8_WEBGL; } else { return null; } } return gl[p] !== void 0 ? gl[p] : null; } return { convert }; } var ArrayCamera = class extends PerspectiveCamera { constructor(array = []) { super(); this.isArrayCamera = true; this.cameras = array; } }; var Group = class extends Object3D { constructor() { super(); this.isGroup = true; this.type = "Group"; } }; var _moveEvent = { type: "move" }; var WebXRController = class { constructor() { this._targetRay = null; this._grip = null; this._hand = null; } getHandSpace() { if (this._hand === null) { this._hand = new Group(); this._hand.matrixAutoUpdate = false; this._hand.visible = false; this._hand.joints = {}; this._hand.inputState = { pinching: false }; } return this._hand; } getTargetRaySpace() { if (this._targetRay === null) { this._targetRay = new Group(); this._targetRay.matrixAutoUpdate = false; this._targetRay.visible = false; this._targetRay.hasLinearVelocity = false; this._targetRay.linearVelocity = new Vector3(); this._targetRay.hasAngularVelocity = false; this._targetRay.angularVelocity = new Vector3(); } return this._targetRay; } getGripSpace() { if (this._grip === null) { this._grip = new Group(); this._grip.matrixAutoUpdate = false; this._grip.visible = false; this._grip.hasLinearVelocity = false; this._grip.linearVelocity = new Vector3(); this._grip.hasAngularVelocity = false; this._grip.angularVelocity = new Vector3(); } return this._grip; } dispatchEvent(event) { if (this._targetRay !== null) { this._targetRay.dispatchEvent(event); } if (this._grip !== null) { this._grip.dispatchEvent(event); } if (this._hand !== null) { this._hand.dispatchEvent(event); } return this; } connect(inputSource) { if (inputSource && inputSource.hand) { const hand = this._hand; if (hand) { for (const inputjoint of inputSource.hand.values()) { this._getHandJoint(hand, inputjoint); } } } this.dispatchEvent({ type: "connected", data: inputSource }); return this; } disconnect(inputSource) { this.dispatchEvent({ type: "disconnected", data: inputSource }); if (this._targetRay !== null) { this._targetRay.visible = false; } if (this._grip !== null) { this._grip.visible = false; } if (this._hand !== null) { this._hand.visible = false; } return this; } update(inputSource, frame2, referenceSpace) { let inputPose = null; let gripPose = null; let handPose = null; const targetRay = this._targetRay; const grip = this._grip; const hand = this._hand; if (inputSource && frame2.session.visibilityState !== "visible-blurred") { if (hand && inputSource.hand) { handPose = true; for (const inputjoint of inputSource.hand.values()) { const jointPose = frame2.getJointPose(inputjoint, referenceSpace); const joint = this._getHandJoint(hand, inputjoint); if (jointPose !== null) { joint.matrix.fromArray(jointPose.transform.matrix); joint.matrix.decompose(joint.position, joint.rotation, joint.scale); joint.matrixWorldNeedsUpdate = true; joint.jointRadius = jointPose.radius; } joint.visible = jointPose !== null; } const indexTip = hand.joints["index-finger-tip"]; const thumbTip = hand.joints["thumb-tip"]; const distance = indexTip.position.distanceTo(thumbTip.position); const distanceToPinch = 0.02; const threshold = 5e-3; if (hand.inputState.pinching && distance > distanceToPinch + threshold) { hand.inputState.pinching = false; this.dispatchEvent({ type: "pinchend", handedness: inputSource.handedness, target: this }); } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) { hand.inputState.pinching = true; this.dispatchEvent({ type: "pinchstart", handedness: inputSource.handedness, target: this }); } } else { if (grip !== null && inputSource.gripSpace) { gripPose = frame2.getPose(inputSource.gripSpace, referenceSpace); if (gripPose !== null) { grip.matrix.fromArray(gripPose.transform.matrix); grip.matrix.decompose(grip.position, grip.rotation, grip.scale); grip.matrixWorldNeedsUpdate = true; if (gripPose.linearVelocity) { grip.hasLinearVelocity = true; grip.linearVelocity.copy(gripPose.linearVelocity); } else { grip.hasLinearVelocity = false; } if (gripPose.angularVelocity) { grip.hasAngularVelocity = true; grip.angularVelocity.copy(gripPose.angularVelocity); } else { grip.hasAngularVelocity = false; } } } } if (targetRay !== null) { inputPose = frame2.getPose(inputSource.targetRaySpace, referenceSpace); if (inputPose === null && gripPose !== null) { inputPose = gripPose; } if (inputPose !== null) { targetRay.matrix.fromArray(inputPose.transform.matrix); targetRay.matrix.decompose(targetRay.position, targetRay.rotation, targetRay.scale); targetRay.matrixWorldNeedsUpdate = true; if (inputPose.linearVelocity) { targetRay.hasLinearVelocity = true; targetRay.linearVelocity.copy(inputPose.linearVelocity); } else { targetRay.hasLinearVelocity = false; } if (inputPose.angularVelocity) { targetRay.hasAngularVelocity = true; targetRay.angularVelocity.copy(inputPose.angularVelocity); } else { targetRay.hasAngularVelocity = false; } this.dispatchEvent(_moveEvent); } } } if (targetRay !== null) { targetRay.visible = inputPose !== null; } if (grip !== null) { grip.visible = gripPose !== null; } if (hand !== null) { hand.visible = handPose !== null; } return this; } // private method _getHandJoint(hand, inputjoint) { if (hand.joints[inputjoint.jointName] === void 0) { const joint = new Group(); joint.matrixAutoUpdate = false; joint.visible = false; hand.joints[inputjoint.jointName] = joint; hand.add(joint); } return hand.joints[inputjoint.jointName]; } }; var DepthTexture = class extends Texture { constructor(width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format2) { format2 = format2 !== void 0 ? format2 : DepthFormat; if (format2 !== DepthFormat && format2 !== DepthStencilFormat) { throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat"); } if (type === void 0 && format2 === DepthFormat) type = UnsignedIntType; if (type === void 0 && format2 === DepthStencilFormat) type = UnsignedInt248Type; super(null, mapping, wrapS, wrapT, magFilter, minFilter, format2, type, anisotropy); this.isDepthTexture = true; this.image = { width, height }; this.magFilter = magFilter !== void 0 ? magFilter : NearestFilter; this.minFilter = minFilter !== void 0 ? minFilter : NearestFilter; this.flipY = false; this.generateMipmaps = false; this.compareFunction = null; } copy(source) { super.copy(source); this.compareFunction = source.compareFunction; return this; } toJSON(meta) { const data = super.toJSON(meta); if (this.compareFunction !== null) data.compareFunction = this.compareFunction; return data; } }; var WebXRManager = class extends EventDispatcher { constructor(renderer3, gl) { super(); const scope = this; let session = null; let framebufferScaleFactor = 1; let referenceSpace = null; let referenceSpaceType = "local-floor"; let foveation = 1; let customReferenceSpace = null; let pose = null; let glBinding = null; let glProjLayer = null; let glBaseLayer = null; let xrFrame = null; const attributes = gl.getContextAttributes(); let initialRenderTarget = null; let newRenderTarget = null; const controllers = []; const controllerInputSources = []; const cameraL = new PerspectiveCamera(); cameraL.layers.enable(1); cameraL.viewport = new Vector4(); const cameraR = new PerspectiveCamera(); cameraR.layers.enable(2); cameraR.viewport = new Vector4(); const cameras = [cameraL, cameraR]; const cameraXR = new ArrayCamera(); cameraXR.layers.enable(1); cameraXR.layers.enable(2); let _currentDepthNear = null; let _currentDepthFar = null; this.cameraAutoUpdate = true; this.enabled = false; this.isPresenting = false; this.getController = function(index6) { let controller = controllers[index6]; if (controller === void 0) { controller = new WebXRController(); controllers[index6] = controller; } return controller.getTargetRaySpace(); }; this.getControllerGrip = function(index6) { let controller = controllers[index6]; if (controller === void 0) { controller = new WebXRController(); controllers[index6] = controller; } return controller.getGripSpace(); }; this.getHand = function(index6) { let controller = controllers[index6]; if (controller === void 0) { controller = new WebXRController(); controllers[index6] = controller; } return controller.getHandSpace(); }; function onSessionEvent(event) { const controllerIndex = controllerInputSources.indexOf(event.inputSource); if (controllerIndex === -1) { return; } const controller = controllers[controllerIndex]; if (controller !== void 0) { controller.update(event.inputSource, event.frame, customReferenceSpace || referenceSpace); controller.dispatchEvent({ type: event.type, data: event.inputSource }); } } function onSessionEnd() { session.removeEventListener("select", onSessionEvent); session.removeEventListener("selectstart", onSessionEvent); session.removeEventListener("selectend", onSessionEvent); session.removeEventListener("squeeze", onSessionEvent); session.removeEventListener("squeezestart", onSessionEvent); session.removeEventListener("squeezeend", onSessionEvent); session.removeEventListener("end", onSessionEnd); session.removeEventListener("inputsourceschange", onInputSourcesChange); for (let i = 0; i < controllers.length; i++) { const inputSource = controllerInputSources[i]; if (inputSource === null) continue; controllerInputSources[i] = null; controllers[i].disconnect(inputSource); } _currentDepthNear = null; _currentDepthFar = null; renderer3.setRenderTarget(initialRenderTarget); glBaseLayer = null; glProjLayer = null; glBinding = null; session = null; newRenderTarget = null; animation.stop(); scope.isPresenting = false; scope.dispatchEvent({ type: "sessionend" }); } this.setFramebufferScaleFactor = function(value) { framebufferScaleFactor = value; if (scope.isPresenting === true) { console.warn("THREE.WebXRManager: Cannot change framebuffer scale while presenting."); } }; this.setReferenceSpaceType = function(value) { referenceSpaceType = value; if (scope.isPresenting === true) { console.warn("THREE.WebXRManager: Cannot change reference space type while presenting."); } }; this.getReferenceSpace = function() { return customReferenceSpace || referenceSpace; }; this.setReferenceSpace = function(space) { customReferenceSpace = space; }; this.getBaseLayer = function() { return glProjLayer !== null ? glProjLayer : glBaseLayer; }; this.getBinding = function() { return glBinding; }; this.getFrame = function() { return xrFrame; }; this.getSession = function() { return session; }; this.setSession = async function(value) { session = value; if (session !== null) { initialRenderTarget = renderer3.getRenderTarget(); session.addEventListener("select", onSessionEvent); session.addEventListener("selectstart", onSessionEvent); session.addEventListener("selectend", onSessionEvent); session.addEventListener("squeeze", onSessionEvent); session.addEventListener("squeezestart", onSessionEvent); session.addEventListener("squeezeend", onSessionEvent); session.addEventListener("end", onSessionEnd); session.addEventListener("inputsourceschange", onInputSourcesChange); if (attributes.xrCompatible !== true) { await gl.makeXRCompatible(); } if (session.renderState.layers === void 0 || renderer3.capabilities.isWebGL2 === false) { const layerInit = { antialias: session.renderState.layers === void 0 ? attributes.antialias : true, alpha: true, depth: attributes.depth, stencil: attributes.stencil, framebufferScaleFactor }; glBaseLayer = new XRWebGLLayer(session, gl, layerInit); session.updateRenderState({ baseLayer: glBaseLayer }); newRenderTarget = new WebGLRenderTarget( glBaseLayer.framebufferWidth, glBaseLayer.framebufferHeight, { format: RGBAFormat, type: UnsignedByteType, colorSpace: renderer3.outputColorSpace, stencilBuffer: attributes.stencil } ); } else { let depthFormat = null; let depthType = null; let glDepthFormat = null; if (attributes.depth) { glDepthFormat = attributes.stencil ? gl.DEPTH24_STENCIL8 : gl.DEPTH_COMPONENT24; depthFormat = attributes.stencil ? DepthStencilFormat : DepthFormat; depthType = attributes.stencil ? UnsignedInt248Type : UnsignedIntType; } const projectionlayerInit = { colorFormat: gl.RGBA8, depthFormat: glDepthFormat, scaleFactor: framebufferScaleFactor }; glBinding = new XRWebGLBinding(session, gl); glProjLayer = glBinding.createProjectionLayer(projectionlayerInit); session.updateRenderState({ layers: [glProjLayer] }); newRenderTarget = new WebGLRenderTarget( glProjLayer.textureWidth, glProjLayer.textureHeight, { format: RGBAFormat, type: UnsignedByteType, depthTexture: new DepthTexture(glProjLayer.textureWidth, glProjLayer.textureHeight, depthType, void 0, void 0, void 0, void 0, void 0, void 0, depthFormat), stencilBuffer: attributes.stencil, colorSpace: renderer3.outputColorSpace, samples: attributes.antialias ? 4 : 0 } ); const renderTargetProperties = renderer3.properties.get(newRenderTarget); renderTargetProperties.__ignoreDepthValues = glProjLayer.ignoreDepthValues; } newRenderTarget.isXRRenderTarget = true; this.setFoveation(foveation); customReferenceSpace = null; referenceSpace = await session.requestReferenceSpace(referenceSpaceType); animation.setContext(session); animation.start(); scope.isPresenting = true; scope.dispatchEvent({ type: "sessionstart" }); } }; this.getEnvironmentBlendMode = function() { if (session !== null) { return session.environmentBlendMode; } }; function onInputSourcesChange(event) { for (let i = 0; i < event.removed.length; i++) { const inputSource = event.removed[i]; const index6 = controllerInputSources.indexOf(inputSource); if (index6 >= 0) { controllerInputSources[index6] = null; controllers[index6].disconnect(inputSource); } } for (let i = 0; i < event.added.length; i++) { const inputSource = event.added[i]; let controllerIndex = controllerInputSources.indexOf(inputSource); if (controllerIndex === -1) { for (let i2 = 0; i2 < controllers.length; i2++) { if (i2 >= controllerInputSources.length) { controllerInputSources.push(inputSource); controllerIndex = i2; break; } else if (controllerInputSources[i2] === null) { controllerInputSources[i2] = inputSource; controllerIndex = i2; break; } } if (controllerIndex === -1) break; } const controller = controllers[controllerIndex]; if (controller) { controller.connect(inputSource); } } } const cameraLPos = new Vector3(); const cameraRPos = new Vector3(); function setProjectionFromUnion(camera3, cameraL2, cameraR2) { cameraLPos.setFromMatrixPosition(cameraL2.matrixWorld); cameraRPos.setFromMatrixPosition(cameraR2.matrixWorld); const ipd = cameraLPos.distanceTo(cameraRPos); const projL = cameraL2.projectionMatrix.elements; const projR = cameraR2.projectionMatrix.elements; const near = projL[14] / (projL[10] - 1); const far = projL[14] / (projL[10] + 1); const topFov = (projL[9] + 1) / projL[5]; const bottomFov = (projL[9] - 1) / projL[5]; const leftFov = (projL[8] - 1) / projL[0]; const rightFov = (projR[8] + 1) / projR[0]; const left = near * leftFov; const right = near * rightFov; const zOffset = ipd / (-leftFov + rightFov); const xOffset = zOffset * -leftFov; cameraL2.matrixWorld.decompose(camera3.position, camera3.quaternion, camera3.scale); camera3.translateX(xOffset); camera3.translateZ(zOffset); camera3.matrixWorld.compose(camera3.position, camera3.quaternion, camera3.scale); camera3.matrixWorldInverse.copy(camera3.matrixWorld).invert(); const near2 = near + zOffset; const far2 = far + zOffset; const left2 = left - xOffset; const right2 = right + (ipd - xOffset); const top2 = topFov * far / far2 * near2; const bottom2 = bottomFov * far / far2 * near2; camera3.projectionMatrix.makePerspective(left2, right2, top2, bottom2, near2, far2); camera3.projectionMatrixInverse.copy(camera3.projectionMatrix).invert(); } function updateCamera(camera3, parent) { if (parent === null) { camera3.matrixWorld.copy(camera3.matrix); } else { camera3.matrixWorld.multiplyMatrices(parent.matrixWorld, camera3.matrix); } camera3.matrixWorldInverse.copy(camera3.matrixWorld).invert(); } this.updateCamera = function(camera3) { if (session === null) return; cameraXR.near = cameraR.near = cameraL.near = camera3.near; cameraXR.far = cameraR.far = cameraL.far = camera3.far; if (_currentDepthNear !== cameraXR.near || _currentDepthFar !== cameraXR.far) { session.updateRenderState({ depthNear: cameraXR.near, depthFar: cameraXR.far }); _currentDepthNear = cameraXR.near; _currentDepthFar = cameraXR.far; } const parent = camera3.parent; const cameras2 = cameraXR.cameras; updateCamera(cameraXR, parent); for (let i = 0; i < cameras2.length; i++) { updateCamera(cameras2[i], parent); } if (cameras2.length === 2) { setProjectionFromUnion(cameraXR, cameraL, cameraR); } else { cameraXR.projectionMatrix.copy(cameraL.projectionMatrix); } updateUserCamera(camera3, cameraXR, parent); }; function updateUserCamera(camera3, cameraXR2, parent) { if (parent === null) { camera3.matrix.copy(cameraXR2.matrixWorld); } else { camera3.matrix.copy(parent.matrixWorld); camera3.matrix.invert(); camera3.matrix.multiply(cameraXR2.matrixWorld); } camera3.matrix.decompose(camera3.position, camera3.quaternion, camera3.scale); camera3.updateMatrixWorld(true); camera3.projectionMatrix.copy(cameraXR2.projectionMatrix); camera3.projectionMatrixInverse.copy(cameraXR2.projectionMatrixInverse); if (camera3.isPerspectiveCamera) { camera3.fov = RAD2DEG * 2 * Math.atan(1 / camera3.projectionMatrix.elements[5]); camera3.zoom = 1; } } this.getCamera = function() { return cameraXR; }; this.getFoveation = function() { if (glProjLayer === null && glBaseLayer === null) { return void 0; } return foveation; }; this.setFoveation = function(value) { foveation = value; if (glProjLayer !== null) { glProjLayer.fixedFoveation = value; } if (glBaseLayer !== null && glBaseLayer.fixedFoveation !== void 0) { glBaseLayer.fixedFoveation = value; } }; let onAnimationFrameCallback = null; function onAnimationFrame(time, frame2) { pose = frame2.getViewerPose(customReferenceSpace || referenceSpace); xrFrame = frame2; if (pose !== null) { const views = pose.views; if (glBaseLayer !== null) { renderer3.setRenderTargetFramebuffer(newRenderTarget, glBaseLayer.framebuffer); renderer3.setRenderTarget(newRenderTarget); } let cameraXRNeedsUpdate = false; if (views.length !== cameraXR.cameras.length) { cameraXR.cameras.length = 0; cameraXRNeedsUpdate = true; } for (let i = 0; i < views.length; i++) { const view = views[i]; let viewport = null; if (glBaseLayer !== null) { viewport = glBaseLayer.getViewport(view); } else { const glSubImage = glBinding.getViewSubImage(glProjLayer, view); viewport = glSubImage.viewport; if (i === 0) { renderer3.setRenderTargetTextures( newRenderTarget, glSubImage.colorTexture, glProjLayer.ignoreDepthValues ? void 0 : glSubImage.depthStencilTexture ); renderer3.setRenderTarget(newRenderTarget); } } let camera3 = cameras[i]; if (camera3 === void 0) { camera3 = new PerspectiveCamera(); camera3.layers.enable(i); camera3.viewport = new Vector4(); cameras[i] = camera3; } camera3.matrix.fromArray(view.transform.matrix); camera3.matrix.decompose(camera3.position, camera3.quaternion, camera3.scale); camera3.projectionMatrix.fromArray(view.projectionMatrix); camera3.projectionMatrixInverse.copy(camera3.projectionMatrix).invert(); camera3.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height); if (i === 0) { cameraXR.matrix.copy(camera3.matrix); cameraXR.matrix.decompose(cameraXR.position, cameraXR.quaternion, cameraXR.scale); } if (cameraXRNeedsUpdate === true) { cameraXR.cameras.push(camera3); } } } for (let i = 0; i < controllers.length; i++) { const inputSource = controllerInputSources[i]; const controller = controllers[i]; if (inputSource !== null && controller !== void 0) { controller.update(inputSource, frame2, customReferenceSpace || referenceSpace); } } if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame2); if (frame2.detectedPlanes) { scope.dispatchEvent({ type: "planesdetected", data: frame2 }); } xrFrame = null; } const animation = new WebGLAnimation(); animation.setAnimationLoop(onAnimationFrame); this.setAnimationLoop = function(callback) { onAnimationFrameCallback = callback; }; this.dispose = function() { }; } }; function WebGLMaterials(renderer3, properties) { function refreshTransformUniform(map, uniform) { if (map.matrixAutoUpdate === true) { map.updateMatrix(); } uniform.value.copy(map.matrix); } function refreshFogUniforms(uniforms, fog) { fog.color.getRGB(uniforms.fogColor.value, getUnlitUniformColorSpace(renderer3)); if (fog.isFog) { uniforms.fogNear.value = fog.near; uniforms.fogFar.value = fog.far; } else if (fog.isFogExp2) { uniforms.fogDensity.value = fog.density; } } function refreshMaterialUniforms(uniforms, material, pixelRatio, height, transmissionRenderTarget) { if (material.isMeshBasicMaterial) { refreshUniformsCommon(uniforms, material); } else if (material.isMeshLambertMaterial) { refreshUniformsCommon(uniforms, material); } else if (material.isMeshToonMaterial) { refreshUniformsCommon(uniforms, material); refreshUniformsToon(uniforms, material); } else if (material.isMeshPhongMaterial) { refreshUniformsCommon(uniforms, material); refreshUniformsPhong(uniforms, material); } else if (material.isMeshStandardMaterial) { refreshUniformsCommon(uniforms, material); refreshUniformsStandard(uniforms, material); if (material.isMeshPhysicalMaterial) { refreshUniformsPhysical(uniforms, material, transmissionRenderTarget); } } else if (material.isMeshMatcapMaterial) { refreshUniformsCommon(uniforms, material); refreshUniformsMatcap(uniforms, material); } else if (material.isMeshDepthMaterial) { refreshUniformsCommon(uniforms, material); } else if (material.isMeshDistanceMaterial) { refreshUniformsCommon(uniforms, material); refreshUniformsDistance(uniforms, material); } else if (material.isMeshNormalMaterial) { refreshUniformsCommon(uniforms, material); } else if (material.isLineBasicMaterial) { refreshUniformsLine(uniforms, material); if (material.isLineDashedMaterial) { refreshUniformsDash(uniforms, material); } } else if (material.isPointsMaterial) { refreshUniformsPoints(uniforms, material, pixelRatio, height); } else if (material.isSpriteMaterial) { refreshUniformsSprites(uniforms, material); } else if (material.isShadowMaterial) { uniforms.color.value.copy(material.color); uniforms.opacity.value = material.opacity; } else if (material.isShaderMaterial) { material.uniformsNeedUpdate = false; } } function refreshUniformsCommon(uniforms, material) { uniforms.opacity.value = material.opacity; if (material.color) { uniforms.diffuse.value.copy(material.color); } if (material.emissive) { uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity); } if (material.map) { uniforms.map.value = material.map; refreshTransformUniform(material.map, uniforms.mapTransform); } if (material.alphaMap) { uniforms.alphaMap.value = material.alphaMap; refreshTransformUniform(material.alphaMap, uniforms.alphaMapTransform); } if (material.bumpMap) { uniforms.bumpMap.value = material.bumpMap; refreshTransformUniform(material.bumpMap, uniforms.bumpMapTransform); uniforms.bumpScale.value = material.bumpScale; if (material.side === BackSide) { uniforms.bumpScale.value *= -1; } } if (material.normalMap) { uniforms.normalMap.value = material.normalMap; refreshTransformUniform(material.normalMap, uniforms.normalMapTransform); uniforms.normalScale.value.copy(material.normalScale); if (material.side === BackSide) { uniforms.normalScale.value.negate(); } } if (material.displacementMap) { uniforms.displacementMap.value = material.displacementMap; refreshTransformUniform(material.displacementMap, uniforms.displacementMapTransform); uniforms.displacementScale.value = material.displacementScale; uniforms.displacementBias.value = material.displacementBias; } if (material.emissiveMap) { uniforms.emissiveMap.value = material.emissiveMap; refreshTransformUniform(material.emissiveMap, uniforms.emissiveMapTransform); } if (material.specularMap) { uniforms.specularMap.value = material.specularMap; refreshTransformUniform(material.specularMap, uniforms.specularMapTransform); } if (material.alphaTest > 0) { uniforms.alphaTest.value = material.alphaTest; } const envMap = properties.get(material).envMap; if (envMap) { uniforms.envMap.value = envMap; uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap.isRenderTargetTexture === false ? -1 : 1; uniforms.reflectivity.value = material.reflectivity; uniforms.ior.value = material.ior; uniforms.refractionRatio.value = material.refractionRatio; } if (material.lightMap) { uniforms.lightMap.value = material.lightMap; const scaleFactor = renderer3._useLegacyLights === true ? Math.PI : 1; uniforms.lightMapIntensity.value = material.lightMapIntensity * scaleFactor; refreshTransformUniform(material.lightMap, uniforms.lightMapTransform); } if (material.aoMap) { uniforms.aoMap.value = material.aoMap; uniforms.aoMapIntensity.value = material.aoMapIntensity; refreshTransformUniform(material.aoMap, uniforms.aoMapTransform); } } function refreshUniformsLine(uniforms, material) { uniforms.diffuse.value.copy(material.color); uniforms.opacity.value = material.opacity; if (material.map) { uniforms.map.value = material.map; refreshTransformUniform(material.map, uniforms.mapTransform); } } function refreshUniformsDash(uniforms, material) { uniforms.dashSize.value = material.dashSize; uniforms.totalSize.value = material.dashSize + material.gapSize; uniforms.scale.value = material.scale; } function refreshUniformsPoints(uniforms, material, pixelRatio, height) { uniforms.diffuse.value.copy(material.color); uniforms.opacity.value = material.opacity; uniforms.size.value = material.size * pixelRatio; uniforms.scale.value = height * 0.5; if (material.map) { uniforms.map.value = material.map; refreshTransformUniform(material.map, uniforms.uvTransform); } if (material.alphaMap) { uniforms.alphaMap.value = material.alphaMap; refreshTransformUniform(material.alphaMap, uniforms.alphaMapTransform); } if (material.alphaTest > 0) { uniforms.alphaTest.value = material.alphaTest; } } function refreshUniformsSprites(uniforms, material) { uniforms.diffuse.value.copy(material.color); uniforms.opacity.value = material.opacity; uniforms.rotation.value = material.rotation; if (material.map) { uniforms.map.value = material.map; refreshTransformUniform(material.map, uniforms.mapTransform); } if (material.alphaMap) { uniforms.alphaMap.value = material.alphaMap; refreshTransformUniform(material.alphaMap, uniforms.alphaMapTransform); } if (material.alphaTest > 0) { uniforms.alphaTest.value = material.alphaTest; } } function refreshUniformsPhong(uniforms, material) { uniforms.specular.value.copy(material.specular); uniforms.shininess.value = Math.max(material.shininess, 1e-4); } function refreshUniformsToon(uniforms, material) { if (material.gradientMap) { uniforms.gradientMap.value = material.gradientMap; } } function refreshUniformsStandard(uniforms, material) { uniforms.metalness.value = material.metalness; if (material.metalnessMap) { uniforms.metalnessMap.value = material.metalnessMap; refreshTransformUniform(material.metalnessMap, uniforms.metalnessMapTransform); } uniforms.roughness.value = material.roughness; if (material.roughnessMap) { uniforms.roughnessMap.value = material.roughnessMap; refreshTransformUniform(material.roughnessMap, uniforms.roughnessMapTransform); } const envMap = properties.get(material).envMap; if (envMap) { uniforms.envMapIntensity.value = material.envMapIntensity; } } function refreshUniformsPhysical(uniforms, material, transmissionRenderTarget) { uniforms.ior.value = material.ior; if (material.sheen > 0) { uniforms.sheenColor.value.copy(material.sheenColor).multiplyScalar(material.sheen); uniforms.sheenRoughness.value = material.sheenRoughness; if (material.sheenColorMap) { uniforms.sheenColorMap.value = material.sheenColorMap; refreshTransformUniform(material.sheenColorMap, uniforms.sheenColorMapTransform); } if (material.sheenRoughnessMap) { uniforms.sheenRoughnessMap.value = material.sheenRoughnessMap; refreshTransformUniform(material.sheenRoughnessMap, uniforms.sheenRoughnessMapTransform); } } if (material.clearcoat > 0) { uniforms.clearcoat.value = material.clearcoat; uniforms.clearcoatRoughness.value = material.clearcoatRoughness; if (material.clearcoatMap) { uniforms.clearcoatMap.value = material.clearcoatMap; refreshTransformUniform(material.clearcoatMap, uniforms.clearcoatMapTransform); } if (material.clearcoatRoughnessMap) { uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap; refreshTransformUniform(material.clearcoatRoughnessMap, uniforms.clearcoatRoughnessMapTransform); } if (material.clearcoatNormalMap) { uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap; refreshTransformUniform(material.clearcoatNormalMap, uniforms.clearcoatNormalMapTransform); uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale); if (material.side === BackSide) { uniforms.clearcoatNormalScale.value.negate(); } } } if (material.iridescence > 0) { uniforms.iridescence.value = material.iridescence; uniforms.iridescenceIOR.value = material.iridescenceIOR; uniforms.iridescenceThicknessMinimum.value = material.iridescenceThicknessRange[0]; uniforms.iridescenceThicknessMaximum.value = material.iridescenceThicknessRange[1]; if (material.iridescenceMap) { uniforms.iridescenceMap.value = material.iridescenceMap; refreshTransformUniform(material.iridescenceMap, uniforms.iridescenceMapTransform); } if (material.iridescenceThicknessMap) { uniforms.iridescenceThicknessMap.value = material.iridescenceThicknessMap; refreshTransformUniform(material.iridescenceThicknessMap, uniforms.iridescenceThicknessMapTransform); } } if (material.transmission > 0) { uniforms.transmission.value = material.transmission; uniforms.transmissionSamplerMap.value = transmissionRenderTarget.texture; uniforms.transmissionSamplerSize.value.set(transmissionRenderTarget.width, transmissionRenderTarget.height); if (material.transmissionMap) { uniforms.transmissionMap.value = material.transmissionMap; refreshTransformUniform(material.transmissionMap, uniforms.transmissionMapTransform); } uniforms.thickness.value = material.thickness; if (material.thicknessMap) { uniforms.thicknessMap.value = material.thicknessMap; refreshTransformUniform(material.thicknessMap, uniforms.thicknessMapTransform); } uniforms.attenuationDistance.value = material.attenuationDistance; uniforms.attenuationColor.value.copy(material.attenuationColor); } if (material.anisotropy > 0) { uniforms.anisotropyVector.value.set(material.anisotropy * Math.cos(material.anisotropyRotation), material.anisotropy * Math.sin(material.anisotropyRotation)); if (material.anisotropyMap) { uniforms.anisotropyMap.value = material.anisotropyMap; refreshTransformUniform(material.anisotropyMap, uniforms.anisotropyMapTransform); } } uniforms.specularIntensity.value = material.specularIntensity; uniforms.specularColor.value.copy(material.specularColor); if (material.specularColorMap) { uniforms.specularColorMap.value = material.specularColorMap; refreshTransformUniform(material.specularColorMap, uniforms.specularColorMapTransform); } if (material.specularIntensityMap) { uniforms.specularIntensityMap.value = material.specularIntensityMap; refreshTransformUniform(material.specularIntensityMap, uniforms.specularIntensityMapTransform); } } function refreshUniformsMatcap(uniforms, material) { if (material.matcap) { uniforms.matcap.value = material.matcap; } } function refreshUniformsDistance(uniforms, material) { const light = properties.get(material).light; uniforms.referencePosition.value.setFromMatrixPosition(light.matrixWorld); uniforms.nearDistance.value = light.shadow.camera.near; uniforms.farDistance.value = light.shadow.camera.far; } return { refreshFogUniforms, refreshMaterialUniforms }; } function WebGLUniformsGroups(gl, info, capabilities, state) { let buffers = {}; let updateList = {}; let allocatedBindingPoints = []; const maxBindingPoints = capabilities.isWebGL2 ? gl.getParameter(gl.MAX_UNIFORM_BUFFER_BINDINGS) : 0; function bind(uniformsGroup, program) { const webglProgram = program.program; state.uniformBlockBinding(uniformsGroup, webglProgram); } function update4(uniformsGroup, program) { let buffer = buffers[uniformsGroup.id]; if (buffer === void 0) { prepareUniformsGroup(uniformsGroup); buffer = createBuffer(uniformsGroup); buffers[uniformsGroup.id] = buffer; uniformsGroup.addEventListener("dispose", onUniformsGroupsDispose); } const webglProgram = program.program; state.updateUBOMapping(uniformsGroup, webglProgram); const frame2 = info.render.frame; if (updateList[uniformsGroup.id] !== frame2) { updateBufferData(uniformsGroup); updateList[uniformsGroup.id] = frame2; } } function createBuffer(uniformsGroup) { const bindingPointIndex = allocateBindingPointIndex(); uniformsGroup.__bindingPointIndex = bindingPointIndex; const buffer = gl.createBuffer(); const size = uniformsGroup.__size; const usage = uniformsGroup.usage; gl.bindBuffer(gl.UNIFORM_BUFFER, buffer); gl.bufferData(gl.UNIFORM_BUFFER, size, usage); gl.bindBuffer(gl.UNIFORM_BUFFER, null); gl.bindBufferBase(gl.UNIFORM_BUFFER, bindingPointIndex, buffer); return buffer; } function allocateBindingPointIndex() { for (let i = 0; i < maxBindingPoints; i++) { if (allocatedBindingPoints.indexOf(i) === -1) { allocatedBindingPoints.push(i); return i; } } console.error("THREE.WebGLRenderer: Maximum number of simultaneously usable uniforms groups reached."); return 0; } function updateBufferData(uniformsGroup) { const buffer = buffers[uniformsGroup.id]; const uniforms = uniformsGroup.uniforms; const cache = uniformsGroup.__cache; gl.bindBuffer(gl.UNIFORM_BUFFER, buffer); for (let i = 0, il = uniforms.length; i < il; i++) { const uniform = uniforms[i]; if (hasUniformChanged(uniform, i, cache) === true) { const offset = uniform.__offset; const values = Array.isArray(uniform.value) ? uniform.value : [uniform.value]; let arrayOffset = 0; for (let i2 = 0; i2 < values.length; i2++) { const value = values[i2]; const info2 = getUniformSize(value); if (typeof value === "number") { uniform.__data[0] = value; gl.bufferSubData(gl.UNIFORM_BUFFER, offset + arrayOffset, uniform.__data); } else if (value.isMatrix3) { uniform.__data[0] = value.elements[0]; uniform.__data[1] = value.elements[1]; uniform.__data[2] = value.elements[2]; uniform.__data[3] = value.elements[0]; uniform.__data[4] = value.elements[3]; uniform.__data[5] = value.elements[4]; uniform.__data[6] = value.elements[5]; uniform.__data[7] = value.elements[0]; uniform.__data[8] = value.elements[6]; uniform.__data[9] = value.elements[7]; uniform.__data[10] = value.elements[8]; uniform.__data[11] = value.elements[0]; } else { value.toArray(uniform.__data, arrayOffset); arrayOffset += info2.storage / Float32Array.BYTES_PER_ELEMENT; } } gl.bufferSubData(gl.UNIFORM_BUFFER, offset, uniform.__data); } } gl.bindBuffer(gl.UNIFORM_BUFFER, null); } function hasUniformChanged(uniform, index6, cache) { const value = uniform.value; if (cache[index6] === void 0) { if (typeof value === "number") { cache[index6] = value; } else { const values = Array.isArray(value) ? value : [value]; const tempValues = []; for (let i = 0; i < values.length; i++) { tempValues.push(values[i].clone()); } cache[index6] = tempValues; } return true; } else { if (typeof value === "number") { if (cache[index6] !== value) { cache[index6] = value; return true; } } else { const cachedObjects = Array.isArray(cache[index6]) ? cache[index6] : [cache[index6]]; const values = Array.isArray(value) ? value : [value]; for (let i = 0; i < cachedObjects.length; i++) { const cachedObject = cachedObjects[i]; if (cachedObject.equals(values[i]) === false) { cachedObject.copy(values[i]); return true; } } } } return false; } function prepareUniformsGroup(uniformsGroup) { const uniforms = uniformsGroup.uniforms; let offset = 0; const chunkSize = 16; let chunkOffset = 0; for (let i = 0, l = uniforms.length; i < l; i++) { const uniform = uniforms[i]; const infos = { boundary: 0, // bytes storage: 0 // bytes }; const values = Array.isArray(uniform.value) ? uniform.value : [uniform.value]; for (let j = 0, jl = values.length; j < jl; j++) { const value = values[j]; const info2 = getUniformSize(value); infos.boundary += info2.boundary; infos.storage += info2.storage; } uniform.__data = new Float32Array(infos.storage / Float32Array.BYTES_PER_ELEMENT); uniform.__offset = offset; if (i > 0) { chunkOffset = offset % chunkSize; const remainingSizeInChunk = chunkSize - chunkOffset; if (chunkOffset !== 0 && remainingSizeInChunk - infos.boundary < 0) { offset += chunkSize - chunkOffset; uniform.__offset = offset; } } offset += infos.storage; } chunkOffset = offset % chunkSize; if (chunkOffset > 0) offset += chunkSize - chunkOffset; uniformsGroup.__size = offset; uniformsGroup.__cache = {}; return this; } function getUniformSize(value) { const info2 = { boundary: 0, // bytes storage: 0 // bytes }; if (typeof value === "number") { info2.boundary = 4; info2.storage = 4; } else if (value.isVector2) { info2.boundary = 8; info2.storage = 8; } else if (value.isVector3 || value.isColor) { info2.boundary = 16; info2.storage = 12; } else if (value.isVector4) { info2.boundary = 16; info2.storage = 16; } else if (value.isMatrix3) { info2.boundary = 48; info2.storage = 48; } else if (value.isMatrix4) { info2.boundary = 64; info2.storage = 64; } else if (value.isTexture) { console.warn("THREE.WebGLRenderer: Texture samplers can not be part of an uniforms group."); } else { console.warn("THREE.WebGLRenderer: Unsupported uniform value type.", value); } return info2; } function onUniformsGroupsDispose(event) { const uniformsGroup = event.target; uniformsGroup.removeEventListener("dispose", onUniformsGroupsDispose); const index6 = allocatedBindingPoints.indexOf(uniformsGroup.__bindingPointIndex); allocatedBindingPoints.splice(index6, 1); gl.deleteBuffer(buffers[uniformsGroup.id]); delete buffers[uniformsGroup.id]; delete updateList[uniformsGroup.id]; } function dispose() { for (const id in buffers) { gl.deleteBuffer(buffers[id]); } allocatedBindingPoints = []; buffers = {}; updateList = {}; } return { bind, update: update4, dispose }; } var WebGLRenderer = class { constructor(parameters = {}) { const { canvas = createCanvasElement(), context = null, depth = true, stencil = true, alpha = false, antialias = false, premultipliedAlpha = true, preserveDrawingBuffer = false, powerPreference = "default", failIfMajorPerformanceCaveat = false } = parameters; this.isWebGLRenderer = true; let _alpha; if (context !== null) { _alpha = context.getContextAttributes().alpha; } else { _alpha = alpha; } const uintClearColor = new Uint32Array(4); const intClearColor = new Int32Array(4); let currentRenderList = null; let currentRenderState = null; const renderListStack = []; const renderStateStack = []; this.domElement = canvas; this.debug = { /** * Enables error checking and reporting when shader programs are being compiled * @type {boolean} */ checkShaderErrors: true, /** * Callback for custom error reporting. * @type {?Function} */ onShaderError: null }; this.autoClear = true; this.autoClearColor = true; this.autoClearDepth = true; this.autoClearStencil = true; this.sortObjects = true; this.clippingPlanes = []; this.localClippingEnabled = false; this._outputColorSpace = SRGBColorSpace; this._useLegacyLights = false; this.toneMapping = NoToneMapping; this.toneMappingExposure = 1; const _this = this; let _isContextLost = false; let _currentActiveCubeFace = 0; let _currentActiveMipmapLevel = 0; let _currentRenderTarget = null; let _currentMaterialId = -1; let _currentCamera = null; const _currentViewport = new Vector4(); const _currentScissor = new Vector4(); let _currentScissorTest = null; const _currentClearColor = new Color(0); let _currentClearAlpha = 0; let _width = canvas.width; let _height = canvas.height; let _pixelRatio = 1; let _opaqueSort = null; let _transparentSort = null; const _viewport = new Vector4(0, 0, _width, _height); const _scissor = new Vector4(0, 0, _width, _height); let _scissorTest = false; const _frustum = new Frustum(); let _clippingEnabled = false; let _localClippingEnabled = false; let _transmissionRenderTarget = null; const _projScreenMatrix = new Matrix4(); const _vector23 = new Vector2(); const _vector3 = new Vector3(); const _emptyScene = { background: null, fog: null, environment: null, overrideMaterial: null, isScene: true }; function getTargetPixelRatio() { return _currentRenderTarget === null ? _pixelRatio : 1; } let _gl = context; function getContext(contextNames, contextAttributes) { for (let i = 0; i < contextNames.length; i++) { const contextName = contextNames[i]; const context2 = canvas.getContext(contextName, contextAttributes); if (context2 !== null) return context2; } return null; } try { const contextAttributes = { alpha: true, depth, stencil, antialias, premultipliedAlpha, preserveDrawingBuffer, powerPreference, failIfMajorPerformanceCaveat }; if ("setAttribute" in canvas) canvas.setAttribute("data-engine", `three.js r${REVISION}`); canvas.addEventListener("webglcontextlost", onContextLost, false); canvas.addEventListener("webglcontextrestored", onContextRestore, false); canvas.addEventListener("webglcontextcreationerror", onContextCreationError, false); if (_gl === null) { const contextNames = ["webgl2", "webgl", "experimental-webgl"]; if (_this.isWebGL1Renderer === true) { contextNames.shift(); } _gl = getContext(contextNames, contextAttributes); if (_gl === null) { if (getContext(contextNames)) { throw new Error("Error creating WebGL context with your selected attributes."); } else { throw new Error("Error creating WebGL context."); } } } if (typeof WebGLRenderingContext !== "undefined" && _gl instanceof WebGLRenderingContext) { console.warn("THREE.WebGLRenderer: WebGL 1 support was deprecated in r153 and will be removed in r163."); } if (_gl.getShaderPrecisionFormat === void 0) { _gl.getShaderPrecisionFormat = function() { return { "rangeMin": 1, "rangeMax": 1, "precision": 1 }; }; } } catch (error) { console.error("THREE.WebGLRenderer: " + error.message); throw error; } let extensions, capabilities, state, info; let properties, textures, cubemaps, cubeuvmaps, attributes, geometries, objects; let programCache, materials, renderLists, renderStates, clipping, shadowMap; let background, morphtargets, bufferRenderer, indexedBufferRenderer; let utils, bindingStates, uniformsGroups; function initGLContext() { extensions = new WebGLExtensions(_gl); capabilities = new WebGLCapabilities(_gl, extensions, parameters); extensions.init(capabilities); utils = new WebGLUtils(_gl, extensions, capabilities); state = new WebGLState(_gl, extensions, capabilities); info = new WebGLInfo(_gl); properties = new WebGLProperties(); textures = new WebGLTextures(_gl, extensions, state, properties, capabilities, utils, info); cubemaps = new WebGLCubeMaps(_this); cubeuvmaps = new WebGLCubeUVMaps(_this); attributes = new WebGLAttributes(_gl, capabilities); bindingStates = new WebGLBindingStates(_gl, extensions, attributes, capabilities); geometries = new WebGLGeometries(_gl, attributes, info, bindingStates); objects = new WebGLObjects(_gl, geometries, attributes, info); morphtargets = new WebGLMorphtargets(_gl, capabilities, textures); clipping = new WebGLClipping(properties); programCache = new WebGLPrograms(_this, cubemaps, cubeuvmaps, extensions, capabilities, bindingStates, clipping); materials = new WebGLMaterials(_this, properties); renderLists = new WebGLRenderLists(); renderStates = new WebGLRenderStates(extensions, capabilities); background = new WebGLBackground(_this, cubemaps, cubeuvmaps, state, objects, _alpha, premultipliedAlpha); shadowMap = new WebGLShadowMap(_this, objects, capabilities); uniformsGroups = new WebGLUniformsGroups(_gl, info, capabilities, state); bufferRenderer = new WebGLBufferRenderer(_gl, extensions, info, capabilities); indexedBufferRenderer = new WebGLIndexedBufferRenderer(_gl, extensions, info, capabilities); info.programs = programCache.programs; _this.capabilities = capabilities; _this.extensions = extensions; _this.properties = properties; _this.renderLists = renderLists; _this.shadowMap = shadowMap; _this.state = state; _this.info = info; } initGLContext(); const xr = new WebXRManager(_this, _gl); this.xr = xr; this.getContext = function() { return _gl; }; this.getContextAttributes = function() { return _gl.getContextAttributes(); }; this.forceContextLoss = function() { const extension = extensions.get("WEBGL_lose_context"); if (extension) extension.loseContext(); }; this.forceContextRestore = function() { const extension = extensions.get("WEBGL_lose_context"); if (extension) extension.restoreContext(); }; this.getPixelRatio = function() { return _pixelRatio; }; this.setPixelRatio = function(value) { if (value === void 0) return; _pixelRatio = value; this.setSize(_width, _height, false); }; this.getSize = function(target) { return target.set(_width, _height); }; this.setSize = function(width, height, updateStyle = true) { if (xr.isPresenting) { console.warn("THREE.WebGLRenderer: Can't change size while VR device is presenting."); return; } _width = width; _height = height; canvas.width = Math.floor(width * _pixelRatio); canvas.height = Math.floor(height * _pixelRatio); if (updateStyle === true) { canvas.style.width = width + "px"; canvas.style.height = height + "px"; } this.setViewport(0, 0, width, height); }; this.getDrawingBufferSize = function(target) { return target.set(_width * _pixelRatio, _height * _pixelRatio).floor(); }; this.setDrawingBufferSize = function(width, height, pixelRatio) { _width = width; _height = height; _pixelRatio = pixelRatio; canvas.width = Math.floor(width * pixelRatio); canvas.height = Math.floor(height * pixelRatio); this.setViewport(0, 0, width, height); }; this.getCurrentViewport = function(target) { return target.copy(_currentViewport); }; this.getViewport = function(target) { return target.copy(_viewport); }; this.setViewport = function(x3, y3, width, height) { if (x3.isVector4) { _viewport.set(x3.x, x3.y, x3.z, x3.w); } else { _viewport.set(x3, y3, width, height); } state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor()); }; this.getScissor = function(target) { return target.copy(_scissor); }; this.setScissor = function(x3, y3, width, height) { if (x3.isVector4) { _scissor.set(x3.x, x3.y, x3.z, x3.w); } else { _scissor.set(x3, y3, width, height); } state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor()); }; this.getScissorTest = function() { return _scissorTest; }; this.setScissorTest = function(boolean) { state.setScissorTest(_scissorTest = boolean); }; this.setOpaqueSort = function(method) { _opaqueSort = method; }; this.setTransparentSort = function(method) { _transparentSort = method; }; this.getClearColor = function(target) { return target.copy(background.getClearColor()); }; this.setClearColor = function() { background.setClearColor.apply(background, arguments); }; this.getClearAlpha = function() { return background.getClearAlpha(); }; this.setClearAlpha = function() { background.setClearAlpha.apply(background, arguments); }; this.clear = function(color = true, depth2 = true, stencil2 = true) { let bits = 0; if (color) { let isIntegerFormat = false; if (_currentRenderTarget !== null) { const targetFormat = _currentRenderTarget.texture.format; isIntegerFormat = targetFormat === RGBAIntegerFormat || targetFormat === RGIntegerFormat || targetFormat === RedIntegerFormat; } if (isIntegerFormat) { const targetType = _currentRenderTarget.texture.type; const isUnsignedType = targetType === UnsignedByteType || targetType === UnsignedIntType || targetType === UnsignedShortType || targetType === UnsignedInt248Type || targetType === UnsignedShort4444Type || targetType === UnsignedShort5551Type; const clearColor = background.getClearColor(); const a2 = background.getClearAlpha(); const r = clearColor.r; const g = clearColor.g; const b = clearColor.b; if (isUnsignedType) { uintClearColor[0] = r; uintClearColor[1] = g; uintClearColor[2] = b; uintClearColor[3] = a2; _gl.clearBufferuiv(_gl.COLOR, 0, uintClearColor); } else { intClearColor[0] = r; intClearColor[1] = g; intClearColor[2] = b; intClearColor[3] = a2; _gl.clearBufferiv(_gl.COLOR, 0, intClearColor); } } else { bits |= _gl.COLOR_BUFFER_BIT; } } if (depth2) bits |= _gl.DEPTH_BUFFER_BIT; if (stencil2) { bits |= _gl.STENCIL_BUFFER_BIT; this.state.buffers.stencil.setMask(4294967295); } _gl.clear(bits); }; this.clearColor = function() { this.clear(true, false, false); }; this.clearDepth = function() { this.clear(false, true, false); }; this.clearStencil = function() { this.clear(false, false, true); }; this.dispose = function() { canvas.removeEventListener("webglcontextlost", onContextLost, false); canvas.removeEventListener("webglcontextrestored", onContextRestore, false); canvas.removeEventListener("webglcontextcreationerror", onContextCreationError, false); renderLists.dispose(); renderStates.dispose(); properties.dispose(); cubemaps.dispose(); cubeuvmaps.dispose(); objects.dispose(); bindingStates.dispose(); uniformsGroups.dispose(); programCache.dispose(); xr.dispose(); xr.removeEventListener("sessionstart", onXRSessionStart); xr.removeEventListener("sessionend", onXRSessionEnd); if (_transmissionRenderTarget) { _transmissionRenderTarget.dispose(); _transmissionRenderTarget = null; } animation.stop(); }; function onContextLost(event) { event.preventDefault(); console.log("THREE.WebGLRenderer: Context Lost."); _isContextLost = true; } function onContextRestore() { console.log("THREE.WebGLRenderer: Context Restored."); _isContextLost = false; const infoAutoReset = info.autoReset; const shadowMapEnabled = shadowMap.enabled; const shadowMapAutoUpdate = shadowMap.autoUpdate; const shadowMapNeedsUpdate = shadowMap.needsUpdate; const shadowMapType = shadowMap.type; initGLContext(); info.autoReset = infoAutoReset; shadowMap.enabled = shadowMapEnabled; shadowMap.autoUpdate = shadowMapAutoUpdate; shadowMap.needsUpdate = shadowMapNeedsUpdate; shadowMap.type = shadowMapType; } function onContextCreationError(event) { console.error("THREE.WebGLRenderer: A WebGL context could not be created. Reason: ", event.statusMessage); } function onMaterialDispose(event) { const material = event.target; material.removeEventListener("dispose", onMaterialDispose); deallocateMaterial(material); } function deallocateMaterial(material) { releaseMaterialProgramReferences(material); properties.remove(material); } function releaseMaterialProgramReferences(material) { const programs = properties.get(material).programs; if (programs !== void 0) { programs.forEach(function(program) { programCache.releaseProgram(program); }); if (material.isShaderMaterial) { programCache.releaseShaderCache(material); } } } this.renderBufferDirect = function(camera3, scene3, geometry, material, object, group) { if (scene3 === null) scene3 = _emptyScene; const frontFaceCW = object.isMesh && object.matrixWorld.determinant() < 0; const program = setProgram(camera3, scene3, geometry, material, object); state.setMaterial(material, frontFaceCW); let index6 = geometry.index; let rangeFactor = 1; if (material.wireframe === true) { index6 = geometries.getWireframeAttribute(geometry); if (index6 === void 0) return; rangeFactor = 2; } const drawRange = geometry.drawRange; const position = geometry.attributes.position; let drawStart = drawRange.start * rangeFactor; let drawEnd = (drawRange.start + drawRange.count) * rangeFactor; if (group !== null) { drawStart = Math.max(drawStart, group.start * rangeFactor); drawEnd = Math.min(drawEnd, (group.start + group.count) * rangeFactor); } if (index6 !== null) { drawStart = Math.max(drawStart, 0); drawEnd = Math.min(drawEnd, index6.count); } else if (position !== void 0 && position !== null) { drawStart = Math.max(drawStart, 0); drawEnd = Math.min(drawEnd, position.count); } const drawCount = drawEnd - drawStart; if (drawCount < 0 || drawCount === Infinity) return; bindingStates.setup(object, material, program, geometry, index6); let attribute; let renderer3 = bufferRenderer; if (index6 !== null) { attribute = attributes.get(index6); renderer3 = indexedBufferRenderer; renderer3.setIndex(attribute); } if (object.isMesh) { if (material.wireframe === true) { state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio()); renderer3.setMode(_gl.LINES); } else { renderer3.setMode(_gl.TRIANGLES); } } else if (object.isLine) { let lineWidth = material.linewidth; if (lineWidth === void 0) lineWidth = 1; state.setLineWidth(lineWidth * getTargetPixelRatio()); if (object.isLineSegments) { renderer3.setMode(_gl.LINES); } else if (object.isLineLoop) { renderer3.setMode(_gl.LINE_LOOP); } else { renderer3.setMode(_gl.LINE_STRIP); } } else if (object.isPoints) { renderer3.setMode(_gl.POINTS); } else if (object.isSprite) { renderer3.setMode(_gl.TRIANGLES); } if (object.isInstancedMesh) { renderer3.renderInstances(drawStart, drawCount, object.count); } else if (geometry.isInstancedBufferGeometry) { const maxInstanceCount = geometry._maxInstanceCount !== void 0 ? geometry._maxInstanceCount : Infinity; const instanceCount = Math.min(geometry.instanceCount, maxInstanceCount); renderer3.renderInstances(drawStart, drawCount, instanceCount); } else { renderer3.render(drawStart, drawCount); } }; function prepareMaterial(material, scene3, object) { if (material.transparent === true && material.side === DoubleSide && material.forceSinglePass === false) { material.side = BackSide; material.needsUpdate = true; getProgram(material, scene3, object); material.side = FrontSide; material.needsUpdate = true; getProgram(material, scene3, object); material.side = DoubleSide; } else { getProgram(material, scene3, object); } } this.compile = function(scene3, camera3, targetScene = null) { if (targetScene === null) targetScene = scene3; currentRenderState = renderStates.get(targetScene); currentRenderState.init(); renderStateStack.push(currentRenderState); targetScene.traverseVisible(function(object) { if (object.isLight && object.layers.test(camera3.layers)) { currentRenderState.pushLight(object); if (object.castShadow) { currentRenderState.pushShadow(object); } } }); if (scene3 !== targetScene) { scene3.traverseVisible(function(object) { if (object.isLight && object.layers.test(camera3.layers)) { currentRenderState.pushLight(object); if (object.castShadow) { currentRenderState.pushShadow(object); } } }); } currentRenderState.setupLights(_this._useLegacyLights); const materials2 = /* @__PURE__ */ new Set(); scene3.traverse(function(object) { const material = object.material; if (material) { if (Array.isArray(material)) { for (let i = 0; i < material.length; i++) { const material2 = material[i]; prepareMaterial(material2, targetScene, object); materials2.add(material2); } } else { prepareMaterial(material, targetScene, object); materials2.add(material); } } }); renderStateStack.pop(); currentRenderState = null; return materials2; }; this.compileAsync = function(scene3, camera3, targetScene = null) { const materials2 = this.compile(scene3, camera3, targetScene); return new Promise((resolve) => { function checkMaterialsReady() { materials2.forEach(function(material) { const materialProperties = properties.get(material); const program = materialProperties.currentProgram; if (program.isReady()) { materials2.delete(material); } }); if (materials2.size === 0) { resolve(scene3); return; } setTimeout(checkMaterialsReady, 10); } if (extensions.get("KHR_parallel_shader_compile") !== null) { checkMaterialsReady(); } else { setTimeout(checkMaterialsReady, 10); } }); }; let onAnimationFrameCallback = null; function onAnimationFrame(time) { if (onAnimationFrameCallback) onAnimationFrameCallback(time); } function onXRSessionStart() { animation.stop(); } function onXRSessionEnd() { animation.start(); } const animation = new WebGLAnimation(); animation.setAnimationLoop(onAnimationFrame); if (typeof self !== "undefined") animation.setContext(self); this.setAnimationLoop = function(callback) { onAnimationFrameCallback = callback; xr.setAnimationLoop(callback); callback === null ? animation.stop() : animation.start(); }; xr.addEventListener("sessionstart", onXRSessionStart); xr.addEventListener("sessionend", onXRSessionEnd); this.render = function(scene3, camera3) { if (camera3 !== void 0 && camera3.isCamera !== true) { console.error("THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera."); return; } if (_isContextLost === true) return; if (scene3.matrixWorldAutoUpdate === true) scene3.updateMatrixWorld(); if (camera3.parent === null && camera3.matrixWorldAutoUpdate === true) camera3.updateMatrixWorld(); if (xr.enabled === true && xr.isPresenting === true) { if (xr.cameraAutoUpdate === true) xr.updateCamera(camera3); camera3 = xr.getCamera(); } if (scene3.isScene === true) scene3.onBeforeRender(_this, scene3, camera3, _currentRenderTarget); currentRenderState = renderStates.get(scene3, renderStateStack.length); currentRenderState.init(); renderStateStack.push(currentRenderState); _projScreenMatrix.multiplyMatrices(camera3.projectionMatrix, camera3.matrixWorldInverse); _frustum.setFromProjectionMatrix(_projScreenMatrix); _localClippingEnabled = this.localClippingEnabled; _clippingEnabled = clipping.init(this.clippingPlanes, _localClippingEnabled); currentRenderList = renderLists.get(scene3, renderListStack.length); currentRenderList.init(); renderListStack.push(currentRenderList); projectObject(scene3, camera3, 0, _this.sortObjects); currentRenderList.finish(); if (_this.sortObjects === true) { currentRenderList.sort(_opaqueSort, _transparentSort); } this.info.render.frame++; if (_clippingEnabled === true) clipping.beginShadows(); const shadowsArray = currentRenderState.state.shadowsArray; shadowMap.render(shadowsArray, scene3, camera3); if (_clippingEnabled === true) clipping.endShadows(); if (this.info.autoReset === true) this.info.reset(); background.render(currentRenderList, scene3); currentRenderState.setupLights(_this._useLegacyLights); if (camera3.isArrayCamera) { const cameras = camera3.cameras; for (let i = 0, l = cameras.length; i < l; i++) { const camera22 = cameras[i]; renderScene(currentRenderList, scene3, camera22, camera22.viewport); } } else { renderScene(currentRenderList, scene3, camera3); } if (_currentRenderTarget !== null) { textures.updateMultisampleRenderTarget(_currentRenderTarget); textures.updateRenderTargetMipmap(_currentRenderTarget); } if (scene3.isScene === true) scene3.onAfterRender(_this, scene3, camera3); bindingStates.resetDefaultState(); _currentMaterialId = -1; _currentCamera = null; renderStateStack.pop(); if (renderStateStack.length > 0) { currentRenderState = renderStateStack[renderStateStack.length - 1]; } else { currentRenderState = null; } renderListStack.pop(); if (renderListStack.length > 0) { currentRenderList = renderListStack[renderListStack.length - 1]; } else { currentRenderList = null; } }; function projectObject(object, camera3, groupOrder, sortObjects) { if (object.visible === false) return; const visible = object.layers.test(camera3.layers); if (visible) { if (object.isGroup) { groupOrder = object.renderOrder; } else if (object.isLOD) { if (object.autoUpdate === true) object.update(camera3); } else if (object.isLight) { currentRenderState.pushLight(object); if (object.castShadow) { currentRenderState.pushShadow(object); } } else if (object.isSprite) { if (!object.frustumCulled || _frustum.intersectsSprite(object)) { if (sortObjects) { _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix); } const geometry = objects.update(object); const material = object.material; if (material.visible) { currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null); } } } else if (object.isMesh || object.isLine || object.isPoints) { if (!object.frustumCulled || _frustum.intersectsObject(object)) { const geometry = objects.update(object); const material = object.material; if (sortObjects) { if (object.boundingSphere !== void 0) { if (object.boundingSphere === null) object.computeBoundingSphere(); _vector3.copy(object.boundingSphere.center); } else { if (geometry.boundingSphere === null) geometry.computeBoundingSphere(); _vector3.copy(geometry.boundingSphere.center); } _vector3.applyMatrix4(object.matrixWorld).applyMatrix4(_projScreenMatrix); } if (Array.isArray(material)) { const groups = geometry.groups; for (let i = 0, l = groups.length; i < l; i++) { const group = groups[i]; const groupMaterial = material[group.materialIndex]; if (groupMaterial && groupMaterial.visible) { currentRenderList.push(object, geometry, groupMaterial, groupOrder, _vector3.z, group); } } } else if (material.visible) { currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null); } } } } const children = object.children; for (let i = 0, l = children.length; i < l; i++) { projectObject(children[i], camera3, groupOrder, sortObjects); } } function renderScene(currentRenderList2, scene3, camera3, viewport) { const opaqueObjects = currentRenderList2.opaque; const transmissiveObjects = currentRenderList2.transmissive; const transparentObjects = currentRenderList2.transparent; currentRenderState.setupLightsView(camera3); if (_clippingEnabled === true) clipping.setGlobalState(_this.clippingPlanes, camera3); if (transmissiveObjects.length > 0) renderTransmissionPass(opaqueObjects, transmissiveObjects, scene3, camera3); if (viewport) state.viewport(_currentViewport.copy(viewport)); if (opaqueObjects.length > 0) renderObjects(opaqueObjects, scene3, camera3); if (transmissiveObjects.length > 0) renderObjects(transmissiveObjects, scene3, camera3); if (transparentObjects.length > 0) renderObjects(transparentObjects, scene3, camera3); state.buffers.depth.setTest(true); state.buffers.depth.setMask(true); state.buffers.color.setMask(true); state.setPolygonOffset(false); } function renderTransmissionPass(opaqueObjects, transmissiveObjects, scene3, camera3) { const overrideMaterial = scene3.isScene === true ? scene3.overrideMaterial : null; if (overrideMaterial !== null) { return; } const isWebGL2 = capabilities.isWebGL2; if (_transmissionRenderTarget === null) { _transmissionRenderTarget = new WebGLRenderTarget(1, 1, { generateMipmaps: true, type: extensions.has("EXT_color_buffer_half_float") ? HalfFloatType : UnsignedByteType, minFilter: LinearMipmapLinearFilter, samples: isWebGL2 ? 4 : 0 }); } _this.getDrawingBufferSize(_vector23); if (isWebGL2) { _transmissionRenderTarget.setSize(_vector23.x, _vector23.y); } else { _transmissionRenderTarget.setSize(floorPowerOfTwo(_vector23.x), floorPowerOfTwo(_vector23.y)); } const currentRenderTarget = _this.getRenderTarget(); _this.setRenderTarget(_transmissionRenderTarget); _this.getClearColor(_currentClearColor); _currentClearAlpha = _this.getClearAlpha(); if (_currentClearAlpha < 1) _this.setClearColor(16777215, 0.5); _this.clear(); const currentToneMapping = _this.toneMapping; _this.toneMapping = NoToneMapping; renderObjects(opaqueObjects, scene3, camera3); textures.updateMultisampleRenderTarget(_transmissionRenderTarget); textures.updateRenderTargetMipmap(_transmissionRenderTarget); let renderTargetNeedsUpdate = false; for (let i = 0, l = transmissiveObjects.length; i < l; i++) { const renderItem = transmissiveObjects[i]; const object = renderItem.object; const geometry = renderItem.geometry; const material = renderItem.material; const group = renderItem.group; if (material.side === DoubleSide && object.layers.test(camera3.layers)) { const currentSide = material.side; material.side = BackSide; material.needsUpdate = true; renderObject(object, scene3, camera3, geometry, material, group); material.side = currentSide; material.needsUpdate = true; renderTargetNeedsUpdate = true; } } if (renderTargetNeedsUpdate === true) { textures.updateMultisampleRenderTarget(_transmissionRenderTarget); textures.updateRenderTargetMipmap(_transmissionRenderTarget); } _this.setRenderTarget(currentRenderTarget); _this.setClearColor(_currentClearColor, _currentClearAlpha); _this.toneMapping = currentToneMapping; } function renderObjects(renderList, scene3, camera3) { const overrideMaterial = scene3.isScene === true ? scene3.overrideMaterial : null; for (let i = 0, l = renderList.length; i < l; i++) { const renderItem = renderList[i]; const object = renderItem.object; const geometry = renderItem.geometry; const material = overrideMaterial === null ? renderItem.material : overrideMaterial; const group = renderItem.group; if (object.layers.test(camera3.layers)) { renderObject(object, scene3, camera3, geometry, material, group); } } } function renderObject(object, scene3, camera3, geometry, material, group) { object.onBeforeRender(_this, scene3, camera3, geometry, material, group); object.modelViewMatrix.multiplyMatrices(camera3.matrixWorldInverse, object.matrixWorld); object.normalMatrix.getNormalMatrix(object.modelViewMatrix); material.onBeforeRender(_this, scene3, camera3, geometry, object, group); if (material.transparent === true && material.side === DoubleSide && material.forceSinglePass === false) { material.side = BackSide; material.needsUpdate = true; _this.renderBufferDirect(camera3, scene3, geometry, material, object, group); material.side = FrontSide; material.needsUpdate = true; _this.renderBufferDirect(camera3, scene3, geometry, material, object, group); material.side = DoubleSide; } else { _this.renderBufferDirect(camera3, scene3, geometry, material, object, group); } object.onAfterRender(_this, scene3, camera3, geometry, material, group); } function getProgram(material, scene3, object) { if (scene3.isScene !== true) scene3 = _emptyScene; const materialProperties = properties.get(material); const lights = currentRenderState.state.lights; const shadowsArray = currentRenderState.state.shadowsArray; const lightsStateVersion = lights.state.version; const parameters2 = programCache.getParameters(material, lights.state, shadowsArray, scene3, object); const programCacheKey = programCache.getProgramCacheKey(parameters2); let programs = materialProperties.programs; materialProperties.environment = material.isMeshStandardMaterial ? scene3.environment : null; materialProperties.fog = scene3.fog; materialProperties.envMap = (material.isMeshStandardMaterial ? cubeuvmaps : cubemaps).get(material.envMap || materialProperties.environment); if (programs === void 0) { material.addEventListener("dispose", onMaterialDispose); programs = /* @__PURE__ */ new Map(); materialProperties.programs = programs; } let program = programs.get(programCacheKey); if (program !== void 0) { if (materialProperties.currentProgram === program && materialProperties.lightsStateVersion === lightsStateVersion) { updateCommonMaterialProperties(material, parameters2); return program; } } else { parameters2.uniforms = programCache.getUniforms(material); material.onBuild(object, parameters2, _this); material.onBeforeCompile(parameters2, _this); program = programCache.acquireProgram(parameters2, programCacheKey); programs.set(programCacheKey, program); materialProperties.uniforms = parameters2.uniforms; } const uniforms = materialProperties.uniforms; if (!material.isShaderMaterial && !material.isRawShaderMaterial || material.clipping === true) { uniforms.clippingPlanes = clipping.uniform; } updateCommonMaterialProperties(material, parameters2); materialProperties.needsLights = materialNeedsLights(material); materialProperties.lightsStateVersion = lightsStateVersion; if (materialProperties.needsLights) { uniforms.ambientLightColor.value = lights.state.ambient; uniforms.lightProbe.value = lights.state.probe; uniforms.directionalLights.value = lights.state.directional; uniforms.directionalLightShadows.value = lights.state.directionalShadow; uniforms.spotLights.value = lights.state.spot; uniforms.spotLightShadows.value = lights.state.spotShadow; uniforms.rectAreaLights.value = lights.state.rectArea; uniforms.ltc_1.value = lights.state.rectAreaLTC1; uniforms.ltc_2.value = lights.state.rectAreaLTC2; uniforms.pointLights.value = lights.state.point; uniforms.pointLightShadows.value = lights.state.pointShadow; uniforms.hemisphereLights.value = lights.state.hemi; uniforms.directionalShadowMap.value = lights.state.directionalShadowMap; uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix; uniforms.spotShadowMap.value = lights.state.spotShadowMap; uniforms.spotLightMatrix.value = lights.state.spotLightMatrix; uniforms.spotLightMap.value = lights.state.spotLightMap; uniforms.pointShadowMap.value = lights.state.pointShadowMap; uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; } materialProperties.currentProgram = program; materialProperties.uniformsList = null; return program; } function getUniformList(materialProperties) { if (materialProperties.uniformsList === null) { const progUniforms = materialProperties.currentProgram.getUniforms(); materialProperties.uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, materialProperties.uniforms); } return materialProperties.uniformsList; } function updateCommonMaterialProperties(material, parameters2) { const materialProperties = properties.get(material); materialProperties.outputColorSpace = parameters2.outputColorSpace; materialProperties.instancing = parameters2.instancing; materialProperties.instancingColor = parameters2.instancingColor; materialProperties.skinning = parameters2.skinning; materialProperties.morphTargets = parameters2.morphTargets; materialProperties.morphNormals = parameters2.morphNormals; materialProperties.morphColors = parameters2.morphColors; materialProperties.morphTargetsCount = parameters2.morphTargetsCount; materialProperties.numClippingPlanes = parameters2.numClippingPlanes; materialProperties.numIntersection = parameters2.numClipIntersection; materialProperties.vertexAlphas = parameters2.vertexAlphas; materialProperties.vertexTangents = parameters2.vertexTangents; materialProperties.toneMapping = parameters2.toneMapping; } function setProgram(camera3, scene3, geometry, material, object) { if (scene3.isScene !== true) scene3 = _emptyScene; textures.resetTextureUnits(); const fog = scene3.fog; const environment = material.isMeshStandardMaterial ? scene3.environment : null; const colorSpace = _currentRenderTarget === null ? _this.outputColorSpace : _currentRenderTarget.isXRRenderTarget === true ? _currentRenderTarget.texture.colorSpace : LinearSRGBColorSpace; const envMap = (material.isMeshStandardMaterial ? cubeuvmaps : cubemaps).get(material.envMap || environment); const vertexAlphas = material.vertexColors === true && !!geometry.attributes.color && geometry.attributes.color.itemSize === 4; const vertexTangents = !!geometry.attributes.tangent && (!!material.normalMap || material.anisotropy > 0); const morphTargets = !!geometry.morphAttributes.position; const morphNormals = !!geometry.morphAttributes.normal; const morphColors = !!geometry.morphAttributes.color; let toneMapping = NoToneMapping; if (material.toneMapped) { if (_currentRenderTarget === null || _currentRenderTarget.isXRRenderTarget === true) { toneMapping = _this.toneMapping; } } const morphAttribute = geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color; const morphTargetsCount = morphAttribute !== void 0 ? morphAttribute.length : 0; const materialProperties = properties.get(material); const lights = currentRenderState.state.lights; if (_clippingEnabled === true) { if (_localClippingEnabled === true || camera3 !== _currentCamera) { const useCache = camera3 === _currentCamera && material.id === _currentMaterialId; clipping.setState(material, camera3, useCache); } } let needsProgramChange = false; if (material.version === materialProperties.__version) { if (materialProperties.needsLights && materialProperties.lightsStateVersion !== lights.state.version) { needsProgramChange = true; } else if (materialProperties.outputColorSpace !== colorSpace) { needsProgramChange = true; } else if (object.isInstancedMesh && materialProperties.instancing === false) { needsProgramChange = true; } else if (!object.isInstancedMesh && materialProperties.instancing === true) { needsProgramChange = true; } else if (object.isSkinnedMesh && materialProperties.skinning === false) { needsProgramChange = true; } else if (!object.isSkinnedMesh && materialProperties.skinning === true) { needsProgramChange = true; } else if (object.isInstancedMesh && materialProperties.instancingColor === true && object.instanceColor === null) { needsProgramChange = true; } else if (object.isInstancedMesh && materialProperties.instancingColor === false && object.instanceColor !== null) { needsProgramChange = true; } else if (materialProperties.envMap !== envMap) { needsProgramChange = true; } else if (material.fog === true && materialProperties.fog !== fog) { needsProgramChange = true; } else if (materialProperties.numClippingPlanes !== void 0 && (materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection)) { needsProgramChange = true; } else if (materialProperties.vertexAlphas !== vertexAlphas) { needsProgramChange = true; } else if (materialProperties.vertexTangents !== vertexTangents) { needsProgramChange = true; } else if (materialProperties.morphTargets !== morphTargets) { needsProgramChange = true; } else if (materialProperties.morphNormals !== morphNormals) { needsProgramChange = true; } else if (materialProperties.morphColors !== morphColors) { needsProgramChange = true; } else if (materialProperties.toneMapping !== toneMapping) { needsProgramChange = true; } else if (capabilities.isWebGL2 === true && materialProperties.morphTargetsCount !== morphTargetsCount) { needsProgramChange = true; } } else { needsProgramChange = true; materialProperties.__version = material.version; } let program = materialProperties.currentProgram; if (needsProgramChange === true) { program = getProgram(material, scene3, object); } let refreshProgram = false; let refreshMaterial = false; let refreshLights = false; const p_uniforms = program.getUniforms(), m_uniforms = materialProperties.uniforms; if (state.useProgram(program.program)) { refreshProgram = true; refreshMaterial = true; refreshLights = true; } if (material.id !== _currentMaterialId) { _currentMaterialId = material.id; refreshMaterial = true; } if (refreshProgram || _currentCamera !== camera3) { p_uniforms.setValue(_gl, "projectionMatrix", camera3.projectionMatrix); p_uniforms.setValue(_gl, "viewMatrix", camera3.matrixWorldInverse); const uCamPos = p_uniforms.map.cameraPosition; if (uCamPos !== void 0) { uCamPos.setValue(_gl, _vector3.setFromMatrixPosition(camera3.matrixWorld)); } if (capabilities.logarithmicDepthBuffer) { p_uniforms.setValue( _gl, "logDepthBufFC", 2 / (Math.log(camera3.far + 1) / Math.LN2) ); } if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) { p_uniforms.setValue(_gl, "isOrthographic", camera3.isOrthographicCamera === true); } if (_currentCamera !== camera3) { _currentCamera = camera3; refreshMaterial = true; refreshLights = true; } } if (object.isSkinnedMesh) { p_uniforms.setOptional(_gl, object, "bindMatrix"); p_uniforms.setOptional(_gl, object, "bindMatrixInverse"); const skeleton = object.skeleton; if (skeleton) { if (capabilities.floatVertexTextures) { if (skeleton.boneTexture === null) skeleton.computeBoneTexture(); p_uniforms.setValue(_gl, "boneTexture", skeleton.boneTexture, textures); p_uniforms.setValue(_gl, "boneTextureSize", skeleton.boneTextureSize); } else { console.warn("THREE.WebGLRenderer: SkinnedMesh can only be used with WebGL 2. With WebGL 1 OES_texture_float and vertex textures support is required."); } } } const morphAttributes = geometry.morphAttributes; if (morphAttributes.position !== void 0 || morphAttributes.normal !== void 0 || morphAttributes.color !== void 0 && capabilities.isWebGL2 === true) { morphtargets.update(object, geometry, program); } if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) { materialProperties.receiveShadow = object.receiveShadow; p_uniforms.setValue(_gl, "receiveShadow", object.receiveShadow); } if (material.isMeshGouraudMaterial && material.envMap !== null) { m_uniforms.envMap.value = envMap; m_uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap.isRenderTargetTexture === false ? -1 : 1; } if (refreshMaterial) { p_uniforms.setValue(_gl, "toneMappingExposure", _this.toneMappingExposure); if (materialProperties.needsLights) { markUniformsLightsNeedsUpdate(m_uniforms, refreshLights); } if (fog && material.fog === true) { materials.refreshFogUniforms(m_uniforms, fog); } materials.refreshMaterialUniforms(m_uniforms, material, _pixelRatio, _height, _transmissionRenderTarget); WebGLUniforms.upload(_gl, getUniformList(materialProperties), m_uniforms, textures); } if (material.isShaderMaterial && material.uniformsNeedUpdate === true) { WebGLUniforms.upload(_gl, getUniformList(materialProperties), m_uniforms, textures); material.uniformsNeedUpdate = false; } if (material.isSpriteMaterial) { p_uniforms.setValue(_gl, "center", object.center); } p_uniforms.setValue(_gl, "modelViewMatrix", object.modelViewMatrix); p_uniforms.setValue(_gl, "normalMatrix", object.normalMatrix); p_uniforms.setValue(_gl, "modelMatrix", object.matrixWorld); if (material.isShaderMaterial || material.isRawShaderMaterial) { const groups = material.uniformsGroups; for (let i = 0, l = groups.length; i < l; i++) { if (capabilities.isWebGL2) { const group = groups[i]; uniformsGroups.update(group, program); uniformsGroups.bind(group, program); } else { console.warn("THREE.WebGLRenderer: Uniform Buffer Objects can only be used with WebGL 2."); } } } return program; } function markUniformsLightsNeedsUpdate(uniforms, value) { uniforms.ambientLightColor.needsUpdate = value; uniforms.lightProbe.needsUpdate = value; uniforms.directionalLights.needsUpdate = value; uniforms.directionalLightShadows.needsUpdate = value; uniforms.pointLights.needsUpdate = value; uniforms.pointLightShadows.needsUpdate = value; uniforms.spotLights.needsUpdate = value; uniforms.spotLightShadows.needsUpdate = value; uniforms.rectAreaLights.needsUpdate = value; uniforms.hemisphereLights.needsUpdate = value; } function materialNeedsLights(material) { return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isShadowMaterial || material.isShaderMaterial && material.lights === true; } this.getActiveCubeFace = function() { return _currentActiveCubeFace; }; this.getActiveMipmapLevel = function() { return _currentActiveMipmapLevel; }; this.getRenderTarget = function() { return _currentRenderTarget; }; this.setRenderTargetTextures = function(renderTarget, colorTexture, depthTexture) { properties.get(renderTarget.texture).__webglTexture = colorTexture; properties.get(renderTarget.depthTexture).__webglTexture = depthTexture; const renderTargetProperties = properties.get(renderTarget); renderTargetProperties.__hasExternalTextures = true; if (renderTargetProperties.__hasExternalTextures) { renderTargetProperties.__autoAllocateDepthBuffer = depthTexture === void 0; if (!renderTargetProperties.__autoAllocateDepthBuffer) { if (extensions.has("WEBGL_multisampled_render_to_texture") === true) { console.warn("THREE.WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided"); renderTargetProperties.__useRenderToTexture = false; } } } }; this.setRenderTargetFramebuffer = function(renderTarget, defaultFramebuffer) { const renderTargetProperties = properties.get(renderTarget); renderTargetProperties.__webglFramebuffer = defaultFramebuffer; renderTargetProperties.__useDefaultFramebuffer = defaultFramebuffer === void 0; }; this.setRenderTarget = function(renderTarget, activeCubeFace = 0, activeMipmapLevel = 0) { _currentRenderTarget = renderTarget; _currentActiveCubeFace = activeCubeFace; _currentActiveMipmapLevel = activeMipmapLevel; let useDefaultFramebuffer = true; let framebuffer = null; let isCube = false; let isRenderTarget3D = false; if (renderTarget) { const renderTargetProperties = properties.get(renderTarget); if (renderTargetProperties.__useDefaultFramebuffer !== void 0) { state.bindFramebuffer(_gl.FRAMEBUFFER, null); useDefaultFramebuffer = false; } else if (renderTargetProperties.__webglFramebuffer === void 0) { textures.setupRenderTarget(renderTarget); } else if (renderTargetProperties.__hasExternalTextures) { textures.rebindTextures(renderTarget, properties.get(renderTarget.texture).__webglTexture, properties.get(renderTarget.depthTexture).__webglTexture); } const texture = renderTarget.texture; if (texture.isData3DTexture || texture.isDataArrayTexture || texture.isCompressedArrayTexture) { isRenderTarget3D = true; } const __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer; if (renderTarget.isWebGLCubeRenderTarget) { if (Array.isArray(__webglFramebuffer[activeCubeFace])) { framebuffer = __webglFramebuffer[activeCubeFace][activeMipmapLevel]; } else { framebuffer = __webglFramebuffer[activeCubeFace]; } isCube = true; } else if (capabilities.isWebGL2 && renderTarget.samples > 0 && textures.useMultisampledRTT(renderTarget) === false) { framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer; } else { if (Array.isArray(__webglFramebuffer)) { framebuffer = __webglFramebuffer[activeMipmapLevel]; } else { framebuffer = __webglFramebuffer; } } _currentViewport.copy(renderTarget.viewport); _currentScissor.copy(renderTarget.scissor); _currentScissorTest = renderTarget.scissorTest; } else { _currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor(); _currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor(); _currentScissorTest = _scissorTest; } const framebufferBound = state.bindFramebuffer(_gl.FRAMEBUFFER, framebuffer); if (framebufferBound && capabilities.drawBuffers && useDefaultFramebuffer) { state.drawBuffers(renderTarget, framebuffer); } state.viewport(_currentViewport); state.scissor(_currentScissor); state.setScissorTest(_currentScissorTest); if (isCube) { const textureProperties = properties.get(renderTarget.texture); _gl.framebufferTexture2D(_gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel); } else if (isRenderTarget3D) { const textureProperties = properties.get(renderTarget.texture); const layer = activeCubeFace || 0; _gl.framebufferTextureLayer(_gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureProperties.__webglTexture, activeMipmapLevel || 0, layer); } _currentMaterialId = -1; }; this.readRenderTargetPixels = function(renderTarget, x3, y3, width, height, buffer, activeCubeFaceIndex) { if (!(renderTarget && renderTarget.isWebGLRenderTarget)) { console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget."); return; } let framebuffer = properties.get(renderTarget).__webglFramebuffer; if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== void 0) { framebuffer = framebuffer[activeCubeFaceIndex]; } if (framebuffer) { state.bindFramebuffer(_gl.FRAMEBUFFER, framebuffer); try { const texture = renderTarget.texture; const textureFormat = texture.format; const textureType = texture.type; if (textureFormat !== RGBAFormat && utils.convert(textureFormat) !== _gl.getParameter(_gl.IMPLEMENTATION_COLOR_READ_FORMAT)) { console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format."); return; } const halfFloatSupportedByExt = textureType === HalfFloatType && (extensions.has("EXT_color_buffer_half_float") || capabilities.isWebGL2 && extensions.has("EXT_color_buffer_float")); if (textureType !== UnsignedByteType && utils.convert(textureType) !== _gl.getParameter(_gl.IMPLEMENTATION_COLOR_READ_TYPE) && // Edge and Chrome Mac < 52 (#9513) !(textureType === FloatType && (capabilities.isWebGL2 || extensions.has("OES_texture_float") || extensions.has("WEBGL_color_buffer_float"))) && // Chrome Mac >= 52 and Firefox !halfFloatSupportedByExt) { console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type."); return; } if (x3 >= 0 && x3 <= renderTarget.width - width && (y3 >= 0 && y3 <= renderTarget.height - height)) { _gl.readPixels(x3, y3, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer); } } finally { const framebuffer2 = _currentRenderTarget !== null ? properties.get(_currentRenderTarget).__webglFramebuffer : null; state.bindFramebuffer(_gl.FRAMEBUFFER, framebuffer2); } } }; this.copyFramebufferToTexture = function(position, texture, level = 0) { const levelScale = Math.pow(2, -level); const width = Math.floor(texture.image.width * levelScale); const height = Math.floor(texture.image.height * levelScale); textures.setTexture2D(texture, 0); _gl.copyTexSubImage2D(_gl.TEXTURE_2D, level, 0, 0, position.x, position.y, width, height); state.unbindTexture(); }; this.copyTextureToTexture = function(position, srcTexture, dstTexture, level = 0) { const width = srcTexture.image.width; const height = srcTexture.image.height; const glFormat = utils.convert(dstTexture.format); const glType = utils.convert(dstTexture.type); textures.setTexture2D(dstTexture, 0); _gl.pixelStorei(_gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY); _gl.pixelStorei(_gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha); _gl.pixelStorei(_gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment); if (srcTexture.isDataTexture) { _gl.texSubImage2D(_gl.TEXTURE_2D, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data); } else { if (srcTexture.isCompressedTexture) { _gl.compressedTexSubImage2D(_gl.TEXTURE_2D, level, position.x, position.y, srcTexture.mipmaps[0].width, srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data); } else { _gl.texSubImage2D(_gl.TEXTURE_2D, level, position.x, position.y, glFormat, glType, srcTexture.image); } } if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(_gl.TEXTURE_2D); state.unbindTexture(); }; this.copyTextureToTexture3D = function(sourceBox, position, srcTexture, dstTexture, level = 0) { if (_this.isWebGL1Renderer) { console.warn("THREE.WebGLRenderer.copyTextureToTexture3D: can only be used with WebGL2."); return; } const width = sourceBox.max.x - sourceBox.min.x + 1; const height = sourceBox.max.y - sourceBox.min.y + 1; const depth2 = sourceBox.max.z - sourceBox.min.z + 1; const glFormat = utils.convert(dstTexture.format); const glType = utils.convert(dstTexture.type); let glTarget; if (dstTexture.isData3DTexture) { textures.setTexture3D(dstTexture, 0); glTarget = _gl.TEXTURE_3D; } else if (dstTexture.isDataArrayTexture) { textures.setTexture2DArray(dstTexture, 0); glTarget = _gl.TEXTURE_2D_ARRAY; } else { console.warn("THREE.WebGLRenderer.copyTextureToTexture3D: only supports THREE.DataTexture3D and THREE.DataTexture2DArray."); return; } _gl.pixelStorei(_gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY); _gl.pixelStorei(_gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha); _gl.pixelStorei(_gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment); const unpackRowLen = _gl.getParameter(_gl.UNPACK_ROW_LENGTH); const unpackImageHeight = _gl.getParameter(_gl.UNPACK_IMAGE_HEIGHT); const unpackSkipPixels = _gl.getParameter(_gl.UNPACK_SKIP_PIXELS); const unpackSkipRows = _gl.getParameter(_gl.UNPACK_SKIP_ROWS); const unpackSkipImages = _gl.getParameter(_gl.UNPACK_SKIP_IMAGES); const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[0] : srcTexture.image; _gl.pixelStorei(_gl.UNPACK_ROW_LENGTH, image.width); _gl.pixelStorei(_gl.UNPACK_IMAGE_HEIGHT, image.height); _gl.pixelStorei(_gl.UNPACK_SKIP_PIXELS, sourceBox.min.x); _gl.pixelStorei(_gl.UNPACK_SKIP_ROWS, sourceBox.min.y); _gl.pixelStorei(_gl.UNPACK_SKIP_IMAGES, sourceBox.min.z); if (srcTexture.isDataTexture || srcTexture.isData3DTexture) { _gl.texSubImage3D(glTarget, level, position.x, position.y, position.z, width, height, depth2, glFormat, glType, image.data); } else { if (srcTexture.isCompressedArrayTexture) { console.warn("THREE.WebGLRenderer.copyTextureToTexture3D: untested support for compressed srcTexture."); _gl.compressedTexSubImage3D(glTarget, level, position.x, position.y, position.z, width, height, depth2, glFormat, image.data); } else { _gl.texSubImage3D(glTarget, level, position.x, position.y, position.z, width, height, depth2, glFormat, glType, image); } } _gl.pixelStorei(_gl.UNPACK_ROW_LENGTH, unpackRowLen); _gl.pixelStorei(_gl.UNPACK_IMAGE_HEIGHT, unpackImageHeight); _gl.pixelStorei(_gl.UNPACK_SKIP_PIXELS, unpackSkipPixels); _gl.pixelStorei(_gl.UNPACK_SKIP_ROWS, unpackSkipRows); _gl.pixelStorei(_gl.UNPACK_SKIP_IMAGES, unpackSkipImages); if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(glTarget); state.unbindTexture(); }; this.initTexture = function(texture) { if (texture.isCubeTexture) { textures.setTextureCube(texture, 0); } else if (texture.isData3DTexture) { textures.setTexture3D(texture, 0); } else if (texture.isDataArrayTexture || texture.isCompressedArrayTexture) { textures.setTexture2DArray(texture, 0); } else { textures.setTexture2D(texture, 0); } state.unbindTexture(); }; this.resetState = function() { _currentActiveCubeFace = 0; _currentActiveMipmapLevel = 0; _currentRenderTarget = null; state.reset(); bindingStates.reset(); }; if (typeof __THREE_DEVTOOLS__ !== "undefined") { __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe", { detail: this })); } } get coordinateSystem() { return WebGLCoordinateSystem; } get outputColorSpace() { return this._outputColorSpace; } set outputColorSpace(colorSpace) { this._outputColorSpace = colorSpace; const gl = this.getContext(); gl.drawingBufferColorSpace = colorSpace === DisplayP3ColorSpace ? "display-p3" : "srgb"; gl.unpackColorSpace = ColorManagement.workingColorSpace === LinearDisplayP3ColorSpace ? "display-p3" : "srgb"; } get physicallyCorrectLights() { console.warn("THREE.WebGLRenderer: The property .physicallyCorrectLights has been removed. Set renderer.useLegacyLights instead."); return !this.useLegacyLights; } set physicallyCorrectLights(value) { console.warn("THREE.WebGLRenderer: The property .physicallyCorrectLights has been removed. Set renderer.useLegacyLights instead."); this.useLegacyLights = !value; } get outputEncoding() { console.warn("THREE.WebGLRenderer: Property .outputEncoding has been removed. Use .outputColorSpace instead."); return this.outputColorSpace === SRGBColorSpace ? sRGBEncoding : LinearEncoding; } set outputEncoding(encoding) { console.warn("THREE.WebGLRenderer: Property .outputEncoding has been removed. Use .outputColorSpace instead."); this.outputColorSpace = encoding === sRGBEncoding ? SRGBColorSpace : LinearSRGBColorSpace; } get useLegacyLights() { console.warn("THREE.WebGLRenderer: The property .useLegacyLights has been deprecated. Migrate your lighting according to the following guide: https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733."); return this._useLegacyLights; } set useLegacyLights(value) { console.warn("THREE.WebGLRenderer: The property .useLegacyLights has been deprecated. Migrate your lighting according to the following guide: https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733."); this._useLegacyLights = value; } }; var WebGL1Renderer = class extends WebGLRenderer { }; WebGL1Renderer.prototype.isWebGL1Renderer = true; function convertArray(array, type, forceClone) { if (!array || // let 'undefined' and 'null' pass !forceClone && array.constructor === type) return array; if (typeof type.BYTES_PER_ELEMENT === "number") { return new type(array); } return Array.prototype.slice.call(array); } function isTypedArray(object) { return ArrayBuffer.isView(object) && !(object instanceof DataView); } var Interpolant = class { constructor(parameterPositions, sampleValues, sampleSize, resultBuffer) { this.parameterPositions = parameterPositions; this._cachedIndex = 0; this.resultBuffer = resultBuffer !== void 0 ? resultBuffer : new sampleValues.constructor(sampleSize); this.sampleValues = sampleValues; this.valueSize = sampleSize; this.settings = null; this.DefaultSettings_ = {}; } evaluate(t) { const pp = this.parameterPositions; let i1 = this._cachedIndex, t1 = pp[i1], t0 = pp[i1 - 1]; validate_interval: { seek: { let right; linear_scan: { forward_scan: if (!(t < t1)) { for (let giveUpAt = i1 + 2; ; ) { if (t1 === void 0) { if (t < t0) break forward_scan; i1 = pp.length; this._cachedIndex = i1; return this.copySampleValue_(i1 - 1); } if (i1 === giveUpAt) break; t0 = t1; t1 = pp[++i1]; if (t < t1) { break seek; } } right = pp.length; break linear_scan; } if (!(t >= t0)) { const t1global = pp[1]; if (t < t1global) { i1 = 2; t0 = t1global; } for (let giveUpAt = i1 - 2; ; ) { if (t0 === void 0) { this._cachedIndex = 0; return this.copySampleValue_(0); } if (i1 === giveUpAt) break; t1 = t0; t0 = pp[--i1 - 1]; if (t >= t0) { break seek; } } right = i1; i1 = 0; break linear_scan; } break validate_interval; } while (i1 < right) { const mid = i1 + right >>> 1; if (t < pp[mid]) { right = mid; } else { i1 = mid + 1; } } t1 = pp[i1]; t0 = pp[i1 - 1]; if (t0 === void 0) { this._cachedIndex = 0; return this.copySampleValue_(0); } if (t1 === void 0) { i1 = pp.length; this._cachedIndex = i1; return this.copySampleValue_(i1 - 1); } } this._cachedIndex = i1; this.intervalChanged_(i1, t0, t1); } return this.interpolate_(i1, t0, t, t1); } getSettings_() { return this.settings || this.DefaultSettings_; } copySampleValue_(index6) { const result = this.resultBuffer, values = this.sampleValues, stride = this.valueSize, offset = index6 * stride; for (let i = 0; i !== stride; ++i) { result[i] = values[offset + i]; } return result; } // Template methods for derived classes: interpolate_() { throw new Error("call to abstract method"); } intervalChanged_() { } }; var CubicInterpolant = class extends Interpolant { constructor(parameterPositions, sampleValues, sampleSize, resultBuffer) { super(parameterPositions, sampleValues, sampleSize, resultBuffer); this._weightPrev = -0; this._offsetPrev = -0; this._weightNext = -0; this._offsetNext = -0; this.DefaultSettings_ = { endingStart: ZeroCurvatureEnding, endingEnd: ZeroCurvatureEnding }; } intervalChanged_(i1, t0, t1) { const pp = this.parameterPositions; let iPrev = i1 - 2, iNext = i1 + 1, tPrev = pp[iPrev], tNext = pp[iNext]; if (tPrev === void 0) { switch (this.getSettings_().endingStart) { case ZeroSlopeEnding: iPrev = i1; tPrev = 2 * t0 - t1; break; case WrapAroundEnding: iPrev = pp.length - 2; tPrev = t0 + pp[iPrev] - pp[iPrev + 1]; break; default: iPrev = i1; tPrev = t1; } } if (tNext === void 0) { switch (this.getSettings_().endingEnd) { case ZeroSlopeEnding: iNext = i1; tNext = 2 * t1 - t0; break; case WrapAroundEnding: iNext = 1; tNext = t1 + pp[1] - pp[0]; break; default: iNext = i1 - 1; tNext = t0; } } const halfDt = (t1 - t0) * 0.5, stride = this.valueSize; this._weightPrev = halfDt / (t0 - tPrev); this._weightNext = halfDt / (tNext - t1); this._offsetPrev = iPrev * stride; this._offsetNext = iNext * stride; } interpolate_(i1, t0, t, t1) { const result = this.resultBuffer, values = this.sampleValues, stride = this.valueSize, o1 = i1 * stride, o0 = o1 - stride, oP = this._offsetPrev, oN = this._offsetNext, wP = this._weightPrev, wN = this._weightNext, p = (t - t0) / (t1 - t0), pp = p * p, ppp = pp * p; const sP = -wP * ppp + 2 * wP * pp - wP * p; const s0 = (1 + wP) * ppp + (-1.5 - 2 * wP) * pp + (-0.5 + wP) * p + 1; const s1 = (-1 - wN) * ppp + (1.5 + wN) * pp + 0.5 * p; const sN = wN * ppp - wN * pp; for (let i = 0; i !== stride; ++i) { result[i] = sP * values[oP + i] + s0 * values[o0 + i] + s1 * values[o1 + i] + sN * values[oN + i]; } return result; } }; var LinearInterpolant = class extends Interpolant { constructor(parameterPositions, sampleValues, sampleSize, resultBuffer) { super(parameterPositions, sampleValues, sampleSize, resultBuffer); } interpolate_(i1, t0, t, t1) { const result = this.resultBuffer, values = this.sampleValues, stride = this.valueSize, offset1 = i1 * stride, offset0 = offset1 - stride, weight1 = (t - t0) / (t1 - t0), weight0 = 1 - weight1; for (let i = 0; i !== stride; ++i) { result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1; } return result; } }; var DiscreteInterpolant = class extends Interpolant { constructor(parameterPositions, sampleValues, sampleSize, resultBuffer) { super(parameterPositions, sampleValues, sampleSize, resultBuffer); } interpolate_(i1) { return this.copySampleValue_(i1 - 1); } }; var KeyframeTrack = class { constructor(name, times, values, interpolation) { if (name === void 0) throw new Error("THREE.KeyframeTrack: track name is undefined"); if (times === void 0 || times.length === 0) throw new Error("THREE.KeyframeTrack: no keyframes in track named " + name); this.name = name; this.times = convertArray(times, this.TimeBufferType); this.values = convertArray(values, this.ValueBufferType); this.setInterpolation(interpolation || this.DefaultInterpolation); } // Serialization (in static context, because of constructor invocation // and automatic invocation of .toJSON): static toJSON(track) { const trackType = track.constructor; let json; if (trackType.toJSON !== this.toJSON) { json = trackType.toJSON(track); } else { json = { "name": track.name, "times": convertArray(track.times, Array), "values": convertArray(track.values, Array) }; const interpolation = track.getInterpolation(); if (interpolation !== track.DefaultInterpolation) { json.interpolation = interpolation; } } json.type = track.ValueTypeName; return json; } InterpolantFactoryMethodDiscrete(result) { return new DiscreteInterpolant(this.times, this.values, this.getValueSize(), result); } InterpolantFactoryMethodLinear(result) { return new LinearInterpolant(this.times, this.values, this.getValueSize(), result); } InterpolantFactoryMethodSmooth(result) { return new CubicInterpolant(this.times, this.values, this.getValueSize(), result); } setInterpolation(interpolation) { let factoryMethod; switch (interpolation) { case InterpolateDiscrete: factoryMethod = this.InterpolantFactoryMethodDiscrete; break; case InterpolateLinear: factoryMethod = this.InterpolantFactoryMethodLinear; break; case InterpolateSmooth: factoryMethod = this.InterpolantFactoryMethodSmooth; break; } if (factoryMethod === void 0) { const message = "unsupported interpolation for " + this.ValueTypeName + " keyframe track named " + this.name; if (this.createInterpolant === void 0) { if (interpolation !== this.DefaultInterpolation) { this.setInterpolation(this.DefaultInterpolation); } else { throw new Error(message); } } console.warn("THREE.KeyframeTrack:", message); return this; } this.createInterpolant = factoryMethod; return this; } getInterpolation() { switch (this.createInterpolant) { case this.InterpolantFactoryMethodDiscrete: return InterpolateDiscrete; case this.InterpolantFactoryMethodLinear: return InterpolateLinear; case this.InterpolantFactoryMethodSmooth: return InterpolateSmooth; } } getValueSize() { return this.values.length / this.times.length; } // move all keyframes either forwards or backwards in time shift(timeOffset) { if (timeOffset !== 0) { const times = this.times; for (let i = 0, n = times.length; i !== n; ++i) { times[i] += timeOffset; } } return this; } // scale all keyframe times by a factor (useful for frame <-> seconds conversions) scale(timeScale) { if (timeScale !== 1) { const times = this.times; for (let i = 0, n = times.length; i !== n; ++i) { times[i] *= timeScale; } } return this; } // removes keyframes before and after animation without changing any values within the range [startTime, endTime]. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values trim(startTime, endTime) { const times = this.times, nKeys = times.length; let from = 0, to = nKeys - 1; while (from !== nKeys && times[from] < startTime) { ++from; } while (to !== -1 && times[to] > endTime) { --to; } ++to; if (from !== 0 || to !== nKeys) { if (from >= to) { to = Math.max(to, 1); from = to - 1; } const stride = this.getValueSize(); this.times = times.slice(from, to); this.values = this.values.slice(from * stride, to * stride); } return this; } // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable validate() { let valid = true; const valueSize = this.getValueSize(); if (valueSize - Math.floor(valueSize) !== 0) { console.error("THREE.KeyframeTrack: Invalid value size in track.", this); valid = false; } const times = this.times, values = this.values, nKeys = times.length; if (nKeys === 0) { console.error("THREE.KeyframeTrack: Track is empty.", this); valid = false; } let prevTime = null; for (let i = 0; i !== nKeys; i++) { const currTime = times[i]; if (typeof currTime === "number" && isNaN(currTime)) { console.error("THREE.KeyframeTrack: Time is not a valid number.", this, i, currTime); valid = false; break; } if (prevTime !== null && prevTime > currTime) { console.error("THREE.KeyframeTrack: Out of order keys.", this, i, currTime, prevTime); valid = false; break; } prevTime = currTime; } if (values !== void 0) { if (isTypedArray(values)) { for (let i = 0, n = values.length; i !== n; ++i) { const value = values[i]; if (isNaN(value)) { console.error("THREE.KeyframeTrack: Value is not a valid number.", this, i, value); valid = false; break; } } } } return valid; } // removes equivalent sequential keys as common in morph target sequences // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0) optimize() { const times = this.times.slice(), values = this.values.slice(), stride = this.getValueSize(), smoothInterpolation = this.getInterpolation() === InterpolateSmooth, lastIndex = times.length - 1; let writeIndex = 1; for (let i = 1; i < lastIndex; ++i) { let keep = false; const time = times[i]; const timeNext = times[i + 1]; if (time !== timeNext && (i !== 1 || time !== times[0])) { if (!smoothInterpolation) { const offset = i * stride, offsetP = offset - stride, offsetN = offset + stride; for (let j = 0; j !== stride; ++j) { const value = values[offset + j]; if (value !== values[offsetP + j] || value !== values[offsetN + j]) { keep = true; break; } } } else { keep = true; } } if (keep) { if (i !== writeIndex) { times[writeIndex] = times[i]; const readOffset = i * stride, writeOffset = writeIndex * stride; for (let j = 0; j !== stride; ++j) { values[writeOffset + j] = values[readOffset + j]; } } ++writeIndex; } } if (lastIndex > 0) { times[writeIndex] = times[lastIndex]; for (let readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++j) { values[writeOffset + j] = values[readOffset + j]; } ++writeIndex; } if (writeIndex !== times.length) { this.times = times.slice(0, writeIndex); this.values = values.slice(0, writeIndex * stride); } else { this.times = times; this.values = values; } return this; } clone() { const times = this.times.slice(); const values = this.values.slice(); const TypedKeyframeTrack = this.constructor; const track = new TypedKeyframeTrack(this.name, times, values); track.createInterpolant = this.createInterpolant; return track; } }; KeyframeTrack.prototype.TimeBufferType = Float32Array; KeyframeTrack.prototype.ValueBufferType = Float32Array; KeyframeTrack.prototype.DefaultInterpolation = InterpolateLinear; var BooleanKeyframeTrack = class extends KeyframeTrack { }; BooleanKeyframeTrack.prototype.ValueTypeName = "bool"; BooleanKeyframeTrack.prototype.ValueBufferType = Array; BooleanKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete; BooleanKeyframeTrack.prototype.InterpolantFactoryMethodLinear = void 0; BooleanKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = void 0; var ColorKeyframeTrack = class extends KeyframeTrack { }; ColorKeyframeTrack.prototype.ValueTypeName = "color"; var NumberKeyframeTrack = class extends KeyframeTrack { }; NumberKeyframeTrack.prototype.ValueTypeName = "number"; var QuaternionLinearInterpolant = class extends Interpolant { constructor(parameterPositions, sampleValues, sampleSize, resultBuffer) { super(parameterPositions, sampleValues, sampleSize, resultBuffer); } interpolate_(i1, t0, t, t1) { const result = this.resultBuffer, values = this.sampleValues, stride = this.valueSize, alpha = (t - t0) / (t1 - t0); let offset = i1 * stride; for (let end = offset + stride; offset !== end; offset += 4) { Quaternion.slerpFlat(result, 0, values, offset - stride, values, offset, alpha); } return result; } }; var QuaternionKeyframeTrack = class extends KeyframeTrack { InterpolantFactoryMethodLinear(result) { return new QuaternionLinearInterpolant(this.times, this.values, this.getValueSize(), result); } }; QuaternionKeyframeTrack.prototype.ValueTypeName = "quaternion"; QuaternionKeyframeTrack.prototype.DefaultInterpolation = InterpolateLinear; QuaternionKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = void 0; var StringKeyframeTrack = class extends KeyframeTrack { }; StringKeyframeTrack.prototype.ValueTypeName = "string"; StringKeyframeTrack.prototype.ValueBufferType = Array; StringKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete; StringKeyframeTrack.prototype.InterpolantFactoryMethodLinear = void 0; StringKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = void 0; var VectorKeyframeTrack = class extends KeyframeTrack { }; VectorKeyframeTrack.prototype.ValueTypeName = "vector"; var LoadingManager = class { constructor(onLoad, onProgress, onError) { const scope = this; let isLoading = false; let itemsLoaded = 0; let itemsTotal = 0; let urlModifier = void 0; const handlers = []; this.onStart = void 0; this.onLoad = onLoad; this.onProgress = onProgress; this.onError = onError; this.itemStart = function(url) { itemsTotal++; if (isLoading === false) { if (scope.onStart !== void 0) { scope.onStart(url, itemsLoaded, itemsTotal); } } isLoading = true; }; this.itemEnd = function(url) { itemsLoaded++; if (scope.onProgress !== void 0) { scope.onProgress(url, itemsLoaded, itemsTotal); } if (itemsLoaded === itemsTotal) { isLoading = false; if (scope.onLoad !== void 0) { scope.onLoad(); } } }; this.itemError = function(url) { if (scope.onError !== void 0) { scope.onError(url); } }; this.resolveURL = function(url) { if (urlModifier) { return urlModifier(url); } return url; }; this.setURLModifier = function(transform) { urlModifier = transform; return this; }; this.addHandler = function(regex, loader) { handlers.push(regex, loader); return this; }; this.removeHandler = function(regex) { const index6 = handlers.indexOf(regex); if (index6 !== -1) { handlers.splice(index6, 2); } return this; }; this.getHandler = function(file) { for (let i = 0, l = handlers.length; i < l; i += 2) { const regex = handlers[i]; const loader = handlers[i + 1]; if (regex.global) regex.lastIndex = 0; if (regex.test(file)) { return loader; } } return null; }; } }; var DefaultLoadingManager = /* @__PURE__ */ new LoadingManager(); var Loader = class { constructor(manager) { this.manager = manager !== void 0 ? manager : DefaultLoadingManager; this.crossOrigin = "anonymous"; this.withCredentials = false; this.path = ""; this.resourcePath = ""; this.requestHeader = {}; } load() { } loadAsync(url, onProgress) { const scope = this; return new Promise(function(resolve, reject) { scope.load(url, resolve, onProgress, reject); }); } parse() { } setCrossOrigin(crossOrigin) { this.crossOrigin = crossOrigin; return this; } setWithCredentials(value) { this.withCredentials = value; return this; } setPath(path) { this.path = path; return this; } setResourcePath(resourcePath) { this.resourcePath = resourcePath; return this; } setRequestHeader(requestHeader) { this.requestHeader = requestHeader; return this; } }; Loader.DEFAULT_MATERIAL_NAME = "__DEFAULT"; var Light = class extends Object3D { constructor(color, intensity = 1) { super(); this.isLight = true; this.type = "Light"; this.color = new Color(color); this.intensity = intensity; } dispose() { } copy(source, recursive) { super.copy(source, recursive); this.color.copy(source.color); this.intensity = source.intensity; return this; } toJSON(meta) { const data = super.toJSON(meta); data.object.color = this.color.getHex(); data.object.intensity = this.intensity; if (this.groundColor !== void 0) data.object.groundColor = this.groundColor.getHex(); if (this.distance !== void 0) data.object.distance = this.distance; if (this.angle !== void 0) data.object.angle = this.angle; if (this.decay !== void 0) data.object.decay = this.decay; if (this.penumbra !== void 0) data.object.penumbra = this.penumbra; if (this.shadow !== void 0) data.object.shadow = this.shadow.toJSON(); return data; } }; var _projScreenMatrix$1 = /* @__PURE__ */ new Matrix4(); var _lightPositionWorld$1 = /* @__PURE__ */ new Vector3(); var _lookTarget$1 = /* @__PURE__ */ new Vector3(); var LightShadow = class { constructor(camera3) { this.camera = camera3; this.bias = 0; this.normalBias = 0; this.radius = 1; this.blurSamples = 8; this.mapSize = new Vector2(512, 512); this.map = null; this.mapPass = null; this.matrix = new Matrix4(); this.autoUpdate = true; this.needsUpdate = false; this._frustum = new Frustum(); this._frameExtents = new Vector2(1, 1); this._viewportCount = 1; this._viewports = [ new Vector4(0, 0, 1, 1) ]; } getViewportCount() { return this._viewportCount; } getFrustum() { return this._frustum; } updateMatrices(light) { const shadowCamera = this.camera; const shadowMatrix = this.matrix; _lightPositionWorld$1.setFromMatrixPosition(light.matrixWorld); shadowCamera.position.copy(_lightPositionWorld$1); _lookTarget$1.setFromMatrixPosition(light.target.matrixWorld); shadowCamera.lookAt(_lookTarget$1); shadowCamera.updateMatrixWorld(); _projScreenMatrix$1.multiplyMatrices(shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse); this._frustum.setFromProjectionMatrix(_projScreenMatrix$1); shadowMatrix.set( 0.5, 0, 0, 0.5, 0, 0.5, 0, 0.5, 0, 0, 0.5, 0.5, 0, 0, 0, 1 ); shadowMatrix.multiply(_projScreenMatrix$1); } getViewport(viewportIndex) { return this._viewports[viewportIndex]; } getFrameExtents() { return this._frameExtents; } dispose() { if (this.map) { this.map.dispose(); } if (this.mapPass) { this.mapPass.dispose(); } } copy(source) { this.camera = source.camera.clone(); this.bias = source.bias; this.radius = source.radius; this.mapSize.copy(source.mapSize); return this; } clone() { return new this.constructor().copy(this); } toJSON() { const object = {}; if (this.bias !== 0) object.bias = this.bias; if (this.normalBias !== 0) object.normalBias = this.normalBias; if (this.radius !== 1) object.radius = this.radius; if (this.mapSize.x !== 512 || this.mapSize.y !== 512) object.mapSize = this.mapSize.toArray(); object.camera = this.camera.toJSON(false).object; delete object.camera.matrix; return object; } }; var DirectionalLightShadow = class extends LightShadow { constructor() { super(new OrthographicCamera(-5, 5, 5, -5, 0.5, 500)); this.isDirectionalLightShadow = true; } }; var DirectionalLight = class extends Light { constructor(color, intensity) { super(color, intensity); this.isDirectionalLight = true; this.type = "DirectionalLight"; this.position.copy(Object3D.DEFAULT_UP); this.updateMatrix(); this.target = new Object3D(); this.shadow = new DirectionalLightShadow(); } dispose() { this.shadow.dispose(); } copy(source) { super.copy(source); this.target = source.target.clone(); this.shadow = source.shadow.clone(); return this; } }; var AmbientLight = class extends Light { constructor(color, intensity) { super(color, intensity); this.isAmbientLight = true; this.type = "AmbientLight"; } }; var _RESERVED_CHARS_RE = "\\[\\]\\.:\\/"; var _reservedRe = new RegExp("[" + _RESERVED_CHARS_RE + "]", "g"); var _wordChar = "[^" + _RESERVED_CHARS_RE + "]"; var _wordCharOrDot = "[^" + _RESERVED_CHARS_RE.replace("\\.", "") + "]"; var _directoryRe = /* @__PURE__ */ /((?:WC+[\/:])*)/.source.replace("WC", _wordChar); var _nodeRe = /* @__PURE__ */ /(WCOD+)?/.source.replace("WCOD", _wordCharOrDot); var _objectRe = /* @__PURE__ */ /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC", _wordChar); var _propertyRe = /* @__PURE__ */ /\.(WC+)(?:\[(.+)\])?/.source.replace("WC", _wordChar); var _trackRe = new RegExp( "^" + _directoryRe + _nodeRe + _objectRe + _propertyRe + "$" ); var _supportedObjectNames = ["material", "materials", "bones", "map"]; var Composite = class { constructor(targetGroup, path, optionalParsedPath) { const parsedPath = optionalParsedPath || PropertyBinding.parseTrackName(path); this._targetGroup = targetGroup; this._bindings = targetGroup.subscribe_(path, parsedPath); } getValue(array, offset) { this.bind(); const firstValidIndex = this._targetGroup.nCachedObjects_, binding = this._bindings[firstValidIndex]; if (binding !== void 0) binding.getValue(array, offset); } setValue(array, offset) { const bindings = this._bindings; for (let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) { bindings[i].setValue(array, offset); } } bind() { const bindings = this._bindings; for (let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) { bindings[i].bind(); } } unbind() { const bindings = this._bindings; for (let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) { bindings[i].unbind(); } } }; var PropertyBinding = class { constructor(rootNode, path, parsedPath) { this.path = path; this.parsedPath = parsedPath || PropertyBinding.parseTrackName(path); this.node = PropertyBinding.findNode(rootNode, this.parsedPath.nodeName); this.rootNode = rootNode; this.getValue = this._getValue_unbound; this.setValue = this._setValue_unbound; } static create(root2, path, parsedPath) { if (!(root2 && root2.isAnimationObjectGroup)) { return new PropertyBinding(root2, path, parsedPath); } else { return new PropertyBinding.Composite(root2, path, parsedPath); } } /** * Replaces spaces with underscores and removes unsupported characters from * node names, to ensure compatibility with parseTrackName(). * * @param {string} name Node name to be sanitized. * @return {string} */ static sanitizeNodeName(name) { return name.replace(/\s/g, "_").replace(_reservedRe, ""); } static parseTrackName(trackName) { const matches = _trackRe.exec(trackName); if (matches === null) { throw new Error("PropertyBinding: Cannot parse trackName: " + trackName); } const results = { // directoryName: matches[ 1 ], // (tschw) currently unused nodeName: matches[2], objectName: matches[3], objectIndex: matches[4], propertyName: matches[5], // required propertyIndex: matches[6] }; const lastDot = results.nodeName && results.nodeName.lastIndexOf("."); if (lastDot !== void 0 && lastDot !== -1) { const objectName = results.nodeName.substring(lastDot + 1); if (_supportedObjectNames.indexOf(objectName) !== -1) { results.nodeName = results.nodeName.substring(0, lastDot); results.objectName = objectName; } } if (results.propertyName === null || results.propertyName.length === 0) { throw new Error("PropertyBinding: can not parse propertyName from trackName: " + trackName); } return results; } static findNode(root2, nodeName) { if (nodeName === void 0 || nodeName === "" || nodeName === "." || nodeName === -1 || nodeName === root2.name || nodeName === root2.uuid) { return root2; } if (root2.skeleton) { const bone = root2.skeleton.getBoneByName(nodeName); if (bone !== void 0) { return bone; } } if (root2.children) { const searchNodeSubtree = function(children) { for (let i = 0; i < children.length; i++) { const childNode = children[i]; if (childNode.name === nodeName || childNode.uuid === nodeName) { return childNode; } const result = searchNodeSubtree(childNode.children); if (result) return result; } return null; }; const subTreeNode = searchNodeSubtree(root2.children); if (subTreeNode) { return subTreeNode; } } return null; } // these are used to "bind" a nonexistent property _getValue_unavailable() { } _setValue_unavailable() { } // Getters _getValue_direct(buffer, offset) { buffer[offset] = this.targetObject[this.propertyName]; } _getValue_array(buffer, offset) { const source = this.resolvedProperty; for (let i = 0, n = source.length; i !== n; ++i) { buffer[offset++] = source[i]; } } _getValue_arrayElement(buffer, offset) { buffer[offset] = this.resolvedProperty[this.propertyIndex]; } _getValue_toArray(buffer, offset) { this.resolvedProperty.toArray(buffer, offset); } // Direct _setValue_direct(buffer, offset) { this.targetObject[this.propertyName] = buffer[offset]; } _setValue_direct_setNeedsUpdate(buffer, offset) { this.targetObject[this.propertyName] = buffer[offset]; this.targetObject.needsUpdate = true; } _setValue_direct_setMatrixWorldNeedsUpdate(buffer, offset) { this.targetObject[this.propertyName] = buffer[offset]; this.targetObject.matrixWorldNeedsUpdate = true; } // EntireArray _setValue_array(buffer, offset) { const dest = this.resolvedProperty; for (let i = 0, n = dest.length; i !== n; ++i) { dest[i] = buffer[offset++]; } } _setValue_array_setNeedsUpdate(buffer, offset) { const dest = this.resolvedProperty; for (let i = 0, n = dest.length; i !== n; ++i) { dest[i] = buffer[offset++]; } this.targetObject.needsUpdate = true; } _setValue_array_setMatrixWorldNeedsUpdate(buffer, offset) { const dest = this.resolvedProperty; for (let i = 0, n = dest.length; i !== n; ++i) { dest[i] = buffer[offset++]; } this.targetObject.matrixWorldNeedsUpdate = true; } // ArrayElement _setValue_arrayElement(buffer, offset) { this.resolvedProperty[this.propertyIndex] = buffer[offset]; } _setValue_arrayElement_setNeedsUpdate(buffer, offset) { this.resolvedProperty[this.propertyIndex] = buffer[offset]; this.targetObject.needsUpdate = true; } _setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer, offset) { this.resolvedProperty[this.propertyIndex] = buffer[offset]; this.targetObject.matrixWorldNeedsUpdate = true; } // HasToFromArray _setValue_fromArray(buffer, offset) { this.resolvedProperty.fromArray(buffer, offset); } _setValue_fromArray_setNeedsUpdate(buffer, offset) { this.resolvedProperty.fromArray(buffer, offset); this.targetObject.needsUpdate = true; } _setValue_fromArray_setMatrixWorldNeedsUpdate(buffer, offset) { this.resolvedProperty.fromArray(buffer, offset); this.targetObject.matrixWorldNeedsUpdate = true; } _getValue_unbound(targetArray, offset) { this.bind(); this.getValue(targetArray, offset); } _setValue_unbound(sourceArray, offset) { this.bind(); this.setValue(sourceArray, offset); } // create getter / setter pair for a property in the scene graph bind() { let targetObject = this.node; const parsedPath = this.parsedPath; const objectName = parsedPath.objectName; const propertyName = parsedPath.propertyName; let propertyIndex = parsedPath.propertyIndex; if (!targetObject) { targetObject = PropertyBinding.findNode(this.rootNode, parsedPath.nodeName); this.node = targetObject; } this.getValue = this._getValue_unavailable; this.setValue = this._setValue_unavailable; if (!targetObject) { console.warn("THREE.PropertyBinding: No target node found for track: " + this.path + "."); return; } if (objectName) { let objectIndex = parsedPath.objectIndex; switch (objectName) { case "materials": if (!targetObject.material) { console.error("THREE.PropertyBinding: Can not bind to material as node does not have a material.", this); return; } if (!targetObject.material.materials) { console.error("THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.", this); return; } targetObject = targetObject.material.materials; break; case "bones": if (!targetObject.skeleton) { console.error("THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.", this); return; } targetObject = targetObject.skeleton.bones; for (let i = 0; i < targetObject.length; i++) { if (targetObject[i].name === objectIndex) { objectIndex = i; break; } } break; case "map": if ("map" in targetObject) { targetObject = targetObject.map; break; } if (!targetObject.material) { console.error("THREE.PropertyBinding: Can not bind to material as node does not have a material.", this); return; } if (!targetObject.material.map) { console.error("THREE.PropertyBinding: Can not bind to material.map as node.material does not have a map.", this); return; } targetObject = targetObject.material.map; break; default: if (targetObject[objectName] === void 0) { console.error("THREE.PropertyBinding: Can not bind to objectName of node undefined.", this); return; } targetObject = targetObject[objectName]; } if (objectIndex !== void 0) { if (targetObject[objectIndex] === void 0) { console.error("THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.", this, targetObject); return; } targetObject = targetObject[objectIndex]; } } const nodeProperty = targetObject[propertyName]; if (nodeProperty === void 0) { const nodeName = parsedPath.nodeName; console.error("THREE.PropertyBinding: Trying to update property for track: " + nodeName + "." + propertyName + " but it wasn't found.", targetObject); return; } let versioning = this.Versioning.None; this.targetObject = targetObject; if (targetObject.needsUpdate !== void 0) { versioning = this.Versioning.NeedsUpdate; } else if (targetObject.matrixWorldNeedsUpdate !== void 0) { versioning = this.Versioning.MatrixWorldNeedsUpdate; } let bindingType = this.BindingType.Direct; if (propertyIndex !== void 0) { if (propertyName === "morphTargetInfluences") { if (!targetObject.geometry) { console.error("THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.", this); return; } if (!targetObject.geometry.morphAttributes) { console.error("THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.", this); return; } if (targetObject.morphTargetDictionary[propertyIndex] !== void 0) { propertyIndex = targetObject.morphTargetDictionary[propertyIndex]; } } bindingType = this.BindingType.ArrayElement; this.resolvedProperty = nodeProperty; this.propertyIndex = propertyIndex; } else if (nodeProperty.fromArray !== void 0 && nodeProperty.toArray !== void 0) { bindingType = this.BindingType.HasFromToArray; this.resolvedProperty = nodeProperty; } else if (Array.isArray(nodeProperty)) { bindingType = this.BindingType.EntireArray; this.resolvedProperty = nodeProperty; } else { this.propertyName = propertyName; } this.getValue = this.GetterByBindingType[bindingType]; this.setValue = this.SetterByBindingTypeAndVersioning[bindingType][versioning]; } unbind() { this.node = null; this.getValue = this._getValue_unbound; this.setValue = this._setValue_unbound; } }; PropertyBinding.Composite = Composite; PropertyBinding.prototype.BindingType = { Direct: 0, EntireArray: 1, ArrayElement: 2, HasFromToArray: 3 }; PropertyBinding.prototype.Versioning = { None: 0, NeedsUpdate: 1, MatrixWorldNeedsUpdate: 2 }; PropertyBinding.prototype.GetterByBindingType = [ PropertyBinding.prototype._getValue_direct, PropertyBinding.prototype._getValue_array, PropertyBinding.prototype._getValue_arrayElement, PropertyBinding.prototype._getValue_toArray ]; PropertyBinding.prototype.SetterByBindingTypeAndVersioning = [ [ // Direct PropertyBinding.prototype._setValue_direct, PropertyBinding.prototype._setValue_direct_setNeedsUpdate, PropertyBinding.prototype._setValue_direct_setMatrixWorldNeedsUpdate ], [ // EntireArray PropertyBinding.prototype._setValue_array, PropertyBinding.prototype._setValue_array_setNeedsUpdate, PropertyBinding.prototype._setValue_array_setMatrixWorldNeedsUpdate ], [ // ArrayElement PropertyBinding.prototype._setValue_arrayElement, PropertyBinding.prototype._setValue_arrayElement_setNeedsUpdate, PropertyBinding.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate ], [ // HasToFromArray PropertyBinding.prototype._setValue_fromArray, PropertyBinding.prototype._setValue_fromArray_setNeedsUpdate, PropertyBinding.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate ] ]; var _controlInterpolantsResultBuffer = new Float32Array(1); var Raycaster = class { constructor(origin3, direction, near = 0, far = Infinity) { this.ray = new Ray(origin3, direction); this.near = near; this.far = far; this.camera = null; this.layers = new Layers(); this.params = { Mesh: {}, Line: { threshold: 1 }, LOD: {}, Points: { threshold: 1 }, Sprite: {} }; } set(origin3, direction) { this.ray.set(origin3, direction); } setFromCamera(coords, camera3) { if (camera3.isPerspectiveCamera) { this.ray.origin.setFromMatrixPosition(camera3.matrixWorld); this.ray.direction.set(coords.x, coords.y, 0.5).unproject(camera3).sub(this.ray.origin).normalize(); this.camera = camera3; } else if (camera3.isOrthographicCamera) { this.ray.origin.set(coords.x, coords.y, (camera3.near + camera3.far) / (camera3.near - camera3.far)).unproject(camera3); this.ray.direction.set(0, 0, -1).transformDirection(camera3.matrixWorld); this.camera = camera3; } else { console.error("THREE.Raycaster: Unsupported camera type: " + camera3.type); } } intersectObject(object, recursive = true, intersects = []) { intersectObject(object, this, intersects, recursive); intersects.sort(ascSort); return intersects; } intersectObjects(objects, recursive = true, intersects = []) { for (let i = 0, l = objects.length; i < l; i++) { intersectObject(objects[i], this, intersects, recursive); } intersects.sort(ascSort); return intersects; } }; function ascSort(a2, b) { return a2.distance - b.distance; } function intersectObject(object, raycaster, intersects, recursive) { if (object.layers.test(raycaster.layers)) { object.raycast(raycaster, intersects); } if (recursive === true) { const children = object.children; for (let i = 0, l = children.length; i < l; i++) { intersectObject(children[i], raycaster, intersects, true); } } } if (typeof __THREE_DEVTOOLS__ !== "undefined") { __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register", { detail: { revision: REVISION } })); } if (typeof window !== "undefined") { if (window.__THREE__) { console.warn("WARNING: Multiple instances of Three.js being imported."); } else { window.__THREE__ = REVISION; } } // node_modules/3d-force-graph/node_modules/three/examples/jsm/controls/DragControls.js var _plane = new Plane(); var _raycaster = new Raycaster(); var _pointer = new Vector2(); var _offset2 = new Vector3(); var _intersection = new Vector3(); var _worldPosition = new Vector3(); var _inverseMatrix = new Matrix4(); var DragControls = class extends EventDispatcher { constructor(_objects, _camera2, _domElement) { super(); _domElement.style.touchAction = "none"; let _selected = null, _hovered = null; const _intersections = []; const scope = this; function activate() { _domElement.addEventListener("pointermove", onPointerMove); _domElement.addEventListener("pointerdown", onPointerDown); _domElement.addEventListener("pointerup", onPointerCancel); _domElement.addEventListener("pointerleave", onPointerCancel); } function deactivate() { _domElement.removeEventListener("pointermove", onPointerMove); _domElement.removeEventListener("pointerdown", onPointerDown); _domElement.removeEventListener("pointerup", onPointerCancel); _domElement.removeEventListener("pointerleave", onPointerCancel); _domElement.style.cursor = ""; } function dispose() { deactivate(); } function getObjects() { return _objects; } function getRaycaster() { return _raycaster; } function onPointerMove(event) { if (scope.enabled === false) return; updatePointer(event); _raycaster.setFromCamera(_pointer, _camera2); if (_selected) { if (_raycaster.ray.intersectPlane(_plane, _intersection)) { _selected.position.copy(_intersection.sub(_offset2).applyMatrix4(_inverseMatrix)); } scope.dispatchEvent({ type: "drag", object: _selected }); return; } if (event.pointerType === "mouse" || event.pointerType === "pen") { _intersections.length = 0; _raycaster.setFromCamera(_pointer, _camera2); _raycaster.intersectObjects(_objects, scope.recursive, _intersections); if (_intersections.length > 0) { const object = _intersections[0].object; _plane.setFromNormalAndCoplanarPoint(_camera2.getWorldDirection(_plane.normal), _worldPosition.setFromMatrixPosition(object.matrixWorld)); if (_hovered !== object && _hovered !== null) { scope.dispatchEvent({ type: "hoveroff", object: _hovered }); _domElement.style.cursor = "auto"; _hovered = null; } if (_hovered !== object) { scope.dispatchEvent({ type: "hoveron", object }); _domElement.style.cursor = "pointer"; _hovered = object; } } else { if (_hovered !== null) { scope.dispatchEvent({ type: "hoveroff", object: _hovered }); _domElement.style.cursor = "auto"; _hovered = null; } } } } function onPointerDown(event) { if (scope.enabled === false) return; updatePointer(event); _intersections.length = 0; _raycaster.setFromCamera(_pointer, _camera2); _raycaster.intersectObjects(_objects, scope.recursive, _intersections); if (_intersections.length > 0) { _selected = scope.transformGroup === true ? _objects[0] : _intersections[0].object; _plane.setFromNormalAndCoplanarPoint(_camera2.getWorldDirection(_plane.normal), _worldPosition.setFromMatrixPosition(_selected.matrixWorld)); if (_raycaster.ray.intersectPlane(_plane, _intersection)) { _inverseMatrix.copy(_selected.parent.matrixWorld).invert(); _offset2.copy(_intersection).sub(_worldPosition.setFromMatrixPosition(_selected.matrixWorld)); } _domElement.style.cursor = "move"; scope.dispatchEvent({ type: "dragstart", object: _selected }); } } function onPointerCancel() { if (scope.enabled === false) return; if (_selected) { scope.dispatchEvent({ type: "dragend", object: _selected }); _selected = null; } _domElement.style.cursor = _hovered ? "pointer" : "auto"; } function updatePointer(event) { const rect = _domElement.getBoundingClientRect(); _pointer.x = (event.clientX - rect.left) / rect.width * 2 - 1; _pointer.y = -(event.clientY - rect.top) / rect.height * 2 + 1; } activate(); this.enabled = true; this.recursive = true; this.transformGroup = false; this.activate = activate; this.deactivate = deactivate; this.dispose = dispose; this.getObjects = getObjects; this.getRaycaster = getRaycaster; } }; // node_modules/three/build/three.module.js var REVISION2 = "157"; var MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 }; var TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 }; var CullFaceNone2 = 0; var CullFaceBack2 = 1; var CullFaceFront2 = 2; var PCFShadowMap2 = 1; var PCFSoftShadowMap2 = 2; var VSMShadowMap2 = 3; var FrontSide2 = 0; var BackSide2 = 1; var DoubleSide2 = 2; var NoBlending2 = 0; var NormalBlending2 = 1; var AdditiveBlending2 = 2; var SubtractiveBlending2 = 3; var MultiplyBlending2 = 4; var CustomBlending2 = 5; var AddEquation2 = 100; var SubtractEquation2 = 101; var ReverseSubtractEquation2 = 102; var MinEquation2 = 103; var MaxEquation2 = 104; var ZeroFactor2 = 200; var OneFactor2 = 201; var SrcColorFactor2 = 202; var OneMinusSrcColorFactor2 = 203; var SrcAlphaFactor2 = 204; var OneMinusSrcAlphaFactor2 = 205; var DstAlphaFactor2 = 206; var OneMinusDstAlphaFactor2 = 207; var DstColorFactor2 = 208; var OneMinusDstColorFactor2 = 209; var SrcAlphaSaturateFactor2 = 210; var NeverDepth2 = 0; var AlwaysDepth2 = 1; var LessDepth2 = 2; var LessEqualDepth2 = 3; var EqualDepth2 = 4; var GreaterEqualDepth2 = 5; var GreaterDepth2 = 6; var NotEqualDepth2 = 7; var MultiplyOperation2 = 0; var MixOperation2 = 1; var AddOperation2 = 2; var NoToneMapping2 = 0; var LinearToneMapping2 = 1; var ReinhardToneMapping2 = 2; var CineonToneMapping2 = 3; var ACESFilmicToneMapping2 = 4; var CustomToneMapping2 = 5; var UVMapping2 = 300; var CubeReflectionMapping2 = 301; var CubeRefractionMapping2 = 302; var EquirectangularReflectionMapping2 = 303; var EquirectangularRefractionMapping2 = 304; var CubeUVReflectionMapping2 = 306; var RepeatWrapping2 = 1e3; var ClampToEdgeWrapping2 = 1001; var MirroredRepeatWrapping2 = 1002; var NearestFilter2 = 1003; var NearestMipmapNearestFilter2 = 1004; var NearestMipmapLinearFilter2 = 1005; var LinearFilter2 = 1006; var LinearMipmapNearestFilter2 = 1007; var LinearMipmapLinearFilter2 = 1008; var UnsignedByteType2 = 1009; var ByteType2 = 1010; var ShortType2 = 1011; var UnsignedShortType2 = 1012; var IntType2 = 1013; var UnsignedIntType2 = 1014; var FloatType2 = 1015; var HalfFloatType2 = 1016; var UnsignedShort4444Type2 = 1017; var UnsignedShort5551Type2 = 1018; var UnsignedInt248Type2 = 1020; var AlphaFormat2 = 1021; var RGBAFormat2 = 1023; var LuminanceFormat2 = 1024; var LuminanceAlphaFormat2 = 1025; var DepthFormat2 = 1026; var DepthStencilFormat2 = 1027; var RedFormat2 = 1028; var RedIntegerFormat2 = 1029; var RGFormat2 = 1030; var RGIntegerFormat2 = 1031; var RGBAIntegerFormat2 = 1033; var RGB_S3TC_DXT1_Format2 = 33776; var RGBA_S3TC_DXT1_Format2 = 33777; var RGBA_S3TC_DXT3_Format2 = 33778; var RGBA_S3TC_DXT5_Format2 = 33779; var RGB_PVRTC_4BPPV1_Format2 = 35840; var RGB_PVRTC_2BPPV1_Format2 = 35841; var RGBA_PVRTC_4BPPV1_Format2 = 35842; var RGBA_PVRTC_2BPPV1_Format2 = 35843; var RGB_ETC1_Format2 = 36196; var RGB_ETC2_Format2 = 37492; var RGBA_ETC2_EAC_Format2 = 37496; var RGBA_ASTC_4x4_Format2 = 37808; var RGBA_ASTC_5x4_Format2 = 37809; var RGBA_ASTC_5x5_Format2 = 37810; var RGBA_ASTC_6x5_Format2 = 37811; var RGBA_ASTC_6x6_Format2 = 37812; var RGBA_ASTC_8x5_Format2 = 37813; var RGBA_ASTC_8x6_Format2 = 37814; var RGBA_ASTC_8x8_Format2 = 37815; var RGBA_ASTC_10x5_Format2 = 37816; var RGBA_ASTC_10x6_Format2 = 37817; var RGBA_ASTC_10x8_Format2 = 37818; var RGBA_ASTC_10x10_Format2 = 37819; var RGBA_ASTC_12x10_Format2 = 37820; var RGBA_ASTC_12x12_Format2 = 37821; var RGBA_BPTC_Format2 = 36492; var RGB_BPTC_SIGNED_Format2 = 36494; var RGB_BPTC_UNSIGNED_Format2 = 36495; var RED_RGTC1_Format2 = 36283; var SIGNED_RED_RGTC1_Format2 = 36284; var RED_GREEN_RGTC2_Format2 = 36285; var SIGNED_RED_GREEN_RGTC2_Format2 = 36286; var InterpolateDiscrete2 = 2300; var InterpolateLinear2 = 2301; var InterpolateSmooth2 = 2302; var ZeroCurvatureEnding2 = 2400; var ZeroSlopeEnding2 = 2401; var WrapAroundEnding2 = 2402; var LinearEncoding2 = 3e3; var sRGBEncoding2 = 3001; var BasicDepthPacking2 = 3200; var RGBADepthPacking2 = 3201; var TangentSpaceNormalMap2 = 0; var ObjectSpaceNormalMap2 = 1; var NoColorSpace2 = ""; var SRGBColorSpace2 = "srgb"; var LinearSRGBColorSpace2 = "srgb-linear"; var DisplayP3ColorSpace2 = "display-p3"; var LinearDisplayP3ColorSpace2 = "display-p3-linear"; var LinearTransfer2 = "linear"; var SRGBTransfer2 = "srgb"; var Rec709Primaries2 = "rec709"; var P3Primaries2 = "p3"; var KeepStencilOp2 = 7680; var AlwaysStencilFunc2 = 519; var NeverCompare2 = 512; var LessCompare2 = 513; var EqualCompare2 = 514; var LessEqualCompare2 = 515; var GreaterCompare2 = 516; var NotEqualCompare2 = 517; var GreaterEqualCompare2 = 518; var AlwaysCompare2 = 519; var StaticDrawUsage2 = 35044; var GLSL32 = "300 es"; var _SRGBAFormat2 = 1035; var WebGLCoordinateSystem2 = 2e3; var WebGPUCoordinateSystem2 = 2001; var EventDispatcher2 = class { addEventListener(type, listener) { if (this._listeners === void 0) this._listeners = {}; const listeners = this._listeners; if (listeners[type] === void 0) { listeners[type] = []; } if (listeners[type].indexOf(listener) === -1) { listeners[type].push(listener); } } hasEventListener(type, listener) { if (this._listeners === void 0) return false; const listeners = this._listeners; return listeners[type] !== void 0 && listeners[type].indexOf(listener) !== -1; } removeEventListener(type, listener) { if (this._listeners === void 0) return; const listeners = this._listeners; const listenerArray = listeners[type]; if (listenerArray !== void 0) { const index6 = listenerArray.indexOf(listener); if (index6 !== -1) { listenerArray.splice(index6, 1); } } } dispatchEvent(event) { if (this._listeners === void 0) return; const listeners = this._listeners; const listenerArray = listeners[event.type]; if (listenerArray !== void 0) { event.target = this; const array = listenerArray.slice(0); for (let i = 0, l = array.length; i < l; i++) { array[i].call(this, event); } event.target = null; } } }; var _lut2 = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a", "0b", "0c", "0d", "0e", "0f", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1a", "1b", "1c", "1d", "1e", "1f", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2a", "2b", "2c", "2d", "2e", "2f", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3a", "3b", "3c", "3d", "3e", "3f", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", "4f", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5a", "5b", "5c", "5d", "5e", "5f", "60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6a", "6b", "6c", "6d", "6e", "6f", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7a", "7b", "7c", "7d", "7e", "7f", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8a", "8b", "8c", "8d", "8e", "8f", "90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9a", "9b", "9c", "9d", "9e", "9f", "a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "aa", "ab", "ac", "ad", "ae", "af", "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "ba", "bb", "bc", "bd", "be", "bf", "c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "ca", "cb", "cc", "cd", "ce", "cf", "d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "da", "db", "dc", "dd", "de", "df", "e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "ea", "eb", "ec", "ed", "ee", "ef", "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe", "ff"]; var _seed = 1234567; var DEG2RAD2 = Math.PI / 180; var RAD2DEG2 = 180 / Math.PI; function generateUUID2() { const d0 = Math.random() * 4294967295 | 0; const d1 = Math.random() * 4294967295 | 0; const d2 = Math.random() * 4294967295 | 0; const d3 = Math.random() * 4294967295 | 0; const uuid = _lut2[d0 & 255] + _lut2[d0 >> 8 & 255] + _lut2[d0 >> 16 & 255] + _lut2[d0 >> 24 & 255] + "-" + _lut2[d1 & 255] + _lut2[d1 >> 8 & 255] + "-" + _lut2[d1 >> 16 & 15 | 64] + _lut2[d1 >> 24 & 255] + "-" + _lut2[d2 & 63 | 128] + _lut2[d2 >> 8 & 255] + "-" + _lut2[d2 >> 16 & 255] + _lut2[d2 >> 24 & 255] + _lut2[d3 & 255] + _lut2[d3 >> 8 & 255] + _lut2[d3 >> 16 & 255] + _lut2[d3 >> 24 & 255]; return uuid.toLowerCase(); } function clamp2(value, min2, max2) { return Math.max(min2, Math.min(max2, value)); } function euclideanModulo2(n, m2) { return (n % m2 + m2) % m2; } function mapLinear(x3, a1, a2, b1, b2) { return b1 + (x3 - a1) * (b2 - b1) / (a2 - a1); } function inverseLerp(x3, y3, value) { if (x3 !== y3) { return (value - x3) / (y3 - x3); } else { return 0; } } function lerp2(x3, y3, t) { return (1 - t) * x3 + t * y3; } function damp(x3, y3, lambda, dt) { return lerp2(x3, y3, 1 - Math.exp(-lambda * dt)); } function pingpong(x3, length = 1) { return length - Math.abs(euclideanModulo2(x3, length * 2) - length); } function smoothstep(x3, min2, max2) { if (x3 <= min2) return 0; if (x3 >= max2) return 1; x3 = (x3 - min2) / (max2 - min2); return x3 * x3 * (3 - 2 * x3); } function smootherstep(x3, min2, max2) { if (x3 <= min2) return 0; if (x3 >= max2) return 1; x3 = (x3 - min2) / (max2 - min2); return x3 * x3 * x3 * (x3 * (x3 * 6 - 15) + 10); } function randInt(low, high) { return low + Math.floor(Math.random() * (high - low + 1)); } function randFloat(low, high) { return low + Math.random() * (high - low); } function randFloatSpread(range) { return range * (0.5 - Math.random()); } function seededRandom(s) { if (s !== void 0) _seed = s; let t = _seed += 1831565813; t = Math.imul(t ^ t >>> 15, t | 1); t ^= t + Math.imul(t ^ t >>> 7, t | 61); return ((t ^ t >>> 14) >>> 0) / 4294967296; } function degToRad(degrees) { return degrees * DEG2RAD2; } function radToDeg(radians) { return radians * RAD2DEG2; } function isPowerOfTwo2(value) { return (value & value - 1) === 0 && value !== 0; } function ceilPowerOfTwo(value) { return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2)); } function floorPowerOfTwo2(value) { return Math.pow(2, Math.floor(Math.log(value) / Math.LN2)); } function setQuaternionFromProperEuler(q, a2, b, c2, order) { const cos = Math.cos; const sin = Math.sin; const c22 = cos(b / 2); const s2 = sin(b / 2); const c13 = cos((a2 + c2) / 2); const s13 = sin((a2 + c2) / 2); const c1_3 = cos((a2 - c2) / 2); const s1_3 = sin((a2 - c2) / 2); const c3_1 = cos((c2 - a2) / 2); const s3_1 = sin((c2 - a2) / 2); switch (order) { case "XYX": q.set(c22 * s13, s2 * c1_3, s2 * s1_3, c22 * c13); break; case "YZY": q.set(s2 * s1_3, c22 * s13, s2 * c1_3, c22 * c13); break; case "ZXZ": q.set(s2 * c1_3, s2 * s1_3, c22 * s13, c22 * c13); break; case "XZX": q.set(c22 * s13, s2 * s3_1, s2 * c3_1, c22 * c13); break; case "YXY": q.set(s2 * c3_1, c22 * s13, s2 * s3_1, c22 * c13); break; case "ZYZ": q.set(s2 * s3_1, s2 * c3_1, c22 * s13, c22 * c13); break; default: console.warn("THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: " + order); } } function denormalize2(value, array) { switch (array.constructor) { case Float32Array: return value; case Uint32Array: return value / 4294967295; case Uint16Array: return value / 65535; case Uint8Array: return value / 255; case Int32Array: return Math.max(value / 2147483647, -1); case Int16Array: return Math.max(value / 32767, -1); case Int8Array: return Math.max(value / 127, -1); default: throw new Error("Invalid component type."); } } function normalize2(value, array) { switch (array.constructor) { case Float32Array: return value; case Uint32Array: return Math.round(value * 4294967295); case Uint16Array: return Math.round(value * 65535); case Uint8Array: return Math.round(value * 255); case Int32Array: return Math.round(value * 2147483647); case Int16Array: return Math.round(value * 32767); case Int8Array: return Math.round(value * 127); default: throw new Error("Invalid component type."); } } var MathUtils = { DEG2RAD: DEG2RAD2, RAD2DEG: RAD2DEG2, generateUUID: generateUUID2, clamp: clamp2, euclideanModulo: euclideanModulo2, mapLinear, inverseLerp, lerp: lerp2, damp, pingpong, smoothstep, smootherstep, randInt, randFloat, randFloatSpread, seededRandom, degToRad, radToDeg, isPowerOfTwo: isPowerOfTwo2, ceilPowerOfTwo, floorPowerOfTwo: floorPowerOfTwo2, setQuaternionFromProperEuler, normalize: normalize2, denormalize: denormalize2 }; var Vector22 = class { constructor(x3 = 0, y3 = 0) { Vector22.prototype.isVector2 = true; this.x = x3; this.y = y3; } get width() { return this.x; } set width(value) { this.x = value; } get height() { return this.y; } set height(value) { this.y = value; } set(x3, y3) { this.x = x3; this.y = y3; return this; } setScalar(scalar) { this.x = scalar; this.y = scalar; return this; } setX(x3) { this.x = x3; return this; } setY(y3) { this.y = y3; return this; } setComponent(index6, value) { switch (index6) { case 0: this.x = value; break; case 1: this.y = value; break; default: throw new Error("index is out of range: " + index6); } return this; } getComponent(index6) { switch (index6) { case 0: return this.x; case 1: return this.y; default: throw new Error("index is out of range: " + index6); } } clone() { return new this.constructor(this.x, this.y); } copy(v) { this.x = v.x; this.y = v.y; return this; } add(v) { this.x += v.x; this.y += v.y; return this; } addScalar(s) { this.x += s; this.y += s; return this; } addVectors(a2, b) { this.x = a2.x + b.x; this.y = a2.y + b.y; return this; } addScaledVector(v, s) { this.x += v.x * s; this.y += v.y * s; return this; } sub(v) { this.x -= v.x; this.y -= v.y; return this; } subScalar(s) { this.x -= s; this.y -= s; return this; } subVectors(a2, b) { this.x = a2.x - b.x; this.y = a2.y - b.y; return this; } multiply(v) { this.x *= v.x; this.y *= v.y; return this; } multiplyScalar(scalar) { this.x *= scalar; this.y *= scalar; return this; } divide(v) { this.x /= v.x; this.y /= v.y; return this; } divideScalar(scalar) { return this.multiplyScalar(1 / scalar); } applyMatrix3(m2) { const x3 = this.x, y3 = this.y; const e = m2.elements; this.x = e[0] * x3 + e[3] * y3 + e[6]; this.y = e[1] * x3 + e[4] * y3 + e[7]; return this; } min(v) { this.x = Math.min(this.x, v.x); this.y = Math.min(this.y, v.y); return this; } max(v) { this.x = Math.max(this.x, v.x); this.y = Math.max(this.y, v.y); return this; } clamp(min2, max2) { this.x = Math.max(min2.x, Math.min(max2.x, this.x)); this.y = Math.max(min2.y, Math.min(max2.y, this.y)); return this; } clampScalar(minVal, maxVal) { this.x = Math.max(minVal, Math.min(maxVal, this.x)); this.y = Math.max(minVal, Math.min(maxVal, this.y)); return this; } clampLength(min2, max2) { const length = this.length(); return this.divideScalar(length || 1).multiplyScalar(Math.max(min2, Math.min(max2, length))); } floor() { this.x = Math.floor(this.x); this.y = Math.floor(this.y); return this; } ceil() { this.x = Math.ceil(this.x); this.y = Math.ceil(this.y); return this; } round() { this.x = Math.round(this.x); this.y = Math.round(this.y); return this; } roundToZero() { this.x = Math.trunc(this.x); this.y = Math.trunc(this.y); return this; } negate() { this.x = -this.x; this.y = -this.y; return this; } dot(v) { return this.x * v.x + this.y * v.y; } cross(v) { return this.x * v.y - this.y * v.x; } lengthSq() { return this.x * this.x + this.y * this.y; } length() { return Math.sqrt(this.x * this.x + this.y * this.y); } manhattanLength() { return Math.abs(this.x) + Math.abs(this.y); } normalize() { return this.divideScalar(this.length() || 1); } angle() { const angle = Math.atan2(-this.y, -this.x) + Math.PI; return angle; } angleTo(v) { const denominator = Math.sqrt(this.lengthSq() * v.lengthSq()); if (denominator === 0) return Math.PI / 2; const theta = this.dot(v) / denominator; return Math.acos(clamp2(theta, -1, 1)); } distanceTo(v) { return Math.sqrt(this.distanceToSquared(v)); } distanceToSquared(v) { const dx = this.x - v.x, dy = this.y - v.y; return dx * dx + dy * dy; } manhattanDistanceTo(v) { return Math.abs(this.x - v.x) + Math.abs(this.y - v.y); } setLength(length) { return this.normalize().multiplyScalar(length); } lerp(v, alpha) { this.x += (v.x - this.x) * alpha; this.y += (v.y - this.y) * alpha; return this; } lerpVectors(v1, v2, alpha) { this.x = v1.x + (v2.x - v1.x) * alpha; this.y = v1.y + (v2.y - v1.y) * alpha; return this; } equals(v) { return v.x === this.x && v.y === this.y; } fromArray(array, offset = 0) { this.x = array[offset]; this.y = array[offset + 1]; return this; } toArray(array = [], offset = 0) { array[offset] = this.x; array[offset + 1] = this.y; return array; } fromBufferAttribute(attribute, index6) { this.x = attribute.getX(index6); this.y = attribute.getY(index6); return this; } rotateAround(center, angle) { const c2 = Math.cos(angle), s = Math.sin(angle); const x3 = this.x - center.x; const y3 = this.y - center.y; this.x = x3 * c2 - y3 * s + center.x; this.y = x3 * s + y3 * c2 + center.y; return this; } random() { this.x = Math.random(); this.y = Math.random(); return this; } *[Symbol.iterator]() { yield this.x; yield this.y; } }; var Matrix32 = class { constructor(n11, n12, n13, n21, n22, n23, n31, n32, n33) { Matrix32.prototype.isMatrix3 = true; this.elements = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ]; if (n11 !== void 0) { this.set(n11, n12, n13, n21, n22, n23, n31, n32, n33); } } set(n11, n12, n13, n21, n22, n23, n31, n32, n33) { const te = this.elements; te[0] = n11; te[1] = n21; te[2] = n31; te[3] = n12; te[4] = n22; te[5] = n32; te[6] = n13; te[7] = n23; te[8] = n33; return this; } identity() { this.set( 1, 0, 0, 0, 1, 0, 0, 0, 1 ); return this; } copy(m2) { const te = this.elements; const me = m2.elements; te[0] = me[0]; te[1] = me[1]; te[2] = me[2]; te[3] = me[3]; te[4] = me[4]; te[5] = me[5]; te[6] = me[6]; te[7] = me[7]; te[8] = me[8]; return this; } extractBasis(xAxis, yAxis, zAxis) { xAxis.setFromMatrix3Column(this, 0); yAxis.setFromMatrix3Column(this, 1); zAxis.setFromMatrix3Column(this, 2); return this; } setFromMatrix4(m2) { const me = m2.elements; this.set( me[0], me[4], me[8], me[1], me[5], me[9], me[2], me[6], me[10] ); return this; } multiply(m2) { return this.multiplyMatrices(this, m2); } premultiply(m2) { return this.multiplyMatrices(m2, this); } multiplyMatrices(a2, b) { const ae = a2.elements; const be = b.elements; const te = this.elements; const a11 = ae[0], a12 = ae[3], a13 = ae[6]; const a21 = ae[1], a22 = ae[4], a23 = ae[7]; const a31 = ae[2], a32 = ae[5], a33 = ae[8]; const b11 = be[0], b12 = be[3], b13 = be[6]; const b21 = be[1], b22 = be[4], b23 = be[7]; const b31 = be[2], b32 = be[5], b33 = be[8]; te[0] = a11 * b11 + a12 * b21 + a13 * b31; te[3] = a11 * b12 + a12 * b22 + a13 * b32; te[6] = a11 * b13 + a12 * b23 + a13 * b33; te[1] = a21 * b11 + a22 * b21 + a23 * b31; te[4] = a21 * b12 + a22 * b22 + a23 * b32; te[7] = a21 * b13 + a22 * b23 + a23 * b33; te[2] = a31 * b11 + a32 * b21 + a33 * b31; te[5] = a31 * b12 + a32 * b22 + a33 * b32; te[8] = a31 * b13 + a32 * b23 + a33 * b33; return this; } multiplyScalar(s) { const te = this.elements; te[0] *= s; te[3] *= s; te[6] *= s; te[1] *= s; te[4] *= s; te[7] *= s; te[2] *= s; te[5] *= s; te[8] *= s; return this; } determinant() { const te = this.elements; const a2 = te[0], b = te[1], c2 = te[2], d = te[3], e = te[4], f = te[5], g = te[6], h = te[7], i = te[8]; return a2 * e * i - a2 * f * h - b * d * i + b * f * g + c2 * d * h - c2 * e * g; } invert() { const te = this.elements, n11 = te[0], n21 = te[1], n31 = te[2], n12 = te[3], n22 = te[4], n32 = te[5], n13 = te[6], n23 = te[7], n33 = te[8], t11 = n33 * n22 - n32 * n23, t12 = n32 * n13 - n33 * n12, t13 = n23 * n12 - n22 * n13, det = n11 * t11 + n21 * t12 + n31 * t13; if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0); const detInv = 1 / det; te[0] = t11 * detInv; te[1] = (n31 * n23 - n33 * n21) * detInv; te[2] = (n32 * n21 - n31 * n22) * detInv; te[3] = t12 * detInv; te[4] = (n33 * n11 - n31 * n13) * detInv; te[5] = (n31 * n12 - n32 * n11) * detInv; te[6] = t13 * detInv; te[7] = (n21 * n13 - n23 * n11) * detInv; te[8] = (n22 * n11 - n21 * n12) * detInv; return this; } transpose() { let tmp2; const m2 = this.elements; tmp2 = m2[1]; m2[1] = m2[3]; m2[3] = tmp2; tmp2 = m2[2]; m2[2] = m2[6]; m2[6] = tmp2; tmp2 = m2[5]; m2[5] = m2[7]; m2[7] = tmp2; return this; } getNormalMatrix(matrix4) { return this.setFromMatrix4(matrix4).invert().transpose(); } transposeIntoArray(r) { const m2 = this.elements; r[0] = m2[0]; r[1] = m2[3]; r[2] = m2[6]; r[3] = m2[1]; r[4] = m2[4]; r[5] = m2[7]; r[6] = m2[2]; r[7] = m2[5]; r[8] = m2[8]; return this; } setUvTransform(tx, ty, sx, sy, rotation, cx, cy) { const c2 = Math.cos(rotation); const s = Math.sin(rotation); this.set( sx * c2, sx * s, -sx * (c2 * cx + s * cy) + cx + tx, -sy * s, sy * c2, -sy * (-s * cx + c2 * cy) + cy + ty, 0, 0, 1 ); return this; } // scale(sx, sy) { this.premultiply(_m32.makeScale(sx, sy)); return this; } rotate(theta) { this.premultiply(_m32.makeRotation(-theta)); return this; } translate(tx, ty) { this.premultiply(_m32.makeTranslation(tx, ty)); return this; } // for 2D Transforms makeTranslation(x3, y3) { if (x3.isVector2) { this.set( 1, 0, x3.x, 0, 1, x3.y, 0, 0, 1 ); } else { this.set( 1, 0, x3, 0, 1, y3, 0, 0, 1 ); } return this; } makeRotation(theta) { const c2 = Math.cos(theta); const s = Math.sin(theta); this.set( c2, -s, 0, s, c2, 0, 0, 0, 1 ); return this; } makeScale(x3, y3) { this.set( x3, 0, 0, 0, y3, 0, 0, 0, 1 ); return this; } // equals(matrix) { const te = this.elements; const me = matrix.elements; for (let i = 0; i < 9; i++) { if (te[i] !== me[i]) return false; } return true; } fromArray(array, offset = 0) { for (let i = 0; i < 9; i++) { this.elements[i] = array[i + offset]; } return this; } toArray(array = [], offset = 0) { const te = this.elements; array[offset] = te[0]; array[offset + 1] = te[1]; array[offset + 2] = te[2]; array[offset + 3] = te[3]; array[offset + 4] = te[4]; array[offset + 5] = te[5]; array[offset + 6] = te[6]; array[offset + 7] = te[7]; array[offset + 8] = te[8]; return array; } clone() { return new this.constructor().fromArray(this.elements); } }; var _m32 = /* @__PURE__ */ new Matrix32(); function arrayNeedsUint322(array) { for (let i = array.length - 1; i >= 0; --i) { if (array[i] >= 65535) return true; } return false; } function createElementNS2(name) { return document.createElementNS("http://www.w3.org/1999/xhtml", name); } function createCanvasElement2() { const canvas = createElementNS2("canvas"); canvas.style.display = "block"; return canvas; } var _cache2 = {}; function warnOnce2(message) { if (message in _cache2) return; _cache2[message] = true; console.warn(message); } var LINEAR_SRGB_TO_LINEAR_DISPLAY_P32 = /* @__PURE__ */ new Matrix32().set( 0.8224621, 0.177538, 0, 0.0331941, 0.9668058, 0, 0.0170827, 0.0723974, 0.9105199 ); var LINEAR_DISPLAY_P3_TO_LINEAR_SRGB2 = /* @__PURE__ */ new Matrix32().set( 1.2249401, -0.2249404, 0, -0.0420569, 1.0420571, 0, -0.0196376, -0.0786361, 1.0982735 ); var COLOR_SPACES2 = { [LinearSRGBColorSpace2]: { transfer: LinearTransfer2, primaries: Rec709Primaries2, toReference: (color) => color, fromReference: (color) => color }, [SRGBColorSpace2]: { transfer: SRGBTransfer2, primaries: Rec709Primaries2, toReference: (color) => color.convertSRGBToLinear(), fromReference: (color) => color.convertLinearToSRGB() }, [LinearDisplayP3ColorSpace2]: { transfer: LinearTransfer2, primaries: P3Primaries2, toReference: (color) => color.applyMatrix3(LINEAR_DISPLAY_P3_TO_LINEAR_SRGB2), fromReference: (color) => color.applyMatrix3(LINEAR_SRGB_TO_LINEAR_DISPLAY_P32) }, [DisplayP3ColorSpace2]: { transfer: SRGBTransfer2, primaries: P3Primaries2, toReference: (color) => color.convertSRGBToLinear().applyMatrix3(LINEAR_DISPLAY_P3_TO_LINEAR_SRGB2), fromReference: (color) => color.applyMatrix3(LINEAR_SRGB_TO_LINEAR_DISPLAY_P32).convertLinearToSRGB() } }; var SUPPORTED_WORKING_COLOR_SPACES2 = /* @__PURE__ */ new Set([LinearSRGBColorSpace2, LinearDisplayP3ColorSpace2]); var ColorManagement2 = { enabled: true, _workingColorSpace: LinearSRGBColorSpace2, get legacyMode() { console.warn("THREE.ColorManagement: .legacyMode=false renamed to .enabled=true in r150."); return !this.enabled; }, set legacyMode(legacyMode) { console.warn("THREE.ColorManagement: .legacyMode=false renamed to .enabled=true in r150."); this.enabled = !legacyMode; }, get workingColorSpace() { return this._workingColorSpace; }, set workingColorSpace(colorSpace) { if (!SUPPORTED_WORKING_COLOR_SPACES2.has(colorSpace)) { throw new Error(`Unsupported working color space, "${colorSpace}".`); } this._workingColorSpace = colorSpace; }, convert: function(color, sourceColorSpace, targetColorSpace) { if (this.enabled === false || sourceColorSpace === targetColorSpace || !sourceColorSpace || !targetColorSpace) { return color; } const sourceToReference = COLOR_SPACES2[sourceColorSpace].toReference; const targetFromReference = COLOR_SPACES2[targetColorSpace].fromReference; return targetFromReference(sourceToReference(color)); }, fromWorkingColorSpace: function(color, targetColorSpace) { return this.convert(color, this._workingColorSpace, targetColorSpace); }, toWorkingColorSpace: function(color, sourceColorSpace) { return this.convert(color, sourceColorSpace, this._workingColorSpace); }, getPrimaries: function(colorSpace) { return COLOR_SPACES2[colorSpace].primaries; }, getTransfer: function(colorSpace) { if (colorSpace === NoColorSpace2) return LinearTransfer2; return COLOR_SPACES2[colorSpace].transfer; } }; function SRGBToLinear2(c2) { return c2 < 0.04045 ? c2 * 0.0773993808 : Math.pow(c2 * 0.9478672986 + 0.0521327014, 2.4); } function LinearToSRGB2(c2) { return c2 < 31308e-7 ? c2 * 12.92 : 1.055 * Math.pow(c2, 0.41666) - 0.055; } var _canvas2; var ImageUtils2 = class { static getDataURL(image) { if (/^data:/i.test(image.src)) { return image.src; } if (typeof HTMLCanvasElement === "undefined") { return image.src; } let canvas; if (image instanceof HTMLCanvasElement) { canvas = image; } else { if (_canvas2 === void 0) _canvas2 = createElementNS2("canvas"); _canvas2.width = image.width; _canvas2.height = image.height; const context = _canvas2.getContext("2d"); if (image instanceof ImageData) { context.putImageData(image, 0, 0); } else { context.drawImage(image, 0, 0, image.width, image.height); } canvas = _canvas2; } if (canvas.width > 2048 || canvas.height > 2048) { console.warn("THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons", image); return canvas.toDataURL("image/jpeg", 0.6); } else { return canvas.toDataURL("image/png"); } } static sRGBToLinear(image) { if (typeof HTMLImageElement !== "undefined" && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== "undefined" && image instanceof HTMLCanvasElement || typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap) { const canvas = createElementNS2("canvas"); canvas.width = image.width; canvas.height = image.height; const context = canvas.getContext("2d"); context.drawImage(image, 0, 0, image.width, image.height); const imageData = context.getImageData(0, 0, image.width, image.height); const data = imageData.data; for (let i = 0; i < data.length; i++) { data[i] = SRGBToLinear2(data[i] / 255) * 255; } context.putImageData(imageData, 0, 0); return canvas; } else if (image.data) { const data = image.data.slice(0); for (let i = 0; i < data.length; i++) { if (data instanceof Uint8Array || data instanceof Uint8ClampedArray) { data[i] = Math.floor(SRGBToLinear2(data[i] / 255) * 255); } else { data[i] = SRGBToLinear2(data[i]); } } return { data, width: image.width, height: image.height }; } else { console.warn("THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied."); return image; } } }; var _sourceId2 = 0; var Source2 = class { constructor(data = null) { this.isSource = true; Object.defineProperty(this, "id", { value: _sourceId2++ }); this.uuid = generateUUID2(); this.data = data; this.version = 0; } set needsUpdate(value) { if (value === true) this.version++; } toJSON(meta) { const isRootObject = meta === void 0 || typeof meta === "string"; if (!isRootObject && meta.images[this.uuid] !== void 0) { return meta.images[this.uuid]; } const output = { uuid: this.uuid, url: "" }; const data = this.data; if (data !== null) { let url; if (Array.isArray(data)) { url = []; for (let i = 0, l = data.length; i < l; i++) { if (data[i].isDataTexture) { url.push(serializeImage2(data[i].image)); } else { url.push(serializeImage2(data[i])); } } } else { url = serializeImage2(data); } output.url = url; } if (!isRootObject) { meta.images[this.uuid] = output; } return output; } }; function serializeImage2(image) { if (typeof HTMLImageElement !== "undefined" && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== "undefined" && image instanceof HTMLCanvasElement || typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap) { return ImageUtils2.getDataURL(image); } else { if (image.data) { return { data: Array.from(image.data), width: image.width, height: image.height, type: image.data.constructor.name }; } else { console.warn("THREE.Texture: Unable to serialize Texture."); return {}; } } } var _textureId2 = 0; var Texture2 = class extends EventDispatcher2 { constructor(image = Texture2.DEFAULT_IMAGE, mapping = Texture2.DEFAULT_MAPPING, wrapS = ClampToEdgeWrapping2, wrapT = ClampToEdgeWrapping2, magFilter = LinearFilter2, minFilter = LinearMipmapLinearFilter2, format2 = RGBAFormat2, type = UnsignedByteType2, anisotropy = Texture2.DEFAULT_ANISOTROPY, colorSpace = NoColorSpace2) { super(); this.isTexture = true; Object.defineProperty(this, "id", { value: _textureId2++ }); this.uuid = generateUUID2(); this.name = ""; this.source = new Source2(image); this.mipmaps = []; this.mapping = mapping; this.channel = 0; this.wrapS = wrapS; this.wrapT = wrapT; this.magFilter = magFilter; this.minFilter = minFilter; this.anisotropy = anisotropy; this.format = format2; this.internalFormat = null; this.type = type; this.offset = new Vector22(0, 0); this.repeat = new Vector22(1, 1); this.center = new Vector22(0, 0); this.rotation = 0; this.matrixAutoUpdate = true; this.matrix = new Matrix32(); this.generateMipmaps = true; this.premultiplyAlpha = false; this.flipY = true; this.unpackAlignment = 4; if (typeof colorSpace === "string") { this.colorSpace = colorSpace; } else { warnOnce2("THREE.Texture: Property .encoding has been replaced by .colorSpace."); this.colorSpace = colorSpace === sRGBEncoding2 ? SRGBColorSpace2 : NoColorSpace2; } this.userData = {}; this.version = 0; this.onUpdate = null; this.isRenderTargetTexture = false; this.needsPMREMUpdate = false; } get image() { return this.source.data; } set image(value = null) { this.source.data = value; } updateMatrix() { this.matrix.setUvTransform(this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y); } clone() { return new this.constructor().copy(this); } copy(source) { this.name = source.name; this.source = source.source; this.mipmaps = source.mipmaps.slice(0); this.mapping = source.mapping; this.channel = source.channel; this.wrapS = source.wrapS; this.wrapT = source.wrapT; this.magFilter = source.magFilter; this.minFilter = source.minFilter; this.anisotropy = source.anisotropy; this.format = source.format; this.internalFormat = source.internalFormat; this.type = source.type; this.offset.copy(source.offset); this.repeat.copy(source.repeat); this.center.copy(source.center); this.rotation = source.rotation; this.matrixAutoUpdate = source.matrixAutoUpdate; this.matrix.copy(source.matrix); this.generateMipmaps = source.generateMipmaps; this.premultiplyAlpha = source.premultiplyAlpha; this.flipY = source.flipY; this.unpackAlignment = source.unpackAlignment; this.colorSpace = source.colorSpace; this.userData = JSON.parse(JSON.stringify(source.userData)); this.needsUpdate = true; return this; } toJSON(meta) { const isRootObject = meta === void 0 || typeof meta === "string"; if (!isRootObject && meta.textures[this.uuid] !== void 0) { return meta.textures[this.uuid]; } const output = { metadata: { version: 4.6, type: "Texture", generator: "Texture.toJSON" }, uuid: this.uuid, name: this.name, image: this.source.toJSON(meta).uuid, mapping: this.mapping, channel: this.channel, repeat: [this.repeat.x, this.repeat.y], offset: [this.offset.x, this.offset.y], center: [this.center.x, this.center.y], rotation: this.rotation, wrap: [this.wrapS, this.wrapT], format: this.format, internalFormat: this.internalFormat, type: this.type, colorSpace: this.colorSpace, minFilter: this.minFilter, magFilter: this.magFilter, anisotropy: this.anisotropy, flipY: this.flipY, generateMipmaps: this.generateMipmaps, premultiplyAlpha: this.premultiplyAlpha, unpackAlignment: this.unpackAlignment }; if (Object.keys(this.userData).length > 0) output.userData = this.userData; if (!isRootObject) { meta.textures[this.uuid] = output; } return output; } dispose() { this.dispatchEvent({ type: "dispose" }); } transformUv(uv) { if (this.mapping !== UVMapping2) return uv; uv.applyMatrix3(this.matrix); if (uv.x < 0 || uv.x > 1) { switch (this.wrapS) { case RepeatWrapping2: uv.x = uv.x - Math.floor(uv.x); break; case ClampToEdgeWrapping2: uv.x = uv.x < 0 ? 0 : 1; break; case MirroredRepeatWrapping2: if (Math.abs(Math.floor(uv.x) % 2) === 1) { uv.x = Math.ceil(uv.x) - uv.x; } else { uv.x = uv.x - Math.floor(uv.x); } break; } } if (uv.y < 0 || uv.y > 1) { switch (this.wrapT) { case RepeatWrapping2: uv.y = uv.y - Math.floor(uv.y); break; case ClampToEdgeWrapping2: uv.y = uv.y < 0 ? 0 : 1; break; case MirroredRepeatWrapping2: if (Math.abs(Math.floor(uv.y) % 2) === 1) { uv.y = Math.ceil(uv.y) - uv.y; } else { uv.y = uv.y - Math.floor(uv.y); } break; } } if (this.flipY) { uv.y = 1 - uv.y; } return uv; } set needsUpdate(value) { if (value === true) { this.version++; this.source.needsUpdate = true; } } get encoding() { warnOnce2("THREE.Texture: Property .encoding has been replaced by .colorSpace."); return this.colorSpace === SRGBColorSpace2 ? sRGBEncoding2 : LinearEncoding2; } set encoding(encoding) { warnOnce2("THREE.Texture: Property .encoding has been replaced by .colorSpace."); this.colorSpace = encoding === sRGBEncoding2 ? SRGBColorSpace2 : NoColorSpace2; } }; Texture2.DEFAULT_IMAGE = null; Texture2.DEFAULT_MAPPING = UVMapping2; Texture2.DEFAULT_ANISOTROPY = 1; var Vector42 = class { constructor(x3 = 0, y3 = 0, z4 = 0, w = 1) { Vector42.prototype.isVector4 = true; this.x = x3; this.y = y3; this.z = z4; this.w = w; } get width() { return this.z; } set width(value) { this.z = value; } get height() { return this.w; } set height(value) { this.w = value; } set(x3, y3, z4, w) { this.x = x3; this.y = y3; this.z = z4; this.w = w; return this; } setScalar(scalar) { this.x = scalar; this.y = scalar; this.z = scalar; this.w = scalar; return this; } setX(x3) { this.x = x3; return this; } setY(y3) { this.y = y3; return this; } setZ(z4) { this.z = z4; return this; } setW(w) { this.w = w; return this; } setComponent(index6, value) { switch (index6) { case 0: this.x = value; break; case 1: this.y = value; break; case 2: this.z = value; break; case 3: this.w = value; break; default: throw new Error("index is out of range: " + index6); } return this; } getComponent(index6) { switch (index6) { case 0: return this.x; case 1: return this.y; case 2: return this.z; case 3: return this.w; default: throw new Error("index is out of range: " + index6); } } clone() { return new this.constructor(this.x, this.y, this.z, this.w); } copy(v) { this.x = v.x; this.y = v.y; this.z = v.z; this.w = v.w !== void 0 ? v.w : 1; return this; } add(v) { this.x += v.x; this.y += v.y; this.z += v.z; this.w += v.w; return this; } addScalar(s) { this.x += s; this.y += s; this.z += s; this.w += s; return this; } addVectors(a2, b) { this.x = a2.x + b.x; this.y = a2.y + b.y; this.z = a2.z + b.z; this.w = a2.w + b.w; return this; } addScaledVector(v, s) { this.x += v.x * s; this.y += v.y * s; this.z += v.z * s; this.w += v.w * s; return this; } sub(v) { this.x -= v.x; this.y -= v.y; this.z -= v.z; this.w -= v.w; return this; } subScalar(s) { this.x -= s; this.y -= s; this.z -= s; this.w -= s; return this; } subVectors(a2, b) { this.x = a2.x - b.x; this.y = a2.y - b.y; this.z = a2.z - b.z; this.w = a2.w - b.w; return this; } multiply(v) { this.x *= v.x; this.y *= v.y; this.z *= v.z; this.w *= v.w; return this; } multiplyScalar(scalar) { this.x *= scalar; this.y *= scalar; this.z *= scalar; this.w *= scalar; return this; } applyMatrix4(m2) { const x3 = this.x, y3 = this.y, z4 = this.z, w = this.w; const e = m2.elements; this.x = e[0] * x3 + e[4] * y3 + e[8] * z4 + e[12] * w; this.y = e[1] * x3 + e[5] * y3 + e[9] * z4 + e[13] * w; this.z = e[2] * x3 + e[6] * y3 + e[10] * z4 + e[14] * w; this.w = e[3] * x3 + e[7] * y3 + e[11] * z4 + e[15] * w; return this; } divideScalar(scalar) { return this.multiplyScalar(1 / scalar); } setAxisAngleFromQuaternion(q) { this.w = 2 * Math.acos(q.w); const s = Math.sqrt(1 - q.w * q.w); if (s < 1e-4) { this.x = 1; this.y = 0; this.z = 0; } else { this.x = q.x / s; this.y = q.y / s; this.z = q.z / s; } return this; } setAxisAngleFromRotationMatrix(m2) { let angle, x3, y3, z4; const epsilon = 0.01, epsilon2 = 0.1, te = m2.elements, m11 = te[0], m12 = te[4], m13 = te[8], m21 = te[1], m22 = te[5], m23 = te[9], m31 = te[2], m32 = te[6], m33 = te[10]; if (Math.abs(m12 - m21) < epsilon && Math.abs(m13 - m31) < epsilon && Math.abs(m23 - m32) < epsilon) { if (Math.abs(m12 + m21) < epsilon2 && Math.abs(m13 + m31) < epsilon2 && Math.abs(m23 + m32) < epsilon2 && Math.abs(m11 + m22 + m33 - 3) < epsilon2) { this.set(1, 0, 0, 0); return this; } angle = Math.PI; const xx = (m11 + 1) / 2; const yy = (m22 + 1) / 2; const zz = (m33 + 1) / 2; const xy = (m12 + m21) / 4; const xz = (m13 + m31) / 4; const yz = (m23 + m32) / 4; if (xx > yy && xx > zz) { if (xx < epsilon) { x3 = 0; y3 = 0.707106781; z4 = 0.707106781; } else { x3 = Math.sqrt(xx); y3 = xy / x3; z4 = xz / x3; } } else if (yy > zz) { if (yy < epsilon) { x3 = 0.707106781; y3 = 0; z4 = 0.707106781; } else { y3 = Math.sqrt(yy); x3 = xy / y3; z4 = yz / y3; } } else { if (zz < epsilon) { x3 = 0.707106781; y3 = 0.707106781; z4 = 0; } else { z4 = Math.sqrt(zz); x3 = xz / z4; y3 = yz / z4; } } this.set(x3, y3, z4, angle); return this; } let s = Math.sqrt((m32 - m23) * (m32 - m23) + (m13 - m31) * (m13 - m31) + (m21 - m12) * (m21 - m12)); if (Math.abs(s) < 1e-3) s = 1; this.x = (m32 - m23) / s; this.y = (m13 - m31) / s; this.z = (m21 - m12) / s; this.w = Math.acos((m11 + m22 + m33 - 1) / 2); return this; } min(v) { this.x = Math.min(this.x, v.x); this.y = Math.min(this.y, v.y); this.z = Math.min(this.z, v.z); this.w = Math.min(this.w, v.w); return this; } max(v) { this.x = Math.max(this.x, v.x); this.y = Math.max(this.y, v.y); this.z = Math.max(this.z, v.z); this.w = Math.max(this.w, v.w); return this; } clamp(min2, max2) { this.x = Math.max(min2.x, Math.min(max2.x, this.x)); this.y = Math.max(min2.y, Math.min(max2.y, this.y)); this.z = Math.max(min2.z, Math.min(max2.z, this.z)); this.w = Math.max(min2.w, Math.min(max2.w, this.w)); return this; } clampScalar(minVal, maxVal) { this.x = Math.max(minVal, Math.min(maxVal, this.x)); this.y = Math.max(minVal, Math.min(maxVal, this.y)); this.z = Math.max(minVal, Math.min(maxVal, this.z)); this.w = Math.max(minVal, Math.min(maxVal, this.w)); return this; } clampLength(min2, max2) { const length = this.length(); return this.divideScalar(length || 1).multiplyScalar(Math.max(min2, Math.min(max2, length))); } floor() { this.x = Math.floor(this.x); this.y = Math.floor(this.y); this.z = Math.floor(this.z); this.w = Math.floor(this.w); return this; } ceil() { this.x = Math.ceil(this.x); this.y = Math.ceil(this.y); this.z = Math.ceil(this.z); this.w = Math.ceil(this.w); return this; } round() { this.x = Math.round(this.x); this.y = Math.round(this.y); this.z = Math.round(this.z); this.w = Math.round(this.w); return this; } roundToZero() { this.x = Math.trunc(this.x); this.y = Math.trunc(this.y); this.z = Math.trunc(this.z); this.w = Math.trunc(this.w); return this; } negate() { this.x = -this.x; this.y = -this.y; this.z = -this.z; this.w = -this.w; return this; } dot(v) { return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w; } lengthSq() { return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w; } length() { return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w); } manhattanLength() { return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z) + Math.abs(this.w); } normalize() { return this.divideScalar(this.length() || 1); } setLength(length) { return this.normalize().multiplyScalar(length); } lerp(v, alpha) { this.x += (v.x - this.x) * alpha; this.y += (v.y - this.y) * alpha; this.z += (v.z - this.z) * alpha; this.w += (v.w - this.w) * alpha; return this; } lerpVectors(v1, v2, alpha) { this.x = v1.x + (v2.x - v1.x) * alpha; this.y = v1.y + (v2.y - v1.y) * alpha; this.z = v1.z + (v2.z - v1.z) * alpha; this.w = v1.w + (v2.w - v1.w) * alpha; return this; } equals(v) { return v.x === this.x && v.y === this.y && v.z === this.z && v.w === this.w; } fromArray(array, offset = 0) { this.x = array[offset]; this.y = array[offset + 1]; this.z = array[offset + 2]; this.w = array[offset + 3]; return this; } toArray(array = [], offset = 0) { array[offset] = this.x; array[offset + 1] = this.y; array[offset + 2] = this.z; array[offset + 3] = this.w; return array; } fromBufferAttribute(attribute, index6) { this.x = attribute.getX(index6); this.y = attribute.getY(index6); this.z = attribute.getZ(index6); this.w = attribute.getW(index6); return this; } random() { this.x = Math.random(); this.y = Math.random(); this.z = Math.random(); this.w = Math.random(); return this; } *[Symbol.iterator]() { yield this.x; yield this.y; yield this.z; yield this.w; } }; var RenderTarget2 = class extends EventDispatcher2 { constructor(width = 1, height = 1, options = {}) { super(); this.isRenderTarget = true; this.width = width; this.height = height; this.depth = 1; this.scissor = new Vector42(0, 0, width, height); this.scissorTest = false; this.viewport = new Vector42(0, 0, width, height); const image = { width, height, depth: 1 }; if (options.encoding !== void 0) { warnOnce2("THREE.WebGLRenderTarget: option.encoding has been replaced by option.colorSpace."); options.colorSpace = options.encoding === sRGBEncoding2 ? SRGBColorSpace2 : NoColorSpace2; } options = Object.assign({ generateMipmaps: false, internalFormat: null, minFilter: LinearFilter2, depthBuffer: true, stencilBuffer: false, depthTexture: null, samples: 0 }, options); this.texture = new Texture2(image, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace); this.texture.isRenderTargetTexture = true; this.texture.flipY = false; this.texture.generateMipmaps = options.generateMipmaps; this.texture.internalFormat = options.internalFormat; this.depthBuffer = options.depthBuffer; this.stencilBuffer = options.stencilBuffer; this.depthTexture = options.depthTexture; this.samples = options.samples; } setSize(width, height, depth = 1) { if (this.width !== width || this.height !== height || this.depth !== depth) { this.width = width; this.height = height; this.depth = depth; this.texture.image.width = width; this.texture.image.height = height; this.texture.image.depth = depth; this.dispose(); } this.viewport.set(0, 0, width, height); this.scissor.set(0, 0, width, height); } clone() { return new this.constructor().copy(this); } copy(source) { this.width = source.width; this.height = source.height; this.depth = source.depth; this.scissor.copy(source.scissor); this.scissorTest = source.scissorTest; this.viewport.copy(source.viewport); this.texture = source.texture.clone(); this.texture.isRenderTargetTexture = true; const image = Object.assign({}, source.texture.image); this.texture.source = new Source2(image); this.depthBuffer = source.depthBuffer; this.stencilBuffer = source.stencilBuffer; if (source.depthTexture !== null) this.depthTexture = source.depthTexture.clone(); this.samples = source.samples; return this; } dispose() { this.dispatchEvent({ type: "dispose" }); } }; var WebGLRenderTarget2 = class extends RenderTarget2 { constructor(width = 1, height = 1, options = {}) { super(width, height, options); this.isWebGLRenderTarget = true; } }; var DataArrayTexture2 = class extends Texture2 { constructor(data = null, width = 1, height = 1, depth = 1) { super(null); this.isDataArrayTexture = true; this.image = { data, width, height, depth }; this.magFilter = NearestFilter2; this.minFilter = NearestFilter2; this.wrapR = ClampToEdgeWrapping2; this.generateMipmaps = false; this.flipY = false; this.unpackAlignment = 1; } }; var Data3DTexture2 = class extends Texture2 { constructor(data = null, width = 1, height = 1, depth = 1) { super(null); this.isData3DTexture = true; this.image = { data, width, height, depth }; this.magFilter = NearestFilter2; this.minFilter = NearestFilter2; this.wrapR = ClampToEdgeWrapping2; this.generateMipmaps = false; this.flipY = false; this.unpackAlignment = 1; } }; var Quaternion2 = class { constructor(x3 = 0, y3 = 0, z4 = 0, w = 1) { this.isQuaternion = true; this._x = x3; this._y = y3; this._z = z4; this._w = w; } static slerpFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t) { let x0 = src0[srcOffset0 + 0], y0 = src0[srcOffset0 + 1], z0 = src0[srcOffset0 + 2], w0 = src0[srcOffset0 + 3]; const x1 = src1[srcOffset1 + 0], y1 = src1[srcOffset1 + 1], z1 = src1[srcOffset1 + 2], w1 = src1[srcOffset1 + 3]; if (t === 0) { dst[dstOffset + 0] = x0; dst[dstOffset + 1] = y0; dst[dstOffset + 2] = z0; dst[dstOffset + 3] = w0; return; } if (t === 1) { dst[dstOffset + 0] = x1; dst[dstOffset + 1] = y1; dst[dstOffset + 2] = z1; dst[dstOffset + 3] = w1; return; } if (w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1) { let s = 1 - t; const cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1, dir = cos >= 0 ? 1 : -1, sqrSin = 1 - cos * cos; if (sqrSin > Number.EPSILON) { const sin = Math.sqrt(sqrSin), len = Math.atan2(sin, cos * dir); s = Math.sin(s * len) / sin; t = Math.sin(t * len) / sin; } const tDir = t * dir; x0 = x0 * s + x1 * tDir; y0 = y0 * s + y1 * tDir; z0 = z0 * s + z1 * tDir; w0 = w0 * s + w1 * tDir; if (s === 1 - t) { const f = 1 / Math.sqrt(x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0); x0 *= f; y0 *= f; z0 *= f; w0 *= f; } } dst[dstOffset] = x0; dst[dstOffset + 1] = y0; dst[dstOffset + 2] = z0; dst[dstOffset + 3] = w0; } static multiplyQuaternionsFlat(dst, dstOffset, src0, srcOffset0, src1, srcOffset1) { const x0 = src0[srcOffset0]; const y0 = src0[srcOffset0 + 1]; const z0 = src0[srcOffset0 + 2]; const w0 = src0[srcOffset0 + 3]; const x1 = src1[srcOffset1]; const y1 = src1[srcOffset1 + 1]; const z1 = src1[srcOffset1 + 2]; const w1 = src1[srcOffset1 + 3]; dst[dstOffset] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1; dst[dstOffset + 1] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1; dst[dstOffset + 2] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1; dst[dstOffset + 3] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1; return dst; } get x() { return this._x; } set x(value) { this._x = value; this._onChangeCallback(); } get y() { return this._y; } set y(value) { this._y = value; this._onChangeCallback(); } get z() { return this._z; } set z(value) { this._z = value; this._onChangeCallback(); } get w() { return this._w; } set w(value) { this._w = value; this._onChangeCallback(); } set(x3, y3, z4, w) { this._x = x3; this._y = y3; this._z = z4; this._w = w; this._onChangeCallback(); return this; } clone() { return new this.constructor(this._x, this._y, this._z, this._w); } copy(quaternion) { this._x = quaternion.x; this._y = quaternion.y; this._z = quaternion.z; this._w = quaternion.w; this._onChangeCallback(); return this; } setFromEuler(euler, update4) { const x3 = euler._x, y3 = euler._y, z4 = euler._z, order = euler._order; const cos = Math.cos; const sin = Math.sin; const c1 = cos(x3 / 2); const c2 = cos(y3 / 2); const c3 = cos(z4 / 2); const s1 = sin(x3 / 2); const s2 = sin(y3 / 2); const s3 = sin(z4 / 2); switch (order) { case "XYZ": this._x = s1 * c2 * c3 + c1 * s2 * s3; this._y = c1 * s2 * c3 - s1 * c2 * s3; this._z = c1 * c2 * s3 + s1 * s2 * c3; this._w = c1 * c2 * c3 - s1 * s2 * s3; break; case "YXZ": this._x = s1 * c2 * c3 + c1 * s2 * s3; this._y = c1 * s2 * c3 - s1 * c2 * s3; this._z = c1 * c2 * s3 - s1 * s2 * c3; this._w = c1 * c2 * c3 + s1 * s2 * s3; break; case "ZXY": this._x = s1 * c2 * c3 - c1 * s2 * s3; this._y = c1 * s2 * c3 + s1 * c2 * s3; this._z = c1 * c2 * s3 + s1 * s2 * c3; this._w = c1 * c2 * c3 - s1 * s2 * s3; break; case "ZYX": this._x = s1 * c2 * c3 - c1 * s2 * s3; this._y = c1 * s2 * c3 + s1 * c2 * s3; this._z = c1 * c2 * s3 - s1 * s2 * c3; this._w = c1 * c2 * c3 + s1 * s2 * s3; break; case "YZX": this._x = s1 * c2 * c3 + c1 * s2 * s3; this._y = c1 * s2 * c3 + s1 * c2 * s3; this._z = c1 * c2 * s3 - s1 * s2 * c3; this._w = c1 * c2 * c3 - s1 * s2 * s3; break; case "XZY": this._x = s1 * c2 * c3 - c1 * s2 * s3; this._y = c1 * s2 * c3 - s1 * c2 * s3; this._z = c1 * c2 * s3 + s1 * s2 * c3; this._w = c1 * c2 * c3 + s1 * s2 * s3; break; default: console.warn("THREE.Quaternion: .setFromEuler() encountered an unknown order: " + order); } if (update4 !== false) this._onChangeCallback(); return this; } setFromAxisAngle(axis, angle) { const halfAngle = angle / 2, s = Math.sin(halfAngle); this._x = axis.x * s; this._y = axis.y * s; this._z = axis.z * s; this._w = Math.cos(halfAngle); this._onChangeCallback(); return this; } setFromRotationMatrix(m2) { const te = m2.elements, m11 = te[0], m12 = te[4], m13 = te[8], m21 = te[1], m22 = te[5], m23 = te[9], m31 = te[2], m32 = te[6], m33 = te[10], trace = m11 + m22 + m33; if (trace > 0) { const s = 0.5 / Math.sqrt(trace + 1); this._w = 0.25 / s; this._x = (m32 - m23) * s; this._y = (m13 - m31) * s; this._z = (m21 - m12) * s; } else if (m11 > m22 && m11 > m33) { const s = 2 * Math.sqrt(1 + m11 - m22 - m33); this._w = (m32 - m23) / s; this._x = 0.25 * s; this._y = (m12 + m21) / s; this._z = (m13 + m31) / s; } else if (m22 > m33) { const s = 2 * Math.sqrt(1 + m22 - m11 - m33); this._w = (m13 - m31) / s; this._x = (m12 + m21) / s; this._y = 0.25 * s; this._z = (m23 + m32) / s; } else { const s = 2 * Math.sqrt(1 + m33 - m11 - m22); this._w = (m21 - m12) / s; this._x = (m13 + m31) / s; this._y = (m23 + m32) / s; this._z = 0.25 * s; } this._onChangeCallback(); return this; } setFromUnitVectors(vFrom, vTo) { let r = vFrom.dot(vTo) + 1; if (r < Number.EPSILON) { r = 0; if (Math.abs(vFrom.x) > Math.abs(vFrom.z)) { this._x = -vFrom.y; this._y = vFrom.x; this._z = 0; this._w = r; } else { this._x = 0; this._y = -vFrom.z; this._z = vFrom.y; this._w = r; } } else { this._x = vFrom.y * vTo.z - vFrom.z * vTo.y; this._y = vFrom.z * vTo.x - vFrom.x * vTo.z; this._z = vFrom.x * vTo.y - vFrom.y * vTo.x; this._w = r; } return this.normalize(); } angleTo(q) { return 2 * Math.acos(Math.abs(clamp2(this.dot(q), -1, 1))); } rotateTowards(q, step) { const angle = this.angleTo(q); if (angle === 0) return this; const t = Math.min(1, step / angle); this.slerp(q, t); return this; } identity() { return this.set(0, 0, 0, 1); } invert() { return this.conjugate(); } conjugate() { this._x *= -1; this._y *= -1; this._z *= -1; this._onChangeCallback(); return this; } dot(v) { return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w; } lengthSq() { return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w; } length() { return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w); } normalize() { let l = this.length(); if (l === 0) { this._x = 0; this._y = 0; this._z = 0; this._w = 1; } else { l = 1 / l; this._x = this._x * l; this._y = this._y * l; this._z = this._z * l; this._w = this._w * l; } this._onChangeCallback(); return this; } multiply(q) { return this.multiplyQuaternions(this, q); } premultiply(q) { return this.multiplyQuaternions(q, this); } multiplyQuaternions(a2, b) { const qax = a2._x, qay = a2._y, qaz = a2._z, qaw = a2._w; const qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w; this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby; this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz; this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx; this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz; this._onChangeCallback(); return this; } slerp(qb, t) { if (t === 0) return this; if (t === 1) return this.copy(qb); const x3 = this._x, y3 = this._y, z4 = this._z, w = this._w; let cosHalfTheta = w * qb._w + x3 * qb._x + y3 * qb._y + z4 * qb._z; if (cosHalfTheta < 0) { this._w = -qb._w; this._x = -qb._x; this._y = -qb._y; this._z = -qb._z; cosHalfTheta = -cosHalfTheta; } else { this.copy(qb); } if (cosHalfTheta >= 1) { this._w = w; this._x = x3; this._y = y3; this._z = z4; return this; } const sqrSinHalfTheta = 1 - cosHalfTheta * cosHalfTheta; if (sqrSinHalfTheta <= Number.EPSILON) { const s = 1 - t; this._w = s * w + t * this._w; this._x = s * x3 + t * this._x; this._y = s * y3 + t * this._y; this._z = s * z4 + t * this._z; this.normalize(); this._onChangeCallback(); return this; } const sinHalfTheta = Math.sqrt(sqrSinHalfTheta); const halfTheta = Math.atan2(sinHalfTheta, cosHalfTheta); const ratioA = Math.sin((1 - t) * halfTheta) / sinHalfTheta, ratioB = Math.sin(t * halfTheta) / sinHalfTheta; this._w = w * ratioA + this._w * ratioB; this._x = x3 * ratioA + this._x * ratioB; this._y = y3 * ratioA + this._y * ratioB; this._z = z4 * ratioA + this._z * ratioB; this._onChangeCallback(); return this; } slerpQuaternions(qa, qb, t) { return this.copy(qa).slerp(qb, t); } random() { const u1 = Math.random(); const sqrt1u1 = Math.sqrt(1 - u1); const sqrtu1 = Math.sqrt(u1); const u2 = 2 * Math.PI * Math.random(); const u3 = 2 * Math.PI * Math.random(); return this.set( sqrt1u1 * Math.cos(u2), sqrtu1 * Math.sin(u3), sqrtu1 * Math.cos(u3), sqrt1u1 * Math.sin(u2) ); } equals(quaternion) { return quaternion._x === this._x && quaternion._y === this._y && quaternion._z === this._z && quaternion._w === this._w; } fromArray(array, offset = 0) { this._x = array[offset]; this._y = array[offset + 1]; this._z = array[offset + 2]; this._w = array[offset + 3]; this._onChangeCallback(); return this; } toArray(array = [], offset = 0) { array[offset] = this._x; array[offset + 1] = this._y; array[offset + 2] = this._z; array[offset + 3] = this._w; return array; } fromBufferAttribute(attribute, index6) { this._x = attribute.getX(index6); this._y = attribute.getY(index6); this._z = attribute.getZ(index6); this._w = attribute.getW(index6); return this; } toJSON() { return this.toArray(); } _onChange(callback) { this._onChangeCallback = callback; return this; } _onChangeCallback() { } *[Symbol.iterator]() { yield this._x; yield this._y; yield this._z; yield this._w; } }; var Vector32 = class { constructor(x3 = 0, y3 = 0, z4 = 0) { Vector32.prototype.isVector3 = true; this.x = x3; this.y = y3; this.z = z4; } set(x3, y3, z4) { if (z4 === void 0) z4 = this.z; this.x = x3; this.y = y3; this.z = z4; return this; } setScalar(scalar) { this.x = scalar; this.y = scalar; this.z = scalar; return this; } setX(x3) { this.x = x3; return this; } setY(y3) { this.y = y3; return this; } setZ(z4) { this.z = z4; return this; } setComponent(index6, value) { switch (index6) { case 0: this.x = value; break; case 1: this.y = value; break; case 2: this.z = value; break; default: throw new Error("index is out of range: " + index6); } return this; } getComponent(index6) { switch (index6) { case 0: return this.x; case 1: return this.y; case 2: return this.z; default: throw new Error("index is out of range: " + index6); } } clone() { return new this.constructor(this.x, this.y, this.z); } copy(v) { this.x = v.x; this.y = v.y; this.z = v.z; return this; } add(v) { this.x += v.x; this.y += v.y; this.z += v.z; return this; } addScalar(s) { this.x += s; this.y += s; this.z += s; return this; } addVectors(a2, b) { this.x = a2.x + b.x; this.y = a2.y + b.y; this.z = a2.z + b.z; return this; } addScaledVector(v, s) { this.x += v.x * s; this.y += v.y * s; this.z += v.z * s; return this; } sub(v) { this.x -= v.x; this.y -= v.y; this.z -= v.z; return this; } subScalar(s) { this.x -= s; this.y -= s; this.z -= s; return this; } subVectors(a2, b) { this.x = a2.x - b.x; this.y = a2.y - b.y; this.z = a2.z - b.z; return this; } multiply(v) { this.x *= v.x; this.y *= v.y; this.z *= v.z; return this; } multiplyScalar(scalar) { this.x *= scalar; this.y *= scalar; this.z *= scalar; return this; } multiplyVectors(a2, b) { this.x = a2.x * b.x; this.y = a2.y * b.y; this.z = a2.z * b.z; return this; } applyEuler(euler) { return this.applyQuaternion(_quaternion$42.setFromEuler(euler)); } applyAxisAngle(axis, angle) { return this.applyQuaternion(_quaternion$42.setFromAxisAngle(axis, angle)); } applyMatrix3(m2) { const x3 = this.x, y3 = this.y, z4 = this.z; const e = m2.elements; this.x = e[0] * x3 + e[3] * y3 + e[6] * z4; this.y = e[1] * x3 + e[4] * y3 + e[7] * z4; this.z = e[2] * x3 + e[5] * y3 + e[8] * z4; return this; } applyNormalMatrix(m2) { return this.applyMatrix3(m2).normalize(); } applyMatrix4(m2) { const x3 = this.x, y3 = this.y, z4 = this.z; const e = m2.elements; const w = 1 / (e[3] * x3 + e[7] * y3 + e[11] * z4 + e[15]); this.x = (e[0] * x3 + e[4] * y3 + e[8] * z4 + e[12]) * w; this.y = (e[1] * x3 + e[5] * y3 + e[9] * z4 + e[13]) * w; this.z = (e[2] * x3 + e[6] * y3 + e[10] * z4 + e[14]) * w; return this; } applyQuaternion(q) { const x3 = this.x, y3 = this.y, z4 = this.z; const qx = q.x, qy = q.y, qz = q.z, qw = q.w; const ix = qw * x3 + qy * z4 - qz * y3; const iy = qw * y3 + qz * x3 - qx * z4; const iz = qw * z4 + qx * y3 - qy * x3; const iw = -qx * x3 - qy * y3 - qz * z4; this.x = ix * qw + iw * -qx + iy * -qz - iz * -qy; this.y = iy * qw + iw * -qy + iz * -qx - ix * -qz; this.z = iz * qw + iw * -qz + ix * -qy - iy * -qx; return this; } project(camera3) { return this.applyMatrix4(camera3.matrixWorldInverse).applyMatrix4(camera3.projectionMatrix); } unproject(camera3) { return this.applyMatrix4(camera3.projectionMatrixInverse).applyMatrix4(camera3.matrixWorld); } transformDirection(m2) { const x3 = this.x, y3 = this.y, z4 = this.z; const e = m2.elements; this.x = e[0] * x3 + e[4] * y3 + e[8] * z4; this.y = e[1] * x3 + e[5] * y3 + e[9] * z4; this.z = e[2] * x3 + e[6] * y3 + e[10] * z4; return this.normalize(); } divide(v) { this.x /= v.x; this.y /= v.y; this.z /= v.z; return this; } divideScalar(scalar) { return this.multiplyScalar(1 / scalar); } min(v) { this.x = Math.min(this.x, v.x); this.y = Math.min(this.y, v.y); this.z = Math.min(this.z, v.z); return this; } max(v) { this.x = Math.max(this.x, v.x); this.y = Math.max(this.y, v.y); this.z = Math.max(this.z, v.z); return this; } clamp(min2, max2) { this.x = Math.max(min2.x, Math.min(max2.x, this.x)); this.y = Math.max(min2.y, Math.min(max2.y, this.y)); this.z = Math.max(min2.z, Math.min(max2.z, this.z)); return this; } clampScalar(minVal, maxVal) { this.x = Math.max(minVal, Math.min(maxVal, this.x)); this.y = Math.max(minVal, Math.min(maxVal, this.y)); this.z = Math.max(minVal, Math.min(maxVal, this.z)); return this; } clampLength(min2, max2) { const length = this.length(); return this.divideScalar(length || 1).multiplyScalar(Math.max(min2, Math.min(max2, length))); } floor() { this.x = Math.floor(this.x); this.y = Math.floor(this.y); this.z = Math.floor(this.z); return this; } ceil() { this.x = Math.ceil(this.x); this.y = Math.ceil(this.y); this.z = Math.ceil(this.z); return this; } round() { this.x = Math.round(this.x); this.y = Math.round(this.y); this.z = Math.round(this.z); return this; } roundToZero() { this.x = Math.trunc(this.x); this.y = Math.trunc(this.y); this.z = Math.trunc(this.z); return this; } negate() { this.x = -this.x; this.y = -this.y; this.z = -this.z; return this; } dot(v) { return this.x * v.x + this.y * v.y + this.z * v.z; } // TODO lengthSquared? lengthSq() { return this.x * this.x + this.y * this.y + this.z * this.z; } length() { return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z); } manhattanLength() { return Math.abs(this.x) + Math.abs(this.y) + Math.abs(this.z); } normalize() { return this.divideScalar(this.length() || 1); } setLength(length) { return this.normalize().multiplyScalar(length); } lerp(v, alpha) { this.x += (v.x - this.x) * alpha; this.y += (v.y - this.y) * alpha; this.z += (v.z - this.z) * alpha; return this; } lerpVectors(v1, v2, alpha) { this.x = v1.x + (v2.x - v1.x) * alpha; this.y = v1.y + (v2.y - v1.y) * alpha; this.z = v1.z + (v2.z - v1.z) * alpha; return this; } cross(v) { return this.crossVectors(this, v); } crossVectors(a2, b) { const ax = a2.x, ay = a2.y, az = a2.z; const bx = b.x, by = b.y, bz = b.z; this.x = ay * bz - az * by; this.y = az * bx - ax * bz; this.z = ax * by - ay * bx; return this; } projectOnVector(v) { const denominator = v.lengthSq(); if (denominator === 0) return this.set(0, 0, 0); const scalar = v.dot(this) / denominator; return this.copy(v).multiplyScalar(scalar); } projectOnPlane(planeNormal) { _vector$b2.copy(this).projectOnVector(planeNormal); return this.sub(_vector$b2); } reflect(normal) { return this.sub(_vector$b2.copy(normal).multiplyScalar(2 * this.dot(normal))); } angleTo(v) { const denominator = Math.sqrt(this.lengthSq() * v.lengthSq()); if (denominator === 0) return Math.PI / 2; const theta = this.dot(v) / denominator; return Math.acos(clamp2(theta, -1, 1)); } distanceTo(v) { return Math.sqrt(this.distanceToSquared(v)); } distanceToSquared(v) { const dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z; return dx * dx + dy * dy + dz * dz; } manhattanDistanceTo(v) { return Math.abs(this.x - v.x) + Math.abs(this.y - v.y) + Math.abs(this.z - v.z); } setFromSpherical(s) { return this.setFromSphericalCoords(s.radius, s.phi, s.theta); } setFromSphericalCoords(radius, phi, theta) { const sinPhiRadius = Math.sin(phi) * radius; this.x = sinPhiRadius * Math.sin(theta); this.y = Math.cos(phi) * radius; this.z = sinPhiRadius * Math.cos(theta); return this; } setFromCylindrical(c2) { return this.setFromCylindricalCoords(c2.radius, c2.theta, c2.y); } setFromCylindricalCoords(radius, theta, y3) { this.x = radius * Math.sin(theta); this.y = y3; this.z = radius * Math.cos(theta); return this; } setFromMatrixPosition(m2) { const e = m2.elements; this.x = e[12]; this.y = e[13]; this.z = e[14]; return this; } setFromMatrixScale(m2) { const sx = this.setFromMatrixColumn(m2, 0).length(); const sy = this.setFromMatrixColumn(m2, 1).length(); const sz = this.setFromMatrixColumn(m2, 2).length(); this.x = sx; this.y = sy; this.z = sz; return this; } setFromMatrixColumn(m2, index6) { return this.fromArray(m2.elements, index6 * 4); } setFromMatrix3Column(m2, index6) { return this.fromArray(m2.elements, index6 * 3); } setFromEuler(e) { this.x = e._x; this.y = e._y; this.z = e._z; return this; } setFromColor(c2) { this.x = c2.r; this.y = c2.g; this.z = c2.b; return this; } equals(v) { return v.x === this.x && v.y === this.y && v.z === this.z; } fromArray(array, offset = 0) { this.x = array[offset]; this.y = array[offset + 1]; this.z = array[offset + 2]; return this; } toArray(array = [], offset = 0) { array[offset] = this.x; array[offset + 1] = this.y; array[offset + 2] = this.z; return array; } fromBufferAttribute(attribute, index6) { this.x = attribute.getX(index6); this.y = attribute.getY(index6); this.z = attribute.getZ(index6); return this; } random() { this.x = Math.random(); this.y = Math.random(); this.z = Math.random(); return this; } randomDirection() { const u = (Math.random() - 0.5) * 2; const t = Math.random() * Math.PI * 2; const f = Math.sqrt(1 - u ** 2); this.x = f * Math.cos(t); this.y = f * Math.sin(t); this.z = u; return this; } *[Symbol.iterator]() { yield this.x; yield this.y; yield this.z; } }; var _vector$b2 = /* @__PURE__ */ new Vector32(); var _quaternion$42 = /* @__PURE__ */ new Quaternion2(); var Box32 = class { constructor(min2 = new Vector32(Infinity, Infinity, Infinity), max2 = new Vector32(-Infinity, -Infinity, -Infinity)) { this.isBox3 = true; this.min = min2; this.max = max2; } set(min2, max2) { this.min.copy(min2); this.max.copy(max2); return this; } setFromArray(array) { this.makeEmpty(); for (let i = 0, il = array.length; i < il; i += 3) { this.expandByPoint(_vector$a2.fromArray(array, i)); } return this; } setFromBufferAttribute(attribute) { this.makeEmpty(); for (let i = 0, il = attribute.count; i < il; i++) { this.expandByPoint(_vector$a2.fromBufferAttribute(attribute, i)); } return this; } setFromPoints(points) { this.makeEmpty(); for (let i = 0, il = points.length; i < il; i++) { this.expandByPoint(points[i]); } return this; } setFromCenterAndSize(center, size) { const halfSize = _vector$a2.copy(size).multiplyScalar(0.5); this.min.copy(center).sub(halfSize); this.max.copy(center).add(halfSize); return this; } setFromObject(object, precise = false) { this.makeEmpty(); return this.expandByObject(object, precise); } clone() { return new this.constructor().copy(this); } copy(box) { this.min.copy(box.min); this.max.copy(box.max); return this; } makeEmpty() { this.min.x = this.min.y = this.min.z = Infinity; this.max.x = this.max.y = this.max.z = -Infinity; return this; } isEmpty() { return this.max.x < this.min.x || this.max.y < this.min.y || this.max.z < this.min.z; } getCenter(target) { return this.isEmpty() ? target.set(0, 0, 0) : target.addVectors(this.min, this.max).multiplyScalar(0.5); } getSize(target) { return this.isEmpty() ? target.set(0, 0, 0) : target.subVectors(this.max, this.min); } expandByPoint(point) { this.min.min(point); this.max.max(point); return this; } expandByVector(vector) { this.min.sub(vector); this.max.add(vector); return this; } expandByScalar(scalar) { this.min.addScalar(-scalar); this.max.addScalar(scalar); return this; } expandByObject(object, precise = false) { object.updateWorldMatrix(false, false); if (object.boundingBox !== void 0) { if (object.boundingBox === null) { object.computeBoundingBox(); } _box$32.copy(object.boundingBox); _box$32.applyMatrix4(object.matrixWorld); this.union(_box$32); } else { const geometry = object.geometry; if (geometry !== void 0) { if (precise && geometry.attributes !== void 0 && geometry.attributes.position !== void 0) { const position = geometry.attributes.position; for (let i = 0, l = position.count; i < l; i++) { _vector$a2.fromBufferAttribute(position, i).applyMatrix4(object.matrixWorld); this.expandByPoint(_vector$a2); } } else { if (geometry.boundingBox === null) { geometry.computeBoundingBox(); } _box$32.copy(geometry.boundingBox); _box$32.applyMatrix4(object.matrixWorld); this.union(_box$32); } } } const children = object.children; for (let i = 0, l = children.length; i < l; i++) { this.expandByObject(children[i], precise); } return this; } containsPoint(point) { return point.x < this.min.x || point.x > this.max.x || point.y < this.min.y || point.y > this.max.y || point.z < this.min.z || point.z > this.max.z ? false : true; } containsBox(box) { return this.min.x <= box.min.x && box.max.x <= this.max.x && this.min.y <= box.min.y && box.max.y <= this.max.y && this.min.z <= box.min.z && box.max.z <= this.max.z; } getParameter(point, target) { return target.set( (point.x - this.min.x) / (this.max.x - this.min.x), (point.y - this.min.y) / (this.max.y - this.min.y), (point.z - this.min.z) / (this.max.z - this.min.z) ); } intersectsBox(box) { return box.max.x < this.min.x || box.min.x > this.max.x || box.max.y < this.min.y || box.min.y > this.max.y || box.max.z < this.min.z || box.min.z > this.max.z ? false : true; } intersectsSphere(sphere) { this.clampPoint(sphere.center, _vector$a2); return _vector$a2.distanceToSquared(sphere.center) <= sphere.radius * sphere.radius; } intersectsPlane(plane) { let min2, max2; if (plane.normal.x > 0) { min2 = plane.normal.x * this.min.x; max2 = plane.normal.x * this.max.x; } else { min2 = plane.normal.x * this.max.x; max2 = plane.normal.x * this.min.x; } if (plane.normal.y > 0) { min2 += plane.normal.y * this.min.y; max2 += plane.normal.y * this.max.y; } else { min2 += plane.normal.y * this.max.y; max2 += plane.normal.y * this.min.y; } if (plane.normal.z > 0) { min2 += plane.normal.z * this.min.z; max2 += plane.normal.z * this.max.z; } else { min2 += plane.normal.z * this.max.z; max2 += plane.normal.z * this.min.z; } return min2 <= -plane.constant && max2 >= -plane.constant; } intersectsTriangle(triangle) { if (this.isEmpty()) { return false; } this.getCenter(_center2); _extents2.subVectors(this.max, _center2); _v0$22.subVectors(triangle.a, _center2); _v1$72.subVectors(triangle.b, _center2); _v2$42.subVectors(triangle.c, _center2); _f02.subVectors(_v1$72, _v0$22); _f12.subVectors(_v2$42, _v1$72); _f22.subVectors(_v0$22, _v2$42); let axes = [ 0, -_f02.z, _f02.y, 0, -_f12.z, _f12.y, 0, -_f22.z, _f22.y, _f02.z, 0, -_f02.x, _f12.z, 0, -_f12.x, _f22.z, 0, -_f22.x, -_f02.y, _f02.x, 0, -_f12.y, _f12.x, 0, -_f22.y, _f22.x, 0 ]; if (!satForAxes2(axes, _v0$22, _v1$72, _v2$42, _extents2)) { return false; } axes = [1, 0, 0, 0, 1, 0, 0, 0, 1]; if (!satForAxes2(axes, _v0$22, _v1$72, _v2$42, _extents2)) { return false; } _triangleNormal2.crossVectors(_f02, _f12); axes = [_triangleNormal2.x, _triangleNormal2.y, _triangleNormal2.z]; return satForAxes2(axes, _v0$22, _v1$72, _v2$42, _extents2); } clampPoint(point, target) { return target.copy(point).clamp(this.min, this.max); } distanceToPoint(point) { return this.clampPoint(point, _vector$a2).distanceTo(point); } getBoundingSphere(target) { if (this.isEmpty()) { target.makeEmpty(); } else { this.getCenter(target.center); target.radius = this.getSize(_vector$a2).length() * 0.5; } return target; } intersect(box) { this.min.max(box.min); this.max.min(box.max); if (this.isEmpty()) this.makeEmpty(); return this; } union(box) { this.min.min(box.min); this.max.max(box.max); return this; } applyMatrix4(matrix) { if (this.isEmpty()) return this; _points2[0].set(this.min.x, this.min.y, this.min.z).applyMatrix4(matrix); _points2[1].set(this.min.x, this.min.y, this.max.z).applyMatrix4(matrix); _points2[2].set(this.min.x, this.max.y, this.min.z).applyMatrix4(matrix); _points2[3].set(this.min.x, this.max.y, this.max.z).applyMatrix4(matrix); _points2[4].set(this.max.x, this.min.y, this.min.z).applyMatrix4(matrix); _points2[5].set(this.max.x, this.min.y, this.max.z).applyMatrix4(matrix); _points2[6].set(this.max.x, this.max.y, this.min.z).applyMatrix4(matrix); _points2[7].set(this.max.x, this.max.y, this.max.z).applyMatrix4(matrix); this.setFromPoints(_points2); return this; } translate(offset) { this.min.add(offset); this.max.add(offset); return this; } equals(box) { return box.min.equals(this.min) && box.max.equals(this.max); } }; var _points2 = [ /* @__PURE__ */ new Vector32(), /* @__PURE__ */ new Vector32(), /* @__PURE__ */ new Vector32(), /* @__PURE__ */ new Vector32(), /* @__PURE__ */ new Vector32(), /* @__PURE__ */ new Vector32(), /* @__PURE__ */ new Vector32(), /* @__PURE__ */ new Vector32() ]; var _vector$a2 = /* @__PURE__ */ new Vector32(); var _box$32 = /* @__PURE__ */ new Box32(); var _v0$22 = /* @__PURE__ */ new Vector32(); var _v1$72 = /* @__PURE__ */ new Vector32(); var _v2$42 = /* @__PURE__ */ new Vector32(); var _f02 = /* @__PURE__ */ new Vector32(); var _f12 = /* @__PURE__ */ new Vector32(); var _f22 = /* @__PURE__ */ new Vector32(); var _center2 = /* @__PURE__ */ new Vector32(); var _extents2 = /* @__PURE__ */ new Vector32(); var _triangleNormal2 = /* @__PURE__ */ new Vector32(); var _testAxis2 = /* @__PURE__ */ new Vector32(); function satForAxes2(axes, v0, v1, v2, extents) { for (let i = 0, j = axes.length - 3; i <= j; i += 3) { _testAxis2.fromArray(axes, i); const r = extents.x * Math.abs(_testAxis2.x) + extents.y * Math.abs(_testAxis2.y) + extents.z * Math.abs(_testAxis2.z); const p0 = v0.dot(_testAxis2); const p1 = v1.dot(_testAxis2); const p2 = v2.dot(_testAxis2); if (Math.max(-Math.max(p0, p1, p2), Math.min(p0, p1, p2)) > r) { return false; } } return true; } var _box$22 = /* @__PURE__ */ new Box32(); var _v1$62 = /* @__PURE__ */ new Vector32(); var _v2$32 = /* @__PURE__ */ new Vector32(); var Sphere2 = class { constructor(center = new Vector32(), radius = -1) { this.center = center; this.radius = radius; } set(center, radius) { this.center.copy(center); this.radius = radius; return this; } setFromPoints(points, optionalCenter) { const center = this.center; if (optionalCenter !== void 0) { center.copy(optionalCenter); } else { _box$22.setFromPoints(points).getCenter(center); } let maxRadiusSq = 0; for (let i = 0, il = points.length; i < il; i++) { maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(points[i])); } this.radius = Math.sqrt(maxRadiusSq); return this; } copy(sphere) { this.center.copy(sphere.center); this.radius = sphere.radius; return this; } isEmpty() { return this.radius < 0; } makeEmpty() { this.center.set(0, 0, 0); this.radius = -1; return this; } containsPoint(point) { return point.distanceToSquared(this.center) <= this.radius * this.radius; } distanceToPoint(point) { return point.distanceTo(this.center) - this.radius; } intersectsSphere(sphere) { const radiusSum = this.radius + sphere.radius; return sphere.center.distanceToSquared(this.center) <= radiusSum * radiusSum; } intersectsBox(box) { return box.intersectsSphere(this); } intersectsPlane(plane) { return Math.abs(plane.distanceToPoint(this.center)) <= this.radius; } clampPoint(point, target) { const deltaLengthSq = this.center.distanceToSquared(point); target.copy(point); if (deltaLengthSq > this.radius * this.radius) { target.sub(this.center).normalize(); target.multiplyScalar(this.radius).add(this.center); } return target; } getBoundingBox(target) { if (this.isEmpty()) { target.makeEmpty(); return target; } target.set(this.center, this.center); target.expandByScalar(this.radius); return target; } applyMatrix4(matrix) { this.center.applyMatrix4(matrix); this.radius = this.radius * matrix.getMaxScaleOnAxis(); return this; } translate(offset) { this.center.add(offset); return this; } expandByPoint(point) { if (this.isEmpty()) { this.center.copy(point); this.radius = 0; return this; } _v1$62.subVectors(point, this.center); const lengthSq = _v1$62.lengthSq(); if (lengthSq > this.radius * this.radius) { const length = Math.sqrt(lengthSq); const delta = (length - this.radius) * 0.5; this.center.addScaledVector(_v1$62, delta / length); this.radius += delta; } return this; } union(sphere) { if (sphere.isEmpty()) { return this; } if (this.isEmpty()) { this.copy(sphere); return this; } if (this.center.equals(sphere.center) === true) { this.radius = Math.max(this.radius, sphere.radius); } else { _v2$32.subVectors(sphere.center, this.center).setLength(sphere.radius); this.expandByPoint(_v1$62.copy(sphere.center).add(_v2$32)); this.expandByPoint(_v1$62.copy(sphere.center).sub(_v2$32)); } return this; } equals(sphere) { return sphere.center.equals(this.center) && sphere.radius === this.radius; } clone() { return new this.constructor().copy(this); } }; var _vector$92 = /* @__PURE__ */ new Vector32(); var _segCenter2 = /* @__PURE__ */ new Vector32(); var _segDir2 = /* @__PURE__ */ new Vector32(); var _diff2 = /* @__PURE__ */ new Vector32(); var _edge12 = /* @__PURE__ */ new Vector32(); var _edge22 = /* @__PURE__ */ new Vector32(); var _normal$12 = /* @__PURE__ */ new Vector32(); var Ray2 = class { constructor(origin3 = new Vector32(), direction = new Vector32(0, 0, -1)) { this.origin = origin3; this.direction = direction; } set(origin3, direction) { this.origin.copy(origin3); this.direction.copy(direction); return this; } copy(ray) { this.origin.copy(ray.origin); this.direction.copy(ray.direction); return this; } at(t, target) { return target.copy(this.origin).addScaledVector(this.direction, t); } lookAt(v) { this.direction.copy(v).sub(this.origin).normalize(); return this; } recast(t) { this.origin.copy(this.at(t, _vector$92)); return this; } closestPointToPoint(point, target) { target.subVectors(point, this.origin); const directionDistance = target.dot(this.direction); if (directionDistance < 0) { return target.copy(this.origin); } return target.copy(this.origin).addScaledVector(this.direction, directionDistance); } distanceToPoint(point) { return Math.sqrt(this.distanceSqToPoint(point)); } distanceSqToPoint(point) { const directionDistance = _vector$92.subVectors(point, this.origin).dot(this.direction); if (directionDistance < 0) { return this.origin.distanceToSquared(point); } _vector$92.copy(this.origin).addScaledVector(this.direction, directionDistance); return _vector$92.distanceToSquared(point); } distanceSqToSegment(v0, v1, optionalPointOnRay, optionalPointOnSegment) { _segCenter2.copy(v0).add(v1).multiplyScalar(0.5); _segDir2.copy(v1).sub(v0).normalize(); _diff2.copy(this.origin).sub(_segCenter2); const segExtent = v0.distanceTo(v1) * 0.5; const a01 = -this.direction.dot(_segDir2); const b0 = _diff2.dot(this.direction); const b1 = -_diff2.dot(_segDir2); const c2 = _diff2.lengthSq(); const det = Math.abs(1 - a01 * a01); let s0, s1, sqrDist, extDet; if (det > 0) { s0 = a01 * b1 - b0; s1 = a01 * b0 - b1; extDet = segExtent * det; if (s0 >= 0) { if (s1 >= -extDet) { if (s1 <= extDet) { const invDet = 1 / det; s0 *= invDet; s1 *= invDet; sqrDist = s0 * (s0 + a01 * s1 + 2 * b0) + s1 * (a01 * s0 + s1 + 2 * b1) + c2; } else { s1 = segExtent; s0 = Math.max(0, -(a01 * s1 + b0)); sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c2; } } else { s1 = -segExtent; s0 = Math.max(0, -(a01 * s1 + b0)); sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c2; } } else { if (s1 <= -extDet) { s0 = Math.max(0, -(-a01 * segExtent + b0)); s1 = s0 > 0 ? -segExtent : Math.min(Math.max(-segExtent, -b1), segExtent); sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c2; } else if (s1 <= extDet) { s0 = 0; s1 = Math.min(Math.max(-segExtent, -b1), segExtent); sqrDist = s1 * (s1 + 2 * b1) + c2; } else { s0 = Math.max(0, -(a01 * segExtent + b0)); s1 = s0 > 0 ? segExtent : Math.min(Math.max(-segExtent, -b1), segExtent); sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c2; } } } else { s1 = a01 > 0 ? -segExtent : segExtent; s0 = Math.max(0, -(a01 * s1 + b0)); sqrDist = -s0 * s0 + s1 * (s1 + 2 * b1) + c2; } if (optionalPointOnRay) { optionalPointOnRay.copy(this.origin).addScaledVector(this.direction, s0); } if (optionalPointOnSegment) { optionalPointOnSegment.copy(_segCenter2).addScaledVector(_segDir2, s1); } return sqrDist; } intersectSphere(sphere, target) { _vector$92.subVectors(sphere.center, this.origin); const tca = _vector$92.dot(this.direction); const d2 = _vector$92.dot(_vector$92) - tca * tca; const radius2 = sphere.radius * sphere.radius; if (d2 > radius2) return null; const thc = Math.sqrt(radius2 - d2); const t0 = tca - thc; const t1 = tca + thc; if (t1 < 0) return null; if (t0 < 0) return this.at(t1, target); return this.at(t0, target); } intersectsSphere(sphere) { return this.distanceSqToPoint(sphere.center) <= sphere.radius * sphere.radius; } distanceToPlane(plane) { const denominator = plane.normal.dot(this.direction); if (denominator === 0) { if (plane.distanceToPoint(this.origin) === 0) { return 0; } return null; } const t = -(this.origin.dot(plane.normal) + plane.constant) / denominator; return t >= 0 ? t : null; } intersectPlane(plane, target) { const t = this.distanceToPlane(plane); if (t === null) { return null; } return this.at(t, target); } intersectsPlane(plane) { const distToPoint = plane.distanceToPoint(this.origin); if (distToPoint === 0) { return true; } const denominator = plane.normal.dot(this.direction); if (denominator * distToPoint < 0) { return true; } return false; } intersectBox(box, target) { let tmin, tmax, tymin, tymax, tzmin, tzmax; const invdirx = 1 / this.direction.x, invdiry = 1 / this.direction.y, invdirz = 1 / this.direction.z; const origin3 = this.origin; if (invdirx >= 0) { tmin = (box.min.x - origin3.x) * invdirx; tmax = (box.max.x - origin3.x) * invdirx; } else { tmin = (box.max.x - origin3.x) * invdirx; tmax = (box.min.x - origin3.x) * invdirx; } if (invdiry >= 0) { tymin = (box.min.y - origin3.y) * invdiry; tymax = (box.max.y - origin3.y) * invdiry; } else { tymin = (box.max.y - origin3.y) * invdiry; tymax = (box.min.y - origin3.y) * invdiry; } if (tmin > tymax || tymin > tmax) return null; if (tymin > tmin || isNaN(tmin)) tmin = tymin; if (tymax < tmax || isNaN(tmax)) tmax = tymax; if (invdirz >= 0) { tzmin = (box.min.z - origin3.z) * invdirz; tzmax = (box.max.z - origin3.z) * invdirz; } else { tzmin = (box.max.z - origin3.z) * invdirz; tzmax = (box.min.z - origin3.z) * invdirz; } if (tmin > tzmax || tzmin > tmax) return null; if (tzmin > tmin || tmin !== tmin) tmin = tzmin; if (tzmax < tmax || tmax !== tmax) tmax = tzmax; if (tmax < 0) return null; return this.at(tmin >= 0 ? tmin : tmax, target); } intersectsBox(box) { return this.intersectBox(box, _vector$92) !== null; } intersectTriangle(a2, b, c2, backfaceCulling, target) { _edge12.subVectors(b, a2); _edge22.subVectors(c2, a2); _normal$12.crossVectors(_edge12, _edge22); let DdN = this.direction.dot(_normal$12); let sign; if (DdN > 0) { if (backfaceCulling) return null; sign = 1; } else if (DdN < 0) { sign = -1; DdN = -DdN; } else { return null; } _diff2.subVectors(this.origin, a2); const DdQxE2 = sign * this.direction.dot(_edge22.crossVectors(_diff2, _edge22)); if (DdQxE2 < 0) { return null; } const DdE1xQ = sign * this.direction.dot(_edge12.cross(_diff2)); if (DdE1xQ < 0) { return null; } if (DdQxE2 + DdE1xQ > DdN) { return null; } const QdN = -sign * _diff2.dot(_normal$12); if (QdN < 0) { return null; } return this.at(QdN / DdN, target); } applyMatrix4(matrix4) { this.origin.applyMatrix4(matrix4); this.direction.transformDirection(matrix4); return this; } equals(ray) { return ray.origin.equals(this.origin) && ray.direction.equals(this.direction); } clone() { return new this.constructor().copy(this); } }; var Matrix42 = class { constructor(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) { Matrix42.prototype.isMatrix4 = true; this.elements = [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]; if (n11 !== void 0) { this.set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44); } } set(n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44) { const te = this.elements; te[0] = n11; te[4] = n12; te[8] = n13; te[12] = n14; te[1] = n21; te[5] = n22; te[9] = n23; te[13] = n24; te[2] = n31; te[6] = n32; te[10] = n33; te[14] = n34; te[3] = n41; te[7] = n42; te[11] = n43; te[15] = n44; return this; } identity() { this.set( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ); return this; } clone() { return new Matrix42().fromArray(this.elements); } copy(m2) { const te = this.elements; const me = m2.elements; te[0] = me[0]; te[1] = me[1]; te[2] = me[2]; te[3] = me[3]; te[4] = me[4]; te[5] = me[5]; te[6] = me[6]; te[7] = me[7]; te[8] = me[8]; te[9] = me[9]; te[10] = me[10]; te[11] = me[11]; te[12] = me[12]; te[13] = me[13]; te[14] = me[14]; te[15] = me[15]; return this; } copyPosition(m2) { const te = this.elements, me = m2.elements; te[12] = me[12]; te[13] = me[13]; te[14] = me[14]; return this; } setFromMatrix3(m2) { const me = m2.elements; this.set( me[0], me[3], me[6], 0, me[1], me[4], me[7], 0, me[2], me[5], me[8], 0, 0, 0, 0, 1 ); return this; } extractBasis(xAxis, yAxis, zAxis) { xAxis.setFromMatrixColumn(this, 0); yAxis.setFromMatrixColumn(this, 1); zAxis.setFromMatrixColumn(this, 2); return this; } makeBasis(xAxis, yAxis, zAxis) { this.set( xAxis.x, yAxis.x, zAxis.x, 0, xAxis.y, yAxis.y, zAxis.y, 0, xAxis.z, yAxis.z, zAxis.z, 0, 0, 0, 0, 1 ); return this; } extractRotation(m2) { const te = this.elements; const me = m2.elements; const scaleX = 1 / _v1$52.setFromMatrixColumn(m2, 0).length(); const scaleY = 1 / _v1$52.setFromMatrixColumn(m2, 1).length(); const scaleZ = 1 / _v1$52.setFromMatrixColumn(m2, 2).length(); te[0] = me[0] * scaleX; te[1] = me[1] * scaleX; te[2] = me[2] * scaleX; te[3] = 0; te[4] = me[4] * scaleY; te[5] = me[5] * scaleY; te[6] = me[6] * scaleY; te[7] = 0; te[8] = me[8] * scaleZ; te[9] = me[9] * scaleZ; te[10] = me[10] * scaleZ; te[11] = 0; te[12] = 0; te[13] = 0; te[14] = 0; te[15] = 1; return this; } makeRotationFromEuler(euler) { const te = this.elements; const x3 = euler.x, y3 = euler.y, z4 = euler.z; const a2 = Math.cos(x3), b = Math.sin(x3); const c2 = Math.cos(y3), d = Math.sin(y3); const e = Math.cos(z4), f = Math.sin(z4); if (euler.order === "XYZ") { const ae = a2 * e, af = a2 * f, be = b * e, bf = b * f; te[0] = c2 * e; te[4] = -c2 * f; te[8] = d; te[1] = af + be * d; te[5] = ae - bf * d; te[9] = -b * c2; te[2] = bf - ae * d; te[6] = be + af * d; te[10] = a2 * c2; } else if (euler.order === "YXZ") { const ce = c2 * e, cf = c2 * f, de = d * e, df = d * f; te[0] = ce + df * b; te[4] = de * b - cf; te[8] = a2 * d; te[1] = a2 * f; te[5] = a2 * e; te[9] = -b; te[2] = cf * b - de; te[6] = df + ce * b; te[10] = a2 * c2; } else if (euler.order === "ZXY") { const ce = c2 * e, cf = c2 * f, de = d * e, df = d * f; te[0] = ce - df * b; te[4] = -a2 * f; te[8] = de + cf * b; te[1] = cf + de * b; te[5] = a2 * e; te[9] = df - ce * b; te[2] = -a2 * d; te[6] = b; te[10] = a2 * c2; } else if (euler.order === "ZYX") { const ae = a2 * e, af = a2 * f, be = b * e, bf = b * f; te[0] = c2 * e; te[4] = be * d - af; te[8] = ae * d + bf; te[1] = c2 * f; te[5] = bf * d + ae; te[9] = af * d - be; te[2] = -d; te[6] = b * c2; te[10] = a2 * c2; } else if (euler.order === "YZX") { const ac = a2 * c2, ad = a2 * d, bc = b * c2, bd = b * d; te[0] = c2 * e; te[4] = bd - ac * f; te[8] = bc * f + ad; te[1] = f; te[5] = a2 * e; te[9] = -b * e; te[2] = -d * e; te[6] = ad * f + bc; te[10] = ac - bd * f; } else if (euler.order === "XZY") { const ac = a2 * c2, ad = a2 * d, bc = b * c2, bd = b * d; te[0] = c2 * e; te[4] = -f; te[8] = d * e; te[1] = ac * f + bd; te[5] = a2 * e; te[9] = ad * f - bc; te[2] = bc * f - ad; te[6] = b * e; te[10] = bd * f + ac; } te[3] = 0; te[7] = 0; te[11] = 0; te[12] = 0; te[13] = 0; te[14] = 0; te[15] = 1; return this; } makeRotationFromQuaternion(q) { return this.compose(_zero2, q, _one2); } lookAt(eye, target, up) { const te = this.elements; _z2.subVectors(eye, target); if (_z2.lengthSq() === 0) { _z2.z = 1; } _z2.normalize(); _x2.crossVectors(up, _z2); if (_x2.lengthSq() === 0) { if (Math.abs(up.z) === 1) { _z2.x += 1e-4; } else { _z2.z += 1e-4; } _z2.normalize(); _x2.crossVectors(up, _z2); } _x2.normalize(); _y2.crossVectors(_z2, _x2); te[0] = _x2.x; te[4] = _y2.x; te[8] = _z2.x; te[1] = _x2.y; te[5] = _y2.y; te[9] = _z2.y; te[2] = _x2.z; te[6] = _y2.z; te[10] = _z2.z; return this; } multiply(m2) { return this.multiplyMatrices(this, m2); } premultiply(m2) { return this.multiplyMatrices(m2, this); } multiplyMatrices(a2, b) { const ae = a2.elements; const be = b.elements; const te = this.elements; const a11 = ae[0], a12 = ae[4], a13 = ae[8], a14 = ae[12]; const a21 = ae[1], a22 = ae[5], a23 = ae[9], a24 = ae[13]; const a31 = ae[2], a32 = ae[6], a33 = ae[10], a34 = ae[14]; const a41 = ae[3], a42 = ae[7], a43 = ae[11], a44 = ae[15]; const b11 = be[0], b12 = be[4], b13 = be[8], b14 = be[12]; const b21 = be[1], b22 = be[5], b23 = be[9], b24 = be[13]; const b31 = be[2], b32 = be[6], b33 = be[10], b34 = be[14]; const b41 = be[3], b42 = be[7], b43 = be[11], b44 = be[15]; te[0] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41; te[4] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42; te[8] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43; te[12] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44; te[1] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41; te[5] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42; te[9] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43; te[13] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44; te[2] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41; te[6] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42; te[10] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43; te[14] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44; te[3] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41; te[7] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42; te[11] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43; te[15] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44; return this; } multiplyScalar(s) { const te = this.elements; te[0] *= s; te[4] *= s; te[8] *= s; te[12] *= s; te[1] *= s; te[5] *= s; te[9] *= s; te[13] *= s; te[2] *= s; te[6] *= s; te[10] *= s; te[14] *= s; te[3] *= s; te[7] *= s; te[11] *= s; te[15] *= s; return this; } determinant() { const te = this.elements; const n11 = te[0], n12 = te[4], n13 = te[8], n14 = te[12]; const n21 = te[1], n22 = te[5], n23 = te[9], n24 = te[13]; const n31 = te[2], n32 = te[6], n33 = te[10], n34 = te[14]; const n41 = te[3], n42 = te[7], n43 = te[11], n44 = te[15]; return n41 * (+n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34) + n42 * (+n11 * n23 * n34 - n11 * n24 * n33 + n14 * n21 * n33 - n13 * n21 * n34 + n13 * n24 * n31 - n14 * n23 * n31) + n43 * (+n11 * n24 * n32 - n11 * n22 * n34 - n14 * n21 * n32 + n12 * n21 * n34 + n14 * n22 * n31 - n12 * n24 * n31) + n44 * (-n13 * n22 * n31 - n11 * n23 * n32 + n11 * n22 * n33 + n13 * n21 * n32 - n12 * n21 * n33 + n12 * n23 * n31); } transpose() { const te = this.elements; let tmp2; tmp2 = te[1]; te[1] = te[4]; te[4] = tmp2; tmp2 = te[2]; te[2] = te[8]; te[8] = tmp2; tmp2 = te[6]; te[6] = te[9]; te[9] = tmp2; tmp2 = te[3]; te[3] = te[12]; te[12] = tmp2; tmp2 = te[7]; te[7] = te[13]; te[13] = tmp2; tmp2 = te[11]; te[11] = te[14]; te[14] = tmp2; return this; } setPosition(x3, y3, z4) { const te = this.elements; if (x3.isVector3) { te[12] = x3.x; te[13] = x3.y; te[14] = x3.z; } else { te[12] = x3; te[13] = y3; te[14] = z4; } return this; } invert() { const te = this.elements, n11 = te[0], n21 = te[1], n31 = te[2], n41 = te[3], n12 = te[4], n22 = te[5], n32 = te[6], n42 = te[7], n13 = te[8], n23 = te[9], n33 = te[10], n43 = te[11], n14 = te[12], n24 = te[13], n34 = te[14], n44 = te[15], t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44, t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44, t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44, t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34; const det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14; if (det === 0) return this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); const detInv = 1 / det; te[0] = t11 * detInv; te[1] = (n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44) * detInv; te[2] = (n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44) * detInv; te[3] = (n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43) * detInv; te[4] = t12 * detInv; te[5] = (n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44) * detInv; te[6] = (n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44) * detInv; te[7] = (n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43) * detInv; te[8] = t13 * detInv; te[9] = (n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44) * detInv; te[10] = (n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44) * detInv; te[11] = (n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43) * detInv; te[12] = t14 * detInv; te[13] = (n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34) * detInv; te[14] = (n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34) * detInv; te[15] = (n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33) * detInv; return this; } scale(v) { const te = this.elements; const x3 = v.x, y3 = v.y, z4 = v.z; te[0] *= x3; te[4] *= y3; te[8] *= z4; te[1] *= x3; te[5] *= y3; te[9] *= z4; te[2] *= x3; te[6] *= y3; te[10] *= z4; te[3] *= x3; te[7] *= y3; te[11] *= z4; return this; } getMaxScaleOnAxis() { const te = this.elements; const scaleXSq = te[0] * te[0] + te[1] * te[1] + te[2] * te[2]; const scaleYSq = te[4] * te[4] + te[5] * te[5] + te[6] * te[6]; const scaleZSq = te[8] * te[8] + te[9] * te[9] + te[10] * te[10]; return Math.sqrt(Math.max(scaleXSq, scaleYSq, scaleZSq)); } makeTranslation(x3, y3, z4) { if (x3.isVector3) { this.set( 1, 0, 0, x3.x, 0, 1, 0, x3.y, 0, 0, 1, x3.z, 0, 0, 0, 1 ); } else { this.set( 1, 0, 0, x3, 0, 1, 0, y3, 0, 0, 1, z4, 0, 0, 0, 1 ); } return this; } makeRotationX(theta) { const c2 = Math.cos(theta), s = Math.sin(theta); this.set( 1, 0, 0, 0, 0, c2, -s, 0, 0, s, c2, 0, 0, 0, 0, 1 ); return this; } makeRotationY(theta) { const c2 = Math.cos(theta), s = Math.sin(theta); this.set( c2, 0, s, 0, 0, 1, 0, 0, -s, 0, c2, 0, 0, 0, 0, 1 ); return this; } makeRotationZ(theta) { const c2 = Math.cos(theta), s = Math.sin(theta); this.set( c2, -s, 0, 0, s, c2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ); return this; } makeRotationAxis(axis, angle) { const c2 = Math.cos(angle); const s = Math.sin(angle); const t = 1 - c2; const x3 = axis.x, y3 = axis.y, z4 = axis.z; const tx = t * x3, ty = t * y3; this.set( tx * x3 + c2, tx * y3 - s * z4, tx * z4 + s * y3, 0, tx * y3 + s * z4, ty * y3 + c2, ty * z4 - s * x3, 0, tx * z4 - s * y3, ty * z4 + s * x3, t * z4 * z4 + c2, 0, 0, 0, 0, 1 ); return this; } makeScale(x3, y3, z4) { this.set( x3, 0, 0, 0, 0, y3, 0, 0, 0, 0, z4, 0, 0, 0, 0, 1 ); return this; } makeShear(xy, xz, yx, yz, zx, zy) { this.set( 1, yx, zx, 0, xy, 1, zy, 0, xz, yz, 1, 0, 0, 0, 0, 1 ); return this; } compose(position, quaternion, scale) { const te = this.elements; const x3 = quaternion._x, y3 = quaternion._y, z4 = quaternion._z, w = quaternion._w; const x22 = x3 + x3, y22 = y3 + y3, z22 = z4 + z4; const xx = x3 * x22, xy = x3 * y22, xz = x3 * z22; const yy = y3 * y22, yz = y3 * z22, zz = z4 * z22; const wx = w * x22, wy = w * y22, wz = w * z22; const sx = scale.x, sy = scale.y, sz = scale.z; te[0] = (1 - (yy + zz)) * sx; te[1] = (xy + wz) * sx; te[2] = (xz - wy) * sx; te[3] = 0; te[4] = (xy - wz) * sy; te[5] = (1 - (xx + zz)) * sy; te[6] = (yz + wx) * sy; te[7] = 0; te[8] = (xz + wy) * sz; te[9] = (yz - wx) * sz; te[10] = (1 - (xx + yy)) * sz; te[11] = 0; te[12] = position.x; te[13] = position.y; te[14] = position.z; te[15] = 1; return this; } decompose(position, quaternion, scale) { const te = this.elements; let sx = _v1$52.set(te[0], te[1], te[2]).length(); const sy = _v1$52.set(te[4], te[5], te[6]).length(); const sz = _v1$52.set(te[8], te[9], te[10]).length(); const det = this.determinant(); if (det < 0) sx = -sx; position.x = te[12]; position.y = te[13]; position.z = te[14]; _m1$22.copy(this); const invSX = 1 / sx; const invSY = 1 / sy; const invSZ = 1 / sz; _m1$22.elements[0] *= invSX; _m1$22.elements[1] *= invSX; _m1$22.elements[2] *= invSX; _m1$22.elements[4] *= invSY; _m1$22.elements[5] *= invSY; _m1$22.elements[6] *= invSY; _m1$22.elements[8] *= invSZ; _m1$22.elements[9] *= invSZ; _m1$22.elements[10] *= invSZ; quaternion.setFromRotationMatrix(_m1$22); scale.x = sx; scale.y = sy; scale.z = sz; return this; } makePerspective(left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem2) { const te = this.elements; const x3 = 2 * near / (right - left); const y3 = 2 * near / (top - bottom); const a2 = (right + left) / (right - left); const b = (top + bottom) / (top - bottom); let c2, d; if (coordinateSystem === WebGLCoordinateSystem2) { c2 = -(far + near) / (far - near); d = -2 * far * near / (far - near); } else if (coordinateSystem === WebGPUCoordinateSystem2) { c2 = -far / (far - near); d = -far * near / (far - near); } else { throw new Error("THREE.Matrix4.makePerspective(): Invalid coordinate system: " + coordinateSystem); } te[0] = x3; te[4] = 0; te[8] = a2; te[12] = 0; te[1] = 0; te[5] = y3; te[9] = b; te[13] = 0; te[2] = 0; te[6] = 0; te[10] = c2; te[14] = d; te[3] = 0; te[7] = 0; te[11] = -1; te[15] = 0; return this; } makeOrthographic(left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem2) { const te = this.elements; const w = 1 / (right - left); const h = 1 / (top - bottom); const p = 1 / (far - near); const x3 = (right + left) * w; const y3 = (top + bottom) * h; let z4, zInv; if (coordinateSystem === WebGLCoordinateSystem2) { z4 = (far + near) * p; zInv = -2 * p; } else if (coordinateSystem === WebGPUCoordinateSystem2) { z4 = near * p; zInv = -1 * p; } else { throw new Error("THREE.Matrix4.makeOrthographic(): Invalid coordinate system: " + coordinateSystem); } te[0] = 2 * w; te[4] = 0; te[8] = 0; te[12] = -x3; te[1] = 0; te[5] = 2 * h; te[9] = 0; te[13] = -y3; te[2] = 0; te[6] = 0; te[10] = zInv; te[14] = -z4; te[3] = 0; te[7] = 0; te[11] = 0; te[15] = 1; return this; } equals(matrix) { const te = this.elements; const me = matrix.elements; for (let i = 0; i < 16; i++) { if (te[i] !== me[i]) return false; } return true; } fromArray(array, offset = 0) { for (let i = 0; i < 16; i++) { this.elements[i] = array[i + offset]; } return this; } toArray(array = [], offset = 0) { const te = this.elements; array[offset] = te[0]; array[offset + 1] = te[1]; array[offset + 2] = te[2]; array[offset + 3] = te[3]; array[offset + 4] = te[4]; array[offset + 5] = te[5]; array[offset + 6] = te[6]; array[offset + 7] = te[7]; array[offset + 8] = te[8]; array[offset + 9] = te[9]; array[offset + 10] = te[10]; array[offset + 11] = te[11]; array[offset + 12] = te[12]; array[offset + 13] = te[13]; array[offset + 14] = te[14]; array[offset + 15] = te[15]; return array; } }; var _v1$52 = /* @__PURE__ */ new Vector32(); var _m1$22 = /* @__PURE__ */ new Matrix42(); var _zero2 = /* @__PURE__ */ new Vector32(0, 0, 0); var _one2 = /* @__PURE__ */ new Vector32(1, 1, 1); var _x2 = /* @__PURE__ */ new Vector32(); var _y2 = /* @__PURE__ */ new Vector32(); var _z2 = /* @__PURE__ */ new Vector32(); var _matrix2 = /* @__PURE__ */ new Matrix42(); var _quaternion$32 = /* @__PURE__ */ new Quaternion2(); var Euler2 = class { constructor(x3 = 0, y3 = 0, z4 = 0, order = Euler2.DEFAULT_ORDER) { this.isEuler = true; this._x = x3; this._y = y3; this._z = z4; this._order = order; } get x() { return this._x; } set x(value) { this._x = value; this._onChangeCallback(); } get y() { return this._y; } set y(value) { this._y = value; this._onChangeCallback(); } get z() { return this._z; } set z(value) { this._z = value; this._onChangeCallback(); } get order() { return this._order; } set order(value) { this._order = value; this._onChangeCallback(); } set(x3, y3, z4, order = this._order) { this._x = x3; this._y = y3; this._z = z4; this._order = order; this._onChangeCallback(); return this; } clone() { return new this.constructor(this._x, this._y, this._z, this._order); } copy(euler) { this._x = euler._x; this._y = euler._y; this._z = euler._z; this._order = euler._order; this._onChangeCallback(); return this; } setFromRotationMatrix(m2, order = this._order, update4 = true) { const te = m2.elements; const m11 = te[0], m12 = te[4], m13 = te[8]; const m21 = te[1], m22 = te[5], m23 = te[9]; const m31 = te[2], m32 = te[6], m33 = te[10]; switch (order) { case "XYZ": this._y = Math.asin(clamp2(m13, -1, 1)); if (Math.abs(m13) < 0.9999999) { this._x = Math.atan2(-m23, m33); this._z = Math.atan2(-m12, m11); } else { this._x = Math.atan2(m32, m22); this._z = 0; } break; case "YXZ": this._x = Math.asin(-clamp2(m23, -1, 1)); if (Math.abs(m23) < 0.9999999) { this._y = Math.atan2(m13, m33); this._z = Math.atan2(m21, m22); } else { this._y = Math.atan2(-m31, m11); this._z = 0; } break; case "ZXY": this._x = Math.asin(clamp2(m32, -1, 1)); if (Math.abs(m32) < 0.9999999) { this._y = Math.atan2(-m31, m33); this._z = Math.atan2(-m12, m22); } else { this._y = 0; this._z = Math.atan2(m21, m11); } break; case "ZYX": this._y = Math.asin(-clamp2(m31, -1, 1)); if (Math.abs(m31) < 0.9999999) { this._x = Math.atan2(m32, m33); this._z = Math.atan2(m21, m11); } else { this._x = 0; this._z = Math.atan2(-m12, m22); } break; case "YZX": this._z = Math.asin(clamp2(m21, -1, 1)); if (Math.abs(m21) < 0.9999999) { this._x = Math.atan2(-m23, m22); this._y = Math.atan2(-m31, m11); } else { this._x = 0; this._y = Math.atan2(m13, m33); } break; case "XZY": this._z = Math.asin(-clamp2(m12, -1, 1)); if (Math.abs(m12) < 0.9999999) { this._x = Math.atan2(m32, m22); this._y = Math.atan2(m13, m11); } else { this._x = Math.atan2(-m23, m33); this._y = 0; } break; default: console.warn("THREE.Euler: .setFromRotationMatrix() encountered an unknown order: " + order); } this._order = order; if (update4 === true) this._onChangeCallback(); return this; } setFromQuaternion(q, order, update4) { _matrix2.makeRotationFromQuaternion(q); return this.setFromRotationMatrix(_matrix2, order, update4); } setFromVector3(v, order = this._order) { return this.set(v.x, v.y, v.z, order); } reorder(newOrder) { _quaternion$32.setFromEuler(this); return this.setFromQuaternion(_quaternion$32, newOrder); } equals(euler) { return euler._x === this._x && euler._y === this._y && euler._z === this._z && euler._order === this._order; } fromArray(array) { this._x = array[0]; this._y = array[1]; this._z = array[2]; if (array[3] !== void 0) this._order = array[3]; this._onChangeCallback(); return this; } toArray(array = [], offset = 0) { array[offset] = this._x; array[offset + 1] = this._y; array[offset + 2] = this._z; array[offset + 3] = this._order; return array; } _onChange(callback) { this._onChangeCallback = callback; return this; } _onChangeCallback() { } *[Symbol.iterator]() { yield this._x; yield this._y; yield this._z; yield this._order; } }; Euler2.DEFAULT_ORDER = "XYZ"; var Layers2 = class { constructor() { this.mask = 1 | 0; } set(channel) { this.mask = (1 << channel | 0) >>> 0; } enable(channel) { this.mask |= 1 << channel | 0; } enableAll() { this.mask = 4294967295 | 0; } toggle(channel) { this.mask ^= 1 << channel | 0; } disable(channel) { this.mask &= ~(1 << channel | 0); } disableAll() { this.mask = 0; } test(layers) { return (this.mask & layers.mask) !== 0; } isEnabled(channel) { return (this.mask & (1 << channel | 0)) !== 0; } }; var _object3DId2 = 0; var _v1$42 = /* @__PURE__ */ new Vector32(); var _q12 = /* @__PURE__ */ new Quaternion2(); var _m1$12 = /* @__PURE__ */ new Matrix42(); var _target2 = /* @__PURE__ */ new Vector32(); var _position$32 = /* @__PURE__ */ new Vector32(); var _scale$22 = /* @__PURE__ */ new Vector32(); var _quaternion$22 = /* @__PURE__ */ new Quaternion2(); var _xAxis2 = /* @__PURE__ */ new Vector32(1, 0, 0); var _yAxis2 = /* @__PURE__ */ new Vector32(0, 1, 0); var _zAxis2 = /* @__PURE__ */ new Vector32(0, 0, 1); var _addedEvent2 = { type: "added" }; var _removedEvent2 = { type: "removed" }; var Object3D2 = class extends EventDispatcher2 { constructor() { super(); this.isObject3D = true; Object.defineProperty(this, "id", { value: _object3DId2++ }); this.uuid = generateUUID2(); this.name = ""; this.type = "Object3D"; this.parent = null; this.children = []; this.up = Object3D2.DEFAULT_UP.clone(); const position = new Vector32(); const rotation = new Euler2(); const quaternion = new Quaternion2(); const scale = new Vector32(1, 1, 1); function onRotationChange() { quaternion.setFromEuler(rotation, false); } function onQuaternionChange() { rotation.setFromQuaternion(quaternion, void 0, false); } rotation._onChange(onRotationChange); quaternion._onChange(onQuaternionChange); Object.defineProperties(this, { position: { configurable: true, enumerable: true, value: position }, rotation: { configurable: true, enumerable: true, value: rotation }, quaternion: { configurable: true, enumerable: true, value: quaternion }, scale: { configurable: true, enumerable: true, value: scale }, modelViewMatrix: { value: new Matrix42() }, normalMatrix: { value: new Matrix32() } }); this.matrix = new Matrix42(); this.matrixWorld = new Matrix42(); this.matrixAutoUpdate = Object3D2.DEFAULT_MATRIX_AUTO_UPDATE; this.matrixWorldNeedsUpdate = false; this.matrixWorldAutoUpdate = Object3D2.DEFAULT_MATRIX_WORLD_AUTO_UPDATE; this.layers = new Layers2(); this.visible = true; this.castShadow = false; this.receiveShadow = false; this.frustumCulled = true; this.renderOrder = 0; this.animations = []; this.userData = {}; } onBeforeRender() { } onAfterRender() { } applyMatrix4(matrix) { if (this.matrixAutoUpdate) this.updateMatrix(); this.matrix.premultiply(matrix); this.matrix.decompose(this.position, this.quaternion, this.scale); } applyQuaternion(q) { this.quaternion.premultiply(q); return this; } setRotationFromAxisAngle(axis, angle) { this.quaternion.setFromAxisAngle(axis, angle); } setRotationFromEuler(euler) { this.quaternion.setFromEuler(euler, true); } setRotationFromMatrix(m2) { this.quaternion.setFromRotationMatrix(m2); } setRotationFromQuaternion(q) { this.quaternion.copy(q); } rotateOnAxis(axis, angle) { _q12.setFromAxisAngle(axis, angle); this.quaternion.multiply(_q12); return this; } rotateOnWorldAxis(axis, angle) { _q12.setFromAxisAngle(axis, angle); this.quaternion.premultiply(_q12); return this; } rotateX(angle) { return this.rotateOnAxis(_xAxis2, angle); } rotateY(angle) { return this.rotateOnAxis(_yAxis2, angle); } rotateZ(angle) { return this.rotateOnAxis(_zAxis2, angle); } translateOnAxis(axis, distance) { _v1$42.copy(axis).applyQuaternion(this.quaternion); this.position.add(_v1$42.multiplyScalar(distance)); return this; } translateX(distance) { return this.translateOnAxis(_xAxis2, distance); } translateY(distance) { return this.translateOnAxis(_yAxis2, distance); } translateZ(distance) { return this.translateOnAxis(_zAxis2, distance); } localToWorld(vector) { this.updateWorldMatrix(true, false); return vector.applyMatrix4(this.matrixWorld); } worldToLocal(vector) { this.updateWorldMatrix(true, false); return vector.applyMatrix4(_m1$12.copy(this.matrixWorld).invert()); } lookAt(x3, y3, z4) { if (x3.isVector3) { _target2.copy(x3); } else { _target2.set(x3, y3, z4); } const parent = this.parent; this.updateWorldMatrix(true, false); _position$32.setFromMatrixPosition(this.matrixWorld); if (this.isCamera || this.isLight) { _m1$12.lookAt(_position$32, _target2, this.up); } else { _m1$12.lookAt(_target2, _position$32, this.up); } this.quaternion.setFromRotationMatrix(_m1$12); if (parent) { _m1$12.extractRotation(parent.matrixWorld); _q12.setFromRotationMatrix(_m1$12); this.quaternion.premultiply(_q12.invert()); } } add(object) { if (arguments.length > 1) { for (let i = 0; i < arguments.length; i++) { this.add(arguments[i]); } return this; } if (object === this) { console.error("THREE.Object3D.add: object can't be added as a child of itself.", object); return this; } if (object && object.isObject3D) { if (object.parent !== null) { object.parent.remove(object); } object.parent = this; this.children.push(object); object.dispatchEvent(_addedEvent2); } else { console.error("THREE.Object3D.add: object not an instance of THREE.Object3D.", object); } return this; } remove(object) { if (arguments.length > 1) { for (let i = 0; i < arguments.length; i++) { this.remove(arguments[i]); } return this; } const index6 = this.children.indexOf(object); if (index6 !== -1) { object.parent = null; this.children.splice(index6, 1); object.dispatchEvent(_removedEvent2); } return this; } removeFromParent() { const parent = this.parent; if (parent !== null) { parent.remove(this); } return this; } clear() { return this.remove(...this.children); } attach(object) { this.updateWorldMatrix(true, false); _m1$12.copy(this.matrixWorld).invert(); if (object.parent !== null) { object.parent.updateWorldMatrix(true, false); _m1$12.multiply(object.parent.matrixWorld); } object.applyMatrix4(_m1$12); this.add(object); object.updateWorldMatrix(false, true); return this; } getObjectById(id) { return this.getObjectByProperty("id", id); } getObjectByName(name) { return this.getObjectByProperty("name", name); } getObjectByProperty(name, value) { if (this[name] === value) return this; for (let i = 0, l = this.children.length; i < l; i++) { const child = this.children[i]; const object = child.getObjectByProperty(name, value); if (object !== void 0) { return object; } } return void 0; } getObjectsByProperty(name, value) { let result = []; if (this[name] === value) result.push(this); for (let i = 0, l = this.children.length; i < l; i++) { const childResult = this.children[i].getObjectsByProperty(name, value); if (childResult.length > 0) { result = result.concat(childResult); } } return result; } getWorldPosition(target) { this.updateWorldMatrix(true, false); return target.setFromMatrixPosition(this.matrixWorld); } getWorldQuaternion(target) { this.updateWorldMatrix(true, false); this.matrixWorld.decompose(_position$32, target, _scale$22); return target; } getWorldScale(target) { this.updateWorldMatrix(true, false); this.matrixWorld.decompose(_position$32, _quaternion$22, target); return target; } getWorldDirection(target) { this.updateWorldMatrix(true, false); const e = this.matrixWorld.elements; return target.set(e[8], e[9], e[10]).normalize(); } raycast() { } traverse(callback) { callback(this); const children = this.children; for (let i = 0, l = children.length; i < l; i++) { children[i].traverse(callback); } } traverseVisible(callback) { if (this.visible === false) return; callback(this); const children = this.children; for (let i = 0, l = children.length; i < l; i++) { children[i].traverseVisible(callback); } } traverseAncestors(callback) { const parent = this.parent; if (parent !== null) { callback(parent); parent.traverseAncestors(callback); } } updateMatrix() { this.matrix.compose(this.position, this.quaternion, this.scale); this.matrixWorldNeedsUpdate = true; } updateMatrixWorld(force) { if (this.matrixAutoUpdate) this.updateMatrix(); if (this.matrixWorldNeedsUpdate || force) { if (this.parent === null) { this.matrixWorld.copy(this.matrix); } else { this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix); } this.matrixWorldNeedsUpdate = false; force = true; } const children = this.children; for (let i = 0, l = children.length; i < l; i++) { const child = children[i]; if (child.matrixWorldAutoUpdate === true || force === true) { child.updateMatrixWorld(force); } } } updateWorldMatrix(updateParents, updateChildren) { const parent = this.parent; if (updateParents === true && parent !== null && parent.matrixWorldAutoUpdate === true) { parent.updateWorldMatrix(true, false); } if (this.matrixAutoUpdate) this.updateMatrix(); if (this.parent === null) { this.matrixWorld.copy(this.matrix); } else { this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix); } if (updateChildren === true) { const children = this.children; for (let i = 0, l = children.length; i < l; i++) { const child = children[i]; if (child.matrixWorldAutoUpdate === true) { child.updateWorldMatrix(false, true); } } } } toJSON(meta) { const isRootObject = meta === void 0 || typeof meta === "string"; const output = {}; if (isRootObject) { meta = { geometries: {}, materials: {}, textures: {}, images: {}, shapes: {}, skeletons: {}, animations: {}, nodes: {} }; output.metadata = { version: 4.6, type: "Object", generator: "Object3D.toJSON" }; } const object = {}; object.uuid = this.uuid; object.type = this.type; if (this.name !== "") object.name = this.name; if (this.castShadow === true) object.castShadow = true; if (this.receiveShadow === true) object.receiveShadow = true; if (this.visible === false) object.visible = false; if (this.frustumCulled === false) object.frustumCulled = false; if (this.renderOrder !== 0) object.renderOrder = this.renderOrder; if (Object.keys(this.userData).length > 0) object.userData = this.userData; object.layers = this.layers.mask; object.matrix = this.matrix.toArray(); object.up = this.up.toArray(); if (this.matrixAutoUpdate === false) object.matrixAutoUpdate = false; if (this.isInstancedMesh) { object.type = "InstancedMesh"; object.count = this.count; object.instanceMatrix = this.instanceMatrix.toJSON(); if (this.instanceColor !== null) object.instanceColor = this.instanceColor.toJSON(); } function serialize(library, element) { if (library[element.uuid] === void 0) { library[element.uuid] = element.toJSON(meta); } return element.uuid; } if (this.isScene) { if (this.background) { if (this.background.isColor) { object.background = this.background.toJSON(); } else if (this.background.isTexture) { object.background = this.background.toJSON(meta).uuid; } } if (this.environment && this.environment.isTexture && this.environment.isRenderTargetTexture !== true) { object.environment = this.environment.toJSON(meta).uuid; } } else if (this.isMesh || this.isLine || this.isPoints) { object.geometry = serialize(meta.geometries, this.geometry); const parameters = this.geometry.parameters; if (parameters !== void 0 && parameters.shapes !== void 0) { const shapes = parameters.shapes; if (Array.isArray(shapes)) { for (let i = 0, l = shapes.length; i < l; i++) { const shape = shapes[i]; serialize(meta.shapes, shape); } } else { serialize(meta.shapes, shapes); } } } if (this.isSkinnedMesh) { object.bindMode = this.bindMode; object.bindMatrix = this.bindMatrix.toArray(); if (this.skeleton !== void 0) { serialize(meta.skeletons, this.skeleton); object.skeleton = this.skeleton.uuid; } } if (this.material !== void 0) { if (Array.isArray(this.material)) { const uuids = []; for (let i = 0, l = this.material.length; i < l; i++) { uuids.push(serialize(meta.materials, this.material[i])); } object.material = uuids; } else { object.material = serialize(meta.materials, this.material); } } if (this.children.length > 0) { object.children = []; for (let i = 0; i < this.children.length; i++) { object.children.push(this.children[i].toJSON(meta).object); } } if (this.animations.length > 0) { object.animations = []; for (let i = 0; i < this.animations.length; i++) { const animation = this.animations[i]; object.animations.push(serialize(meta.animations, animation)); } } if (isRootObject) { const geometries = extractFromCache(meta.geometries); const materials = extractFromCache(meta.materials); const textures = extractFromCache(meta.textures); const images = extractFromCache(meta.images); const shapes = extractFromCache(meta.shapes); const skeletons = extractFromCache(meta.skeletons); const animations = extractFromCache(meta.animations); const nodes = extractFromCache(meta.nodes); if (geometries.length > 0) output.geometries = geometries; if (materials.length > 0) output.materials = materials; if (textures.length > 0) output.textures = textures; if (images.length > 0) output.images = images; if (shapes.length > 0) output.shapes = shapes; if (skeletons.length > 0) output.skeletons = skeletons; if (animations.length > 0) output.animations = animations; if (nodes.length > 0) output.nodes = nodes; } output.object = object; return output; function extractFromCache(cache) { const values = []; for (const key in cache) { const data = cache[key]; delete data.metadata; values.push(data); } return values; } } clone(recursive) { return new this.constructor().copy(this, recursive); } copy(source, recursive = true) { this.name = source.name; this.up.copy(source.up); this.position.copy(source.position); this.rotation.order = source.rotation.order; this.quaternion.copy(source.quaternion); this.scale.copy(source.scale); this.matrix.copy(source.matrix); this.matrixWorld.copy(source.matrixWorld); this.matrixAutoUpdate = source.matrixAutoUpdate; this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate; this.matrixWorldAutoUpdate = source.matrixWorldAutoUpdate; this.layers.mask = source.layers.mask; this.visible = source.visible; this.castShadow = source.castShadow; this.receiveShadow = source.receiveShadow; this.frustumCulled = source.frustumCulled; this.renderOrder = source.renderOrder; this.animations = source.animations.slice(); this.userData = JSON.parse(JSON.stringify(source.userData)); if (recursive === true) { for (let i = 0; i < source.children.length; i++) { const child = source.children[i]; this.add(child.clone()); } } return this; } }; Object3D2.DEFAULT_UP = /* @__PURE__ */ new Vector32(0, 1, 0); Object3D2.DEFAULT_MATRIX_AUTO_UPDATE = true; Object3D2.DEFAULT_MATRIX_WORLD_AUTO_UPDATE = true; var _v0$12 = /* @__PURE__ */ new Vector32(); var _v1$32 = /* @__PURE__ */ new Vector32(); var _v2$22 = /* @__PURE__ */ new Vector32(); var _v3$12 = /* @__PURE__ */ new Vector32(); var _vab2 = /* @__PURE__ */ new Vector32(); var _vac2 = /* @__PURE__ */ new Vector32(); var _vbc2 = /* @__PURE__ */ new Vector32(); var _vap2 = /* @__PURE__ */ new Vector32(); var _vbp2 = /* @__PURE__ */ new Vector32(); var _vcp2 = /* @__PURE__ */ new Vector32(); var warnedGetUV2 = false; var Triangle2 = class { constructor(a2 = new Vector32(), b = new Vector32(), c2 = new Vector32()) { this.a = a2; this.b = b; this.c = c2; } static getNormal(a2, b, c2, target) { target.subVectors(c2, b); _v0$12.subVectors(a2, b); target.cross(_v0$12); const targetLengthSq = target.lengthSq(); if (targetLengthSq > 0) { return target.multiplyScalar(1 / Math.sqrt(targetLengthSq)); } return target.set(0, 0, 0); } // static/instance method to calculate barycentric coordinates // based on: http://www.blackpawn.com/texts/pointinpoly/default.html static getBarycoord(point, a2, b, c2, target) { _v0$12.subVectors(c2, a2); _v1$32.subVectors(b, a2); _v2$22.subVectors(point, a2); const dot00 = _v0$12.dot(_v0$12); const dot01 = _v0$12.dot(_v1$32); const dot02 = _v0$12.dot(_v2$22); const dot11 = _v1$32.dot(_v1$32); const dot12 = _v1$32.dot(_v2$22); const denom = dot00 * dot11 - dot01 * dot01; if (denom === 0) { return target.set(-2, -1, -1); } const invDenom = 1 / denom; const u = (dot11 * dot02 - dot01 * dot12) * invDenom; const v = (dot00 * dot12 - dot01 * dot02) * invDenom; return target.set(1 - u - v, v, u); } static containsPoint(point, a2, b, c2) { this.getBarycoord(point, a2, b, c2, _v3$12); return _v3$12.x >= 0 && _v3$12.y >= 0 && _v3$12.x + _v3$12.y <= 1; } static getUV(point, p1, p2, p3, uv1, uv2, uv3, target) { if (warnedGetUV2 === false) { console.warn("THREE.Triangle.getUV() has been renamed to THREE.Triangle.getInterpolation()."); warnedGetUV2 = true; } return this.getInterpolation(point, p1, p2, p3, uv1, uv2, uv3, target); } static getInterpolation(point, p1, p2, p3, v1, v2, v3, target) { this.getBarycoord(point, p1, p2, p3, _v3$12); target.setScalar(0); target.addScaledVector(v1, _v3$12.x); target.addScaledVector(v2, _v3$12.y); target.addScaledVector(v3, _v3$12.z); return target; } static isFrontFacing(a2, b, c2, direction) { _v0$12.subVectors(c2, b); _v1$32.subVectors(a2, b); return _v0$12.cross(_v1$32).dot(direction) < 0 ? true : false; } set(a2, b, c2) { this.a.copy(a2); this.b.copy(b); this.c.copy(c2); return this; } setFromPointsAndIndices(points, i0, i1, i2) { this.a.copy(points[i0]); this.b.copy(points[i1]); this.c.copy(points[i2]); return this; } setFromAttributeAndIndices(attribute, i0, i1, i2) { this.a.fromBufferAttribute(attribute, i0); this.b.fromBufferAttribute(attribute, i1); this.c.fromBufferAttribute(attribute, i2); return this; } clone() { return new this.constructor().copy(this); } copy(triangle) { this.a.copy(triangle.a); this.b.copy(triangle.b); this.c.copy(triangle.c); return this; } getArea() { _v0$12.subVectors(this.c, this.b); _v1$32.subVectors(this.a, this.b); return _v0$12.cross(_v1$32).length() * 0.5; } getMidpoint(target) { return target.addVectors(this.a, this.b).add(this.c).multiplyScalar(1 / 3); } getNormal(target) { return Triangle2.getNormal(this.a, this.b, this.c, target); } getPlane(target) { return target.setFromCoplanarPoints(this.a, this.b, this.c); } getBarycoord(point, target) { return Triangle2.getBarycoord(point, this.a, this.b, this.c, target); } getUV(point, uv1, uv2, uv3, target) { if (warnedGetUV2 === false) { console.warn("THREE.Triangle.getUV() has been renamed to THREE.Triangle.getInterpolation()."); warnedGetUV2 = true; } return Triangle2.getInterpolation(point, this.a, this.b, this.c, uv1, uv2, uv3, target); } getInterpolation(point, v1, v2, v3, target) { return Triangle2.getInterpolation(point, this.a, this.b, this.c, v1, v2, v3, target); } containsPoint(point) { return Triangle2.containsPoint(point, this.a, this.b, this.c); } isFrontFacing(direction) { return Triangle2.isFrontFacing(this.a, this.b, this.c, direction); } intersectsBox(box) { return box.intersectsTriangle(this); } closestPointToPoint(p, target) { const a2 = this.a, b = this.b, c2 = this.c; let v, w; _vab2.subVectors(b, a2); _vac2.subVectors(c2, a2); _vap2.subVectors(p, a2); const d1 = _vab2.dot(_vap2); const d2 = _vac2.dot(_vap2); if (d1 <= 0 && d2 <= 0) { return target.copy(a2); } _vbp2.subVectors(p, b); const d3 = _vab2.dot(_vbp2); const d4 = _vac2.dot(_vbp2); if (d3 >= 0 && d4 <= d3) { return target.copy(b); } const vc = d1 * d4 - d3 * d2; if (vc <= 0 && d1 >= 0 && d3 <= 0) { v = d1 / (d1 - d3); return target.copy(a2).addScaledVector(_vab2, v); } _vcp2.subVectors(p, c2); const d5 = _vab2.dot(_vcp2); const d6 = _vac2.dot(_vcp2); if (d6 >= 0 && d5 <= d6) { return target.copy(c2); } const vb = d5 * d2 - d1 * d6; if (vb <= 0 && d2 >= 0 && d6 <= 0) { w = d2 / (d2 - d6); return target.copy(a2).addScaledVector(_vac2, w); } const va = d3 * d6 - d5 * d4; if (va <= 0 && d4 - d3 >= 0 && d5 - d6 >= 0) { _vbc2.subVectors(c2, b); w = (d4 - d3) / (d4 - d3 + (d5 - d6)); return target.copy(b).addScaledVector(_vbc2, w); } const denom = 1 / (va + vb + vc); v = vb * denom; w = vc * denom; return target.copy(a2).addScaledVector(_vab2, v).addScaledVector(_vac2, w); } equals(triangle) { return triangle.a.equals(this.a) && triangle.b.equals(this.b) && triangle.c.equals(this.c); } }; var _materialId2 = 0; var Material2 = class extends EventDispatcher2 { constructor() { super(); this.isMaterial = true; Object.defineProperty(this, "id", { value: _materialId2++ }); this.uuid = generateUUID2(); this.name = ""; this.type = "Material"; this.blending = NormalBlending2; this.side = FrontSide2; this.vertexColors = false; this.opacity = 1; this.transparent = false; this.alphaHash = false; this.blendSrc = SrcAlphaFactor2; this.blendDst = OneMinusSrcAlphaFactor2; this.blendEquation = AddEquation2; this.blendSrcAlpha = null; this.blendDstAlpha = null; this.blendEquationAlpha = null; this.depthFunc = LessEqualDepth2; this.depthTest = true; this.depthWrite = true; this.stencilWriteMask = 255; this.stencilFunc = AlwaysStencilFunc2; this.stencilRef = 0; this.stencilFuncMask = 255; this.stencilFail = KeepStencilOp2; this.stencilZFail = KeepStencilOp2; this.stencilZPass = KeepStencilOp2; this.stencilWrite = false; this.clippingPlanes = null; this.clipIntersection = false; this.clipShadows = false; this.shadowSide = null; this.colorWrite = true; this.precision = null; this.polygonOffset = false; this.polygonOffsetFactor = 0; this.polygonOffsetUnits = 0; this.dithering = false; this.alphaToCoverage = false; this.premultipliedAlpha = false; this.forceSinglePass = false; this.visible = true; this.toneMapped = true; this.userData = {}; this.version = 0; this._alphaTest = 0; } get alphaTest() { return this._alphaTest; } set alphaTest(value) { if (this._alphaTest > 0 !== value > 0) { this.version++; } this._alphaTest = value; } onBuild() { } onBeforeRender() { } onBeforeCompile() { } customProgramCacheKey() { return this.onBeforeCompile.toString(); } setValues(values) { if (values === void 0) return; for (const key in values) { const newValue = values[key]; if (newValue === void 0) { console.warn(`THREE.Material: parameter '${key}' has value of undefined.`); continue; } const currentValue = this[key]; if (currentValue === void 0) { console.warn(`THREE.Material: '${key}' is not a property of THREE.${this.type}.`); continue; } if (currentValue && currentValue.isColor) { currentValue.set(newValue); } else if (currentValue && currentValue.isVector3 && (newValue && newValue.isVector3)) { currentValue.copy(newValue); } else { this[key] = newValue; } } } toJSON(meta) { const isRootObject = meta === void 0 || typeof meta === "string"; if (isRootObject) { meta = { textures: {}, images: {} }; } const data = { metadata: { version: 4.6, type: "Material", generator: "Material.toJSON" } }; data.uuid = this.uuid; data.type = this.type; if (this.name !== "") data.name = this.name; if (this.color && this.color.isColor) data.color = this.color.getHex(); if (this.roughness !== void 0) data.roughness = this.roughness; if (this.metalness !== void 0) data.metalness = this.metalness; if (this.sheen !== void 0) data.sheen = this.sheen; if (this.sheenColor && this.sheenColor.isColor) data.sheenColor = this.sheenColor.getHex(); if (this.sheenRoughness !== void 0) data.sheenRoughness = this.sheenRoughness; if (this.emissive && this.emissive.isColor) data.emissive = this.emissive.getHex(); if (this.emissiveIntensity && this.emissiveIntensity !== 1) data.emissiveIntensity = this.emissiveIntensity; if (this.specular && this.specular.isColor) data.specular = this.specular.getHex(); if (this.specularIntensity !== void 0) data.specularIntensity = this.specularIntensity; if (this.specularColor && this.specularColor.isColor) data.specularColor = this.specularColor.getHex(); if (this.shininess !== void 0) data.shininess = this.shininess; if (this.clearcoat !== void 0) data.clearcoat = this.clearcoat; if (this.clearcoatRoughness !== void 0) data.clearcoatRoughness = this.clearcoatRoughness; if (this.clearcoatMap && this.clearcoatMap.isTexture) { data.clearcoatMap = this.clearcoatMap.toJSON(meta).uuid; } if (this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture) { data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON(meta).uuid; } if (this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture) { data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON(meta).uuid; data.clearcoatNormalScale = this.clearcoatNormalScale.toArray(); } if (this.iridescence !== void 0) data.iridescence = this.iridescence; if (this.iridescenceIOR !== void 0) data.iridescenceIOR = this.iridescenceIOR; if (this.iridescenceThicknessRange !== void 0) data.iridescenceThicknessRange = this.iridescenceThicknessRange; if (this.iridescenceMap && this.iridescenceMap.isTexture) { data.iridescenceMap = this.iridescenceMap.toJSON(meta).uuid; } if (this.iridescenceThicknessMap && this.iridescenceThicknessMap.isTexture) { data.iridescenceThicknessMap = this.iridescenceThicknessMap.toJSON(meta).uuid; } if (this.anisotropy !== void 0) data.anisotropy = this.anisotropy; if (this.anisotropyRotation !== void 0) data.anisotropyRotation = this.anisotropyRotation; if (this.anisotropyMap && this.anisotropyMap.isTexture) { data.anisotropyMap = this.anisotropyMap.toJSON(meta).uuid; } if (this.map && this.map.isTexture) data.map = this.map.toJSON(meta).uuid; if (this.matcap && this.matcap.isTexture) data.matcap = this.matcap.toJSON(meta).uuid; if (this.alphaMap && this.alphaMap.isTexture) data.alphaMap = this.alphaMap.toJSON(meta).uuid; if (this.lightMap && this.lightMap.isTexture) { data.lightMap = this.lightMap.toJSON(meta).uuid; data.lightMapIntensity = this.lightMapIntensity; } if (this.aoMap && this.aoMap.isTexture) { data.aoMap = this.aoMap.toJSON(meta).uuid; data.aoMapIntensity = this.aoMapIntensity; } if (this.bumpMap && this.bumpMap.isTexture) { data.bumpMap = this.bumpMap.toJSON(meta).uuid; data.bumpScale = this.bumpScale; } if (this.normalMap && this.normalMap.isTexture) { data.normalMap = this.normalMap.toJSON(meta).uuid; data.normalMapType = this.normalMapType; data.normalScale = this.normalScale.toArray(); } if (this.displacementMap && this.displacementMap.isTexture) { data.displacementMap = this.displacementMap.toJSON(meta).uuid; data.displacementScale = this.displacementScale; data.displacementBias = this.displacementBias; } if (this.roughnessMap && this.roughnessMap.isTexture) data.roughnessMap = this.roughnessMap.toJSON(meta).uuid; if (this.metalnessMap && this.metalnessMap.isTexture) data.metalnessMap = this.metalnessMap.toJSON(meta).uuid; if (this.emissiveMap && this.emissiveMap.isTexture) data.emissiveMap = this.emissiveMap.toJSON(meta).uuid; if (this.specularMap && this.specularMap.isTexture) data.specularMap = this.specularMap.toJSON(meta).uuid; if (this.specularIntensityMap && this.specularIntensityMap.isTexture) data.specularIntensityMap = this.specularIntensityMap.toJSON(meta).uuid; if (this.specularColorMap && this.specularColorMap.isTexture) data.specularColorMap = this.specularColorMap.toJSON(meta).uuid; if (this.envMap && this.envMap.isTexture) { data.envMap = this.envMap.toJSON(meta).uuid; if (this.combine !== void 0) data.combine = this.combine; } if (this.envMapIntensity !== void 0) data.envMapIntensity = this.envMapIntensity; if (this.reflectivity !== void 0) data.reflectivity = this.reflectivity; if (this.refractionRatio !== void 0) data.refractionRatio = this.refractionRatio; if (this.gradientMap && this.gradientMap.isTexture) { data.gradientMap = this.gradientMap.toJSON(meta).uuid; } if (this.transmission !== void 0) data.transmission = this.transmission; if (this.transmissionMap && this.transmissionMap.isTexture) data.transmissionMap = this.transmissionMap.toJSON(meta).uuid; if (this.thickness !== void 0) data.thickness = this.thickness; if (this.thicknessMap && this.thicknessMap.isTexture) data.thicknessMap = this.thicknessMap.toJSON(meta).uuid; if (this.attenuationDistance !== void 0 && this.attenuationDistance !== Infinity) data.attenuationDistance = this.attenuationDistance; if (this.attenuationColor !== void 0) data.attenuationColor = this.attenuationColor.getHex(); if (this.size !== void 0) data.size = this.size; if (this.shadowSide !== null) data.shadowSide = this.shadowSide; if (this.sizeAttenuation !== void 0) data.sizeAttenuation = this.sizeAttenuation; if (this.blending !== NormalBlending2) data.blending = this.blending; if (this.side !== FrontSide2) data.side = this.side; if (this.vertexColors === true) data.vertexColors = true; if (this.opacity < 1) data.opacity = this.opacity; if (this.transparent === true) data.transparent = true; data.depthFunc = this.depthFunc; data.depthTest = this.depthTest; data.depthWrite = this.depthWrite; data.colorWrite = this.colorWrite; data.stencilWrite = this.stencilWrite; data.stencilWriteMask = this.stencilWriteMask; data.stencilFunc = this.stencilFunc; data.stencilRef = this.stencilRef; data.stencilFuncMask = this.stencilFuncMask; data.stencilFail = this.stencilFail; data.stencilZFail = this.stencilZFail; data.stencilZPass = this.stencilZPass; if (this.rotation !== void 0 && this.rotation !== 0) data.rotation = this.rotation; if (this.polygonOffset === true) data.polygonOffset = true; if (this.polygonOffsetFactor !== 0) data.polygonOffsetFactor = this.polygonOffsetFactor; if (this.polygonOffsetUnits !== 0) data.polygonOffsetUnits = this.polygonOffsetUnits; if (this.linewidth !== void 0 && this.linewidth !== 1) data.linewidth = this.linewidth; if (this.dashSize !== void 0) data.dashSize = this.dashSize; if (this.gapSize !== void 0) data.gapSize = this.gapSize; if (this.scale !== void 0) data.scale = this.scale; if (this.dithering === true) data.dithering = true; if (this.alphaTest > 0) data.alphaTest = this.alphaTest; if (this.alphaHash === true) data.alphaHash = true; if (this.alphaToCoverage === true) data.alphaToCoverage = true; if (this.premultipliedAlpha === true) data.premultipliedAlpha = true; if (this.forceSinglePass === true) data.forceSinglePass = true; if (this.wireframe === true) data.wireframe = true; if (this.wireframeLinewidth > 1) data.wireframeLinewidth = this.wireframeLinewidth; if (this.wireframeLinecap !== "round") data.wireframeLinecap = this.wireframeLinecap; if (this.wireframeLinejoin !== "round") data.wireframeLinejoin = this.wireframeLinejoin; if (this.flatShading === true) data.flatShading = true; if (this.visible === false) data.visible = false; if (this.toneMapped === false) data.toneMapped = false; if (this.fog === false) data.fog = false; if (Object.keys(this.userData).length > 0) data.userData = this.userData; function extractFromCache(cache) { const values = []; for (const key in cache) { const data2 = cache[key]; delete data2.metadata; values.push(data2); } return values; } if (isRootObject) { const textures = extractFromCache(meta.textures); const images = extractFromCache(meta.images); if (textures.length > 0) data.textures = textures; if (images.length > 0) data.images = images; } return data; } clone() { return new this.constructor().copy(this); } copy(source) { this.name = source.name; this.blending = source.blending; this.side = source.side; this.vertexColors = source.vertexColors; this.opacity = source.opacity; this.transparent = source.transparent; this.blendSrc = source.blendSrc; this.blendDst = source.blendDst; this.blendEquation = source.blendEquation; this.blendSrcAlpha = source.blendSrcAlpha; this.blendDstAlpha = source.blendDstAlpha; this.blendEquationAlpha = source.blendEquationAlpha; this.depthFunc = source.depthFunc; this.depthTest = source.depthTest; this.depthWrite = source.depthWrite; this.stencilWriteMask = source.stencilWriteMask; this.stencilFunc = source.stencilFunc; this.stencilRef = source.stencilRef; this.stencilFuncMask = source.stencilFuncMask; this.stencilFail = source.stencilFail; this.stencilZFail = source.stencilZFail; this.stencilZPass = source.stencilZPass; this.stencilWrite = source.stencilWrite; const srcPlanes = source.clippingPlanes; let dstPlanes = null; if (srcPlanes !== null) { const n = srcPlanes.length; dstPlanes = new Array(n); for (let i = 0; i !== n; ++i) { dstPlanes[i] = srcPlanes[i].clone(); } } this.clippingPlanes = dstPlanes; this.clipIntersection = source.clipIntersection; this.clipShadows = source.clipShadows; this.shadowSide = source.shadowSide; this.colorWrite = source.colorWrite; this.precision = source.precision; this.polygonOffset = source.polygonOffset; this.polygonOffsetFactor = source.polygonOffsetFactor; this.polygonOffsetUnits = source.polygonOffsetUnits; this.dithering = source.dithering; this.alphaTest = source.alphaTest; this.alphaHash = source.alphaHash; this.alphaToCoverage = source.alphaToCoverage; this.premultipliedAlpha = source.premultipliedAlpha; this.forceSinglePass = source.forceSinglePass; this.visible = source.visible; this.toneMapped = source.toneMapped; this.userData = JSON.parse(JSON.stringify(source.userData)); return this; } dispose() { this.dispatchEvent({ type: "dispose" }); } set needsUpdate(value) { if (value === true) this.version++; } }; var _colorKeywords2 = { "aliceblue": 15792383, "antiquewhite": 16444375, "aqua": 65535, "aquamarine": 8388564, "azure": 15794175, "beige": 16119260, "bisque": 16770244, "black": 0, "blanchedalmond": 16772045, "blue": 255, "blueviolet": 9055202, "brown": 10824234, "burlywood": 14596231, "cadetblue": 6266528, "chartreuse": 8388352, "chocolate": 13789470, "coral": 16744272, "cornflowerblue": 6591981, "cornsilk": 16775388, "crimson": 14423100, "cyan": 65535, "darkblue": 139, "darkcyan": 35723, "darkgoldenrod": 12092939, "darkgray": 11119017, "darkgreen": 25600, "darkgrey": 11119017, "darkkhaki": 12433259, "darkmagenta": 9109643, "darkolivegreen": 5597999, "darkorange": 16747520, "darkorchid": 10040012, "darkred": 9109504, "darksalmon": 15308410, "darkseagreen": 9419919, "darkslateblue": 4734347, "darkslategray": 3100495, "darkslategrey": 3100495, "darkturquoise": 52945, "darkviolet": 9699539, "deeppink": 16716947, "deepskyblue": 49151, "dimgray": 6908265, "dimgrey": 6908265, "dodgerblue": 2003199, "firebrick": 11674146, "floralwhite": 16775920, "forestgreen": 2263842, "fuchsia": 16711935, "gainsboro": 14474460, "ghostwhite": 16316671, "gold": 16766720, "goldenrod": 14329120, "gray": 8421504, "green": 32768, "greenyellow": 11403055, "grey": 8421504, "honeydew": 15794160, "hotpink": 16738740, "indianred": 13458524, "indigo": 4915330, "ivory": 16777200, "khaki": 15787660, "lavender": 15132410, "lavenderblush": 16773365, "lawngreen": 8190976, "lemonchiffon": 16775885, "lightblue": 11393254, "lightcoral": 15761536, "lightcyan": 14745599, "lightgoldenrodyellow": 16448210, "lightgray": 13882323, "lightgreen": 9498256, "lightgrey": 13882323, "lightpink": 16758465, "lightsalmon": 16752762, "lightseagreen": 2142890, "lightskyblue": 8900346, "lightslategray": 7833753, "lightslategrey": 7833753, "lightsteelblue": 11584734, "lightyellow": 16777184, "lime": 65280, "limegreen": 3329330, "linen": 16445670, "magenta": 16711935, "maroon": 8388608, "mediumaquamarine": 6737322, "mediumblue": 205, "mediumorchid": 12211667, "mediumpurple": 9662683, "mediumseagreen": 3978097, "mediumslateblue": 8087790, "mediumspringgreen": 64154, "mediumturquoise": 4772300, "mediumvioletred": 13047173, "midnightblue": 1644912, "mintcream": 16121850, "mistyrose": 16770273, "moccasin": 16770229, "navajowhite": 16768685, "navy": 128, "oldlace": 16643558, "olive": 8421376, "olivedrab": 7048739, "orange": 16753920, "orangered": 16729344, "orchid": 14315734, "palegoldenrod": 15657130, "palegreen": 10025880, "paleturquoise": 11529966, "palevioletred": 14381203, "papayawhip": 16773077, "peachpuff": 16767673, "peru": 13468991, "pink": 16761035, "plum": 14524637, "powderblue": 11591910, "purple": 8388736, "rebeccapurple": 6697881, "red": 16711680, "rosybrown": 12357519, "royalblue": 4286945, "saddlebrown": 9127187, "salmon": 16416882, "sandybrown": 16032864, "seagreen": 3050327, "seashell": 16774638, "sienna": 10506797, "silver": 12632256, "skyblue": 8900331, "slateblue": 6970061, "slategray": 7372944, "slategrey": 7372944, "snow": 16775930, "springgreen": 65407, "steelblue": 4620980, "tan": 13808780, "teal": 32896, "thistle": 14204888, "tomato": 16737095, "turquoise": 4251856, "violet": 15631086, "wheat": 16113331, "white": 16777215, "whitesmoke": 16119285, "yellow": 16776960, "yellowgreen": 10145074 }; var _hslA2 = { h: 0, s: 0, l: 0 }; var _hslB2 = { h: 0, s: 0, l: 0 }; function hue2rgb2(p, q, t) { if (t < 0) t += 1; if (t > 1) t -= 1; if (t < 1 / 6) return p + (q - p) * 6 * t; if (t < 1 / 2) return q; if (t < 2 / 3) return p + (q - p) * 6 * (2 / 3 - t); return p; } var Color2 = class { constructor(r, g, b) { this.isColor = true; this.r = 1; this.g = 1; this.b = 1; return this.set(r, g, b); } set(r, g, b) { if (g === void 0 && b === void 0) { const value = r; if (value && value.isColor) { this.copy(value); } else if (typeof value === "number") { this.setHex(value); } else if (typeof value === "string") { this.setStyle(value); } } else { this.setRGB(r, g, b); } return this; } setScalar(scalar) { this.r = scalar; this.g = scalar; this.b = scalar; return this; } setHex(hex, colorSpace = SRGBColorSpace2) { hex = Math.floor(hex); this.r = (hex >> 16 & 255) / 255; this.g = (hex >> 8 & 255) / 255; this.b = (hex & 255) / 255; ColorManagement2.toWorkingColorSpace(this, colorSpace); return this; } setRGB(r, g, b, colorSpace = ColorManagement2.workingColorSpace) { this.r = r; this.g = g; this.b = b; ColorManagement2.toWorkingColorSpace(this, colorSpace); return this; } setHSL(h, s, l, colorSpace = ColorManagement2.workingColorSpace) { h = euclideanModulo2(h, 1); s = clamp2(s, 0, 1); l = clamp2(l, 0, 1); if (s === 0) { this.r = this.g = this.b = l; } else { const p = l <= 0.5 ? l * (1 + s) : l + s - l * s; const q = 2 * l - p; this.r = hue2rgb2(q, p, h + 1 / 3); this.g = hue2rgb2(q, p, h); this.b = hue2rgb2(q, p, h - 1 / 3); } ColorManagement2.toWorkingColorSpace(this, colorSpace); return this; } setStyle(style, colorSpace = SRGBColorSpace2) { function handleAlpha(string) { if (string === void 0) return; if (parseFloat(string) < 1) { console.warn("THREE.Color: Alpha component of " + style + " will be ignored."); } } let m2; if (m2 = /^(\w+)\(([^\)]*)\)/.exec(style)) { let color; const name = m2[1]; const components = m2[2]; switch (name) { case "rgb": case "rgba": if (color = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) { handleAlpha(color[4]); return this.setRGB( Math.min(255, parseInt(color[1], 10)) / 255, Math.min(255, parseInt(color[2], 10)) / 255, Math.min(255, parseInt(color[3], 10)) / 255, colorSpace ); } if (color = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) { handleAlpha(color[4]); return this.setRGB( Math.min(100, parseInt(color[1], 10)) / 100, Math.min(100, parseInt(color[2], 10)) / 100, Math.min(100, parseInt(color[3], 10)) / 100, colorSpace ); } break; case "hsl": case "hsla": if (color = /^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) { handleAlpha(color[4]); return this.setHSL( parseFloat(color[1]) / 360, parseFloat(color[2]) / 100, parseFloat(color[3]) / 100, colorSpace ); } break; default: console.warn("THREE.Color: Unknown color model " + style); } } else if (m2 = /^\#([A-Fa-f\d]+)$/.exec(style)) { const hex = m2[1]; const size = hex.length; if (size === 3) { return this.setRGB( parseInt(hex.charAt(0), 16) / 15, parseInt(hex.charAt(1), 16) / 15, parseInt(hex.charAt(2), 16) / 15, colorSpace ); } else if (size === 6) { return this.setHex(parseInt(hex, 16), colorSpace); } else { console.warn("THREE.Color: Invalid hex color " + style); } } else if (style && style.length > 0) { return this.setColorName(style, colorSpace); } return this; } setColorName(style, colorSpace = SRGBColorSpace2) { const hex = _colorKeywords2[style.toLowerCase()]; if (hex !== void 0) { this.setHex(hex, colorSpace); } else { console.warn("THREE.Color: Unknown color " + style); } return this; } clone() { return new this.constructor(this.r, this.g, this.b); } copy(color) { this.r = color.r; this.g = color.g; this.b = color.b; return this; } copySRGBToLinear(color) { this.r = SRGBToLinear2(color.r); this.g = SRGBToLinear2(color.g); this.b = SRGBToLinear2(color.b); return this; } copyLinearToSRGB(color) { this.r = LinearToSRGB2(color.r); this.g = LinearToSRGB2(color.g); this.b = LinearToSRGB2(color.b); return this; } convertSRGBToLinear() { this.copySRGBToLinear(this); return this; } convertLinearToSRGB() { this.copyLinearToSRGB(this); return this; } getHex(colorSpace = SRGBColorSpace2) { ColorManagement2.fromWorkingColorSpace(_color2.copy(this), colorSpace); return Math.round(clamp2(_color2.r * 255, 0, 255)) * 65536 + Math.round(clamp2(_color2.g * 255, 0, 255)) * 256 + Math.round(clamp2(_color2.b * 255, 0, 255)); } getHexString(colorSpace = SRGBColorSpace2) { return ("000000" + this.getHex(colorSpace).toString(16)).slice(-6); } getHSL(target, colorSpace = ColorManagement2.workingColorSpace) { ColorManagement2.fromWorkingColorSpace(_color2.copy(this), colorSpace); const r = _color2.r, g = _color2.g, b = _color2.b; const max2 = Math.max(r, g, b); const min2 = Math.min(r, g, b); let hue, saturation; const lightness = (min2 + max2) / 2; if (min2 === max2) { hue = 0; saturation = 0; } else { const delta = max2 - min2; saturation = lightness <= 0.5 ? delta / (max2 + min2) : delta / (2 - max2 - min2); switch (max2) { case r: hue = (g - b) / delta + (g < b ? 6 : 0); break; case g: hue = (b - r) / delta + 2; break; case b: hue = (r - g) / delta + 4; break; } hue /= 6; } target.h = hue; target.s = saturation; target.l = lightness; return target; } getRGB(target, colorSpace = ColorManagement2.workingColorSpace) { ColorManagement2.fromWorkingColorSpace(_color2.copy(this), colorSpace); target.r = _color2.r; target.g = _color2.g; target.b = _color2.b; return target; } getStyle(colorSpace = SRGBColorSpace2) { ColorManagement2.fromWorkingColorSpace(_color2.copy(this), colorSpace); const r = _color2.r, g = _color2.g, b = _color2.b; if (colorSpace !== SRGBColorSpace2) { return `color(${colorSpace} ${r.toFixed(3)} ${g.toFixed(3)} ${b.toFixed(3)})`; } return `rgb(${Math.round(r * 255)},${Math.round(g * 255)},${Math.round(b * 255)})`; } offsetHSL(h, s, l) { this.getHSL(_hslA2); return this.setHSL(_hslA2.h + h, _hslA2.s + s, _hslA2.l + l); } add(color) { this.r += color.r; this.g += color.g; this.b += color.b; return this; } addColors(color1, color2) { this.r = color1.r + color2.r; this.g = color1.g + color2.g; this.b = color1.b + color2.b; return this; } addScalar(s) { this.r += s; this.g += s; this.b += s; return this; } sub(color) { this.r = Math.max(0, this.r - color.r); this.g = Math.max(0, this.g - color.g); this.b = Math.max(0, this.b - color.b); return this; } multiply(color) { this.r *= color.r; this.g *= color.g; this.b *= color.b; return this; } multiplyScalar(s) { this.r *= s; this.g *= s; this.b *= s; return this; } lerp(color, alpha) { this.r += (color.r - this.r) * alpha; this.g += (color.g - this.g) * alpha; this.b += (color.b - this.b) * alpha; return this; } lerpColors(color1, color2, alpha) { this.r = color1.r + (color2.r - color1.r) * alpha; this.g = color1.g + (color2.g - color1.g) * alpha; this.b = color1.b + (color2.b - color1.b) * alpha; return this; } lerpHSL(color, alpha) { this.getHSL(_hslA2); color.getHSL(_hslB2); const h = lerp2(_hslA2.h, _hslB2.h, alpha); const s = lerp2(_hslA2.s, _hslB2.s, alpha); const l = lerp2(_hslA2.l, _hslB2.l, alpha); this.setHSL(h, s, l); return this; } setFromVector3(v) { this.r = v.x; this.g = v.y; this.b = v.z; return this; } applyMatrix3(m2) { const r = this.r, g = this.g, b = this.b; const e = m2.elements; this.r = e[0] * r + e[3] * g + e[6] * b; this.g = e[1] * r + e[4] * g + e[7] * b; this.b = e[2] * r + e[5] * g + e[8] * b; return this; } equals(c2) { return c2.r === this.r && c2.g === this.g && c2.b === this.b; } fromArray(array, offset = 0) { this.r = array[offset]; this.g = array[offset + 1]; this.b = array[offset + 2]; return this; } toArray(array = [], offset = 0) { array[offset] = this.r; array[offset + 1] = this.g; array[offset + 2] = this.b; return array; } fromBufferAttribute(attribute, index6) { this.r = attribute.getX(index6); this.g = attribute.getY(index6); this.b = attribute.getZ(index6); return this; } toJSON() { return this.getHex(); } *[Symbol.iterator]() { yield this.r; yield this.g; yield this.b; } }; var _color2 = /* @__PURE__ */ new Color2(); Color2.NAMES = _colorKeywords2; var MeshBasicMaterial2 = class extends Material2 { constructor(parameters) { super(); this.isMeshBasicMaterial = true; this.type = "MeshBasicMaterial"; this.color = new Color2(16777215); this.map = null; this.lightMap = null; this.lightMapIntensity = 1; this.aoMap = null; this.aoMapIntensity = 1; this.specularMap = null; this.alphaMap = null; this.envMap = null; this.combine = MultiplyOperation2; this.reflectivity = 1; this.refractionRatio = 0.98; this.wireframe = false; this.wireframeLinewidth = 1; this.wireframeLinecap = "round"; this.wireframeLinejoin = "round"; this.fog = true; this.setValues(parameters); } copy(source) { super.copy(source); this.color.copy(source.color); this.map = source.map; this.lightMap = source.lightMap; this.lightMapIntensity = source.lightMapIntensity; this.aoMap = source.aoMap; this.aoMapIntensity = source.aoMapIntensity; this.specularMap = source.specularMap; this.alphaMap = source.alphaMap; this.envMap = source.envMap; this.combine = source.combine; this.reflectivity = source.reflectivity; this.refractionRatio = source.refractionRatio; this.wireframe = source.wireframe; this.wireframeLinewidth = source.wireframeLinewidth; this.wireframeLinecap = source.wireframeLinecap; this.wireframeLinejoin = source.wireframeLinejoin; this.fog = source.fog; return this; } }; var _vector$82 = /* @__PURE__ */ new Vector32(); var _vector2$12 = /* @__PURE__ */ new Vector22(); var BufferAttribute2 = class { constructor(array, itemSize, normalized = false) { if (Array.isArray(array)) { throw new TypeError("THREE.BufferAttribute: array should be a Typed Array."); } this.isBufferAttribute = true; this.name = ""; this.array = array; this.itemSize = itemSize; this.count = array !== void 0 ? array.length / itemSize : 0; this.normalized = normalized; this.usage = StaticDrawUsage2; this.updateRange = { offset: 0, count: -1 }; this.gpuType = FloatType2; this.version = 0; } onUploadCallback() { } set needsUpdate(value) { if (value === true) this.version++; } setUsage(value) { this.usage = value; return this; } copy(source) { this.name = source.name; this.array = new source.array.constructor(source.array); this.itemSize = source.itemSize; this.count = source.count; this.normalized = source.normalized; this.usage = source.usage; this.gpuType = source.gpuType; return this; } copyAt(index1, attribute, index22) { index1 *= this.itemSize; index22 *= attribute.itemSize; for (let i = 0, l = this.itemSize; i < l; i++) { this.array[index1 + i] = attribute.array[index22 + i]; } return this; } copyArray(array) { this.array.set(array); return this; } applyMatrix3(m2) { if (this.itemSize === 2) { for (let i = 0, l = this.count; i < l; i++) { _vector2$12.fromBufferAttribute(this, i); _vector2$12.applyMatrix3(m2); this.setXY(i, _vector2$12.x, _vector2$12.y); } } else if (this.itemSize === 3) { for (let i = 0, l = this.count; i < l; i++) { _vector$82.fromBufferAttribute(this, i); _vector$82.applyMatrix3(m2); this.setXYZ(i, _vector$82.x, _vector$82.y, _vector$82.z); } } return this; } applyMatrix4(m2) { for (let i = 0, l = this.count; i < l; i++) { _vector$82.fromBufferAttribute(this, i); _vector$82.applyMatrix4(m2); this.setXYZ(i, _vector$82.x, _vector$82.y, _vector$82.z); } return this; } applyNormalMatrix(m2) { for (let i = 0, l = this.count; i < l; i++) { _vector$82.fromBufferAttribute(this, i); _vector$82.applyNormalMatrix(m2); this.setXYZ(i, _vector$82.x, _vector$82.y, _vector$82.z); } return this; } transformDirection(m2) { for (let i = 0, l = this.count; i < l; i++) { _vector$82.fromBufferAttribute(this, i); _vector$82.transformDirection(m2); this.setXYZ(i, _vector$82.x, _vector$82.y, _vector$82.z); } return this; } set(value, offset = 0) { this.array.set(value, offset); return this; } getComponent(index6, component) { let value = this.array[index6 * this.itemSize + component]; if (this.normalized) value = denormalize2(value, this.array); return value; } setComponent(index6, component, value) { if (this.normalized) value = normalize2(value, this.array); this.array[index6 * this.itemSize + component] = value; return this; } getX(index6) { let x3 = this.array[index6 * this.itemSize]; if (this.normalized) x3 = denormalize2(x3, this.array); return x3; } setX(index6, x3) { if (this.normalized) x3 = normalize2(x3, this.array); this.array[index6 * this.itemSize] = x3; return this; } getY(index6) { let y3 = this.array[index6 * this.itemSize + 1]; if (this.normalized) y3 = denormalize2(y3, this.array); return y3; } setY(index6, y3) { if (this.normalized) y3 = normalize2(y3, this.array); this.array[index6 * this.itemSize + 1] = y3; return this; } getZ(index6) { let z4 = this.array[index6 * this.itemSize + 2]; if (this.normalized) z4 = denormalize2(z4, this.array); return z4; } setZ(index6, z4) { if (this.normalized) z4 = normalize2(z4, this.array); this.array[index6 * this.itemSize + 2] = z4; return this; } getW(index6) { let w = this.array[index6 * this.itemSize + 3]; if (this.normalized) w = denormalize2(w, this.array); return w; } setW(index6, w) { if (this.normalized) w = normalize2(w, this.array); this.array[index6 * this.itemSize + 3] = w; return this; } setXY(index6, x3, y3) { index6 *= this.itemSize; if (this.normalized) { x3 = normalize2(x3, this.array); y3 = normalize2(y3, this.array); } this.array[index6 + 0] = x3; this.array[index6 + 1] = y3; return this; } setXYZ(index6, x3, y3, z4) { index6 *= this.itemSize; if (this.normalized) { x3 = normalize2(x3, this.array); y3 = normalize2(y3, this.array); z4 = normalize2(z4, this.array); } this.array[index6 + 0] = x3; this.array[index6 + 1] = y3; this.array[index6 + 2] = z4; return this; } setXYZW(index6, x3, y3, z4, w) { index6 *= this.itemSize; if (this.normalized) { x3 = normalize2(x3, this.array); y3 = normalize2(y3, this.array); z4 = normalize2(z4, this.array); w = normalize2(w, this.array); } this.array[index6 + 0] = x3; this.array[index6 + 1] = y3; this.array[index6 + 2] = z4; this.array[index6 + 3] = w; return this; } onUpload(callback) { this.onUploadCallback = callback; return this; } clone() { return new this.constructor(this.array, this.itemSize).copy(this); } toJSON() { const data = { itemSize: this.itemSize, type: this.array.constructor.name, array: Array.from(this.array), normalized: this.normalized }; if (this.name !== "") data.name = this.name; if (this.usage !== StaticDrawUsage2) data.usage = this.usage; if (this.updateRange.offset !== 0 || this.updateRange.count !== -1) data.updateRange = this.updateRange; return data; } }; var Uint16BufferAttribute2 = class extends BufferAttribute2 { constructor(array, itemSize, normalized) { super(new Uint16Array(array), itemSize, normalized); } }; var Uint32BufferAttribute2 = class extends BufferAttribute2 { constructor(array, itemSize, normalized) { super(new Uint32Array(array), itemSize, normalized); } }; var Float32BufferAttribute2 = class extends BufferAttribute2 { constructor(array, itemSize, normalized) { super(new Float32Array(array), itemSize, normalized); } }; var _id$22 = 0; var _m12 = /* @__PURE__ */ new Matrix42(); var _obj2 = /* @__PURE__ */ new Object3D2(); var _offset3 = /* @__PURE__ */ new Vector32(); var _box$12 = /* @__PURE__ */ new Box32(); var _boxMorphTargets2 = /* @__PURE__ */ new Box32(); var _vector$72 = /* @__PURE__ */ new Vector32(); var BufferGeometry2 = class extends EventDispatcher2 { constructor() { super(); this.isBufferGeometry = true; Object.defineProperty(this, "id", { value: _id$22++ }); this.uuid = generateUUID2(); this.name = ""; this.type = "BufferGeometry"; this.index = null; this.attributes = {}; this.morphAttributes = {}; this.morphTargetsRelative = false; this.groups = []; this.boundingBox = null; this.boundingSphere = null; this.drawRange = { start: 0, count: Infinity }; this.userData = {}; } getIndex() { return this.index; } setIndex(index6) { if (Array.isArray(index6)) { this.index = new (arrayNeedsUint322(index6) ? Uint32BufferAttribute2 : Uint16BufferAttribute2)(index6, 1); } else { this.index = index6; } return this; } getAttribute(name) { return this.attributes[name]; } setAttribute(name, attribute) { this.attributes[name] = attribute; return this; } deleteAttribute(name) { delete this.attributes[name]; return this; } hasAttribute(name) { return this.attributes[name] !== void 0; } addGroup(start, count, materialIndex = 0) { this.groups.push({ start, count, materialIndex }); } clearGroups() { this.groups = []; } setDrawRange(start, count) { this.drawRange.start = start; this.drawRange.count = count; } applyMatrix4(matrix) { const position = this.attributes.position; if (position !== void 0) { position.applyMatrix4(matrix); position.needsUpdate = true; } const normal = this.attributes.normal; if (normal !== void 0) { const normalMatrix = new Matrix32().getNormalMatrix(matrix); normal.applyNormalMatrix(normalMatrix); normal.needsUpdate = true; } const tangent = this.attributes.tangent; if (tangent !== void 0) { tangent.transformDirection(matrix); tangent.needsUpdate = true; } if (this.boundingBox !== null) { this.computeBoundingBox(); } if (this.boundingSphere !== null) { this.computeBoundingSphere(); } return this; } applyQuaternion(q) { _m12.makeRotationFromQuaternion(q); this.applyMatrix4(_m12); return this; } rotateX(angle) { _m12.makeRotationX(angle); this.applyMatrix4(_m12); return this; } rotateY(angle) { _m12.makeRotationY(angle); this.applyMatrix4(_m12); return this; } rotateZ(angle) { _m12.makeRotationZ(angle); this.applyMatrix4(_m12); return this; } translate(x3, y3, z4) { _m12.makeTranslation(x3, y3, z4); this.applyMatrix4(_m12); return this; } scale(x3, y3, z4) { _m12.makeScale(x3, y3, z4); this.applyMatrix4(_m12); return this; } lookAt(vector) { _obj2.lookAt(vector); _obj2.updateMatrix(); this.applyMatrix4(_obj2.matrix); return this; } center() { this.computeBoundingBox(); this.boundingBox.getCenter(_offset3).negate(); this.translate(_offset3.x, _offset3.y, _offset3.z); return this; } setFromPoints(points) { const position = []; for (let i = 0, l = points.length; i < l; i++) { const point = points[i]; position.push(point.x, point.y, point.z || 0); } this.setAttribute("position", new Float32BufferAttribute2(position, 3)); return this; } computeBoundingBox() { if (this.boundingBox === null) { this.boundingBox = new Box32(); } const position = this.attributes.position; const morphAttributesPosition = this.morphAttributes.position; if (position && position.isGLBufferAttribute) { console.error('THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this); this.boundingBox.set( new Vector32(-Infinity, -Infinity, -Infinity), new Vector32(Infinity, Infinity, Infinity) ); return; } if (position !== void 0) { this.boundingBox.setFromBufferAttribute(position); if (morphAttributesPosition) { for (let i = 0, il = morphAttributesPosition.length; i < il; i++) { const morphAttribute = morphAttributesPosition[i]; _box$12.setFromBufferAttribute(morphAttribute); if (this.morphTargetsRelative) { _vector$72.addVectors(this.boundingBox.min, _box$12.min); this.boundingBox.expandByPoint(_vector$72); _vector$72.addVectors(this.boundingBox.max, _box$12.max); this.boundingBox.expandByPoint(_vector$72); } else { this.boundingBox.expandByPoint(_box$12.min); this.boundingBox.expandByPoint(_box$12.max); } } } } else { this.boundingBox.makeEmpty(); } if (isNaN(this.boundingBox.min.x) || isNaN(this.boundingBox.min.y) || isNaN(this.boundingBox.min.z)) { console.error('THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this); } } computeBoundingSphere() { if (this.boundingSphere === null) { this.boundingSphere = new Sphere2(); } const position = this.attributes.position; const morphAttributesPosition = this.morphAttributes.position; if (position && position.isGLBufferAttribute) { console.error('THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this); this.boundingSphere.set(new Vector32(), Infinity); return; } if (position) { const center = this.boundingSphere.center; _box$12.setFromBufferAttribute(position); if (morphAttributesPosition) { for (let i = 0, il = morphAttributesPosition.length; i < il; i++) { const morphAttribute = morphAttributesPosition[i]; _boxMorphTargets2.setFromBufferAttribute(morphAttribute); if (this.morphTargetsRelative) { _vector$72.addVectors(_box$12.min, _boxMorphTargets2.min); _box$12.expandByPoint(_vector$72); _vector$72.addVectors(_box$12.max, _boxMorphTargets2.max); _box$12.expandByPoint(_vector$72); } else { _box$12.expandByPoint(_boxMorphTargets2.min); _box$12.expandByPoint(_boxMorphTargets2.max); } } } _box$12.getCenter(center); let maxRadiusSq = 0; for (let i = 0, il = position.count; i < il; i++) { _vector$72.fromBufferAttribute(position, i); maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$72)); } if (morphAttributesPosition) { for (let i = 0, il = morphAttributesPosition.length; i < il; i++) { const morphAttribute = morphAttributesPosition[i]; const morphTargetsRelative = this.morphTargetsRelative; for (let j = 0, jl = morphAttribute.count; j < jl; j++) { _vector$72.fromBufferAttribute(morphAttribute, j); if (morphTargetsRelative) { _offset3.fromBufferAttribute(position, j); _vector$72.add(_offset3); } maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$72)); } } } this.boundingSphere.radius = Math.sqrt(maxRadiusSq); if (isNaN(this.boundingSphere.radius)) { console.error('THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this); } } } computeTangents() { const index6 = this.index; const attributes = this.attributes; if (index6 === null || attributes.position === void 0 || attributes.normal === void 0 || attributes.uv === void 0) { console.error("THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)"); return; } const indices = index6.array; const positions = attributes.position.array; const normals = attributes.normal.array; const uvs = attributes.uv.array; const nVertices = positions.length / 3; if (this.hasAttribute("tangent") === false) { this.setAttribute("tangent", new BufferAttribute2(new Float32Array(4 * nVertices), 4)); } const tangents = this.getAttribute("tangent").array; const tan1 = [], tan2 = []; for (let i = 0; i < nVertices; i++) { tan1[i] = new Vector32(); tan2[i] = new Vector32(); } const vA = new Vector32(), vB = new Vector32(), vC = new Vector32(), uvA = new Vector22(), uvB = new Vector22(), uvC = new Vector22(), sdir = new Vector32(), tdir = new Vector32(); function handleTriangle(a2, b, c2) { vA.fromArray(positions, a2 * 3); vB.fromArray(positions, b * 3); vC.fromArray(positions, c2 * 3); uvA.fromArray(uvs, a2 * 2); uvB.fromArray(uvs, b * 2); uvC.fromArray(uvs, c2 * 2); vB.sub(vA); vC.sub(vA); uvB.sub(uvA); uvC.sub(uvA); const r = 1 / (uvB.x * uvC.y - uvC.x * uvB.y); if (!isFinite(r)) return; sdir.copy(vB).multiplyScalar(uvC.y).addScaledVector(vC, -uvB.y).multiplyScalar(r); tdir.copy(vC).multiplyScalar(uvB.x).addScaledVector(vB, -uvC.x).multiplyScalar(r); tan1[a2].add(sdir); tan1[b].add(sdir); tan1[c2].add(sdir); tan2[a2].add(tdir); tan2[b].add(tdir); tan2[c2].add(tdir); } let groups = this.groups; if (groups.length === 0) { groups = [{ start: 0, count: indices.length }]; } for (let i = 0, il = groups.length; i < il; ++i) { const group = groups[i]; const start = group.start; const count = group.count; for (let j = start, jl = start + count; j < jl; j += 3) { handleTriangle( indices[j + 0], indices[j + 1], indices[j + 2] ); } } const tmp2 = new Vector32(), tmp22 = new Vector32(); const n = new Vector32(), n2 = new Vector32(); function handleVertex(v) { n.fromArray(normals, v * 3); n2.copy(n); const t = tan1[v]; tmp2.copy(t); tmp2.sub(n.multiplyScalar(n.dot(t))).normalize(); tmp22.crossVectors(n2, t); const test = tmp22.dot(tan2[v]); const w = test < 0 ? -1 : 1; tangents[v * 4] = tmp2.x; tangents[v * 4 + 1] = tmp2.y; tangents[v * 4 + 2] = tmp2.z; tangents[v * 4 + 3] = w; } for (let i = 0, il = groups.length; i < il; ++i) { const group = groups[i]; const start = group.start; const count = group.count; for (let j = start, jl = start + count; j < jl; j += 3) { handleVertex(indices[j + 0]); handleVertex(indices[j + 1]); handleVertex(indices[j + 2]); } } } computeVertexNormals() { const index6 = this.index; const positionAttribute = this.getAttribute("position"); if (positionAttribute !== void 0) { let normalAttribute = this.getAttribute("normal"); if (normalAttribute === void 0) { normalAttribute = new BufferAttribute2(new Float32Array(positionAttribute.count * 3), 3); this.setAttribute("normal", normalAttribute); } else { for (let i = 0, il = normalAttribute.count; i < il; i++) { normalAttribute.setXYZ(i, 0, 0, 0); } } const pA = new Vector32(), pB = new Vector32(), pC = new Vector32(); const nA = new Vector32(), nB = new Vector32(), nC = new Vector32(); const cb = new Vector32(), ab = new Vector32(); if (index6) { for (let i = 0, il = index6.count; i < il; i += 3) { const vA = index6.getX(i + 0); const vB = index6.getX(i + 1); const vC = index6.getX(i + 2); pA.fromBufferAttribute(positionAttribute, vA); pB.fromBufferAttribute(positionAttribute, vB); pC.fromBufferAttribute(positionAttribute, vC); cb.subVectors(pC, pB); ab.subVectors(pA, pB); cb.cross(ab); nA.fromBufferAttribute(normalAttribute, vA); nB.fromBufferAttribute(normalAttribute, vB); nC.fromBufferAttribute(normalAttribute, vC); nA.add(cb); nB.add(cb); nC.add(cb); normalAttribute.setXYZ(vA, nA.x, nA.y, nA.z); normalAttribute.setXYZ(vB, nB.x, nB.y, nB.z); normalAttribute.setXYZ(vC, nC.x, nC.y, nC.z); } } else { for (let i = 0, il = positionAttribute.count; i < il; i += 3) { pA.fromBufferAttribute(positionAttribute, i + 0); pB.fromBufferAttribute(positionAttribute, i + 1); pC.fromBufferAttribute(positionAttribute, i + 2); cb.subVectors(pC, pB); ab.subVectors(pA, pB); cb.cross(ab); normalAttribute.setXYZ(i + 0, cb.x, cb.y, cb.z); normalAttribute.setXYZ(i + 1, cb.x, cb.y, cb.z); normalAttribute.setXYZ(i + 2, cb.x, cb.y, cb.z); } } this.normalizeNormals(); normalAttribute.needsUpdate = true; } } normalizeNormals() { const normals = this.attributes.normal; for (let i = 0, il = normals.count; i < il; i++) { _vector$72.fromBufferAttribute(normals, i); _vector$72.normalize(); normals.setXYZ(i, _vector$72.x, _vector$72.y, _vector$72.z); } } toNonIndexed() { function convertBufferAttribute(attribute, indices2) { const array = attribute.array; const itemSize = attribute.itemSize; const normalized = attribute.normalized; const array2 = new array.constructor(indices2.length * itemSize); let index6 = 0, index22 = 0; for (let i = 0, l = indices2.length; i < l; i++) { if (attribute.isInterleavedBufferAttribute) { index6 = indices2[i] * attribute.data.stride + attribute.offset; } else { index6 = indices2[i] * itemSize; } for (let j = 0; j < itemSize; j++) { array2[index22++] = array[index6++]; } } return new BufferAttribute2(array2, itemSize, normalized); } if (this.index === null) { console.warn("THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed."); return this; } const geometry2 = new BufferGeometry2(); const indices = this.index.array; const attributes = this.attributes; for (const name in attributes) { const attribute = attributes[name]; const newAttribute = convertBufferAttribute(attribute, indices); geometry2.setAttribute(name, newAttribute); } const morphAttributes = this.morphAttributes; for (const name in morphAttributes) { const morphArray = []; const morphAttribute = morphAttributes[name]; for (let i = 0, il = morphAttribute.length; i < il; i++) { const attribute = morphAttribute[i]; const newAttribute = convertBufferAttribute(attribute, indices); morphArray.push(newAttribute); } geometry2.morphAttributes[name] = morphArray; } geometry2.morphTargetsRelative = this.morphTargetsRelative; const groups = this.groups; for (let i = 0, l = groups.length; i < l; i++) { const group = groups[i]; geometry2.addGroup(group.start, group.count, group.materialIndex); } return geometry2; } toJSON() { const data = { metadata: { version: 4.6, type: "BufferGeometry", generator: "BufferGeometry.toJSON" } }; data.uuid = this.uuid; data.type = this.type; if (this.name !== "") data.name = this.name; if (Object.keys(this.userData).length > 0) data.userData = this.userData; if (this.parameters !== void 0) { const parameters = this.parameters; for (const key in parameters) { if (parameters[key] !== void 0) data[key] = parameters[key]; } return data; } data.data = { attributes: {} }; const index6 = this.index; if (index6 !== null) { data.data.index = { type: index6.array.constructor.name, array: Array.prototype.slice.call(index6.array) }; } const attributes = this.attributes; for (const key in attributes) { const attribute = attributes[key]; data.data.attributes[key] = attribute.toJSON(data.data); } const morphAttributes = {}; let hasMorphAttributes = false; for (const key in this.morphAttributes) { const attributeArray = this.morphAttributes[key]; const array = []; for (let i = 0, il = attributeArray.length; i < il; i++) { const attribute = attributeArray[i]; array.push(attribute.toJSON(data.data)); } if (array.length > 0) { morphAttributes[key] = array; hasMorphAttributes = true; } } if (hasMorphAttributes) { data.data.morphAttributes = morphAttributes; data.data.morphTargetsRelative = this.morphTargetsRelative; } const groups = this.groups; if (groups.length > 0) { data.data.groups = JSON.parse(JSON.stringify(groups)); } const boundingSphere = this.boundingSphere; if (boundingSphere !== null) { data.data.boundingSphere = { center: boundingSphere.center.toArray(), radius: boundingSphere.radius }; } return data; } clone() { return new this.constructor().copy(this); } copy(source) { this.index = null; this.attributes = {}; this.morphAttributes = {}; this.groups = []; this.boundingBox = null; this.boundingSphere = null; const data = {}; this.name = source.name; const index6 = source.index; if (index6 !== null) { this.setIndex(index6.clone(data)); } const attributes = source.attributes; for (const name in attributes) { const attribute = attributes[name]; this.setAttribute(name, attribute.clone(data)); } const morphAttributes = source.morphAttributes; for (const name in morphAttributes) { const array = []; const morphAttribute = morphAttributes[name]; for (let i = 0, l = morphAttribute.length; i < l; i++) { array.push(morphAttribute[i].clone(data)); } this.morphAttributes[name] = array; } this.morphTargetsRelative = source.morphTargetsRelative; const groups = source.groups; for (let i = 0, l = groups.length; i < l; i++) { const group = groups[i]; this.addGroup(group.start, group.count, group.materialIndex); } const boundingBox = source.boundingBox; if (boundingBox !== null) { this.boundingBox = boundingBox.clone(); } const boundingSphere = source.boundingSphere; if (boundingSphere !== null) { this.boundingSphere = boundingSphere.clone(); } this.drawRange.start = source.drawRange.start; this.drawRange.count = source.drawRange.count; this.userData = source.userData; return this; } dispose() { this.dispatchEvent({ type: "dispose" }); } }; var _inverseMatrix$32 = /* @__PURE__ */ new Matrix42(); var _ray$32 = /* @__PURE__ */ new Ray2(); var _sphere$52 = /* @__PURE__ */ new Sphere2(); var _sphereHitAt2 = /* @__PURE__ */ new Vector32(); var _vA$12 = /* @__PURE__ */ new Vector32(); var _vB$12 = /* @__PURE__ */ new Vector32(); var _vC$12 = /* @__PURE__ */ new Vector32(); var _tempA2 = /* @__PURE__ */ new Vector32(); var _morphA2 = /* @__PURE__ */ new Vector32(); var _uvA$12 = /* @__PURE__ */ new Vector22(); var _uvB$12 = /* @__PURE__ */ new Vector22(); var _uvC$12 = /* @__PURE__ */ new Vector22(); var _normalA2 = /* @__PURE__ */ new Vector32(); var _normalB2 = /* @__PURE__ */ new Vector32(); var _normalC2 = /* @__PURE__ */ new Vector32(); var _intersectionPoint2 = /* @__PURE__ */ new Vector32(); var _intersectionPointWorld2 = /* @__PURE__ */ new Vector32(); var Mesh2 = class extends Object3D2 { constructor(geometry = new BufferGeometry2(), material = new MeshBasicMaterial2()) { super(); this.isMesh = true; this.type = "Mesh"; this.geometry = geometry; this.material = material; this.updateMorphTargets(); } copy(source, recursive) { super.copy(source, recursive); if (source.morphTargetInfluences !== void 0) { this.morphTargetInfluences = source.morphTargetInfluences.slice(); } if (source.morphTargetDictionary !== void 0) { this.morphTargetDictionary = Object.assign({}, source.morphTargetDictionary); } this.material = Array.isArray(source.material) ? source.material.slice() : source.material; this.geometry = source.geometry; return this; } updateMorphTargets() { const geometry = this.geometry; const morphAttributes = geometry.morphAttributes; const keys = Object.keys(morphAttributes); if (keys.length > 0) { const morphAttribute = morphAttributes[keys[0]]; if (morphAttribute !== void 0) { this.morphTargetInfluences = []; this.morphTargetDictionary = {}; for (let m2 = 0, ml = morphAttribute.length; m2 < ml; m2++) { const name = morphAttribute[m2].name || String(m2); this.morphTargetInfluences.push(0); this.morphTargetDictionary[name] = m2; } } } } getVertexPosition(index6, target) { const geometry = this.geometry; const position = geometry.attributes.position; const morphPosition = geometry.morphAttributes.position; const morphTargetsRelative = geometry.morphTargetsRelative; target.fromBufferAttribute(position, index6); const morphInfluences = this.morphTargetInfluences; if (morphPosition && morphInfluences) { _morphA2.set(0, 0, 0); for (let i = 0, il = morphPosition.length; i < il; i++) { const influence = morphInfluences[i]; const morphAttribute = morphPosition[i]; if (influence === 0) continue; _tempA2.fromBufferAttribute(morphAttribute, index6); if (morphTargetsRelative) { _morphA2.addScaledVector(_tempA2, influence); } else { _morphA2.addScaledVector(_tempA2.sub(target), influence); } } target.add(_morphA2); } return target; } raycast(raycaster, intersects) { const geometry = this.geometry; const material = this.material; const matrixWorld = this.matrixWorld; if (material === void 0) return; if (geometry.boundingSphere === null) geometry.computeBoundingSphere(); _sphere$52.copy(geometry.boundingSphere); _sphere$52.applyMatrix4(matrixWorld); _ray$32.copy(raycaster.ray).recast(raycaster.near); if (_sphere$52.containsPoint(_ray$32.origin) === false) { if (_ray$32.intersectSphere(_sphere$52, _sphereHitAt2) === null) return; if (_ray$32.origin.distanceToSquared(_sphereHitAt2) > (raycaster.far - raycaster.near) ** 2) return; } _inverseMatrix$32.copy(matrixWorld).invert(); _ray$32.copy(raycaster.ray).applyMatrix4(_inverseMatrix$32); if (geometry.boundingBox !== null) { if (_ray$32.intersectsBox(geometry.boundingBox) === false) return; } this._computeIntersections(raycaster, intersects, _ray$32); } _computeIntersections(raycaster, intersects, rayLocalSpace) { let intersection; const geometry = this.geometry; const material = this.material; const index6 = geometry.index; const position = geometry.attributes.position; const uv = geometry.attributes.uv; const uv1 = geometry.attributes.uv1; const normal = geometry.attributes.normal; const groups = geometry.groups; const drawRange = geometry.drawRange; if (index6 !== null) { if (Array.isArray(material)) { for (let i = 0, il = groups.length; i < il; i++) { const group = groups[i]; const groupMaterial = material[group.materialIndex]; const start = Math.max(group.start, drawRange.start); const end = Math.min(index6.count, Math.min(group.start + group.count, drawRange.start + drawRange.count)); for (let j = start, jl = end; j < jl; j += 3) { const a2 = index6.getX(j); const b = index6.getX(j + 1); const c2 = index6.getX(j + 2); intersection = checkGeometryIntersection2(this, groupMaterial, raycaster, rayLocalSpace, uv, uv1, normal, a2, b, c2); if (intersection) { intersection.faceIndex = Math.floor(j / 3); intersection.face.materialIndex = group.materialIndex; intersects.push(intersection); } } } } else { const start = Math.max(0, drawRange.start); const end = Math.min(index6.count, drawRange.start + drawRange.count); for (let i = start, il = end; i < il; i += 3) { const a2 = index6.getX(i); const b = index6.getX(i + 1); const c2 = index6.getX(i + 2); intersection = checkGeometryIntersection2(this, material, raycaster, rayLocalSpace, uv, uv1, normal, a2, b, c2); if (intersection) { intersection.faceIndex = Math.floor(i / 3); intersects.push(intersection); } } } } else if (position !== void 0) { if (Array.isArray(material)) { for (let i = 0, il = groups.length; i < il; i++) { const group = groups[i]; const groupMaterial = material[group.materialIndex]; const start = Math.max(group.start, drawRange.start); const end = Math.min(position.count, Math.min(group.start + group.count, drawRange.start + drawRange.count)); for (let j = start, jl = end; j < jl; j += 3) { const a2 = j; const b = j + 1; const c2 = j + 2; intersection = checkGeometryIntersection2(this, groupMaterial, raycaster, rayLocalSpace, uv, uv1, normal, a2, b, c2); if (intersection) { intersection.faceIndex = Math.floor(j / 3); intersection.face.materialIndex = group.materialIndex; intersects.push(intersection); } } } } else { const start = Math.max(0, drawRange.start); const end = Math.min(position.count, drawRange.start + drawRange.count); for (let i = start, il = end; i < il; i += 3) { const a2 = i; const b = i + 1; const c2 = i + 2; intersection = checkGeometryIntersection2(this, material, raycaster, rayLocalSpace, uv, uv1, normal, a2, b, c2); if (intersection) { intersection.faceIndex = Math.floor(i / 3); intersects.push(intersection); } } } } } }; function checkIntersection2(object, material, raycaster, ray, pA, pB, pC, point) { let intersect; if (material.side === BackSide2) { intersect = ray.intersectTriangle(pC, pB, pA, true, point); } else { intersect = ray.intersectTriangle(pA, pB, pC, material.side === FrontSide2, point); } if (intersect === null) return null; _intersectionPointWorld2.copy(point); _intersectionPointWorld2.applyMatrix4(object.matrixWorld); const distance = raycaster.ray.origin.distanceTo(_intersectionPointWorld2); if (distance < raycaster.near || distance > raycaster.far) return null; return { distance, point: _intersectionPointWorld2.clone(), object }; } function checkGeometryIntersection2(object, material, raycaster, ray, uv, uv1, normal, a2, b, c2) { object.getVertexPosition(a2, _vA$12); object.getVertexPosition(b, _vB$12); object.getVertexPosition(c2, _vC$12); const intersection = checkIntersection2(object, material, raycaster, ray, _vA$12, _vB$12, _vC$12, _intersectionPoint2); if (intersection) { if (uv) { _uvA$12.fromBufferAttribute(uv, a2); _uvB$12.fromBufferAttribute(uv, b); _uvC$12.fromBufferAttribute(uv, c2); intersection.uv = Triangle2.getInterpolation(_intersectionPoint2, _vA$12, _vB$12, _vC$12, _uvA$12, _uvB$12, _uvC$12, new Vector22()); } if (uv1) { _uvA$12.fromBufferAttribute(uv1, a2); _uvB$12.fromBufferAttribute(uv1, b); _uvC$12.fromBufferAttribute(uv1, c2); intersection.uv1 = Triangle2.getInterpolation(_intersectionPoint2, _vA$12, _vB$12, _vC$12, _uvA$12, _uvB$12, _uvC$12, new Vector22()); intersection.uv2 = intersection.uv1; } if (normal) { _normalA2.fromBufferAttribute(normal, a2); _normalB2.fromBufferAttribute(normal, b); _normalC2.fromBufferAttribute(normal, c2); intersection.normal = Triangle2.getInterpolation(_intersectionPoint2, _vA$12, _vB$12, _vC$12, _normalA2, _normalB2, _normalC2, new Vector32()); if (intersection.normal.dot(ray.direction) > 0) { intersection.normal.multiplyScalar(-1); } } const face = { a: a2, b, c: c2, normal: new Vector32(), materialIndex: 0 }; Triangle2.getNormal(_vA$12, _vB$12, _vC$12, face.normal); intersection.face = face; } return intersection; } var BoxGeometry2 = class extends BufferGeometry2 { constructor(width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1) { super(); this.type = "BoxGeometry"; this.parameters = { width, height, depth, widthSegments, heightSegments, depthSegments }; const scope = this; widthSegments = Math.floor(widthSegments); heightSegments = Math.floor(heightSegments); depthSegments = Math.floor(depthSegments); const indices = []; const vertices = []; const normals = []; const uvs = []; let numberOfVertices = 0; let groupStart = 0; buildPlane("z", "y", "x", -1, -1, depth, height, width, depthSegments, heightSegments, 0); buildPlane("z", "y", "x", 1, -1, depth, height, -width, depthSegments, heightSegments, 1); buildPlane("x", "z", "y", 1, 1, width, depth, height, widthSegments, depthSegments, 2); buildPlane("x", "z", "y", 1, -1, width, depth, -height, widthSegments, depthSegments, 3); buildPlane("x", "y", "z", 1, -1, width, height, depth, widthSegments, heightSegments, 4); buildPlane("x", "y", "z", -1, -1, width, height, -depth, widthSegments, heightSegments, 5); this.setIndex(indices); this.setAttribute("position", new Float32BufferAttribute2(vertices, 3)); this.setAttribute("normal", new Float32BufferAttribute2(normals, 3)); this.setAttribute("uv", new Float32BufferAttribute2(uvs, 2)); function buildPlane(u, v, w, udir, vdir, width2, height2, depth2, gridX, gridY, materialIndex) { const segmentWidth = width2 / gridX; const segmentHeight = height2 / gridY; const widthHalf = width2 / 2; const heightHalf = height2 / 2; const depthHalf = depth2 / 2; const gridX1 = gridX + 1; const gridY1 = gridY + 1; let vertexCounter = 0; let groupCount = 0; const vector = new Vector32(); for (let iy = 0; iy < gridY1; iy++) { const y3 = iy * segmentHeight - heightHalf; for (let ix = 0; ix < gridX1; ix++) { const x3 = ix * segmentWidth - widthHalf; vector[u] = x3 * udir; vector[v] = y3 * vdir; vector[w] = depthHalf; vertices.push(vector.x, vector.y, vector.z); vector[u] = 0; vector[v] = 0; vector[w] = depth2 > 0 ? 1 : -1; normals.push(vector.x, vector.y, vector.z); uvs.push(ix / gridX); uvs.push(1 - iy / gridY); vertexCounter += 1; } } for (let iy = 0; iy < gridY; iy++) { for (let ix = 0; ix < gridX; ix++) { const a2 = numberOfVertices + ix + gridX1 * iy; const b = numberOfVertices + ix + gridX1 * (iy + 1); const c2 = numberOfVertices + (ix + 1) + gridX1 * (iy + 1); const d = numberOfVertices + (ix + 1) + gridX1 * iy; indices.push(a2, b, d); indices.push(b, c2, d); groupCount += 6; } } scope.addGroup(groupStart, groupCount, materialIndex); groupStart += groupCount; numberOfVertices += vertexCounter; } } copy(source) { super.copy(source); this.parameters = Object.assign({}, source.parameters); return this; } static fromJSON(data) { return new BoxGeometry2(data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments); } }; function cloneUniforms2(src) { const dst = {}; for (const u in src) { dst[u] = {}; for (const p in src[u]) { const property = src[u][p]; if (property && (property.isColor || property.isMatrix3 || property.isMatrix4 || property.isVector2 || property.isVector3 || property.isVector4 || property.isTexture || property.isQuaternion)) { if (property.isRenderTargetTexture) { console.warn("UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms()."); dst[u][p] = null; } else { dst[u][p] = property.clone(); } } else if (Array.isArray(property)) { dst[u][p] = property.slice(); } else { dst[u][p] = property; } } } return dst; } function mergeUniforms2(uniforms) { const merged = {}; for (let u = 0; u < uniforms.length; u++) { const tmp2 = cloneUniforms2(uniforms[u]); for (const p in tmp2) { merged[p] = tmp2[p]; } } return merged; } function cloneUniformsGroups2(src) { const dst = []; for (let u = 0; u < src.length; u++) { dst.push(src[u].clone()); } return dst; } function getUnlitUniformColorSpace2(renderer3) { if (renderer3.getRenderTarget() === null) { return renderer3.outputColorSpace; } return ColorManagement2.workingColorSpace; } var UniformsUtils2 = { clone: cloneUniforms2, merge: mergeUniforms2 }; var default_vertex2 = "void main() {\n gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}"; var default_fragment2 = "void main() {\n gl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}"; var ShaderMaterial2 = class extends Material2 { constructor(parameters) { super(); this.isShaderMaterial = true; this.type = "ShaderMaterial"; this.defines = {}; this.uniforms = {}; this.uniformsGroups = []; this.vertexShader = default_vertex2; this.fragmentShader = default_fragment2; this.linewidth = 1; this.wireframe = false; this.wireframeLinewidth = 1; this.fog = false; this.lights = false; this.clipping = false; this.forceSinglePass = true; this.extensions = { derivatives: false, // set to use derivatives fragDepth: false, // set to use fragment depth values drawBuffers: false, // set to use draw buffers shaderTextureLOD: false // set to use shader texture LOD }; this.defaultAttributeValues = { "color": [1, 1, 1], "uv": [0, 0], "uv1": [0, 0] }; this.index0AttributeName = void 0; this.uniformsNeedUpdate = false; this.glslVersion = null; if (parameters !== void 0) { this.setValues(parameters); } } copy(source) { super.copy(source); this.fragmentShader = source.fragmentShader; this.vertexShader = source.vertexShader; this.uniforms = cloneUniforms2(source.uniforms); this.uniformsGroups = cloneUniformsGroups2(source.uniformsGroups); this.defines = Object.assign({}, source.defines); this.wireframe = source.wireframe; this.wireframeLinewidth = source.wireframeLinewidth; this.fog = source.fog; this.lights = source.lights; this.clipping = source.clipping; this.extensions = Object.assign({}, source.extensions); this.glslVersion = source.glslVersion; return this; } toJSON(meta) { const data = super.toJSON(meta); data.glslVersion = this.glslVersion; data.uniforms = {}; for (const name in this.uniforms) { const uniform = this.uniforms[name]; const value = uniform.value; if (value && value.isTexture) { data.uniforms[name] = { type: "t", value: value.toJSON(meta).uuid }; } else if (value && value.isColor) { data.uniforms[name] = { type: "c", value: value.getHex() }; } else if (value && value.isVector2) { data.uniforms[name] = { type: "v2", value: value.toArray() }; } else if (value && value.isVector3) { data.uniforms[name] = { type: "v3", value: value.toArray() }; } else if (value && value.isVector4) { data.uniforms[name] = { type: "v4", value: value.toArray() }; } else if (value && value.isMatrix3) { data.uniforms[name] = { type: "m3", value: value.toArray() }; } else if (value && value.isMatrix4) { data.uniforms[name] = { type: "m4", value: value.toArray() }; } else { data.uniforms[name] = { value }; } } if (Object.keys(this.defines).length > 0) data.defines = this.defines; data.vertexShader = this.vertexShader; data.fragmentShader = this.fragmentShader; data.lights = this.lights; data.clipping = this.clipping; const extensions = {}; for (const key in this.extensions) { if (this.extensions[key] === true) extensions[key] = true; } if (Object.keys(extensions).length > 0) data.extensions = extensions; return data; } }; var Camera2 = class extends Object3D2 { constructor() { super(); this.isCamera = true; this.type = "Camera"; this.matrixWorldInverse = new Matrix42(); this.projectionMatrix = new Matrix42(); this.projectionMatrixInverse = new Matrix42(); this.coordinateSystem = WebGLCoordinateSystem2; } copy(source, recursive) { super.copy(source, recursive); this.matrixWorldInverse.copy(source.matrixWorldInverse); this.projectionMatrix.copy(source.projectionMatrix); this.projectionMatrixInverse.copy(source.projectionMatrixInverse); this.coordinateSystem = source.coordinateSystem; return this; } getWorldDirection(target) { return super.getWorldDirection(target).negate(); } updateMatrixWorld(force) { super.updateMatrixWorld(force); this.matrixWorldInverse.copy(this.matrixWorld).invert(); } updateWorldMatrix(updateParents, updateChildren) { super.updateWorldMatrix(updateParents, updateChildren); this.matrixWorldInverse.copy(this.matrixWorld).invert(); } clone() { return new this.constructor().copy(this); } }; var PerspectiveCamera2 = class extends Camera2 { constructor(fov3 = 50, aspect3 = 1, near = 0.1, far = 2e3) { super(); this.isPerspectiveCamera = true; this.type = "PerspectiveCamera"; this.fov = fov3; this.zoom = 1; this.near = near; this.far = far; this.focus = 10; this.aspect = aspect3; this.view = null; this.filmGauge = 35; this.filmOffset = 0; this.updateProjectionMatrix(); } copy(source, recursive) { super.copy(source, recursive); this.fov = source.fov; this.zoom = source.zoom; this.near = source.near; this.far = source.far; this.focus = source.focus; this.aspect = source.aspect; this.view = source.view === null ? null : Object.assign({}, source.view); this.filmGauge = source.filmGauge; this.filmOffset = source.filmOffset; return this; } /** * Sets the FOV by focal length in respect to the current .filmGauge. * * The default film gauge is 35, so that the focal length can be specified for * a 35mm (full frame) camera. * * Values for focal length and film gauge must have the same unit. */ setFocalLength(focalLength) { const vExtentSlope = 0.5 * this.getFilmHeight() / focalLength; this.fov = RAD2DEG2 * 2 * Math.atan(vExtentSlope); this.updateProjectionMatrix(); } /** * Calculates the focal length from the current .fov and .filmGauge. */ getFocalLength() { const vExtentSlope = Math.tan(DEG2RAD2 * 0.5 * this.fov); return 0.5 * this.getFilmHeight() / vExtentSlope; } getEffectiveFOV() { return RAD2DEG2 * 2 * Math.atan( Math.tan(DEG2RAD2 * 0.5 * this.fov) / this.zoom ); } getFilmWidth() { return this.filmGauge * Math.min(this.aspect, 1); } getFilmHeight() { return this.filmGauge / Math.max(this.aspect, 1); } /** * Sets an offset in a larger frustum. This is useful for multi-window or * multi-monitor/multi-machine setups. * * For example, if you have 3x2 monitors and each monitor is 1920x1080 and * the monitors are in grid like this * * +---+---+---+ * | A | B | C | * +---+---+---+ * | D | E | F | * +---+---+---+ * * then for each monitor you would call it like this * * const w = 1920; * const h = 1080; * const fullWidth = w * 3; * const fullHeight = h * 2; * * --A-- * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h ); * --B-- * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h ); * --C-- * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h ); * --D-- * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h ); * --E-- * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h ); * --F-- * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h ); * * Note there is no reason monitors have to be the same size or in a grid. */ setViewOffset(fullWidth, fullHeight, x3, y3, width, height) { this.aspect = fullWidth / fullHeight; if (this.view === null) { this.view = { enabled: true, fullWidth: 1, fullHeight: 1, offsetX: 0, offsetY: 0, width: 1, height: 1 }; } this.view.enabled = true; this.view.fullWidth = fullWidth; this.view.fullHeight = fullHeight; this.view.offsetX = x3; this.view.offsetY = y3; this.view.width = width; this.view.height = height; this.updateProjectionMatrix(); } clearViewOffset() { if (this.view !== null) { this.view.enabled = false; } this.updateProjectionMatrix(); } updateProjectionMatrix() { const near = this.near; let top = near * Math.tan(DEG2RAD2 * 0.5 * this.fov) / this.zoom; let height = 2 * top; let width = this.aspect * height; let left = -0.5 * width; const view = this.view; if (this.view !== null && this.view.enabled) { const fullWidth = view.fullWidth, fullHeight = view.fullHeight; left += view.offsetX * width / fullWidth; top -= view.offsetY * height / fullHeight; width *= view.width / fullWidth; height *= view.height / fullHeight; } const skew = this.filmOffset; if (skew !== 0) left += near * skew / this.getFilmWidth(); this.projectionMatrix.makePerspective(left, left + width, top, top - height, near, this.far, this.coordinateSystem); this.projectionMatrixInverse.copy(this.projectionMatrix).invert(); } toJSON(meta) { const data = super.toJSON(meta); data.object.fov = this.fov; data.object.zoom = this.zoom; data.object.near = this.near; data.object.far = this.far; data.object.focus = this.focus; data.object.aspect = this.aspect; if (this.view !== null) data.object.view = Object.assign({}, this.view); data.object.filmGauge = this.filmGauge; data.object.filmOffset = this.filmOffset; return data; } }; var fov2 = -90; var aspect2 = 1; var CubeCamera2 = class extends Object3D2 { constructor(near, far, renderTarget) { super(); this.type = "CubeCamera"; this.renderTarget = renderTarget; this.coordinateSystem = null; this.activeMipmapLevel = 0; const cameraPX = new PerspectiveCamera2(fov2, aspect2, near, far); cameraPX.layers = this.layers; this.add(cameraPX); const cameraNX = new PerspectiveCamera2(fov2, aspect2, near, far); cameraNX.layers = this.layers; this.add(cameraNX); const cameraPY = new PerspectiveCamera2(fov2, aspect2, near, far); cameraPY.layers = this.layers; this.add(cameraPY); const cameraNY = new PerspectiveCamera2(fov2, aspect2, near, far); cameraNY.layers = this.layers; this.add(cameraNY); const cameraPZ = new PerspectiveCamera2(fov2, aspect2, near, far); cameraPZ.layers = this.layers; this.add(cameraPZ); const cameraNZ = new PerspectiveCamera2(fov2, aspect2, near, far); cameraNZ.layers = this.layers; this.add(cameraNZ); } updateCoordinateSystem() { const coordinateSystem = this.coordinateSystem; const cameras = this.children.concat(); const [cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ] = cameras; for (const camera3 of cameras) this.remove(camera3); if (coordinateSystem === WebGLCoordinateSystem2) { cameraPX.up.set(0, 1, 0); cameraPX.lookAt(1, 0, 0); cameraNX.up.set(0, 1, 0); cameraNX.lookAt(-1, 0, 0); cameraPY.up.set(0, 0, -1); cameraPY.lookAt(0, 1, 0); cameraNY.up.set(0, 0, 1); cameraNY.lookAt(0, -1, 0); cameraPZ.up.set(0, 1, 0); cameraPZ.lookAt(0, 0, 1); cameraNZ.up.set(0, 1, 0); cameraNZ.lookAt(0, 0, -1); } else if (coordinateSystem === WebGPUCoordinateSystem2) { cameraPX.up.set(0, -1, 0); cameraPX.lookAt(-1, 0, 0); cameraNX.up.set(0, -1, 0); cameraNX.lookAt(1, 0, 0); cameraPY.up.set(0, 0, 1); cameraPY.lookAt(0, 1, 0); cameraNY.up.set(0, 0, -1); cameraNY.lookAt(0, -1, 0); cameraPZ.up.set(0, -1, 0); cameraPZ.lookAt(0, 0, 1); cameraNZ.up.set(0, -1, 0); cameraNZ.lookAt(0, 0, -1); } else { throw new Error("THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: " + coordinateSystem); } for (const camera3 of cameras) { this.add(camera3); camera3.updateMatrixWorld(); } } update(renderer3, scene3) { if (this.parent === null) this.updateMatrixWorld(); const { renderTarget, activeMipmapLevel } = this; if (this.coordinateSystem !== renderer3.coordinateSystem) { this.coordinateSystem = renderer3.coordinateSystem; this.updateCoordinateSystem(); } const [cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ] = this.children; const currentRenderTarget = renderer3.getRenderTarget(); const currentActiveCubeFace = renderer3.getActiveCubeFace(); const currentActiveMipmapLevel = renderer3.getActiveMipmapLevel(); const currentXrEnabled = renderer3.xr.enabled; renderer3.xr.enabled = false; const generateMipmaps = renderTarget.texture.generateMipmaps; renderTarget.texture.generateMipmaps = false; renderer3.setRenderTarget(renderTarget, 0, activeMipmapLevel); renderer3.render(scene3, cameraPX); renderer3.setRenderTarget(renderTarget, 1, activeMipmapLevel); renderer3.render(scene3, cameraNX); renderer3.setRenderTarget(renderTarget, 2, activeMipmapLevel); renderer3.render(scene3, cameraPY); renderer3.setRenderTarget(renderTarget, 3, activeMipmapLevel); renderer3.render(scene3, cameraNY); renderer3.setRenderTarget(renderTarget, 4, activeMipmapLevel); renderer3.render(scene3, cameraPZ); renderTarget.texture.generateMipmaps = generateMipmaps; renderer3.setRenderTarget(renderTarget, 5, activeMipmapLevel); renderer3.render(scene3, cameraNZ); renderer3.setRenderTarget(currentRenderTarget, currentActiveCubeFace, currentActiveMipmapLevel); renderer3.xr.enabled = currentXrEnabled; renderTarget.texture.needsPMREMUpdate = true; } }; var CubeTexture2 = class extends Texture2 { constructor(images, mapping, wrapS, wrapT, magFilter, minFilter, format2, type, anisotropy, colorSpace) { images = images !== void 0 ? images : []; mapping = mapping !== void 0 ? mapping : CubeReflectionMapping2; super(images, mapping, wrapS, wrapT, magFilter, minFilter, format2, type, anisotropy, colorSpace); this.isCubeTexture = true; this.flipY = false; } get images() { return this.image; } set images(value) { this.image = value; } }; var WebGLCubeRenderTarget2 = class extends WebGLRenderTarget2 { constructor(size = 1, options = {}) { super(size, size, options); this.isWebGLCubeRenderTarget = true; const image = { width: size, height: size, depth: 1 }; const images = [image, image, image, image, image, image]; if (options.encoding !== void 0) { warnOnce2("THREE.WebGLCubeRenderTarget: option.encoding has been replaced by option.colorSpace."); options.colorSpace = options.encoding === sRGBEncoding2 ? SRGBColorSpace2 : NoColorSpace2; } this.texture = new CubeTexture2(images, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace); this.texture.isRenderTargetTexture = true; this.texture.generateMipmaps = options.generateMipmaps !== void 0 ? options.generateMipmaps : false; this.texture.minFilter = options.minFilter !== void 0 ? options.minFilter : LinearFilter2; } fromEquirectangularTexture(renderer3, texture) { this.texture.type = texture.type; this.texture.colorSpace = texture.colorSpace; this.texture.generateMipmaps = texture.generateMipmaps; this.texture.minFilter = texture.minFilter; this.texture.magFilter = texture.magFilter; const shader = { uniforms: { tEquirect: { value: null } }, vertexShader: ( /* glsl */ ` varying vec3 vWorldDirection; vec3 transformDirection( in vec3 dir, in mat4 matrix ) { return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz ); } void main() { vWorldDirection = transformDirection( position, modelMatrix ); #include #include } ` ), fragmentShader: ( /* glsl */ ` uniform sampler2D tEquirect; varying vec3 vWorldDirection; #include void main() { vec3 direction = normalize( vWorldDirection ); vec2 sampleUV = equirectUv( direction ); gl_FragColor = texture2D( tEquirect, sampleUV ); } ` ) }; const geometry = new BoxGeometry2(5, 5, 5); const material = new ShaderMaterial2({ name: "CubemapFromEquirect", uniforms: cloneUniforms2(shader.uniforms), vertexShader: shader.vertexShader, fragmentShader: shader.fragmentShader, side: BackSide2, blending: NoBlending2 }); material.uniforms.tEquirect.value = texture; const mesh = new Mesh2(geometry, material); const currentMinFilter = texture.minFilter; if (texture.minFilter === LinearMipmapLinearFilter2) texture.minFilter = LinearFilter2; const camera3 = new CubeCamera2(1, 10, this); camera3.update(renderer3, mesh); texture.minFilter = currentMinFilter; mesh.geometry.dispose(); mesh.material.dispose(); return this; } clear(renderer3, color, depth, stencil) { const currentRenderTarget = renderer3.getRenderTarget(); for (let i = 0; i < 6; i++) { renderer3.setRenderTarget(this, i); renderer3.clear(color, depth, stencil); } renderer3.setRenderTarget(currentRenderTarget); } }; var _vector12 = /* @__PURE__ */ new Vector32(); var _vector22 = /* @__PURE__ */ new Vector32(); var _normalMatrix2 = /* @__PURE__ */ new Matrix32(); var Plane2 = class { constructor(normal = new Vector32(1, 0, 0), constant = 0) { this.isPlane = true; this.normal = normal; this.constant = constant; } set(normal, constant) { this.normal.copy(normal); this.constant = constant; return this; } setComponents(x3, y3, z4, w) { this.normal.set(x3, y3, z4); this.constant = w; return this; } setFromNormalAndCoplanarPoint(normal, point) { this.normal.copy(normal); this.constant = -point.dot(this.normal); return this; } setFromCoplanarPoints(a2, b, c2) { const normal = _vector12.subVectors(c2, b).cross(_vector22.subVectors(a2, b)).normalize(); this.setFromNormalAndCoplanarPoint(normal, a2); return this; } copy(plane) { this.normal.copy(plane.normal); this.constant = plane.constant; return this; } normalize() { const inverseNormalLength = 1 / this.normal.length(); this.normal.multiplyScalar(inverseNormalLength); this.constant *= inverseNormalLength; return this; } negate() { this.constant *= -1; this.normal.negate(); return this; } distanceToPoint(point) { return this.normal.dot(point) + this.constant; } distanceToSphere(sphere) { return this.distanceToPoint(sphere.center) - sphere.radius; } projectPoint(point, target) { return target.copy(point).addScaledVector(this.normal, -this.distanceToPoint(point)); } intersectLine(line, target) { const direction = line.delta(_vector12); const denominator = this.normal.dot(direction); if (denominator === 0) { if (this.distanceToPoint(line.start) === 0) { return target.copy(line.start); } return null; } const t = -(line.start.dot(this.normal) + this.constant) / denominator; if (t < 0 || t > 1) { return null; } return target.copy(line.start).addScaledVector(direction, t); } intersectsLine(line) { const startSign = this.distanceToPoint(line.start); const endSign = this.distanceToPoint(line.end); return startSign < 0 && endSign > 0 || endSign < 0 && startSign > 0; } intersectsBox(box) { return box.intersectsPlane(this); } intersectsSphere(sphere) { return sphere.intersectsPlane(this); } coplanarPoint(target) { return target.copy(this.normal).multiplyScalar(-this.constant); } applyMatrix4(matrix, optionalNormalMatrix) { const normalMatrix = optionalNormalMatrix || _normalMatrix2.getNormalMatrix(matrix); const referencePoint = this.coplanarPoint(_vector12).applyMatrix4(matrix); const normal = this.normal.applyMatrix3(normalMatrix).normalize(); this.constant = -referencePoint.dot(normal); return this; } translate(offset) { this.constant -= offset.dot(this.normal); return this; } equals(plane) { return plane.normal.equals(this.normal) && plane.constant === this.constant; } clone() { return new this.constructor().copy(this); } }; var _sphere$42 = /* @__PURE__ */ new Sphere2(); var _vector$62 = /* @__PURE__ */ new Vector32(); var Frustum2 = class { constructor(p0 = new Plane2(), p1 = new Plane2(), p2 = new Plane2(), p3 = new Plane2(), p4 = new Plane2(), p5 = new Plane2()) { this.planes = [p0, p1, p2, p3, p4, p5]; } set(p0, p1, p2, p3, p4, p5) { const planes = this.planes; planes[0].copy(p0); planes[1].copy(p1); planes[2].copy(p2); planes[3].copy(p3); planes[4].copy(p4); planes[5].copy(p5); return this; } copy(frustum) { const planes = this.planes; for (let i = 0; i < 6; i++) { planes[i].copy(frustum.planes[i]); } return this; } setFromProjectionMatrix(m2, coordinateSystem = WebGLCoordinateSystem2) { const planes = this.planes; const me = m2.elements; const me0 = me[0], me1 = me[1], me2 = me[2], me3 = me[3]; const me4 = me[4], me5 = me[5], me6 = me[6], me7 = me[7]; const me8 = me[8], me9 = me[9], me10 = me[10], me11 = me[11]; const me12 = me[12], me13 = me[13], me14 = me[14], me15 = me[15]; planes[0].setComponents(me3 - me0, me7 - me4, me11 - me8, me15 - me12).normalize(); planes[1].setComponents(me3 + me0, me7 + me4, me11 + me8, me15 + me12).normalize(); planes[2].setComponents(me3 + me1, me7 + me5, me11 + me9, me15 + me13).normalize(); planes[3].setComponents(me3 - me1, me7 - me5, me11 - me9, me15 - me13).normalize(); planes[4].setComponents(me3 - me2, me7 - me6, me11 - me10, me15 - me14).normalize(); if (coordinateSystem === WebGLCoordinateSystem2) { planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize(); } else if (coordinateSystem === WebGPUCoordinateSystem2) { planes[5].setComponents(me2, me6, me10, me14).normalize(); } else { throw new Error("THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: " + coordinateSystem); } return this; } intersectsObject(object) { if (object.boundingSphere !== void 0) { if (object.boundingSphere === null) object.computeBoundingSphere(); _sphere$42.copy(object.boundingSphere).applyMatrix4(object.matrixWorld); } else { const geometry = object.geometry; if (geometry.boundingSphere === null) geometry.computeBoundingSphere(); _sphere$42.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld); } return this.intersectsSphere(_sphere$42); } intersectsSprite(sprite) { _sphere$42.center.set(0, 0, 0); _sphere$42.radius = 0.7071067811865476; _sphere$42.applyMatrix4(sprite.matrixWorld); return this.intersectsSphere(_sphere$42); } intersectsSphere(sphere) { const planes = this.planes; const center = sphere.center; const negRadius = -sphere.radius; for (let i = 0; i < 6; i++) { const distance = planes[i].distanceToPoint(center); if (distance < negRadius) { return false; } } return true; } intersectsBox(box) { const planes = this.planes; for (let i = 0; i < 6; i++) { const plane = planes[i]; _vector$62.x = plane.normal.x > 0 ? box.max.x : box.min.x; _vector$62.y = plane.normal.y > 0 ? box.max.y : box.min.y; _vector$62.z = plane.normal.z > 0 ? box.max.z : box.min.z; if (plane.distanceToPoint(_vector$62) < 0) { return false; } } return true; } containsPoint(point) { const planes = this.planes; for (let i = 0; i < 6; i++) { if (planes[i].distanceToPoint(point) < 0) { return false; } } return true; } clone() { return new this.constructor().copy(this); } }; function WebGLAnimation2() { let context = null; let isAnimating = false; let animationLoop = null; let requestId = null; function onAnimationFrame(time, frame2) { animationLoop(time, frame2); requestId = context.requestAnimationFrame(onAnimationFrame); } return { start: function() { if (isAnimating === true) return; if (animationLoop === null) return; requestId = context.requestAnimationFrame(onAnimationFrame); isAnimating = true; }, stop: function() { context.cancelAnimationFrame(requestId); isAnimating = false; }, setAnimationLoop: function(callback) { animationLoop = callback; }, setContext: function(value) { context = value; } }; } function WebGLAttributes2(gl, capabilities) { const isWebGL2 = capabilities.isWebGL2; const buffers = /* @__PURE__ */ new WeakMap(); function createBuffer(attribute, bufferType) { const array = attribute.array; const usage = attribute.usage; const buffer = gl.createBuffer(); gl.bindBuffer(bufferType, buffer); gl.bufferData(bufferType, array, usage); attribute.onUploadCallback(); let type; if (array instanceof Float32Array) { type = gl.FLOAT; } else if (array instanceof Uint16Array) { if (attribute.isFloat16BufferAttribute) { if (isWebGL2) { type = gl.HALF_FLOAT; } else { throw new Error("THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2."); } } else { type = gl.UNSIGNED_SHORT; } } else if (array instanceof Int16Array) { type = gl.SHORT; } else if (array instanceof Uint32Array) { type = gl.UNSIGNED_INT; } else if (array instanceof Int32Array) { type = gl.INT; } else if (array instanceof Int8Array) { type = gl.BYTE; } else if (array instanceof Uint8Array) { type = gl.UNSIGNED_BYTE; } else if (array instanceof Uint8ClampedArray) { type = gl.UNSIGNED_BYTE; } else { throw new Error("THREE.WebGLAttributes: Unsupported buffer data format: " + array); } return { buffer, type, bytesPerElement: array.BYTES_PER_ELEMENT, version: attribute.version }; } function updateBuffer(buffer, attribute, bufferType) { const array = attribute.array; const updateRange = attribute.updateRange; gl.bindBuffer(bufferType, buffer); if (updateRange.count === -1) { gl.bufferSubData(bufferType, 0, array); } else { if (isWebGL2) { gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array, updateRange.offset, updateRange.count ); } else { gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT, array.subarray(updateRange.offset, updateRange.offset + updateRange.count) ); } updateRange.count = -1; } attribute.onUploadCallback(); } function get2(attribute) { if (attribute.isInterleavedBufferAttribute) attribute = attribute.data; return buffers.get(attribute); } function remove2(attribute) { if (attribute.isInterleavedBufferAttribute) attribute = attribute.data; const data = buffers.get(attribute); if (data) { gl.deleteBuffer(data.buffer); buffers.delete(attribute); } } function update4(attribute, bufferType) { if (attribute.isGLBufferAttribute) { const cached = buffers.get(attribute); if (!cached || cached.version < attribute.version) { buffers.set(attribute, { buffer: attribute.buffer, type: attribute.type, bytesPerElement: attribute.elementSize, version: attribute.version }); } return; } if (attribute.isInterleavedBufferAttribute) attribute = attribute.data; const data = buffers.get(attribute); if (data === void 0) { buffers.set(attribute, createBuffer(attribute, bufferType)); } else if (data.version < attribute.version) { updateBuffer(data.buffer, attribute, bufferType); data.version = attribute.version; } } return { get: get2, remove: remove2, update: update4 }; } var PlaneGeometry2 = class extends BufferGeometry2 { constructor(width = 1, height = 1, widthSegments = 1, heightSegments = 1) { super(); this.type = "PlaneGeometry"; this.parameters = { width, height, widthSegments, heightSegments }; const width_half = width / 2; const height_half = height / 2; const gridX = Math.floor(widthSegments); const gridY = Math.floor(heightSegments); const gridX1 = gridX + 1; const gridY1 = gridY + 1; const segment_width = width / gridX; const segment_height = height / gridY; const indices = []; const vertices = []; const normals = []; const uvs = []; for (let iy = 0; iy < gridY1; iy++) { const y3 = iy * segment_height - height_half; for (let ix = 0; ix < gridX1; ix++) { const x3 = ix * segment_width - width_half; vertices.push(x3, -y3, 0); normals.push(0, 0, 1); uvs.push(ix / gridX); uvs.push(1 - iy / gridY); } } for (let iy = 0; iy < gridY; iy++) { for (let ix = 0; ix < gridX; ix++) { const a2 = ix + gridX1 * iy; const b = ix + gridX1 * (iy + 1); const c2 = ix + 1 + gridX1 * (iy + 1); const d = ix + 1 + gridX1 * iy; indices.push(a2, b, d); indices.push(b, c2, d); } } this.setIndex(indices); this.setAttribute("position", new Float32BufferAttribute2(vertices, 3)); this.setAttribute("normal", new Float32BufferAttribute2(normals, 3)); this.setAttribute("uv", new Float32BufferAttribute2(uvs, 2)); } copy(source) { super.copy(source); this.parameters = Object.assign({}, source.parameters); return this; } static fromJSON(data) { return new PlaneGeometry2(data.width, data.height, data.widthSegments, data.heightSegments); } }; var alphahash_fragment2 = "#ifdef USE_ALPHAHASH\n if ( diffuseColor.a < getAlphaHashThreshold( vPosition ) ) discard;\n#endif"; var alphahash_pars_fragment2 = "#ifdef USE_ALPHAHASH\n const float ALPHA_HASH_SCALE = 0.05;\n float hash2D( vec2 value ) {\n return fract( 1.0e4 * sin( 17.0 * value.x + 0.1 * value.y ) * ( 0.1 + abs( sin( 13.0 * value.y + value.x ) ) ) );\n }\n float hash3D( vec3 value ) {\n return hash2D( vec2( hash2D( value.xy ), value.z ) );\n }\n float getAlphaHashThreshold( vec3 position ) {\n float maxDeriv = max(\n length( dFdx( position.xyz ) ),\n length( dFdy( position.xyz ) )\n );\n float pixScale = 1.0 / ( ALPHA_HASH_SCALE * maxDeriv );\n vec2 pixScales = vec2(\n exp2( floor( log2( pixScale ) ) ),\n exp2( ceil( log2( pixScale ) ) )\n );\n vec2 alpha = vec2(\n hash3D( floor( pixScales.x * position.xyz ) ),\n hash3D( floor( pixScales.y * position.xyz ) )\n );\n float lerpFactor = fract( log2( pixScale ) );\n float x = ( 1.0 - lerpFactor ) * alpha.x + lerpFactor * alpha.y;\n float a = min( lerpFactor, 1.0 - lerpFactor );\n vec3 cases = vec3(\n x * x / ( 2.0 * a * ( 1.0 - a ) ),\n ( x - 0.5 * a ) / ( 1.0 - a ),\n 1.0 - ( ( 1.0 - x ) * ( 1.0 - x ) / ( 2.0 * a * ( 1.0 - a ) ) )\n );\n float threshold = ( x < ( 1.0 - a ) )\n ? ( ( x < a ) ? cases.x : cases.y )\n : cases.z;\n return clamp( threshold , 1.0e-6, 1.0 );\n }\n#endif"; var alphamap_fragment2 = "#ifdef USE_ALPHAMAP\n diffuseColor.a *= texture2D( alphaMap, vAlphaMapUv ).g;\n#endif"; var alphamap_pars_fragment2 = "#ifdef USE_ALPHAMAP\n uniform sampler2D alphaMap;\n#endif"; var alphatest_fragment2 = "#ifdef USE_ALPHATEST\n if ( diffuseColor.a < alphaTest ) discard;\n#endif"; var alphatest_pars_fragment2 = "#ifdef USE_ALPHATEST\n uniform float alphaTest;\n#endif"; var aomap_fragment2 = "#ifdef USE_AOMAP\n float ambientOcclusion = ( texture2D( aoMap, vAoMapUv ).r - 1.0 ) * aoMapIntensity + 1.0;\n reflectedLight.indirectDiffuse *= ambientOcclusion;\n #if defined( USE_ENVMAP ) && defined( STANDARD )\n float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );\n reflectedLight.indirectSpecular *= computeSpecularOcclusion( dotNV, ambientOcclusion, material.roughness );\n #endif\n#endif"; var aomap_pars_fragment2 = "#ifdef USE_AOMAP\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n#endif"; var begin_vertex2 = "vec3 transformed = vec3( position );\n#ifdef USE_ALPHAHASH\n vPosition = vec3( position );\n#endif"; var beginnormal_vertex2 = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n vec3 objectTangent = vec3( tangent.xyz );\n#endif"; var bsdfs2 = "float G_BlinnPhong_Implicit( ) {\n return 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_BlinnPhong( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 specularColor, const in float shininess ) {\n vec3 halfDir = normalize( lightDir + viewDir );\n float dotNH = saturate( dot( normal, halfDir ) );\n float dotVH = saturate( dot( viewDir, halfDir ) );\n vec3 F = F_Schlick( specularColor, 1.0, dotVH );\n float G = G_BlinnPhong_Implicit( );\n float D = D_BlinnPhong( shininess, dotNH );\n return F * ( G * D );\n} // validated"; var iridescence_fragment2 = "#ifdef USE_IRIDESCENCE\n const mat3 XYZ_TO_REC709 = mat3(\n 3.2404542, -0.9692660, 0.0556434,\n -1.5371385, 1.8760108, -0.2040259,\n -0.4985314, 0.0415560, 1.0572252\n );\n vec3 Fresnel0ToIor( vec3 fresnel0 ) {\n vec3 sqrtF0 = sqrt( fresnel0 );\n return ( vec3( 1.0 ) + sqrtF0 ) / ( vec3( 1.0 ) - sqrtF0 );\n }\n vec3 IorToFresnel0( vec3 transmittedIor, float incidentIor ) {\n return pow2( ( transmittedIor - vec3( incidentIor ) ) / ( transmittedIor + vec3( incidentIor ) ) );\n }\n float IorToFresnel0( float transmittedIor, float incidentIor ) {\n return pow2( ( transmittedIor - incidentIor ) / ( transmittedIor + incidentIor ));\n }\n vec3 evalSensitivity( float OPD, vec3 shift ) {\n float phase = 2.0 * PI * OPD * 1.0e-9;\n vec3 val = vec3( 5.4856e-13, 4.4201e-13, 5.2481e-13 );\n vec3 pos = vec3( 1.6810e+06, 1.7953e+06, 2.2084e+06 );\n vec3 var = vec3( 4.3278e+09, 9.3046e+09, 6.6121e+09 );\n vec3 xyz = val * sqrt( 2.0 * PI * var ) * cos( pos * phase + shift ) * exp( - pow2( phase ) * var );\n xyz.x += 9.7470e-14 * sqrt( 2.0 * PI * 4.5282e+09 ) * cos( 2.2399e+06 * phase + shift[ 0 ] ) * exp( - 4.5282e+09 * pow2( phase ) );\n xyz /= 1.0685e-7;\n vec3 rgb = XYZ_TO_REC709 * xyz;\n return rgb;\n }\n vec3 evalIridescence( float outsideIOR, float eta2, float cosTheta1, float thinFilmThickness, vec3 baseF0 ) {\n vec3 I;\n float iridescenceIOR = mix( outsideIOR, eta2, smoothstep( 0.0, 0.03, thinFilmThickness ) );\n float sinTheta2Sq = pow2( outsideIOR / iridescenceIOR ) * ( 1.0 - pow2( cosTheta1 ) );\n float cosTheta2Sq = 1.0 - sinTheta2Sq;\n if ( cosTheta2Sq < 0.0 ) {\n return vec3( 1.0 );\n }\n float cosTheta2 = sqrt( cosTheta2Sq );\n float R0 = IorToFresnel0( iridescenceIOR, outsideIOR );\n float R12 = F_Schlick( R0, 1.0, cosTheta1 );\n float T121 = 1.0 - R12;\n float phi12 = 0.0;\n if ( iridescenceIOR < outsideIOR ) phi12 = PI;\n float phi21 = PI - phi12;\n vec3 baseIOR = Fresnel0ToIor( clamp( baseF0, 0.0, 0.9999 ) ); vec3 R1 = IorToFresnel0( baseIOR, iridescenceIOR );\n vec3 R23 = F_Schlick( R1, 1.0, cosTheta2 );\n vec3 phi23 = vec3( 0.0 );\n if ( baseIOR[ 0 ] < iridescenceIOR ) phi23[ 0 ] = PI;\n if ( baseIOR[ 1 ] < iridescenceIOR ) phi23[ 1 ] = PI;\n if ( baseIOR[ 2 ] < iridescenceIOR ) phi23[ 2 ] = PI;\n float OPD = 2.0 * iridescenceIOR * thinFilmThickness * cosTheta2;\n vec3 phi = vec3( phi21 ) + phi23;\n vec3 R123 = clamp( R12 * R23, 1e-5, 0.9999 );\n vec3 r123 = sqrt( R123 );\n vec3 Rs = pow2( T121 ) * R23 / ( vec3( 1.0 ) - R123 );\n vec3 C0 = R12 + Rs;\n I = C0;\n vec3 Cm = Rs - T121;\n for ( int m = 1; m <= 2; ++ m ) {\n Cm *= r123;\n vec3 Sm = 2.0 * evalSensitivity( float( m ) * OPD, float( m ) * phi );\n I += Cm * Sm;\n }\n return max( I, vec3( 0.0 ) );\n }\n#endif"; var bumpmap_pars_fragment2 = "#ifdef USE_BUMPMAP\n uniform sampler2D bumpMap;\n uniform float bumpScale;\n vec2 dHdxy_fwd() {\n vec2 dSTdx = dFdx( vBumpMapUv );\n vec2 dSTdy = dFdy( vBumpMapUv );\n float Hll = bumpScale * texture2D( bumpMap, vBumpMapUv ).x;\n float dBx = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdx ).x - Hll;\n float dBy = bumpScale * texture2D( bumpMap, vBumpMapUv + dSTdy ).x - Hll;\n return vec2( dBx, dBy );\n }\n vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {\n vec3 vSigmaX = dFdx( surf_pos.xyz );\n vec3 vSigmaY = dFdy( surf_pos.xyz );\n vec3 vN = surf_norm;\n vec3 R1 = cross( vSigmaY, vN );\n vec3 R2 = cross( vN, vSigmaX );\n float fDet = dot( vSigmaX, R1 ) * faceDirection;\n vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n return normalize( abs( fDet ) * surf_norm - vGrad );\n }\n#endif"; var clipping_planes_fragment2 = "#if NUM_CLIPPING_PLANES > 0\n vec4 plane;\n #pragma unroll_loop_start\n for ( int i = 0; i < UNION_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n if ( dot( vClipPosition, plane.xyz ) > plane.w ) discard;\n }\n #pragma unroll_loop_end\n #if UNION_CLIPPING_PLANES < NUM_CLIPPING_PLANES\n bool clipped = true;\n #pragma unroll_loop_start\n for ( int i = UNION_CLIPPING_PLANES; i < NUM_CLIPPING_PLANES; i ++ ) {\n plane = clippingPlanes[ i ];\n clipped = ( dot( vClipPosition, plane.xyz ) > plane.w ) && clipped;\n }\n #pragma unroll_loop_end\n if ( clipped ) discard;\n #endif\n#endif"; var clipping_planes_pars_fragment2 = "#if NUM_CLIPPING_PLANES > 0\n varying vec3 vClipPosition;\n uniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif"; var clipping_planes_pars_vertex2 = "#if NUM_CLIPPING_PLANES > 0\n varying vec3 vClipPosition;\n#endif"; var clipping_planes_vertex2 = "#if NUM_CLIPPING_PLANES > 0\n vClipPosition = - mvPosition.xyz;\n#endif"; var color_fragment2 = "#if defined( USE_COLOR_ALPHA )\n diffuseColor *= vColor;\n#elif defined( USE_COLOR )\n diffuseColor.rgb *= vColor;\n#endif"; var color_pars_fragment2 = "#if defined( USE_COLOR_ALPHA )\n varying vec4 vColor;\n#elif defined( USE_COLOR )\n varying vec3 vColor;\n#endif"; var color_pars_vertex2 = "#if defined( USE_COLOR_ALPHA )\n varying vec4 vColor;\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n varying vec3 vColor;\n#endif"; var color_vertex2 = "#if defined( USE_COLOR_ALPHA )\n vColor = vec4( 1.0 );\n#elif defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n vColor = vec3( 1.0 );\n#endif\n#ifdef USE_COLOR\n vColor *= color;\n#endif\n#ifdef USE_INSTANCING_COLOR\n vColor.xyz *= instanceColor.xyz;\n#endif"; var common2 = "#define PI 3.141592653589793\n#define PI2 6.283185307179586\n#define PI_HALF 1.5707963267948966\n#define RECIPROCAL_PI 0.3183098861837907\n#define RECIPROCAL_PI2 0.15915494309189535\n#define EPSILON 1e-6\n#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\n#define whiteComplement( a ) ( 1.0 - saturate( a ) )\nfloat pow2( const in float x ) { return x*x; }\nvec3 pow2( const in vec3 x ) { return x*x; }\nfloat pow3( const in float x ) { return x*x*x; }\nfloat pow4( const in float x ) { float x2 = x*x; return x2*x2; }\nfloat max3( const in vec3 v ) { return max( max( v.x, v.y ), v.z ); }\nfloat average( const in vec3 v ) { return dot( v, vec3( 0.3333333 ) ); }\nhighp float rand( const in vec2 uv ) {\n const highp float a = 12.9898, b = 78.233, c = 43758.5453;\n highp float dt = dot( uv.xy, vec2( a,b ) ), sn = mod( dt, PI );\n return fract( sin( sn ) * c );\n}\n#ifdef HIGH_PRECISION\n float precisionSafeLength( vec3 v ) { return length( v ); }\n#else\n float precisionSafeLength( vec3 v ) {\n float maxComponent = max3( abs( v ) );\n return length( v / maxComponent ) * maxComponent;\n }\n#endif\nstruct IncidentLight {\n vec3 color;\n vec3 direction;\n bool visible;\n};\nstruct ReflectedLight {\n vec3 directDiffuse;\n vec3 directSpecular;\n vec3 indirectDiffuse;\n vec3 indirectSpecular;\n};\n#ifdef USE_ALPHAHASH\n varying vec3 vPosition;\n#endif\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nmat3 transposeMat3( const in mat3 m ) {\n mat3 tmp;\n tmp[ 0 ] = vec3( m[ 0 ].x, m[ 1 ].x, m[ 2 ].x );\n tmp[ 1 ] = vec3( m[ 0 ].y, m[ 1 ].y, m[ 2 ].y );\n tmp[ 2 ] = vec3( m[ 0 ].z, m[ 1 ].z, m[ 2 ].z );\n return tmp;\n}\nfloat luminance( const in vec3 rgb ) {\n const vec3 weights = vec3( 0.2126729, 0.7151522, 0.0721750 );\n return dot( weights, rgb );\n}\nbool isPerspectiveMatrix( mat4 m ) {\n return m[ 2 ][ 3 ] == - 1.0;\n}\nvec2 equirectUv( in vec3 dir ) {\n float u = atan( dir.z, dir.x ) * RECIPROCAL_PI2 + 0.5;\n float v = asin( clamp( dir.y, - 1.0, 1.0 ) ) * RECIPROCAL_PI + 0.5;\n return vec2( u, v );\n}\nvec3 BRDF_Lambert( const in vec3 diffuseColor ) {\n return RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 f0, const in float f90, const in float dotVH ) {\n float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n}\nfloat F_Schlick( const in float f0, const in float f90, const in float dotVH ) {\n float fresnel = exp2( ( - 5.55473 * dotVH - 6.98316 ) * dotVH );\n return f0 * ( 1.0 - fresnel ) + ( f90 * fresnel );\n} // validated"; var cube_uv_reflection_fragment2 = "#ifdef ENVMAP_TYPE_CUBE_UV\n #define cubeUV_minMipLevel 4.0\n #define cubeUV_minTileSize 16.0\n float getFace( vec3 direction ) {\n vec3 absDirection = abs( direction );\n float face = - 1.0;\n if ( absDirection.x > absDirection.z ) {\n if ( absDirection.x > absDirection.y )\n face = direction.x > 0.0 ? 0.0 : 3.0;\n else\n face = direction.y > 0.0 ? 1.0 : 4.0;\n } else {\n if ( absDirection.z > absDirection.y )\n face = direction.z > 0.0 ? 2.0 : 5.0;\n else\n face = direction.y > 0.0 ? 1.0 : 4.0;\n }\n return face;\n }\n vec2 getUV( vec3 direction, float face ) {\n vec2 uv;\n if ( face == 0.0 ) {\n uv = vec2( direction.z, direction.y ) / abs( direction.x );\n } else if ( face == 1.0 ) {\n uv = vec2( - direction.x, - direction.z ) / abs( direction.y );\n } else if ( face == 2.0 ) {\n uv = vec2( - direction.x, direction.y ) / abs( direction.z );\n } else if ( face == 3.0 ) {\n uv = vec2( - direction.z, direction.y ) / abs( direction.x );\n } else if ( face == 4.0 ) {\n uv = vec2( - direction.x, direction.z ) / abs( direction.y );\n } else {\n uv = vec2( direction.x, direction.y ) / abs( direction.z );\n }\n return 0.5 * ( uv + 1.0 );\n }\n vec3 bilinearCubeUV( sampler2D envMap, vec3 direction, float mipInt ) {\n float face = getFace( direction );\n float filterInt = max( cubeUV_minMipLevel - mipInt, 0.0 );\n mipInt = max( mipInt, cubeUV_minMipLevel );\n float faceSize = exp2( mipInt );\n highp vec2 uv = getUV( direction, face ) * ( faceSize - 2.0 ) + 1.0;\n if ( face > 2.0 ) {\n uv.y += faceSize;\n face -= 3.0;\n }\n uv.x += face * faceSize;\n uv.x += filterInt * 3.0 * cubeUV_minTileSize;\n uv.y += 4.0 * ( exp2( CUBEUV_MAX_MIP ) - faceSize );\n uv.x *= CUBEUV_TEXEL_WIDTH;\n uv.y *= CUBEUV_TEXEL_HEIGHT;\n #ifdef texture2DGradEXT\n return texture2DGradEXT( envMap, uv, vec2( 0.0 ), vec2( 0.0 ) ).rgb;\n #else\n return texture2D( envMap, uv ).rgb;\n #endif\n }\n #define cubeUV_r0 1.0\n #define cubeUV_v0 0.339\n #define cubeUV_m0 - 2.0\n #define cubeUV_r1 0.8\n #define cubeUV_v1 0.276\n #define cubeUV_m1 - 1.0\n #define cubeUV_r4 0.4\n #define cubeUV_v4 0.046\n #define cubeUV_m4 2.0\n #define cubeUV_r5 0.305\n #define cubeUV_v5 0.016\n #define cubeUV_m5 3.0\n #define cubeUV_r6 0.21\n #define cubeUV_v6 0.0038\n #define cubeUV_m6 4.0\n float roughnessToMip( float roughness ) {\n float mip = 0.0;\n if ( roughness >= cubeUV_r1 ) {\n mip = ( cubeUV_r0 - roughness ) * ( cubeUV_m1 - cubeUV_m0 ) / ( cubeUV_r0 - cubeUV_r1 ) + cubeUV_m0;\n } else if ( roughness >= cubeUV_r4 ) {\n mip = ( cubeUV_r1 - roughness ) * ( cubeUV_m4 - cubeUV_m1 ) / ( cubeUV_r1 - cubeUV_r4 ) + cubeUV_m1;\n } else if ( roughness >= cubeUV_r5 ) {\n mip = ( cubeUV_r4 - roughness ) * ( cubeUV_m5 - cubeUV_m4 ) / ( cubeUV_r4 - cubeUV_r5 ) + cubeUV_m4;\n } else if ( roughness >= cubeUV_r6 ) {\n mip = ( cubeUV_r5 - roughness ) * ( cubeUV_m6 - cubeUV_m5 ) / ( cubeUV_r5 - cubeUV_r6 ) + cubeUV_m5;\n } else {\n mip = - 2.0 * log2( 1.16 * roughness ); }\n return mip;\n }\n vec4 textureCubeUV( sampler2D envMap, vec3 sampleDir, float roughness ) {\n float mip = clamp( roughnessToMip( roughness ), cubeUV_m0, CUBEUV_MAX_MIP );\n float mipF = fract( mip );\n float mipInt = floor( mip );\n vec3 color0 = bilinearCubeUV( envMap, sampleDir, mipInt );\n if ( mipF == 0.0 ) {\n return vec4( color0, 1.0 );\n } else {\n vec3 color1 = bilinearCubeUV( envMap, sampleDir, mipInt + 1.0 );\n return vec4( mix( color0, color1, mipF ), 1.0 );\n }\n }\n#endif"; var defaultnormal_vertex2 = "vec3 transformedNormal = objectNormal;\n#ifdef USE_INSTANCING\n mat3 m = mat3( instanceMatrix );\n transformedNormal /= vec3( dot( m[ 0 ], m[ 0 ] ), dot( m[ 1 ], m[ 1 ] ), dot( m[ 2 ], m[ 2 ] ) );\n transformedNormal = m * transformedNormal;\n#endif\ntransformedNormal = normalMatrix * transformedNormal;\n#ifdef FLIP_SIDED\n transformedNormal = - transformedNormal;\n#endif\n#ifdef USE_TANGENT\n vec3 transformedTangent = ( modelViewMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n #ifdef FLIP_SIDED\n transformedTangent = - transformedTangent;\n #endif\n#endif"; var displacementmap_pars_vertex2 = "#ifdef USE_DISPLACEMENTMAP\n uniform sampler2D displacementMap;\n uniform float displacementScale;\n uniform float displacementBias;\n#endif"; var displacementmap_vertex2 = "#ifdef USE_DISPLACEMENTMAP\n transformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias );\n#endif"; var emissivemap_fragment2 = "#ifdef USE_EMISSIVEMAP\n vec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );\n totalEmissiveRadiance *= emissiveColor.rgb;\n#endif"; var emissivemap_pars_fragment2 = "#ifdef USE_EMISSIVEMAP\n uniform sampler2D emissiveMap;\n#endif"; var colorspace_fragment2 = "gl_FragColor = linearToOutputTexel( gl_FragColor );"; var colorspace_pars_fragment2 = "\nconst mat3 LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 = mat3(\n vec3( 0.8224621, 0.177538, 0.0 ),\n vec3( 0.0331941, 0.9668058, 0.0 ),\n vec3( 0.0170827, 0.0723974, 0.9105199 )\n);\nconst mat3 LINEAR_DISPLAY_P3_TO_LINEAR_SRGB = mat3(\n vec3( 1.2249401, - 0.2249404, 0.0 ),\n vec3( - 0.0420569, 1.0420571, 0.0 ),\n vec3( - 0.0196376, - 0.0786361, 1.0982735 )\n);\nvec4 LinearSRGBToLinearDisplayP3( in vec4 value ) {\n return vec4( value.rgb * LINEAR_SRGB_TO_LINEAR_DISPLAY_P3, value.a );\n}\nvec4 LinearDisplayP3ToLinearSRGB( in vec4 value ) {\n return vec4( value.rgb * LINEAR_DISPLAY_P3_TO_LINEAR_SRGB, value.a );\n}\nvec4 LinearTransferOETF( in vec4 value ) {\n return value;\n}\nvec4 sRGBTransferOETF( in vec4 value ) {\n return vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );\n}\nvec4 LinearToLinear( in vec4 value ) {\n return value;\n}\nvec4 LinearTosRGB( in vec4 value ) {\n return sRGBTransferOETF( value );\n}"; var envmap_fragment2 = "#ifdef USE_ENVMAP\n #ifdef ENV_WORLDPOS\n vec3 cameraToFrag;\n if ( isOrthographic ) {\n cameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n } else {\n cameraToFrag = normalize( vWorldPosition - cameraPosition );\n }\n vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n #ifdef ENVMAP_MODE_REFLECTION\n vec3 reflectVec = reflect( cameraToFrag, worldNormal );\n #else\n vec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n #endif\n #else\n vec3 reflectVec = vReflect;\n #endif\n #ifdef ENVMAP_TYPE_CUBE\n vec4 envColor = textureCube( envMap, vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n #else\n vec4 envColor = vec4( 0.0 );\n #endif\n #ifdef ENVMAP_BLENDING_MULTIPLY\n outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n #elif defined( ENVMAP_BLENDING_MIX )\n outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n #elif defined( ENVMAP_BLENDING_ADD )\n outgoingLight += envColor.xyz * specularStrength * reflectivity;\n #endif\n#endif"; var envmap_common_pars_fragment2 = "#ifdef USE_ENVMAP\n uniform float envMapIntensity;\n uniform float flipEnvMap;\n #ifdef ENVMAP_TYPE_CUBE\n uniform samplerCube envMap;\n #else\n uniform sampler2D envMap;\n #endif\n \n#endif"; var envmap_pars_fragment2 = "#ifdef USE_ENVMAP\n uniform float reflectivity;\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\n #define ENV_WORLDPOS\n #endif\n #ifdef ENV_WORLDPOS\n varying vec3 vWorldPosition;\n uniform float refractionRatio;\n #else\n varying vec3 vReflect;\n #endif\n#endif"; var envmap_pars_vertex2 = "#ifdef USE_ENVMAP\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( LAMBERT )\n #define ENV_WORLDPOS\n #endif\n #ifdef ENV_WORLDPOS\n \n varying vec3 vWorldPosition;\n #else\n varying vec3 vReflect;\n uniform float refractionRatio;\n #endif\n#endif"; var envmap_vertex2 = "#ifdef USE_ENVMAP\n #ifdef ENV_WORLDPOS\n vWorldPosition = worldPosition.xyz;\n #else\n vec3 cameraToVertex;\n if ( isOrthographic ) {\n cameraToVertex = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n } else {\n cameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n }\n vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n #ifdef ENVMAP_MODE_REFLECTION\n vReflect = reflect( cameraToVertex, worldNormal );\n #else\n vReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n #endif\n #endif\n#endif"; var fog_vertex2 = "#ifdef USE_FOG\n vFogDepth = - mvPosition.z;\n#endif"; var fog_pars_vertex2 = "#ifdef USE_FOG\n varying float vFogDepth;\n#endif"; var fog_fragment2 = "#ifdef USE_FOG\n #ifdef FOG_EXP2\n float fogFactor = 1.0 - exp( - fogDensity * fogDensity * vFogDepth * vFogDepth );\n #else\n float fogFactor = smoothstep( fogNear, fogFar, vFogDepth );\n #endif\n gl_FragColor.rgb = mix( gl_FragColor.rgb, fogColor, fogFactor );\n#endif"; var fog_pars_fragment2 = "#ifdef USE_FOG\n uniform vec3 fogColor;\n varying float vFogDepth;\n #ifdef FOG_EXP2\n uniform float fogDensity;\n #else\n uniform float fogNear;\n uniform float fogFar;\n #endif\n#endif"; var gradientmap_pars_fragment2 = "#ifdef USE_GRADIENTMAP\n uniform sampler2D gradientMap;\n#endif\nvec3 getGradientIrradiance( vec3 normal, vec3 lightDirection ) {\n float dotNL = dot( normal, lightDirection );\n vec2 coord = vec2( dotNL * 0.5 + 0.5, 0.0 );\n #ifdef USE_GRADIENTMAP\n return vec3( texture2D( gradientMap, coord ).r );\n #else\n vec2 fw = fwidth( coord ) * 0.5;\n return mix( vec3( 0.7 ), vec3( 1.0 ), smoothstep( 0.7 - fw.x, 0.7 + fw.x, coord.x ) );\n #endif\n}"; var lightmap_fragment2 = "#ifdef USE_LIGHTMAP\n vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n reflectedLight.indirectDiffuse += lightMapIrradiance;\n#endif"; var lightmap_pars_fragment2 = "#ifdef USE_LIGHTMAP\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n#endif"; var lights_lambert_fragment2 = "LambertMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularStrength = specularStrength;"; var lights_lambert_pars_fragment2 = "varying vec3 vViewPosition;\nstruct LambertMaterial {\n vec3 diffuseColor;\n float specularStrength;\n};\nvoid RE_Direct_Lambert( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {\n float dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n vec3 irradiance = dotNL * directLight.color;\n reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Lambert( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in LambertMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct RE_Direct_Lambert\n#define RE_IndirectDiffuse RE_IndirectDiffuse_Lambert"; var lights_pars_begin2 = "uniform bool receiveShadow;\nuniform vec3 ambientLightColor;\n#if defined( USE_LIGHT_PROBES )\n uniform vec3 lightProbe[ 9 ];\n#endif\nvec3 shGetIrradianceAt( in vec3 normal, in vec3 shCoefficients[ 9 ] ) {\n float x = normal.x, y = normal.y, z = normal.z;\n vec3 result = shCoefficients[ 0 ] * 0.886227;\n result += shCoefficients[ 1 ] * 2.0 * 0.511664 * y;\n result += shCoefficients[ 2 ] * 2.0 * 0.511664 * z;\n result += shCoefficients[ 3 ] * 2.0 * 0.511664 * x;\n result += shCoefficients[ 4 ] * 2.0 * 0.429043 * x * y;\n result += shCoefficients[ 5 ] * 2.0 * 0.429043 * y * z;\n result += shCoefficients[ 6 ] * ( 0.743125 * z * z - 0.247708 );\n result += shCoefficients[ 7 ] * 2.0 * 0.429043 * x * z;\n result += shCoefficients[ 8 ] * 0.429043 * ( x * x - y * y );\n return result;\n}\nvec3 getLightProbeIrradiance( const in vec3 lightProbe[ 9 ], const in vec3 normal ) {\n vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n vec3 irradiance = shGetIrradianceAt( worldNormal, lightProbe );\n return irradiance;\n}\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n vec3 irradiance = ambientLightColor;\n return irradiance;\n}\nfloat getDistanceAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n #if defined ( LEGACY_LIGHTS )\n if ( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n return pow( saturate( - lightDistance / cutoffDistance + 1.0 ), decayExponent );\n }\n return 1.0;\n #else\n float distanceFalloff = 1.0 / max( pow( lightDistance, decayExponent ), 0.01 );\n if ( cutoffDistance > 0.0 ) {\n distanceFalloff *= pow2( saturate( 1.0 - pow4( lightDistance / cutoffDistance ) ) );\n }\n return distanceFalloff;\n #endif\n}\nfloat getSpotAttenuation( const in float coneCosine, const in float penumbraCosine, const in float angleCosine ) {\n return smoothstep( coneCosine, penumbraCosine, angleCosine );\n}\n#if NUM_DIR_LIGHTS > 0\n struct DirectionalLight {\n vec3 direction;\n vec3 color;\n };\n uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n void getDirectionalLightInfo( const in DirectionalLight directionalLight, out IncidentLight light ) {\n light.color = directionalLight.color;\n light.direction = directionalLight.direction;\n light.visible = true;\n }\n#endif\n#if NUM_POINT_LIGHTS > 0\n struct PointLight {\n vec3 position;\n vec3 color;\n float distance;\n float decay;\n };\n uniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n void getPointLightInfo( const in PointLight pointLight, const in vec3 geometryPosition, out IncidentLight light ) {\n vec3 lVector = pointLight.position - geometryPosition;\n light.direction = normalize( lVector );\n float lightDistance = length( lVector );\n light.color = pointLight.color;\n light.color *= getDistanceAttenuation( lightDistance, pointLight.distance, pointLight.decay );\n light.visible = ( light.color != vec3( 0.0 ) );\n }\n#endif\n#if NUM_SPOT_LIGHTS > 0\n struct SpotLight {\n vec3 position;\n vec3 direction;\n vec3 color;\n float distance;\n float decay;\n float coneCos;\n float penumbraCos;\n };\n uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n void getSpotLightInfo( const in SpotLight spotLight, const in vec3 geometryPosition, out IncidentLight light ) {\n vec3 lVector = spotLight.position - geometryPosition;\n light.direction = normalize( lVector );\n float angleCos = dot( light.direction, spotLight.direction );\n float spotAttenuation = getSpotAttenuation( spotLight.coneCos, spotLight.penumbraCos, angleCos );\n if ( spotAttenuation > 0.0 ) {\n float lightDistance = length( lVector );\n light.color = spotLight.color * spotAttenuation;\n light.color *= getDistanceAttenuation( lightDistance, spotLight.distance, spotLight.decay );\n light.visible = ( light.color != vec3( 0.0 ) );\n } else {\n light.color = vec3( 0.0 );\n light.visible = false;\n }\n }\n#endif\n#if NUM_RECT_AREA_LIGHTS > 0\n struct RectAreaLight {\n vec3 color;\n vec3 position;\n vec3 halfWidth;\n vec3 halfHeight;\n };\n uniform sampler2D ltc_1; uniform sampler2D ltc_2;\n uniform RectAreaLight rectAreaLights[ NUM_RECT_AREA_LIGHTS ];\n#endif\n#if NUM_HEMI_LIGHTS > 0\n struct HemisphereLight {\n vec3 direction;\n vec3 skyColor;\n vec3 groundColor;\n };\n uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in vec3 normal ) {\n float dotNL = dot( normal, hemiLight.direction );\n float hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n vec3 irradiance = mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n return irradiance;\n }\n#endif"; var envmap_physical_pars_fragment2 = "#ifdef USE_ENVMAP\n vec3 getIBLIrradiance( const in vec3 normal ) {\n #ifdef ENVMAP_TYPE_CUBE_UV\n vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n vec4 envMapColor = textureCubeUV( envMap, worldNormal, 1.0 );\n return PI * envMapColor.rgb * envMapIntensity;\n #else\n return vec3( 0.0 );\n #endif\n }\n vec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) {\n #ifdef ENVMAP_TYPE_CUBE_UV\n vec3 reflectVec = reflect( - viewDir, normal );\n reflectVec = normalize( mix( reflectVec, normal, roughness * roughness) );\n reflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n vec4 envMapColor = textureCubeUV( envMap, reflectVec, roughness );\n return envMapColor.rgb * envMapIntensity;\n #else\n return vec3( 0.0 );\n #endif\n }\n #ifdef USE_ANISOTROPY\n vec3 getIBLAnisotropyRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness, const in vec3 bitangent, const in float anisotropy ) {\n #ifdef ENVMAP_TYPE_CUBE_UV\n vec3 bentNormal = cross( bitangent, viewDir );\n bentNormal = normalize( cross( bentNormal, bitangent ) );\n bentNormal = normalize( mix( bentNormal, normal, pow2( pow2( 1.0 - anisotropy * ( 1.0 - roughness ) ) ) ) );\n return getIBLRadiance( viewDir, bentNormal, roughness );\n #else\n return vec3( 0.0 );\n #endif\n }\n #endif\n#endif"; var lights_toon_fragment2 = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;"; var lights_toon_pars_fragment2 = "varying vec3 vViewPosition;\nstruct ToonMaterial {\n vec3 diffuseColor;\n};\nvoid RE_Direct_Toon( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n vec3 irradiance = getGradientIrradiance( geometryNormal, directLight.direction ) * directLight.color;\n reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct RE_Direct_Toon\n#define RE_IndirectDiffuse RE_IndirectDiffuse_Toon"; var lights_phong_fragment2 = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;"; var lights_phong_pars_fragment2 = "varying vec3 vViewPosition;\nstruct BlinnPhongMaterial {\n vec3 diffuseColor;\n vec3 specularColor;\n float specularShininess;\n float specularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n float dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n vec3 irradiance = dotNL * directLight.color;\n reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometryViewDir, geometryNormal, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\n#define RE_Direct RE_Direct_BlinnPhong\n#define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong"; var lights_physical_fragment2 = "PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nvec3 dxy = max( abs( dFdx( nonPerturbedNormal ) ), abs( dFdy( nonPerturbedNormal ) ) );\nfloat geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );\nmaterial.roughness = max( roughnessFactor, 0.0525 );material.roughness += geometryRoughness;\nmaterial.roughness = min( material.roughness, 1.0 );\n#ifdef IOR\n material.ior = ior;\n #ifdef USE_SPECULAR\n float specularIntensityFactor = specularIntensity;\n vec3 specularColorFactor = specularColor;\n #ifdef USE_SPECULAR_COLORMAP\n specularColorFactor *= texture2D( specularColorMap, vSpecularColorMapUv ).rgb;\n #endif\n #ifdef USE_SPECULAR_INTENSITYMAP\n specularIntensityFactor *= texture2D( specularIntensityMap, vSpecularIntensityMapUv ).a;\n #endif\n material.specularF90 = mix( specularIntensityFactor, 1.0, metalnessFactor );\n #else\n float specularIntensityFactor = 1.0;\n vec3 specularColorFactor = vec3( 1.0 );\n material.specularF90 = 1.0;\n #endif\n material.specularColor = mix( min( pow2( ( material.ior - 1.0 ) / ( material.ior + 1.0 ) ) * specularColorFactor, vec3( 1.0 ) ) * specularIntensityFactor, diffuseColor.rgb, metalnessFactor );\n#else\n material.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );\n material.specularF90 = 1.0;\n#endif\n#ifdef USE_CLEARCOAT\n material.clearcoat = clearcoat;\n material.clearcoatRoughness = clearcoatRoughness;\n material.clearcoatF0 = vec3( 0.04 );\n material.clearcoatF90 = 1.0;\n #ifdef USE_CLEARCOATMAP\n material.clearcoat *= texture2D( clearcoatMap, vClearcoatMapUv ).x;\n #endif\n #ifdef USE_CLEARCOAT_ROUGHNESSMAP\n material.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vClearcoatRoughnessMapUv ).y;\n #endif\n material.clearcoat = saturate( material.clearcoat ); material.clearcoatRoughness = max( material.clearcoatRoughness, 0.0525 );\n material.clearcoatRoughness += geometryRoughness;\n material.clearcoatRoughness = min( material.clearcoatRoughness, 1.0 );\n#endif\n#ifdef USE_IRIDESCENCE\n material.iridescence = iridescence;\n material.iridescenceIOR = iridescenceIOR;\n #ifdef USE_IRIDESCENCEMAP\n material.iridescence *= texture2D( iridescenceMap, vIridescenceMapUv ).r;\n #endif\n #ifdef USE_IRIDESCENCE_THICKNESSMAP\n material.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vIridescenceThicknessMapUv ).g + iridescenceThicknessMinimum;\n #else\n material.iridescenceThickness = iridescenceThicknessMaximum;\n #endif\n#endif\n#ifdef USE_SHEEN\n material.sheenColor = sheenColor;\n #ifdef USE_SHEEN_COLORMAP\n material.sheenColor *= texture2D( sheenColorMap, vSheenColorMapUv ).rgb;\n #endif\n material.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );\n #ifdef USE_SHEEN_ROUGHNESSMAP\n material.sheenRoughness *= texture2D( sheenRoughnessMap, vSheenRoughnessMapUv ).a;\n #endif\n#endif\n#ifdef USE_ANISOTROPY\n #ifdef USE_ANISOTROPYMAP\n mat2 anisotropyMat = mat2( anisotropyVector.x, anisotropyVector.y, - anisotropyVector.y, anisotropyVector.x );\n vec3 anisotropyPolar = texture2D( anisotropyMap, vAnisotropyMapUv ).rgb;\n vec2 anisotropyV = anisotropyMat * normalize( 2.0 * anisotropyPolar.rg - vec2( 1.0 ) ) * anisotropyPolar.b;\n #else\n vec2 anisotropyV = anisotropyVector;\n #endif\n material.anisotropy = length( anisotropyV );\n anisotropyV /= material.anisotropy;\n material.anisotropy = saturate( material.anisotropy );\n material.alphaT = mix( pow2( material.roughness ), 1.0, pow2( material.anisotropy ) );\n material.anisotropyT = tbn[ 0 ] * anisotropyV.x - tbn[ 1 ] * anisotropyV.y;\n material.anisotropyB = tbn[ 1 ] * anisotropyV.x + tbn[ 0 ] * anisotropyV.y;\n#endif"; var lights_physical_pars_fragment2 = "struct PhysicalMaterial {\n vec3 diffuseColor;\n float roughness;\n vec3 specularColor;\n float specularF90;\n #ifdef USE_CLEARCOAT\n float clearcoat;\n float clearcoatRoughness;\n vec3 clearcoatF0;\n float clearcoatF90;\n #endif\n #ifdef USE_IRIDESCENCE\n float iridescence;\n float iridescenceIOR;\n float iridescenceThickness;\n vec3 iridescenceFresnel;\n vec3 iridescenceF0;\n #endif\n #ifdef USE_SHEEN\n vec3 sheenColor;\n float sheenRoughness;\n #endif\n #ifdef IOR\n float ior;\n #endif\n #ifdef USE_TRANSMISSION\n float transmission;\n float transmissionAlpha;\n float thickness;\n float attenuationDistance;\n vec3 attenuationColor;\n #endif\n #ifdef USE_ANISOTROPY\n float anisotropy;\n float alphaT;\n vec3 anisotropyT;\n vec3 anisotropyB;\n #endif\n};\nvec3 clearcoatSpecular = vec3( 0.0 );\nvec3 sheenSpecular = vec3( 0.0 );\nvec3 Schlick_to_F0( const in vec3 f, const in float f90, const in float dotVH ) {\n float x = clamp( 1.0 - dotVH, 0.0, 1.0 );\n float x2 = x * x;\n float x5 = clamp( x * x2 * x2, 0.0, 0.9999 );\n return ( f - vec3( f90 ) * x5 ) / ( 1.0 - x5 );\n}\nfloat V_GGX_SmithCorrelated( const in float alpha, const in float dotNL, const in float dotNV ) {\n float a2 = pow2( alpha );\n float gv = dotNL * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNV ) );\n float gl = dotNV * sqrt( a2 + ( 1.0 - a2 ) * pow2( dotNL ) );\n return 0.5 / max( gv + gl, EPSILON );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n float a2 = pow2( alpha );\n float denom = pow2( dotNH ) * ( a2 - 1.0 ) + 1.0;\n return RECIPROCAL_PI * a2 / pow2( denom );\n}\n#ifdef USE_ANISOTROPY\n float V_GGX_SmithCorrelated_Anisotropic( const in float alphaT, const in float alphaB, const in float dotTV, const in float dotBV, const in float dotTL, const in float dotBL, const in float dotNV, const in float dotNL ) {\n float gv = dotNL * length( vec3( alphaT * dotTV, alphaB * dotBV, dotNV ) );\n float gl = dotNV * length( vec3( alphaT * dotTL, alphaB * dotBL, dotNL ) );\n float v = 0.5 / ( gv + gl );\n return saturate(v);\n }\n float D_GGX_Anisotropic( const in float alphaT, const in float alphaB, const in float dotNH, const in float dotTH, const in float dotBH ) {\n float a2 = alphaT * alphaB;\n highp vec3 v = vec3( alphaB * dotTH, alphaT * dotBH, a2 * dotNH );\n highp float v2 = dot( v, v );\n float w2 = a2 / v2;\n return RECIPROCAL_PI * a2 * pow2 ( w2 );\n }\n#endif\n#ifdef USE_CLEARCOAT\n vec3 BRDF_GGX_Clearcoat( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material) {\n vec3 f0 = material.clearcoatF0;\n float f90 = material.clearcoatF90;\n float roughness = material.clearcoatRoughness;\n float alpha = pow2( roughness );\n vec3 halfDir = normalize( lightDir + viewDir );\n float dotNL = saturate( dot( normal, lightDir ) );\n float dotNV = saturate( dot( normal, viewDir ) );\n float dotNH = saturate( dot( normal, halfDir ) );\n float dotVH = saturate( dot( viewDir, halfDir ) );\n vec3 F = F_Schlick( f0, f90, dotVH );\n float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n float D = D_GGX( alpha, dotNH );\n return F * ( V * D );\n }\n#endif\nvec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in PhysicalMaterial material ) {\n vec3 f0 = material.specularColor;\n float f90 = material.specularF90;\n float roughness = material.roughness;\n float alpha = pow2( roughness );\n vec3 halfDir = normalize( lightDir + viewDir );\n float dotNL = saturate( dot( normal, lightDir ) );\n float dotNV = saturate( dot( normal, viewDir ) );\n float dotNH = saturate( dot( normal, halfDir ) );\n float dotVH = saturate( dot( viewDir, halfDir ) );\n vec3 F = F_Schlick( f0, f90, dotVH );\n #ifdef USE_IRIDESCENCE\n F = mix( F, material.iridescenceFresnel, material.iridescence );\n #endif\n #ifdef USE_ANISOTROPY\n float dotTL = dot( material.anisotropyT, lightDir );\n float dotTV = dot( material.anisotropyT, viewDir );\n float dotTH = dot( material.anisotropyT, halfDir );\n float dotBL = dot( material.anisotropyB, lightDir );\n float dotBV = dot( material.anisotropyB, viewDir );\n float dotBH = dot( material.anisotropyB, halfDir );\n float V = V_GGX_SmithCorrelated_Anisotropic( material.alphaT, alpha, dotTV, dotBV, dotTL, dotBL, dotNV, dotNL );\n float D = D_GGX_Anisotropic( material.alphaT, alpha, dotNH, dotTH, dotBH );\n #else\n float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n float D = D_GGX( alpha, dotNH );\n #endif\n return F * ( V * D );\n}\nvec2 LTC_Uv( const in vec3 N, const in vec3 V, const in float roughness ) {\n const float LUT_SIZE = 64.0;\n const float LUT_SCALE = ( LUT_SIZE - 1.0 ) / LUT_SIZE;\n const float LUT_BIAS = 0.5 / LUT_SIZE;\n float dotNV = saturate( dot( N, V ) );\n vec2 uv = vec2( roughness, sqrt( 1.0 - dotNV ) );\n uv = uv * LUT_SCALE + LUT_BIAS;\n return uv;\n}\nfloat LTC_ClippedSphereFormFactor( const in vec3 f ) {\n float l = length( f );\n return max( ( l * l + f.z ) / ( l + 1.0 ), 0.0 );\n}\nvec3 LTC_EdgeVectorFormFactor( const in vec3 v1, const in vec3 v2 ) {\n float x = dot( v1, v2 );\n float y = abs( x );\n float a = 0.8543985 + ( 0.4965155 + 0.0145206 * y ) * y;\n float b = 3.4175940 + ( 4.1616724 + y ) * y;\n float v = a / b;\n float theta_sintheta = ( x > 0.0 ) ? v : 0.5 * inversesqrt( max( 1.0 - x * x, 1e-7 ) ) - v;\n return cross( v1, v2 ) * theta_sintheta;\n}\nvec3 LTC_Evaluate( const in vec3 N, const in vec3 V, const in vec3 P, const in mat3 mInv, const in vec3 rectCoords[ 4 ] ) {\n vec3 v1 = rectCoords[ 1 ] - rectCoords[ 0 ];\n vec3 v2 = rectCoords[ 3 ] - rectCoords[ 0 ];\n vec3 lightNormal = cross( v1, v2 );\n if( dot( lightNormal, P - rectCoords[ 0 ] ) < 0.0 ) return vec3( 0.0 );\n vec3 T1, T2;\n T1 = normalize( V - N * dot( V, N ) );\n T2 = - cross( N, T1 );\n mat3 mat = mInv * transposeMat3( mat3( T1, T2, N ) );\n vec3 coords[ 4 ];\n coords[ 0 ] = mat * ( rectCoords[ 0 ] - P );\n coords[ 1 ] = mat * ( rectCoords[ 1 ] - P );\n coords[ 2 ] = mat * ( rectCoords[ 2 ] - P );\n coords[ 3 ] = mat * ( rectCoords[ 3 ] - P );\n coords[ 0 ] = normalize( coords[ 0 ] );\n coords[ 1 ] = normalize( coords[ 1 ] );\n coords[ 2 ] = normalize( coords[ 2 ] );\n coords[ 3 ] = normalize( coords[ 3 ] );\n vec3 vectorFormFactor = vec3( 0.0 );\n vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 0 ], coords[ 1 ] );\n vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 1 ], coords[ 2 ] );\n vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 2 ], coords[ 3 ] );\n vectorFormFactor += LTC_EdgeVectorFormFactor( coords[ 3 ], coords[ 0 ] );\n float result = LTC_ClippedSphereFormFactor( vectorFormFactor );\n return vec3( result );\n}\n#if defined( USE_SHEEN )\nfloat D_Charlie( float roughness, float dotNH ) {\n float alpha = pow2( roughness );\n float invAlpha = 1.0 / alpha;\n float cos2h = dotNH * dotNH;\n float sin2h = max( 1.0 - cos2h, 0.0078125 );\n return ( 2.0 + invAlpha ) * pow( sin2h, invAlpha * 0.5 ) / ( 2.0 * PI );\n}\nfloat V_Neubelt( float dotNV, float dotNL ) {\n return saturate( 1.0 / ( 4.0 * ( dotNL + dotNV - dotNL * dotNV ) ) );\n}\nvec3 BRDF_Sheen( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, vec3 sheenColor, const in float sheenRoughness ) {\n vec3 halfDir = normalize( lightDir + viewDir );\n float dotNL = saturate( dot( normal, lightDir ) );\n float dotNV = saturate( dot( normal, viewDir ) );\n float dotNH = saturate( dot( normal, halfDir ) );\n float D = D_Charlie( sheenRoughness, dotNH );\n float V = V_Neubelt( dotNV, dotNL );\n return sheenColor * ( D * V );\n}\n#endif\nfloat IBLSheenBRDF( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n float dotNV = saturate( dot( normal, viewDir ) );\n float r2 = roughness * roughness;\n float a = roughness < 0.25 ? -339.2 * r2 + 161.4 * roughness - 25.9 : -8.48 * r2 + 14.3 * roughness - 9.95;\n float b = roughness < 0.25 ? 44.0 * r2 - 23.7 * roughness + 3.26 : 1.97 * r2 - 3.27 * roughness + 0.72;\n float DG = exp( a * dotNV + b ) + ( roughness < 0.25 ? 0.0 : 0.1 * ( roughness - 0.25 ) );\n return saturate( DG * RECIPROCAL_PI );\n}\nvec2 DFGApprox( const in vec3 normal, const in vec3 viewDir, const in float roughness ) {\n float dotNV = saturate( dot( normal, viewDir ) );\n const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n vec2 fab = vec2( - 1.04, 1.04 ) * a004 + r.zw;\n return fab;\n}\nvec3 EnvironmentBRDF( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness ) {\n vec2 fab = DFGApprox( normal, viewDir, roughness );\n return specularColor * fab.x + specularF90 * fab.y;\n}\n#ifdef USE_IRIDESCENCE\nvoid computeMultiscatteringIridescence( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float iridescence, const in vec3 iridescenceF0, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#else\nvoid computeMultiscattering( const in vec3 normal, const in vec3 viewDir, const in vec3 specularColor, const in float specularF90, const in float roughness, inout vec3 singleScatter, inout vec3 multiScatter ) {\n#endif\n vec2 fab = DFGApprox( normal, viewDir, roughness );\n #ifdef USE_IRIDESCENCE\n vec3 Fr = mix( specularColor, iridescenceF0, iridescence );\n #else\n vec3 Fr = specularColor;\n #endif\n vec3 FssEss = Fr * fab.x + specularF90 * fab.y;\n float Ess = fab.x + fab.y;\n float Ems = 1.0 - Ess;\n vec3 Favg = Fr + ( 1.0 - Fr ) * 0.047619; vec3 Fms = FssEss * Favg / ( 1.0 - Ems * Favg );\n singleScatter += FssEss;\n multiScatter += Fms * Ems;\n}\n#if NUM_RECT_AREA_LIGHTS > 0\n void RE_Direct_RectArea_Physical( const in RectAreaLight rectAreaLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n vec3 normal = geometryNormal;\n vec3 viewDir = geometryViewDir;\n vec3 position = geometryPosition;\n vec3 lightPos = rectAreaLight.position;\n vec3 halfWidth = rectAreaLight.halfWidth;\n vec3 halfHeight = rectAreaLight.halfHeight;\n vec3 lightColor = rectAreaLight.color;\n float roughness = material.roughness;\n vec3 rectCoords[ 4 ];\n rectCoords[ 0 ] = lightPos + halfWidth - halfHeight; rectCoords[ 1 ] = lightPos - halfWidth - halfHeight;\n rectCoords[ 2 ] = lightPos - halfWidth + halfHeight;\n rectCoords[ 3 ] = lightPos + halfWidth + halfHeight;\n vec2 uv = LTC_Uv( normal, viewDir, roughness );\n vec4 t1 = texture2D( ltc_1, uv );\n vec4 t2 = texture2D( ltc_2, uv );\n mat3 mInv = mat3(\n vec3( t1.x, 0, t1.y ),\n vec3( 0, 1, 0 ),\n vec3( t1.z, 0, t1.w )\n );\n vec3 fresnel = ( material.specularColor * t2.x + ( vec3( 1.0 ) - material.specularColor ) * t2.y );\n reflectedLight.directSpecular += lightColor * fresnel * LTC_Evaluate( normal, viewDir, position, mInv, rectCoords );\n reflectedLight.directDiffuse += lightColor * material.diffuseColor * LTC_Evaluate( normal, viewDir, position, mat3( 1.0 ), rectCoords );\n }\n#endif\nvoid RE_Direct_Physical( const in IncidentLight directLight, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n float dotNL = saturate( dot( geometryNormal, directLight.direction ) );\n vec3 irradiance = dotNL * directLight.color;\n #ifdef USE_CLEARCOAT\n float dotNLcc = saturate( dot( geometryClearcoatNormal, directLight.direction ) );\n vec3 ccIrradiance = dotNLcc * directLight.color;\n clearcoatSpecular += ccIrradiance * BRDF_GGX_Clearcoat( directLight.direction, geometryViewDir, geometryClearcoatNormal, material );\n #endif\n #ifdef USE_SHEEN\n sheenSpecular += irradiance * BRDF_Sheen( directLight.direction, geometryViewDir, geometryNormal, material.sheenColor, material.sheenRoughness );\n #endif\n reflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometryViewDir, geometryNormal, material );\n reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Physical( const in vec3 radiance, const in vec3 irradiance, const in vec3 clearcoatRadiance, const in vec3 geometryPosition, const in vec3 geometryNormal, const in vec3 geometryViewDir, const in vec3 geometryClearcoatNormal, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n #ifdef USE_CLEARCOAT\n clearcoatSpecular += clearcoatRadiance * EnvironmentBRDF( geometryClearcoatNormal, geometryViewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n #endif\n #ifdef USE_SHEEN\n sheenSpecular += irradiance * material.sheenColor * IBLSheenBRDF( geometryNormal, geometryViewDir, material.sheenRoughness );\n #endif\n vec3 singleScattering = vec3( 0.0 );\n vec3 multiScattering = vec3( 0.0 );\n vec3 cosineWeightedIrradiance = irradiance * RECIPROCAL_PI;\n #ifdef USE_IRIDESCENCE\n computeMultiscatteringIridescence( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnel, material.roughness, singleScattering, multiScattering );\n #else\n computeMultiscattering( geometryNormal, geometryViewDir, material.specularColor, material.specularF90, material.roughness, singleScattering, multiScattering );\n #endif\n vec3 totalScattering = singleScattering + multiScattering;\n vec3 diffuse = material.diffuseColor * ( 1.0 - max( max( totalScattering.r, totalScattering.g ), totalScattering.b ) );\n reflectedLight.indirectSpecular += radiance * singleScattering;\n reflectedLight.indirectSpecular += multiScattering * cosineWeightedIrradiance;\n reflectedLight.indirectDiffuse += diffuse * cosineWeightedIrradiance;\n}\n#define RE_Direct RE_Direct_Physical\n#define RE_Direct_RectArea RE_Direct_RectArea_Physical\n#define RE_IndirectDiffuse RE_IndirectDiffuse_Physical\n#define RE_IndirectSpecular RE_IndirectSpecular_Physical\nfloat computeSpecularOcclusion( const in float dotNV, const in float ambientOcclusion, const in float roughness ) {\n return saturate( pow( dotNV + ambientOcclusion, exp2( - 16.0 * roughness - 1.0 ) ) - 1.0 + ambientOcclusion );\n}"; var lights_fragment_begin2 = "\nvec3 geometryPosition = - vViewPosition;\nvec3 geometryNormal = normal;\nvec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\nvec3 geometryClearcoatNormal;\n#ifdef USE_CLEARCOAT\n geometryClearcoatNormal = clearcoatNormal;\n#endif\n#ifdef USE_IRIDESCENCE\n float dotNVi = saturate( dot( normal, geometryViewDir ) );\n if ( material.iridescenceThickness == 0.0 ) {\n material.iridescence = 0.0;\n } else {\n material.iridescence = saturate( material.iridescence );\n }\n if ( material.iridescence > 0.0 ) {\n material.iridescenceFresnel = evalIridescence( 1.0, material.iridescenceIOR, dotNVi, material.iridescenceThickness, material.specularColor );\n material.iridescenceF0 = Schlick_to_F0( material.iridescenceFresnel, 1.0, dotNVi );\n }\n#endif\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n PointLight pointLight;\n #if defined( USE_SHADOWMAP ) && NUM_POINT_LIGHT_SHADOWS > 0\n PointLightShadow pointLightShadow;\n #endif\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n pointLight = pointLights[ i ];\n getPointLightInfo( pointLight, geometryPosition, directLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n pointLightShadow = pointLightShadows[ i ];\n directLight.color *= ( directLight.visible && receiveShadow ) ? getPointShadow( pointShadowMap[ i ], pointLightShadow.shadowMapSize, pointLightShadow.shadowBias, pointLightShadow.shadowRadius, vPointShadowCoord[ i ], pointLightShadow.shadowCameraNear, pointLightShadow.shadowCameraFar ) : 1.0;\n #endif\n RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n }\n #pragma unroll_loop_end\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n SpotLight spotLight;\n vec4 spotColor;\n vec3 spotLightCoord;\n bool inSpotLightMap;\n #if defined( USE_SHADOWMAP ) && NUM_SPOT_LIGHT_SHADOWS > 0\n SpotLightShadow spotLightShadow;\n #endif\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n spotLight = spotLights[ i ];\n getSpotLightInfo( spotLight, geometryPosition, directLight );\n #if ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n #define SPOT_LIGHT_MAP_INDEX UNROLLED_LOOP_INDEX\n #elif ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n #define SPOT_LIGHT_MAP_INDEX NUM_SPOT_LIGHT_MAPS\n #else\n #define SPOT_LIGHT_MAP_INDEX ( UNROLLED_LOOP_INDEX - NUM_SPOT_LIGHT_SHADOWS + NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS )\n #endif\n #if ( SPOT_LIGHT_MAP_INDEX < NUM_SPOT_LIGHT_MAPS )\n spotLightCoord = vSpotLightCoord[ i ].xyz / vSpotLightCoord[ i ].w;\n inSpotLightMap = all( lessThan( abs( spotLightCoord * 2. - 1. ), vec3( 1.0 ) ) );\n spotColor = texture2D( spotLightMap[ SPOT_LIGHT_MAP_INDEX ], spotLightCoord.xy );\n directLight.color = inSpotLightMap ? directLight.color * spotColor.rgb : directLight.color;\n #endif\n #undef SPOT_LIGHT_MAP_INDEX\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n spotLightShadow = spotLightShadows[ i ];\n directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n }\n #pragma unroll_loop_end\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n DirectionalLight directionalLight;\n #if defined( USE_SHADOWMAP ) && NUM_DIR_LIGHT_SHADOWS > 0\n DirectionalLightShadow directionalLightShadow;\n #endif\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n directionalLight = directionalLights[ i ];\n getDirectionalLightInfo( directionalLight, directLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n directionalLightShadow = directionalLightShadows[ i ];\n directLight.color *= ( directLight.visible && receiveShadow ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( directLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n }\n #pragma unroll_loop_end\n#endif\n#if ( NUM_RECT_AREA_LIGHTS > 0 ) && defined( RE_Direct_RectArea )\n RectAreaLight rectAreaLight;\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_RECT_AREA_LIGHTS; i ++ ) {\n rectAreaLight = rectAreaLights[ i ];\n RE_Direct_RectArea( rectAreaLight, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n }\n #pragma unroll_loop_end\n#endif\n#if defined( RE_IndirectDiffuse )\n vec3 iblIrradiance = vec3( 0.0 );\n vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n #if defined( USE_LIGHT_PROBES )\n irradiance += getLightProbeIrradiance( lightProbe, geometryNormal );\n #endif\n #if ( NUM_HEMI_LIGHTS > 0 )\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometryNormal );\n }\n #pragma unroll_loop_end\n #endif\n#endif\n#if defined( RE_IndirectSpecular )\n vec3 radiance = vec3( 0.0 );\n vec3 clearcoatRadiance = vec3( 0.0 );\n#endif"; var lights_fragment_maps2 = "#if defined( RE_IndirectDiffuse )\n #ifdef USE_LIGHTMAP\n vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n vec3 lightMapIrradiance = lightMapTexel.rgb * lightMapIntensity;\n irradiance += lightMapIrradiance;\n #endif\n #if defined( USE_ENVMAP ) && defined( STANDARD ) && defined( ENVMAP_TYPE_CUBE_UV )\n iblIrradiance += getIBLIrradiance( geometryNormal );\n #endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n #ifdef USE_ANISOTROPY\n radiance += getIBLAnisotropyRadiance( geometryViewDir, geometryNormal, material.roughness, material.anisotropyB, material.anisotropy );\n #else\n radiance += getIBLRadiance( geometryViewDir, geometryNormal, material.roughness );\n #endif\n #ifdef USE_CLEARCOAT\n clearcoatRadiance += getIBLRadiance( geometryViewDir, geometryClearcoatNormal, material.clearcoatRoughness );\n #endif\n#endif"; var lights_fragment_end2 = "#if defined( RE_IndirectDiffuse )\n RE_IndirectDiffuse( irradiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometryPosition, geometryNormal, geometryViewDir, geometryClearcoatNormal, material, reflectedLight );\n#endif"; var logdepthbuf_fragment2 = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n gl_FragDepthEXT = vIsPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;\n#endif"; var logdepthbuf_pars_fragment2 = "#if defined( USE_LOGDEPTHBUF ) && defined( USE_LOGDEPTHBUF_EXT )\n uniform float logDepthBufFC;\n varying float vFragDepth;\n varying float vIsPerspective;\n#endif"; var logdepthbuf_pars_vertex2 = "#ifdef USE_LOGDEPTHBUF\n #ifdef USE_LOGDEPTHBUF_EXT\n varying float vFragDepth;\n varying float vIsPerspective;\n #else\n uniform float logDepthBufFC;\n #endif\n#endif"; var logdepthbuf_vertex2 = "#ifdef USE_LOGDEPTHBUF\n #ifdef USE_LOGDEPTHBUF_EXT\n vFragDepth = 1.0 + gl_Position.w;\n vIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n #else\n if ( isPerspectiveMatrix( projectionMatrix ) ) {\n gl_Position.z = log2( max( EPSILON, gl_Position.w + 1.0 ) ) * logDepthBufFC - 1.0;\n gl_Position.z *= gl_Position.w;\n }\n #endif\n#endif"; var map_fragment2 = "#ifdef USE_MAP\n vec4 sampledDiffuseColor = texture2D( map, vMapUv );\n #ifdef DECODE_VIDEO_TEXTURE\n sampledDiffuseColor = vec4( mix( pow( sampledDiffuseColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), sampledDiffuseColor.rgb * 0.0773993808, vec3( lessThanEqual( sampledDiffuseColor.rgb, vec3( 0.04045 ) ) ) ), sampledDiffuseColor.w );\n \n #endif\n diffuseColor *= sampledDiffuseColor;\n#endif"; var map_pars_fragment2 = "#ifdef USE_MAP\n uniform sampler2D map;\n#endif"; var map_particle_fragment2 = "#if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n #if defined( USE_POINTS_UV )\n vec2 uv = vUv;\n #else\n vec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\n #endif\n#endif\n#ifdef USE_MAP\n diffuseColor *= texture2D( map, uv );\n#endif\n#ifdef USE_ALPHAMAP\n diffuseColor.a *= texture2D( alphaMap, uv ).g;\n#endif"; var map_particle_pars_fragment2 = "#if defined( USE_POINTS_UV )\n varying vec2 vUv;\n#else\n #if defined( USE_MAP ) || defined( USE_ALPHAMAP )\n uniform mat3 uvTransform;\n #endif\n#endif\n#ifdef USE_MAP\n uniform sampler2D map;\n#endif\n#ifdef USE_ALPHAMAP\n uniform sampler2D alphaMap;\n#endif"; var metalnessmap_fragment2 = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n vec4 texelMetalness = texture2D( metalnessMap, vMetalnessMapUv );\n metalnessFactor *= texelMetalness.b;\n#endif"; var metalnessmap_pars_fragment2 = "#ifdef USE_METALNESSMAP\n uniform sampler2D metalnessMap;\n#endif"; var morphcolor_vertex2 = "#if defined( USE_MORPHCOLORS ) && defined( MORPHTARGETS_TEXTURE )\n vColor *= morphTargetBaseInfluence;\n for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n #if defined( USE_COLOR_ALPHA )\n if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ) * morphTargetInfluences[ i ];\n #elif defined( USE_COLOR )\n if ( morphTargetInfluences[ i ] != 0.0 ) vColor += getMorph( gl_VertexID, i, 2 ).rgb * morphTargetInfluences[ i ];\n #endif\n }\n#endif"; var morphnormal_vertex2 = "#ifdef USE_MORPHNORMALS\n objectNormal *= morphTargetBaseInfluence;\n #ifdef MORPHTARGETS_TEXTURE\n for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n if ( morphTargetInfluences[ i ] != 0.0 ) objectNormal += getMorph( gl_VertexID, i, 1 ).xyz * morphTargetInfluences[ i ];\n }\n #else\n objectNormal += morphNormal0 * morphTargetInfluences[ 0 ];\n objectNormal += morphNormal1 * morphTargetInfluences[ 1 ];\n objectNormal += morphNormal2 * morphTargetInfluences[ 2 ];\n objectNormal += morphNormal3 * morphTargetInfluences[ 3 ];\n #endif\n#endif"; var morphtarget_pars_vertex2 = "#ifdef USE_MORPHTARGETS\n uniform float morphTargetBaseInfluence;\n #ifdef MORPHTARGETS_TEXTURE\n uniform float morphTargetInfluences[ MORPHTARGETS_COUNT ];\n uniform sampler2DArray morphTargetsTexture;\n uniform ivec2 morphTargetsTextureSize;\n vec4 getMorph( const in int vertexIndex, const in int morphTargetIndex, const in int offset ) {\n int texelIndex = vertexIndex * MORPHTARGETS_TEXTURE_STRIDE + offset;\n int y = texelIndex / morphTargetsTextureSize.x;\n int x = texelIndex - y * morphTargetsTextureSize.x;\n ivec3 morphUV = ivec3( x, y, morphTargetIndex );\n return texelFetch( morphTargetsTexture, morphUV, 0 );\n }\n #else\n #ifndef USE_MORPHNORMALS\n uniform float morphTargetInfluences[ 8 ];\n #else\n uniform float morphTargetInfluences[ 4 ];\n #endif\n #endif\n#endif"; var morphtarget_vertex2 = "#ifdef USE_MORPHTARGETS\n transformed *= morphTargetBaseInfluence;\n #ifdef MORPHTARGETS_TEXTURE\n for ( int i = 0; i < MORPHTARGETS_COUNT; i ++ ) {\n if ( morphTargetInfluences[ i ] != 0.0 ) transformed += getMorph( gl_VertexID, i, 0 ).xyz * morphTargetInfluences[ i ];\n }\n #else\n transformed += morphTarget0 * morphTargetInfluences[ 0 ];\n transformed += morphTarget1 * morphTargetInfluences[ 1 ];\n transformed += morphTarget2 * morphTargetInfluences[ 2 ];\n transformed += morphTarget3 * morphTargetInfluences[ 3 ];\n #ifndef USE_MORPHNORMALS\n transformed += morphTarget4 * morphTargetInfluences[ 4 ];\n transformed += morphTarget5 * morphTargetInfluences[ 5 ];\n transformed += morphTarget6 * morphTargetInfluences[ 6 ];\n transformed += morphTarget7 * morphTargetInfluences[ 7 ];\n #endif\n #endif\n#endif"; var normal_fragment_begin2 = "float faceDirection = gl_FrontFacing ? 1.0 : - 1.0;\n#ifdef FLAT_SHADED\n vec3 fdx = dFdx( vViewPosition );\n vec3 fdy = dFdy( vViewPosition );\n vec3 normal = normalize( cross( fdx, fdy ) );\n#else\n vec3 normal = normalize( vNormal );\n #ifdef DOUBLE_SIDED\n normal *= faceDirection;\n #endif\n#endif\n#if defined( USE_NORMALMAP_TANGENTSPACE ) || defined( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY )\n #ifdef USE_TANGENT\n mat3 tbn = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\n #else\n mat3 tbn = getTangentFrame( - vViewPosition, normal,\n #if defined( USE_NORMALMAP )\n vNormalMapUv\n #elif defined( USE_CLEARCOAT_NORMALMAP )\n vClearcoatNormalMapUv\n #else\n vUv\n #endif\n );\n #endif\n #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )\n tbn[0] *= faceDirection;\n tbn[1] *= faceDirection;\n #endif\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n #ifdef USE_TANGENT\n mat3 tbn2 = mat3( normalize( vTangent ), normalize( vBitangent ), normal );\n #else\n mat3 tbn2 = getTangentFrame( - vViewPosition, normal, vClearcoatNormalMapUv );\n #endif\n #if defined( DOUBLE_SIDED ) && ! defined( FLAT_SHADED )\n tbn2[0] *= faceDirection;\n tbn2[1] *= faceDirection;\n #endif\n#endif\nvec3 nonPerturbedNormal = normal;"; var normal_fragment_maps2 = "#ifdef USE_NORMALMAP_OBJECTSPACE\n normal = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n #ifdef FLIP_SIDED\n normal = - normal;\n #endif\n #ifdef DOUBLE_SIDED\n normal = normal * faceDirection;\n #endif\n normal = normalize( normalMatrix * normal );\n#elif defined( USE_NORMALMAP_TANGENTSPACE )\n vec3 mapN = texture2D( normalMap, vNormalMapUv ).xyz * 2.0 - 1.0;\n mapN.xy *= normalScale;\n normal = normalize( tbn * mapN );\n#elif defined( USE_BUMPMAP )\n normal = perturbNormalArb( - vViewPosition, normal, dHdxy_fwd(), faceDirection );\n#endif"; var normal_pars_fragment2 = "#ifndef FLAT_SHADED\n varying vec3 vNormal;\n #ifdef USE_TANGENT\n varying vec3 vTangent;\n varying vec3 vBitangent;\n #endif\n#endif"; var normal_pars_vertex2 = "#ifndef FLAT_SHADED\n varying vec3 vNormal;\n #ifdef USE_TANGENT\n varying vec3 vTangent;\n varying vec3 vBitangent;\n #endif\n#endif"; var normal_vertex2 = "#ifndef FLAT_SHADED\n vNormal = normalize( transformedNormal );\n #ifdef USE_TANGENT\n vTangent = normalize( transformedTangent );\n vBitangent = normalize( cross( vNormal, vTangent ) * tangent.w );\n #endif\n#endif"; var normalmap_pars_fragment2 = "#ifdef USE_NORMALMAP\n uniform sampler2D normalMap;\n uniform vec2 normalScale;\n#endif\n#ifdef USE_NORMALMAP_OBJECTSPACE\n uniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( USE_NORMALMAP_TANGENTSPACE ) || defined ( USE_CLEARCOAT_NORMALMAP ) || defined( USE_ANISOTROPY ) )\n mat3 getTangentFrame( vec3 eye_pos, vec3 surf_norm, vec2 uv ) {\n vec3 q0 = dFdx( eye_pos.xyz );\n vec3 q1 = dFdy( eye_pos.xyz );\n vec2 st0 = dFdx( uv.st );\n vec2 st1 = dFdy( uv.st );\n vec3 N = surf_norm;\n vec3 q1perp = cross( q1, N );\n vec3 q0perp = cross( N, q0 );\n vec3 T = q1perp * st0.x + q0perp * st1.x;\n vec3 B = q1perp * st0.y + q0perp * st1.y;\n float det = max( dot( T, T ), dot( B, B ) );\n float scale = ( det == 0.0 ) ? 0.0 : inversesqrt( det );\n return mat3( T * scale, B * scale, N );\n }\n#endif"; var clearcoat_normal_fragment_begin2 = "#ifdef USE_CLEARCOAT\n vec3 clearcoatNormal = nonPerturbedNormal;\n#endif"; var clearcoat_normal_fragment_maps2 = "#ifdef USE_CLEARCOAT_NORMALMAP\n vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vClearcoatNormalMapUv ).xyz * 2.0 - 1.0;\n clearcoatMapN.xy *= clearcoatNormalScale;\n clearcoatNormal = normalize( tbn2 * clearcoatMapN );\n#endif"; var clearcoat_pars_fragment2 = "#ifdef USE_CLEARCOATMAP\n uniform sampler2D clearcoatMap;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n uniform sampler2D clearcoatNormalMap;\n uniform vec2 clearcoatNormalScale;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n uniform sampler2D clearcoatRoughnessMap;\n#endif"; var iridescence_pars_fragment2 = "#ifdef USE_IRIDESCENCEMAP\n uniform sampler2D iridescenceMap;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n uniform sampler2D iridescenceThicknessMap;\n#endif"; var opaque_fragment2 = "#ifdef OPAQUE\ndiffuseColor.a = 1.0;\n#endif\n#ifdef USE_TRANSMISSION\ndiffuseColor.a *= material.transmissionAlpha;\n#endif\ngl_FragColor = vec4( outgoingLight, diffuseColor.a );"; var packing2 = "vec3 packNormalToRGB( const in vec3 normal ) {\n return normalize( normal ) * 0.5 + 0.5;\n}\nvec3 unpackRGBToNormal( const in vec3 rgb ) {\n return 2.0 * rgb.xyz - 1.0;\n}\nconst float PackUpscale = 256. / 255.;const float UnpackDownscale = 255. / 256.;\nconst vec3 PackFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );\nconst vec4 UnpackFactors = UnpackDownscale / vec4( PackFactors, 1. );\nconst float ShiftRight8 = 1. / 256.;\nvec4 packDepthToRGBA( const in float v ) {\n vec4 r = vec4( fract( v * PackFactors ), v );\n r.yzw -= r.xyz * ShiftRight8; return r * PackUpscale;\n}\nfloat unpackRGBAToDepth( const in vec4 v ) {\n return dot( v, UnpackFactors );\n}\nvec2 packDepthToRG( in highp float v ) {\n return packDepthToRGBA( v ).yx;\n}\nfloat unpackRGToDepth( const in highp vec2 v ) {\n return unpackRGBAToDepth( vec4( v.xy, 0.0, 0.0 ) );\n}\nvec4 pack2HalfToRGBA( vec2 v ) {\n vec4 r = vec4( v.x, fract( v.x * 255.0 ), v.y, fract( v.y * 255.0 ) );\n return vec4( r.x - r.y / 255.0, r.y, r.z - r.w / 255.0, r.w );\n}\nvec2 unpackRGBATo2Half( vec4 v ) {\n return vec2( v.x + ( v.y / 255.0 ), v.z + ( v.w / 255.0 ) );\n}\nfloat viewZToOrthographicDepth( const in float viewZ, const in float near, const in float far ) {\n return ( viewZ + near ) / ( near - far );\n}\nfloat orthographicDepthToViewZ( const in float depth, const in float near, const in float far ) {\n return depth * ( near - far ) - near;\n}\nfloat viewZToPerspectiveDepth( const in float viewZ, const in float near, const in float far ) {\n return ( ( near + viewZ ) * far ) / ( ( far - near ) * viewZ );\n}\nfloat perspectiveDepthToViewZ( const in float depth, const in float near, const in float far ) {\n return ( near * far ) / ( ( far - near ) * depth - far );\n}"; var premultiplied_alpha_fragment2 = "#ifdef PREMULTIPLIED_ALPHA\n gl_FragColor.rgb *= gl_FragColor.a;\n#endif"; var project_vertex2 = "vec4 mvPosition = vec4( transformed, 1.0 );\n#ifdef USE_INSTANCING\n mvPosition = instanceMatrix * mvPosition;\n#endif\nmvPosition = modelViewMatrix * mvPosition;\ngl_Position = projectionMatrix * mvPosition;"; var dithering_fragment2 = "#ifdef DITHERING\n gl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif"; var dithering_pars_fragment2 = "#ifdef DITHERING\n vec3 dithering( vec3 color ) {\n float grid_position = rand( gl_FragCoord.xy );\n vec3 dither_shift_RGB = vec3( 0.25 / 255.0, -0.25 / 255.0, 0.25 / 255.0 );\n dither_shift_RGB = mix( 2.0 * dither_shift_RGB, -2.0 * dither_shift_RGB, grid_position );\n return color + dither_shift_RGB;\n }\n#endif"; var roughnessmap_fragment2 = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n vec4 texelRoughness = texture2D( roughnessMap, vRoughnessMapUv );\n roughnessFactor *= texelRoughness.g;\n#endif"; var roughnessmap_pars_fragment2 = "#ifdef USE_ROUGHNESSMAP\n uniform sampler2D roughnessMap;\n#endif"; var shadowmap_pars_fragment2 = "#if NUM_SPOT_LIGHT_COORDS > 0\n varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n#endif\n#if NUM_SPOT_LIGHT_MAPS > 0\n uniform sampler2D spotLightMap[ NUM_SPOT_LIGHT_MAPS ];\n#endif\n#ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHT_SHADOWS > 0\n uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHT_SHADOWS ];\n varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n struct DirectionalLightShadow {\n float shadowBias;\n float shadowNormalBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n #endif\n #if NUM_SPOT_LIGHT_SHADOWS > 0\n uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHT_SHADOWS ];\n struct SpotLightShadow {\n float shadowBias;\n float shadowNormalBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n #endif\n #if NUM_POINT_LIGHT_SHADOWS > 0\n uniform sampler2D pointShadowMap[ NUM_POINT_LIGHT_SHADOWS ];\n varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n struct PointLightShadow {\n float shadowBias;\n float shadowNormalBias;\n float shadowRadius;\n vec2 shadowMapSize;\n float shadowCameraNear;\n float shadowCameraFar;\n };\n uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n #endif\n float texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n return step( compare, unpackRGBAToDepth( texture2D( depths, uv ) ) );\n }\n vec2 texture2DDistribution( sampler2D shadow, vec2 uv ) {\n return unpackRGBATo2Half( texture2D( shadow, uv ) );\n }\n float VSMShadow (sampler2D shadow, vec2 uv, float compare ){\n float occlusion = 1.0;\n vec2 distribution = texture2DDistribution( shadow, uv );\n float hard_shadow = step( compare , distribution.x );\n if (hard_shadow != 1.0 ) {\n float distance = compare - distribution.x ;\n float variance = max( 0.00000, distribution.y * distribution.y );\n float softness_probability = variance / (variance + distance * distance ); softness_probability = clamp( ( softness_probability - 0.3 ) / ( 0.95 - 0.3 ), 0.0, 1.0 ); occlusion = clamp( max( hard_shadow, softness_probability ), 0.0, 1.0 );\n }\n return occlusion;\n }\n float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n float shadow = 1.0;\n shadowCoord.xyz /= shadowCoord.w;\n shadowCoord.z += shadowBias;\n bool inFrustum = shadowCoord.x >= 0.0 && shadowCoord.x <= 1.0 && shadowCoord.y >= 0.0 && shadowCoord.y <= 1.0;\n bool frustumTest = inFrustum && shadowCoord.z <= 1.0;\n if ( frustumTest ) {\n #if defined( SHADOWMAP_TYPE_PCF )\n vec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n float dx0 = - texelSize.x * shadowRadius;\n float dy0 = - texelSize.y * shadowRadius;\n float dx1 = + texelSize.x * shadowRadius;\n float dy1 = + texelSize.y * shadowRadius;\n float dx2 = dx0 / 2.0;\n float dy2 = dy0 / 2.0;\n float dx3 = dx1 / 2.0;\n float dy3 = dy1 / 2.0;\n shadow = (\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy2 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy2 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy2 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx2, dy3 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy3 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx3, dy3 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n ) * ( 1.0 / 17.0 );\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n vec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n float dx = texelSize.x;\n float dy = texelSize.y;\n vec2 uv = shadowCoord.xy;\n vec2 f = fract( uv * shadowMapSize + 0.5 );\n uv -= f * texelSize;\n shadow = (\n texture2DCompare( shadowMap, uv, shadowCoord.z ) +\n texture2DCompare( shadowMap, uv + vec2( dx, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, uv + vec2( 0.0, dy ), shadowCoord.z ) +\n texture2DCompare( shadowMap, uv + texelSize, shadowCoord.z ) +\n mix( texture2DCompare( shadowMap, uv + vec2( -dx, 0.0 ), shadowCoord.z ),\n texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 0.0 ), shadowCoord.z ),\n f.x ) +\n mix( texture2DCompare( shadowMap, uv + vec2( -dx, dy ), shadowCoord.z ),\n texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, dy ), shadowCoord.z ),\n f.x ) +\n mix( texture2DCompare( shadowMap, uv + vec2( 0.0, -dy ), shadowCoord.z ),\n texture2DCompare( shadowMap, uv + vec2( 0.0, 2.0 * dy ), shadowCoord.z ),\n f.y ) +\n mix( texture2DCompare( shadowMap, uv + vec2( dx, -dy ), shadowCoord.z ),\n texture2DCompare( shadowMap, uv + vec2( dx, 2.0 * dy ), shadowCoord.z ),\n f.y ) +\n mix( mix( texture2DCompare( shadowMap, uv + vec2( -dx, -dy ), shadowCoord.z ),\n texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, -dy ), shadowCoord.z ),\n f.x ),\n mix( texture2DCompare( shadowMap, uv + vec2( -dx, 2.0 * dy ), shadowCoord.z ),\n texture2DCompare( shadowMap, uv + vec2( 2.0 * dx, 2.0 * dy ), shadowCoord.z ),\n f.x ),\n f.y )\n ) * ( 1.0 / 9.0 );\n #elif defined( SHADOWMAP_TYPE_VSM )\n shadow = VSMShadow( shadowMap, shadowCoord.xy, shadowCoord.z );\n #else\n shadow = texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n #endif\n }\n return shadow;\n }\n vec2 cubeToUV( vec3 v, float texelSizeY ) {\n vec3 absV = abs( v );\n float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n absV *= scaleToCube;\n v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n vec2 planar = v.xy;\n float almostATexel = 1.5 * texelSizeY;\n float almostOne = 1.0 - almostATexel;\n if ( absV.z >= almostOne ) {\n if ( v.z > 0.0 )\n planar.x = 4.0 - v.x;\n } else if ( absV.x >= almostOne ) {\n float signX = sign( v.x );\n planar.x = v.z * signX + 2.0 * signX;\n } else if ( absV.y >= almostOne ) {\n float signY = sign( v.y );\n planar.x = v.x + 2.0 * signY + 2.0;\n planar.y = v.z * signY - 2.0;\n }\n return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n }\n float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord, float shadowCameraNear, float shadowCameraFar ) {\n vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n vec3 lightToPosition = shadowCoord.xyz;\n float dp = ( length( lightToPosition ) - shadowCameraNear ) / ( shadowCameraFar - shadowCameraNear ); dp += shadowBias;\n vec3 bd3D = normalize( lightToPosition );\n #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT ) || defined( SHADOWMAP_TYPE_VSM )\n vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n return (\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n ) * ( 1.0 / 9.0 );\n #else\n return texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n #endif\n }\n#endif"; var shadowmap_pars_vertex2 = "#if NUM_SPOT_LIGHT_COORDS > 0\n uniform mat4 spotLightMatrix[ NUM_SPOT_LIGHT_COORDS ];\n varying vec4 vSpotLightCoord[ NUM_SPOT_LIGHT_COORDS ];\n#endif\n#ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHT_SHADOWS > 0\n uniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHT_SHADOWS ];\n varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHT_SHADOWS ];\n struct DirectionalLightShadow {\n float shadowBias;\n float shadowNormalBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform DirectionalLightShadow directionalLightShadows[ NUM_DIR_LIGHT_SHADOWS ];\n #endif\n #if NUM_SPOT_LIGHT_SHADOWS > 0\n struct SpotLightShadow {\n float shadowBias;\n float shadowNormalBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform SpotLightShadow spotLightShadows[ NUM_SPOT_LIGHT_SHADOWS ];\n #endif\n #if NUM_POINT_LIGHT_SHADOWS > 0\n uniform mat4 pointShadowMatrix[ NUM_POINT_LIGHT_SHADOWS ];\n varying vec4 vPointShadowCoord[ NUM_POINT_LIGHT_SHADOWS ];\n struct PointLightShadow {\n float shadowBias;\n float shadowNormalBias;\n float shadowRadius;\n vec2 shadowMapSize;\n float shadowCameraNear;\n float shadowCameraFar;\n };\n uniform PointLightShadow pointLightShadows[ NUM_POINT_LIGHT_SHADOWS ];\n #endif\n#endif"; var shadowmap_vertex2 = "#if ( defined( USE_SHADOWMAP ) && ( NUM_DIR_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0 ) ) || ( NUM_SPOT_LIGHT_COORDS > 0 )\n vec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n vec4 shadowWorldPosition;\n#endif\n#if defined( USE_SHADOWMAP )\n #if NUM_DIR_LIGHT_SHADOWS > 0\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * directionalLightShadows[ i ].shadowNormalBias, 0 );\n vDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * shadowWorldPosition;\n }\n #pragma unroll_loop_end\n #endif\n #if NUM_POINT_LIGHT_SHADOWS > 0\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * pointLightShadows[ i ].shadowNormalBias, 0 );\n vPointShadowCoord[ i ] = pointShadowMatrix[ i ] * shadowWorldPosition;\n }\n #pragma unroll_loop_end\n #endif\n#endif\n#if NUM_SPOT_LIGHT_COORDS > 0\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_SPOT_LIGHT_COORDS; i ++ ) {\n shadowWorldPosition = worldPosition;\n #if ( defined( USE_SHADOWMAP ) && UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n shadowWorldPosition.xyz += shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias;\n #endif\n vSpotLightCoord[ i ] = spotLightMatrix[ i ] * shadowWorldPosition;\n }\n #pragma unroll_loop_end\n#endif"; var shadowmask_pars_fragment2 = "float getShadowMask() {\n float shadow = 1.0;\n #ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHT_SHADOWS > 0\n DirectionalLightShadow directionalLight;\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_DIR_LIGHT_SHADOWS; i ++ ) {\n directionalLight = directionalLightShadows[ i ];\n shadow *= receiveShadow ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n }\n #pragma unroll_loop_end\n #endif\n #if NUM_SPOT_LIGHT_SHADOWS > 0\n SpotLightShadow spotLight;\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n spotLight = spotLightShadows[ i ];\n shadow *= receiveShadow ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotLightCoord[ i ] ) : 1.0;\n }\n #pragma unroll_loop_end\n #endif\n #if NUM_POINT_LIGHT_SHADOWS > 0\n PointLightShadow pointLight;\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_POINT_LIGHT_SHADOWS; i ++ ) {\n pointLight = pointLightShadows[ i ];\n shadow *= receiveShadow ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ], pointLight.shadowCameraNear, pointLight.shadowCameraFar ) : 1.0;\n }\n #pragma unroll_loop_end\n #endif\n #endif\n return shadow;\n}"; var skinbase_vertex2 = "#ifdef USE_SKINNING\n mat4 boneMatX = getBoneMatrix( skinIndex.x );\n mat4 boneMatY = getBoneMatrix( skinIndex.y );\n mat4 boneMatZ = getBoneMatrix( skinIndex.z );\n mat4 boneMatW = getBoneMatrix( skinIndex.w );\n#endif"; var skinning_pars_vertex2 = "#ifdef USE_SKINNING\n uniform mat4 bindMatrix;\n uniform mat4 bindMatrixInverse;\n uniform highp sampler2D boneTexture;\n uniform int boneTextureSize;\n mat4 getBoneMatrix( const in float i ) {\n float j = i * 4.0;\n float x = mod( j, float( boneTextureSize ) );\n float y = floor( j / float( boneTextureSize ) );\n float dx = 1.0 / float( boneTextureSize );\n float dy = 1.0 / float( boneTextureSize );\n y = dy * ( y + 0.5 );\n vec4 v1 = texture2D( boneTexture, vec2( dx * ( x + 0.5 ), y ) );\n vec4 v2 = texture2D( boneTexture, vec2( dx * ( x + 1.5 ), y ) );\n vec4 v3 = texture2D( boneTexture, vec2( dx * ( x + 2.5 ), y ) );\n vec4 v4 = texture2D( boneTexture, vec2( dx * ( x + 3.5 ), y ) );\n mat4 bone = mat4( v1, v2, v3, v4 );\n return bone;\n }\n#endif"; var skinning_vertex2 = "#ifdef USE_SKINNING\n vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n vec4 skinned = vec4( 0.0 );\n skinned += boneMatX * skinVertex * skinWeight.x;\n skinned += boneMatY * skinVertex * skinWeight.y;\n skinned += boneMatZ * skinVertex * skinWeight.z;\n skinned += boneMatW * skinVertex * skinWeight.w;\n transformed = ( bindMatrixInverse * skinned ).xyz;\n#endif"; var skinnormal_vertex2 = "#ifdef USE_SKINNING\n mat4 skinMatrix = mat4( 0.0 );\n skinMatrix += skinWeight.x * boneMatX;\n skinMatrix += skinWeight.y * boneMatY;\n skinMatrix += skinWeight.z * boneMatZ;\n skinMatrix += skinWeight.w * boneMatW;\n skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n #ifdef USE_TANGENT\n objectTangent = vec4( skinMatrix * vec4( objectTangent, 0.0 ) ).xyz;\n #endif\n#endif"; var specularmap_fragment2 = "float specularStrength;\n#ifdef USE_SPECULARMAP\n vec4 texelSpecular = texture2D( specularMap, vSpecularMapUv );\n specularStrength = texelSpecular.r;\n#else\n specularStrength = 1.0;\n#endif"; var specularmap_pars_fragment2 = "#ifdef USE_SPECULARMAP\n uniform sampler2D specularMap;\n#endif"; var tonemapping_fragment2 = "#if defined( TONE_MAPPING )\n gl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif"; var tonemapping_pars_fragment2 = "#ifndef saturate\n#define saturate( a ) clamp( a, 0.0, 1.0 )\n#endif\nuniform float toneMappingExposure;\nvec3 LinearToneMapping( vec3 color ) {\n return saturate( toneMappingExposure * color );\n}\nvec3 ReinhardToneMapping( vec3 color ) {\n color *= toneMappingExposure;\n return saturate( color / ( vec3( 1.0 ) + color ) );\n}\nvec3 OptimizedCineonToneMapping( vec3 color ) {\n color *= toneMappingExposure;\n color = max( vec3( 0.0 ), color - 0.004 );\n return pow( ( color * ( 6.2 * color + 0.5 ) ) / ( color * ( 6.2 * color + 1.7 ) + 0.06 ), vec3( 2.2 ) );\n}\nvec3 RRTAndODTFit( vec3 v ) {\n vec3 a = v * ( v + 0.0245786 ) - 0.000090537;\n vec3 b = v * ( 0.983729 * v + 0.4329510 ) + 0.238081;\n return a / b;\n}\nvec3 ACESFilmicToneMapping( vec3 color ) {\n const mat3 ACESInputMat = mat3(\n vec3( 0.59719, 0.07600, 0.02840 ), vec3( 0.35458, 0.90834, 0.13383 ),\n vec3( 0.04823, 0.01566, 0.83777 )\n );\n const mat3 ACESOutputMat = mat3(\n vec3( 1.60475, -0.10208, -0.00327 ), vec3( -0.53108, 1.10813, -0.07276 ),\n vec3( -0.07367, -0.00605, 1.07602 )\n );\n color *= toneMappingExposure / 0.6;\n color = ACESInputMat * color;\n color = RRTAndODTFit( color );\n color = ACESOutputMat * color;\n return saturate( color );\n}\nvec3 CustomToneMapping( vec3 color ) { return color; }"; var transmission_fragment2 = "#ifdef USE_TRANSMISSION\n material.transmission = transmission;\n material.transmissionAlpha = 1.0;\n material.thickness = thickness;\n material.attenuationDistance = attenuationDistance;\n material.attenuationColor = attenuationColor;\n #ifdef USE_TRANSMISSIONMAP\n material.transmission *= texture2D( transmissionMap, vTransmissionMapUv ).r;\n #endif\n #ifdef USE_THICKNESSMAP\n material.thickness *= texture2D( thicknessMap, vThicknessMapUv ).g;\n #endif\n vec3 pos = vWorldPosition;\n vec3 v = normalize( cameraPosition - pos );\n vec3 n = inverseTransformDirection( normal, viewMatrix );\n vec4 transmitted = getIBLVolumeRefraction(\n n, v, material.roughness, material.diffuseColor, material.specularColor, material.specularF90,\n pos, modelMatrix, viewMatrix, projectionMatrix, material.ior, material.thickness,\n material.attenuationColor, material.attenuationDistance );\n material.transmissionAlpha = mix( material.transmissionAlpha, transmitted.a, material.transmission );\n totalDiffuse = mix( totalDiffuse, transmitted.rgb, material.transmission );\n#endif"; var transmission_pars_fragment2 = "#ifdef USE_TRANSMISSION\n uniform float transmission;\n uniform float thickness;\n uniform float attenuationDistance;\n uniform vec3 attenuationColor;\n #ifdef USE_TRANSMISSIONMAP\n uniform sampler2D transmissionMap;\n #endif\n #ifdef USE_THICKNESSMAP\n uniform sampler2D thicknessMap;\n #endif\n uniform vec2 transmissionSamplerSize;\n uniform sampler2D transmissionSamplerMap;\n uniform mat4 modelMatrix;\n uniform mat4 projectionMatrix;\n varying vec3 vWorldPosition;\n float w0( float a ) {\n return ( 1.0 / 6.0 ) * ( a * ( a * ( - a + 3.0 ) - 3.0 ) + 1.0 );\n }\n float w1( float a ) {\n return ( 1.0 / 6.0 ) * ( a * a * ( 3.0 * a - 6.0 ) + 4.0 );\n }\n float w2( float a ){\n return ( 1.0 / 6.0 ) * ( a * ( a * ( - 3.0 * a + 3.0 ) + 3.0 ) + 1.0 );\n }\n float w3( float a ) {\n return ( 1.0 / 6.0 ) * ( a * a * a );\n }\n float g0( float a ) {\n return w0( a ) + w1( a );\n }\n float g1( float a ) {\n return w2( a ) + w3( a );\n }\n float h0( float a ) {\n return - 1.0 + w1( a ) / ( w0( a ) + w1( a ) );\n }\n float h1( float a ) {\n return 1.0 + w3( a ) / ( w2( a ) + w3( a ) );\n }\n vec4 bicubic( sampler2D tex, vec2 uv, vec4 texelSize, float lod ) {\n uv = uv * texelSize.zw + 0.5;\n vec2 iuv = floor( uv );\n vec2 fuv = fract( uv );\n float g0x = g0( fuv.x );\n float g1x = g1( fuv.x );\n float h0x = h0( fuv.x );\n float h1x = h1( fuv.x );\n float h0y = h0( fuv.y );\n float h1y = h1( fuv.y );\n vec2 p0 = ( vec2( iuv.x + h0x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\n vec2 p1 = ( vec2( iuv.x + h1x, iuv.y + h0y ) - 0.5 ) * texelSize.xy;\n vec2 p2 = ( vec2( iuv.x + h0x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\n vec2 p3 = ( vec2( iuv.x + h1x, iuv.y + h1y ) - 0.5 ) * texelSize.xy;\n return g0( fuv.y ) * ( g0x * textureLod( tex, p0, lod ) + g1x * textureLod( tex, p1, lod ) ) +\n g1( fuv.y ) * ( g0x * textureLod( tex, p2, lod ) + g1x * textureLod( tex, p3, lod ) );\n }\n vec4 textureBicubic( sampler2D sampler, vec2 uv, float lod ) {\n vec2 fLodSize = vec2( textureSize( sampler, int( lod ) ) );\n vec2 cLodSize = vec2( textureSize( sampler, int( lod + 1.0 ) ) );\n vec2 fLodSizeInv = 1.0 / fLodSize;\n vec2 cLodSizeInv = 1.0 / cLodSize;\n vec4 fSample = bicubic( sampler, uv, vec4( fLodSizeInv, fLodSize ), floor( lod ) );\n vec4 cSample = bicubic( sampler, uv, vec4( cLodSizeInv, cLodSize ), ceil( lod ) );\n return mix( fSample, cSample, fract( lod ) );\n }\n vec3 getVolumeTransmissionRay( const in vec3 n, const in vec3 v, const in float thickness, const in float ior, const in mat4 modelMatrix ) {\n vec3 refractionVector = refract( - v, normalize( n ), 1.0 / ior );\n vec3 modelScale;\n modelScale.x = length( vec3( modelMatrix[ 0 ].xyz ) );\n modelScale.y = length( vec3( modelMatrix[ 1 ].xyz ) );\n modelScale.z = length( vec3( modelMatrix[ 2 ].xyz ) );\n return normalize( refractionVector ) * thickness * modelScale;\n }\n float applyIorToRoughness( const in float roughness, const in float ior ) {\n return roughness * clamp( ior * 2.0 - 2.0, 0.0, 1.0 );\n }\n vec4 getTransmissionSample( const in vec2 fragCoord, const in float roughness, const in float ior ) {\n float lod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );\n return textureBicubic( transmissionSamplerMap, fragCoord.xy, lod );\n }\n vec3 volumeAttenuation( const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {\n if ( isinf( attenuationDistance ) ) {\n return vec3( 1.0 );\n } else {\n vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;\n vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance ); return transmittance;\n }\n }\n vec4 getIBLVolumeRefraction( const in vec3 n, const in vec3 v, const in float roughness, const in vec3 diffuseColor,\n const in vec3 specularColor, const in float specularF90, const in vec3 position, const in mat4 modelMatrix,\n const in mat4 viewMatrix, const in mat4 projMatrix, const in float ior, const in float thickness,\n const in vec3 attenuationColor, const in float attenuationDistance ) {\n vec3 transmissionRay = getVolumeTransmissionRay( n, v, thickness, ior, modelMatrix );\n vec3 refractedRayExit = position + transmissionRay;\n vec4 ndcPos = projMatrix * viewMatrix * vec4( refractedRayExit, 1.0 );\n vec2 refractionCoords = ndcPos.xy / ndcPos.w;\n refractionCoords += 1.0;\n refractionCoords /= 2.0;\n vec4 transmittedLight = getTransmissionSample( refractionCoords, roughness, ior );\n vec3 transmittance = diffuseColor * volumeAttenuation( length( transmissionRay ), attenuationColor, attenuationDistance );\n vec3 attenuatedColor = transmittance * transmittedLight.rgb;\n vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );\n float transmittanceFactor = ( transmittance.r + transmittance.g + transmittance.b ) / 3.0;\n return vec4( ( 1.0 - F ) * attenuatedColor, 1.0 - ( 1.0 - transmittedLight.a ) * transmittanceFactor );\n }\n#endif"; var uv_pars_fragment2 = "#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n varying vec2 vUv;\n#endif\n#ifdef USE_MAP\n varying vec2 vMapUv;\n#endif\n#ifdef USE_ALPHAMAP\n varying vec2 vAlphaMapUv;\n#endif\n#ifdef USE_LIGHTMAP\n varying vec2 vLightMapUv;\n#endif\n#ifdef USE_AOMAP\n varying vec2 vAoMapUv;\n#endif\n#ifdef USE_BUMPMAP\n varying vec2 vBumpMapUv;\n#endif\n#ifdef USE_NORMALMAP\n varying vec2 vNormalMapUv;\n#endif\n#ifdef USE_EMISSIVEMAP\n varying vec2 vEmissiveMapUv;\n#endif\n#ifdef USE_METALNESSMAP\n varying vec2 vMetalnessMapUv;\n#endif\n#ifdef USE_ROUGHNESSMAP\n varying vec2 vRoughnessMapUv;\n#endif\n#ifdef USE_ANISOTROPYMAP\n varying vec2 vAnisotropyMapUv;\n#endif\n#ifdef USE_CLEARCOATMAP\n varying vec2 vClearcoatMapUv;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n varying vec2 vClearcoatNormalMapUv;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n varying vec2 vClearcoatRoughnessMapUv;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n varying vec2 vIridescenceMapUv;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n varying vec2 vIridescenceThicknessMapUv;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n varying vec2 vSheenColorMapUv;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n varying vec2 vSheenRoughnessMapUv;\n#endif\n#ifdef USE_SPECULARMAP\n varying vec2 vSpecularMapUv;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n varying vec2 vSpecularColorMapUv;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n varying vec2 vSpecularIntensityMapUv;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n uniform mat3 transmissionMapTransform;\n varying vec2 vTransmissionMapUv;\n#endif\n#ifdef USE_THICKNESSMAP\n uniform mat3 thicknessMapTransform;\n varying vec2 vThicknessMapUv;\n#endif"; var uv_pars_vertex2 = "#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n varying vec2 vUv;\n#endif\n#ifdef USE_MAP\n uniform mat3 mapTransform;\n varying vec2 vMapUv;\n#endif\n#ifdef USE_ALPHAMAP\n uniform mat3 alphaMapTransform;\n varying vec2 vAlphaMapUv;\n#endif\n#ifdef USE_LIGHTMAP\n uniform mat3 lightMapTransform;\n varying vec2 vLightMapUv;\n#endif\n#ifdef USE_AOMAP\n uniform mat3 aoMapTransform;\n varying vec2 vAoMapUv;\n#endif\n#ifdef USE_BUMPMAP\n uniform mat3 bumpMapTransform;\n varying vec2 vBumpMapUv;\n#endif\n#ifdef USE_NORMALMAP\n uniform mat3 normalMapTransform;\n varying vec2 vNormalMapUv;\n#endif\n#ifdef USE_DISPLACEMENTMAP\n uniform mat3 displacementMapTransform;\n varying vec2 vDisplacementMapUv;\n#endif\n#ifdef USE_EMISSIVEMAP\n uniform mat3 emissiveMapTransform;\n varying vec2 vEmissiveMapUv;\n#endif\n#ifdef USE_METALNESSMAP\n uniform mat3 metalnessMapTransform;\n varying vec2 vMetalnessMapUv;\n#endif\n#ifdef USE_ROUGHNESSMAP\n uniform mat3 roughnessMapTransform;\n varying vec2 vRoughnessMapUv;\n#endif\n#ifdef USE_ANISOTROPYMAP\n uniform mat3 anisotropyMapTransform;\n varying vec2 vAnisotropyMapUv;\n#endif\n#ifdef USE_CLEARCOATMAP\n uniform mat3 clearcoatMapTransform;\n varying vec2 vClearcoatMapUv;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n uniform mat3 clearcoatNormalMapTransform;\n varying vec2 vClearcoatNormalMapUv;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n uniform mat3 clearcoatRoughnessMapTransform;\n varying vec2 vClearcoatRoughnessMapUv;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n uniform mat3 sheenColorMapTransform;\n varying vec2 vSheenColorMapUv;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n uniform mat3 sheenRoughnessMapTransform;\n varying vec2 vSheenRoughnessMapUv;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n uniform mat3 iridescenceMapTransform;\n varying vec2 vIridescenceMapUv;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n uniform mat3 iridescenceThicknessMapTransform;\n varying vec2 vIridescenceThicknessMapUv;\n#endif\n#ifdef USE_SPECULARMAP\n uniform mat3 specularMapTransform;\n varying vec2 vSpecularMapUv;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n uniform mat3 specularColorMapTransform;\n varying vec2 vSpecularColorMapUv;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n uniform mat3 specularIntensityMapTransform;\n varying vec2 vSpecularIntensityMapUv;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n uniform mat3 transmissionMapTransform;\n varying vec2 vTransmissionMapUv;\n#endif\n#ifdef USE_THICKNESSMAP\n uniform mat3 thicknessMapTransform;\n varying vec2 vThicknessMapUv;\n#endif"; var uv_vertex2 = "#if defined( USE_UV ) || defined( USE_ANISOTROPY )\n vUv = vec3( uv, 1 ).xy;\n#endif\n#ifdef USE_MAP\n vMapUv = ( mapTransform * vec3( MAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ALPHAMAP\n vAlphaMapUv = ( alphaMapTransform * vec3( ALPHAMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_LIGHTMAP\n vLightMapUv = ( lightMapTransform * vec3( LIGHTMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_AOMAP\n vAoMapUv = ( aoMapTransform * vec3( AOMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_BUMPMAP\n vBumpMapUv = ( bumpMapTransform * vec3( BUMPMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_NORMALMAP\n vNormalMapUv = ( normalMapTransform * vec3( NORMALMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_DISPLACEMENTMAP\n vDisplacementMapUv = ( displacementMapTransform * vec3( DISPLACEMENTMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_EMISSIVEMAP\n vEmissiveMapUv = ( emissiveMapTransform * vec3( EMISSIVEMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_METALNESSMAP\n vMetalnessMapUv = ( metalnessMapTransform * vec3( METALNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ROUGHNESSMAP\n vRoughnessMapUv = ( roughnessMapTransform * vec3( ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_ANISOTROPYMAP\n vAnisotropyMapUv = ( anisotropyMapTransform * vec3( ANISOTROPYMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOATMAP\n vClearcoatMapUv = ( clearcoatMapTransform * vec3( CLEARCOATMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n vClearcoatNormalMapUv = ( clearcoatNormalMapTransform * vec3( CLEARCOAT_NORMALMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n vClearcoatRoughnessMapUv = ( clearcoatRoughnessMapTransform * vec3( CLEARCOAT_ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_IRIDESCENCEMAP\n vIridescenceMapUv = ( iridescenceMapTransform * vec3( IRIDESCENCEMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_IRIDESCENCE_THICKNESSMAP\n vIridescenceThicknessMapUv = ( iridescenceThicknessMapTransform * vec3( IRIDESCENCE_THICKNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SHEEN_COLORMAP\n vSheenColorMapUv = ( sheenColorMapTransform * vec3( SHEEN_COLORMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SHEEN_ROUGHNESSMAP\n vSheenRoughnessMapUv = ( sheenRoughnessMapTransform * vec3( SHEEN_ROUGHNESSMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULARMAP\n vSpecularMapUv = ( specularMapTransform * vec3( SPECULARMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULAR_COLORMAP\n vSpecularColorMapUv = ( specularColorMapTransform * vec3( SPECULAR_COLORMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_SPECULAR_INTENSITYMAP\n vSpecularIntensityMapUv = ( specularIntensityMapTransform * vec3( SPECULAR_INTENSITYMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_TRANSMISSIONMAP\n vTransmissionMapUv = ( transmissionMapTransform * vec3( TRANSMISSIONMAP_UV, 1 ) ).xy;\n#endif\n#ifdef USE_THICKNESSMAP\n vThicknessMapUv = ( thicknessMapTransform * vec3( THICKNESSMAP_UV, 1 ) ).xy;\n#endif"; var worldpos_vertex2 = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION ) || NUM_SPOT_LIGHT_COORDS > 0\n vec4 worldPosition = vec4( transformed, 1.0 );\n #ifdef USE_INSTANCING\n worldPosition = instanceMatrix * worldPosition;\n #endif\n worldPosition = modelMatrix * worldPosition;\n#endif"; var vertex$h2 = "varying vec2 vUv;\nuniform mat3 uvTransform;\nvoid main() {\n vUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n gl_Position = vec4( position.xy, 1.0, 1.0 );\n}"; var fragment$h2 = "uniform sampler2D t2D;\nuniform float backgroundIntensity;\nvarying vec2 vUv;\nvoid main() {\n vec4 texColor = texture2D( t2D, vUv );\n #ifdef DECODE_VIDEO_TEXTURE\n texColor = vec4( mix( pow( texColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), texColor.rgb * 0.0773993808, vec3( lessThanEqual( texColor.rgb, vec3( 0.04045 ) ) ) ), texColor.w );\n #endif\n texColor.rgb *= backgroundIntensity;\n gl_FragColor = texColor;\n #include \n #include \n}"; var vertex$g2 = "varying vec3 vWorldDirection;\n#include \nvoid main() {\n vWorldDirection = transformDirection( position, modelMatrix );\n #include \n #include \n gl_Position.z = gl_Position.w;\n}"; var fragment$g2 = "#ifdef ENVMAP_TYPE_CUBE\n uniform samplerCube envMap;\n#elif defined( ENVMAP_TYPE_CUBE_UV )\n uniform sampler2D envMap;\n#endif\nuniform float flipEnvMap;\nuniform float backgroundBlurriness;\nuniform float backgroundIntensity;\nvarying vec3 vWorldDirection;\n#include \nvoid main() {\n #ifdef ENVMAP_TYPE_CUBE\n vec4 texColor = textureCube( envMap, vec3( flipEnvMap * vWorldDirection.x, vWorldDirection.yz ) );\n #elif defined( ENVMAP_TYPE_CUBE_UV )\n vec4 texColor = textureCubeUV( envMap, vWorldDirection, backgroundBlurriness );\n #else\n vec4 texColor = vec4( 0.0, 0.0, 0.0, 1.0 );\n #endif\n texColor.rgb *= backgroundIntensity;\n gl_FragColor = texColor;\n #include \n #include \n}"; var vertex$f2 = "varying vec3 vWorldDirection;\n#include \nvoid main() {\n vWorldDirection = transformDirection( position, modelMatrix );\n #include \n #include \n gl_Position.z = gl_Position.w;\n}"; var fragment$f2 = "uniform samplerCube tCube;\nuniform float tFlip;\nuniform float opacity;\nvarying vec3 vWorldDirection;\nvoid main() {\n vec4 texColor = textureCube( tCube, vec3( tFlip * vWorldDirection.x, vWorldDirection.yz ) );\n gl_FragColor = texColor;\n gl_FragColor.a *= opacity;\n #include \n #include \n}"; var vertex$e2 = "#include \n#include \n#include \n#include \n#include \n#include \n#include \nvarying vec2 vHighPrecisionZW;\nvoid main() {\n #include \n #include \n #ifdef USE_DISPLACEMENTMAP\n #include \n #include \n #include \n #endif\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n vHighPrecisionZW = gl_Position.zw;\n}"; var fragment$e2 = "#if DEPTH_PACKING == 3200\n uniform float opacity;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvarying vec2 vHighPrecisionZW;\nvoid main() {\n #include \n vec4 diffuseColor = vec4( 1.0 );\n #if DEPTH_PACKING == 3200\n diffuseColor.a = opacity;\n #endif\n #include \n #include \n #include \n #include \n #include \n float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;\n #if DEPTH_PACKING == 3200\n gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );\n #elif DEPTH_PACKING == 3201\n gl_FragColor = packDepthToRGBA( fragCoordZ );\n #endif\n}"; var vertex$d2 = "#define DISTANCE\nvarying vec3 vWorldPosition;\n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n #include \n #ifdef USE_DISPLACEMENTMAP\n #include \n #include \n #include \n #endif\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n vWorldPosition = worldPosition.xyz;\n}"; var fragment$d2 = "#define DISTANCE\nuniform vec3 referencePosition;\nuniform float nearDistance;\nuniform float farDistance;\nvarying vec3 vWorldPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main () {\n #include \n vec4 diffuseColor = vec4( 1.0 );\n #include \n #include \n #include \n #include \n float dist = length( vWorldPosition - referencePosition );\n dist = ( dist - nearDistance ) / ( farDistance - nearDistance );\n dist = saturate( dist );\n gl_FragColor = packDepthToRGBA( dist );\n}"; var vertex$c2 = "varying vec3 vWorldDirection;\n#include \nvoid main() {\n vWorldDirection = transformDirection( position, modelMatrix );\n #include \n #include \n}"; var fragment$c2 = "uniform sampler2D tEquirect;\nvarying vec3 vWorldDirection;\n#include \nvoid main() {\n vec3 direction = normalize( vWorldDirection );\n vec2 sampleUV = equirectUv( direction );\n gl_FragColor = texture2D( tEquirect, sampleUV );\n #include \n #include \n}"; var vertex$b2 = "uniform float scale;\nattribute float lineDistance;\nvarying float vLineDistance;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n vLineDistance = scale * lineDistance;\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n}"; var fragment$b2 = "uniform vec3 diffuse;\nuniform float opacity;\nuniform float dashSize;\nuniform float totalSize;\nvarying float vLineDistance;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n if ( mod( vLineDistance, totalSize ) > dashSize ) {\n discard;\n }\n vec3 outgoingLight = vec3( 0.0 );\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include \n #include \n #include \n outgoingLight = diffuseColor.rgb;\n #include \n #include \n #include \n #include \n #include \n}"; var vertex$a2 = "#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n #include \n #include \n #if defined ( USE_ENVMAP ) || defined ( USE_SKINNING )\n #include \n #include \n #include \n #include \n #include \n #endif\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n}"; var fragment$a2 = "uniform vec3 diffuse;\nuniform float opacity;\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n vec4 diffuseColor = vec4( diffuse, opacity );\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n #ifdef USE_LIGHTMAP\n vec4 lightMapTexel = texture2D( lightMap, vLightMapUv );\n reflectedLight.indirectDiffuse += lightMapTexel.rgb * lightMapIntensity * RECIPROCAL_PI;\n #else\n reflectedLight.indirectDiffuse += vec3( 1.0 );\n #endif\n #include \n reflectedLight.indirectDiffuse *= diffuseColor.rgb;\n vec3 outgoingLight = reflectedLight.indirectDiffuse;\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n}"; var vertex$92 = "#define LAMBERT\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n vViewPosition = - mvPosition.xyz;\n #include \n #include \n #include \n #include \n}"; var fragment$92 = "#define LAMBERT\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n vec4 diffuseColor = vec4( diffuse, opacity );\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n}"; var vertex$82 = "#define MATCAP\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n vViewPosition = - mvPosition.xyz;\n}"; var fragment$82 = "#define MATCAP\nuniform vec3 diffuse;\nuniform float opacity;\nuniform sampler2D matcap;\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n vec4 diffuseColor = vec4( diffuse, opacity );\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n vec3 viewDir = normalize( vViewPosition );\n vec3 x = normalize( vec3( viewDir.z, 0.0, - viewDir.x ) );\n vec3 y = cross( viewDir, x );\n vec2 uv = vec2( dot( x, normal ), dot( y, normal ) ) * 0.495 + 0.5;\n #ifdef USE_MATCAP\n vec4 matcapColor = texture2D( matcap, uv );\n #else\n vec4 matcapColor = vec4( vec3( mix( 0.2, 0.8, uv.y ) ), 1.0 );\n #endif\n vec3 outgoingLight = diffuseColor.rgb * matcapColor.rgb;\n #include \n #include \n #include \n #include \n #include \n #include \n}"; var vertex$72 = "#define NORMAL\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n varying vec3 vViewPosition;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n vViewPosition = - mvPosition.xyz;\n#endif\n}"; var fragment$72 = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP_TANGENTSPACE )\n varying vec3 vViewPosition;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n #include \n #include \n #include \n gl_FragColor = vec4( packNormalToRGB( normal ), opacity );\n #ifdef OPAQUE\n gl_FragColor.a = 1.0;\n #endif\n}"; var vertex$62 = "#define PHONG\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n vViewPosition = - mvPosition.xyz;\n #include \n #include \n #include \n #include \n}"; var fragment$62 = "#define PHONG\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform vec3 specular;\nuniform float shininess;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n vec4 diffuseColor = vec4( diffuse, opacity );\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveRadiance;\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n}"; var vertex$52 = "#define STANDARD\nvarying vec3 vViewPosition;\n#ifdef USE_TRANSMISSION\n varying vec3 vWorldPosition;\n#endif\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n vViewPosition = - mvPosition.xyz;\n #include \n #include \n #include \n#ifdef USE_TRANSMISSION\n vWorldPosition = worldPosition.xyz;\n#endif\n}"; var fragment$52 = "#define STANDARD\n#ifdef PHYSICAL\n #define IOR\n #define USE_SPECULAR\n#endif\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float roughness;\nuniform float metalness;\nuniform float opacity;\n#ifdef IOR\n uniform float ior;\n#endif\n#ifdef USE_SPECULAR\n uniform float specularIntensity;\n uniform vec3 specularColor;\n #ifdef USE_SPECULAR_COLORMAP\n uniform sampler2D specularColorMap;\n #endif\n #ifdef USE_SPECULAR_INTENSITYMAP\n uniform sampler2D specularIntensityMap;\n #endif\n#endif\n#ifdef USE_CLEARCOAT\n uniform float clearcoat;\n uniform float clearcoatRoughness;\n#endif\n#ifdef USE_IRIDESCENCE\n uniform float iridescence;\n uniform float iridescenceIOR;\n uniform float iridescenceThicknessMinimum;\n uniform float iridescenceThicknessMaximum;\n#endif\n#ifdef USE_SHEEN\n uniform vec3 sheenColor;\n uniform float sheenRoughness;\n #ifdef USE_SHEEN_COLORMAP\n uniform sampler2D sheenColorMap;\n #endif\n #ifdef USE_SHEEN_ROUGHNESSMAP\n uniform sampler2D sheenRoughnessMap;\n #endif\n#endif\n#ifdef USE_ANISOTROPY\n uniform vec2 anisotropyVector;\n #ifdef USE_ANISOTROPYMAP\n uniform sampler2D anisotropyMap;\n #endif\n#endif\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n vec4 diffuseColor = vec4( diffuse, opacity );\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n vec3 totalDiffuse = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse;\n vec3 totalSpecular = reflectedLight.directSpecular + reflectedLight.indirectSpecular;\n #include \n vec3 outgoingLight = totalDiffuse + totalSpecular + totalEmissiveRadiance;\n #ifdef USE_SHEEN\n float sheenEnergyComp = 1.0 - 0.157 * max3( material.sheenColor );\n outgoingLight = outgoingLight * sheenEnergyComp + sheenSpecular;\n #endif\n #ifdef USE_CLEARCOAT\n float dotNVcc = saturate( dot( geometryClearcoatNormal, geometryViewDir ) );\n vec3 Fcc = F_Schlick( material.clearcoatF0, material.clearcoatF90, dotNVcc );\n outgoingLight = outgoingLight * ( 1.0 - material.clearcoat * Fcc ) + clearcoatSpecular * material.clearcoat;\n #endif\n #include \n #include \n #include \n #include \n #include \n #include \n}"; var vertex$42 = "#define TOON\nvarying vec3 vViewPosition;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n vViewPosition = - mvPosition.xyz;\n #include \n #include \n #include \n}"; var fragment$42 = "#define TOON\nuniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n vec4 diffuseColor = vec4( diffuse, opacity );\n ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n vec3 totalEmissiveRadiance = emissive;\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveRadiance;\n #include \n #include \n #include \n #include \n #include \n #include \n}"; var vertex$32 = "uniform float size;\nuniform float scale;\n#include \n#include \n#include \n#include \n#include \n#include \n#ifdef USE_POINTS_UV\n varying vec2 vUv;\n uniform mat3 uvTransform;\n#endif\nvoid main() {\n #ifdef USE_POINTS_UV\n vUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n #endif\n #include \n #include \n #include \n #include \n #include \n gl_PointSize = size;\n #ifdef USE_SIZEATTENUATION\n bool isPerspective = isPerspectiveMatrix( projectionMatrix );\n if ( isPerspective ) gl_PointSize *= ( scale / - mvPosition.z );\n #endif\n #include \n #include \n #include \n #include \n}"; var fragment$32 = "uniform vec3 diffuse;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n vec3 outgoingLight = vec3( 0.0 );\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include \n #include \n #include \n #include \n #include \n outgoingLight = diffuseColor.rgb;\n #include \n #include \n #include \n #include \n #include \n}"; var vertex$22 = "#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n #include \n}"; var fragment$22 = "uniform vec3 color;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n gl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n #include \n #include \n #include \n}"; var vertex$12 = "uniform float rotation;\nuniform vec2 center;\n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n vec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n vec2 scale;\n scale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n scale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n #ifndef USE_SIZEATTENUATION\n bool isPerspective = isPerspectiveMatrix( projectionMatrix );\n if ( isPerspective ) scale *= - mvPosition.z;\n #endif\n vec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n vec2 rotatedPosition;\n rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n mvPosition.xy += rotatedPosition;\n gl_Position = projectionMatrix * mvPosition;\n #include \n #include \n #include \n}"; var fragment$12 = "uniform vec3 diffuse;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\n #include \n vec3 outgoingLight = vec3( 0.0 );\n vec4 diffuseColor = vec4( diffuse, opacity );\n #include \n #include \n #include \n #include \n #include \n outgoingLight = diffuseColor.rgb;\n #include \n #include \n #include \n #include \n}"; var ShaderChunk2 = { alphahash_fragment: alphahash_fragment2, alphahash_pars_fragment: alphahash_pars_fragment2, alphamap_fragment: alphamap_fragment2, alphamap_pars_fragment: alphamap_pars_fragment2, alphatest_fragment: alphatest_fragment2, alphatest_pars_fragment: alphatest_pars_fragment2, aomap_fragment: aomap_fragment2, aomap_pars_fragment: aomap_pars_fragment2, begin_vertex: begin_vertex2, beginnormal_vertex: beginnormal_vertex2, bsdfs: bsdfs2, iridescence_fragment: iridescence_fragment2, bumpmap_pars_fragment: bumpmap_pars_fragment2, clipping_planes_fragment: clipping_planes_fragment2, clipping_planes_pars_fragment: clipping_planes_pars_fragment2, clipping_planes_pars_vertex: clipping_planes_pars_vertex2, clipping_planes_vertex: clipping_planes_vertex2, color_fragment: color_fragment2, color_pars_fragment: color_pars_fragment2, color_pars_vertex: color_pars_vertex2, color_vertex: color_vertex2, common: common2, cube_uv_reflection_fragment: cube_uv_reflection_fragment2, defaultnormal_vertex: defaultnormal_vertex2, displacementmap_pars_vertex: displacementmap_pars_vertex2, displacementmap_vertex: displacementmap_vertex2, emissivemap_fragment: emissivemap_fragment2, emissivemap_pars_fragment: emissivemap_pars_fragment2, colorspace_fragment: colorspace_fragment2, colorspace_pars_fragment: colorspace_pars_fragment2, envmap_fragment: envmap_fragment2, envmap_common_pars_fragment: envmap_common_pars_fragment2, envmap_pars_fragment: envmap_pars_fragment2, envmap_pars_vertex: envmap_pars_vertex2, envmap_physical_pars_fragment: envmap_physical_pars_fragment2, envmap_vertex: envmap_vertex2, fog_vertex: fog_vertex2, fog_pars_vertex: fog_pars_vertex2, fog_fragment: fog_fragment2, fog_pars_fragment: fog_pars_fragment2, gradientmap_pars_fragment: gradientmap_pars_fragment2, lightmap_fragment: lightmap_fragment2, lightmap_pars_fragment: lightmap_pars_fragment2, lights_lambert_fragment: lights_lambert_fragment2, lights_lambert_pars_fragment: lights_lambert_pars_fragment2, lights_pars_begin: lights_pars_begin2, lights_toon_fragment: lights_toon_fragment2, lights_toon_pars_fragment: lights_toon_pars_fragment2, lights_phong_fragment: lights_phong_fragment2, lights_phong_pars_fragment: lights_phong_pars_fragment2, lights_physical_fragment: lights_physical_fragment2, lights_physical_pars_fragment: lights_physical_pars_fragment2, lights_fragment_begin: lights_fragment_begin2, lights_fragment_maps: lights_fragment_maps2, lights_fragment_end: lights_fragment_end2, logdepthbuf_fragment: logdepthbuf_fragment2, logdepthbuf_pars_fragment: logdepthbuf_pars_fragment2, logdepthbuf_pars_vertex: logdepthbuf_pars_vertex2, logdepthbuf_vertex: logdepthbuf_vertex2, map_fragment: map_fragment2, map_pars_fragment: map_pars_fragment2, map_particle_fragment: map_particle_fragment2, map_particle_pars_fragment: map_particle_pars_fragment2, metalnessmap_fragment: metalnessmap_fragment2, metalnessmap_pars_fragment: metalnessmap_pars_fragment2, morphcolor_vertex: morphcolor_vertex2, morphnormal_vertex: morphnormal_vertex2, morphtarget_pars_vertex: morphtarget_pars_vertex2, morphtarget_vertex: morphtarget_vertex2, normal_fragment_begin: normal_fragment_begin2, normal_fragment_maps: normal_fragment_maps2, normal_pars_fragment: normal_pars_fragment2, normal_pars_vertex: normal_pars_vertex2, normal_vertex: normal_vertex2, normalmap_pars_fragment: normalmap_pars_fragment2, clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin2, clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps2, clearcoat_pars_fragment: clearcoat_pars_fragment2, iridescence_pars_fragment: iridescence_pars_fragment2, opaque_fragment: opaque_fragment2, packing: packing2, premultiplied_alpha_fragment: premultiplied_alpha_fragment2, project_vertex: project_vertex2, dithering_fragment: dithering_fragment2, dithering_pars_fragment: dithering_pars_fragment2, roughnessmap_fragment: roughnessmap_fragment2, roughnessmap_pars_fragment: roughnessmap_pars_fragment2, shadowmap_pars_fragment: shadowmap_pars_fragment2, shadowmap_pars_vertex: shadowmap_pars_vertex2, shadowmap_vertex: shadowmap_vertex2, shadowmask_pars_fragment: shadowmask_pars_fragment2, skinbase_vertex: skinbase_vertex2, skinning_pars_vertex: skinning_pars_vertex2, skinning_vertex: skinning_vertex2, skinnormal_vertex: skinnormal_vertex2, specularmap_fragment: specularmap_fragment2, specularmap_pars_fragment: specularmap_pars_fragment2, tonemapping_fragment: tonemapping_fragment2, tonemapping_pars_fragment: tonemapping_pars_fragment2, transmission_fragment: transmission_fragment2, transmission_pars_fragment: transmission_pars_fragment2, uv_pars_fragment: uv_pars_fragment2, uv_pars_vertex: uv_pars_vertex2, uv_vertex: uv_vertex2, worldpos_vertex: worldpos_vertex2, background_vert: vertex$h2, background_frag: fragment$h2, backgroundCube_vert: vertex$g2, backgroundCube_frag: fragment$g2, cube_vert: vertex$f2, cube_frag: fragment$f2, depth_vert: vertex$e2, depth_frag: fragment$e2, distanceRGBA_vert: vertex$d2, distanceRGBA_frag: fragment$d2, equirect_vert: vertex$c2, equirect_frag: fragment$c2, linedashed_vert: vertex$b2, linedashed_frag: fragment$b2, meshbasic_vert: vertex$a2, meshbasic_frag: fragment$a2, meshlambert_vert: vertex$92, meshlambert_frag: fragment$92, meshmatcap_vert: vertex$82, meshmatcap_frag: fragment$82, meshnormal_vert: vertex$72, meshnormal_frag: fragment$72, meshphong_vert: vertex$62, meshphong_frag: fragment$62, meshphysical_vert: vertex$52, meshphysical_frag: fragment$52, meshtoon_vert: vertex$42, meshtoon_frag: fragment$42, points_vert: vertex$32, points_frag: fragment$32, shadow_vert: vertex$22, shadow_frag: fragment$22, sprite_vert: vertex$12, sprite_frag: fragment$12 }; var UniformsLib2 = { common: { diffuse: { value: /* @__PURE__ */ new Color2(16777215) }, opacity: { value: 1 }, map: { value: null }, mapTransform: { value: /* @__PURE__ */ new Matrix32() }, alphaMap: { value: null }, alphaMapTransform: { value: /* @__PURE__ */ new Matrix32() }, alphaTest: { value: 0 } }, specularmap: { specularMap: { value: null }, specularMapTransform: { value: /* @__PURE__ */ new Matrix32() } }, envmap: { envMap: { value: null }, flipEnvMap: { value: -1 }, reflectivity: { value: 1 }, // basic, lambert, phong ior: { value: 1.5 }, // physical refractionRatio: { value: 0.98 } // basic, lambert, phong }, aomap: { aoMap: { value: null }, aoMapIntensity: { value: 1 }, aoMapTransform: { value: /* @__PURE__ */ new Matrix32() } }, lightmap: { lightMap: { value: null }, lightMapIntensity: { value: 1 }, lightMapTransform: { value: /* @__PURE__ */ new Matrix32() } }, bumpmap: { bumpMap: { value: null }, bumpMapTransform: { value: /* @__PURE__ */ new Matrix32() }, bumpScale: { value: 1 } }, normalmap: { normalMap: { value: null }, normalMapTransform: { value: /* @__PURE__ */ new Matrix32() }, normalScale: { value: /* @__PURE__ */ new Vector22(1, 1) } }, displacementmap: { displacementMap: { value: null }, displacementMapTransform: { value: /* @__PURE__ */ new Matrix32() }, displacementScale: { value: 1 }, displacementBias: { value: 0 } }, emissivemap: { emissiveMap: { value: null }, emissiveMapTransform: { value: /* @__PURE__ */ new Matrix32() } }, metalnessmap: { metalnessMap: { value: null }, metalnessMapTransform: { value: /* @__PURE__ */ new Matrix32() } }, roughnessmap: { roughnessMap: { value: null }, roughnessMapTransform: { value: /* @__PURE__ */ new Matrix32() } }, gradientmap: { gradientMap: { value: null } }, fog: { fogDensity: { value: 25e-5 }, fogNear: { value: 1 }, fogFar: { value: 2e3 }, fogColor: { value: /* @__PURE__ */ new Color2(16777215) } }, lights: { ambientLightColor: { value: [] }, lightProbe: { value: [] }, directionalLights: { value: [], properties: { direction: {}, color: {} } }, directionalLightShadows: { value: [], properties: { shadowBias: {}, shadowNormalBias: {}, shadowRadius: {}, shadowMapSize: {} } }, directionalShadowMap: { value: [] }, directionalShadowMatrix: { value: [] }, spotLights: { value: [], properties: { color: {}, position: {}, direction: {}, distance: {}, coneCos: {}, penumbraCos: {}, decay: {} } }, spotLightShadows: { value: [], properties: { shadowBias: {}, shadowNormalBias: {}, shadowRadius: {}, shadowMapSize: {} } }, spotLightMap: { value: [] }, spotShadowMap: { value: [] }, spotLightMatrix: { value: [] }, pointLights: { value: [], properties: { color: {}, position: {}, decay: {}, distance: {} } }, pointLightShadows: { value: [], properties: { shadowBias: {}, shadowNormalBias: {}, shadowRadius: {}, shadowMapSize: {}, shadowCameraNear: {}, shadowCameraFar: {} } }, pointShadowMap: { value: [] }, pointShadowMatrix: { value: [] }, hemisphereLights: { value: [], properties: { direction: {}, skyColor: {}, groundColor: {} } }, // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src rectAreaLights: { value: [], properties: { color: {}, position: {}, width: {}, height: {} } }, ltc_1: { value: null }, ltc_2: { value: null } }, points: { diffuse: { value: /* @__PURE__ */ new Color2(16777215) }, opacity: { value: 1 }, size: { value: 1 }, scale: { value: 1 }, map: { value: null }, alphaMap: { value: null }, alphaMapTransform: { value: /* @__PURE__ */ new Matrix32() }, alphaTest: { value: 0 }, uvTransform: { value: /* @__PURE__ */ new Matrix32() } }, sprite: { diffuse: { value: /* @__PURE__ */ new Color2(16777215) }, opacity: { value: 1 }, center: { value: /* @__PURE__ */ new Vector22(0.5, 0.5) }, rotation: { value: 0 }, map: { value: null }, mapTransform: { value: /* @__PURE__ */ new Matrix32() }, alphaMap: { value: null }, alphaMapTransform: { value: /* @__PURE__ */ new Matrix32() }, alphaTest: { value: 0 } } }; var ShaderLib2 = { basic: { uniforms: /* @__PURE__ */ mergeUniforms2([ UniformsLib2.common, UniformsLib2.specularmap, UniformsLib2.envmap, UniformsLib2.aomap, UniformsLib2.lightmap, UniformsLib2.fog ]), vertexShader: ShaderChunk2.meshbasic_vert, fragmentShader: ShaderChunk2.meshbasic_frag }, lambert: { uniforms: /* @__PURE__ */ mergeUniforms2([ UniformsLib2.common, UniformsLib2.specularmap, UniformsLib2.envmap, UniformsLib2.aomap, UniformsLib2.lightmap, UniformsLib2.emissivemap, UniformsLib2.bumpmap, UniformsLib2.normalmap, UniformsLib2.displacementmap, UniformsLib2.fog, UniformsLib2.lights, { emissive: { value: /* @__PURE__ */ new Color2(0) } } ]), vertexShader: ShaderChunk2.meshlambert_vert, fragmentShader: ShaderChunk2.meshlambert_frag }, phong: { uniforms: /* @__PURE__ */ mergeUniforms2([ UniformsLib2.common, UniformsLib2.specularmap, UniformsLib2.envmap, UniformsLib2.aomap, UniformsLib2.lightmap, UniformsLib2.emissivemap, UniformsLib2.bumpmap, UniformsLib2.normalmap, UniformsLib2.displacementmap, UniformsLib2.fog, UniformsLib2.lights, { emissive: { value: /* @__PURE__ */ new Color2(0) }, specular: { value: /* @__PURE__ */ new Color2(1118481) }, shininess: { value: 30 } } ]), vertexShader: ShaderChunk2.meshphong_vert, fragmentShader: ShaderChunk2.meshphong_frag }, standard: { uniforms: /* @__PURE__ */ mergeUniforms2([ UniformsLib2.common, UniformsLib2.envmap, UniformsLib2.aomap, UniformsLib2.lightmap, UniformsLib2.emissivemap, UniformsLib2.bumpmap, UniformsLib2.normalmap, UniformsLib2.displacementmap, UniformsLib2.roughnessmap, UniformsLib2.metalnessmap, UniformsLib2.fog, UniformsLib2.lights, { emissive: { value: /* @__PURE__ */ new Color2(0) }, roughness: { value: 1 }, metalness: { value: 0 }, envMapIntensity: { value: 1 } // temporary } ]), vertexShader: ShaderChunk2.meshphysical_vert, fragmentShader: ShaderChunk2.meshphysical_frag }, toon: { uniforms: /* @__PURE__ */ mergeUniforms2([ UniformsLib2.common, UniformsLib2.aomap, UniformsLib2.lightmap, UniformsLib2.emissivemap, UniformsLib2.bumpmap, UniformsLib2.normalmap, UniformsLib2.displacementmap, UniformsLib2.gradientmap, UniformsLib2.fog, UniformsLib2.lights, { emissive: { value: /* @__PURE__ */ new Color2(0) } } ]), vertexShader: ShaderChunk2.meshtoon_vert, fragmentShader: ShaderChunk2.meshtoon_frag }, matcap: { uniforms: /* @__PURE__ */ mergeUniforms2([ UniformsLib2.common, UniformsLib2.bumpmap, UniformsLib2.normalmap, UniformsLib2.displacementmap, UniformsLib2.fog, { matcap: { value: null } } ]), vertexShader: ShaderChunk2.meshmatcap_vert, fragmentShader: ShaderChunk2.meshmatcap_frag }, points: { uniforms: /* @__PURE__ */ mergeUniforms2([ UniformsLib2.points, UniformsLib2.fog ]), vertexShader: ShaderChunk2.points_vert, fragmentShader: ShaderChunk2.points_frag }, dashed: { uniforms: /* @__PURE__ */ mergeUniforms2([ UniformsLib2.common, UniformsLib2.fog, { scale: { value: 1 }, dashSize: { value: 1 }, totalSize: { value: 2 } } ]), vertexShader: ShaderChunk2.linedashed_vert, fragmentShader: ShaderChunk2.linedashed_frag }, depth: { uniforms: /* @__PURE__ */ mergeUniforms2([ UniformsLib2.common, UniformsLib2.displacementmap ]), vertexShader: ShaderChunk2.depth_vert, fragmentShader: ShaderChunk2.depth_frag }, normal: { uniforms: /* @__PURE__ */ mergeUniforms2([ UniformsLib2.common, UniformsLib2.bumpmap, UniformsLib2.normalmap, UniformsLib2.displacementmap, { opacity: { value: 1 } } ]), vertexShader: ShaderChunk2.meshnormal_vert, fragmentShader: ShaderChunk2.meshnormal_frag }, sprite: { uniforms: /* @__PURE__ */ mergeUniforms2([ UniformsLib2.sprite, UniformsLib2.fog ]), vertexShader: ShaderChunk2.sprite_vert, fragmentShader: ShaderChunk2.sprite_frag }, background: { uniforms: { uvTransform: { value: /* @__PURE__ */ new Matrix32() }, t2D: { value: null }, backgroundIntensity: { value: 1 } }, vertexShader: ShaderChunk2.background_vert, fragmentShader: ShaderChunk2.background_frag }, backgroundCube: { uniforms: { envMap: { value: null }, flipEnvMap: { value: -1 }, backgroundBlurriness: { value: 0 }, backgroundIntensity: { value: 1 } }, vertexShader: ShaderChunk2.backgroundCube_vert, fragmentShader: ShaderChunk2.backgroundCube_frag }, cube: { uniforms: { tCube: { value: null }, tFlip: { value: -1 }, opacity: { value: 1 } }, vertexShader: ShaderChunk2.cube_vert, fragmentShader: ShaderChunk2.cube_frag }, equirect: { uniforms: { tEquirect: { value: null } }, vertexShader: ShaderChunk2.equirect_vert, fragmentShader: ShaderChunk2.equirect_frag }, distanceRGBA: { uniforms: /* @__PURE__ */ mergeUniforms2([ UniformsLib2.common, UniformsLib2.displacementmap, { referencePosition: { value: /* @__PURE__ */ new Vector32() }, nearDistance: { value: 1 }, farDistance: { value: 1e3 } } ]), vertexShader: ShaderChunk2.distanceRGBA_vert, fragmentShader: ShaderChunk2.distanceRGBA_frag }, shadow: { uniforms: /* @__PURE__ */ mergeUniforms2([ UniformsLib2.lights, UniformsLib2.fog, { color: { value: /* @__PURE__ */ new Color2(0) }, opacity: { value: 1 } } ]), vertexShader: ShaderChunk2.shadow_vert, fragmentShader: ShaderChunk2.shadow_frag } }; ShaderLib2.physical = { uniforms: /* @__PURE__ */ mergeUniforms2([ ShaderLib2.standard.uniforms, { clearcoat: { value: 0 }, clearcoatMap: { value: null }, clearcoatMapTransform: { value: /* @__PURE__ */ new Matrix32() }, clearcoatNormalMap: { value: null }, clearcoatNormalMapTransform: { value: /* @__PURE__ */ new Matrix32() }, clearcoatNormalScale: { value: /* @__PURE__ */ new Vector22(1, 1) }, clearcoatRoughness: { value: 0 }, clearcoatRoughnessMap: { value: null }, clearcoatRoughnessMapTransform: { value: /* @__PURE__ */ new Matrix32() }, iridescence: { value: 0 }, iridescenceMap: { value: null }, iridescenceMapTransform: { value: /* @__PURE__ */ new Matrix32() }, iridescenceIOR: { value: 1.3 }, iridescenceThicknessMinimum: { value: 100 }, iridescenceThicknessMaximum: { value: 400 }, iridescenceThicknessMap: { value: null }, iridescenceThicknessMapTransform: { value: /* @__PURE__ */ new Matrix32() }, sheen: { value: 0 }, sheenColor: { value: /* @__PURE__ */ new Color2(0) }, sheenColorMap: { value: null }, sheenColorMapTransform: { value: /* @__PURE__ */ new Matrix32() }, sheenRoughness: { value: 1 }, sheenRoughnessMap: { value: null }, sheenRoughnessMapTransform: { value: /* @__PURE__ */ new Matrix32() }, transmission: { value: 0 }, transmissionMap: { value: null }, transmissionMapTransform: { value: /* @__PURE__ */ new Matrix32() }, transmissionSamplerSize: { value: /* @__PURE__ */ new Vector22() }, transmissionSamplerMap: { value: null }, thickness: { value: 0 }, thicknessMap: { value: null }, thicknessMapTransform: { value: /* @__PURE__ */ new Matrix32() }, attenuationDistance: { value: 0 }, attenuationColor: { value: /* @__PURE__ */ new Color2(0) }, specularColor: { value: /* @__PURE__ */ new Color2(1, 1, 1) }, specularColorMap: { value: null }, specularColorMapTransform: { value: /* @__PURE__ */ new Matrix32() }, specularIntensity: { value: 1 }, specularIntensityMap: { value: null }, specularIntensityMapTransform: { value: /* @__PURE__ */ new Matrix32() }, anisotropyVector: { value: /* @__PURE__ */ new Vector22() }, anisotropyMap: { value: null }, anisotropyMapTransform: { value: /* @__PURE__ */ new Matrix32() } } ]), vertexShader: ShaderChunk2.meshphysical_vert, fragmentShader: ShaderChunk2.meshphysical_frag }; var _rgb2 = { r: 0, b: 0, g: 0 }; function WebGLBackground2(renderer3, cubemaps, cubeuvmaps, state, objects, alpha, premultipliedAlpha) { const clearColor = new Color2(0); let clearAlpha = alpha === true ? 0 : 1; let planeMesh; let boxMesh; let currentBackground = null; let currentBackgroundVersion = 0; let currentTonemapping = null; function render(renderList, scene3) { let forceClear = false; let background = scene3.isScene === true ? scene3.background : null; if (background && background.isTexture) { const usePMREM = scene3.backgroundBlurriness > 0; background = (usePMREM ? cubeuvmaps : cubemaps).get(background); } if (background === null) { setClear(clearColor, clearAlpha); } else if (background && background.isColor) { setClear(background, 1); forceClear = true; } const environmentBlendMode = renderer3.xr.getEnvironmentBlendMode(); if (environmentBlendMode === "additive") { state.buffers.color.setClear(0, 0, 0, 1, premultipliedAlpha); } else if (environmentBlendMode === "alpha-blend") { state.buffers.color.setClear(0, 0, 0, 0, premultipliedAlpha); } if (renderer3.autoClear || forceClear) { renderer3.clear(renderer3.autoClearColor, renderer3.autoClearDepth, renderer3.autoClearStencil); } if (background && (background.isCubeTexture || background.mapping === CubeUVReflectionMapping2)) { if (boxMesh === void 0) { boxMesh = new Mesh2( new BoxGeometry2(1, 1, 1), new ShaderMaterial2({ name: "BackgroundCubeMaterial", uniforms: cloneUniforms2(ShaderLib2.backgroundCube.uniforms), vertexShader: ShaderLib2.backgroundCube.vertexShader, fragmentShader: ShaderLib2.backgroundCube.fragmentShader, side: BackSide2, depthTest: false, depthWrite: false, fog: false }) ); boxMesh.geometry.deleteAttribute("normal"); boxMesh.geometry.deleteAttribute("uv"); boxMesh.onBeforeRender = function(renderer4, scene4, camera3) { this.matrixWorld.copyPosition(camera3.matrixWorld); }; Object.defineProperty(boxMesh.material, "envMap", { get: function() { return this.uniforms.envMap.value; } }); objects.update(boxMesh); } boxMesh.material.uniforms.envMap.value = background; boxMesh.material.uniforms.flipEnvMap.value = background.isCubeTexture && background.isRenderTargetTexture === false ? -1 : 1; boxMesh.material.uniforms.backgroundBlurriness.value = scene3.backgroundBlurriness; boxMesh.material.uniforms.backgroundIntensity.value = scene3.backgroundIntensity; boxMesh.material.toneMapped = ColorManagement2.getTransfer(background.colorSpace) !== SRGBTransfer2; if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer3.toneMapping) { boxMesh.material.needsUpdate = true; currentBackground = background; currentBackgroundVersion = background.version; currentTonemapping = renderer3.toneMapping; } boxMesh.layers.enableAll(); renderList.unshift(boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null); } else if (background && background.isTexture) { if (planeMesh === void 0) { planeMesh = new Mesh2( new PlaneGeometry2(2, 2), new ShaderMaterial2({ name: "BackgroundMaterial", uniforms: cloneUniforms2(ShaderLib2.background.uniforms), vertexShader: ShaderLib2.background.vertexShader, fragmentShader: ShaderLib2.background.fragmentShader, side: FrontSide2, depthTest: false, depthWrite: false, fog: false }) ); planeMesh.geometry.deleteAttribute("normal"); Object.defineProperty(planeMesh.material, "map", { get: function() { return this.uniforms.t2D.value; } }); objects.update(planeMesh); } planeMesh.material.uniforms.t2D.value = background; planeMesh.material.uniforms.backgroundIntensity.value = scene3.backgroundIntensity; planeMesh.material.toneMapped = ColorManagement2.getTransfer(background.colorSpace) !== SRGBTransfer2; if (background.matrixAutoUpdate === true) { background.updateMatrix(); } planeMesh.material.uniforms.uvTransform.value.copy(background.matrix); if (currentBackground !== background || currentBackgroundVersion !== background.version || currentTonemapping !== renderer3.toneMapping) { planeMesh.material.needsUpdate = true; currentBackground = background; currentBackgroundVersion = background.version; currentTonemapping = renderer3.toneMapping; } planeMesh.layers.enableAll(); renderList.unshift(planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null); } } function setClear(color, alpha2) { color.getRGB(_rgb2, getUnlitUniformColorSpace2(renderer3)); state.buffers.color.setClear(_rgb2.r, _rgb2.g, _rgb2.b, alpha2, premultipliedAlpha); } return { getClearColor: function() { return clearColor; }, setClearColor: function(color, alpha2 = 1) { clearColor.set(color); clearAlpha = alpha2; setClear(clearColor, clearAlpha); }, getClearAlpha: function() { return clearAlpha; }, setClearAlpha: function(alpha2) { clearAlpha = alpha2; setClear(clearColor, clearAlpha); }, render }; } function WebGLBindingStates2(gl, extensions, attributes, capabilities) { const maxVertexAttributes = gl.getParameter(gl.MAX_VERTEX_ATTRIBS); const extension = capabilities.isWebGL2 ? null : extensions.get("OES_vertex_array_object"); const vaoAvailable = capabilities.isWebGL2 || extension !== null; const bindingStates = {}; const defaultState = createBindingState(null); let currentState = defaultState; let forceUpdate = false; function setup(object, material, program, geometry, index6) { let updateBuffers = false; if (vaoAvailable) { const state = getBindingState(geometry, program, material); if (currentState !== state) { currentState = state; bindVertexArrayObject(currentState.object); } updateBuffers = needsUpdate(object, geometry, program, index6); if (updateBuffers) saveCache(object, geometry, program, index6); } else { const wireframe = material.wireframe === true; if (currentState.geometry !== geometry.id || currentState.program !== program.id || currentState.wireframe !== wireframe) { currentState.geometry = geometry.id; currentState.program = program.id; currentState.wireframe = wireframe; updateBuffers = true; } } if (index6 !== null) { attributes.update(index6, gl.ELEMENT_ARRAY_BUFFER); } if (updateBuffers || forceUpdate) { forceUpdate = false; setupVertexAttributes(object, material, program, geometry); if (index6 !== null) { gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, attributes.get(index6).buffer); } } } function createVertexArrayObject() { if (capabilities.isWebGL2) return gl.createVertexArray(); return extension.createVertexArrayOES(); } function bindVertexArrayObject(vao) { if (capabilities.isWebGL2) return gl.bindVertexArray(vao); return extension.bindVertexArrayOES(vao); } function deleteVertexArrayObject(vao) { if (capabilities.isWebGL2) return gl.deleteVertexArray(vao); return extension.deleteVertexArrayOES(vao); } function getBindingState(geometry, program, material) { const wireframe = material.wireframe === true; let programMap = bindingStates[geometry.id]; if (programMap === void 0) { programMap = {}; bindingStates[geometry.id] = programMap; } let stateMap = programMap[program.id]; if (stateMap === void 0) { stateMap = {}; programMap[program.id] = stateMap; } let state = stateMap[wireframe]; if (state === void 0) { state = createBindingState(createVertexArrayObject()); stateMap[wireframe] = state; } return state; } function createBindingState(vao) { const newAttributes = []; const enabledAttributes = []; const attributeDivisors = []; for (let i = 0; i < maxVertexAttributes; i++) { newAttributes[i] = 0; enabledAttributes[i] = 0; attributeDivisors[i] = 0; } return { // for backward compatibility on non-VAO support browser geometry: null, program: null, wireframe: false, newAttributes, enabledAttributes, attributeDivisors, object: vao, attributes: {}, index: null }; } function needsUpdate(object, geometry, program, index6) { const cachedAttributes = currentState.attributes; const geometryAttributes = geometry.attributes; let attributesNum = 0; const programAttributes = program.getAttributes(); for (const name in programAttributes) { const programAttribute = programAttributes[name]; if (programAttribute.location >= 0) { const cachedAttribute = cachedAttributes[name]; let geometryAttribute = geometryAttributes[name]; if (geometryAttribute === void 0) { if (name === "instanceMatrix" && object.instanceMatrix) geometryAttribute = object.instanceMatrix; if (name === "instanceColor" && object.instanceColor) geometryAttribute = object.instanceColor; } if (cachedAttribute === void 0) return true; if (cachedAttribute.attribute !== geometryAttribute) return true; if (geometryAttribute && cachedAttribute.data !== geometryAttribute.data) return true; attributesNum++; } } if (currentState.attributesNum !== attributesNum) return true; if (currentState.index !== index6) return true; return false; } function saveCache(object, geometry, program, index6) { const cache = {}; const attributes2 = geometry.attributes; let attributesNum = 0; const programAttributes = program.getAttributes(); for (const name in programAttributes) { const programAttribute = programAttributes[name]; if (programAttribute.location >= 0) { let attribute = attributes2[name]; if (attribute === void 0) { if (name === "instanceMatrix" && object.instanceMatrix) attribute = object.instanceMatrix; if (name === "instanceColor" && object.instanceColor) attribute = object.instanceColor; } const data = {}; data.attribute = attribute; if (attribute && attribute.data) { data.data = attribute.data; } cache[name] = data; attributesNum++; } } currentState.attributes = cache; currentState.attributesNum = attributesNum; currentState.index = index6; } function initAttributes() { const newAttributes = currentState.newAttributes; for (let i = 0, il = newAttributes.length; i < il; i++) { newAttributes[i] = 0; } } function enableAttribute(attribute) { enableAttributeAndDivisor(attribute, 0); } function enableAttributeAndDivisor(attribute, meshPerAttribute) { const newAttributes = currentState.newAttributes; const enabledAttributes = currentState.enabledAttributes; const attributeDivisors = currentState.attributeDivisors; newAttributes[attribute] = 1; if (enabledAttributes[attribute] === 0) { gl.enableVertexAttribArray(attribute); enabledAttributes[attribute] = 1; } if (attributeDivisors[attribute] !== meshPerAttribute) { const extension2 = capabilities.isWebGL2 ? gl : extensions.get("ANGLE_instanced_arrays"); extension2[capabilities.isWebGL2 ? "vertexAttribDivisor" : "vertexAttribDivisorANGLE"](attribute, meshPerAttribute); attributeDivisors[attribute] = meshPerAttribute; } } function disableUnusedAttributes() { const newAttributes = currentState.newAttributes; const enabledAttributes = currentState.enabledAttributes; for (let i = 0, il = enabledAttributes.length; i < il; i++) { if (enabledAttributes[i] !== newAttributes[i]) { gl.disableVertexAttribArray(i); enabledAttributes[i] = 0; } } } function vertexAttribPointer(index6, size, type, normalized, stride, offset, integer) { if (integer === true) { gl.vertexAttribIPointer(index6, size, type, stride, offset); } else { gl.vertexAttribPointer(index6, size, type, normalized, stride, offset); } } function setupVertexAttributes(object, material, program, geometry) { if (capabilities.isWebGL2 === false && (object.isInstancedMesh || geometry.isInstancedBufferGeometry)) { if (extensions.get("ANGLE_instanced_arrays") === null) return; } initAttributes(); const geometryAttributes = geometry.attributes; const programAttributes = program.getAttributes(); const materialDefaultAttributeValues = material.defaultAttributeValues; for (const name in programAttributes) { const programAttribute = programAttributes[name]; if (programAttribute.location >= 0) { let geometryAttribute = geometryAttributes[name]; if (geometryAttribute === void 0) { if (name === "instanceMatrix" && object.instanceMatrix) geometryAttribute = object.instanceMatrix; if (name === "instanceColor" && object.instanceColor) geometryAttribute = object.instanceColor; } if (geometryAttribute !== void 0) { const normalized = geometryAttribute.normalized; const size = geometryAttribute.itemSize; const attribute = attributes.get(geometryAttribute); if (attribute === void 0) continue; const buffer = attribute.buffer; const type = attribute.type; const bytesPerElement = attribute.bytesPerElement; const integer = capabilities.isWebGL2 === true && (type === gl.INT || type === gl.UNSIGNED_INT || geometryAttribute.gpuType === IntType2); if (geometryAttribute.isInterleavedBufferAttribute) { const data = geometryAttribute.data; const stride = data.stride; const offset = geometryAttribute.offset; if (data.isInstancedInterleavedBuffer) { for (let i = 0; i < programAttribute.locationSize; i++) { enableAttributeAndDivisor(programAttribute.location + i, data.meshPerAttribute); } if (object.isInstancedMesh !== true && geometry._maxInstanceCount === void 0) { geometry._maxInstanceCount = data.meshPerAttribute * data.count; } } else { for (let i = 0; i < programAttribute.locationSize; i++) { enableAttribute(programAttribute.location + i); } } gl.bindBuffer(gl.ARRAY_BUFFER, buffer); for (let i = 0; i < programAttribute.locationSize; i++) { vertexAttribPointer( programAttribute.location + i, size / programAttribute.locationSize, type, normalized, stride * bytesPerElement, (offset + size / programAttribute.locationSize * i) * bytesPerElement, integer ); } } else { if (geometryAttribute.isInstancedBufferAttribute) { for (let i = 0; i < programAttribute.locationSize; i++) { enableAttributeAndDivisor(programAttribute.location + i, geometryAttribute.meshPerAttribute); } if (object.isInstancedMesh !== true && geometry._maxInstanceCount === void 0) { geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count; } } else { for (let i = 0; i < programAttribute.locationSize; i++) { enableAttribute(programAttribute.location + i); } } gl.bindBuffer(gl.ARRAY_BUFFER, buffer); for (let i = 0; i < programAttribute.locationSize; i++) { vertexAttribPointer( programAttribute.location + i, size / programAttribute.locationSize, type, normalized, size * bytesPerElement, size / programAttribute.locationSize * i * bytesPerElement, integer ); } } } else if (materialDefaultAttributeValues !== void 0) { const value = materialDefaultAttributeValues[name]; if (value !== void 0) { switch (value.length) { case 2: gl.vertexAttrib2fv(programAttribute.location, value); break; case 3: gl.vertexAttrib3fv(programAttribute.location, value); break; case 4: gl.vertexAttrib4fv(programAttribute.location, value); break; default: gl.vertexAttrib1fv(programAttribute.location, value); } } } } } disableUnusedAttributes(); } function dispose() { reset(); for (const geometryId in bindingStates) { const programMap = bindingStates[geometryId]; for (const programId in programMap) { const stateMap = programMap[programId]; for (const wireframe in stateMap) { deleteVertexArrayObject(stateMap[wireframe].object); delete stateMap[wireframe]; } delete programMap[programId]; } delete bindingStates[geometryId]; } } function releaseStatesOfGeometry(geometry) { if (bindingStates[geometry.id] === void 0) return; const programMap = bindingStates[geometry.id]; for (const programId in programMap) { const stateMap = programMap[programId]; for (const wireframe in stateMap) { deleteVertexArrayObject(stateMap[wireframe].object); delete stateMap[wireframe]; } delete programMap[programId]; } delete bindingStates[geometry.id]; } function releaseStatesOfProgram(program) { for (const geometryId in bindingStates) { const programMap = bindingStates[geometryId]; if (programMap[program.id] === void 0) continue; const stateMap = programMap[program.id]; for (const wireframe in stateMap) { deleteVertexArrayObject(stateMap[wireframe].object); delete stateMap[wireframe]; } delete programMap[program.id]; } } function reset() { resetDefaultState(); forceUpdate = true; if (currentState === defaultState) return; currentState = defaultState; bindVertexArrayObject(currentState.object); } function resetDefaultState() { defaultState.geometry = null; defaultState.program = null; defaultState.wireframe = false; } return { setup, reset, resetDefaultState, dispose, releaseStatesOfGeometry, releaseStatesOfProgram, initAttributes, enableAttribute, disableUnusedAttributes }; } function WebGLBufferRenderer2(gl, extensions, info, capabilities) { const isWebGL2 = capabilities.isWebGL2; let mode; function setMode(value) { mode = value; } function render(start, count) { gl.drawArrays(mode, start, count); info.update(count, mode, 1); } function renderInstances(start, count, primcount) { if (primcount === 0) return; let extension, methodName; if (isWebGL2) { extension = gl; methodName = "drawArraysInstanced"; } else { extension = extensions.get("ANGLE_instanced_arrays"); methodName = "drawArraysInstancedANGLE"; if (extension === null) { console.error("THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays."); return; } } extension[methodName](mode, start, count, primcount); info.update(count, mode, primcount); } this.setMode = setMode; this.render = render; this.renderInstances = renderInstances; } function WebGLCapabilities2(gl, extensions, parameters) { let maxAnisotropy; function getMaxAnisotropy() { if (maxAnisotropy !== void 0) return maxAnisotropy; if (extensions.has("EXT_texture_filter_anisotropic") === true) { const extension = extensions.get("EXT_texture_filter_anisotropic"); maxAnisotropy = gl.getParameter(extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT); } else { maxAnisotropy = 0; } return maxAnisotropy; } function getMaxPrecision(precision2) { if (precision2 === "highp") { if (gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.HIGH_FLOAT).precision > 0 && gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT).precision > 0) { return "highp"; } precision2 = "mediump"; } if (precision2 === "mediump") { if (gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.MEDIUM_FLOAT).precision > 0 && gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT).precision > 0) { return "mediump"; } } return "lowp"; } const isWebGL2 = typeof WebGL2RenderingContext !== "undefined" && gl.constructor.name === "WebGL2RenderingContext"; let precision = parameters.precision !== void 0 ? parameters.precision : "highp"; const maxPrecision = getMaxPrecision(precision); if (maxPrecision !== precision) { console.warn("THREE.WebGLRenderer:", precision, "not supported, using", maxPrecision, "instead."); precision = maxPrecision; } const drawBuffers = isWebGL2 || extensions.has("WEBGL_draw_buffers"); const logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true; const maxTextures = gl.getParameter(gl.MAX_TEXTURE_IMAGE_UNITS); const maxVertexTextures = gl.getParameter(gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS); const maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE); const maxCubemapSize = gl.getParameter(gl.MAX_CUBE_MAP_TEXTURE_SIZE); const maxAttributes = gl.getParameter(gl.MAX_VERTEX_ATTRIBS); const maxVertexUniforms = gl.getParameter(gl.MAX_VERTEX_UNIFORM_VECTORS); const maxVaryings = gl.getParameter(gl.MAX_VARYING_VECTORS); const maxFragmentUniforms = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS); const vertexTextures = maxVertexTextures > 0; const floatFragmentTextures = isWebGL2 || extensions.has("OES_texture_float"); const floatVertexTextures = vertexTextures && floatFragmentTextures; const maxSamples = isWebGL2 ? gl.getParameter(gl.MAX_SAMPLES) : 0; return { isWebGL2, drawBuffers, getMaxAnisotropy, getMaxPrecision, precision, logarithmicDepthBuffer, maxTextures, maxVertexTextures, maxTextureSize, maxCubemapSize, maxAttributes, maxVertexUniforms, maxVaryings, maxFragmentUniforms, vertexTextures, floatFragmentTextures, floatVertexTextures, maxSamples }; } function WebGLClipping2(properties) { const scope = this; let globalState = null, numGlobalPlanes = 0, localClippingEnabled = false, renderingShadows = false; const plane = new Plane2(), viewNormalMatrix = new Matrix32(), uniform = { value: null, needsUpdate: false }; this.uniform = uniform; this.numPlanes = 0; this.numIntersection = 0; this.init = function(planes, enableLocalClipping) { const enabled = planes.length !== 0 || enableLocalClipping || // enable state of previous frame - the clipping code has to // run another frame in order to reset the state: numGlobalPlanes !== 0 || localClippingEnabled; localClippingEnabled = enableLocalClipping; numGlobalPlanes = planes.length; return enabled; }; this.beginShadows = function() { renderingShadows = true; projectPlanes(null); }; this.endShadows = function() { renderingShadows = false; }; this.setGlobalState = function(planes, camera3) { globalState = projectPlanes(planes, camera3, 0); }; this.setState = function(material, camera3, useCache) { const planes = material.clippingPlanes, clipIntersection = material.clipIntersection, clipShadows = material.clipShadows; const materialProperties = properties.get(material); if (!localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && !clipShadows) { if (renderingShadows) { projectPlanes(null); } else { resetGlobalState(); } } else { const nGlobal = renderingShadows ? 0 : numGlobalPlanes, lGlobal = nGlobal * 4; let dstArray = materialProperties.clippingState || null; uniform.value = dstArray; dstArray = projectPlanes(planes, camera3, lGlobal, useCache); for (let i = 0; i !== lGlobal; ++i) { dstArray[i] = globalState[i]; } materialProperties.clippingState = dstArray; this.numIntersection = clipIntersection ? this.numPlanes : 0; this.numPlanes += nGlobal; } }; function resetGlobalState() { if (uniform.value !== globalState) { uniform.value = globalState; uniform.needsUpdate = numGlobalPlanes > 0; } scope.numPlanes = numGlobalPlanes; scope.numIntersection = 0; } function projectPlanes(planes, camera3, dstOffset, skipTransform) { const nPlanes = planes !== null ? planes.length : 0; let dstArray = null; if (nPlanes !== 0) { dstArray = uniform.value; if (skipTransform !== true || dstArray === null) { const flatSize = dstOffset + nPlanes * 4, viewMatrix = camera3.matrixWorldInverse; viewNormalMatrix.getNormalMatrix(viewMatrix); if (dstArray === null || dstArray.length < flatSize) { dstArray = new Float32Array(flatSize); } for (let i = 0, i4 = dstOffset; i !== nPlanes; ++i, i4 += 4) { plane.copy(planes[i]).applyMatrix4(viewMatrix, viewNormalMatrix); plane.normal.toArray(dstArray, i4); dstArray[i4 + 3] = plane.constant; } } uniform.value = dstArray; uniform.needsUpdate = true; } scope.numPlanes = nPlanes; scope.numIntersection = 0; return dstArray; } } function WebGLCubeMaps2(renderer3) { let cubemaps = /* @__PURE__ */ new WeakMap(); function mapTextureMapping(texture, mapping) { if (mapping === EquirectangularReflectionMapping2) { texture.mapping = CubeReflectionMapping2; } else if (mapping === EquirectangularRefractionMapping2) { texture.mapping = CubeRefractionMapping2; } return texture; } function get2(texture) { if (texture && texture.isTexture && texture.isRenderTargetTexture === false) { const mapping = texture.mapping; if (mapping === EquirectangularReflectionMapping2 || mapping === EquirectangularRefractionMapping2) { if (cubemaps.has(texture)) { const cubemap = cubemaps.get(texture).texture; return mapTextureMapping(cubemap, texture.mapping); } else { const image = texture.image; if (image && image.height > 0) { const renderTarget = new WebGLCubeRenderTarget2(image.height / 2); renderTarget.fromEquirectangularTexture(renderer3, texture); cubemaps.set(texture, renderTarget); texture.addEventListener("dispose", onTextureDispose); return mapTextureMapping(renderTarget.texture, texture.mapping); } else { return null; } } } } return texture; } function onTextureDispose(event) { const texture = event.target; texture.removeEventListener("dispose", onTextureDispose); const cubemap = cubemaps.get(texture); if (cubemap !== void 0) { cubemaps.delete(texture); cubemap.dispose(); } } function dispose() { cubemaps = /* @__PURE__ */ new WeakMap(); } return { get: get2, dispose }; } var OrthographicCamera2 = class extends Camera2 { constructor(left = -1, right = 1, top = 1, bottom = -1, near = 0.1, far = 2e3) { super(); this.isOrthographicCamera = true; this.type = "OrthographicCamera"; this.zoom = 1; this.view = null; this.left = left; this.right = right; this.top = top; this.bottom = bottom; this.near = near; this.far = far; this.updateProjectionMatrix(); } copy(source, recursive) { super.copy(source, recursive); this.left = source.left; this.right = source.right; this.top = source.top; this.bottom = source.bottom; this.near = source.near; this.far = source.far; this.zoom = source.zoom; this.view = source.view === null ? null : Object.assign({}, source.view); return this; } setViewOffset(fullWidth, fullHeight, x3, y3, width, height) { if (this.view === null) { this.view = { enabled: true, fullWidth: 1, fullHeight: 1, offsetX: 0, offsetY: 0, width: 1, height: 1 }; } this.view.enabled = true; this.view.fullWidth = fullWidth; this.view.fullHeight = fullHeight; this.view.offsetX = x3; this.view.offsetY = y3; this.view.width = width; this.view.height = height; this.updateProjectionMatrix(); } clearViewOffset() { if (this.view !== null) { this.view.enabled = false; } this.updateProjectionMatrix(); } updateProjectionMatrix() { const dx = (this.right - this.left) / (2 * this.zoom); const dy = (this.top - this.bottom) / (2 * this.zoom); const cx = (this.right + this.left) / 2; const cy = (this.top + this.bottom) / 2; let left = cx - dx; let right = cx + dx; let top = cy + dy; let bottom = cy - dy; if (this.view !== null && this.view.enabled) { const scaleW = (this.right - this.left) / this.view.fullWidth / this.zoom; const scaleH = (this.top - this.bottom) / this.view.fullHeight / this.zoom; left += scaleW * this.view.offsetX; right = left + scaleW * this.view.width; top -= scaleH * this.view.offsetY; bottom = top - scaleH * this.view.height; } this.projectionMatrix.makeOrthographic(left, right, top, bottom, this.near, this.far, this.coordinateSystem); this.projectionMatrixInverse.copy(this.projectionMatrix).invert(); } toJSON(meta) { const data = super.toJSON(meta); data.object.zoom = this.zoom; data.object.left = this.left; data.object.right = this.right; data.object.top = this.top; data.object.bottom = this.bottom; data.object.near = this.near; data.object.far = this.far; if (this.view !== null) data.object.view = Object.assign({}, this.view); return data; } }; var LOD_MIN2 = 4; var EXTRA_LOD_SIGMA2 = [0.125, 0.215, 0.35, 0.446, 0.526, 0.582]; var MAX_SAMPLES2 = 20; var _flatCamera2 = /* @__PURE__ */ new OrthographicCamera2(); var _clearColor2 = /* @__PURE__ */ new Color2(); var _oldTarget2 = null; var PHI2 = (1 + Math.sqrt(5)) / 2; var INV_PHI2 = 1 / PHI2; var _axisDirections2 = [ /* @__PURE__ */ new Vector32(1, 1, 1), /* @__PURE__ */ new Vector32(-1, 1, 1), /* @__PURE__ */ new Vector32(1, 1, -1), /* @__PURE__ */ new Vector32(-1, 1, -1), /* @__PURE__ */ new Vector32(0, PHI2, INV_PHI2), /* @__PURE__ */ new Vector32(0, PHI2, -INV_PHI2), /* @__PURE__ */ new Vector32(INV_PHI2, 0, PHI2), /* @__PURE__ */ new Vector32(-INV_PHI2, 0, PHI2), /* @__PURE__ */ new Vector32(PHI2, INV_PHI2, 0), /* @__PURE__ */ new Vector32(-PHI2, INV_PHI2, 0) ]; var PMREMGenerator2 = class { constructor(renderer3) { this._renderer = renderer3; this._pingPongRenderTarget = null; this._lodMax = 0; this._cubeSize = 0; this._lodPlanes = []; this._sizeLods = []; this._sigmas = []; this._blurMaterial = null; this._cubemapMaterial = null; this._equirectMaterial = null; this._compileMaterial(this._blurMaterial); } /** * Generates a PMREM from a supplied Scene, which can be faster than using an * image if networking bandwidth is low. Optional sigma specifies a blur radius * in radians to be applied to the scene before PMREM generation. Optional near * and far planes ensure the scene is rendered in its entirety (the cubeCamera * is placed at the origin). */ fromScene(scene3, sigma = 0, near = 0.1, far = 100) { _oldTarget2 = this._renderer.getRenderTarget(); this._setSize(256); const cubeUVRenderTarget = this._allocateTargets(); cubeUVRenderTarget.depthBuffer = true; this._sceneToCubeUV(scene3, near, far, cubeUVRenderTarget); if (sigma > 0) { this._blur(cubeUVRenderTarget, 0, 0, sigma); } this._applyPMREM(cubeUVRenderTarget); this._cleanup(cubeUVRenderTarget); return cubeUVRenderTarget; } /** * Generates a PMREM from an equirectangular texture, which can be either LDR * or HDR. The ideal input image size is 1k (1024 x 512), * as this matches best with the 256 x 256 cubemap output. */ fromEquirectangular(equirectangular, renderTarget = null) { return this._fromTexture(equirectangular, renderTarget); } /** * Generates a PMREM from an cubemap texture, which can be either LDR * or HDR. The ideal input cube size is 256 x 256, * as this matches best with the 256 x 256 cubemap output. */ fromCubemap(cubemap, renderTarget = null) { return this._fromTexture(cubemap, renderTarget); } /** * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during * your texture's network fetch for increased concurrency. */ compileCubemapShader() { if (this._cubemapMaterial === null) { this._cubemapMaterial = _getCubemapMaterial2(); this._compileMaterial(this._cubemapMaterial); } } /** * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during * your texture's network fetch for increased concurrency. */ compileEquirectangularShader() { if (this._equirectMaterial === null) { this._equirectMaterial = _getEquirectMaterial2(); this._compileMaterial(this._equirectMaterial); } } /** * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class, * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on * one of them will cause any others to also become unusable. */ dispose() { this._dispose(); if (this._cubemapMaterial !== null) this._cubemapMaterial.dispose(); if (this._equirectMaterial !== null) this._equirectMaterial.dispose(); } // private interface _setSize(cubeSize) { this._lodMax = Math.floor(Math.log2(cubeSize)); this._cubeSize = Math.pow(2, this._lodMax); } _dispose() { if (this._blurMaterial !== null) this._blurMaterial.dispose(); if (this._pingPongRenderTarget !== null) this._pingPongRenderTarget.dispose(); for (let i = 0; i < this._lodPlanes.length; i++) { this._lodPlanes[i].dispose(); } } _cleanup(outputTarget) { this._renderer.setRenderTarget(_oldTarget2); outputTarget.scissorTest = false; _setViewport2(outputTarget, 0, 0, outputTarget.width, outputTarget.height); } _fromTexture(texture, renderTarget) { if (texture.mapping === CubeReflectionMapping2 || texture.mapping === CubeRefractionMapping2) { this._setSize(texture.image.length === 0 ? 16 : texture.image[0].width || texture.image[0].image.width); } else { this._setSize(texture.image.width / 4); } _oldTarget2 = this._renderer.getRenderTarget(); const cubeUVRenderTarget = renderTarget || this._allocateTargets(); this._textureToCubeUV(texture, cubeUVRenderTarget); this._applyPMREM(cubeUVRenderTarget); this._cleanup(cubeUVRenderTarget); return cubeUVRenderTarget; } _allocateTargets() { const width = 3 * Math.max(this._cubeSize, 16 * 7); const height = 4 * this._cubeSize; const params = { magFilter: LinearFilter2, minFilter: LinearFilter2, generateMipmaps: false, type: HalfFloatType2, format: RGBAFormat2, colorSpace: LinearSRGBColorSpace2, depthBuffer: false }; const cubeUVRenderTarget = _createRenderTarget2(width, height, params); if (this._pingPongRenderTarget === null || this._pingPongRenderTarget.width !== width || this._pingPongRenderTarget.height !== height) { if (this._pingPongRenderTarget !== null) { this._dispose(); } this._pingPongRenderTarget = _createRenderTarget2(width, height, params); const { _lodMax } = this; ({ sizeLods: this._sizeLods, lodPlanes: this._lodPlanes, sigmas: this._sigmas } = _createPlanes2(_lodMax)); this._blurMaterial = _getBlurShader2(_lodMax, width, height); } return cubeUVRenderTarget; } _compileMaterial(material) { const tmpMesh = new Mesh2(this._lodPlanes[0], material); this._renderer.compile(tmpMesh, _flatCamera2); } _sceneToCubeUV(scene3, near, far, cubeUVRenderTarget) { const fov3 = 90; const aspect3 = 1; const cubeCamera = new PerspectiveCamera2(fov3, aspect3, near, far); const upSign = [1, -1, 1, 1, 1, 1]; const forwardSign = [1, 1, 1, -1, -1, -1]; const renderer3 = this._renderer; const originalAutoClear = renderer3.autoClear; const toneMapping = renderer3.toneMapping; renderer3.getClearColor(_clearColor2); renderer3.toneMapping = NoToneMapping2; renderer3.autoClear = false; const backgroundMaterial = new MeshBasicMaterial2({ name: "PMREM.Background", side: BackSide2, depthWrite: false, depthTest: false }); const backgroundBox = new Mesh2(new BoxGeometry2(), backgroundMaterial); let useSolidColor = false; const background = scene3.background; if (background) { if (background.isColor) { backgroundMaterial.color.copy(background); scene3.background = null; useSolidColor = true; } } else { backgroundMaterial.color.copy(_clearColor2); useSolidColor = true; } for (let i = 0; i < 6; i++) { const col = i % 3; if (col === 0) { cubeCamera.up.set(0, upSign[i], 0); cubeCamera.lookAt(forwardSign[i], 0, 0); } else if (col === 1) { cubeCamera.up.set(0, 0, upSign[i]); cubeCamera.lookAt(0, forwardSign[i], 0); } else { cubeCamera.up.set(0, upSign[i], 0); cubeCamera.lookAt(0, 0, forwardSign[i]); } const size = this._cubeSize; _setViewport2(cubeUVRenderTarget, col * size, i > 2 ? size : 0, size, size); renderer3.setRenderTarget(cubeUVRenderTarget); if (useSolidColor) { renderer3.render(backgroundBox, cubeCamera); } renderer3.render(scene3, cubeCamera); } backgroundBox.geometry.dispose(); backgroundBox.material.dispose(); renderer3.toneMapping = toneMapping; renderer3.autoClear = originalAutoClear; scene3.background = background; } _textureToCubeUV(texture, cubeUVRenderTarget) { const renderer3 = this._renderer; const isCubeTexture = texture.mapping === CubeReflectionMapping2 || texture.mapping === CubeRefractionMapping2; if (isCubeTexture) { if (this._cubemapMaterial === null) { this._cubemapMaterial = _getCubemapMaterial2(); } this._cubemapMaterial.uniforms.flipEnvMap.value = texture.isRenderTargetTexture === false ? -1 : 1; } else { if (this._equirectMaterial === null) { this._equirectMaterial = _getEquirectMaterial2(); } } const material = isCubeTexture ? this._cubemapMaterial : this._equirectMaterial; const mesh = new Mesh2(this._lodPlanes[0], material); const uniforms = material.uniforms; uniforms["envMap"].value = texture; const size = this._cubeSize; _setViewport2(cubeUVRenderTarget, 0, 0, 3 * size, 2 * size); renderer3.setRenderTarget(cubeUVRenderTarget); renderer3.render(mesh, _flatCamera2); } _applyPMREM(cubeUVRenderTarget) { const renderer3 = this._renderer; const autoClear = renderer3.autoClear; renderer3.autoClear = false; for (let i = 1; i < this._lodPlanes.length; i++) { const sigma = Math.sqrt(this._sigmas[i] * this._sigmas[i] - this._sigmas[i - 1] * this._sigmas[i - 1]); const poleAxis = _axisDirections2[(i - 1) % _axisDirections2.length]; this._blur(cubeUVRenderTarget, i - 1, i, sigma, poleAxis); } renderer3.autoClear = autoClear; } /** * This is a two-pass Gaussian blur for a cubemap. Normally this is done * vertically and horizontally, but this breaks down on a cube. Here we apply * the blur latitudinally (around the poles), and then longitudinally (towards * the poles) to approximate the orthogonally-separable blur. It is least * accurate at the poles, but still does a decent job. */ _blur(cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis) { const pingPongRenderTarget = this._pingPongRenderTarget; this._halfBlur( cubeUVRenderTarget, pingPongRenderTarget, lodIn, lodOut, sigma, "latitudinal", poleAxis ); this._halfBlur( pingPongRenderTarget, cubeUVRenderTarget, lodOut, lodOut, sigma, "longitudinal", poleAxis ); } _halfBlur(targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis) { const renderer3 = this._renderer; const blurMaterial = this._blurMaterial; if (direction !== "latitudinal" && direction !== "longitudinal") { console.error( "blur direction must be either latitudinal or longitudinal!" ); } const STANDARD_DEVIATIONS = 3; const blurMesh = new Mesh2(this._lodPlanes[lodOut], blurMaterial); const blurUniforms = blurMaterial.uniforms; const pixels = this._sizeLods[lodIn] - 1; const radiansPerPixel = isFinite(sigmaRadians) ? Math.PI / (2 * pixels) : 2 * Math.PI / (2 * MAX_SAMPLES2 - 1); const sigmaPixels = sigmaRadians / radiansPerPixel; const samples = isFinite(sigmaRadians) ? 1 + Math.floor(STANDARD_DEVIATIONS * sigmaPixels) : MAX_SAMPLES2; if (samples > MAX_SAMPLES2) { console.warn(`sigmaRadians, ${sigmaRadians}, is too large and will clip, as it requested ${samples} samples when the maximum is set to ${MAX_SAMPLES2}`); } const weights = []; let sum = 0; for (let i = 0; i < MAX_SAMPLES2; ++i) { const x4 = i / sigmaPixels; const weight = Math.exp(-x4 * x4 / 2); weights.push(weight); if (i === 0) { sum += weight; } else if (i < samples) { sum += 2 * weight; } } for (let i = 0; i < weights.length; i++) { weights[i] = weights[i] / sum; } blurUniforms["envMap"].value = targetIn.texture; blurUniforms["samples"].value = samples; blurUniforms["weights"].value = weights; blurUniforms["latitudinal"].value = direction === "latitudinal"; if (poleAxis) { blurUniforms["poleAxis"].value = poleAxis; } const { _lodMax } = this; blurUniforms["dTheta"].value = radiansPerPixel; blurUniforms["mipInt"].value = _lodMax - lodIn; const outputSize = this._sizeLods[lodOut]; const x3 = 3 * outputSize * (lodOut > _lodMax - LOD_MIN2 ? lodOut - _lodMax + LOD_MIN2 : 0); const y3 = 4 * (this._cubeSize - outputSize); _setViewport2(targetOut, x3, y3, 3 * outputSize, 2 * outputSize); renderer3.setRenderTarget(targetOut); renderer3.render(blurMesh, _flatCamera2); } }; function _createPlanes2(lodMax) { const lodPlanes = []; const sizeLods = []; const sigmas = []; let lod = lodMax; const totalLods = lodMax - LOD_MIN2 + 1 + EXTRA_LOD_SIGMA2.length; for (let i = 0; i < totalLods; i++) { const sizeLod = Math.pow(2, lod); sizeLods.push(sizeLod); let sigma = 1 / sizeLod; if (i > lodMax - LOD_MIN2) { sigma = EXTRA_LOD_SIGMA2[i - lodMax + LOD_MIN2 - 1]; } else if (i === 0) { sigma = 0; } sigmas.push(sigma); const texelSize = 1 / (sizeLod - 2); const min2 = -texelSize; const max2 = 1 + texelSize; const uv1 = [min2, min2, max2, min2, max2, max2, min2, min2, max2, max2, min2, max2]; const cubeFaces = 6; const vertices = 6; const positionSize = 3; const uvSize = 2; const faceIndexSize = 1; const position = new Float32Array(positionSize * vertices * cubeFaces); const uv = new Float32Array(uvSize * vertices * cubeFaces); const faceIndex = new Float32Array(faceIndexSize * vertices * cubeFaces); for (let face = 0; face < cubeFaces; face++) { const x3 = face % 3 * 2 / 3 - 1; const y3 = face > 2 ? 0 : -1; const coordinates = [ x3, y3, 0, x3 + 2 / 3, y3, 0, x3 + 2 / 3, y3 + 1, 0, x3, y3, 0, x3 + 2 / 3, y3 + 1, 0, x3, y3 + 1, 0 ]; position.set(coordinates, positionSize * vertices * face); uv.set(uv1, uvSize * vertices * face); const fill = [face, face, face, face, face, face]; faceIndex.set(fill, faceIndexSize * vertices * face); } const planes = new BufferGeometry2(); planes.setAttribute("position", new BufferAttribute2(position, positionSize)); planes.setAttribute("uv", new BufferAttribute2(uv, uvSize)); planes.setAttribute("faceIndex", new BufferAttribute2(faceIndex, faceIndexSize)); lodPlanes.push(planes); if (lod > LOD_MIN2) { lod--; } } return { lodPlanes, sizeLods, sigmas }; } function _createRenderTarget2(width, height, params) { const cubeUVRenderTarget = new WebGLRenderTarget2(width, height, params); cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping2; cubeUVRenderTarget.texture.name = "PMREM.cubeUv"; cubeUVRenderTarget.scissorTest = true; return cubeUVRenderTarget; } function _setViewport2(target, x3, y3, width, height) { target.viewport.set(x3, y3, width, height); target.scissor.set(x3, y3, width, height); } function _getBlurShader2(lodMax, width, height) { const weights = new Float32Array(MAX_SAMPLES2); const poleAxis = new Vector32(0, 1, 0); const shaderMaterial = new ShaderMaterial2({ name: "SphericalGaussianBlur", defines: { "n": MAX_SAMPLES2, "CUBEUV_TEXEL_WIDTH": 1 / width, "CUBEUV_TEXEL_HEIGHT": 1 / height, "CUBEUV_MAX_MIP": `${lodMax}.0` }, uniforms: { "envMap": { value: null }, "samples": { value: 1 }, "weights": { value: weights }, "latitudinal": { value: false }, "dTheta": { value: 0 }, "mipInt": { value: 0 }, "poleAxis": { value: poleAxis } }, vertexShader: _getCommonVertexShader2(), fragmentShader: ( /* glsl */ ` precision mediump float; precision mediump int; varying vec3 vOutputDirection; uniform sampler2D envMap; uniform int samples; uniform float weights[ n ]; uniform bool latitudinal; uniform float dTheta; uniform float mipInt; uniform vec3 poleAxis; #define ENVMAP_TYPE_CUBE_UV #include vec3 getSample( float theta, vec3 axis ) { float cosTheta = cos( theta ); // Rodrigues' axis-angle rotation vec3 sampleDirection = vOutputDirection * cosTheta + cross( axis, vOutputDirection ) * sin( theta ) + axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta ); return bilinearCubeUV( envMap, sampleDirection, mipInt ); } void main() { vec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection ); if ( all( equal( axis, vec3( 0.0 ) ) ) ) { axis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x ); } axis = normalize( axis ); gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 ); gl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis ); for ( int i = 1; i < n; i++ ) { if ( i >= samples ) { break; } float theta = dTheta * float( i ); gl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis ); gl_FragColor.rgb += weights[ i ] * getSample( theta, axis ); } } ` ), blending: NoBlending2, depthTest: false, depthWrite: false }); return shaderMaterial; } function _getEquirectMaterial2() { return new ShaderMaterial2({ name: "EquirectangularToCubeUV", uniforms: { "envMap": { value: null } }, vertexShader: _getCommonVertexShader2(), fragmentShader: ( /* glsl */ ` precision mediump float; precision mediump int; varying vec3 vOutputDirection; uniform sampler2D envMap; #include void main() { vec3 outputDirection = normalize( vOutputDirection ); vec2 uv = equirectUv( outputDirection ); gl_FragColor = vec4( texture2D ( envMap, uv ).rgb, 1.0 ); } ` ), blending: NoBlending2, depthTest: false, depthWrite: false }); } function _getCubemapMaterial2() { return new ShaderMaterial2({ name: "CubemapToCubeUV", uniforms: { "envMap": { value: null }, "flipEnvMap": { value: -1 } }, vertexShader: _getCommonVertexShader2(), fragmentShader: ( /* glsl */ ` precision mediump float; precision mediump int; uniform float flipEnvMap; varying vec3 vOutputDirection; uniform samplerCube envMap; void main() { gl_FragColor = textureCube( envMap, vec3( flipEnvMap * vOutputDirection.x, vOutputDirection.yz ) ); } ` ), blending: NoBlending2, depthTest: false, depthWrite: false }); } function _getCommonVertexShader2() { return ( /* glsl */ ` precision mediump float; precision mediump int; attribute float faceIndex; varying vec3 vOutputDirection; // RH coordinate system; PMREM face-indexing convention vec3 getDirection( vec2 uv, float face ) { uv = 2.0 * uv - 1.0; vec3 direction = vec3( uv, 1.0 ); if ( face == 0.0 ) { direction = direction.zyx; // ( 1, v, u ) pos x } else if ( face == 1.0 ) { direction = direction.xzy; direction.xz *= -1.0; // ( -u, 1, -v ) pos y } else if ( face == 2.0 ) { direction.x *= -1.0; // ( -u, v, 1 ) pos z } else if ( face == 3.0 ) { direction = direction.zyx; direction.xz *= -1.0; // ( -1, v, -u ) neg x } else if ( face == 4.0 ) { direction = direction.xzy; direction.xy *= -1.0; // ( -u, -1, v ) neg y } else if ( face == 5.0 ) { direction.z *= -1.0; // ( u, v, -1 ) neg z } return direction; } void main() { vOutputDirection = getDirection( uv, faceIndex ); gl_Position = vec4( position, 1.0 ); } ` ); } function WebGLCubeUVMaps2(renderer3) { let cubeUVmaps = /* @__PURE__ */ new WeakMap(); let pmremGenerator = null; function get2(texture) { if (texture && texture.isTexture) { const mapping = texture.mapping; const isEquirectMap = mapping === EquirectangularReflectionMapping2 || mapping === EquirectangularRefractionMapping2; const isCubeMap = mapping === CubeReflectionMapping2 || mapping === CubeRefractionMapping2; if (isEquirectMap || isCubeMap) { if (texture.isRenderTargetTexture && texture.needsPMREMUpdate === true) { texture.needsPMREMUpdate = false; let renderTarget = cubeUVmaps.get(texture); if (pmremGenerator === null) pmremGenerator = new PMREMGenerator2(renderer3); renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular(texture, renderTarget) : pmremGenerator.fromCubemap(texture, renderTarget); cubeUVmaps.set(texture, renderTarget); return renderTarget.texture; } else { if (cubeUVmaps.has(texture)) { return cubeUVmaps.get(texture).texture; } else { const image = texture.image; if (isEquirectMap && image && image.height > 0 || isCubeMap && image && isCubeTextureComplete(image)) { if (pmremGenerator === null) pmremGenerator = new PMREMGenerator2(renderer3); const renderTarget = isEquirectMap ? pmremGenerator.fromEquirectangular(texture) : pmremGenerator.fromCubemap(texture); cubeUVmaps.set(texture, renderTarget); texture.addEventListener("dispose", onTextureDispose); return renderTarget.texture; } else { return null; } } } } } return texture; } function isCubeTextureComplete(image) { let count = 0; const length = 6; for (let i = 0; i < length; i++) { if (image[i] !== void 0) count++; } return count === length; } function onTextureDispose(event) { const texture = event.target; texture.removeEventListener("dispose", onTextureDispose); const cubemapUV = cubeUVmaps.get(texture); if (cubemapUV !== void 0) { cubeUVmaps.delete(texture); cubemapUV.dispose(); } } function dispose() { cubeUVmaps = /* @__PURE__ */ new WeakMap(); if (pmremGenerator !== null) { pmremGenerator.dispose(); pmremGenerator = null; } } return { get: get2, dispose }; } function WebGLExtensions2(gl) { const extensions = {}; function getExtension(name) { if (extensions[name] !== void 0) { return extensions[name]; } let extension; switch (name) { case "WEBGL_depth_texture": extension = gl.getExtension("WEBGL_depth_texture") || gl.getExtension("MOZ_WEBGL_depth_texture") || gl.getExtension("WEBKIT_WEBGL_depth_texture"); break; case "EXT_texture_filter_anisotropic": extension = gl.getExtension("EXT_texture_filter_anisotropic") || gl.getExtension("MOZ_EXT_texture_filter_anisotropic") || gl.getExtension("WEBKIT_EXT_texture_filter_anisotropic"); break; case "WEBGL_compressed_texture_s3tc": extension = gl.getExtension("WEBGL_compressed_texture_s3tc") || gl.getExtension("MOZ_WEBGL_compressed_texture_s3tc") || gl.getExtension("WEBKIT_WEBGL_compressed_texture_s3tc"); break; case "WEBGL_compressed_texture_pvrtc": extension = gl.getExtension("WEBGL_compressed_texture_pvrtc") || gl.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"); break; default: extension = gl.getExtension(name); } extensions[name] = extension; return extension; } return { has: function(name) { return getExtension(name) !== null; }, init: function(capabilities) { if (capabilities.isWebGL2) { getExtension("EXT_color_buffer_float"); } else { getExtension("WEBGL_depth_texture"); getExtension("OES_texture_float"); getExtension("OES_texture_half_float"); getExtension("OES_texture_half_float_linear"); getExtension("OES_standard_derivatives"); getExtension("OES_element_index_uint"); getExtension("OES_vertex_array_object"); getExtension("ANGLE_instanced_arrays"); } getExtension("OES_texture_float_linear"); getExtension("EXT_color_buffer_half_float"); getExtension("WEBGL_multisampled_render_to_texture"); }, get: function(name) { const extension = getExtension(name); if (extension === null) { console.warn("THREE.WebGLRenderer: " + name + " extension not supported."); } return extension; } }; } function WebGLGeometries2(gl, attributes, info, bindingStates) { const geometries = {}; const wireframeAttributes = /* @__PURE__ */ new WeakMap(); function onGeometryDispose(event) { const geometry = event.target; if (geometry.index !== null) { attributes.remove(geometry.index); } for (const name in geometry.attributes) { attributes.remove(geometry.attributes[name]); } for (const name in geometry.morphAttributes) { const array = geometry.morphAttributes[name]; for (let i = 0, l = array.length; i < l; i++) { attributes.remove(array[i]); } } geometry.removeEventListener("dispose", onGeometryDispose); delete geometries[geometry.id]; const attribute = wireframeAttributes.get(geometry); if (attribute) { attributes.remove(attribute); wireframeAttributes.delete(geometry); } bindingStates.releaseStatesOfGeometry(geometry); if (geometry.isInstancedBufferGeometry === true) { delete geometry._maxInstanceCount; } info.memory.geometries--; } function get2(object, geometry) { if (geometries[geometry.id] === true) return geometry; geometry.addEventListener("dispose", onGeometryDispose); geometries[geometry.id] = true; info.memory.geometries++; return geometry; } function update4(geometry) { const geometryAttributes = geometry.attributes; for (const name in geometryAttributes) { attributes.update(geometryAttributes[name], gl.ARRAY_BUFFER); } const morphAttributes = geometry.morphAttributes; for (const name in morphAttributes) { const array = morphAttributes[name]; for (let i = 0, l = array.length; i < l; i++) { attributes.update(array[i], gl.ARRAY_BUFFER); } } } function updateWireframeAttribute(geometry) { const indices = []; const geometryIndex = geometry.index; const geometryPosition = geometry.attributes.position; let version = 0; if (geometryIndex !== null) { const array = geometryIndex.array; version = geometryIndex.version; for (let i = 0, l = array.length; i < l; i += 3) { const a2 = array[i + 0]; const b = array[i + 1]; const c2 = array[i + 2]; indices.push(a2, b, b, c2, c2, a2); } } else if (geometryPosition !== void 0) { const array = geometryPosition.array; version = geometryPosition.version; for (let i = 0, l = array.length / 3 - 1; i < l; i += 3) { const a2 = i + 0; const b = i + 1; const c2 = i + 2; indices.push(a2, b, b, c2, c2, a2); } } else { return; } const attribute = new (arrayNeedsUint322(indices) ? Uint32BufferAttribute2 : Uint16BufferAttribute2)(indices, 1); attribute.version = version; const previousAttribute = wireframeAttributes.get(geometry); if (previousAttribute) attributes.remove(previousAttribute); wireframeAttributes.set(geometry, attribute); } function getWireframeAttribute(geometry) { const currentAttribute = wireframeAttributes.get(geometry); if (currentAttribute) { const geometryIndex = geometry.index; if (geometryIndex !== null) { if (currentAttribute.version < geometryIndex.version) { updateWireframeAttribute(geometry); } } } else { updateWireframeAttribute(geometry); } return wireframeAttributes.get(geometry); } return { get: get2, update: update4, getWireframeAttribute }; } function WebGLIndexedBufferRenderer2(gl, extensions, info, capabilities) { const isWebGL2 = capabilities.isWebGL2; let mode; function setMode(value) { mode = value; } let type, bytesPerElement; function setIndex(value) { type = value.type; bytesPerElement = value.bytesPerElement; } function render(start, count) { gl.drawElements(mode, count, type, start * bytesPerElement); info.update(count, mode, 1); } function renderInstances(start, count, primcount) { if (primcount === 0) return; let extension, methodName; if (isWebGL2) { extension = gl; methodName = "drawElementsInstanced"; } else { extension = extensions.get("ANGLE_instanced_arrays"); methodName = "drawElementsInstancedANGLE"; if (extension === null) { console.error("THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays."); return; } } extension[methodName](mode, count, type, start * bytesPerElement, primcount); info.update(count, mode, primcount); } this.setMode = setMode; this.setIndex = setIndex; this.render = render; this.renderInstances = renderInstances; } function WebGLInfo2(gl) { const memory = { geometries: 0, textures: 0 }; const render = { frame: 0, calls: 0, triangles: 0, points: 0, lines: 0 }; function update4(count, mode, instanceCount) { render.calls++; switch (mode) { case gl.TRIANGLES: render.triangles += instanceCount * (count / 3); break; case gl.LINES: render.lines += instanceCount * (count / 2); break; case gl.LINE_STRIP: render.lines += instanceCount * (count - 1); break; case gl.LINE_LOOP: render.lines += instanceCount * count; break; case gl.POINTS: render.points += instanceCount * count; break; default: console.error("THREE.WebGLInfo: Unknown draw mode:", mode); break; } } function reset() { render.calls = 0; render.triangles = 0; render.points = 0; render.lines = 0; } return { memory, render, programs: null, autoReset: true, reset, update: update4 }; } function numericalSort2(a2, b) { return a2[0] - b[0]; } function absNumericalSort2(a2, b) { return Math.abs(b[1]) - Math.abs(a2[1]); } function WebGLMorphtargets2(gl, capabilities, textures) { const influencesList = {}; const morphInfluences = new Float32Array(8); const morphTextures = /* @__PURE__ */ new WeakMap(); const morph = new Vector42(); const workInfluences = []; for (let i = 0; i < 8; i++) { workInfluences[i] = [i, 0]; } function update4(object, geometry, program) { const objectInfluences = object.morphTargetInfluences; if (capabilities.isWebGL2 === true) { const morphAttribute = geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color; const morphTargetsCount = morphAttribute !== void 0 ? morphAttribute.length : 0; let entry = morphTextures.get(geometry); if (entry === void 0 || entry.count !== morphTargetsCount) { let disposeTexture = function() { texture.dispose(); morphTextures.delete(geometry); geometry.removeEventListener("dispose", disposeTexture); }; if (entry !== void 0) entry.texture.dispose(); const hasMorphPosition = geometry.morphAttributes.position !== void 0; const hasMorphNormals = geometry.morphAttributes.normal !== void 0; const hasMorphColors = geometry.morphAttributes.color !== void 0; const morphTargets = geometry.morphAttributes.position || []; const morphNormals = geometry.morphAttributes.normal || []; const morphColors = geometry.morphAttributes.color || []; let vertexDataCount = 0; if (hasMorphPosition === true) vertexDataCount = 1; if (hasMorphNormals === true) vertexDataCount = 2; if (hasMorphColors === true) vertexDataCount = 3; let width = geometry.attributes.position.count * vertexDataCount; let height = 1; if (width > capabilities.maxTextureSize) { height = Math.ceil(width / capabilities.maxTextureSize); width = capabilities.maxTextureSize; } const buffer = new Float32Array(width * height * 4 * morphTargetsCount); const texture = new DataArrayTexture2(buffer, width, height, morphTargetsCount); texture.type = FloatType2; texture.needsUpdate = true; const vertexDataStride = vertexDataCount * 4; for (let i = 0; i < morphTargetsCount; i++) { const morphTarget = morphTargets[i]; const morphNormal = morphNormals[i]; const morphColor = morphColors[i]; const offset = width * height * 4 * i; for (let j = 0; j < morphTarget.count; j++) { const stride = j * vertexDataStride; if (hasMorphPosition === true) { morph.fromBufferAttribute(morphTarget, j); buffer[offset + stride + 0] = morph.x; buffer[offset + stride + 1] = morph.y; buffer[offset + stride + 2] = morph.z; buffer[offset + stride + 3] = 0; } if (hasMorphNormals === true) { morph.fromBufferAttribute(morphNormal, j); buffer[offset + stride + 4] = morph.x; buffer[offset + stride + 5] = morph.y; buffer[offset + stride + 6] = morph.z; buffer[offset + stride + 7] = 0; } if (hasMorphColors === true) { morph.fromBufferAttribute(morphColor, j); buffer[offset + stride + 8] = morph.x; buffer[offset + stride + 9] = morph.y; buffer[offset + stride + 10] = morph.z; buffer[offset + stride + 11] = morphColor.itemSize === 4 ? morph.w : 1; } } } entry = { count: morphTargetsCount, texture, size: new Vector22(width, height) }; morphTextures.set(geometry, entry); geometry.addEventListener("dispose", disposeTexture); } let morphInfluencesSum = 0; for (let i = 0; i < objectInfluences.length; i++) { morphInfluencesSum += objectInfluences[i]; } const morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum; program.getUniforms().setValue(gl, "morphTargetBaseInfluence", morphBaseInfluence); program.getUniforms().setValue(gl, "morphTargetInfluences", objectInfluences); program.getUniforms().setValue(gl, "morphTargetsTexture", entry.texture, textures); program.getUniforms().setValue(gl, "morphTargetsTextureSize", entry.size); } else { const length = objectInfluences === void 0 ? 0 : objectInfluences.length; let influences = influencesList[geometry.id]; if (influences === void 0 || influences.length !== length) { influences = []; for (let i = 0; i < length; i++) { influences[i] = [i, 0]; } influencesList[geometry.id] = influences; } for (let i = 0; i < length; i++) { const influence = influences[i]; influence[0] = i; influence[1] = objectInfluences[i]; } influences.sort(absNumericalSort2); for (let i = 0; i < 8; i++) { if (i < length && influences[i][1]) { workInfluences[i][0] = influences[i][0]; workInfluences[i][1] = influences[i][1]; } else { workInfluences[i][0] = Number.MAX_SAFE_INTEGER; workInfluences[i][1] = 0; } } workInfluences.sort(numericalSort2); const morphTargets = geometry.morphAttributes.position; const morphNormals = geometry.morphAttributes.normal; let morphInfluencesSum = 0; for (let i = 0; i < 8; i++) { const influence = workInfluences[i]; const index6 = influence[0]; const value = influence[1]; if (index6 !== Number.MAX_SAFE_INTEGER && value) { if (morphTargets && geometry.getAttribute("morphTarget" + i) !== morphTargets[index6]) { geometry.setAttribute("morphTarget" + i, morphTargets[index6]); } if (morphNormals && geometry.getAttribute("morphNormal" + i) !== morphNormals[index6]) { geometry.setAttribute("morphNormal" + i, morphNormals[index6]); } morphInfluences[i] = value; morphInfluencesSum += value; } else { if (morphTargets && geometry.hasAttribute("morphTarget" + i) === true) { geometry.deleteAttribute("morphTarget" + i); } if (morphNormals && geometry.hasAttribute("morphNormal" + i) === true) { geometry.deleteAttribute("morphNormal" + i); } morphInfluences[i] = 0; } } const morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum; program.getUniforms().setValue(gl, "morphTargetBaseInfluence", morphBaseInfluence); program.getUniforms().setValue(gl, "morphTargetInfluences", morphInfluences); } } return { update: update4 }; } function WebGLObjects2(gl, geometries, attributes, info) { let updateMap = /* @__PURE__ */ new WeakMap(); function update4(object) { const frame2 = info.render.frame; const geometry = object.geometry; const buffergeometry = geometries.get(object, geometry); if (updateMap.get(buffergeometry) !== frame2) { geometries.update(buffergeometry); updateMap.set(buffergeometry, frame2); } if (object.isInstancedMesh) { if (object.hasEventListener("dispose", onInstancedMeshDispose) === false) { object.addEventListener("dispose", onInstancedMeshDispose); } if (updateMap.get(object) !== frame2) { attributes.update(object.instanceMatrix, gl.ARRAY_BUFFER); if (object.instanceColor !== null) { attributes.update(object.instanceColor, gl.ARRAY_BUFFER); } updateMap.set(object, frame2); } } if (object.isSkinnedMesh) { const skeleton = object.skeleton; if (updateMap.get(skeleton) !== frame2) { skeleton.update(); updateMap.set(skeleton, frame2); } } return buffergeometry; } function dispose() { updateMap = /* @__PURE__ */ new WeakMap(); } function onInstancedMeshDispose(event) { const instancedMesh = event.target; instancedMesh.removeEventListener("dispose", onInstancedMeshDispose); attributes.remove(instancedMesh.instanceMatrix); if (instancedMesh.instanceColor !== null) attributes.remove(instancedMesh.instanceColor); } return { update: update4, dispose }; } var emptyTexture2 = /* @__PURE__ */ new Texture2(); var emptyArrayTexture2 = /* @__PURE__ */ new DataArrayTexture2(); var empty3dTexture2 = /* @__PURE__ */ new Data3DTexture2(); var emptyCubeTexture2 = /* @__PURE__ */ new CubeTexture2(); var arrayCacheF322 = []; var arrayCacheI322 = []; var mat4array2 = new Float32Array(16); var mat3array2 = new Float32Array(9); var mat2array2 = new Float32Array(4); function flatten2(array, nBlocks, blockSize) { const firstElem = array[0]; if (firstElem <= 0 || firstElem > 0) return array; const n = nBlocks * blockSize; let r = arrayCacheF322[n]; if (r === void 0) { r = new Float32Array(n); arrayCacheF322[n] = r; } if (nBlocks !== 0) { firstElem.toArray(r, 0); for (let i = 1, offset = 0; i !== nBlocks; ++i) { offset += blockSize; array[i].toArray(r, offset); } } return r; } function arraysEqual2(a2, b) { if (a2.length !== b.length) return false; for (let i = 0, l = a2.length; i < l; i++) { if (a2[i] !== b[i]) return false; } return true; } function copyArray2(a2, b) { for (let i = 0, l = b.length; i < l; i++) { a2[i] = b[i]; } } function allocTexUnits2(textures, n) { let r = arrayCacheI322[n]; if (r === void 0) { r = new Int32Array(n); arrayCacheI322[n] = r; } for (let i = 0; i !== n; ++i) { r[i] = textures.allocateTextureUnit(); } return r; } function setValueV1f2(gl, v) { const cache = this.cache; if (cache[0] === v) return; gl.uniform1f(this.addr, v); cache[0] = v; } function setValueV2f2(gl, v) { const cache = this.cache; if (v.x !== void 0) { if (cache[0] !== v.x || cache[1] !== v.y) { gl.uniform2f(this.addr, v.x, v.y); cache[0] = v.x; cache[1] = v.y; } } else { if (arraysEqual2(cache, v)) return; gl.uniform2fv(this.addr, v); copyArray2(cache, v); } } function setValueV3f2(gl, v) { const cache = this.cache; if (v.x !== void 0) { if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) { gl.uniform3f(this.addr, v.x, v.y, v.z); cache[0] = v.x; cache[1] = v.y; cache[2] = v.z; } } else if (v.r !== void 0) { if (cache[0] !== v.r || cache[1] !== v.g || cache[2] !== v.b) { gl.uniform3f(this.addr, v.r, v.g, v.b); cache[0] = v.r; cache[1] = v.g; cache[2] = v.b; } } else { if (arraysEqual2(cache, v)) return; gl.uniform3fv(this.addr, v); copyArray2(cache, v); } } function setValueV4f2(gl, v) { const cache = this.cache; if (v.x !== void 0) { if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) { gl.uniform4f(this.addr, v.x, v.y, v.z, v.w); cache[0] = v.x; cache[1] = v.y; cache[2] = v.z; cache[3] = v.w; } } else { if (arraysEqual2(cache, v)) return; gl.uniform4fv(this.addr, v); copyArray2(cache, v); } } function setValueM22(gl, v) { const cache = this.cache; const elements = v.elements; if (elements === void 0) { if (arraysEqual2(cache, v)) return; gl.uniformMatrix2fv(this.addr, false, v); copyArray2(cache, v); } else { if (arraysEqual2(cache, elements)) return; mat2array2.set(elements); gl.uniformMatrix2fv(this.addr, false, mat2array2); copyArray2(cache, elements); } } function setValueM32(gl, v) { const cache = this.cache; const elements = v.elements; if (elements === void 0) { if (arraysEqual2(cache, v)) return; gl.uniformMatrix3fv(this.addr, false, v); copyArray2(cache, v); } else { if (arraysEqual2(cache, elements)) return; mat3array2.set(elements); gl.uniformMatrix3fv(this.addr, false, mat3array2); copyArray2(cache, elements); } } function setValueM42(gl, v) { const cache = this.cache; const elements = v.elements; if (elements === void 0) { if (arraysEqual2(cache, v)) return; gl.uniformMatrix4fv(this.addr, false, v); copyArray2(cache, v); } else { if (arraysEqual2(cache, elements)) return; mat4array2.set(elements); gl.uniformMatrix4fv(this.addr, false, mat4array2); copyArray2(cache, elements); } } function setValueV1i2(gl, v) { const cache = this.cache; if (cache[0] === v) return; gl.uniform1i(this.addr, v); cache[0] = v; } function setValueV2i2(gl, v) { const cache = this.cache; if (v.x !== void 0) { if (cache[0] !== v.x || cache[1] !== v.y) { gl.uniform2i(this.addr, v.x, v.y); cache[0] = v.x; cache[1] = v.y; } } else { if (arraysEqual2(cache, v)) return; gl.uniform2iv(this.addr, v); copyArray2(cache, v); } } function setValueV3i2(gl, v) { const cache = this.cache; if (v.x !== void 0) { if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) { gl.uniform3i(this.addr, v.x, v.y, v.z); cache[0] = v.x; cache[1] = v.y; cache[2] = v.z; } } else { if (arraysEqual2(cache, v)) return; gl.uniform3iv(this.addr, v); copyArray2(cache, v); } } function setValueV4i2(gl, v) { const cache = this.cache; if (v.x !== void 0) { if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) { gl.uniform4i(this.addr, v.x, v.y, v.z, v.w); cache[0] = v.x; cache[1] = v.y; cache[2] = v.z; cache[3] = v.w; } } else { if (arraysEqual2(cache, v)) return; gl.uniform4iv(this.addr, v); copyArray2(cache, v); } } function setValueV1ui2(gl, v) { const cache = this.cache; if (cache[0] === v) return; gl.uniform1ui(this.addr, v); cache[0] = v; } function setValueV2ui2(gl, v) { const cache = this.cache; if (v.x !== void 0) { if (cache[0] !== v.x || cache[1] !== v.y) { gl.uniform2ui(this.addr, v.x, v.y); cache[0] = v.x; cache[1] = v.y; } } else { if (arraysEqual2(cache, v)) return; gl.uniform2uiv(this.addr, v); copyArray2(cache, v); } } function setValueV3ui2(gl, v) { const cache = this.cache; if (v.x !== void 0) { if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z) { gl.uniform3ui(this.addr, v.x, v.y, v.z); cache[0] = v.x; cache[1] = v.y; cache[2] = v.z; } } else { if (arraysEqual2(cache, v)) return; gl.uniform3uiv(this.addr, v); copyArray2(cache, v); } } function setValueV4ui2(gl, v) { const cache = this.cache; if (v.x !== void 0) { if (cache[0] !== v.x || cache[1] !== v.y || cache[2] !== v.z || cache[3] !== v.w) { gl.uniform4ui(this.addr, v.x, v.y, v.z, v.w); cache[0] = v.x; cache[1] = v.y; cache[2] = v.z; cache[3] = v.w; } } else { if (arraysEqual2(cache, v)) return; gl.uniform4uiv(this.addr, v); copyArray2(cache, v); } } function setValueT12(gl, v, textures) { const cache = this.cache; const unit = textures.allocateTextureUnit(); if (cache[0] !== unit) { gl.uniform1i(this.addr, unit); cache[0] = unit; } textures.setTexture2D(v || emptyTexture2, unit); } function setValueT3D12(gl, v, textures) { const cache = this.cache; const unit = textures.allocateTextureUnit(); if (cache[0] !== unit) { gl.uniform1i(this.addr, unit); cache[0] = unit; } textures.setTexture3D(v || empty3dTexture2, unit); } function setValueT62(gl, v, textures) { const cache = this.cache; const unit = textures.allocateTextureUnit(); if (cache[0] !== unit) { gl.uniform1i(this.addr, unit); cache[0] = unit; } textures.setTextureCube(v || emptyCubeTexture2, unit); } function setValueT2DArray12(gl, v, textures) { const cache = this.cache; const unit = textures.allocateTextureUnit(); if (cache[0] !== unit) { gl.uniform1i(this.addr, unit); cache[0] = unit; } textures.setTexture2DArray(v || emptyArrayTexture2, unit); } function getSingularSetter2(type) { switch (type) { case 5126: return setValueV1f2; case 35664: return setValueV2f2; case 35665: return setValueV3f2; case 35666: return setValueV4f2; case 35674: return setValueM22; case 35675: return setValueM32; case 35676: return setValueM42; case 5124: case 35670: return setValueV1i2; case 35667: case 35671: return setValueV2i2; case 35668: case 35672: return setValueV3i2; case 35669: case 35673: return setValueV4i2; case 5125: return setValueV1ui2; case 36294: return setValueV2ui2; case 36295: return setValueV3ui2; case 36296: return setValueV4ui2; case 35678: case 36198: case 36298: case 36306: case 35682: return setValueT12; case 35679: case 36299: case 36307: return setValueT3D12; case 35680: case 36300: case 36308: case 36293: return setValueT62; case 36289: case 36303: case 36311: case 36292: return setValueT2DArray12; } } function setValueV1fArray2(gl, v) { gl.uniform1fv(this.addr, v); } function setValueV2fArray2(gl, v) { const data = flatten2(v, this.size, 2); gl.uniform2fv(this.addr, data); } function setValueV3fArray2(gl, v) { const data = flatten2(v, this.size, 3); gl.uniform3fv(this.addr, data); } function setValueV4fArray2(gl, v) { const data = flatten2(v, this.size, 4); gl.uniform4fv(this.addr, data); } function setValueM2Array2(gl, v) { const data = flatten2(v, this.size, 4); gl.uniformMatrix2fv(this.addr, false, data); } function setValueM3Array2(gl, v) { const data = flatten2(v, this.size, 9); gl.uniformMatrix3fv(this.addr, false, data); } function setValueM4Array2(gl, v) { const data = flatten2(v, this.size, 16); gl.uniformMatrix4fv(this.addr, false, data); } function setValueV1iArray2(gl, v) { gl.uniform1iv(this.addr, v); } function setValueV2iArray2(gl, v) { gl.uniform2iv(this.addr, v); } function setValueV3iArray2(gl, v) { gl.uniform3iv(this.addr, v); } function setValueV4iArray2(gl, v) { gl.uniform4iv(this.addr, v); } function setValueV1uiArray2(gl, v) { gl.uniform1uiv(this.addr, v); } function setValueV2uiArray2(gl, v) { gl.uniform2uiv(this.addr, v); } function setValueV3uiArray2(gl, v) { gl.uniform3uiv(this.addr, v); } function setValueV4uiArray2(gl, v) { gl.uniform4uiv(this.addr, v); } function setValueT1Array2(gl, v, textures) { const cache = this.cache; const n = v.length; const units = allocTexUnits2(textures, n); if (!arraysEqual2(cache, units)) { gl.uniform1iv(this.addr, units); copyArray2(cache, units); } for (let i = 0; i !== n; ++i) { textures.setTexture2D(v[i] || emptyTexture2, units[i]); } } function setValueT3DArray2(gl, v, textures) { const cache = this.cache; const n = v.length; const units = allocTexUnits2(textures, n); if (!arraysEqual2(cache, units)) { gl.uniform1iv(this.addr, units); copyArray2(cache, units); } for (let i = 0; i !== n; ++i) { textures.setTexture3D(v[i] || empty3dTexture2, units[i]); } } function setValueT6Array2(gl, v, textures) { const cache = this.cache; const n = v.length; const units = allocTexUnits2(textures, n); if (!arraysEqual2(cache, units)) { gl.uniform1iv(this.addr, units); copyArray2(cache, units); } for (let i = 0; i !== n; ++i) { textures.setTextureCube(v[i] || emptyCubeTexture2, units[i]); } } function setValueT2DArrayArray2(gl, v, textures) { const cache = this.cache; const n = v.length; const units = allocTexUnits2(textures, n); if (!arraysEqual2(cache, units)) { gl.uniform1iv(this.addr, units); copyArray2(cache, units); } for (let i = 0; i !== n; ++i) { textures.setTexture2DArray(v[i] || emptyArrayTexture2, units[i]); } } function getPureArraySetter2(type) { switch (type) { case 5126: return setValueV1fArray2; case 35664: return setValueV2fArray2; case 35665: return setValueV3fArray2; case 35666: return setValueV4fArray2; case 35674: return setValueM2Array2; case 35675: return setValueM3Array2; case 35676: return setValueM4Array2; case 5124: case 35670: return setValueV1iArray2; case 35667: case 35671: return setValueV2iArray2; case 35668: case 35672: return setValueV3iArray2; case 35669: case 35673: return setValueV4iArray2; case 5125: return setValueV1uiArray2; case 36294: return setValueV2uiArray2; case 36295: return setValueV3uiArray2; case 36296: return setValueV4uiArray2; case 35678: case 36198: case 36298: case 36306: case 35682: return setValueT1Array2; case 35679: case 36299: case 36307: return setValueT3DArray2; case 35680: case 36300: case 36308: case 36293: return setValueT6Array2; case 36289: case 36303: case 36311: case 36292: return setValueT2DArrayArray2; } } var SingleUniform2 = class { constructor(id, activeInfo, addr) { this.id = id; this.addr = addr; this.cache = []; this.setValue = getSingularSetter2(activeInfo.type); } }; var PureArrayUniform2 = class { constructor(id, activeInfo, addr) { this.id = id; this.addr = addr; this.cache = []; this.size = activeInfo.size; this.setValue = getPureArraySetter2(activeInfo.type); } }; var StructuredUniform2 = class { constructor(id) { this.id = id; this.seq = []; this.map = {}; } setValue(gl, value, textures) { const seq = this.seq; for (let i = 0, n = seq.length; i !== n; ++i) { const u = seq[i]; u.setValue(gl, value[u.id], textures); } } }; var RePathPart2 = /(\w+)(\])?(\[|\.)?/g; function addUniform2(container, uniformObject) { container.seq.push(uniformObject); container.map[uniformObject.id] = uniformObject; } function parseUniform2(activeInfo, addr, container) { const path = activeInfo.name, pathLength = path.length; RePathPart2.lastIndex = 0; while (true) { const match = RePathPart2.exec(path), matchEnd = RePathPart2.lastIndex; let id = match[1]; const idIsIndex = match[2] === "]", subscript = match[3]; if (idIsIndex) id = id | 0; if (subscript === void 0 || subscript === "[" && matchEnd + 2 === pathLength) { addUniform2(container, subscript === void 0 ? new SingleUniform2(id, activeInfo, addr) : new PureArrayUniform2(id, activeInfo, addr)); break; } else { const map = container.map; let next = map[id]; if (next === void 0) { next = new StructuredUniform2(id); addUniform2(container, next); } container = next; } } } var WebGLUniforms2 = class { constructor(gl, program) { this.seq = []; this.map = {}; const n = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS); for (let i = 0; i < n; ++i) { const info = gl.getActiveUniform(program, i), addr = gl.getUniformLocation(program, info.name); parseUniform2(info, addr, this); } } setValue(gl, name, value, textures) { const u = this.map[name]; if (u !== void 0) u.setValue(gl, value, textures); } setOptional(gl, object, name) { const v = object[name]; if (v !== void 0) this.setValue(gl, name, v); } static upload(gl, seq, values, textures) { for (let i = 0, n = seq.length; i !== n; ++i) { const u = seq[i], v = values[u.id]; if (v.needsUpdate !== false) { u.setValue(gl, v.value, textures); } } } static seqWithValue(seq, values) { const r = []; for (let i = 0, n = seq.length; i !== n; ++i) { const u = seq[i]; if (u.id in values) r.push(u); } return r; } }; function WebGLShader2(gl, type, string) { const shader = gl.createShader(type); gl.shaderSource(shader, string); gl.compileShader(shader); return shader; } var programIdCount2 = 0; function handleSource2(string, errorLine) { const lines = string.split("\n"); const lines2 = []; const from = Math.max(errorLine - 6, 0); const to = Math.min(errorLine + 6, lines.length); for (let i = from; i < to; i++) { const line = i + 1; lines2.push(`${line === errorLine ? ">" : " "} ${line}: ${lines[i]}`); } return lines2.join("\n"); } function getEncodingComponents2(colorSpace) { const workingPrimaries = ColorManagement2.getPrimaries(ColorManagement2.workingColorSpace); const encodingPrimaries = ColorManagement2.getPrimaries(colorSpace); let gamutMapping; if (workingPrimaries === encodingPrimaries) { gamutMapping = ""; } else if (workingPrimaries === P3Primaries2 && encodingPrimaries === Rec709Primaries2) { gamutMapping = "LinearDisplayP3ToLinearSRGB"; } else if (workingPrimaries === Rec709Primaries2 && encodingPrimaries === P3Primaries2) { gamutMapping = "LinearSRGBToLinearDisplayP3"; } switch (colorSpace) { case LinearSRGBColorSpace2: case LinearDisplayP3ColorSpace2: return [gamutMapping, "LinearTransferOETF"]; case SRGBColorSpace2: case DisplayP3ColorSpace2: return [gamutMapping, "sRGBTransferOETF"]; default: console.warn("THREE.WebGLProgram: Unsupported color space:", colorSpace); return [gamutMapping, "LinearTransferOETF"]; } } function getShaderErrors2(gl, shader, type) { const status = gl.getShaderParameter(shader, gl.COMPILE_STATUS); const errors = gl.getShaderInfoLog(shader).trim(); if (status && errors === "") return ""; const errorMatches = /ERROR: 0:(\d+)/.exec(errors); if (errorMatches) { const errorLine = parseInt(errorMatches[1]); return type.toUpperCase() + "\n\n" + errors + "\n\n" + handleSource2(gl.getShaderSource(shader), errorLine); } else { return errors; } } function getTexelEncodingFunction2(functionName, colorSpace) { const components = getEncodingComponents2(colorSpace); return `vec4 ${functionName}( vec4 value ) { return ${components[0]}( ${components[1]}( value ) ); }`; } function getToneMappingFunction2(functionName, toneMapping) { let toneMappingName; switch (toneMapping) { case LinearToneMapping2: toneMappingName = "Linear"; break; case ReinhardToneMapping2: toneMappingName = "Reinhard"; break; case CineonToneMapping2: toneMappingName = "OptimizedCineon"; break; case ACESFilmicToneMapping2: toneMappingName = "ACESFilmic"; break; case CustomToneMapping2: toneMappingName = "Custom"; break; default: console.warn("THREE.WebGLProgram: Unsupported toneMapping:", toneMapping); toneMappingName = "Linear"; } return "vec3 " + functionName + "( vec3 color ) { return " + toneMappingName + "ToneMapping( color ); }"; } function generateExtensions2(parameters) { const chunks = [ parameters.extensionDerivatives || !!parameters.envMapCubeUVHeight || parameters.bumpMap || parameters.normalMapTangentSpace || parameters.clearcoatNormalMap || parameters.flatShading || parameters.shaderID === "physical" ? "#extension GL_OES_standard_derivatives : enable" : "", (parameters.extensionFragDepth || parameters.logarithmicDepthBuffer) && parameters.rendererExtensionFragDepth ? "#extension GL_EXT_frag_depth : enable" : "", parameters.extensionDrawBuffers && parameters.rendererExtensionDrawBuffers ? "#extension GL_EXT_draw_buffers : require" : "", (parameters.extensionShaderTextureLOD || parameters.envMap || parameters.transmission) && parameters.rendererExtensionShaderTextureLod ? "#extension GL_EXT_shader_texture_lod : enable" : "" ]; return chunks.filter(filterEmptyLine2).join("\n"); } function generateDefines2(defines) { const chunks = []; for (const name in defines) { const value = defines[name]; if (value === false) continue; chunks.push("#define " + name + " " + value); } return chunks.join("\n"); } function fetchAttributeLocations2(gl, program) { const attributes = {}; const n = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES); for (let i = 0; i < n; i++) { const info = gl.getActiveAttrib(program, i); const name = info.name; let locationSize = 1; if (info.type === gl.FLOAT_MAT2) locationSize = 2; if (info.type === gl.FLOAT_MAT3) locationSize = 3; if (info.type === gl.FLOAT_MAT4) locationSize = 4; attributes[name] = { type: info.type, location: gl.getAttribLocation(program, name), locationSize }; } return attributes; } function filterEmptyLine2(string) { return string !== ""; } function replaceLightNums2(string, parameters) { const numSpotLightCoords = parameters.numSpotLightShadows + parameters.numSpotLightMaps - parameters.numSpotLightShadowsWithMaps; return string.replace(/NUM_DIR_LIGHTS/g, parameters.numDirLights).replace(/NUM_SPOT_LIGHTS/g, parameters.numSpotLights).replace(/NUM_SPOT_LIGHT_MAPS/g, parameters.numSpotLightMaps).replace(/NUM_SPOT_LIGHT_COORDS/g, numSpotLightCoords).replace(/NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights).replace(/NUM_POINT_LIGHTS/g, parameters.numPointLights).replace(/NUM_HEMI_LIGHTS/g, parameters.numHemiLights).replace(/NUM_DIR_LIGHT_SHADOWS/g, parameters.numDirLightShadows).replace(/NUM_SPOT_LIGHT_SHADOWS_WITH_MAPS/g, parameters.numSpotLightShadowsWithMaps).replace(/NUM_SPOT_LIGHT_SHADOWS/g, parameters.numSpotLightShadows).replace(/NUM_POINT_LIGHT_SHADOWS/g, parameters.numPointLightShadows); } function replaceClippingPlaneNums2(string, parameters) { return string.replace(/NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes).replace(/UNION_CLIPPING_PLANES/g, parameters.numClippingPlanes - parameters.numClipIntersection); } var includePattern2 = /^[ \t]*#include +<([\w\d./]+)>/gm; function resolveIncludes2(string) { return string.replace(includePattern2, includeReplacer2); } var shaderChunkMap2 = /* @__PURE__ */ new Map([ ["encodings_fragment", "colorspace_fragment"], // @deprecated, r154 ["encodings_pars_fragment", "colorspace_pars_fragment"], // @deprecated, r154 ["output_fragment", "opaque_fragment"] // @deprecated, r154 ]); function includeReplacer2(match, include) { let string = ShaderChunk2[include]; if (string === void 0) { const newInclude = shaderChunkMap2.get(include); if (newInclude !== void 0) { string = ShaderChunk2[newInclude]; console.warn('THREE.WebGLRenderer: Shader chunk "%s" has been deprecated. Use "%s" instead.', include, newInclude); } else { throw new Error("Can not resolve #include <" + include + ">"); } } return resolveIncludes2(string); } var unrollLoopPattern2 = /#pragma unroll_loop_start\s+for\s*\(\s*int\s+i\s*=\s*(\d+)\s*;\s*i\s*<\s*(\d+)\s*;\s*i\s*\+\+\s*\)\s*{([\s\S]+?)}\s+#pragma unroll_loop_end/g; function unrollLoops2(string) { return string.replace(unrollLoopPattern2, loopReplacer2); } function loopReplacer2(match, start, end, snippet) { let string = ""; for (let i = parseInt(start); i < parseInt(end); i++) { string += snippet.replace(/\[\s*i\s*\]/g, "[ " + i + " ]").replace(/UNROLLED_LOOP_INDEX/g, i); } return string; } function generatePrecision2(parameters) { let precisionstring = "precision " + parameters.precision + " float;\nprecision " + parameters.precision + " int;"; if (parameters.precision === "highp") { precisionstring += "\n#define HIGH_PRECISION"; } else if (parameters.precision === "mediump") { precisionstring += "\n#define MEDIUM_PRECISION"; } else if (parameters.precision === "lowp") { precisionstring += "\n#define LOW_PRECISION"; } return precisionstring; } function generateShadowMapTypeDefine2(parameters) { let shadowMapTypeDefine = "SHADOWMAP_TYPE_BASIC"; if (parameters.shadowMapType === PCFShadowMap2) { shadowMapTypeDefine = "SHADOWMAP_TYPE_PCF"; } else if (parameters.shadowMapType === PCFSoftShadowMap2) { shadowMapTypeDefine = "SHADOWMAP_TYPE_PCF_SOFT"; } else if (parameters.shadowMapType === VSMShadowMap2) { shadowMapTypeDefine = "SHADOWMAP_TYPE_VSM"; } return shadowMapTypeDefine; } function generateEnvMapTypeDefine2(parameters) { let envMapTypeDefine = "ENVMAP_TYPE_CUBE"; if (parameters.envMap) { switch (parameters.envMapMode) { case CubeReflectionMapping2: case CubeRefractionMapping2: envMapTypeDefine = "ENVMAP_TYPE_CUBE"; break; case CubeUVReflectionMapping2: envMapTypeDefine = "ENVMAP_TYPE_CUBE_UV"; break; } } return envMapTypeDefine; } function generateEnvMapModeDefine2(parameters) { let envMapModeDefine = "ENVMAP_MODE_REFLECTION"; if (parameters.envMap) { switch (parameters.envMapMode) { case CubeRefractionMapping2: envMapModeDefine = "ENVMAP_MODE_REFRACTION"; break; } } return envMapModeDefine; } function generateEnvMapBlendingDefine2(parameters) { let envMapBlendingDefine = "ENVMAP_BLENDING_NONE"; if (parameters.envMap) { switch (parameters.combine) { case MultiplyOperation2: envMapBlendingDefine = "ENVMAP_BLENDING_MULTIPLY"; break; case MixOperation2: envMapBlendingDefine = "ENVMAP_BLENDING_MIX"; break; case AddOperation2: envMapBlendingDefine = "ENVMAP_BLENDING_ADD"; break; } } return envMapBlendingDefine; } function generateCubeUVSize2(parameters) { const imageHeight = parameters.envMapCubeUVHeight; if (imageHeight === null) return null; const maxMip = Math.log2(imageHeight) - 2; const texelHeight = 1 / imageHeight; const texelWidth = 1 / (3 * Math.max(Math.pow(2, maxMip), 7 * 16)); return { texelWidth, texelHeight, maxMip }; } function WebGLProgram2(renderer3, cacheKey, parameters, bindingStates) { const gl = renderer3.getContext(); const defines = parameters.defines; let vertexShader = parameters.vertexShader; let fragmentShader = parameters.fragmentShader; const shadowMapTypeDefine = generateShadowMapTypeDefine2(parameters); const envMapTypeDefine = generateEnvMapTypeDefine2(parameters); const envMapModeDefine = generateEnvMapModeDefine2(parameters); const envMapBlendingDefine = generateEnvMapBlendingDefine2(parameters); const envMapCubeUVSize = generateCubeUVSize2(parameters); const customExtensions = parameters.isWebGL2 ? "" : generateExtensions2(parameters); const customDefines = generateDefines2(defines); const program = gl.createProgram(); let prefixVertex, prefixFragment; let versionString = parameters.glslVersion ? "#version " + parameters.glslVersion + "\n" : ""; if (parameters.isRawShaderMaterial) { prefixVertex = [ "#define SHADER_TYPE " + parameters.shaderType, "#define SHADER_NAME " + parameters.shaderName, customDefines ].filter(filterEmptyLine2).join("\n"); if (prefixVertex.length > 0) { prefixVertex += "\n"; } prefixFragment = [ customExtensions, "#define SHADER_TYPE " + parameters.shaderType, "#define SHADER_NAME " + parameters.shaderName, customDefines ].filter(filterEmptyLine2).join("\n"); if (prefixFragment.length > 0) { prefixFragment += "\n"; } } else { prefixVertex = [ generatePrecision2(parameters), "#define SHADER_TYPE " + parameters.shaderType, "#define SHADER_NAME " + parameters.shaderName, customDefines, parameters.instancing ? "#define USE_INSTANCING" : "", parameters.instancingColor ? "#define USE_INSTANCING_COLOR" : "", parameters.useFog && parameters.fog ? "#define USE_FOG" : "", parameters.useFog && parameters.fogExp2 ? "#define FOG_EXP2" : "", parameters.map ? "#define USE_MAP" : "", parameters.envMap ? "#define USE_ENVMAP" : "", parameters.envMap ? "#define " + envMapModeDefine : "", parameters.lightMap ? "#define USE_LIGHTMAP" : "", parameters.aoMap ? "#define USE_AOMAP" : "", parameters.bumpMap ? "#define USE_BUMPMAP" : "", parameters.normalMap ? "#define USE_NORMALMAP" : "", parameters.normalMapObjectSpace ? "#define USE_NORMALMAP_OBJECTSPACE" : "", parameters.normalMapTangentSpace ? "#define USE_NORMALMAP_TANGENTSPACE" : "", parameters.displacementMap ? "#define USE_DISPLACEMENTMAP" : "", parameters.emissiveMap ? "#define USE_EMISSIVEMAP" : "", parameters.anisotropy ? "#define USE_ANISOTROPY" : "", parameters.anisotropyMap ? "#define USE_ANISOTROPYMAP" : "", parameters.clearcoatMap ? "#define USE_CLEARCOATMAP" : "", parameters.clearcoatRoughnessMap ? "#define USE_CLEARCOAT_ROUGHNESSMAP" : "", parameters.clearcoatNormalMap ? "#define USE_CLEARCOAT_NORMALMAP" : "", parameters.iridescenceMap ? "#define USE_IRIDESCENCEMAP" : "", parameters.iridescenceThicknessMap ? "#define USE_IRIDESCENCE_THICKNESSMAP" : "", parameters.specularMap ? "#define USE_SPECULARMAP" : "", parameters.specularColorMap ? "#define USE_SPECULAR_COLORMAP" : "", parameters.specularIntensityMap ? "#define USE_SPECULAR_INTENSITYMAP" : "", parameters.roughnessMap ? "#define USE_ROUGHNESSMAP" : "", parameters.metalnessMap ? "#define USE_METALNESSMAP" : "", parameters.alphaMap ? "#define USE_ALPHAMAP" : "", parameters.alphaHash ? "#define USE_ALPHAHASH" : "", parameters.transmission ? "#define USE_TRANSMISSION" : "", parameters.transmissionMap ? "#define USE_TRANSMISSIONMAP" : "", parameters.thicknessMap ? "#define USE_THICKNESSMAP" : "", parameters.sheenColorMap ? "#define USE_SHEEN_COLORMAP" : "", parameters.sheenRoughnessMap ? "#define USE_SHEEN_ROUGHNESSMAP" : "", // parameters.mapUv ? "#define MAP_UV " + parameters.mapUv : "", parameters.alphaMapUv ? "#define ALPHAMAP_UV " + parameters.alphaMapUv : "", parameters.lightMapUv ? "#define LIGHTMAP_UV " + parameters.lightMapUv : "", parameters.aoMapUv ? "#define AOMAP_UV " + parameters.aoMapUv : "", parameters.emissiveMapUv ? "#define EMISSIVEMAP_UV " + parameters.emissiveMapUv : "", parameters.bumpMapUv ? "#define BUMPMAP_UV " + parameters.bumpMapUv : "", parameters.normalMapUv ? "#define NORMALMAP_UV " + parameters.normalMapUv : "", parameters.displacementMapUv ? "#define DISPLACEMENTMAP_UV " + parameters.displacementMapUv : "", parameters.metalnessMapUv ? "#define METALNESSMAP_UV " + parameters.metalnessMapUv : "", parameters.roughnessMapUv ? "#define ROUGHNESSMAP_UV " + parameters.roughnessMapUv : "", parameters.anisotropyMapUv ? "#define ANISOTROPYMAP_UV " + parameters.anisotropyMapUv : "", parameters.clearcoatMapUv ? "#define CLEARCOATMAP_UV " + parameters.clearcoatMapUv : "", parameters.clearcoatNormalMapUv ? "#define CLEARCOAT_NORMALMAP_UV " + parameters.clearcoatNormalMapUv : "", parameters.clearcoatRoughnessMapUv ? "#define CLEARCOAT_ROUGHNESSMAP_UV " + parameters.clearcoatRoughnessMapUv : "", parameters.iridescenceMapUv ? "#define IRIDESCENCEMAP_UV " + parameters.iridescenceMapUv : "", parameters.iridescenceThicknessMapUv ? "#define IRIDESCENCE_THICKNESSMAP_UV " + parameters.iridescenceThicknessMapUv : "", parameters.sheenColorMapUv ? "#define SHEEN_COLORMAP_UV " + parameters.sheenColorMapUv : "", parameters.sheenRoughnessMapUv ? "#define SHEEN_ROUGHNESSMAP_UV " + parameters.sheenRoughnessMapUv : "", parameters.specularMapUv ? "#define SPECULARMAP_UV " + parameters.specularMapUv : "", parameters.specularColorMapUv ? "#define SPECULAR_COLORMAP_UV " + parameters.specularColorMapUv : "", parameters.specularIntensityMapUv ? "#define SPECULAR_INTENSITYMAP_UV " + parameters.specularIntensityMapUv : "", parameters.transmissionMapUv ? "#define TRANSMISSIONMAP_UV " + parameters.transmissionMapUv : "", parameters.thicknessMapUv ? "#define THICKNESSMAP_UV " + parameters.thicknessMapUv : "", // parameters.vertexTangents && parameters.flatShading === false ? "#define USE_TANGENT" : "", parameters.vertexColors ? "#define USE_COLOR" : "", parameters.vertexAlphas ? "#define USE_COLOR_ALPHA" : "", parameters.vertexUv1s ? "#define USE_UV1" : "", parameters.vertexUv2s ? "#define USE_UV2" : "", parameters.vertexUv3s ? "#define USE_UV3" : "", parameters.pointsUvs ? "#define USE_POINTS_UV" : "", parameters.flatShading ? "#define FLAT_SHADED" : "", parameters.skinning ? "#define USE_SKINNING" : "", parameters.morphTargets ? "#define USE_MORPHTARGETS" : "", parameters.morphNormals && parameters.flatShading === false ? "#define USE_MORPHNORMALS" : "", parameters.morphColors && parameters.isWebGL2 ? "#define USE_MORPHCOLORS" : "", parameters.morphTargetsCount > 0 && parameters.isWebGL2 ? "#define MORPHTARGETS_TEXTURE" : "", parameters.morphTargetsCount > 0 && parameters.isWebGL2 ? "#define MORPHTARGETS_TEXTURE_STRIDE " + parameters.morphTextureStride : "", parameters.morphTargetsCount > 0 && parameters.isWebGL2 ? "#define MORPHTARGETS_COUNT " + parameters.morphTargetsCount : "", parameters.doubleSided ? "#define DOUBLE_SIDED" : "", parameters.flipSided ? "#define FLIP_SIDED" : "", parameters.shadowMapEnabled ? "#define USE_SHADOWMAP" : "", parameters.shadowMapEnabled ? "#define " + shadowMapTypeDefine : "", parameters.sizeAttenuation ? "#define USE_SIZEATTENUATION" : "", parameters.numLightProbes > 0 ? "#define USE_LIGHT_PROBES" : "", parameters.useLegacyLights ? "#define LEGACY_LIGHTS" : "", parameters.logarithmicDepthBuffer ? "#define USE_LOGDEPTHBUF" : "", parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ? "#define USE_LOGDEPTHBUF_EXT" : "", "uniform mat4 modelMatrix;", "uniform mat4 modelViewMatrix;", "uniform mat4 projectionMatrix;", "uniform mat4 viewMatrix;", "uniform mat3 normalMatrix;", "uniform vec3 cameraPosition;", "uniform bool isOrthographic;", "#ifdef USE_INSTANCING", " attribute mat4 instanceMatrix;", "#endif", "#ifdef USE_INSTANCING_COLOR", " attribute vec3 instanceColor;", "#endif", "attribute vec3 position;", "attribute vec3 normal;", "attribute vec2 uv;", "#ifdef USE_UV1", " attribute vec2 uv1;", "#endif", "#ifdef USE_UV2", " attribute vec2 uv2;", "#endif", "#ifdef USE_UV3", " attribute vec2 uv3;", "#endif", "#ifdef USE_TANGENT", " attribute vec4 tangent;", "#endif", "#if defined( USE_COLOR_ALPHA )", " attribute vec4 color;", "#elif defined( USE_COLOR )", " attribute vec3 color;", "#endif", "#if ( defined( USE_MORPHTARGETS ) && ! defined( MORPHTARGETS_TEXTURE ) )", " attribute vec3 morphTarget0;", " attribute vec3 morphTarget1;", " attribute vec3 morphTarget2;", " attribute vec3 morphTarget3;", " #ifdef USE_MORPHNORMALS", " attribute vec3 morphNormal0;", " attribute vec3 morphNormal1;", " attribute vec3 morphNormal2;", " attribute vec3 morphNormal3;", " #else", " attribute vec3 morphTarget4;", " attribute vec3 morphTarget5;", " attribute vec3 morphTarget6;", " attribute vec3 morphTarget7;", " #endif", "#endif", "#ifdef USE_SKINNING", " attribute vec4 skinIndex;", " attribute vec4 skinWeight;", "#endif", "\n" ].filter(filterEmptyLine2).join("\n"); prefixFragment = [ customExtensions, generatePrecision2(parameters), "#define SHADER_TYPE " + parameters.shaderType, "#define SHADER_NAME " + parameters.shaderName, customDefines, parameters.useFog && parameters.fog ? "#define USE_FOG" : "", parameters.useFog && parameters.fogExp2 ? "#define FOG_EXP2" : "", parameters.map ? "#define USE_MAP" : "", parameters.matcap ? "#define USE_MATCAP" : "", parameters.envMap ? "#define USE_ENVMAP" : "", parameters.envMap ? "#define " + envMapTypeDefine : "", parameters.envMap ? "#define " + envMapModeDefine : "", parameters.envMap ? "#define " + envMapBlendingDefine : "", envMapCubeUVSize ? "#define CUBEUV_TEXEL_WIDTH " + envMapCubeUVSize.texelWidth : "", envMapCubeUVSize ? "#define CUBEUV_TEXEL_HEIGHT " + envMapCubeUVSize.texelHeight : "", envMapCubeUVSize ? "#define CUBEUV_MAX_MIP " + envMapCubeUVSize.maxMip + ".0" : "", parameters.lightMap ? "#define USE_LIGHTMAP" : "", parameters.aoMap ? "#define USE_AOMAP" : "", parameters.bumpMap ? "#define USE_BUMPMAP" : "", parameters.normalMap ? "#define USE_NORMALMAP" : "", parameters.normalMapObjectSpace ? "#define USE_NORMALMAP_OBJECTSPACE" : "", parameters.normalMapTangentSpace ? "#define USE_NORMALMAP_TANGENTSPACE" : "", parameters.emissiveMap ? "#define USE_EMISSIVEMAP" : "", parameters.anisotropy ? "#define USE_ANISOTROPY" : "", parameters.anisotropyMap ? "#define USE_ANISOTROPYMAP" : "", parameters.clearcoat ? "#define USE_CLEARCOAT" : "", parameters.clearcoatMap ? "#define USE_CLEARCOATMAP" : "", parameters.clearcoatRoughnessMap ? "#define USE_CLEARCOAT_ROUGHNESSMAP" : "", parameters.clearcoatNormalMap ? "#define USE_CLEARCOAT_NORMALMAP" : "", parameters.iridescence ? "#define USE_IRIDESCENCE" : "", parameters.iridescenceMap ? "#define USE_IRIDESCENCEMAP" : "", parameters.iridescenceThicknessMap ? "#define USE_IRIDESCENCE_THICKNESSMAP" : "", parameters.specularMap ? "#define USE_SPECULARMAP" : "", parameters.specularColorMap ? "#define USE_SPECULAR_COLORMAP" : "", parameters.specularIntensityMap ? "#define USE_SPECULAR_INTENSITYMAP" : "", parameters.roughnessMap ? "#define USE_ROUGHNESSMAP" : "", parameters.metalnessMap ? "#define USE_METALNESSMAP" : "", parameters.alphaMap ? "#define USE_ALPHAMAP" : "", parameters.alphaTest ? "#define USE_ALPHATEST" : "", parameters.alphaHash ? "#define USE_ALPHAHASH" : "", parameters.sheen ? "#define USE_SHEEN" : "", parameters.sheenColorMap ? "#define USE_SHEEN_COLORMAP" : "", parameters.sheenRoughnessMap ? "#define USE_SHEEN_ROUGHNESSMAP" : "", parameters.transmission ? "#define USE_TRANSMISSION" : "", parameters.transmissionMap ? "#define USE_TRANSMISSIONMAP" : "", parameters.thicknessMap ? "#define USE_THICKNESSMAP" : "", parameters.vertexTangents && parameters.flatShading === false ? "#define USE_TANGENT" : "", parameters.vertexColors || parameters.instancingColor ? "#define USE_COLOR" : "", parameters.vertexAlphas ? "#define USE_COLOR_ALPHA" : "", parameters.vertexUv1s ? "#define USE_UV1" : "", parameters.vertexUv2s ? "#define USE_UV2" : "", parameters.vertexUv3s ? "#define USE_UV3" : "", parameters.pointsUvs ? "#define USE_POINTS_UV" : "", parameters.gradientMap ? "#define USE_GRADIENTMAP" : "", parameters.flatShading ? "#define FLAT_SHADED" : "", parameters.doubleSided ? "#define DOUBLE_SIDED" : "", parameters.flipSided ? "#define FLIP_SIDED" : "", parameters.shadowMapEnabled ? "#define USE_SHADOWMAP" : "", parameters.shadowMapEnabled ? "#define " + shadowMapTypeDefine : "", parameters.premultipliedAlpha ? "#define PREMULTIPLIED_ALPHA" : "", parameters.numLightProbes > 0 ? "#define USE_LIGHT_PROBES" : "", parameters.useLegacyLights ? "#define LEGACY_LIGHTS" : "", parameters.decodeVideoTexture ? "#define DECODE_VIDEO_TEXTURE" : "", parameters.logarithmicDepthBuffer ? "#define USE_LOGDEPTHBUF" : "", parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ? "#define USE_LOGDEPTHBUF_EXT" : "", "uniform mat4 viewMatrix;", "uniform vec3 cameraPosition;", "uniform bool isOrthographic;", parameters.toneMapping !== NoToneMapping2 ? "#define TONE_MAPPING" : "", parameters.toneMapping !== NoToneMapping2 ? ShaderChunk2["tonemapping_pars_fragment"] : "", // this code is required here because it is used by the toneMapping() function defined below parameters.toneMapping !== NoToneMapping2 ? getToneMappingFunction2("toneMapping", parameters.toneMapping) : "", parameters.dithering ? "#define DITHERING" : "", parameters.opaque ? "#define OPAQUE" : "", ShaderChunk2["colorspace_pars_fragment"], // this code is required here because it is used by the various encoding/decoding function defined below getTexelEncodingFunction2("linearToOutputTexel", parameters.outputColorSpace), parameters.useDepthPacking ? "#define DEPTH_PACKING " + parameters.depthPacking : "", "\n" ].filter(filterEmptyLine2).join("\n"); } vertexShader = resolveIncludes2(vertexShader); vertexShader = replaceLightNums2(vertexShader, parameters); vertexShader = replaceClippingPlaneNums2(vertexShader, parameters); fragmentShader = resolveIncludes2(fragmentShader); fragmentShader = replaceLightNums2(fragmentShader, parameters); fragmentShader = replaceClippingPlaneNums2(fragmentShader, parameters); vertexShader = unrollLoops2(vertexShader); fragmentShader = unrollLoops2(fragmentShader); if (parameters.isWebGL2 && parameters.isRawShaderMaterial !== true) { versionString = "#version 300 es\n"; prefixVertex = [ "precision mediump sampler2DArray;", "#define attribute in", "#define varying out", "#define texture2D texture" ].join("\n") + "\n" + prefixVertex; prefixFragment = [ "#define varying in", parameters.glslVersion === GLSL32 ? "" : "layout(location = 0) out highp vec4 pc_fragColor;", parameters.glslVersion === GLSL32 ? "" : "#define gl_FragColor pc_fragColor", "#define gl_FragDepthEXT gl_FragDepth", "#define texture2D texture", "#define textureCube texture", "#define texture2DProj textureProj", "#define texture2DLodEXT textureLod", "#define texture2DProjLodEXT textureProjLod", "#define textureCubeLodEXT textureLod", "#define texture2DGradEXT textureGrad", "#define texture2DProjGradEXT textureProjGrad", "#define textureCubeGradEXT textureGrad" ].join("\n") + "\n" + prefixFragment; } const vertexGlsl = versionString + prefixVertex + vertexShader; const fragmentGlsl = versionString + prefixFragment + fragmentShader; const glVertexShader = WebGLShader2(gl, gl.VERTEX_SHADER, vertexGlsl); const glFragmentShader = WebGLShader2(gl, gl.FRAGMENT_SHADER, fragmentGlsl); gl.attachShader(program, glVertexShader); gl.attachShader(program, glFragmentShader); if (parameters.index0AttributeName !== void 0) { gl.bindAttribLocation(program, 0, parameters.index0AttributeName); } else if (parameters.morphTargets === true) { gl.bindAttribLocation(program, 0, "position"); } gl.linkProgram(program); if (renderer3.debug.checkShaderErrors) { const programLog = gl.getProgramInfoLog(program).trim(); const vertexLog = gl.getShaderInfoLog(glVertexShader).trim(); const fragmentLog = gl.getShaderInfoLog(glFragmentShader).trim(); let runnable = true; let haveDiagnostics = true; if (gl.getProgramParameter(program, gl.LINK_STATUS) === false) { runnable = false; if (typeof renderer3.debug.onShaderError === "function") { renderer3.debug.onShaderError(gl, program, glVertexShader, glFragmentShader); } else { const vertexErrors = getShaderErrors2(gl, glVertexShader, "vertex"); const fragmentErrors = getShaderErrors2(gl, glFragmentShader, "fragment"); console.error( "THREE.WebGLProgram: Shader Error " + gl.getError() + " - VALIDATE_STATUS " + gl.getProgramParameter(program, gl.VALIDATE_STATUS) + "\n\nProgram Info Log: " + programLog + "\n" + vertexErrors + "\n" + fragmentErrors ); } } else if (programLog !== "") { console.warn("THREE.WebGLProgram: Program Info Log:", programLog); } else if (vertexLog === "" || fragmentLog === "") { haveDiagnostics = false; } if (haveDiagnostics) { this.diagnostics = { runnable, programLog, vertexShader: { log: vertexLog, prefix: prefixVertex }, fragmentShader: { log: fragmentLog, prefix: prefixFragment } }; } } gl.deleteShader(glVertexShader); gl.deleteShader(glFragmentShader); let cachedUniforms; this.getUniforms = function() { if (cachedUniforms === void 0) { cachedUniforms = new WebGLUniforms2(gl, program); } return cachedUniforms; }; let cachedAttributes; this.getAttributes = function() { if (cachedAttributes === void 0) { cachedAttributes = fetchAttributeLocations2(gl, program); } return cachedAttributes; }; this.destroy = function() { bindingStates.releaseStatesOfProgram(this); gl.deleteProgram(program); this.program = void 0; }; this.type = parameters.shaderType; this.name = parameters.shaderName; this.id = programIdCount2++; this.cacheKey = cacheKey; this.usedTimes = 1; this.program = program; this.vertexShader = glVertexShader; this.fragmentShader = glFragmentShader; return this; } var _id$12 = 0; var WebGLShaderCache2 = class { constructor() { this.shaderCache = /* @__PURE__ */ new Map(); this.materialCache = /* @__PURE__ */ new Map(); } update(material) { const vertexShader = material.vertexShader; const fragmentShader = material.fragmentShader; const vertexShaderStage = this._getShaderStage(vertexShader); const fragmentShaderStage = this._getShaderStage(fragmentShader); const materialShaders = this._getShaderCacheForMaterial(material); if (materialShaders.has(vertexShaderStage) === false) { materialShaders.add(vertexShaderStage); vertexShaderStage.usedTimes++; } if (materialShaders.has(fragmentShaderStage) === false) { materialShaders.add(fragmentShaderStage); fragmentShaderStage.usedTimes++; } return this; } remove(material) { const materialShaders = this.materialCache.get(material); for (const shaderStage of materialShaders) { shaderStage.usedTimes--; if (shaderStage.usedTimes === 0) this.shaderCache.delete(shaderStage.code); } this.materialCache.delete(material); return this; } getVertexShaderID(material) { return this._getShaderStage(material.vertexShader).id; } getFragmentShaderID(material) { return this._getShaderStage(material.fragmentShader).id; } dispose() { this.shaderCache.clear(); this.materialCache.clear(); } _getShaderCacheForMaterial(material) { const cache = this.materialCache; let set2 = cache.get(material); if (set2 === void 0) { set2 = /* @__PURE__ */ new Set(); cache.set(material, set2); } return set2; } _getShaderStage(code) { const cache = this.shaderCache; let stage = cache.get(code); if (stage === void 0) { stage = new WebGLShaderStage2(code); cache.set(code, stage); } return stage; } }; var WebGLShaderStage2 = class { constructor(code) { this.id = _id$12++; this.code = code; this.usedTimes = 0; } }; function WebGLPrograms2(renderer3, cubemaps, cubeuvmaps, extensions, capabilities, bindingStates, clipping) { const _programLayers = new Layers2(); const _customShaders = new WebGLShaderCache2(); const programs = []; const IS_WEBGL2 = capabilities.isWebGL2; const logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer; const SUPPORTS_VERTEX_TEXTURES = capabilities.vertexTextures; let precision = capabilities.precision; const shaderIDs = { MeshDepthMaterial: "depth", MeshDistanceMaterial: "distanceRGBA", MeshNormalMaterial: "normal", MeshBasicMaterial: "basic", MeshLambertMaterial: "lambert", MeshPhongMaterial: "phong", MeshToonMaterial: "toon", MeshStandardMaterial: "physical", MeshPhysicalMaterial: "physical", MeshMatcapMaterial: "matcap", LineBasicMaterial: "basic", LineDashedMaterial: "dashed", PointsMaterial: "points", ShadowMaterial: "shadow", SpriteMaterial: "sprite" }; function getChannel(value) { if (value === 0) return "uv"; return `uv${value}`; } function getParameters(material, lights, shadows, scene3, object) { const fog = scene3.fog; const geometry = object.geometry; const environment = material.isMeshStandardMaterial ? scene3.environment : null; const envMap = (material.isMeshStandardMaterial ? cubeuvmaps : cubemaps).get(material.envMap || environment); const envMapCubeUVHeight = !!envMap && envMap.mapping === CubeUVReflectionMapping2 ? envMap.image.height : null; const shaderID = shaderIDs[material.type]; if (material.precision !== null) { precision = capabilities.getMaxPrecision(material.precision); if (precision !== material.precision) { console.warn("THREE.WebGLProgram.getParameters:", material.precision, "not supported, using", precision, "instead."); } } const morphAttribute = geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color; const morphTargetsCount = morphAttribute !== void 0 ? morphAttribute.length : 0; let morphTextureStride = 0; if (geometry.morphAttributes.position !== void 0) morphTextureStride = 1; if (geometry.morphAttributes.normal !== void 0) morphTextureStride = 2; if (geometry.morphAttributes.color !== void 0) morphTextureStride = 3; let vertexShader, fragmentShader; let customVertexShaderID, customFragmentShaderID; if (shaderID) { const shader = ShaderLib2[shaderID]; vertexShader = shader.vertexShader; fragmentShader = shader.fragmentShader; } else { vertexShader = material.vertexShader; fragmentShader = material.fragmentShader; _customShaders.update(material); customVertexShaderID = _customShaders.getVertexShaderID(material); customFragmentShaderID = _customShaders.getFragmentShaderID(material); } const currentRenderTarget = renderer3.getRenderTarget(); const IS_INSTANCEDMESH = object.isInstancedMesh === true; const HAS_MAP = !!material.map; const HAS_MATCAP = !!material.matcap; const HAS_ENVMAP = !!envMap; const HAS_AOMAP = !!material.aoMap; const HAS_LIGHTMAP = !!material.lightMap; const HAS_BUMPMAP = !!material.bumpMap; const HAS_NORMALMAP = !!material.normalMap; const HAS_DISPLACEMENTMAP = !!material.displacementMap; const HAS_EMISSIVEMAP = !!material.emissiveMap; const HAS_METALNESSMAP = !!material.metalnessMap; const HAS_ROUGHNESSMAP = !!material.roughnessMap; const HAS_ANISOTROPY = material.anisotropy > 0; const HAS_CLEARCOAT = material.clearcoat > 0; const HAS_IRIDESCENCE = material.iridescence > 0; const HAS_SHEEN = material.sheen > 0; const HAS_TRANSMISSION = material.transmission > 0; const HAS_ANISOTROPYMAP = HAS_ANISOTROPY && !!material.anisotropyMap; const HAS_CLEARCOATMAP = HAS_CLEARCOAT && !!material.clearcoatMap; const HAS_CLEARCOAT_NORMALMAP = HAS_CLEARCOAT && !!material.clearcoatNormalMap; const HAS_CLEARCOAT_ROUGHNESSMAP = HAS_CLEARCOAT && !!material.clearcoatRoughnessMap; const HAS_IRIDESCENCEMAP = HAS_IRIDESCENCE && !!material.iridescenceMap; const HAS_IRIDESCENCE_THICKNESSMAP = HAS_IRIDESCENCE && !!material.iridescenceThicknessMap; const HAS_SHEEN_COLORMAP = HAS_SHEEN && !!material.sheenColorMap; const HAS_SHEEN_ROUGHNESSMAP = HAS_SHEEN && !!material.sheenRoughnessMap; const HAS_SPECULARMAP = !!material.specularMap; const HAS_SPECULAR_COLORMAP = !!material.specularColorMap; const HAS_SPECULAR_INTENSITYMAP = !!material.specularIntensityMap; const HAS_TRANSMISSIONMAP = HAS_TRANSMISSION && !!material.transmissionMap; const HAS_THICKNESSMAP = HAS_TRANSMISSION && !!material.thicknessMap; const HAS_GRADIENTMAP = !!material.gradientMap; const HAS_ALPHAMAP = !!material.alphaMap; const HAS_ALPHATEST = material.alphaTest > 0; const HAS_ALPHAHASH = !!material.alphaHash; const HAS_EXTENSIONS = !!material.extensions; const HAS_ATTRIBUTE_UV1 = !!geometry.attributes.uv1; const HAS_ATTRIBUTE_UV2 = !!geometry.attributes.uv2; const HAS_ATTRIBUTE_UV3 = !!geometry.attributes.uv3; let toneMapping = NoToneMapping2; if (material.toneMapped) { if (currentRenderTarget === null || currentRenderTarget.isXRRenderTarget === true) { toneMapping = renderer3.toneMapping; } } const parameters = { isWebGL2: IS_WEBGL2, shaderID, shaderType: material.type, shaderName: material.name, vertexShader, fragmentShader, defines: material.defines, customVertexShaderID, customFragmentShaderID, isRawShaderMaterial: material.isRawShaderMaterial === true, glslVersion: material.glslVersion, precision, instancing: IS_INSTANCEDMESH, instancingColor: IS_INSTANCEDMESH && object.instanceColor !== null, supportsVertexTextures: SUPPORTS_VERTEX_TEXTURES, outputColorSpace: currentRenderTarget === null ? renderer3.outputColorSpace : currentRenderTarget.isXRRenderTarget === true ? currentRenderTarget.texture.colorSpace : LinearSRGBColorSpace2, map: HAS_MAP, matcap: HAS_MATCAP, envMap: HAS_ENVMAP, envMapMode: HAS_ENVMAP && envMap.mapping, envMapCubeUVHeight, aoMap: HAS_AOMAP, lightMap: HAS_LIGHTMAP, bumpMap: HAS_BUMPMAP, normalMap: HAS_NORMALMAP, displacementMap: SUPPORTS_VERTEX_TEXTURES && HAS_DISPLACEMENTMAP, emissiveMap: HAS_EMISSIVEMAP, normalMapObjectSpace: HAS_NORMALMAP && material.normalMapType === ObjectSpaceNormalMap2, normalMapTangentSpace: HAS_NORMALMAP && material.normalMapType === TangentSpaceNormalMap2, metalnessMap: HAS_METALNESSMAP, roughnessMap: HAS_ROUGHNESSMAP, anisotropy: HAS_ANISOTROPY, anisotropyMap: HAS_ANISOTROPYMAP, clearcoat: HAS_CLEARCOAT, clearcoatMap: HAS_CLEARCOATMAP, clearcoatNormalMap: HAS_CLEARCOAT_NORMALMAP, clearcoatRoughnessMap: HAS_CLEARCOAT_ROUGHNESSMAP, iridescence: HAS_IRIDESCENCE, iridescenceMap: HAS_IRIDESCENCEMAP, iridescenceThicknessMap: HAS_IRIDESCENCE_THICKNESSMAP, sheen: HAS_SHEEN, sheenColorMap: HAS_SHEEN_COLORMAP, sheenRoughnessMap: HAS_SHEEN_ROUGHNESSMAP, specularMap: HAS_SPECULARMAP, specularColorMap: HAS_SPECULAR_COLORMAP, specularIntensityMap: HAS_SPECULAR_INTENSITYMAP, transmission: HAS_TRANSMISSION, transmissionMap: HAS_TRANSMISSIONMAP, thicknessMap: HAS_THICKNESSMAP, gradientMap: HAS_GRADIENTMAP, opaque: material.transparent === false && material.blending === NormalBlending2, alphaMap: HAS_ALPHAMAP, alphaTest: HAS_ALPHATEST, alphaHash: HAS_ALPHAHASH, combine: material.combine, // mapUv: HAS_MAP && getChannel(material.map.channel), aoMapUv: HAS_AOMAP && getChannel(material.aoMap.channel), lightMapUv: HAS_LIGHTMAP && getChannel(material.lightMap.channel), bumpMapUv: HAS_BUMPMAP && getChannel(material.bumpMap.channel), normalMapUv: HAS_NORMALMAP && getChannel(material.normalMap.channel), displacementMapUv: HAS_DISPLACEMENTMAP && getChannel(material.displacementMap.channel), emissiveMapUv: HAS_EMISSIVEMAP && getChannel(material.emissiveMap.channel), metalnessMapUv: HAS_METALNESSMAP && getChannel(material.metalnessMap.channel), roughnessMapUv: HAS_ROUGHNESSMAP && getChannel(material.roughnessMap.channel), anisotropyMapUv: HAS_ANISOTROPYMAP && getChannel(material.anisotropyMap.channel), clearcoatMapUv: HAS_CLEARCOATMAP && getChannel(material.clearcoatMap.channel), clearcoatNormalMapUv: HAS_CLEARCOAT_NORMALMAP && getChannel(material.clearcoatNormalMap.channel), clearcoatRoughnessMapUv: HAS_CLEARCOAT_ROUGHNESSMAP && getChannel(material.clearcoatRoughnessMap.channel), iridescenceMapUv: HAS_IRIDESCENCEMAP && getChannel(material.iridescenceMap.channel), iridescenceThicknessMapUv: HAS_IRIDESCENCE_THICKNESSMAP && getChannel(material.iridescenceThicknessMap.channel), sheenColorMapUv: HAS_SHEEN_COLORMAP && getChannel(material.sheenColorMap.channel), sheenRoughnessMapUv: HAS_SHEEN_ROUGHNESSMAP && getChannel(material.sheenRoughnessMap.channel), specularMapUv: HAS_SPECULARMAP && getChannel(material.specularMap.channel), specularColorMapUv: HAS_SPECULAR_COLORMAP && getChannel(material.specularColorMap.channel), specularIntensityMapUv: HAS_SPECULAR_INTENSITYMAP && getChannel(material.specularIntensityMap.channel), transmissionMapUv: HAS_TRANSMISSIONMAP && getChannel(material.transmissionMap.channel), thicknessMapUv: HAS_THICKNESSMAP && getChannel(material.thicknessMap.channel), alphaMapUv: HAS_ALPHAMAP && getChannel(material.alphaMap.channel), // vertexTangents: !!geometry.attributes.tangent && (HAS_NORMALMAP || HAS_ANISOTROPY), vertexColors: material.vertexColors, vertexAlphas: material.vertexColors === true && !!geometry.attributes.color && geometry.attributes.color.itemSize === 4, vertexUv1s: HAS_ATTRIBUTE_UV1, vertexUv2s: HAS_ATTRIBUTE_UV2, vertexUv3s: HAS_ATTRIBUTE_UV3, pointsUvs: object.isPoints === true && !!geometry.attributes.uv && (HAS_MAP || HAS_ALPHAMAP), fog: !!fog, useFog: material.fog === true, fogExp2: fog && fog.isFogExp2, flatShading: material.flatShading === true, sizeAttenuation: material.sizeAttenuation === true, logarithmicDepthBuffer, skinning: object.isSkinnedMesh === true, morphTargets: geometry.morphAttributes.position !== void 0, morphNormals: geometry.morphAttributes.normal !== void 0, morphColors: geometry.morphAttributes.color !== void 0, morphTargetsCount, morphTextureStride, numDirLights: lights.directional.length, numPointLights: lights.point.length, numSpotLights: lights.spot.length, numSpotLightMaps: lights.spotLightMap.length, numRectAreaLights: lights.rectArea.length, numHemiLights: lights.hemi.length, numDirLightShadows: lights.directionalShadowMap.length, numPointLightShadows: lights.pointShadowMap.length, numSpotLightShadows: lights.spotShadowMap.length, numSpotLightShadowsWithMaps: lights.numSpotLightShadowsWithMaps, numLightProbes: lights.numLightProbes, numClippingPlanes: clipping.numPlanes, numClipIntersection: clipping.numIntersection, dithering: material.dithering, shadowMapEnabled: renderer3.shadowMap.enabled && shadows.length > 0, shadowMapType: renderer3.shadowMap.type, toneMapping, useLegacyLights: renderer3._useLegacyLights, decodeVideoTexture: HAS_MAP && material.map.isVideoTexture === true && ColorManagement2.getTransfer(material.map.colorSpace) === SRGBTransfer2, premultipliedAlpha: material.premultipliedAlpha, doubleSided: material.side === DoubleSide2, flipSided: material.side === BackSide2, useDepthPacking: material.depthPacking >= 0, depthPacking: material.depthPacking || 0, index0AttributeName: material.index0AttributeName, extensionDerivatives: HAS_EXTENSIONS && material.extensions.derivatives === true, extensionFragDepth: HAS_EXTENSIONS && material.extensions.fragDepth === true, extensionDrawBuffers: HAS_EXTENSIONS && material.extensions.drawBuffers === true, extensionShaderTextureLOD: HAS_EXTENSIONS && material.extensions.shaderTextureLOD === true, rendererExtensionFragDepth: IS_WEBGL2 || extensions.has("EXT_frag_depth"), rendererExtensionDrawBuffers: IS_WEBGL2 || extensions.has("WEBGL_draw_buffers"), rendererExtensionShaderTextureLod: IS_WEBGL2 || extensions.has("EXT_shader_texture_lod"), customProgramCacheKey: material.customProgramCacheKey() }; return parameters; } function getProgramCacheKey(parameters) { const array = []; if (parameters.shaderID) { array.push(parameters.shaderID); } else { array.push(parameters.customVertexShaderID); array.push(parameters.customFragmentShaderID); } if (parameters.defines !== void 0) { for (const name in parameters.defines) { array.push(name); array.push(parameters.defines[name]); } } if (parameters.isRawShaderMaterial === false) { getProgramCacheKeyParameters(array, parameters); getProgramCacheKeyBooleans(array, parameters); array.push(renderer3.outputColorSpace); } array.push(parameters.customProgramCacheKey); return array.join(); } function getProgramCacheKeyParameters(array, parameters) { array.push(parameters.precision); array.push(parameters.outputColorSpace); array.push(parameters.envMapMode); array.push(parameters.envMapCubeUVHeight); array.push(parameters.mapUv); array.push(parameters.alphaMapUv); array.push(parameters.lightMapUv); array.push(parameters.aoMapUv); array.push(parameters.bumpMapUv); array.push(parameters.normalMapUv); array.push(parameters.displacementMapUv); array.push(parameters.emissiveMapUv); array.push(parameters.metalnessMapUv); array.push(parameters.roughnessMapUv); array.push(parameters.anisotropyMapUv); array.push(parameters.clearcoatMapUv); array.push(parameters.clearcoatNormalMapUv); array.push(parameters.clearcoatRoughnessMapUv); array.push(parameters.iridescenceMapUv); array.push(parameters.iridescenceThicknessMapUv); array.push(parameters.sheenColorMapUv); array.push(parameters.sheenRoughnessMapUv); array.push(parameters.specularMapUv); array.push(parameters.specularColorMapUv); array.push(parameters.specularIntensityMapUv); array.push(parameters.transmissionMapUv); array.push(parameters.thicknessMapUv); array.push(parameters.combine); array.push(parameters.fogExp2); array.push(parameters.sizeAttenuation); array.push(parameters.morphTargetsCount); array.push(parameters.morphAttributeCount); array.push(parameters.numDirLights); array.push(parameters.numPointLights); array.push(parameters.numSpotLights); array.push(parameters.numSpotLightMaps); array.push(parameters.numHemiLights); array.push(parameters.numRectAreaLights); array.push(parameters.numDirLightShadows); array.push(parameters.numPointLightShadows); array.push(parameters.numSpotLightShadows); array.push(parameters.numSpotLightShadowsWithMaps); array.push(parameters.numLightProbes); array.push(parameters.shadowMapType); array.push(parameters.toneMapping); array.push(parameters.numClippingPlanes); array.push(parameters.numClipIntersection); array.push(parameters.depthPacking); } function getProgramCacheKeyBooleans(array, parameters) { _programLayers.disableAll(); if (parameters.isWebGL2) _programLayers.enable(0); if (parameters.supportsVertexTextures) _programLayers.enable(1); if (parameters.instancing) _programLayers.enable(2); if (parameters.instancingColor) _programLayers.enable(3); if (parameters.matcap) _programLayers.enable(4); if (parameters.envMap) _programLayers.enable(5); if (parameters.normalMapObjectSpace) _programLayers.enable(6); if (parameters.normalMapTangentSpace) _programLayers.enable(7); if (parameters.clearcoat) _programLayers.enable(8); if (parameters.iridescence) _programLayers.enable(9); if (parameters.alphaTest) _programLayers.enable(10); if (parameters.vertexColors) _programLayers.enable(11); if (parameters.vertexAlphas) _programLayers.enable(12); if (parameters.vertexUv1s) _programLayers.enable(13); if (parameters.vertexUv2s) _programLayers.enable(14); if (parameters.vertexUv3s) _programLayers.enable(15); if (parameters.vertexTangents) _programLayers.enable(16); if (parameters.anisotropy) _programLayers.enable(17); array.push(_programLayers.mask); _programLayers.disableAll(); if (parameters.fog) _programLayers.enable(0); if (parameters.useFog) _programLayers.enable(1); if (parameters.flatShading) _programLayers.enable(2); if (parameters.logarithmicDepthBuffer) _programLayers.enable(3); if (parameters.skinning) _programLayers.enable(4); if (parameters.morphTargets) _programLayers.enable(5); if (parameters.morphNormals) _programLayers.enable(6); if (parameters.morphColors) _programLayers.enable(7); if (parameters.premultipliedAlpha) _programLayers.enable(8); if (parameters.shadowMapEnabled) _programLayers.enable(9); if (parameters.useLegacyLights) _programLayers.enable(10); if (parameters.doubleSided) _programLayers.enable(11); if (parameters.flipSided) _programLayers.enable(12); if (parameters.useDepthPacking) _programLayers.enable(13); if (parameters.dithering) _programLayers.enable(14); if (parameters.transmission) _programLayers.enable(15); if (parameters.sheen) _programLayers.enable(16); if (parameters.opaque) _programLayers.enable(17); if (parameters.pointsUvs) _programLayers.enable(18); if (parameters.decodeVideoTexture) _programLayers.enable(19); array.push(_programLayers.mask); } function getUniforms(material) { const shaderID = shaderIDs[material.type]; let uniforms; if (shaderID) { const shader = ShaderLib2[shaderID]; uniforms = UniformsUtils2.clone(shader.uniforms); } else { uniforms = material.uniforms; } return uniforms; } function acquireProgram(parameters, cacheKey) { let program; for (let p = 0, pl = programs.length; p < pl; p++) { const preexistingProgram = programs[p]; if (preexistingProgram.cacheKey === cacheKey) { program = preexistingProgram; ++program.usedTimes; break; } } if (program === void 0) { program = new WebGLProgram2(renderer3, cacheKey, parameters, bindingStates); programs.push(program); } return program; } function releaseProgram(program) { if (--program.usedTimes === 0) { const i = programs.indexOf(program); programs[i] = programs[programs.length - 1]; programs.pop(); program.destroy(); } } function releaseShaderCache(material) { _customShaders.remove(material); } function dispose() { _customShaders.dispose(); } return { getParameters, getProgramCacheKey, getUniforms, acquireProgram, releaseProgram, releaseShaderCache, // Exposed for resource monitoring & error feedback via renderer.info: programs, dispose }; } function WebGLProperties2() { let properties = /* @__PURE__ */ new WeakMap(); function get2(object) { let map = properties.get(object); if (map === void 0) { map = {}; properties.set(object, map); } return map; } function remove2(object) { properties.delete(object); } function update4(object, key, value) { properties.get(object)[key] = value; } function dispose() { properties = /* @__PURE__ */ new WeakMap(); } return { get: get2, remove: remove2, update: update4, dispose }; } function painterSortStable2(a2, b) { if (a2.groupOrder !== b.groupOrder) { return a2.groupOrder - b.groupOrder; } else if (a2.renderOrder !== b.renderOrder) { return a2.renderOrder - b.renderOrder; } else if (a2.material.id !== b.material.id) { return a2.material.id - b.material.id; } else if (a2.z !== b.z) { return a2.z - b.z; } else { return a2.id - b.id; } } function reversePainterSortStable2(a2, b) { if (a2.groupOrder !== b.groupOrder) { return a2.groupOrder - b.groupOrder; } else if (a2.renderOrder !== b.renderOrder) { return a2.renderOrder - b.renderOrder; } else if (a2.z !== b.z) { return b.z - a2.z; } else { return a2.id - b.id; } } function WebGLRenderList2() { const renderItems = []; let renderItemsIndex = 0; const opaque = []; const transmissive = []; const transparent = []; function init4() { renderItemsIndex = 0; opaque.length = 0; transmissive.length = 0; transparent.length = 0; } function getNextRenderItem(object, geometry, material, groupOrder, z4, group) { let renderItem = renderItems[renderItemsIndex]; if (renderItem === void 0) { renderItem = { id: object.id, object, geometry, material, groupOrder, renderOrder: object.renderOrder, z: z4, group }; renderItems[renderItemsIndex] = renderItem; } else { renderItem.id = object.id; renderItem.object = object; renderItem.geometry = geometry; renderItem.material = material; renderItem.groupOrder = groupOrder; renderItem.renderOrder = object.renderOrder; renderItem.z = z4; renderItem.group = group; } renderItemsIndex++; return renderItem; } function push(object, geometry, material, groupOrder, z4, group) { const renderItem = getNextRenderItem(object, geometry, material, groupOrder, z4, group); if (material.transmission > 0) { transmissive.push(renderItem); } else if (material.transparent === true) { transparent.push(renderItem); } else { opaque.push(renderItem); } } function unshift(object, geometry, material, groupOrder, z4, group) { const renderItem = getNextRenderItem(object, geometry, material, groupOrder, z4, group); if (material.transmission > 0) { transmissive.unshift(renderItem); } else if (material.transparent === true) { transparent.unshift(renderItem); } else { opaque.unshift(renderItem); } } function sort(customOpaqueSort, customTransparentSort) { if (opaque.length > 1) opaque.sort(customOpaqueSort || painterSortStable2); if (transmissive.length > 1) transmissive.sort(customTransparentSort || reversePainterSortStable2); if (transparent.length > 1) transparent.sort(customTransparentSort || reversePainterSortStable2); } function finish() { for (let i = renderItemsIndex, il = renderItems.length; i < il; i++) { const renderItem = renderItems[i]; if (renderItem.id === null) break; renderItem.id = null; renderItem.object = null; renderItem.geometry = null; renderItem.material = null; renderItem.group = null; } } return { opaque, transmissive, transparent, init: init4, push, unshift, finish, sort }; } function WebGLRenderLists2() { let lists = /* @__PURE__ */ new WeakMap(); function get2(scene3, renderCallDepth) { const listArray = lists.get(scene3); let list; if (listArray === void 0) { list = new WebGLRenderList2(); lists.set(scene3, [list]); } else { if (renderCallDepth >= listArray.length) { list = new WebGLRenderList2(); listArray.push(list); } else { list = listArray[renderCallDepth]; } } return list; } function dispose() { lists = /* @__PURE__ */ new WeakMap(); } return { get: get2, dispose }; } function UniformsCache2() { const lights = {}; return { get: function(light) { if (lights[light.id] !== void 0) { return lights[light.id]; } let uniforms; switch (light.type) { case "DirectionalLight": uniforms = { direction: new Vector32(), color: new Color2() }; break; case "SpotLight": uniforms = { position: new Vector32(), direction: new Vector32(), color: new Color2(), distance: 0, coneCos: 0, penumbraCos: 0, decay: 0 }; break; case "PointLight": uniforms = { position: new Vector32(), color: new Color2(), distance: 0, decay: 0 }; break; case "HemisphereLight": uniforms = { direction: new Vector32(), skyColor: new Color2(), groundColor: new Color2() }; break; case "RectAreaLight": uniforms = { color: new Color2(), position: new Vector32(), halfWidth: new Vector32(), halfHeight: new Vector32() }; break; } lights[light.id] = uniforms; return uniforms; } }; } function ShadowUniformsCache2() { const lights = {}; return { get: function(light) { if (lights[light.id] !== void 0) { return lights[light.id]; } let uniforms; switch (light.type) { case "DirectionalLight": uniforms = { shadowBias: 0, shadowNormalBias: 0, shadowRadius: 1, shadowMapSize: new Vector22() }; break; case "SpotLight": uniforms = { shadowBias: 0, shadowNormalBias: 0, shadowRadius: 1, shadowMapSize: new Vector22() }; break; case "PointLight": uniforms = { shadowBias: 0, shadowNormalBias: 0, shadowRadius: 1, shadowMapSize: new Vector22(), shadowCameraNear: 1, shadowCameraFar: 1e3 }; break; } lights[light.id] = uniforms; return uniforms; } }; } var nextVersion2 = 0; function shadowCastingAndTexturingLightsFirst2(lightA, lightB) { return (lightB.castShadow ? 2 : 0) - (lightA.castShadow ? 2 : 0) + (lightB.map ? 1 : 0) - (lightA.map ? 1 : 0); } function WebGLLights2(extensions, capabilities) { const cache = new UniformsCache2(); const shadowCache = ShadowUniformsCache2(); const state = { version: 0, hash: { directionalLength: -1, pointLength: -1, spotLength: -1, rectAreaLength: -1, hemiLength: -1, numDirectionalShadows: -1, numPointShadows: -1, numSpotShadows: -1, numSpotMaps: -1, numLightProbes: -1 }, ambient: [0, 0, 0], probe: [], directional: [], directionalShadow: [], directionalShadowMap: [], directionalShadowMatrix: [], spot: [], spotLightMap: [], spotShadow: [], spotShadowMap: [], spotLightMatrix: [], rectArea: [], rectAreaLTC1: null, rectAreaLTC2: null, point: [], pointShadow: [], pointShadowMap: [], pointShadowMatrix: [], hemi: [], numSpotLightShadowsWithMaps: 0, numLightProbes: 0 }; for (let i = 0; i < 9; i++) state.probe.push(new Vector32()); const vector3 = new Vector32(); const matrix4 = new Matrix42(); const matrix42 = new Matrix42(); function setup(lights, useLegacyLights) { let r = 0, g = 0, b = 0; for (let i = 0; i < 9; i++) state.probe[i].set(0, 0, 0); let directionalLength = 0; let pointLength = 0; let spotLength = 0; let rectAreaLength = 0; let hemiLength = 0; let numDirectionalShadows = 0; let numPointShadows = 0; let numSpotShadows = 0; let numSpotMaps = 0; let numSpotShadowsWithMaps = 0; let numLightProbes = 0; lights.sort(shadowCastingAndTexturingLightsFirst2); const scaleFactor = useLegacyLights === true ? Math.PI : 1; for (let i = 0, l = lights.length; i < l; i++) { const light = lights[i]; const color = light.color; const intensity = light.intensity; const distance = light.distance; const shadowMap = light.shadow && light.shadow.map ? light.shadow.map.texture : null; if (light.isAmbientLight) { r += color.r * intensity * scaleFactor; g += color.g * intensity * scaleFactor; b += color.b * intensity * scaleFactor; } else if (light.isLightProbe) { for (let j = 0; j < 9; j++) { state.probe[j].addScaledVector(light.sh.coefficients[j], intensity); } numLightProbes++; } else if (light.isDirectionalLight) { const uniforms = cache.get(light); uniforms.color.copy(light.color).multiplyScalar(light.intensity * scaleFactor); if (light.castShadow) { const shadow = light.shadow; const shadowUniforms = shadowCache.get(light); shadowUniforms.shadowBias = shadow.bias; shadowUniforms.shadowNormalBias = shadow.normalBias; shadowUniforms.shadowRadius = shadow.radius; shadowUniforms.shadowMapSize = shadow.mapSize; state.directionalShadow[directionalLength] = shadowUniforms; state.directionalShadowMap[directionalLength] = shadowMap; state.directionalShadowMatrix[directionalLength] = light.shadow.matrix; numDirectionalShadows++; } state.directional[directionalLength] = uniforms; directionalLength++; } else if (light.isSpotLight) { const uniforms = cache.get(light); uniforms.position.setFromMatrixPosition(light.matrixWorld); uniforms.color.copy(color).multiplyScalar(intensity * scaleFactor); uniforms.distance = distance; uniforms.coneCos = Math.cos(light.angle); uniforms.penumbraCos = Math.cos(light.angle * (1 - light.penumbra)); uniforms.decay = light.decay; state.spot[spotLength] = uniforms; const shadow = light.shadow; if (light.map) { state.spotLightMap[numSpotMaps] = light.map; numSpotMaps++; shadow.updateMatrices(light); if (light.castShadow) numSpotShadowsWithMaps++; } state.spotLightMatrix[spotLength] = shadow.matrix; if (light.castShadow) { const shadowUniforms = shadowCache.get(light); shadowUniforms.shadowBias = shadow.bias; shadowUniforms.shadowNormalBias = shadow.normalBias; shadowUniforms.shadowRadius = shadow.radius; shadowUniforms.shadowMapSize = shadow.mapSize; state.spotShadow[spotLength] = shadowUniforms; state.spotShadowMap[spotLength] = shadowMap; numSpotShadows++; } spotLength++; } else if (light.isRectAreaLight) { const uniforms = cache.get(light); uniforms.color.copy(color).multiplyScalar(intensity); uniforms.halfWidth.set(light.width * 0.5, 0, 0); uniforms.halfHeight.set(0, light.height * 0.5, 0); state.rectArea[rectAreaLength] = uniforms; rectAreaLength++; } else if (light.isPointLight) { const uniforms = cache.get(light); uniforms.color.copy(light.color).multiplyScalar(light.intensity * scaleFactor); uniforms.distance = light.distance; uniforms.decay = light.decay; if (light.castShadow) { const shadow = light.shadow; const shadowUniforms = shadowCache.get(light); shadowUniforms.shadowBias = shadow.bias; shadowUniforms.shadowNormalBias = shadow.normalBias; shadowUniforms.shadowRadius = shadow.radius; shadowUniforms.shadowMapSize = shadow.mapSize; shadowUniforms.shadowCameraNear = shadow.camera.near; shadowUniforms.shadowCameraFar = shadow.camera.far; state.pointShadow[pointLength] = shadowUniforms; state.pointShadowMap[pointLength] = shadowMap; state.pointShadowMatrix[pointLength] = light.shadow.matrix; numPointShadows++; } state.point[pointLength] = uniforms; pointLength++; } else if (light.isHemisphereLight) { const uniforms = cache.get(light); uniforms.skyColor.copy(light.color).multiplyScalar(intensity * scaleFactor); uniforms.groundColor.copy(light.groundColor).multiplyScalar(intensity * scaleFactor); state.hemi[hemiLength] = uniforms; hemiLength++; } } if (rectAreaLength > 0) { if (capabilities.isWebGL2) { state.rectAreaLTC1 = UniformsLib2.LTC_FLOAT_1; state.rectAreaLTC2 = UniformsLib2.LTC_FLOAT_2; } else { if (extensions.has("OES_texture_float_linear") === true) { state.rectAreaLTC1 = UniformsLib2.LTC_FLOAT_1; state.rectAreaLTC2 = UniformsLib2.LTC_FLOAT_2; } else if (extensions.has("OES_texture_half_float_linear") === true) { state.rectAreaLTC1 = UniformsLib2.LTC_HALF_1; state.rectAreaLTC2 = UniformsLib2.LTC_HALF_2; } else { console.error("THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions."); } } } state.ambient[0] = r; state.ambient[1] = g; state.ambient[2] = b; const hash = state.hash; if (hash.directionalLength !== directionalLength || hash.pointLength !== pointLength || hash.spotLength !== spotLength || hash.rectAreaLength !== rectAreaLength || hash.hemiLength !== hemiLength || hash.numDirectionalShadows !== numDirectionalShadows || hash.numPointShadows !== numPointShadows || hash.numSpotShadows !== numSpotShadows || hash.numSpotMaps !== numSpotMaps || hash.numLightProbes !== numLightProbes) { state.directional.length = directionalLength; state.spot.length = spotLength; state.rectArea.length = rectAreaLength; state.point.length = pointLength; state.hemi.length = hemiLength; state.directionalShadow.length = numDirectionalShadows; state.directionalShadowMap.length = numDirectionalShadows; state.pointShadow.length = numPointShadows; state.pointShadowMap.length = numPointShadows; state.spotShadow.length = numSpotShadows; state.spotShadowMap.length = numSpotShadows; state.directionalShadowMatrix.length = numDirectionalShadows; state.pointShadowMatrix.length = numPointShadows; state.spotLightMatrix.length = numSpotShadows + numSpotMaps - numSpotShadowsWithMaps; state.spotLightMap.length = numSpotMaps; state.numSpotLightShadowsWithMaps = numSpotShadowsWithMaps; state.numLightProbes = numLightProbes; hash.directionalLength = directionalLength; hash.pointLength = pointLength; hash.spotLength = spotLength; hash.rectAreaLength = rectAreaLength; hash.hemiLength = hemiLength; hash.numDirectionalShadows = numDirectionalShadows; hash.numPointShadows = numPointShadows; hash.numSpotShadows = numSpotShadows; hash.numSpotMaps = numSpotMaps; hash.numLightProbes = numLightProbes; state.version = nextVersion2++; } } function setupView(lights, camera3) { let directionalLength = 0; let pointLength = 0; let spotLength = 0; let rectAreaLength = 0; let hemiLength = 0; const viewMatrix = camera3.matrixWorldInverse; for (let i = 0, l = lights.length; i < l; i++) { const light = lights[i]; if (light.isDirectionalLight) { const uniforms = state.directional[directionalLength]; uniforms.direction.setFromMatrixPosition(light.matrixWorld); vector3.setFromMatrixPosition(light.target.matrixWorld); uniforms.direction.sub(vector3); uniforms.direction.transformDirection(viewMatrix); directionalLength++; } else if (light.isSpotLight) { const uniforms = state.spot[spotLength]; uniforms.position.setFromMatrixPosition(light.matrixWorld); uniforms.position.applyMatrix4(viewMatrix); uniforms.direction.setFromMatrixPosition(light.matrixWorld); vector3.setFromMatrixPosition(light.target.matrixWorld); uniforms.direction.sub(vector3); uniforms.direction.transformDirection(viewMatrix); spotLength++; } else if (light.isRectAreaLight) { const uniforms = state.rectArea[rectAreaLength]; uniforms.position.setFromMatrixPosition(light.matrixWorld); uniforms.position.applyMatrix4(viewMatrix); matrix42.identity(); matrix4.copy(light.matrixWorld); matrix4.premultiply(viewMatrix); matrix42.extractRotation(matrix4); uniforms.halfWidth.set(light.width * 0.5, 0, 0); uniforms.halfHeight.set(0, light.height * 0.5, 0); uniforms.halfWidth.applyMatrix4(matrix42); uniforms.halfHeight.applyMatrix4(matrix42); rectAreaLength++; } else if (light.isPointLight) { const uniforms = state.point[pointLength]; uniforms.position.setFromMatrixPosition(light.matrixWorld); uniforms.position.applyMatrix4(viewMatrix); pointLength++; } else if (light.isHemisphereLight) { const uniforms = state.hemi[hemiLength]; uniforms.direction.setFromMatrixPosition(light.matrixWorld); uniforms.direction.transformDirection(viewMatrix); hemiLength++; } } } return { setup, setupView, state }; } function WebGLRenderState2(extensions, capabilities) { const lights = new WebGLLights2(extensions, capabilities); const lightsArray = []; const shadowsArray = []; function init4() { lightsArray.length = 0; shadowsArray.length = 0; } function pushLight(light) { lightsArray.push(light); } function pushShadow(shadowLight) { shadowsArray.push(shadowLight); } function setupLights(useLegacyLights) { lights.setup(lightsArray, useLegacyLights); } function setupLightsView(camera3) { lights.setupView(lightsArray, camera3); } const state = { lightsArray, shadowsArray, lights }; return { init: init4, state, setupLights, setupLightsView, pushLight, pushShadow }; } function WebGLRenderStates2(extensions, capabilities) { let renderStates = /* @__PURE__ */ new WeakMap(); function get2(scene3, renderCallDepth = 0) { const renderStateArray = renderStates.get(scene3); let renderState; if (renderStateArray === void 0) { renderState = new WebGLRenderState2(extensions, capabilities); renderStates.set(scene3, [renderState]); } else { if (renderCallDepth >= renderStateArray.length) { renderState = new WebGLRenderState2(extensions, capabilities); renderStateArray.push(renderState); } else { renderState = renderStateArray[renderCallDepth]; } } return renderState; } function dispose() { renderStates = /* @__PURE__ */ new WeakMap(); } return { get: get2, dispose }; } var MeshDepthMaterial2 = class extends Material2 { constructor(parameters) { super(); this.isMeshDepthMaterial = true; this.type = "MeshDepthMaterial"; this.depthPacking = BasicDepthPacking2; this.map = null; this.alphaMap = null; this.displacementMap = null; this.displacementScale = 1; this.displacementBias = 0; this.wireframe = false; this.wireframeLinewidth = 1; this.setValues(parameters); } copy(source) { super.copy(source); this.depthPacking = source.depthPacking; this.map = source.map; this.alphaMap = source.alphaMap; this.displacementMap = source.displacementMap; this.displacementScale = source.displacementScale; this.displacementBias = source.displacementBias; this.wireframe = source.wireframe; this.wireframeLinewidth = source.wireframeLinewidth; return this; } }; var MeshDistanceMaterial2 = class extends Material2 { constructor(parameters) { super(); this.isMeshDistanceMaterial = true; this.type = "MeshDistanceMaterial"; this.map = null; this.alphaMap = null; this.displacementMap = null; this.displacementScale = 1; this.displacementBias = 0; this.setValues(parameters); } copy(source) { super.copy(source); this.map = source.map; this.alphaMap = source.alphaMap; this.displacementMap = source.displacementMap; this.displacementScale = source.displacementScale; this.displacementBias = source.displacementBias; return this; } }; var vertex2 = "void main() {\n gl_Position = vec4( position, 1.0 );\n}"; var fragment2 = "uniform sampler2D shadow_pass;\nuniform vec2 resolution;\nuniform float radius;\n#include \nvoid main() {\n const float samples = float( VSM_SAMPLES );\n float mean = 0.0;\n float squared_mean = 0.0;\n float uvStride = samples <= 1.0 ? 0.0 : 2.0 / ( samples - 1.0 );\n float uvStart = samples <= 1.0 ? 0.0 : - 1.0;\n for ( float i = 0.0; i < samples; i ++ ) {\n float uvOffset = uvStart + i * uvStride;\n #ifdef HORIZONTAL_PASS\n vec2 distribution = unpackRGBATo2Half( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( uvOffset, 0.0 ) * radius ) / resolution ) );\n mean += distribution.x;\n squared_mean += distribution.y * distribution.y + distribution.x * distribution.x;\n #else\n float depth = unpackRGBAToDepth( texture2D( shadow_pass, ( gl_FragCoord.xy + vec2( 0.0, uvOffset ) * radius ) / resolution ) );\n mean += depth;\n squared_mean += depth * depth;\n #endif\n }\n mean = mean / samples;\n squared_mean = squared_mean / samples;\n float std_dev = sqrt( squared_mean - mean * mean );\n gl_FragColor = pack2HalfToRGBA( vec2( mean, std_dev ) );\n}"; function WebGLShadowMap2(_renderer, _objects, _capabilities) { let _frustum = new Frustum2(); const _shadowMapSize = new Vector22(), _viewportSize = new Vector22(), _viewport = new Vector42(), _depthMaterial = new MeshDepthMaterial2({ depthPacking: RGBADepthPacking2 }), _distanceMaterial = new MeshDistanceMaterial2(), _materialCache = {}, _maxTextureSize = _capabilities.maxTextureSize; const shadowSide = { [FrontSide2]: BackSide2, [BackSide2]: FrontSide2, [DoubleSide2]: DoubleSide2 }; const shadowMaterialVertical = new ShaderMaterial2({ defines: { VSM_SAMPLES: 8 }, uniforms: { shadow_pass: { value: null }, resolution: { value: new Vector22() }, radius: { value: 4 } }, vertexShader: vertex2, fragmentShader: fragment2 }); const shadowMaterialHorizontal = shadowMaterialVertical.clone(); shadowMaterialHorizontal.defines.HORIZONTAL_PASS = 1; const fullScreenTri = new BufferGeometry2(); fullScreenTri.setAttribute( "position", new BufferAttribute2( new Float32Array([-1, -1, 0.5, 3, -1, 0.5, -1, 3, 0.5]), 3 ) ); const fullScreenMesh = new Mesh2(fullScreenTri, shadowMaterialVertical); const scope = this; this.enabled = false; this.autoUpdate = true; this.needsUpdate = false; this.type = PCFShadowMap2; let _previousType = this.type; this.render = function(lights, scene3, camera3) { if (scope.enabled === false) return; if (scope.autoUpdate === false && scope.needsUpdate === false) return; if (lights.length === 0) return; const currentRenderTarget = _renderer.getRenderTarget(); const activeCubeFace = _renderer.getActiveCubeFace(); const activeMipmapLevel = _renderer.getActiveMipmapLevel(); const _state = _renderer.state; _state.setBlending(NoBlending2); _state.buffers.color.setClear(1, 1, 1, 1); _state.buffers.depth.setTest(true); _state.setScissorTest(false); const toVSM = _previousType !== VSMShadowMap2 && this.type === VSMShadowMap2; const fromVSM = _previousType === VSMShadowMap2 && this.type !== VSMShadowMap2; for (let i = 0, il = lights.length; i < il; i++) { const light = lights[i]; const shadow = light.shadow; if (shadow === void 0) { console.warn("THREE.WebGLShadowMap:", light, "has no shadow."); continue; } if (shadow.autoUpdate === false && shadow.needsUpdate === false) continue; _shadowMapSize.copy(shadow.mapSize); const shadowFrameExtents = shadow.getFrameExtents(); _shadowMapSize.multiply(shadowFrameExtents); _viewportSize.copy(shadow.mapSize); if (_shadowMapSize.x > _maxTextureSize || _shadowMapSize.y > _maxTextureSize) { if (_shadowMapSize.x > _maxTextureSize) { _viewportSize.x = Math.floor(_maxTextureSize / shadowFrameExtents.x); _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x; shadow.mapSize.x = _viewportSize.x; } if (_shadowMapSize.y > _maxTextureSize) { _viewportSize.y = Math.floor(_maxTextureSize / shadowFrameExtents.y); _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y; shadow.mapSize.y = _viewportSize.y; } } if (shadow.map === null || toVSM === true || fromVSM === true) { const pars = this.type !== VSMShadowMap2 ? { minFilter: NearestFilter2, magFilter: NearestFilter2 } : {}; if (shadow.map !== null) { shadow.map.dispose(); } shadow.map = new WebGLRenderTarget2(_shadowMapSize.x, _shadowMapSize.y, pars); shadow.map.texture.name = light.name + ".shadowMap"; shadow.camera.updateProjectionMatrix(); } _renderer.setRenderTarget(shadow.map); _renderer.clear(); const viewportCount = shadow.getViewportCount(); for (let vp = 0; vp < viewportCount; vp++) { const viewport = shadow.getViewport(vp); _viewport.set( _viewportSize.x * viewport.x, _viewportSize.y * viewport.y, _viewportSize.x * viewport.z, _viewportSize.y * viewport.w ); _state.viewport(_viewport); shadow.updateMatrices(light, vp); _frustum = shadow.getFrustum(); renderObject(scene3, camera3, shadow.camera, light, this.type); } if (shadow.isPointLightShadow !== true && this.type === VSMShadowMap2) { VSMPass(shadow, camera3); } shadow.needsUpdate = false; } _previousType = this.type; scope.needsUpdate = false; _renderer.setRenderTarget(currentRenderTarget, activeCubeFace, activeMipmapLevel); }; function VSMPass(shadow, camera3) { const geometry = _objects.update(fullScreenMesh); if (shadowMaterialVertical.defines.VSM_SAMPLES !== shadow.blurSamples) { shadowMaterialVertical.defines.VSM_SAMPLES = shadow.blurSamples; shadowMaterialHorizontal.defines.VSM_SAMPLES = shadow.blurSamples; shadowMaterialVertical.needsUpdate = true; shadowMaterialHorizontal.needsUpdate = true; } if (shadow.mapPass === null) { shadow.mapPass = new WebGLRenderTarget2(_shadowMapSize.x, _shadowMapSize.y); } shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture; shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize; shadowMaterialVertical.uniforms.radius.value = shadow.radius; _renderer.setRenderTarget(shadow.mapPass); _renderer.clear(); _renderer.renderBufferDirect(camera3, null, geometry, shadowMaterialVertical, fullScreenMesh, null); shadowMaterialHorizontal.uniforms.shadow_pass.value = shadow.mapPass.texture; shadowMaterialHorizontal.uniforms.resolution.value = shadow.mapSize; shadowMaterialHorizontal.uniforms.radius.value = shadow.radius; _renderer.setRenderTarget(shadow.map); _renderer.clear(); _renderer.renderBufferDirect(camera3, null, geometry, shadowMaterialHorizontal, fullScreenMesh, null); } function getDepthMaterial(object, material, light, type) { let result = null; const customMaterial = light.isPointLight === true ? object.customDistanceMaterial : object.customDepthMaterial; if (customMaterial !== void 0) { result = customMaterial; } else { result = light.isPointLight === true ? _distanceMaterial : _depthMaterial; if (_renderer.localClippingEnabled && material.clipShadows === true && Array.isArray(material.clippingPlanes) && material.clippingPlanes.length !== 0 || material.displacementMap && material.displacementScale !== 0 || material.alphaMap && material.alphaTest > 0 || material.map && material.alphaTest > 0) { const keyA = result.uuid, keyB = material.uuid; let materialsForVariant = _materialCache[keyA]; if (materialsForVariant === void 0) { materialsForVariant = {}; _materialCache[keyA] = materialsForVariant; } let cachedMaterial = materialsForVariant[keyB]; if (cachedMaterial === void 0) { cachedMaterial = result.clone(); materialsForVariant[keyB] = cachedMaterial; } result = cachedMaterial; } } result.visible = material.visible; result.wireframe = material.wireframe; if (type === VSMShadowMap2) { result.side = material.shadowSide !== null ? material.shadowSide : material.side; } else { result.side = material.shadowSide !== null ? material.shadowSide : shadowSide[material.side]; } result.alphaMap = material.alphaMap; result.alphaTest = material.alphaTest; result.map = material.map; result.clipShadows = material.clipShadows; result.clippingPlanes = material.clippingPlanes; result.clipIntersection = material.clipIntersection; result.displacementMap = material.displacementMap; result.displacementScale = material.displacementScale; result.displacementBias = material.displacementBias; result.wireframeLinewidth = material.wireframeLinewidth; result.linewidth = material.linewidth; if (light.isPointLight === true && result.isMeshDistanceMaterial === true) { const materialProperties = _renderer.properties.get(result); materialProperties.light = light; } return result; } function renderObject(object, camera3, shadowCamera, light, type) { if (object.visible === false) return; const visible = object.layers.test(camera3.layers); if (visible && (object.isMesh || object.isLine || object.isPoints)) { if ((object.castShadow || object.receiveShadow && type === VSMShadowMap2) && (!object.frustumCulled || _frustum.intersectsObject(object))) { object.modelViewMatrix.multiplyMatrices(shadowCamera.matrixWorldInverse, object.matrixWorld); const geometry = _objects.update(object); const material = object.material; if (Array.isArray(material)) { const groups = geometry.groups; for (let k = 0, kl = groups.length; k < kl; k++) { const group = groups[k]; const groupMaterial = material[group.materialIndex]; if (groupMaterial && groupMaterial.visible) { const depthMaterial = getDepthMaterial(object, groupMaterial, light, type); _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group); } } } else if (material.visible) { const depthMaterial = getDepthMaterial(object, material, light, type); _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, null); } } } const children = object.children; for (let i = 0, l = children.length; i < l; i++) { renderObject(children[i], camera3, shadowCamera, light, type); } } } function WebGLState2(gl, extensions, capabilities) { const isWebGL2 = capabilities.isWebGL2; function ColorBuffer() { let locked = false; const color = new Vector42(); let currentColorMask = null; const currentColorClear = new Vector42(0, 0, 0, 0); return { setMask: function(colorMask) { if (currentColorMask !== colorMask && !locked) { gl.colorMask(colorMask, colorMask, colorMask, colorMask); currentColorMask = colorMask; } }, setLocked: function(lock) { locked = lock; }, setClear: function(r, g, b, a2, premultipliedAlpha) { if (premultipliedAlpha === true) { r *= a2; g *= a2; b *= a2; } color.set(r, g, b, a2); if (currentColorClear.equals(color) === false) { gl.clearColor(r, g, b, a2); currentColorClear.copy(color); } }, reset: function() { locked = false; currentColorMask = null; currentColorClear.set(-1, 0, 0, 0); } }; } function DepthBuffer() { let locked = false; let currentDepthMask = null; let currentDepthFunc = null; let currentDepthClear = null; return { setTest: function(depthTest) { if (depthTest) { enable(gl.DEPTH_TEST); } else { disable(gl.DEPTH_TEST); } }, setMask: function(depthMask) { if (currentDepthMask !== depthMask && !locked) { gl.depthMask(depthMask); currentDepthMask = depthMask; } }, setFunc: function(depthFunc) { if (currentDepthFunc !== depthFunc) { switch (depthFunc) { case NeverDepth2: gl.depthFunc(gl.NEVER); break; case AlwaysDepth2: gl.depthFunc(gl.ALWAYS); break; case LessDepth2: gl.depthFunc(gl.LESS); break; case LessEqualDepth2: gl.depthFunc(gl.LEQUAL); break; case EqualDepth2: gl.depthFunc(gl.EQUAL); break; case GreaterEqualDepth2: gl.depthFunc(gl.GEQUAL); break; case GreaterDepth2: gl.depthFunc(gl.GREATER); break; case NotEqualDepth2: gl.depthFunc(gl.NOTEQUAL); break; default: gl.depthFunc(gl.LEQUAL); } currentDepthFunc = depthFunc; } }, setLocked: function(lock) { locked = lock; }, setClear: function(depth) { if (currentDepthClear !== depth) { gl.clearDepth(depth); currentDepthClear = depth; } }, reset: function() { locked = false; currentDepthMask = null; currentDepthFunc = null; currentDepthClear = null; } }; } function StencilBuffer() { let locked = false; let currentStencilMask = null; let currentStencilFunc = null; let currentStencilRef = null; let currentStencilFuncMask = null; let currentStencilFail = null; let currentStencilZFail = null; let currentStencilZPass = null; let currentStencilClear = null; return { setTest: function(stencilTest) { if (!locked) { if (stencilTest) { enable(gl.STENCIL_TEST); } else { disable(gl.STENCIL_TEST); } } }, setMask: function(stencilMask) { if (currentStencilMask !== stencilMask && !locked) { gl.stencilMask(stencilMask); currentStencilMask = stencilMask; } }, setFunc: function(stencilFunc, stencilRef, stencilMask) { if (currentStencilFunc !== stencilFunc || currentStencilRef !== stencilRef || currentStencilFuncMask !== stencilMask) { gl.stencilFunc(stencilFunc, stencilRef, stencilMask); currentStencilFunc = stencilFunc; currentStencilRef = stencilRef; currentStencilFuncMask = stencilMask; } }, setOp: function(stencilFail, stencilZFail, stencilZPass) { if (currentStencilFail !== stencilFail || currentStencilZFail !== stencilZFail || currentStencilZPass !== stencilZPass) { gl.stencilOp(stencilFail, stencilZFail, stencilZPass); currentStencilFail = stencilFail; currentStencilZFail = stencilZFail; currentStencilZPass = stencilZPass; } }, setLocked: function(lock) { locked = lock; }, setClear: function(stencil) { if (currentStencilClear !== stencil) { gl.clearStencil(stencil); currentStencilClear = stencil; } }, reset: function() { locked = false; currentStencilMask = null; currentStencilFunc = null; currentStencilRef = null; currentStencilFuncMask = null; currentStencilFail = null; currentStencilZFail = null; currentStencilZPass = null; currentStencilClear = null; } }; } const colorBuffer = new ColorBuffer(); const depthBuffer = new DepthBuffer(); const stencilBuffer = new StencilBuffer(); const uboBindings = /* @__PURE__ */ new WeakMap(); const uboProgramMap = /* @__PURE__ */ new WeakMap(); let enabledCapabilities = {}; let currentBoundFramebuffers = {}; let currentDrawbuffers = /* @__PURE__ */ new WeakMap(); let defaultDrawbuffers = []; let currentProgram = null; let currentBlendingEnabled = false; let currentBlending = null; let currentBlendEquation = null; let currentBlendSrc = null; let currentBlendDst = null; let currentBlendEquationAlpha = null; let currentBlendSrcAlpha = null; let currentBlendDstAlpha = null; let currentPremultipledAlpha = false; let currentFlipSided = null; let currentCullFace = null; let currentLineWidth = null; let currentPolygonOffsetFactor = null; let currentPolygonOffsetUnits = null; const maxTextures = gl.getParameter(gl.MAX_COMBINED_TEXTURE_IMAGE_UNITS); let lineWidthAvailable = false; let version = 0; const glVersion = gl.getParameter(gl.VERSION); if (glVersion.indexOf("WebGL") !== -1) { version = parseFloat(/^WebGL (\d)/.exec(glVersion)[1]); lineWidthAvailable = version >= 1; } else if (glVersion.indexOf("OpenGL ES") !== -1) { version = parseFloat(/^OpenGL ES (\d)/.exec(glVersion)[1]); lineWidthAvailable = version >= 2; } let currentTextureSlot = null; let currentBoundTextures = {}; const scissorParam = gl.getParameter(gl.SCISSOR_BOX); const viewportParam = gl.getParameter(gl.VIEWPORT); const currentScissor = new Vector42().fromArray(scissorParam); const currentViewport = new Vector42().fromArray(viewportParam); function createTexture(type, target, count, dimensions) { const data = new Uint8Array(4); const texture = gl.createTexture(); gl.bindTexture(type, texture); gl.texParameteri(type, gl.TEXTURE_MIN_FILTER, gl.NEAREST); gl.texParameteri(type, gl.TEXTURE_MAG_FILTER, gl.NEAREST); for (let i = 0; i < count; i++) { if (isWebGL2 && (type === gl.TEXTURE_3D || type === gl.TEXTURE_2D_ARRAY)) { gl.texImage3D(target, 0, gl.RGBA, 1, 1, dimensions, 0, gl.RGBA, gl.UNSIGNED_BYTE, data); } else { gl.texImage2D(target + i, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, data); } } return texture; } const emptyTextures = {}; emptyTextures[gl.TEXTURE_2D] = createTexture(gl.TEXTURE_2D, gl.TEXTURE_2D, 1); emptyTextures[gl.TEXTURE_CUBE_MAP] = createTexture(gl.TEXTURE_CUBE_MAP, gl.TEXTURE_CUBE_MAP_POSITIVE_X, 6); if (isWebGL2) { emptyTextures[gl.TEXTURE_2D_ARRAY] = createTexture(gl.TEXTURE_2D_ARRAY, gl.TEXTURE_2D_ARRAY, 1, 1); emptyTextures[gl.TEXTURE_3D] = createTexture(gl.TEXTURE_3D, gl.TEXTURE_3D, 1, 1); } colorBuffer.setClear(0, 0, 0, 1); depthBuffer.setClear(1); stencilBuffer.setClear(0); enable(gl.DEPTH_TEST); depthBuffer.setFunc(LessEqualDepth2); setFlipSided(false); setCullFace(CullFaceBack2); enable(gl.CULL_FACE); setBlending(NoBlending2); function enable(id) { if (enabledCapabilities[id] !== true) { gl.enable(id); enabledCapabilities[id] = true; } } function disable(id) { if (enabledCapabilities[id] !== false) { gl.disable(id); enabledCapabilities[id] = false; } } function bindFramebuffer(target, framebuffer) { if (currentBoundFramebuffers[target] !== framebuffer) { gl.bindFramebuffer(target, framebuffer); currentBoundFramebuffers[target] = framebuffer; if (isWebGL2) { if (target === gl.DRAW_FRAMEBUFFER) { currentBoundFramebuffers[gl.FRAMEBUFFER] = framebuffer; } if (target === gl.FRAMEBUFFER) { currentBoundFramebuffers[gl.DRAW_FRAMEBUFFER] = framebuffer; } } return true; } return false; } function drawBuffers(renderTarget, framebuffer) { let drawBuffers2 = defaultDrawbuffers; let needsUpdate = false; if (renderTarget) { drawBuffers2 = currentDrawbuffers.get(framebuffer); if (drawBuffers2 === void 0) { drawBuffers2 = []; currentDrawbuffers.set(framebuffer, drawBuffers2); } if (renderTarget.isWebGLMultipleRenderTargets) { const textures = renderTarget.texture; if (drawBuffers2.length !== textures.length || drawBuffers2[0] !== gl.COLOR_ATTACHMENT0) { for (let i = 0, il = textures.length; i < il; i++) { drawBuffers2[i] = gl.COLOR_ATTACHMENT0 + i; } drawBuffers2.length = textures.length; needsUpdate = true; } } else { if (drawBuffers2[0] !== gl.COLOR_ATTACHMENT0) { drawBuffers2[0] = gl.COLOR_ATTACHMENT0; needsUpdate = true; } } } else { if (drawBuffers2[0] !== gl.BACK) { drawBuffers2[0] = gl.BACK; needsUpdate = true; } } if (needsUpdate) { if (capabilities.isWebGL2) { gl.drawBuffers(drawBuffers2); } else { extensions.get("WEBGL_draw_buffers").drawBuffersWEBGL(drawBuffers2); } } } function useProgram(program) { if (currentProgram !== program) { gl.useProgram(program); currentProgram = program; return true; } return false; } const equationToGL = { [AddEquation2]: gl.FUNC_ADD, [SubtractEquation2]: gl.FUNC_SUBTRACT, [ReverseSubtractEquation2]: gl.FUNC_REVERSE_SUBTRACT }; if (isWebGL2) { equationToGL[MinEquation2] = gl.MIN; equationToGL[MaxEquation2] = gl.MAX; } else { const extension = extensions.get("EXT_blend_minmax"); if (extension !== null) { equationToGL[MinEquation2] = extension.MIN_EXT; equationToGL[MaxEquation2] = extension.MAX_EXT; } } const factorToGL = { [ZeroFactor2]: gl.ZERO, [OneFactor2]: gl.ONE, [SrcColorFactor2]: gl.SRC_COLOR, [SrcAlphaFactor2]: gl.SRC_ALPHA, [SrcAlphaSaturateFactor2]: gl.SRC_ALPHA_SATURATE, [DstColorFactor2]: gl.DST_COLOR, [DstAlphaFactor2]: gl.DST_ALPHA, [OneMinusSrcColorFactor2]: gl.ONE_MINUS_SRC_COLOR, [OneMinusSrcAlphaFactor2]: gl.ONE_MINUS_SRC_ALPHA, [OneMinusDstColorFactor2]: gl.ONE_MINUS_DST_COLOR, [OneMinusDstAlphaFactor2]: gl.ONE_MINUS_DST_ALPHA }; function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha) { if (blending === NoBlending2) { if (currentBlendingEnabled === true) { disable(gl.BLEND); currentBlendingEnabled = false; } return; } if (currentBlendingEnabled === false) { enable(gl.BLEND); currentBlendingEnabled = true; } if (blending !== CustomBlending2) { if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) { if (currentBlendEquation !== AddEquation2 || currentBlendEquationAlpha !== AddEquation2) { gl.blendEquation(gl.FUNC_ADD); currentBlendEquation = AddEquation2; currentBlendEquationAlpha = AddEquation2; } if (premultipliedAlpha) { switch (blending) { case NormalBlending2: gl.blendFuncSeparate(gl.ONE, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA); break; case AdditiveBlending2: gl.blendFunc(gl.ONE, gl.ONE); break; case SubtractiveBlending2: gl.blendFuncSeparate(gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ZERO, gl.ONE); break; case MultiplyBlending2: gl.blendFuncSeparate(gl.ZERO, gl.SRC_COLOR, gl.ZERO, gl.SRC_ALPHA); break; default: console.error("THREE.WebGLState: Invalid blending: ", blending); break; } } else { switch (blending) { case NormalBlending2: gl.blendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA); break; case AdditiveBlending2: gl.blendFunc(gl.SRC_ALPHA, gl.ONE); break; case SubtractiveBlending2: gl.blendFuncSeparate(gl.ZERO, gl.ONE_MINUS_SRC_COLOR, gl.ZERO, gl.ONE); break; case MultiplyBlending2: gl.blendFunc(gl.ZERO, gl.SRC_COLOR); break; default: console.error("THREE.WebGLState: Invalid blending: ", blending); break; } } currentBlendSrc = null; currentBlendDst = null; currentBlendSrcAlpha = null; currentBlendDstAlpha = null; currentBlending = blending; currentPremultipledAlpha = premultipliedAlpha; } return; } blendEquationAlpha = blendEquationAlpha || blendEquation; blendSrcAlpha = blendSrcAlpha || blendSrc; blendDstAlpha = blendDstAlpha || blendDst; if (blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha) { gl.blendEquationSeparate(equationToGL[blendEquation], equationToGL[blendEquationAlpha]); currentBlendEquation = blendEquation; currentBlendEquationAlpha = blendEquationAlpha; } if (blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha) { gl.blendFuncSeparate(factorToGL[blendSrc], factorToGL[blendDst], factorToGL[blendSrcAlpha], factorToGL[blendDstAlpha]); currentBlendSrc = blendSrc; currentBlendDst = blendDst; currentBlendSrcAlpha = blendSrcAlpha; currentBlendDstAlpha = blendDstAlpha; } currentBlending = blending; currentPremultipledAlpha = false; } function setMaterial(material, frontFaceCW) { material.side === DoubleSide2 ? disable(gl.CULL_FACE) : enable(gl.CULL_FACE); let flipSided = material.side === BackSide2; if (frontFaceCW) flipSided = !flipSided; setFlipSided(flipSided); material.blending === NormalBlending2 && material.transparent === false ? setBlending(NoBlending2) : setBlending(material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha); depthBuffer.setFunc(material.depthFunc); depthBuffer.setTest(material.depthTest); depthBuffer.setMask(material.depthWrite); colorBuffer.setMask(material.colorWrite); const stencilWrite = material.stencilWrite; stencilBuffer.setTest(stencilWrite); if (stencilWrite) { stencilBuffer.setMask(material.stencilWriteMask); stencilBuffer.setFunc(material.stencilFunc, material.stencilRef, material.stencilFuncMask); stencilBuffer.setOp(material.stencilFail, material.stencilZFail, material.stencilZPass); } setPolygonOffset(material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits); material.alphaToCoverage === true ? enable(gl.SAMPLE_ALPHA_TO_COVERAGE) : disable(gl.SAMPLE_ALPHA_TO_COVERAGE); } function setFlipSided(flipSided) { if (currentFlipSided !== flipSided) { if (flipSided) { gl.frontFace(gl.CW); } else { gl.frontFace(gl.CCW); } currentFlipSided = flipSided; } } function setCullFace(cullFace) { if (cullFace !== CullFaceNone2) { enable(gl.CULL_FACE); if (cullFace !== currentCullFace) { if (cullFace === CullFaceBack2) { gl.cullFace(gl.BACK); } else if (cullFace === CullFaceFront2) { gl.cullFace(gl.FRONT); } else { gl.cullFace(gl.FRONT_AND_BACK); } } } else { disable(gl.CULL_FACE); } currentCullFace = cullFace; } function setLineWidth(width) { if (width !== currentLineWidth) { if (lineWidthAvailable) gl.lineWidth(width); currentLineWidth = width; } } function setPolygonOffset(polygonOffset, factor, units) { if (polygonOffset) { enable(gl.POLYGON_OFFSET_FILL); if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) { gl.polygonOffset(factor, units); currentPolygonOffsetFactor = factor; currentPolygonOffsetUnits = units; } } else { disable(gl.POLYGON_OFFSET_FILL); } } function setScissorTest(scissorTest) { if (scissorTest) { enable(gl.SCISSOR_TEST); } else { disable(gl.SCISSOR_TEST); } } function activeTexture(webglSlot) { if (webglSlot === void 0) webglSlot = gl.TEXTURE0 + maxTextures - 1; if (currentTextureSlot !== webglSlot) { gl.activeTexture(webglSlot); currentTextureSlot = webglSlot; } } function bindTexture(webglType, webglTexture, webglSlot) { if (webglSlot === void 0) { if (currentTextureSlot === null) { webglSlot = gl.TEXTURE0 + maxTextures - 1; } else { webglSlot = currentTextureSlot; } } let boundTexture = currentBoundTextures[webglSlot]; if (boundTexture === void 0) { boundTexture = { type: void 0, texture: void 0 }; currentBoundTextures[webglSlot] = boundTexture; } if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) { if (currentTextureSlot !== webglSlot) { gl.activeTexture(webglSlot); currentTextureSlot = webglSlot; } gl.bindTexture(webglType, webglTexture || emptyTextures[webglType]); boundTexture.type = webglType; boundTexture.texture = webglTexture; } } function unbindTexture() { const boundTexture = currentBoundTextures[currentTextureSlot]; if (boundTexture !== void 0 && boundTexture.type !== void 0) { gl.bindTexture(boundTexture.type, null); boundTexture.type = void 0; boundTexture.texture = void 0; } } function compressedTexImage2D() { try { gl.compressedTexImage2D.apply(gl, arguments); } catch (error) { console.error("THREE.WebGLState:", error); } } function compressedTexImage3D() { try { gl.compressedTexImage3D.apply(gl, arguments); } catch (error) { console.error("THREE.WebGLState:", error); } } function texSubImage2D() { try { gl.texSubImage2D.apply(gl, arguments); } catch (error) { console.error("THREE.WebGLState:", error); } } function texSubImage3D() { try { gl.texSubImage3D.apply(gl, arguments); } catch (error) { console.error("THREE.WebGLState:", error); } } function compressedTexSubImage2D() { try { gl.compressedTexSubImage2D.apply(gl, arguments); } catch (error) { console.error("THREE.WebGLState:", error); } } function compressedTexSubImage3D() { try { gl.compressedTexSubImage3D.apply(gl, arguments); } catch (error) { console.error("THREE.WebGLState:", error); } } function texStorage2D() { try { gl.texStorage2D.apply(gl, arguments); } catch (error) { console.error("THREE.WebGLState:", error); } } function texStorage3D() { try { gl.texStorage3D.apply(gl, arguments); } catch (error) { console.error("THREE.WebGLState:", error); } } function texImage2D() { try { gl.texImage2D.apply(gl, arguments); } catch (error) { console.error("THREE.WebGLState:", error); } } function texImage3D() { try { gl.texImage3D.apply(gl, arguments); } catch (error) { console.error("THREE.WebGLState:", error); } } function scissor(scissor2) { if (currentScissor.equals(scissor2) === false) { gl.scissor(scissor2.x, scissor2.y, scissor2.z, scissor2.w); currentScissor.copy(scissor2); } } function viewport(viewport2) { if (currentViewport.equals(viewport2) === false) { gl.viewport(viewport2.x, viewport2.y, viewport2.z, viewport2.w); currentViewport.copy(viewport2); } } function updateUBOMapping(uniformsGroup, program) { let mapping = uboProgramMap.get(program); if (mapping === void 0) { mapping = /* @__PURE__ */ new WeakMap(); uboProgramMap.set(program, mapping); } let blockIndex = mapping.get(uniformsGroup); if (blockIndex === void 0) { blockIndex = gl.getUniformBlockIndex(program, uniformsGroup.name); mapping.set(uniformsGroup, blockIndex); } } function uniformBlockBinding(uniformsGroup, program) { const mapping = uboProgramMap.get(program); const blockIndex = mapping.get(uniformsGroup); if (uboBindings.get(program) !== blockIndex) { gl.uniformBlockBinding(program, blockIndex, uniformsGroup.__bindingPointIndex); uboBindings.set(program, blockIndex); } } function reset() { gl.disable(gl.BLEND); gl.disable(gl.CULL_FACE); gl.disable(gl.DEPTH_TEST); gl.disable(gl.POLYGON_OFFSET_FILL); gl.disable(gl.SCISSOR_TEST); gl.disable(gl.STENCIL_TEST); gl.disable(gl.SAMPLE_ALPHA_TO_COVERAGE); gl.blendEquation(gl.FUNC_ADD); gl.blendFunc(gl.ONE, gl.ZERO); gl.blendFuncSeparate(gl.ONE, gl.ZERO, gl.ONE, gl.ZERO); gl.colorMask(true, true, true, true); gl.clearColor(0, 0, 0, 0); gl.depthMask(true); gl.depthFunc(gl.LESS); gl.clearDepth(1); gl.stencilMask(4294967295); gl.stencilFunc(gl.ALWAYS, 0, 4294967295); gl.stencilOp(gl.KEEP, gl.KEEP, gl.KEEP); gl.clearStencil(0); gl.cullFace(gl.BACK); gl.frontFace(gl.CCW); gl.polygonOffset(0, 0); gl.activeTexture(gl.TEXTURE0); gl.bindFramebuffer(gl.FRAMEBUFFER, null); if (isWebGL2 === true) { gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, null); gl.bindFramebuffer(gl.READ_FRAMEBUFFER, null); } gl.useProgram(null); gl.lineWidth(1); gl.scissor(0, 0, gl.canvas.width, gl.canvas.height); gl.viewport(0, 0, gl.canvas.width, gl.canvas.height); enabledCapabilities = {}; currentTextureSlot = null; currentBoundTextures = {}; currentBoundFramebuffers = {}; currentDrawbuffers = /* @__PURE__ */ new WeakMap(); defaultDrawbuffers = []; currentProgram = null; currentBlendingEnabled = false; currentBlending = null; currentBlendEquation = null; currentBlendSrc = null; currentBlendDst = null; currentBlendEquationAlpha = null; currentBlendSrcAlpha = null; currentBlendDstAlpha = null; currentPremultipledAlpha = false; currentFlipSided = null; currentCullFace = null; currentLineWidth = null; currentPolygonOffsetFactor = null; currentPolygonOffsetUnits = null; currentScissor.set(0, 0, gl.canvas.width, gl.canvas.height); currentViewport.set(0, 0, gl.canvas.width, gl.canvas.height); colorBuffer.reset(); depthBuffer.reset(); stencilBuffer.reset(); } return { buffers: { color: colorBuffer, depth: depthBuffer, stencil: stencilBuffer }, enable, disable, bindFramebuffer, drawBuffers, useProgram, setBlending, setMaterial, setFlipSided, setCullFace, setLineWidth, setPolygonOffset, setScissorTest, activeTexture, bindTexture, unbindTexture, compressedTexImage2D, compressedTexImage3D, texImage2D, texImage3D, updateUBOMapping, uniformBlockBinding, texStorage2D, texStorage3D, texSubImage2D, texSubImage3D, compressedTexSubImage2D, compressedTexSubImage3D, scissor, viewport, reset }; } function WebGLTextures2(_gl, extensions, state, properties, capabilities, utils, info) { const isWebGL2 = capabilities.isWebGL2; const maxTextures = capabilities.maxTextures; const maxCubemapSize = capabilities.maxCubemapSize; const maxTextureSize = capabilities.maxTextureSize; const maxSamples = capabilities.maxSamples; const multisampledRTTExt = extensions.has("WEBGL_multisampled_render_to_texture") ? extensions.get("WEBGL_multisampled_render_to_texture") : null; const supportsInvalidateFramebuffer = typeof navigator === "undefined" ? false : /OculusBrowser/g.test(navigator.userAgent); const _videoTextures = /* @__PURE__ */ new WeakMap(); let _canvas3; const _sources = /* @__PURE__ */ new WeakMap(); let useOffscreenCanvas = false; try { useOffscreenCanvas = typeof OffscreenCanvas !== "undefined" && new OffscreenCanvas(1, 1).getContext("2d") !== null; } catch (err) { } function createCanvas(width, height) { return useOffscreenCanvas ? ( // eslint-disable-next-line compat/compat new OffscreenCanvas(width, height) ) : createElementNS2("canvas"); } function resizeImage(image, needsPowerOfTwo, needsNewCanvas, maxSize) { let scale = 1; if (image.width > maxSize || image.height > maxSize) { scale = maxSize / Math.max(image.width, image.height); } if (scale < 1 || needsPowerOfTwo === true) { if (typeof HTMLImageElement !== "undefined" && image instanceof HTMLImageElement || typeof HTMLCanvasElement !== "undefined" && image instanceof HTMLCanvasElement || typeof ImageBitmap !== "undefined" && image instanceof ImageBitmap) { const floor = needsPowerOfTwo ? floorPowerOfTwo2 : Math.floor; const width = floor(scale * image.width); const height = floor(scale * image.height); if (_canvas3 === void 0) _canvas3 = createCanvas(width, height); const canvas = needsNewCanvas ? createCanvas(width, height) : _canvas3; canvas.width = width; canvas.height = height; const context = canvas.getContext("2d"); context.drawImage(image, 0, 0, width, height); console.warn("THREE.WebGLRenderer: Texture has been resized from (" + image.width + "x" + image.height + ") to (" + width + "x" + height + ")."); return canvas; } else { if ("data" in image) { console.warn("THREE.WebGLRenderer: Image in DataTexture is too big (" + image.width + "x" + image.height + ")."); } return image; } } return image; } function isPowerOfTwo$1(image) { return isPowerOfTwo2(image.width) && isPowerOfTwo2(image.height); } function textureNeedsPowerOfTwo(texture) { if (isWebGL2) return false; return texture.wrapS !== ClampToEdgeWrapping2 || texture.wrapT !== ClampToEdgeWrapping2 || texture.minFilter !== NearestFilter2 && texture.minFilter !== LinearFilter2; } function textureNeedsGenerateMipmaps(texture, supportsMips) { return texture.generateMipmaps && supportsMips && texture.minFilter !== NearestFilter2 && texture.minFilter !== LinearFilter2; } function generateMipmap(target) { _gl.generateMipmap(target); } function getInternalFormat(internalFormatName, glFormat, glType, colorSpace, forceLinearTransfer = false) { if (isWebGL2 === false) return glFormat; if (internalFormatName !== null) { if (_gl[internalFormatName] !== void 0) return _gl[internalFormatName]; console.warn("THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format '" + internalFormatName + "'"); } let internalFormat = glFormat; if (glFormat === _gl.RED) { if (glType === _gl.FLOAT) internalFormat = _gl.R32F; if (glType === _gl.HALF_FLOAT) internalFormat = _gl.R16F; if (glType === _gl.UNSIGNED_BYTE) internalFormat = _gl.R8; } if (glFormat === _gl.RED_INTEGER) { if (glType === _gl.UNSIGNED_BYTE) internalFormat = _gl.R8UI; if (glType === _gl.UNSIGNED_SHORT) internalFormat = _gl.R16UI; if (glType === _gl.UNSIGNED_INT) internalFormat = _gl.R32UI; if (glType === _gl.BYTE) internalFormat = _gl.R8I; if (glType === _gl.SHORT) internalFormat = _gl.R16I; if (glType === _gl.INT) internalFormat = _gl.R32I; } if (glFormat === _gl.RG) { if (glType === _gl.FLOAT) internalFormat = _gl.RG32F; if (glType === _gl.HALF_FLOAT) internalFormat = _gl.RG16F; if (glType === _gl.UNSIGNED_BYTE) internalFormat = _gl.RG8; } if (glFormat === _gl.RGBA) { const transfer = forceLinearTransfer ? LinearTransfer2 : ColorManagement2.getTransfer(colorSpace); if (glType === _gl.FLOAT) internalFormat = _gl.RGBA32F; if (glType === _gl.HALF_FLOAT) internalFormat = _gl.RGBA16F; if (glType === _gl.UNSIGNED_BYTE) internalFormat = transfer === SRGBTransfer2 ? _gl.SRGB8_ALPHA8 : _gl.RGBA8; if (glType === _gl.UNSIGNED_SHORT_4_4_4_4) internalFormat = _gl.RGBA4; if (glType === _gl.UNSIGNED_SHORT_5_5_5_1) internalFormat = _gl.RGB5_A1; } if (internalFormat === _gl.R16F || internalFormat === _gl.R32F || internalFormat === _gl.RG16F || internalFormat === _gl.RG32F || internalFormat === _gl.RGBA16F || internalFormat === _gl.RGBA32F) { extensions.get("EXT_color_buffer_float"); } return internalFormat; } function getMipLevels(texture, image, supportsMips) { if (textureNeedsGenerateMipmaps(texture, supportsMips) === true || texture.isFramebufferTexture && texture.minFilter !== NearestFilter2 && texture.minFilter !== LinearFilter2) { return Math.log2(Math.max(image.width, image.height)) + 1; } else if (texture.mipmaps !== void 0 && texture.mipmaps.length > 0) { return texture.mipmaps.length; } else if (texture.isCompressedTexture && Array.isArray(texture.image)) { return image.mipmaps.length; } else { return 1; } } function filterFallback(f) { if (f === NearestFilter2 || f === NearestMipmapNearestFilter2 || f === NearestMipmapLinearFilter2) { return _gl.NEAREST; } return _gl.LINEAR; } function onTextureDispose(event) { const texture = event.target; texture.removeEventListener("dispose", onTextureDispose); deallocateTexture(texture); if (texture.isVideoTexture) { _videoTextures.delete(texture); } } function onRenderTargetDispose(event) { const renderTarget = event.target; renderTarget.removeEventListener("dispose", onRenderTargetDispose); deallocateRenderTarget(renderTarget); } function deallocateTexture(texture) { const textureProperties = properties.get(texture); if (textureProperties.__webglInit === void 0) return; const source = texture.source; const webglTextures = _sources.get(source); if (webglTextures) { const webglTexture = webglTextures[textureProperties.__cacheKey]; webglTexture.usedTimes--; if (webglTexture.usedTimes === 0) { deleteTexture(texture); } if (Object.keys(webglTextures).length === 0) { _sources.delete(source); } } properties.remove(texture); } function deleteTexture(texture) { const textureProperties = properties.get(texture); _gl.deleteTexture(textureProperties.__webglTexture); const source = texture.source; const webglTextures = _sources.get(source); delete webglTextures[textureProperties.__cacheKey]; info.memory.textures--; } function deallocateRenderTarget(renderTarget) { const texture = renderTarget.texture; const renderTargetProperties = properties.get(renderTarget); const textureProperties = properties.get(texture); if (textureProperties.__webglTexture !== void 0) { _gl.deleteTexture(textureProperties.__webglTexture); info.memory.textures--; } if (renderTarget.depthTexture) { renderTarget.depthTexture.dispose(); } if (renderTarget.isWebGLCubeRenderTarget) { for (let i = 0; i < 6; i++) { if (Array.isArray(renderTargetProperties.__webglFramebuffer[i])) { for (let level = 0; level < renderTargetProperties.__webglFramebuffer[i].length; level++) _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i][level]); } else { _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]); } if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]); } } else { if (Array.isArray(renderTargetProperties.__webglFramebuffer)) { for (let level = 0; level < renderTargetProperties.__webglFramebuffer.length; level++) _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[level]); } else { _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer); } if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer); if (renderTargetProperties.__webglMultisampledFramebuffer) _gl.deleteFramebuffer(renderTargetProperties.__webglMultisampledFramebuffer); if (renderTargetProperties.__webglColorRenderbuffer) { for (let i = 0; i < renderTargetProperties.__webglColorRenderbuffer.length; i++) { if (renderTargetProperties.__webglColorRenderbuffer[i]) _gl.deleteRenderbuffer(renderTargetProperties.__webglColorRenderbuffer[i]); } } if (renderTargetProperties.__webglDepthRenderbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthRenderbuffer); } if (renderTarget.isWebGLMultipleRenderTargets) { for (let i = 0, il = texture.length; i < il; i++) { const attachmentProperties = properties.get(texture[i]); if (attachmentProperties.__webglTexture) { _gl.deleteTexture(attachmentProperties.__webglTexture); info.memory.textures--; } properties.remove(texture[i]); } } properties.remove(texture); properties.remove(renderTarget); } let textureUnits = 0; function resetTextureUnits() { textureUnits = 0; } function allocateTextureUnit() { const textureUnit = textureUnits; if (textureUnit >= maxTextures) { console.warn("THREE.WebGLTextures: Trying to use " + textureUnit + " texture units while this GPU supports only " + maxTextures); } textureUnits += 1; return textureUnit; } function getTextureCacheKey(texture) { const array = []; array.push(texture.wrapS); array.push(texture.wrapT); array.push(texture.wrapR || 0); array.push(texture.magFilter); array.push(texture.minFilter); array.push(texture.anisotropy); array.push(texture.internalFormat); array.push(texture.format); array.push(texture.type); array.push(texture.generateMipmaps); array.push(texture.premultiplyAlpha); array.push(texture.flipY); array.push(texture.unpackAlignment); array.push(texture.colorSpace); return array.join(); } function setTexture2D(texture, slot) { const textureProperties = properties.get(texture); if (texture.isVideoTexture) updateVideoTexture(texture); if (texture.isRenderTargetTexture === false && texture.version > 0 && textureProperties.__version !== texture.version) { const image = texture.image; if (image === null) { console.warn("THREE.WebGLRenderer: Texture marked for update but no image data found."); } else if (image.complete === false) { console.warn("THREE.WebGLRenderer: Texture marked for update but image is incomplete"); } else { uploadTexture(textureProperties, texture, slot); return; } } state.bindTexture(_gl.TEXTURE_2D, textureProperties.__webglTexture, _gl.TEXTURE0 + slot); } function setTexture2DArray(texture, slot) { const textureProperties = properties.get(texture); if (texture.version > 0 && textureProperties.__version !== texture.version) { uploadTexture(textureProperties, texture, slot); return; } state.bindTexture(_gl.TEXTURE_2D_ARRAY, textureProperties.__webglTexture, _gl.TEXTURE0 + slot); } function setTexture3D(texture, slot) { const textureProperties = properties.get(texture); if (texture.version > 0 && textureProperties.__version !== texture.version) { uploadTexture(textureProperties, texture, slot); return; } state.bindTexture(_gl.TEXTURE_3D, textureProperties.__webglTexture, _gl.TEXTURE0 + slot); } function setTextureCube(texture, slot) { const textureProperties = properties.get(texture); if (texture.version > 0 && textureProperties.__version !== texture.version) { uploadCubeTexture(textureProperties, texture, slot); return; } state.bindTexture(_gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture, _gl.TEXTURE0 + slot); } const wrappingToGL = { [RepeatWrapping2]: _gl.REPEAT, [ClampToEdgeWrapping2]: _gl.CLAMP_TO_EDGE, [MirroredRepeatWrapping2]: _gl.MIRRORED_REPEAT }; const filterToGL = { [NearestFilter2]: _gl.NEAREST, [NearestMipmapNearestFilter2]: _gl.NEAREST_MIPMAP_NEAREST, [NearestMipmapLinearFilter2]: _gl.NEAREST_MIPMAP_LINEAR, [LinearFilter2]: _gl.LINEAR, [LinearMipmapNearestFilter2]: _gl.LINEAR_MIPMAP_NEAREST, [LinearMipmapLinearFilter2]: _gl.LINEAR_MIPMAP_LINEAR }; const compareToGL = { [NeverCompare2]: _gl.NEVER, [AlwaysCompare2]: _gl.ALWAYS, [LessCompare2]: _gl.LESS, [LessEqualCompare2]: _gl.LEQUAL, [EqualCompare2]: _gl.EQUAL, [GreaterEqualCompare2]: _gl.GEQUAL, [GreaterCompare2]: _gl.GREATER, [NotEqualCompare2]: _gl.NOTEQUAL }; function setTextureParameters(textureType, texture, supportsMips) { if (supportsMips) { _gl.texParameteri(textureType, _gl.TEXTURE_WRAP_S, wrappingToGL[texture.wrapS]); _gl.texParameteri(textureType, _gl.TEXTURE_WRAP_T, wrappingToGL[texture.wrapT]); if (textureType === _gl.TEXTURE_3D || textureType === _gl.TEXTURE_2D_ARRAY) { _gl.texParameteri(textureType, _gl.TEXTURE_WRAP_R, wrappingToGL[texture.wrapR]); } _gl.texParameteri(textureType, _gl.TEXTURE_MAG_FILTER, filterToGL[texture.magFilter]); _gl.texParameteri(textureType, _gl.TEXTURE_MIN_FILTER, filterToGL[texture.minFilter]); } else { _gl.texParameteri(textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE); _gl.texParameteri(textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE); if (textureType === _gl.TEXTURE_3D || textureType === _gl.TEXTURE_2D_ARRAY) { _gl.texParameteri(textureType, _gl.TEXTURE_WRAP_R, _gl.CLAMP_TO_EDGE); } if (texture.wrapS !== ClampToEdgeWrapping2 || texture.wrapT !== ClampToEdgeWrapping2) { console.warn("THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping."); } _gl.texParameteri(textureType, _gl.TEXTURE_MAG_FILTER, filterFallback(texture.magFilter)); _gl.texParameteri(textureType, _gl.TEXTURE_MIN_FILTER, filterFallback(texture.minFilter)); if (texture.minFilter !== NearestFilter2 && texture.minFilter !== LinearFilter2) { console.warn("THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter."); } } if (texture.compareFunction) { _gl.texParameteri(textureType, _gl.TEXTURE_COMPARE_MODE, _gl.COMPARE_REF_TO_TEXTURE); _gl.texParameteri(textureType, _gl.TEXTURE_COMPARE_FUNC, compareToGL[texture.compareFunction]); } if (extensions.has("EXT_texture_filter_anisotropic") === true) { const extension = extensions.get("EXT_texture_filter_anisotropic"); if (texture.magFilter === NearestFilter2) return; if (texture.minFilter !== NearestMipmapLinearFilter2 && texture.minFilter !== LinearMipmapLinearFilter2) return; if (texture.type === FloatType2 && extensions.has("OES_texture_float_linear") === false) return; if (isWebGL2 === false && (texture.type === HalfFloatType2 && extensions.has("OES_texture_half_float_linear") === false)) return; if (texture.anisotropy > 1 || properties.get(texture).__currentAnisotropy) { _gl.texParameterf(textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min(texture.anisotropy, capabilities.getMaxAnisotropy())); properties.get(texture).__currentAnisotropy = texture.anisotropy; } } } function initTexture(textureProperties, texture) { let forceUpload = false; if (textureProperties.__webglInit === void 0) { textureProperties.__webglInit = true; texture.addEventListener("dispose", onTextureDispose); } const source = texture.source; let webglTextures = _sources.get(source); if (webglTextures === void 0) { webglTextures = {}; _sources.set(source, webglTextures); } const textureCacheKey = getTextureCacheKey(texture); if (textureCacheKey !== textureProperties.__cacheKey) { if (webglTextures[textureCacheKey] === void 0) { webglTextures[textureCacheKey] = { texture: _gl.createTexture(), usedTimes: 0 }; info.memory.textures++; forceUpload = true; } webglTextures[textureCacheKey].usedTimes++; const webglTexture = webglTextures[textureProperties.__cacheKey]; if (webglTexture !== void 0) { webglTextures[textureProperties.__cacheKey].usedTimes--; if (webglTexture.usedTimes === 0) { deleteTexture(texture); } } textureProperties.__cacheKey = textureCacheKey; textureProperties.__webglTexture = webglTextures[textureCacheKey].texture; } return forceUpload; } function uploadTexture(textureProperties, texture, slot) { let textureType = _gl.TEXTURE_2D; if (texture.isDataArrayTexture || texture.isCompressedArrayTexture) textureType = _gl.TEXTURE_2D_ARRAY; if (texture.isData3DTexture) textureType = _gl.TEXTURE_3D; const forceUpload = initTexture(textureProperties, texture); const source = texture.source; state.bindTexture(textureType, textureProperties.__webglTexture, _gl.TEXTURE0 + slot); const sourceProperties = properties.get(source); if (source.version !== sourceProperties.__version || forceUpload === true) { state.activeTexture(_gl.TEXTURE0 + slot); const workingPrimaries = ColorManagement2.getPrimaries(ColorManagement2.workingColorSpace); const texturePrimaries = texture.colorSpace === NoColorSpace2 ? null : ColorManagement2.getPrimaries(texture.colorSpace); const unpackConversion = texture.colorSpace === NoColorSpace2 || workingPrimaries === texturePrimaries ? _gl.NONE : _gl.BROWSER_DEFAULT_WEBGL; _gl.pixelStorei(_gl.UNPACK_FLIP_Y_WEBGL, texture.flipY); _gl.pixelStorei(_gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha); _gl.pixelStorei(_gl.UNPACK_ALIGNMENT, texture.unpackAlignment); _gl.pixelStorei(_gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, unpackConversion); const needsPowerOfTwo = textureNeedsPowerOfTwo(texture) && isPowerOfTwo$1(texture.image) === false; let image = resizeImage(texture.image, needsPowerOfTwo, false, maxTextureSize); image = verifyColorSpace(texture, image); const supportsMips = isPowerOfTwo$1(image) || isWebGL2, glFormat = utils.convert(texture.format, texture.colorSpace); let glType = utils.convert(texture.type), glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.colorSpace, texture.isVideoTexture); setTextureParameters(textureType, texture, supportsMips); let mipmap; const mipmaps = texture.mipmaps; const useTexStorage = isWebGL2 && texture.isVideoTexture !== true; const allocateMemory = sourceProperties.__version === void 0 || forceUpload === true; const levels = getMipLevels(texture, image, supportsMips); if (texture.isDepthTexture) { glInternalFormat = _gl.DEPTH_COMPONENT; if (isWebGL2) { if (texture.type === FloatType2) { glInternalFormat = _gl.DEPTH_COMPONENT32F; } else if (texture.type === UnsignedIntType2) { glInternalFormat = _gl.DEPTH_COMPONENT24; } else if (texture.type === UnsignedInt248Type2) { glInternalFormat = _gl.DEPTH24_STENCIL8; } else { glInternalFormat = _gl.DEPTH_COMPONENT16; } } else { if (texture.type === FloatType2) { console.error("WebGLRenderer: Floating point depth texture requires WebGL2."); } } if (texture.format === DepthFormat2 && glInternalFormat === _gl.DEPTH_COMPONENT) { if (texture.type !== UnsignedShortType2 && texture.type !== UnsignedIntType2) { console.warn("THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture."); texture.type = UnsignedIntType2; glType = utils.convert(texture.type); } } if (texture.format === DepthStencilFormat2 && glInternalFormat === _gl.DEPTH_COMPONENT) { glInternalFormat = _gl.DEPTH_STENCIL; if (texture.type !== UnsignedInt248Type2) { console.warn("THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture."); texture.type = UnsignedInt248Type2; glType = utils.convert(texture.type); } } if (allocateMemory) { if (useTexStorage) { state.texStorage2D(_gl.TEXTURE_2D, 1, glInternalFormat, image.width, image.height); } else { state.texImage2D(_gl.TEXTURE_2D, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null); } } } else if (texture.isDataTexture) { if (mipmaps.length > 0 && supportsMips) { if (useTexStorage && allocateMemory) { state.texStorage2D(_gl.TEXTURE_2D, levels, glInternalFormat, mipmaps[0].width, mipmaps[0].height); } for (let i = 0, il = mipmaps.length; i < il; i++) { mipmap = mipmaps[i]; if (useTexStorage) { state.texSubImage2D(_gl.TEXTURE_2D, i, 0, 0, mipmap.width, mipmap.height, glFormat, glType, mipmap.data); } else { state.texImage2D(_gl.TEXTURE_2D, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data); } } texture.generateMipmaps = false; } else { if (useTexStorage) { if (allocateMemory) { state.texStorage2D(_gl.TEXTURE_2D, levels, glInternalFormat, image.width, image.height); } state.texSubImage2D(_gl.TEXTURE_2D, 0, 0, 0, image.width, image.height, glFormat, glType, image.data); } else { state.texImage2D(_gl.TEXTURE_2D, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data); } } } else if (texture.isCompressedTexture) { if (texture.isCompressedArrayTexture) { if (useTexStorage && allocateMemory) { state.texStorage3D(_gl.TEXTURE_2D_ARRAY, levels, glInternalFormat, mipmaps[0].width, mipmaps[0].height, image.depth); } for (let i = 0, il = mipmaps.length; i < il; i++) { mipmap = mipmaps[i]; if (texture.format !== RGBAFormat2) { if (glFormat !== null) { if (useTexStorage) { state.compressedTexSubImage3D(_gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, mipmap.data, 0, 0); } else { state.compressedTexImage3D(_gl.TEXTURE_2D_ARRAY, i, glInternalFormat, mipmap.width, mipmap.height, image.depth, 0, mipmap.data, 0, 0); } } else { console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"); } } else { if (useTexStorage) { state.texSubImage3D(_gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, glType, mipmap.data); } else { state.texImage3D(_gl.TEXTURE_2D_ARRAY, i, glInternalFormat, mipmap.width, mipmap.height, image.depth, 0, glFormat, glType, mipmap.data); } } } } else { if (useTexStorage && allocateMemory) { state.texStorage2D(_gl.TEXTURE_2D, levels, glInternalFormat, mipmaps[0].width, mipmaps[0].height); } for (let i = 0, il = mipmaps.length; i < il; i++) { mipmap = mipmaps[i]; if (texture.format !== RGBAFormat2) { if (glFormat !== null) { if (useTexStorage) { state.compressedTexSubImage2D(_gl.TEXTURE_2D, i, 0, 0, mipmap.width, mipmap.height, glFormat, mipmap.data); } else { state.compressedTexImage2D(_gl.TEXTURE_2D, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data); } } else { console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()"); } } else { if (useTexStorage) { state.texSubImage2D(_gl.TEXTURE_2D, i, 0, 0, mipmap.width, mipmap.height, glFormat, glType, mipmap.data); } else { state.texImage2D(_gl.TEXTURE_2D, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data); } } } } } else if (texture.isDataArrayTexture) { if (useTexStorage) { if (allocateMemory) { state.texStorage3D(_gl.TEXTURE_2D_ARRAY, levels, glInternalFormat, image.width, image.height, image.depth); } state.texSubImage3D(_gl.TEXTURE_2D_ARRAY, 0, 0, 0, 0, image.width, image.height, image.depth, glFormat, glType, image.data); } else { state.texImage3D(_gl.TEXTURE_2D_ARRAY, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data); } } else if (texture.isData3DTexture) { if (useTexStorage) { if (allocateMemory) { state.texStorage3D(_gl.TEXTURE_3D, levels, glInternalFormat, image.width, image.height, image.depth); } state.texSubImage3D(_gl.TEXTURE_3D, 0, 0, 0, 0, image.width, image.height, image.depth, glFormat, glType, image.data); } else { state.texImage3D(_gl.TEXTURE_3D, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data); } } else if (texture.isFramebufferTexture) { if (allocateMemory) { if (useTexStorage) { state.texStorage2D(_gl.TEXTURE_2D, levels, glInternalFormat, image.width, image.height); } else { let width = image.width, height = image.height; for (let i = 0; i < levels; i++) { state.texImage2D(_gl.TEXTURE_2D, i, glInternalFormat, width, height, 0, glFormat, glType, null); width >>= 1; height >>= 1; } } } } else { if (mipmaps.length > 0 && supportsMips) { if (useTexStorage && allocateMemory) { state.texStorage2D(_gl.TEXTURE_2D, levels, glInternalFormat, mipmaps[0].width, mipmaps[0].height); } for (let i = 0, il = mipmaps.length; i < il; i++) { mipmap = mipmaps[i]; if (useTexStorage) { state.texSubImage2D(_gl.TEXTURE_2D, i, 0, 0, glFormat, glType, mipmap); } else { state.texImage2D(_gl.TEXTURE_2D, i, glInternalFormat, glFormat, glType, mipmap); } } texture.generateMipmaps = false; } else { if (useTexStorage) { if (allocateMemory) { state.texStorage2D(_gl.TEXTURE_2D, levels, glInternalFormat, image.width, image.height); } state.texSubImage2D(_gl.TEXTURE_2D, 0, 0, 0, glFormat, glType, image); } else { state.texImage2D(_gl.TEXTURE_2D, 0, glInternalFormat, glFormat, glType, image); } } } if (textureNeedsGenerateMipmaps(texture, supportsMips)) { generateMipmap(textureType); } sourceProperties.__version = source.version; if (texture.onUpdate) texture.onUpdate(texture); } textureProperties.__version = texture.version; } function uploadCubeTexture(textureProperties, texture, slot) { if (texture.image.length !== 6) return; const forceUpload = initTexture(textureProperties, texture); const source = texture.source; state.bindTexture(_gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture, _gl.TEXTURE0 + slot); const sourceProperties = properties.get(source); if (source.version !== sourceProperties.__version || forceUpload === true) { state.activeTexture(_gl.TEXTURE0 + slot); const workingPrimaries = ColorManagement2.getPrimaries(ColorManagement2.workingColorSpace); const texturePrimaries = texture.colorSpace === NoColorSpace2 ? null : ColorManagement2.getPrimaries(texture.colorSpace); const unpackConversion = texture.colorSpace === NoColorSpace2 || workingPrimaries === texturePrimaries ? _gl.NONE : _gl.BROWSER_DEFAULT_WEBGL; _gl.pixelStorei(_gl.UNPACK_FLIP_Y_WEBGL, texture.flipY); _gl.pixelStorei(_gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha); _gl.pixelStorei(_gl.UNPACK_ALIGNMENT, texture.unpackAlignment); _gl.pixelStorei(_gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, unpackConversion); const isCompressed = texture.isCompressedTexture || texture.image[0].isCompressedTexture; const isDataTexture = texture.image[0] && texture.image[0].isDataTexture; const cubeImage = []; for (let i = 0; i < 6; i++) { if (!isCompressed && !isDataTexture) { cubeImage[i] = resizeImage(texture.image[i], false, true, maxCubemapSize); } else { cubeImage[i] = isDataTexture ? texture.image[i].image : texture.image[i]; } cubeImage[i] = verifyColorSpace(texture, cubeImage[i]); } const image = cubeImage[0], supportsMips = isPowerOfTwo$1(image) || isWebGL2, glFormat = utils.convert(texture.format, texture.colorSpace), glType = utils.convert(texture.type), glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.colorSpace); const useTexStorage = isWebGL2 && texture.isVideoTexture !== true; const allocateMemory = sourceProperties.__version === void 0 || forceUpload === true; let levels = getMipLevels(texture, image, supportsMips); setTextureParameters(_gl.TEXTURE_CUBE_MAP, texture, supportsMips); let mipmaps; if (isCompressed) { if (useTexStorage && allocateMemory) { state.texStorage2D(_gl.TEXTURE_CUBE_MAP, levels, glInternalFormat, image.width, image.height); } for (let i = 0; i < 6; i++) { mipmaps = cubeImage[i].mipmaps; for (let j = 0; j < mipmaps.length; j++) { const mipmap = mipmaps[j]; if (texture.format !== RGBAFormat2) { if (glFormat !== null) { if (useTexStorage) { state.compressedTexSubImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, 0, 0, mipmap.width, mipmap.height, glFormat, mipmap.data); } else { state.compressedTexImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data); } } else { console.warn("THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()"); } } else { if (useTexStorage) { state.texSubImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, 0, 0, mipmap.width, mipmap.height, glFormat, glType, mipmap.data); } else { state.texImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data); } } } } } else { mipmaps = texture.mipmaps; if (useTexStorage && allocateMemory) { if (mipmaps.length > 0) levels++; state.texStorage2D(_gl.TEXTURE_CUBE_MAP, levels, glInternalFormat, cubeImage[0].width, cubeImage[0].height); } for (let i = 0; i < 6; i++) { if (isDataTexture) { if (useTexStorage) { state.texSubImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 0, 0, cubeImage[i].width, cubeImage[i].height, glFormat, glType, cubeImage[i].data); } else { state.texImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glInternalFormat, cubeImage[i].width, cubeImage[i].height, 0, glFormat, glType, cubeImage[i].data); } for (let j = 0; j < mipmaps.length; j++) { const mipmap = mipmaps[j]; const mipmapImage = mipmap.image[i].image; if (useTexStorage) { state.texSubImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, 0, 0, mipmapImage.width, mipmapImage.height, glFormat, glType, mipmapImage.data); } else { state.texImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data); } } } else { if (useTexStorage) { state.texSubImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, 0, 0, glFormat, glType, cubeImage[i]); } else { state.texImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glInternalFormat, glFormat, glType, cubeImage[i]); } for (let j = 0; j < mipmaps.length; j++) { const mipmap = mipmaps[j]; if (useTexStorage) { state.texSubImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, 0, 0, glFormat, glType, mipmap.image[i]); } else { state.texImage2D(_gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j + 1, glInternalFormat, glFormat, glType, mipmap.image[i]); } } } } } if (textureNeedsGenerateMipmaps(texture, supportsMips)) { generateMipmap(_gl.TEXTURE_CUBE_MAP); } sourceProperties.__version = source.version; if (texture.onUpdate) texture.onUpdate(texture); } textureProperties.__version = texture.version; } function setupFrameBufferTexture(framebuffer, renderTarget, texture, attachment, textureTarget, level) { const glFormat = utils.convert(texture.format, texture.colorSpace); const glType = utils.convert(texture.type); const glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.colorSpace); const renderTargetProperties = properties.get(renderTarget); if (!renderTargetProperties.__hasExternalTextures) { const width = Math.max(1, renderTarget.width >> level); const height = Math.max(1, renderTarget.height >> level); if (textureTarget === _gl.TEXTURE_3D || textureTarget === _gl.TEXTURE_2D_ARRAY) { state.texImage3D(textureTarget, level, glInternalFormat, width, height, renderTarget.depth, 0, glFormat, glType, null); } else { state.texImage2D(textureTarget, level, glInternalFormat, width, height, 0, glFormat, glType, null); } } state.bindFramebuffer(_gl.FRAMEBUFFER, framebuffer); if (useMultisampledRTT(renderTarget)) { multisampledRTTExt.framebufferTexture2DMultisampleEXT(_gl.FRAMEBUFFER, attachment, textureTarget, properties.get(texture).__webglTexture, 0, getRenderTargetSamples(renderTarget)); } else if (textureTarget === _gl.TEXTURE_2D || textureTarget >= _gl.TEXTURE_CUBE_MAP_POSITIVE_X && textureTarget <= _gl.TEXTURE_CUBE_MAP_NEGATIVE_Z) { _gl.framebufferTexture2D(_gl.FRAMEBUFFER, attachment, textureTarget, properties.get(texture).__webglTexture, level); } state.bindFramebuffer(_gl.FRAMEBUFFER, null); } function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) { _gl.bindRenderbuffer(_gl.RENDERBUFFER, renderbuffer); if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) { let glInternalFormat = isWebGL2 === true ? _gl.DEPTH_COMPONENT24 : _gl.DEPTH_COMPONENT16; if (isMultisample || useMultisampledRTT(renderTarget)) { const depthTexture = renderTarget.depthTexture; if (depthTexture && depthTexture.isDepthTexture) { if (depthTexture.type === FloatType2) { glInternalFormat = _gl.DEPTH_COMPONENT32F; } else if (depthTexture.type === UnsignedIntType2) { glInternalFormat = _gl.DEPTH_COMPONENT24; } } const samples = getRenderTargetSamples(renderTarget); if (useMultisampledRTT(renderTarget)) { multisampledRTTExt.renderbufferStorageMultisampleEXT(_gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height); } else { _gl.renderbufferStorageMultisample(_gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height); } } else { _gl.renderbufferStorage(_gl.RENDERBUFFER, glInternalFormat, renderTarget.width, renderTarget.height); } _gl.framebufferRenderbuffer(_gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer); } else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) { const samples = getRenderTargetSamples(renderTarget); if (isMultisample && useMultisampledRTT(renderTarget) === false) { _gl.renderbufferStorageMultisample(_gl.RENDERBUFFER, samples, _gl.DEPTH24_STENCIL8, renderTarget.width, renderTarget.height); } else if (useMultisampledRTT(renderTarget)) { multisampledRTTExt.renderbufferStorageMultisampleEXT(_gl.RENDERBUFFER, samples, _gl.DEPTH24_STENCIL8, renderTarget.width, renderTarget.height); } else { _gl.renderbufferStorage(_gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height); } _gl.framebufferRenderbuffer(_gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer); } else { const textures = renderTarget.isWebGLMultipleRenderTargets === true ? renderTarget.texture : [renderTarget.texture]; for (let i = 0; i < textures.length; i++) { const texture = textures[i]; const glFormat = utils.convert(texture.format, texture.colorSpace); const glType = utils.convert(texture.type); const glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.colorSpace); const samples = getRenderTargetSamples(renderTarget); if (isMultisample && useMultisampledRTT(renderTarget) === false) { _gl.renderbufferStorageMultisample(_gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height); } else if (useMultisampledRTT(renderTarget)) { multisampledRTTExt.renderbufferStorageMultisampleEXT(_gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height); } else { _gl.renderbufferStorage(_gl.RENDERBUFFER, glInternalFormat, renderTarget.width, renderTarget.height); } } } _gl.bindRenderbuffer(_gl.RENDERBUFFER, null); } function setupDepthTexture(framebuffer, renderTarget) { const isCube = renderTarget && renderTarget.isWebGLCubeRenderTarget; if (isCube) throw new Error("Depth Texture with cube render targets is not supported"); state.bindFramebuffer(_gl.FRAMEBUFFER, framebuffer); if (!(renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture)) { throw new Error("renderTarget.depthTexture must be an instance of THREE.DepthTexture"); } if (!properties.get(renderTarget.depthTexture).__webglTexture || renderTarget.depthTexture.image.width !== renderTarget.width || renderTarget.depthTexture.image.height !== renderTarget.height) { renderTarget.depthTexture.image.width = renderTarget.width; renderTarget.depthTexture.image.height = renderTarget.height; renderTarget.depthTexture.needsUpdate = true; } setTexture2D(renderTarget.depthTexture, 0); const webglDepthTexture = properties.get(renderTarget.depthTexture).__webglTexture; const samples = getRenderTargetSamples(renderTarget); if (renderTarget.depthTexture.format === DepthFormat2) { if (useMultisampledRTT(renderTarget)) { multisampledRTTExt.framebufferTexture2DMultisampleEXT(_gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0, samples); } else { _gl.framebufferTexture2D(_gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0); } } else if (renderTarget.depthTexture.format === DepthStencilFormat2) { if (useMultisampledRTT(renderTarget)) { multisampledRTTExt.framebufferTexture2DMultisampleEXT(_gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0, samples); } else { _gl.framebufferTexture2D(_gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.TEXTURE_2D, webglDepthTexture, 0); } } else { throw new Error("Unknown depthTexture format"); } } function setupDepthRenderbuffer(renderTarget) { const renderTargetProperties = properties.get(renderTarget); const isCube = renderTarget.isWebGLCubeRenderTarget === true; if (renderTarget.depthTexture && !renderTargetProperties.__autoAllocateDepthBuffer) { if (isCube) throw new Error("target.depthTexture not supported in Cube render targets"); setupDepthTexture(renderTargetProperties.__webglFramebuffer, renderTarget); } else { if (isCube) { renderTargetProperties.__webglDepthbuffer = []; for (let i = 0; i < 6; i++) { state.bindFramebuffer(_gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[i]); renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer(); setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false); } } else { state.bindFramebuffer(_gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer); renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer(); setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false); } } state.bindFramebuffer(_gl.FRAMEBUFFER, null); } function rebindTextures(renderTarget, colorTexture, depthTexture) { const renderTargetProperties = properties.get(renderTarget); if (colorTexture !== void 0) { setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, renderTarget.texture, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, 0); } if (depthTexture !== void 0) { setupDepthRenderbuffer(renderTarget); } } function setupRenderTarget(renderTarget) { const texture = renderTarget.texture; const renderTargetProperties = properties.get(renderTarget); const textureProperties = properties.get(texture); renderTarget.addEventListener("dispose", onRenderTargetDispose); if (renderTarget.isWebGLMultipleRenderTargets !== true) { if (textureProperties.__webglTexture === void 0) { textureProperties.__webglTexture = _gl.createTexture(); } textureProperties.__version = texture.version; info.memory.textures++; } const isCube = renderTarget.isWebGLCubeRenderTarget === true; const isMultipleRenderTargets = renderTarget.isWebGLMultipleRenderTargets === true; const supportsMips = isPowerOfTwo$1(renderTarget) || isWebGL2; if (isCube) { renderTargetProperties.__webglFramebuffer = []; for (let i = 0; i < 6; i++) { if (isWebGL2 && texture.mipmaps && texture.mipmaps.length > 0) { renderTargetProperties.__webglFramebuffer[i] = []; for (let level = 0; level < texture.mipmaps.length; level++) { renderTargetProperties.__webglFramebuffer[i][level] = _gl.createFramebuffer(); } } else { renderTargetProperties.__webglFramebuffer[i] = _gl.createFramebuffer(); } } } else { if (isWebGL2 && texture.mipmaps && texture.mipmaps.length > 0) { renderTargetProperties.__webglFramebuffer = []; for (let level = 0; level < texture.mipmaps.length; level++) { renderTargetProperties.__webglFramebuffer[level] = _gl.createFramebuffer(); } } else { renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer(); } if (isMultipleRenderTargets) { if (capabilities.drawBuffers) { const textures = renderTarget.texture; for (let i = 0, il = textures.length; i < il; i++) { const attachmentProperties = properties.get(textures[i]); if (attachmentProperties.__webglTexture === void 0) { attachmentProperties.__webglTexture = _gl.createTexture(); info.memory.textures++; } } } else { console.warn("THREE.WebGLRenderer: WebGLMultipleRenderTargets can only be used with WebGL2 or WEBGL_draw_buffers extension."); } } if (isWebGL2 && renderTarget.samples > 0 && useMultisampledRTT(renderTarget) === false) { const textures = isMultipleRenderTargets ? texture : [texture]; renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer(); renderTargetProperties.__webglColorRenderbuffer = []; state.bindFramebuffer(_gl.FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer); for (let i = 0; i < textures.length; i++) { const texture2 = textures[i]; renderTargetProperties.__webglColorRenderbuffer[i] = _gl.createRenderbuffer(); _gl.bindRenderbuffer(_gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer[i]); const glFormat = utils.convert(texture2.format, texture2.colorSpace); const glType = utils.convert(texture2.type); const glInternalFormat = getInternalFormat(texture2.internalFormat, glFormat, glType, texture2.colorSpace, renderTarget.isXRRenderTarget === true); const samples = getRenderTargetSamples(renderTarget); _gl.renderbufferStorageMultisample(_gl.RENDERBUFFER, samples, glInternalFormat, renderTarget.width, renderTarget.height); _gl.framebufferRenderbuffer(_gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer[i]); } _gl.bindRenderbuffer(_gl.RENDERBUFFER, null); if (renderTarget.depthBuffer) { renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer(); setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true); } state.bindFramebuffer(_gl.FRAMEBUFFER, null); } } if (isCube) { state.bindTexture(_gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture); setTextureParameters(_gl.TEXTURE_CUBE_MAP, texture, supportsMips); for (let i = 0; i < 6; i++) { if (isWebGL2 && texture.mipmaps && texture.mipmaps.length > 0) { for (let level = 0; level < texture.mipmaps.length; level++) { setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[i][level], renderTarget, texture, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, level); } } else { setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[i], renderTarget, texture, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0); } } if (textureNeedsGenerateMipmaps(texture, supportsMips)) { generateMipmap(_gl.TEXTURE_CUBE_MAP); } state.unbindTexture(); } else if (isMultipleRenderTargets) { const textures = renderTarget.texture; for (let i = 0, il = textures.length; i < il; i++) { const attachment = textures[i]; const attachmentProperties = properties.get(attachment); state.bindTexture(_gl.TEXTURE_2D, attachmentProperties.__webglTexture); setTextureParameters(_gl.TEXTURE_2D, attachment, supportsMips); setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, attachment, _gl.COLOR_ATTACHMENT0 + i, _gl.TEXTURE_2D, 0); if (textureNeedsGenerateMipmaps(attachment, supportsMips)) { generateMipmap(_gl.TEXTURE_2D); } } state.unbindTexture(); } else { let glTextureType = _gl.TEXTURE_2D; if (renderTarget.isWebGL3DRenderTarget || renderTarget.isWebGLArrayRenderTarget) { if (isWebGL2) { glTextureType = renderTarget.isWebGL3DRenderTarget ? _gl.TEXTURE_3D : _gl.TEXTURE_2D_ARRAY; } else { console.error("THREE.WebGLTextures: THREE.Data3DTexture and THREE.DataArrayTexture only supported with WebGL2."); } } state.bindTexture(glTextureType, textureProperties.__webglTexture); setTextureParameters(glTextureType, texture, supportsMips); if (isWebGL2 && texture.mipmaps && texture.mipmaps.length > 0) { for (let level = 0; level < texture.mipmaps.length; level++) { setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[level], renderTarget, texture, _gl.COLOR_ATTACHMENT0, glTextureType, level); } } else { setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, texture, _gl.COLOR_ATTACHMENT0, glTextureType, 0); } if (textureNeedsGenerateMipmaps(texture, supportsMips)) { generateMipmap(glTextureType); } state.unbindTexture(); } if (renderTarget.depthBuffer) { setupDepthRenderbuffer(renderTarget); } } function updateRenderTargetMipmap(renderTarget) { const supportsMips = isPowerOfTwo$1(renderTarget) || isWebGL2; const textures = renderTarget.isWebGLMultipleRenderTargets === true ? renderTarget.texture : [renderTarget.texture]; for (let i = 0, il = textures.length; i < il; i++) { const texture = textures[i]; if (textureNeedsGenerateMipmaps(texture, supportsMips)) { const target = renderTarget.isWebGLCubeRenderTarget ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D; const webglTexture = properties.get(texture).__webglTexture; state.bindTexture(target, webglTexture); generateMipmap(target); state.unbindTexture(); } } } function updateMultisampleRenderTarget(renderTarget) { if (isWebGL2 && renderTarget.samples > 0 && useMultisampledRTT(renderTarget) === false) { const textures = renderTarget.isWebGLMultipleRenderTargets ? renderTarget.texture : [renderTarget.texture]; const width = renderTarget.width; const height = renderTarget.height; let mask = _gl.COLOR_BUFFER_BIT; const invalidationArray = []; const depthStyle = renderTarget.stencilBuffer ? _gl.DEPTH_STENCIL_ATTACHMENT : _gl.DEPTH_ATTACHMENT; const renderTargetProperties = properties.get(renderTarget); const isMultipleRenderTargets = renderTarget.isWebGLMultipleRenderTargets === true; if (isMultipleRenderTargets) { for (let i = 0; i < textures.length; i++) { state.bindFramebuffer(_gl.FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer); _gl.framebufferRenderbuffer(_gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.RENDERBUFFER, null); state.bindFramebuffer(_gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer); _gl.framebufferTexture2D(_gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.TEXTURE_2D, null, 0); } } state.bindFramebuffer(_gl.READ_FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer); state.bindFramebuffer(_gl.DRAW_FRAMEBUFFER, renderTargetProperties.__webglFramebuffer); for (let i = 0; i < textures.length; i++) { invalidationArray.push(_gl.COLOR_ATTACHMENT0 + i); if (renderTarget.depthBuffer) { invalidationArray.push(depthStyle); } const ignoreDepthValues = renderTargetProperties.__ignoreDepthValues !== void 0 ? renderTargetProperties.__ignoreDepthValues : false; if (ignoreDepthValues === false) { if (renderTarget.depthBuffer) mask |= _gl.DEPTH_BUFFER_BIT; if (renderTarget.stencilBuffer) mask |= _gl.STENCIL_BUFFER_BIT; } if (isMultipleRenderTargets) { _gl.framebufferRenderbuffer(_gl.READ_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer[i]); } if (ignoreDepthValues === true) { _gl.invalidateFramebuffer(_gl.READ_FRAMEBUFFER, [depthStyle]); _gl.invalidateFramebuffer(_gl.DRAW_FRAMEBUFFER, [depthStyle]); } if (isMultipleRenderTargets) { const webglTexture = properties.get(textures[i]).__webglTexture; _gl.framebufferTexture2D(_gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, webglTexture, 0); } _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, _gl.NEAREST); if (supportsInvalidateFramebuffer) { _gl.invalidateFramebuffer(_gl.READ_FRAMEBUFFER, invalidationArray); } } state.bindFramebuffer(_gl.READ_FRAMEBUFFER, null); state.bindFramebuffer(_gl.DRAW_FRAMEBUFFER, null); if (isMultipleRenderTargets) { for (let i = 0; i < textures.length; i++) { state.bindFramebuffer(_gl.FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer); _gl.framebufferRenderbuffer(_gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.RENDERBUFFER, renderTargetProperties.__webglColorRenderbuffer[i]); const webglTexture = properties.get(textures[i]).__webglTexture; state.bindFramebuffer(_gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer); _gl.framebufferTexture2D(_gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0 + i, _gl.TEXTURE_2D, webglTexture, 0); } } state.bindFramebuffer(_gl.DRAW_FRAMEBUFFER, renderTargetProperties.__webglMultisampledFramebuffer); } } function getRenderTargetSamples(renderTarget) { return Math.min(maxSamples, renderTarget.samples); } function useMultisampledRTT(renderTarget) { const renderTargetProperties = properties.get(renderTarget); return isWebGL2 && renderTarget.samples > 0 && extensions.has("WEBGL_multisampled_render_to_texture") === true && renderTargetProperties.__useRenderToTexture !== false; } function updateVideoTexture(texture) { const frame2 = info.render.frame; if (_videoTextures.get(texture) !== frame2) { _videoTextures.set(texture, frame2); texture.update(); } } function verifyColorSpace(texture, image) { const colorSpace = texture.colorSpace; const format2 = texture.format; const type = texture.type; if (texture.isCompressedTexture === true || texture.isVideoTexture === true || texture.format === _SRGBAFormat2) return image; if (colorSpace !== LinearSRGBColorSpace2 && colorSpace !== NoColorSpace2) { if (ColorManagement2.getTransfer(colorSpace) === SRGBTransfer2) { if (isWebGL2 === false) { if (extensions.has("EXT_sRGB") === true && format2 === RGBAFormat2) { texture.format = _SRGBAFormat2; texture.minFilter = LinearFilter2; texture.generateMipmaps = false; } else { image = ImageUtils2.sRGBToLinear(image); } } else { if (format2 !== RGBAFormat2 || type !== UnsignedByteType2) { console.warn("THREE.WebGLTextures: sRGB encoded textures have to use RGBAFormat and UnsignedByteType."); } } } else { console.error("THREE.WebGLTextures: Unsupported texture color space:", colorSpace); } } return image; } this.allocateTextureUnit = allocateTextureUnit; this.resetTextureUnits = resetTextureUnits; this.setTexture2D = setTexture2D; this.setTexture2DArray = setTexture2DArray; this.setTexture3D = setTexture3D; this.setTextureCube = setTextureCube; this.rebindTextures = rebindTextures; this.setupRenderTarget = setupRenderTarget; this.updateRenderTargetMipmap = updateRenderTargetMipmap; this.updateMultisampleRenderTarget = updateMultisampleRenderTarget; this.setupDepthRenderbuffer = setupDepthRenderbuffer; this.setupFrameBufferTexture = setupFrameBufferTexture; this.useMultisampledRTT = useMultisampledRTT; } function WebGLUtils2(gl, extensions, capabilities) { const isWebGL2 = capabilities.isWebGL2; function convert(p, colorSpace = NoColorSpace2) { let extension; const transfer = ColorManagement2.getTransfer(colorSpace); if (p === UnsignedByteType2) return gl.UNSIGNED_BYTE; if (p === UnsignedShort4444Type2) return gl.UNSIGNED_SHORT_4_4_4_4; if (p === UnsignedShort5551Type2) return gl.UNSIGNED_SHORT_5_5_5_1; if (p === ByteType2) return gl.BYTE; if (p === ShortType2) return gl.SHORT; if (p === UnsignedShortType2) return gl.UNSIGNED_SHORT; if (p === IntType2) return gl.INT; if (p === UnsignedIntType2) return gl.UNSIGNED_INT; if (p === FloatType2) return gl.FLOAT; if (p === HalfFloatType2) { if (isWebGL2) return gl.HALF_FLOAT; extension = extensions.get("OES_texture_half_float"); if (extension !== null) { return extension.HALF_FLOAT_OES; } else { return null; } } if (p === AlphaFormat2) return gl.ALPHA; if (p === RGBAFormat2) return gl.RGBA; if (p === LuminanceFormat2) return gl.LUMINANCE; if (p === LuminanceAlphaFormat2) return gl.LUMINANCE_ALPHA; if (p === DepthFormat2) return gl.DEPTH_COMPONENT; if (p === DepthStencilFormat2) return gl.DEPTH_STENCIL; if (p === _SRGBAFormat2) { extension = extensions.get("EXT_sRGB"); if (extension !== null) { return extension.SRGB_ALPHA_EXT; } else { return null; } } if (p === RedFormat2) return gl.RED; if (p === RedIntegerFormat2) return gl.RED_INTEGER; if (p === RGFormat2) return gl.RG; if (p === RGIntegerFormat2) return gl.RG_INTEGER; if (p === RGBAIntegerFormat2) return gl.RGBA_INTEGER; if (p === RGB_S3TC_DXT1_Format2 || p === RGBA_S3TC_DXT1_Format2 || p === RGBA_S3TC_DXT3_Format2 || p === RGBA_S3TC_DXT5_Format2) { if (transfer === SRGBTransfer2) { extension = extensions.get("WEBGL_compressed_texture_s3tc_srgb"); if (extension !== null) { if (p === RGB_S3TC_DXT1_Format2) return extension.COMPRESSED_SRGB_S3TC_DXT1_EXT; if (p === RGBA_S3TC_DXT1_Format2) return extension.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT; if (p === RGBA_S3TC_DXT3_Format2) return extension.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT; if (p === RGBA_S3TC_DXT5_Format2) return extension.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT; } else { return null; } } else { extension = extensions.get("WEBGL_compressed_texture_s3tc"); if (extension !== null) { if (p === RGB_S3TC_DXT1_Format2) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT; if (p === RGBA_S3TC_DXT1_Format2) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT; if (p === RGBA_S3TC_DXT3_Format2) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT; if (p === RGBA_S3TC_DXT5_Format2) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT; } else { return null; } } } if (p === RGB_PVRTC_4BPPV1_Format2 || p === RGB_PVRTC_2BPPV1_Format2 || p === RGBA_PVRTC_4BPPV1_Format2 || p === RGBA_PVRTC_2BPPV1_Format2) { extension = extensions.get("WEBGL_compressed_texture_pvrtc"); if (extension !== null) { if (p === RGB_PVRTC_4BPPV1_Format2) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG; if (p === RGB_PVRTC_2BPPV1_Format2) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG; if (p === RGBA_PVRTC_4BPPV1_Format2) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG; if (p === RGBA_PVRTC_2BPPV1_Format2) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG; } else { return null; } } if (p === RGB_ETC1_Format2) { extension = extensions.get("WEBGL_compressed_texture_etc1"); if (extension !== null) { return extension.COMPRESSED_RGB_ETC1_WEBGL; } else { return null; } } if (p === RGB_ETC2_Format2 || p === RGBA_ETC2_EAC_Format2) { extension = extensions.get("WEBGL_compressed_texture_etc"); if (extension !== null) { if (p === RGB_ETC2_Format2) return transfer === SRGBTransfer2 ? extension.COMPRESSED_SRGB8_ETC2 : extension.COMPRESSED_RGB8_ETC2; if (p === RGBA_ETC2_EAC_Format2) return transfer === SRGBTransfer2 ? extension.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC : extension.COMPRESSED_RGBA8_ETC2_EAC; } else { return null; } } if (p === RGBA_ASTC_4x4_Format2 || p === RGBA_ASTC_5x4_Format2 || p === RGBA_ASTC_5x5_Format2 || p === RGBA_ASTC_6x5_Format2 || p === RGBA_ASTC_6x6_Format2 || p === RGBA_ASTC_8x5_Format2 || p === RGBA_ASTC_8x6_Format2 || p === RGBA_ASTC_8x8_Format2 || p === RGBA_ASTC_10x5_Format2 || p === RGBA_ASTC_10x6_Format2 || p === RGBA_ASTC_10x8_Format2 || p === RGBA_ASTC_10x10_Format2 || p === RGBA_ASTC_12x10_Format2 || p === RGBA_ASTC_12x12_Format2) { extension = extensions.get("WEBGL_compressed_texture_astc"); if (extension !== null) { if (p === RGBA_ASTC_4x4_Format2) return transfer === SRGBTransfer2 ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR : extension.COMPRESSED_RGBA_ASTC_4x4_KHR; if (p === RGBA_ASTC_5x4_Format2) return transfer === SRGBTransfer2 ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR : extension.COMPRESSED_RGBA_ASTC_5x4_KHR; if (p === RGBA_ASTC_5x5_Format2) return transfer === SRGBTransfer2 ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR : extension.COMPRESSED_RGBA_ASTC_5x5_KHR; if (p === RGBA_ASTC_6x5_Format2) return transfer === SRGBTransfer2 ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR : extension.COMPRESSED_RGBA_ASTC_6x5_KHR; if (p === RGBA_ASTC_6x6_Format2) return transfer === SRGBTransfer2 ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR : extension.COMPRESSED_RGBA_ASTC_6x6_KHR; if (p === RGBA_ASTC_8x5_Format2) return transfer === SRGBTransfer2 ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR : extension.COMPRESSED_RGBA_ASTC_8x5_KHR; if (p === RGBA_ASTC_8x6_Format2) return transfer === SRGBTransfer2 ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR : extension.COMPRESSED_RGBA_ASTC_8x6_KHR; if (p === RGBA_ASTC_8x8_Format2) return transfer === SRGBTransfer2 ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR : extension.COMPRESSED_RGBA_ASTC_8x8_KHR; if (p === RGBA_ASTC_10x5_Format2) return transfer === SRGBTransfer2 ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR : extension.COMPRESSED_RGBA_ASTC_10x5_KHR; if (p === RGBA_ASTC_10x6_Format2) return transfer === SRGBTransfer2 ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR : extension.COMPRESSED_RGBA_ASTC_10x6_KHR; if (p === RGBA_ASTC_10x8_Format2) return transfer === SRGBTransfer2 ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR : extension.COMPRESSED_RGBA_ASTC_10x8_KHR; if (p === RGBA_ASTC_10x10_Format2) return transfer === SRGBTransfer2 ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR : extension.COMPRESSED_RGBA_ASTC_10x10_KHR; if (p === RGBA_ASTC_12x10_Format2) return transfer === SRGBTransfer2 ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR : extension.COMPRESSED_RGBA_ASTC_12x10_KHR; if (p === RGBA_ASTC_12x12_Format2) return transfer === SRGBTransfer2 ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR : extension.COMPRESSED_RGBA_ASTC_12x12_KHR; } else { return null; } } if (p === RGBA_BPTC_Format2 || p === RGB_BPTC_SIGNED_Format2 || p === RGB_BPTC_UNSIGNED_Format2) { extension = extensions.get("EXT_texture_compression_bptc"); if (extension !== null) { if (p === RGBA_BPTC_Format2) return transfer === SRGBTransfer2 ? extension.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT : extension.COMPRESSED_RGBA_BPTC_UNORM_EXT; if (p === RGB_BPTC_SIGNED_Format2) return extension.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT; if (p === RGB_BPTC_UNSIGNED_Format2) return extension.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT; } else { return null; } } if (p === RED_RGTC1_Format2 || p === SIGNED_RED_RGTC1_Format2 || p === RED_GREEN_RGTC2_Format2 || p === SIGNED_RED_GREEN_RGTC2_Format2) { extension = extensions.get("EXT_texture_compression_rgtc"); if (extension !== null) { if (p === RGBA_BPTC_Format2) return extension.COMPRESSED_RED_RGTC1_EXT; if (p === SIGNED_RED_RGTC1_Format2) return extension.COMPRESSED_SIGNED_RED_RGTC1_EXT; if (p === RED_GREEN_RGTC2_Format2) return extension.COMPRESSED_RED_GREEN_RGTC2_EXT; if (p === SIGNED_RED_GREEN_RGTC2_Format2) return extension.COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT; } else { return null; } } if (p === UnsignedInt248Type2) { if (isWebGL2) return gl.UNSIGNED_INT_24_8; extension = extensions.get("WEBGL_depth_texture"); if (extension !== null) { return extension.UNSIGNED_INT_24_8_WEBGL; } else { return null; } } return gl[p] !== void 0 ? gl[p] : null; } return { convert }; } var ArrayCamera2 = class extends PerspectiveCamera2 { constructor(array = []) { super(); this.isArrayCamera = true; this.cameras = array; } }; var Group2 = class extends Object3D2 { constructor() { super(); this.isGroup = true; this.type = "Group"; } }; var _moveEvent2 = { type: "move" }; var WebXRController2 = class { constructor() { this._targetRay = null; this._grip = null; this._hand = null; } getHandSpace() { if (this._hand === null) { this._hand = new Group2(); this._hand.matrixAutoUpdate = false; this._hand.visible = false; this._hand.joints = {}; this._hand.inputState = { pinching: false }; } return this._hand; } getTargetRaySpace() { if (this._targetRay === null) { this._targetRay = new Group2(); this._targetRay.matrixAutoUpdate = false; this._targetRay.visible = false; this._targetRay.hasLinearVelocity = false; this._targetRay.linearVelocity = new Vector32(); this._targetRay.hasAngularVelocity = false; this._targetRay.angularVelocity = new Vector32(); } return this._targetRay; } getGripSpace() { if (this._grip === null) { this._grip = new Group2(); this._grip.matrixAutoUpdate = false; this._grip.visible = false; this._grip.hasLinearVelocity = false; this._grip.linearVelocity = new Vector32(); this._grip.hasAngularVelocity = false; this._grip.angularVelocity = new Vector32(); } return this._grip; } dispatchEvent(event) { if (this._targetRay !== null) { this._targetRay.dispatchEvent(event); } if (this._grip !== null) { this._grip.dispatchEvent(event); } if (this._hand !== null) { this._hand.dispatchEvent(event); } return this; } connect(inputSource) { if (inputSource && inputSource.hand) { const hand = this._hand; if (hand) { for (const inputjoint of inputSource.hand.values()) { this._getHandJoint(hand, inputjoint); } } } this.dispatchEvent({ type: "connected", data: inputSource }); return this; } disconnect(inputSource) { this.dispatchEvent({ type: "disconnected", data: inputSource }); if (this._targetRay !== null) { this._targetRay.visible = false; } if (this._grip !== null) { this._grip.visible = false; } if (this._hand !== null) { this._hand.visible = false; } return this; } update(inputSource, frame2, referenceSpace) { let inputPose = null; let gripPose = null; let handPose = null; const targetRay = this._targetRay; const grip = this._grip; const hand = this._hand; if (inputSource && frame2.session.visibilityState !== "visible-blurred") { if (hand && inputSource.hand) { handPose = true; for (const inputjoint of inputSource.hand.values()) { const jointPose = frame2.getJointPose(inputjoint, referenceSpace); const joint = this._getHandJoint(hand, inputjoint); if (jointPose !== null) { joint.matrix.fromArray(jointPose.transform.matrix); joint.matrix.decompose(joint.position, joint.rotation, joint.scale); joint.matrixWorldNeedsUpdate = true; joint.jointRadius = jointPose.radius; } joint.visible = jointPose !== null; } const indexTip = hand.joints["index-finger-tip"]; const thumbTip = hand.joints["thumb-tip"]; const distance = indexTip.position.distanceTo(thumbTip.position); const distanceToPinch = 0.02; const threshold = 5e-3; if (hand.inputState.pinching && distance > distanceToPinch + threshold) { hand.inputState.pinching = false; this.dispatchEvent({ type: "pinchend", handedness: inputSource.handedness, target: this }); } else if (!hand.inputState.pinching && distance <= distanceToPinch - threshold) { hand.inputState.pinching = true; this.dispatchEvent({ type: "pinchstart", handedness: inputSource.handedness, target: this }); } } else { if (grip !== null && inputSource.gripSpace) { gripPose = frame2.getPose(inputSource.gripSpace, referenceSpace); if (gripPose !== null) { grip.matrix.fromArray(gripPose.transform.matrix); grip.matrix.decompose(grip.position, grip.rotation, grip.scale); grip.matrixWorldNeedsUpdate = true; if (gripPose.linearVelocity) { grip.hasLinearVelocity = true; grip.linearVelocity.copy(gripPose.linearVelocity); } else { grip.hasLinearVelocity = false; } if (gripPose.angularVelocity) { grip.hasAngularVelocity = true; grip.angularVelocity.copy(gripPose.angularVelocity); } else { grip.hasAngularVelocity = false; } } } } if (targetRay !== null) { inputPose = frame2.getPose(inputSource.targetRaySpace, referenceSpace); if (inputPose === null && gripPose !== null) { inputPose = gripPose; } if (inputPose !== null) { targetRay.matrix.fromArray(inputPose.transform.matrix); targetRay.matrix.decompose(targetRay.position, targetRay.rotation, targetRay.scale); targetRay.matrixWorldNeedsUpdate = true; if (inputPose.linearVelocity) { targetRay.hasLinearVelocity = true; targetRay.linearVelocity.copy(inputPose.linearVelocity); } else { targetRay.hasLinearVelocity = false; } if (inputPose.angularVelocity) { targetRay.hasAngularVelocity = true; targetRay.angularVelocity.copy(inputPose.angularVelocity); } else { targetRay.hasAngularVelocity = false; } this.dispatchEvent(_moveEvent2); } } } if (targetRay !== null) { targetRay.visible = inputPose !== null; } if (grip !== null) { grip.visible = gripPose !== null; } if (hand !== null) { hand.visible = handPose !== null; } return this; } // private method _getHandJoint(hand, inputjoint) { if (hand.joints[inputjoint.jointName] === void 0) { const joint = new Group2(); joint.matrixAutoUpdate = false; joint.visible = false; hand.joints[inputjoint.jointName] = joint; hand.add(joint); } return hand.joints[inputjoint.jointName]; } }; var DepthTexture2 = class extends Texture2 { constructor(width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format2) { format2 = format2 !== void 0 ? format2 : DepthFormat2; if (format2 !== DepthFormat2 && format2 !== DepthStencilFormat2) { throw new Error("DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat"); } if (type === void 0 && format2 === DepthFormat2) type = UnsignedIntType2; if (type === void 0 && format2 === DepthStencilFormat2) type = UnsignedInt248Type2; super(null, mapping, wrapS, wrapT, magFilter, minFilter, format2, type, anisotropy); this.isDepthTexture = true; this.image = { width, height }; this.magFilter = magFilter !== void 0 ? magFilter : NearestFilter2; this.minFilter = minFilter !== void 0 ? minFilter : NearestFilter2; this.flipY = false; this.generateMipmaps = false; this.compareFunction = null; } copy(source) { super.copy(source); this.compareFunction = source.compareFunction; return this; } toJSON(meta) { const data = super.toJSON(meta); if (this.compareFunction !== null) data.compareFunction = this.compareFunction; return data; } }; var WebXRManager2 = class extends EventDispatcher2 { constructor(renderer3, gl) { super(); const scope = this; let session = null; let framebufferScaleFactor = 1; let referenceSpace = null; let referenceSpaceType = "local-floor"; let foveation = 1; let customReferenceSpace = null; let pose = null; let glBinding = null; let glProjLayer = null; let glBaseLayer = null; let xrFrame = null; const attributes = gl.getContextAttributes(); let initialRenderTarget = null; let newRenderTarget = null; const controllers = []; const controllerInputSources = []; const cameraL = new PerspectiveCamera2(); cameraL.layers.enable(1); cameraL.viewport = new Vector42(); const cameraR = new PerspectiveCamera2(); cameraR.layers.enable(2); cameraR.viewport = new Vector42(); const cameras = [cameraL, cameraR]; const cameraXR = new ArrayCamera2(); cameraXR.layers.enable(1); cameraXR.layers.enable(2); let _currentDepthNear = null; let _currentDepthFar = null; this.cameraAutoUpdate = true; this.enabled = false; this.isPresenting = false; this.getController = function(index6) { let controller = controllers[index6]; if (controller === void 0) { controller = new WebXRController2(); controllers[index6] = controller; } return controller.getTargetRaySpace(); }; this.getControllerGrip = function(index6) { let controller = controllers[index6]; if (controller === void 0) { controller = new WebXRController2(); controllers[index6] = controller; } return controller.getGripSpace(); }; this.getHand = function(index6) { let controller = controllers[index6]; if (controller === void 0) { controller = new WebXRController2(); controllers[index6] = controller; } return controller.getHandSpace(); }; function onSessionEvent(event) { const controllerIndex = controllerInputSources.indexOf(event.inputSource); if (controllerIndex === -1) { return; } const controller = controllers[controllerIndex]; if (controller !== void 0) { controller.update(event.inputSource, event.frame, customReferenceSpace || referenceSpace); controller.dispatchEvent({ type: event.type, data: event.inputSource }); } } function onSessionEnd() { session.removeEventListener("select", onSessionEvent); session.removeEventListener("selectstart", onSessionEvent); session.removeEventListener("selectend", onSessionEvent); session.removeEventListener("squeeze", onSessionEvent); session.removeEventListener("squeezestart", onSessionEvent); session.removeEventListener("squeezeend", onSessionEvent); session.removeEventListener("end", onSessionEnd); session.removeEventListener("inputsourceschange", onInputSourcesChange); for (let i = 0; i < controllers.length; i++) { const inputSource = controllerInputSources[i]; if (inputSource === null) continue; controllerInputSources[i] = null; controllers[i].disconnect(inputSource); } _currentDepthNear = null; _currentDepthFar = null; renderer3.setRenderTarget(initialRenderTarget); glBaseLayer = null; glProjLayer = null; glBinding = null; session = null; newRenderTarget = null; animation.stop(); scope.isPresenting = false; scope.dispatchEvent({ type: "sessionend" }); } this.setFramebufferScaleFactor = function(value) { framebufferScaleFactor = value; if (scope.isPresenting === true) { console.warn("THREE.WebXRManager: Cannot change framebuffer scale while presenting."); } }; this.setReferenceSpaceType = function(value) { referenceSpaceType = value; if (scope.isPresenting === true) { console.warn("THREE.WebXRManager: Cannot change reference space type while presenting."); } }; this.getReferenceSpace = function() { return customReferenceSpace || referenceSpace; }; this.setReferenceSpace = function(space) { customReferenceSpace = space; }; this.getBaseLayer = function() { return glProjLayer !== null ? glProjLayer : glBaseLayer; }; this.getBinding = function() { return glBinding; }; this.getFrame = function() { return xrFrame; }; this.getSession = function() { return session; }; this.setSession = async function(value) { session = value; if (session !== null) { initialRenderTarget = renderer3.getRenderTarget(); session.addEventListener("select", onSessionEvent); session.addEventListener("selectstart", onSessionEvent); session.addEventListener("selectend", onSessionEvent); session.addEventListener("squeeze", onSessionEvent); session.addEventListener("squeezestart", onSessionEvent); session.addEventListener("squeezeend", onSessionEvent); session.addEventListener("end", onSessionEnd); session.addEventListener("inputsourceschange", onInputSourcesChange); if (attributes.xrCompatible !== true) { await gl.makeXRCompatible(); } if (session.renderState.layers === void 0 || renderer3.capabilities.isWebGL2 === false) { const layerInit = { antialias: session.renderState.layers === void 0 ? attributes.antialias : true, alpha: true, depth: attributes.depth, stencil: attributes.stencil, framebufferScaleFactor }; glBaseLayer = new XRWebGLLayer(session, gl, layerInit); session.updateRenderState({ baseLayer: glBaseLayer }); newRenderTarget = new WebGLRenderTarget2( glBaseLayer.framebufferWidth, glBaseLayer.framebufferHeight, { format: RGBAFormat2, type: UnsignedByteType2, colorSpace: renderer3.outputColorSpace, stencilBuffer: attributes.stencil } ); } else { let depthFormat = null; let depthType = null; let glDepthFormat = null; if (attributes.depth) { glDepthFormat = attributes.stencil ? gl.DEPTH24_STENCIL8 : gl.DEPTH_COMPONENT24; depthFormat = attributes.stencil ? DepthStencilFormat2 : DepthFormat2; depthType = attributes.stencil ? UnsignedInt248Type2 : UnsignedIntType2; } const projectionlayerInit = { colorFormat: gl.RGBA8, depthFormat: glDepthFormat, scaleFactor: framebufferScaleFactor }; glBinding = new XRWebGLBinding(session, gl); glProjLayer = glBinding.createProjectionLayer(projectionlayerInit); session.updateRenderState({ layers: [glProjLayer] }); newRenderTarget = new WebGLRenderTarget2( glProjLayer.textureWidth, glProjLayer.textureHeight, { format: RGBAFormat2, type: UnsignedByteType2, depthTexture: new DepthTexture2(glProjLayer.textureWidth, glProjLayer.textureHeight, depthType, void 0, void 0, void 0, void 0, void 0, void 0, depthFormat), stencilBuffer: attributes.stencil, colorSpace: renderer3.outputColorSpace, samples: attributes.antialias ? 4 : 0 } ); const renderTargetProperties = renderer3.properties.get(newRenderTarget); renderTargetProperties.__ignoreDepthValues = glProjLayer.ignoreDepthValues; } newRenderTarget.isXRRenderTarget = true; this.setFoveation(foveation); customReferenceSpace = null; referenceSpace = await session.requestReferenceSpace(referenceSpaceType); animation.setContext(session); animation.start(); scope.isPresenting = true; scope.dispatchEvent({ type: "sessionstart" }); } }; this.getEnvironmentBlendMode = function() { if (session !== null) { return session.environmentBlendMode; } }; function onInputSourcesChange(event) { for (let i = 0; i < event.removed.length; i++) { const inputSource = event.removed[i]; const index6 = controllerInputSources.indexOf(inputSource); if (index6 >= 0) { controllerInputSources[index6] = null; controllers[index6].disconnect(inputSource); } } for (let i = 0; i < event.added.length; i++) { const inputSource = event.added[i]; let controllerIndex = controllerInputSources.indexOf(inputSource); if (controllerIndex === -1) { for (let i2 = 0; i2 < controllers.length; i2++) { if (i2 >= controllerInputSources.length) { controllerInputSources.push(inputSource); controllerIndex = i2; break; } else if (controllerInputSources[i2] === null) { controllerInputSources[i2] = inputSource; controllerIndex = i2; break; } } if (controllerIndex === -1) break; } const controller = controllers[controllerIndex]; if (controller) { controller.connect(inputSource); } } } const cameraLPos = new Vector32(); const cameraRPos = new Vector32(); function setProjectionFromUnion(camera3, cameraL2, cameraR2) { cameraLPos.setFromMatrixPosition(cameraL2.matrixWorld); cameraRPos.setFromMatrixPosition(cameraR2.matrixWorld); const ipd = cameraLPos.distanceTo(cameraRPos); const projL = cameraL2.projectionMatrix.elements; const projR = cameraR2.projectionMatrix.elements; const near = projL[14] / (projL[10] - 1); const far = projL[14] / (projL[10] + 1); const topFov = (projL[9] + 1) / projL[5]; const bottomFov = (projL[9] - 1) / projL[5]; const leftFov = (projL[8] - 1) / projL[0]; const rightFov = (projR[8] + 1) / projR[0]; const left = near * leftFov; const right = near * rightFov; const zOffset = ipd / (-leftFov + rightFov); const xOffset = zOffset * -leftFov; cameraL2.matrixWorld.decompose(camera3.position, camera3.quaternion, camera3.scale); camera3.translateX(xOffset); camera3.translateZ(zOffset); camera3.matrixWorld.compose(camera3.position, camera3.quaternion, camera3.scale); camera3.matrixWorldInverse.copy(camera3.matrixWorld).invert(); const near2 = near + zOffset; const far2 = far + zOffset; const left2 = left - xOffset; const right2 = right + (ipd - xOffset); const top2 = topFov * far / far2 * near2; const bottom2 = bottomFov * far / far2 * near2; camera3.projectionMatrix.makePerspective(left2, right2, top2, bottom2, near2, far2); camera3.projectionMatrixInverse.copy(camera3.projectionMatrix).invert(); } function updateCamera(camera3, parent) { if (parent === null) { camera3.matrixWorld.copy(camera3.matrix); } else { camera3.matrixWorld.multiplyMatrices(parent.matrixWorld, camera3.matrix); } camera3.matrixWorldInverse.copy(camera3.matrixWorld).invert(); } this.updateCamera = function(camera3) { if (session === null) return; cameraXR.near = cameraR.near = cameraL.near = camera3.near; cameraXR.far = cameraR.far = cameraL.far = camera3.far; if (_currentDepthNear !== cameraXR.near || _currentDepthFar !== cameraXR.far) { session.updateRenderState({ depthNear: cameraXR.near, depthFar: cameraXR.far }); _currentDepthNear = cameraXR.near; _currentDepthFar = cameraXR.far; } const parent = camera3.parent; const cameras2 = cameraXR.cameras; updateCamera(cameraXR, parent); for (let i = 0; i < cameras2.length; i++) { updateCamera(cameras2[i], parent); } if (cameras2.length === 2) { setProjectionFromUnion(cameraXR, cameraL, cameraR); } else { cameraXR.projectionMatrix.copy(cameraL.projectionMatrix); } updateUserCamera(camera3, cameraXR, parent); }; function updateUserCamera(camera3, cameraXR2, parent) { if (parent === null) { camera3.matrix.copy(cameraXR2.matrixWorld); } else { camera3.matrix.copy(parent.matrixWorld); camera3.matrix.invert(); camera3.matrix.multiply(cameraXR2.matrixWorld); } camera3.matrix.decompose(camera3.position, camera3.quaternion, camera3.scale); camera3.updateMatrixWorld(true); camera3.projectionMatrix.copy(cameraXR2.projectionMatrix); camera3.projectionMatrixInverse.copy(cameraXR2.projectionMatrixInverse); if (camera3.isPerspectiveCamera) { camera3.fov = RAD2DEG2 * 2 * Math.atan(1 / camera3.projectionMatrix.elements[5]); camera3.zoom = 1; } } this.getCamera = function() { return cameraXR; }; this.getFoveation = function() { if (glProjLayer === null && glBaseLayer === null) { return void 0; } return foveation; }; this.setFoveation = function(value) { foveation = value; if (glProjLayer !== null) { glProjLayer.fixedFoveation = value; } if (glBaseLayer !== null && glBaseLayer.fixedFoveation !== void 0) { glBaseLayer.fixedFoveation = value; } }; let onAnimationFrameCallback = null; function onAnimationFrame(time, frame2) { pose = frame2.getViewerPose(customReferenceSpace || referenceSpace); xrFrame = frame2; if (pose !== null) { const views = pose.views; if (glBaseLayer !== null) { renderer3.setRenderTargetFramebuffer(newRenderTarget, glBaseLayer.framebuffer); renderer3.setRenderTarget(newRenderTarget); } let cameraXRNeedsUpdate = false; if (views.length !== cameraXR.cameras.length) { cameraXR.cameras.length = 0; cameraXRNeedsUpdate = true; } for (let i = 0; i < views.length; i++) { const view = views[i]; let viewport = null; if (glBaseLayer !== null) { viewport = glBaseLayer.getViewport(view); } else { const glSubImage = glBinding.getViewSubImage(glProjLayer, view); viewport = glSubImage.viewport; if (i === 0) { renderer3.setRenderTargetTextures( newRenderTarget, glSubImage.colorTexture, glProjLayer.ignoreDepthValues ? void 0 : glSubImage.depthStencilTexture ); renderer3.setRenderTarget(newRenderTarget); } } let camera3 = cameras[i]; if (camera3 === void 0) { camera3 = new PerspectiveCamera2(); camera3.layers.enable(i); camera3.viewport = new Vector42(); cameras[i] = camera3; } camera3.matrix.fromArray(view.transform.matrix); camera3.matrix.decompose(camera3.position, camera3.quaternion, camera3.scale); camera3.projectionMatrix.fromArray(view.projectionMatrix); camera3.projectionMatrixInverse.copy(camera3.projectionMatrix).invert(); camera3.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height); if (i === 0) { cameraXR.matrix.copy(camera3.matrix); cameraXR.matrix.decompose(cameraXR.position, cameraXR.quaternion, cameraXR.scale); } if (cameraXRNeedsUpdate === true) { cameraXR.cameras.push(camera3); } } } for (let i = 0; i < controllers.length; i++) { const inputSource = controllerInputSources[i]; const controller = controllers[i]; if (inputSource !== null && controller !== void 0) { controller.update(inputSource, frame2, customReferenceSpace || referenceSpace); } } if (onAnimationFrameCallback) onAnimationFrameCallback(time, frame2); if (frame2.detectedPlanes) { scope.dispatchEvent({ type: "planesdetected", data: frame2 }); } xrFrame = null; } const animation = new WebGLAnimation2(); animation.setAnimationLoop(onAnimationFrame); this.setAnimationLoop = function(callback) { onAnimationFrameCallback = callback; }; this.dispose = function() { }; } }; function WebGLMaterials2(renderer3, properties) { function refreshTransformUniform(map, uniform) { if (map.matrixAutoUpdate === true) { map.updateMatrix(); } uniform.value.copy(map.matrix); } function refreshFogUniforms(uniforms, fog) { fog.color.getRGB(uniforms.fogColor.value, getUnlitUniformColorSpace2(renderer3)); if (fog.isFog) { uniforms.fogNear.value = fog.near; uniforms.fogFar.value = fog.far; } else if (fog.isFogExp2) { uniforms.fogDensity.value = fog.density; } } function refreshMaterialUniforms(uniforms, material, pixelRatio, height, transmissionRenderTarget) { if (material.isMeshBasicMaterial) { refreshUniformsCommon(uniforms, material); } else if (material.isMeshLambertMaterial) { refreshUniformsCommon(uniforms, material); } else if (material.isMeshToonMaterial) { refreshUniformsCommon(uniforms, material); refreshUniformsToon(uniforms, material); } else if (material.isMeshPhongMaterial) { refreshUniformsCommon(uniforms, material); refreshUniformsPhong(uniforms, material); } else if (material.isMeshStandardMaterial) { refreshUniformsCommon(uniforms, material); refreshUniformsStandard(uniforms, material); if (material.isMeshPhysicalMaterial) { refreshUniformsPhysical(uniforms, material, transmissionRenderTarget); } } else if (material.isMeshMatcapMaterial) { refreshUniformsCommon(uniforms, material); refreshUniformsMatcap(uniforms, material); } else if (material.isMeshDepthMaterial) { refreshUniformsCommon(uniforms, material); } else if (material.isMeshDistanceMaterial) { refreshUniformsCommon(uniforms, material); refreshUniformsDistance(uniforms, material); } else if (material.isMeshNormalMaterial) { refreshUniformsCommon(uniforms, material); } else if (material.isLineBasicMaterial) { refreshUniformsLine(uniforms, material); if (material.isLineDashedMaterial) { refreshUniformsDash(uniforms, material); } } else if (material.isPointsMaterial) { refreshUniformsPoints(uniforms, material, pixelRatio, height); } else if (material.isSpriteMaterial) { refreshUniformsSprites(uniforms, material); } else if (material.isShadowMaterial) { uniforms.color.value.copy(material.color); uniforms.opacity.value = material.opacity; } else if (material.isShaderMaterial) { material.uniformsNeedUpdate = false; } } function refreshUniformsCommon(uniforms, material) { uniforms.opacity.value = material.opacity; if (material.color) { uniforms.diffuse.value.copy(material.color); } if (material.emissive) { uniforms.emissive.value.copy(material.emissive).multiplyScalar(material.emissiveIntensity); } if (material.map) { uniforms.map.value = material.map; refreshTransformUniform(material.map, uniforms.mapTransform); } if (material.alphaMap) { uniforms.alphaMap.value = material.alphaMap; refreshTransformUniform(material.alphaMap, uniforms.alphaMapTransform); } if (material.bumpMap) { uniforms.bumpMap.value = material.bumpMap; refreshTransformUniform(material.bumpMap, uniforms.bumpMapTransform); uniforms.bumpScale.value = material.bumpScale; if (material.side === BackSide2) { uniforms.bumpScale.value *= -1; } } if (material.normalMap) { uniforms.normalMap.value = material.normalMap; refreshTransformUniform(material.normalMap, uniforms.normalMapTransform); uniforms.normalScale.value.copy(material.normalScale); if (material.side === BackSide2) { uniforms.normalScale.value.negate(); } } if (material.displacementMap) { uniforms.displacementMap.value = material.displacementMap; refreshTransformUniform(material.displacementMap, uniforms.displacementMapTransform); uniforms.displacementScale.value = material.displacementScale; uniforms.displacementBias.value = material.displacementBias; } if (material.emissiveMap) { uniforms.emissiveMap.value = material.emissiveMap; refreshTransformUniform(material.emissiveMap, uniforms.emissiveMapTransform); } if (material.specularMap) { uniforms.specularMap.value = material.specularMap; refreshTransformUniform(material.specularMap, uniforms.specularMapTransform); } if (material.alphaTest > 0) { uniforms.alphaTest.value = material.alphaTest; } const envMap = properties.get(material).envMap; if (envMap) { uniforms.envMap.value = envMap; uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap.isRenderTargetTexture === false ? -1 : 1; uniforms.reflectivity.value = material.reflectivity; uniforms.ior.value = material.ior; uniforms.refractionRatio.value = material.refractionRatio; } if (material.lightMap) { uniforms.lightMap.value = material.lightMap; const scaleFactor = renderer3._useLegacyLights === true ? Math.PI : 1; uniforms.lightMapIntensity.value = material.lightMapIntensity * scaleFactor; refreshTransformUniform(material.lightMap, uniforms.lightMapTransform); } if (material.aoMap) { uniforms.aoMap.value = material.aoMap; uniforms.aoMapIntensity.value = material.aoMapIntensity; refreshTransformUniform(material.aoMap, uniforms.aoMapTransform); } } function refreshUniformsLine(uniforms, material) { uniforms.diffuse.value.copy(material.color); uniforms.opacity.value = material.opacity; if (material.map) { uniforms.map.value = material.map; refreshTransformUniform(material.map, uniforms.mapTransform); } } function refreshUniformsDash(uniforms, material) { uniforms.dashSize.value = material.dashSize; uniforms.totalSize.value = material.dashSize + material.gapSize; uniforms.scale.value = material.scale; } function refreshUniformsPoints(uniforms, material, pixelRatio, height) { uniforms.diffuse.value.copy(material.color); uniforms.opacity.value = material.opacity; uniforms.size.value = material.size * pixelRatio; uniforms.scale.value = height * 0.5; if (material.map) { uniforms.map.value = material.map; refreshTransformUniform(material.map, uniforms.uvTransform); } if (material.alphaMap) { uniforms.alphaMap.value = material.alphaMap; refreshTransformUniform(material.alphaMap, uniforms.alphaMapTransform); } if (material.alphaTest > 0) { uniforms.alphaTest.value = material.alphaTest; } } function refreshUniformsSprites(uniforms, material) { uniforms.diffuse.value.copy(material.color); uniforms.opacity.value = material.opacity; uniforms.rotation.value = material.rotation; if (material.map) { uniforms.map.value = material.map; refreshTransformUniform(material.map, uniforms.mapTransform); } if (material.alphaMap) { uniforms.alphaMap.value = material.alphaMap; refreshTransformUniform(material.alphaMap, uniforms.alphaMapTransform); } if (material.alphaTest > 0) { uniforms.alphaTest.value = material.alphaTest; } } function refreshUniformsPhong(uniforms, material) { uniforms.specular.value.copy(material.specular); uniforms.shininess.value = Math.max(material.shininess, 1e-4); } function refreshUniformsToon(uniforms, material) { if (material.gradientMap) { uniforms.gradientMap.value = material.gradientMap; } } function refreshUniformsStandard(uniforms, material) { uniforms.metalness.value = material.metalness; if (material.metalnessMap) { uniforms.metalnessMap.value = material.metalnessMap; refreshTransformUniform(material.metalnessMap, uniforms.metalnessMapTransform); } uniforms.roughness.value = material.roughness; if (material.roughnessMap) { uniforms.roughnessMap.value = material.roughnessMap; refreshTransformUniform(material.roughnessMap, uniforms.roughnessMapTransform); } const envMap = properties.get(material).envMap; if (envMap) { uniforms.envMapIntensity.value = material.envMapIntensity; } } function refreshUniformsPhysical(uniforms, material, transmissionRenderTarget) { uniforms.ior.value = material.ior; if (material.sheen > 0) { uniforms.sheenColor.value.copy(material.sheenColor).multiplyScalar(material.sheen); uniforms.sheenRoughness.value = material.sheenRoughness; if (material.sheenColorMap) { uniforms.sheenColorMap.value = material.sheenColorMap; refreshTransformUniform(material.sheenColorMap, uniforms.sheenColorMapTransform); } if (material.sheenRoughnessMap) { uniforms.sheenRoughnessMap.value = material.sheenRoughnessMap; refreshTransformUniform(material.sheenRoughnessMap, uniforms.sheenRoughnessMapTransform); } } if (material.clearcoat > 0) { uniforms.clearcoat.value = material.clearcoat; uniforms.clearcoatRoughness.value = material.clearcoatRoughness; if (material.clearcoatMap) { uniforms.clearcoatMap.value = material.clearcoatMap; refreshTransformUniform(material.clearcoatMap, uniforms.clearcoatMapTransform); } if (material.clearcoatRoughnessMap) { uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap; refreshTransformUniform(material.clearcoatRoughnessMap, uniforms.clearcoatRoughnessMapTransform); } if (material.clearcoatNormalMap) { uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap; refreshTransformUniform(material.clearcoatNormalMap, uniforms.clearcoatNormalMapTransform); uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale); if (material.side === BackSide2) { uniforms.clearcoatNormalScale.value.negate(); } } } if (material.iridescence > 0) { uniforms.iridescence.value = material.iridescence; uniforms.iridescenceIOR.value = material.iridescenceIOR; uniforms.iridescenceThicknessMinimum.value = material.iridescenceThicknessRange[0]; uniforms.iridescenceThicknessMaximum.value = material.iridescenceThicknessRange[1]; if (material.iridescenceMap) { uniforms.iridescenceMap.value = material.iridescenceMap; refreshTransformUniform(material.iridescenceMap, uniforms.iridescenceMapTransform); } if (material.iridescenceThicknessMap) { uniforms.iridescenceThicknessMap.value = material.iridescenceThicknessMap; refreshTransformUniform(material.iridescenceThicknessMap, uniforms.iridescenceThicknessMapTransform); } } if (material.transmission > 0) { uniforms.transmission.value = material.transmission; uniforms.transmissionSamplerMap.value = transmissionRenderTarget.texture; uniforms.transmissionSamplerSize.value.set(transmissionRenderTarget.width, transmissionRenderTarget.height); if (material.transmissionMap) { uniforms.transmissionMap.value = material.transmissionMap; refreshTransformUniform(material.transmissionMap, uniforms.transmissionMapTransform); } uniforms.thickness.value = material.thickness; if (material.thicknessMap) { uniforms.thicknessMap.value = material.thicknessMap; refreshTransformUniform(material.thicknessMap, uniforms.thicknessMapTransform); } uniforms.attenuationDistance.value = material.attenuationDistance; uniforms.attenuationColor.value.copy(material.attenuationColor); } if (material.anisotropy > 0) { uniforms.anisotropyVector.value.set(material.anisotropy * Math.cos(material.anisotropyRotation), material.anisotropy * Math.sin(material.anisotropyRotation)); if (material.anisotropyMap) { uniforms.anisotropyMap.value = material.anisotropyMap; refreshTransformUniform(material.anisotropyMap, uniforms.anisotropyMapTransform); } } uniforms.specularIntensity.value = material.specularIntensity; uniforms.specularColor.value.copy(material.specularColor); if (material.specularColorMap) { uniforms.specularColorMap.value = material.specularColorMap; refreshTransformUniform(material.specularColorMap, uniforms.specularColorMapTransform); } if (material.specularIntensityMap) { uniforms.specularIntensityMap.value = material.specularIntensityMap; refreshTransformUniform(material.specularIntensityMap, uniforms.specularIntensityMapTransform); } } function refreshUniformsMatcap(uniforms, material) { if (material.matcap) { uniforms.matcap.value = material.matcap; } } function refreshUniformsDistance(uniforms, material) { const light = properties.get(material).light; uniforms.referencePosition.value.setFromMatrixPosition(light.matrixWorld); uniforms.nearDistance.value = light.shadow.camera.near; uniforms.farDistance.value = light.shadow.camera.far; } return { refreshFogUniforms, refreshMaterialUniforms }; } function WebGLUniformsGroups2(gl, info, capabilities, state) { let buffers = {}; let updateList = {}; let allocatedBindingPoints = []; const maxBindingPoints = capabilities.isWebGL2 ? gl.getParameter(gl.MAX_UNIFORM_BUFFER_BINDINGS) : 0; function bind(uniformsGroup, program) { const webglProgram = program.program; state.uniformBlockBinding(uniformsGroup, webglProgram); } function update4(uniformsGroup, program) { let buffer = buffers[uniformsGroup.id]; if (buffer === void 0) { prepareUniformsGroup(uniformsGroup); buffer = createBuffer(uniformsGroup); buffers[uniformsGroup.id] = buffer; uniformsGroup.addEventListener("dispose", onUniformsGroupsDispose); } const webglProgram = program.program; state.updateUBOMapping(uniformsGroup, webglProgram); const frame2 = info.render.frame; if (updateList[uniformsGroup.id] !== frame2) { updateBufferData(uniformsGroup); updateList[uniformsGroup.id] = frame2; } } function createBuffer(uniformsGroup) { const bindingPointIndex = allocateBindingPointIndex(); uniformsGroup.__bindingPointIndex = bindingPointIndex; const buffer = gl.createBuffer(); const size = uniformsGroup.__size; const usage = uniformsGroup.usage; gl.bindBuffer(gl.UNIFORM_BUFFER, buffer); gl.bufferData(gl.UNIFORM_BUFFER, size, usage); gl.bindBuffer(gl.UNIFORM_BUFFER, null); gl.bindBufferBase(gl.UNIFORM_BUFFER, bindingPointIndex, buffer); return buffer; } function allocateBindingPointIndex() { for (let i = 0; i < maxBindingPoints; i++) { if (allocatedBindingPoints.indexOf(i) === -1) { allocatedBindingPoints.push(i); return i; } } console.error("THREE.WebGLRenderer: Maximum number of simultaneously usable uniforms groups reached."); return 0; } function updateBufferData(uniformsGroup) { const buffer = buffers[uniformsGroup.id]; const uniforms = uniformsGroup.uniforms; const cache = uniformsGroup.__cache; gl.bindBuffer(gl.UNIFORM_BUFFER, buffer); for (let i = 0, il = uniforms.length; i < il; i++) { const uniform = uniforms[i]; if (hasUniformChanged(uniform, i, cache) === true) { const offset = uniform.__offset; const values = Array.isArray(uniform.value) ? uniform.value : [uniform.value]; let arrayOffset = 0; for (let i2 = 0; i2 < values.length; i2++) { const value = values[i2]; const info2 = getUniformSize(value); if (typeof value === "number") { uniform.__data[0] = value; gl.bufferSubData(gl.UNIFORM_BUFFER, offset + arrayOffset, uniform.__data); } else if (value.isMatrix3) { uniform.__data[0] = value.elements[0]; uniform.__data[1] = value.elements[1]; uniform.__data[2] = value.elements[2]; uniform.__data[3] = value.elements[0]; uniform.__data[4] = value.elements[3]; uniform.__data[5] = value.elements[4]; uniform.__data[6] = value.elements[5]; uniform.__data[7] = value.elements[0]; uniform.__data[8] = value.elements[6]; uniform.__data[9] = value.elements[7]; uniform.__data[10] = value.elements[8]; uniform.__data[11] = value.elements[0]; } else { value.toArray(uniform.__data, arrayOffset); arrayOffset += info2.storage / Float32Array.BYTES_PER_ELEMENT; } } gl.bufferSubData(gl.UNIFORM_BUFFER, offset, uniform.__data); } } gl.bindBuffer(gl.UNIFORM_BUFFER, null); } function hasUniformChanged(uniform, index6, cache) { const value = uniform.value; if (cache[index6] === void 0) { if (typeof value === "number") { cache[index6] = value; } else { const values = Array.isArray(value) ? value : [value]; const tempValues = []; for (let i = 0; i < values.length; i++) { tempValues.push(values[i].clone()); } cache[index6] = tempValues; } return true; } else { if (typeof value === "number") { if (cache[index6] !== value) { cache[index6] = value; return true; } } else { const cachedObjects = Array.isArray(cache[index6]) ? cache[index6] : [cache[index6]]; const values = Array.isArray(value) ? value : [value]; for (let i = 0; i < cachedObjects.length; i++) { const cachedObject = cachedObjects[i]; if (cachedObject.equals(values[i]) === false) { cachedObject.copy(values[i]); return true; } } } } return false; } function prepareUniformsGroup(uniformsGroup) { const uniforms = uniformsGroup.uniforms; let offset = 0; const chunkSize = 16; let chunkOffset = 0; for (let i = 0, l = uniforms.length; i < l; i++) { const uniform = uniforms[i]; const infos = { boundary: 0, // bytes storage: 0 // bytes }; const values = Array.isArray(uniform.value) ? uniform.value : [uniform.value]; for (let j = 0, jl = values.length; j < jl; j++) { const value = values[j]; const info2 = getUniformSize(value); infos.boundary += info2.boundary; infos.storage += info2.storage; } uniform.__data = new Float32Array(infos.storage / Float32Array.BYTES_PER_ELEMENT); uniform.__offset = offset; if (i > 0) { chunkOffset = offset % chunkSize; const remainingSizeInChunk = chunkSize - chunkOffset; if (chunkOffset !== 0 && remainingSizeInChunk - infos.boundary < 0) { offset += chunkSize - chunkOffset; uniform.__offset = offset; } } offset += infos.storage; } chunkOffset = offset % chunkSize; if (chunkOffset > 0) offset += chunkSize - chunkOffset; uniformsGroup.__size = offset; uniformsGroup.__cache = {}; return this; } function getUniformSize(value) { const info2 = { boundary: 0, // bytes storage: 0 // bytes }; if (typeof value === "number") { info2.boundary = 4; info2.storage = 4; } else if (value.isVector2) { info2.boundary = 8; info2.storage = 8; } else if (value.isVector3 || value.isColor) { info2.boundary = 16; info2.storage = 12; } else if (value.isVector4) { info2.boundary = 16; info2.storage = 16; } else if (value.isMatrix3) { info2.boundary = 48; info2.storage = 48; } else if (value.isMatrix4) { info2.boundary = 64; info2.storage = 64; } else if (value.isTexture) { console.warn("THREE.WebGLRenderer: Texture samplers can not be part of an uniforms group."); } else { console.warn("THREE.WebGLRenderer: Unsupported uniform value type.", value); } return info2; } function onUniformsGroupsDispose(event) { const uniformsGroup = event.target; uniformsGroup.removeEventListener("dispose", onUniformsGroupsDispose); const index6 = allocatedBindingPoints.indexOf(uniformsGroup.__bindingPointIndex); allocatedBindingPoints.splice(index6, 1); gl.deleteBuffer(buffers[uniformsGroup.id]); delete buffers[uniformsGroup.id]; delete updateList[uniformsGroup.id]; } function dispose() { for (const id in buffers) { gl.deleteBuffer(buffers[id]); } allocatedBindingPoints = []; buffers = {}; updateList = {}; } return { bind, update: update4, dispose }; } var WebGLRenderer2 = class { constructor(parameters = {}) { const { canvas = createCanvasElement2(), context = null, depth = true, stencil = true, alpha = false, antialias = false, premultipliedAlpha = true, preserveDrawingBuffer = false, powerPreference = "default", failIfMajorPerformanceCaveat = false } = parameters; this.isWebGLRenderer = true; let _alpha; if (context !== null) { _alpha = context.getContextAttributes().alpha; } else { _alpha = alpha; } const uintClearColor = new Uint32Array(4); const intClearColor = new Int32Array(4); let currentRenderList = null; let currentRenderState = null; const renderListStack = []; const renderStateStack = []; this.domElement = canvas; this.debug = { /** * Enables error checking and reporting when shader programs are being compiled * @type {boolean} */ checkShaderErrors: true, /** * Callback for custom error reporting. * @type {?Function} */ onShaderError: null }; this.autoClear = true; this.autoClearColor = true; this.autoClearDepth = true; this.autoClearStencil = true; this.sortObjects = true; this.clippingPlanes = []; this.localClippingEnabled = false; this._outputColorSpace = SRGBColorSpace2; this._useLegacyLights = false; this.toneMapping = NoToneMapping2; this.toneMappingExposure = 1; const _this = this; let _isContextLost = false; let _currentActiveCubeFace = 0; let _currentActiveMipmapLevel = 0; let _currentRenderTarget = null; let _currentMaterialId = -1; let _currentCamera = null; const _currentViewport = new Vector42(); const _currentScissor = new Vector42(); let _currentScissorTest = null; const _currentClearColor = new Color2(0); let _currentClearAlpha = 0; let _width = canvas.width; let _height = canvas.height; let _pixelRatio = 1; let _opaqueSort = null; let _transparentSort = null; const _viewport = new Vector42(0, 0, _width, _height); const _scissor = new Vector42(0, 0, _width, _height); let _scissorTest = false; const _frustum = new Frustum2(); let _clippingEnabled = false; let _localClippingEnabled = false; let _transmissionRenderTarget = null; const _projScreenMatrix = new Matrix42(); const _vector23 = new Vector22(); const _vector3 = new Vector32(); const _emptyScene = { background: null, fog: null, environment: null, overrideMaterial: null, isScene: true }; function getTargetPixelRatio() { return _currentRenderTarget === null ? _pixelRatio : 1; } let _gl = context; function getContext(contextNames, contextAttributes) { for (let i = 0; i < contextNames.length; i++) { const contextName = contextNames[i]; const context2 = canvas.getContext(contextName, contextAttributes); if (context2 !== null) return context2; } return null; } try { const contextAttributes = { alpha: true, depth, stencil, antialias, premultipliedAlpha, preserveDrawingBuffer, powerPreference, failIfMajorPerformanceCaveat }; if ("setAttribute" in canvas) canvas.setAttribute("data-engine", `three.js r${REVISION2}`); canvas.addEventListener("webglcontextlost", onContextLost, false); canvas.addEventListener("webglcontextrestored", onContextRestore, false); canvas.addEventListener("webglcontextcreationerror", onContextCreationError, false); if (_gl === null) { const contextNames = ["webgl2", "webgl", "experimental-webgl"]; if (_this.isWebGL1Renderer === true) { contextNames.shift(); } _gl = getContext(contextNames, contextAttributes); if (_gl === null) { if (getContext(contextNames)) { throw new Error("Error creating WebGL context with your selected attributes."); } else { throw new Error("Error creating WebGL context."); } } } if (typeof WebGLRenderingContext !== "undefined" && _gl instanceof WebGLRenderingContext) { console.warn("THREE.WebGLRenderer: WebGL 1 support was deprecated in r153 and will be removed in r163."); } if (_gl.getShaderPrecisionFormat === void 0) { _gl.getShaderPrecisionFormat = function() { return { "rangeMin": 1, "rangeMax": 1, "precision": 1 }; }; } } catch (error) { console.error("THREE.WebGLRenderer: " + error.message); throw error; } let extensions, capabilities, state, info; let properties, textures, cubemaps, cubeuvmaps, attributes, geometries, objects; let programCache, materials, renderLists, renderStates, clipping, shadowMap; let background, morphtargets, bufferRenderer, indexedBufferRenderer; let utils, bindingStates, uniformsGroups; function initGLContext() { extensions = new WebGLExtensions2(_gl); capabilities = new WebGLCapabilities2(_gl, extensions, parameters); extensions.init(capabilities); utils = new WebGLUtils2(_gl, extensions, capabilities); state = new WebGLState2(_gl, extensions, capabilities); info = new WebGLInfo2(_gl); properties = new WebGLProperties2(); textures = new WebGLTextures2(_gl, extensions, state, properties, capabilities, utils, info); cubemaps = new WebGLCubeMaps2(_this); cubeuvmaps = new WebGLCubeUVMaps2(_this); attributes = new WebGLAttributes2(_gl, capabilities); bindingStates = new WebGLBindingStates2(_gl, extensions, attributes, capabilities); geometries = new WebGLGeometries2(_gl, attributes, info, bindingStates); objects = new WebGLObjects2(_gl, geometries, attributes, info); morphtargets = new WebGLMorphtargets2(_gl, capabilities, textures); clipping = new WebGLClipping2(properties); programCache = new WebGLPrograms2(_this, cubemaps, cubeuvmaps, extensions, capabilities, bindingStates, clipping); materials = new WebGLMaterials2(_this, properties); renderLists = new WebGLRenderLists2(); renderStates = new WebGLRenderStates2(extensions, capabilities); background = new WebGLBackground2(_this, cubemaps, cubeuvmaps, state, objects, _alpha, premultipliedAlpha); shadowMap = new WebGLShadowMap2(_this, objects, capabilities); uniformsGroups = new WebGLUniformsGroups2(_gl, info, capabilities, state); bufferRenderer = new WebGLBufferRenderer2(_gl, extensions, info, capabilities); indexedBufferRenderer = new WebGLIndexedBufferRenderer2(_gl, extensions, info, capabilities); info.programs = programCache.programs; _this.capabilities = capabilities; _this.extensions = extensions; _this.properties = properties; _this.renderLists = renderLists; _this.shadowMap = shadowMap; _this.state = state; _this.info = info; } initGLContext(); const xr = new WebXRManager2(_this, _gl); this.xr = xr; this.getContext = function() { return _gl; }; this.getContextAttributes = function() { return _gl.getContextAttributes(); }; this.forceContextLoss = function() { const extension = extensions.get("WEBGL_lose_context"); if (extension) extension.loseContext(); }; this.forceContextRestore = function() { const extension = extensions.get("WEBGL_lose_context"); if (extension) extension.restoreContext(); }; this.getPixelRatio = function() { return _pixelRatio; }; this.setPixelRatio = function(value) { if (value === void 0) return; _pixelRatio = value; this.setSize(_width, _height, false); }; this.getSize = function(target) { return target.set(_width, _height); }; this.setSize = function(width, height, updateStyle = true) { if (xr.isPresenting) { console.warn("THREE.WebGLRenderer: Can't change size while VR device is presenting."); return; } _width = width; _height = height; canvas.width = Math.floor(width * _pixelRatio); canvas.height = Math.floor(height * _pixelRatio); if (updateStyle === true) { canvas.style.width = width + "px"; canvas.style.height = height + "px"; } this.setViewport(0, 0, width, height); }; this.getDrawingBufferSize = function(target) { return target.set(_width * _pixelRatio, _height * _pixelRatio).floor(); }; this.setDrawingBufferSize = function(width, height, pixelRatio) { _width = width; _height = height; _pixelRatio = pixelRatio; canvas.width = Math.floor(width * pixelRatio); canvas.height = Math.floor(height * pixelRatio); this.setViewport(0, 0, width, height); }; this.getCurrentViewport = function(target) { return target.copy(_currentViewport); }; this.getViewport = function(target) { return target.copy(_viewport); }; this.setViewport = function(x3, y3, width, height) { if (x3.isVector4) { _viewport.set(x3.x, x3.y, x3.z, x3.w); } else { _viewport.set(x3, y3, width, height); } state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor()); }; this.getScissor = function(target) { return target.copy(_scissor); }; this.setScissor = function(x3, y3, width, height) { if (x3.isVector4) { _scissor.set(x3.x, x3.y, x3.z, x3.w); } else { _scissor.set(x3, y3, width, height); } state.scissor(_currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor()); }; this.getScissorTest = function() { return _scissorTest; }; this.setScissorTest = function(boolean) { state.setScissorTest(_scissorTest = boolean); }; this.setOpaqueSort = function(method) { _opaqueSort = method; }; this.setTransparentSort = function(method) { _transparentSort = method; }; this.getClearColor = function(target) { return target.copy(background.getClearColor()); }; this.setClearColor = function() { background.setClearColor.apply(background, arguments); }; this.getClearAlpha = function() { return background.getClearAlpha(); }; this.setClearAlpha = function() { background.setClearAlpha.apply(background, arguments); }; this.clear = function(color = true, depth2 = true, stencil2 = true) { let bits = 0; if (color) { let isIntegerFormat = false; if (_currentRenderTarget !== null) { const targetFormat = _currentRenderTarget.texture.format; isIntegerFormat = targetFormat === RGBAIntegerFormat2 || targetFormat === RGIntegerFormat2 || targetFormat === RedIntegerFormat2; } if (isIntegerFormat) { const targetType = _currentRenderTarget.texture.type; const isUnsignedType = targetType === UnsignedByteType2 || targetType === UnsignedIntType2 || targetType === UnsignedShortType2 || targetType === UnsignedInt248Type2 || targetType === UnsignedShort4444Type2 || targetType === UnsignedShort5551Type2; const clearColor = background.getClearColor(); const a2 = background.getClearAlpha(); const r = clearColor.r; const g = clearColor.g; const b = clearColor.b; if (isUnsignedType) { uintClearColor[0] = r; uintClearColor[1] = g; uintClearColor[2] = b; uintClearColor[3] = a2; _gl.clearBufferuiv(_gl.COLOR, 0, uintClearColor); } else { intClearColor[0] = r; intClearColor[1] = g; intClearColor[2] = b; intClearColor[3] = a2; _gl.clearBufferiv(_gl.COLOR, 0, intClearColor); } } else { bits |= _gl.COLOR_BUFFER_BIT; } } if (depth2) bits |= _gl.DEPTH_BUFFER_BIT; if (stencil2) bits |= _gl.STENCIL_BUFFER_BIT; _gl.clear(bits); }; this.clearColor = function() { this.clear(true, false, false); }; this.clearDepth = function() { this.clear(false, true, false); }; this.clearStencil = function() { this.clear(false, false, true); }; this.dispose = function() { canvas.removeEventListener("webglcontextlost", onContextLost, false); canvas.removeEventListener("webglcontextrestored", onContextRestore, false); canvas.removeEventListener("webglcontextcreationerror", onContextCreationError, false); renderLists.dispose(); renderStates.dispose(); properties.dispose(); cubemaps.dispose(); cubeuvmaps.dispose(); objects.dispose(); bindingStates.dispose(); uniformsGroups.dispose(); programCache.dispose(); xr.dispose(); xr.removeEventListener("sessionstart", onXRSessionStart); xr.removeEventListener("sessionend", onXRSessionEnd); if (_transmissionRenderTarget) { _transmissionRenderTarget.dispose(); _transmissionRenderTarget = null; } animation.stop(); }; function onContextLost(event) { event.preventDefault(); console.log("THREE.WebGLRenderer: Context Lost."); _isContextLost = true; } function onContextRestore() { console.log("THREE.WebGLRenderer: Context Restored."); _isContextLost = false; const infoAutoReset = info.autoReset; const shadowMapEnabled = shadowMap.enabled; const shadowMapAutoUpdate = shadowMap.autoUpdate; const shadowMapNeedsUpdate = shadowMap.needsUpdate; const shadowMapType = shadowMap.type; initGLContext(); info.autoReset = infoAutoReset; shadowMap.enabled = shadowMapEnabled; shadowMap.autoUpdate = shadowMapAutoUpdate; shadowMap.needsUpdate = shadowMapNeedsUpdate; shadowMap.type = shadowMapType; } function onContextCreationError(event) { console.error("THREE.WebGLRenderer: A WebGL context could not be created. Reason: ", event.statusMessage); } function onMaterialDispose(event) { const material = event.target; material.removeEventListener("dispose", onMaterialDispose); deallocateMaterial(material); } function deallocateMaterial(material) { releaseMaterialProgramReferences(material); properties.remove(material); } function releaseMaterialProgramReferences(material) { const programs = properties.get(material).programs; if (programs !== void 0) { programs.forEach(function(program) { programCache.releaseProgram(program); }); if (material.isShaderMaterial) { programCache.releaseShaderCache(material); } } } this.renderBufferDirect = function(camera3, scene3, geometry, material, object, group) { if (scene3 === null) scene3 = _emptyScene; const frontFaceCW = object.isMesh && object.matrixWorld.determinant() < 0; const program = setProgram(camera3, scene3, geometry, material, object); state.setMaterial(material, frontFaceCW); let index6 = geometry.index; let rangeFactor = 1; if (material.wireframe === true) { index6 = geometries.getWireframeAttribute(geometry); if (index6 === void 0) return; rangeFactor = 2; } const drawRange = geometry.drawRange; const position = geometry.attributes.position; let drawStart = drawRange.start * rangeFactor; let drawEnd = (drawRange.start + drawRange.count) * rangeFactor; if (group !== null) { drawStart = Math.max(drawStart, group.start * rangeFactor); drawEnd = Math.min(drawEnd, (group.start + group.count) * rangeFactor); } if (index6 !== null) { drawStart = Math.max(drawStart, 0); drawEnd = Math.min(drawEnd, index6.count); } else if (position !== void 0 && position !== null) { drawStart = Math.max(drawStart, 0); drawEnd = Math.min(drawEnd, position.count); } const drawCount = drawEnd - drawStart; if (drawCount < 0 || drawCount === Infinity) return; bindingStates.setup(object, material, program, geometry, index6); let attribute; let renderer3 = bufferRenderer; if (index6 !== null) { attribute = attributes.get(index6); renderer3 = indexedBufferRenderer; renderer3.setIndex(attribute); } if (object.isMesh) { if (material.wireframe === true) { state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio()); renderer3.setMode(_gl.LINES); } else { renderer3.setMode(_gl.TRIANGLES); } } else if (object.isLine) { let lineWidth = material.linewidth; if (lineWidth === void 0) lineWidth = 1; state.setLineWidth(lineWidth * getTargetPixelRatio()); if (object.isLineSegments) { renderer3.setMode(_gl.LINES); } else if (object.isLineLoop) { renderer3.setMode(_gl.LINE_LOOP); } else { renderer3.setMode(_gl.LINE_STRIP); } } else if (object.isPoints) { renderer3.setMode(_gl.POINTS); } else if (object.isSprite) { renderer3.setMode(_gl.TRIANGLES); } if (object.isInstancedMesh) { renderer3.renderInstances(drawStart, drawCount, object.count); } else if (geometry.isInstancedBufferGeometry) { const maxInstanceCount = geometry._maxInstanceCount !== void 0 ? geometry._maxInstanceCount : Infinity; const instanceCount = Math.min(geometry.instanceCount, maxInstanceCount); renderer3.renderInstances(drawStart, drawCount, instanceCount); } else { renderer3.render(drawStart, drawCount); } }; this.compile = function(scene3, camera3) { function prepare(material, scene4, object) { if (material.transparent === true && material.side === DoubleSide2 && material.forceSinglePass === false) { material.side = BackSide2; material.needsUpdate = true; getProgram(material, scene4, object); material.side = FrontSide2; material.needsUpdate = true; getProgram(material, scene4, object); material.side = DoubleSide2; } else { getProgram(material, scene4, object); } } currentRenderState = renderStates.get(scene3); currentRenderState.init(); renderStateStack.push(currentRenderState); scene3.traverseVisible(function(object) { if (object.isLight && object.layers.test(camera3.layers)) { currentRenderState.pushLight(object); if (object.castShadow) { currentRenderState.pushShadow(object); } } }); currentRenderState.setupLights(_this._useLegacyLights); scene3.traverse(function(object) { const material = object.material; if (material) { if (Array.isArray(material)) { for (let i = 0; i < material.length; i++) { const material2 = material[i]; prepare(material2, scene3, object); } } else { prepare(material, scene3, object); } } }); renderStateStack.pop(); currentRenderState = null; }; let onAnimationFrameCallback = null; function onAnimationFrame(time) { if (onAnimationFrameCallback) onAnimationFrameCallback(time); } function onXRSessionStart() { animation.stop(); } function onXRSessionEnd() { animation.start(); } const animation = new WebGLAnimation2(); animation.setAnimationLoop(onAnimationFrame); if (typeof self !== "undefined") animation.setContext(self); this.setAnimationLoop = function(callback) { onAnimationFrameCallback = callback; xr.setAnimationLoop(callback); callback === null ? animation.stop() : animation.start(); }; xr.addEventListener("sessionstart", onXRSessionStart); xr.addEventListener("sessionend", onXRSessionEnd); this.render = function(scene3, camera3) { if (camera3 !== void 0 && camera3.isCamera !== true) { console.error("THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera."); return; } if (_isContextLost === true) return; if (scene3.matrixWorldAutoUpdate === true) scene3.updateMatrixWorld(); if (camera3.parent === null && camera3.matrixWorldAutoUpdate === true) camera3.updateMatrixWorld(); if (xr.enabled === true && xr.isPresenting === true) { if (xr.cameraAutoUpdate === true) xr.updateCamera(camera3); camera3 = xr.getCamera(); } if (scene3.isScene === true) scene3.onBeforeRender(_this, scene3, camera3, _currentRenderTarget); currentRenderState = renderStates.get(scene3, renderStateStack.length); currentRenderState.init(); renderStateStack.push(currentRenderState); _projScreenMatrix.multiplyMatrices(camera3.projectionMatrix, camera3.matrixWorldInverse); _frustum.setFromProjectionMatrix(_projScreenMatrix); _localClippingEnabled = this.localClippingEnabled; _clippingEnabled = clipping.init(this.clippingPlanes, _localClippingEnabled); currentRenderList = renderLists.get(scene3, renderListStack.length); currentRenderList.init(); renderListStack.push(currentRenderList); projectObject(scene3, camera3, 0, _this.sortObjects); currentRenderList.finish(); if (_this.sortObjects === true) { currentRenderList.sort(_opaqueSort, _transparentSort); } this.info.render.frame++; if (_clippingEnabled === true) clipping.beginShadows(); const shadowsArray = currentRenderState.state.shadowsArray; shadowMap.render(shadowsArray, scene3, camera3); if (_clippingEnabled === true) clipping.endShadows(); if (this.info.autoReset === true) this.info.reset(); background.render(currentRenderList, scene3); currentRenderState.setupLights(_this._useLegacyLights); if (camera3.isArrayCamera) { const cameras = camera3.cameras; for (let i = 0, l = cameras.length; i < l; i++) { const camera22 = cameras[i]; renderScene(currentRenderList, scene3, camera22, camera22.viewport); } } else { renderScene(currentRenderList, scene3, camera3); } if (_currentRenderTarget !== null) { textures.updateMultisampleRenderTarget(_currentRenderTarget); textures.updateRenderTargetMipmap(_currentRenderTarget); } if (scene3.isScene === true) scene3.onAfterRender(_this, scene3, camera3); bindingStates.resetDefaultState(); _currentMaterialId = -1; _currentCamera = null; renderStateStack.pop(); if (renderStateStack.length > 0) { currentRenderState = renderStateStack[renderStateStack.length - 1]; } else { currentRenderState = null; } renderListStack.pop(); if (renderListStack.length > 0) { currentRenderList = renderListStack[renderListStack.length - 1]; } else { currentRenderList = null; } }; function projectObject(object, camera3, groupOrder, sortObjects) { if (object.visible === false) return; const visible = object.layers.test(camera3.layers); if (visible) { if (object.isGroup) { groupOrder = object.renderOrder; } else if (object.isLOD) { if (object.autoUpdate === true) object.update(camera3); } else if (object.isLight) { currentRenderState.pushLight(object); if (object.castShadow) { currentRenderState.pushShadow(object); } } else if (object.isSprite) { if (!object.frustumCulled || _frustum.intersectsSprite(object)) { if (sortObjects) { _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix); } const geometry = objects.update(object); const material = object.material; if (material.visible) { currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null); } } } else if (object.isMesh || object.isLine || object.isPoints) { if (!object.frustumCulled || _frustum.intersectsObject(object)) { const geometry = objects.update(object); const material = object.material; if (sortObjects) { if (object.boundingSphere !== void 0) { if (object.boundingSphere === null) object.computeBoundingSphere(); _vector3.copy(object.boundingSphere.center); } else { if (geometry.boundingSphere === null) geometry.computeBoundingSphere(); _vector3.copy(geometry.boundingSphere.center); } _vector3.applyMatrix4(object.matrixWorld).applyMatrix4(_projScreenMatrix); } if (Array.isArray(material)) { const groups = geometry.groups; for (let i = 0, l = groups.length; i < l; i++) { const group = groups[i]; const groupMaterial = material[group.materialIndex]; if (groupMaterial && groupMaterial.visible) { currentRenderList.push(object, geometry, groupMaterial, groupOrder, _vector3.z, group); } } } else if (material.visible) { currentRenderList.push(object, geometry, material, groupOrder, _vector3.z, null); } } } } const children = object.children; for (let i = 0, l = children.length; i < l; i++) { projectObject(children[i], camera3, groupOrder, sortObjects); } } function renderScene(currentRenderList2, scene3, camera3, viewport) { const opaqueObjects = currentRenderList2.opaque; const transmissiveObjects = currentRenderList2.transmissive; const transparentObjects = currentRenderList2.transparent; currentRenderState.setupLightsView(camera3); if (_clippingEnabled === true) clipping.setGlobalState(_this.clippingPlanes, camera3); if (transmissiveObjects.length > 0) renderTransmissionPass(opaqueObjects, transmissiveObjects, scene3, camera3); if (viewport) state.viewport(_currentViewport.copy(viewport)); if (opaqueObjects.length > 0) renderObjects(opaqueObjects, scene3, camera3); if (transmissiveObjects.length > 0) renderObjects(transmissiveObjects, scene3, camera3); if (transparentObjects.length > 0) renderObjects(transparentObjects, scene3, camera3); state.buffers.depth.setTest(true); state.buffers.depth.setMask(true); state.buffers.color.setMask(true); state.setPolygonOffset(false); } function renderTransmissionPass(opaqueObjects, transmissiveObjects, scene3, camera3) { const isWebGL2 = capabilities.isWebGL2; if (_transmissionRenderTarget === null) { _transmissionRenderTarget = new WebGLRenderTarget2(1, 1, { generateMipmaps: true, type: extensions.has("EXT_color_buffer_half_float") ? HalfFloatType2 : UnsignedByteType2, minFilter: LinearMipmapLinearFilter2, samples: isWebGL2 ? 4 : 0 }); } _this.getDrawingBufferSize(_vector23); if (isWebGL2) { _transmissionRenderTarget.setSize(_vector23.x, _vector23.y); } else { _transmissionRenderTarget.setSize(floorPowerOfTwo2(_vector23.x), floorPowerOfTwo2(_vector23.y)); } const currentRenderTarget = _this.getRenderTarget(); _this.setRenderTarget(_transmissionRenderTarget); _this.getClearColor(_currentClearColor); _currentClearAlpha = _this.getClearAlpha(); if (_currentClearAlpha < 1) _this.setClearColor(16777215, 0.5); _this.clear(); const currentToneMapping = _this.toneMapping; _this.toneMapping = NoToneMapping2; renderObjects(opaqueObjects, scene3, camera3); textures.updateMultisampleRenderTarget(_transmissionRenderTarget); textures.updateRenderTargetMipmap(_transmissionRenderTarget); let renderTargetNeedsUpdate = false; for (let i = 0, l = transmissiveObjects.length; i < l; i++) { const renderItem = transmissiveObjects[i]; const object = renderItem.object; const geometry = renderItem.geometry; const material = renderItem.material; const group = renderItem.group; if (material.side === DoubleSide2 && object.layers.test(camera3.layers)) { const currentSide = material.side; material.side = BackSide2; material.needsUpdate = true; renderObject(object, scene3, camera3, geometry, material, group); material.side = currentSide; material.needsUpdate = true; renderTargetNeedsUpdate = true; } } if (renderTargetNeedsUpdate === true) { textures.updateMultisampleRenderTarget(_transmissionRenderTarget); textures.updateRenderTargetMipmap(_transmissionRenderTarget); } _this.setRenderTarget(currentRenderTarget); _this.setClearColor(_currentClearColor, _currentClearAlpha); _this.toneMapping = currentToneMapping; } function renderObjects(renderList, scene3, camera3) { const overrideMaterial = scene3.isScene === true ? scene3.overrideMaterial : null; for (let i = 0, l = renderList.length; i < l; i++) { const renderItem = renderList[i]; const object = renderItem.object; const geometry = renderItem.geometry; const material = overrideMaterial === null ? renderItem.material : overrideMaterial; const group = renderItem.group; if (object.layers.test(camera3.layers)) { renderObject(object, scene3, camera3, geometry, material, group); } } } function renderObject(object, scene3, camera3, geometry, material, group) { object.onBeforeRender(_this, scene3, camera3, geometry, material, group); object.modelViewMatrix.multiplyMatrices(camera3.matrixWorldInverse, object.matrixWorld); object.normalMatrix.getNormalMatrix(object.modelViewMatrix); material.onBeforeRender(_this, scene3, camera3, geometry, object, group); if (material.transparent === true && material.side === DoubleSide2 && material.forceSinglePass === false) { material.side = BackSide2; material.needsUpdate = true; _this.renderBufferDirect(camera3, scene3, geometry, material, object, group); material.side = FrontSide2; material.needsUpdate = true; _this.renderBufferDirect(camera3, scene3, geometry, material, object, group); material.side = DoubleSide2; } else { _this.renderBufferDirect(camera3, scene3, geometry, material, object, group); } object.onAfterRender(_this, scene3, camera3, geometry, material, group); } function getProgram(material, scene3, object) { if (scene3.isScene !== true) scene3 = _emptyScene; const materialProperties = properties.get(material); const lights = currentRenderState.state.lights; const shadowsArray = currentRenderState.state.shadowsArray; const lightsStateVersion = lights.state.version; const parameters2 = programCache.getParameters(material, lights.state, shadowsArray, scene3, object); const programCacheKey = programCache.getProgramCacheKey(parameters2); let programs = materialProperties.programs; materialProperties.environment = material.isMeshStandardMaterial ? scene3.environment : null; materialProperties.fog = scene3.fog; materialProperties.envMap = (material.isMeshStandardMaterial ? cubeuvmaps : cubemaps).get(material.envMap || materialProperties.environment); if (programs === void 0) { material.addEventListener("dispose", onMaterialDispose); programs = /* @__PURE__ */ new Map(); materialProperties.programs = programs; } let program = programs.get(programCacheKey); if (program !== void 0) { if (materialProperties.currentProgram === program && materialProperties.lightsStateVersion === lightsStateVersion) { updateCommonMaterialProperties(material, parameters2); return program; } } else { parameters2.uniforms = programCache.getUniforms(material); material.onBuild(object, parameters2, _this); material.onBeforeCompile(parameters2, _this); program = programCache.acquireProgram(parameters2, programCacheKey); programs.set(programCacheKey, program); materialProperties.uniforms = parameters2.uniforms; } const uniforms = materialProperties.uniforms; if (!material.isShaderMaterial && !material.isRawShaderMaterial || material.clipping === true) { uniforms.clippingPlanes = clipping.uniform; } updateCommonMaterialProperties(material, parameters2); materialProperties.needsLights = materialNeedsLights(material); materialProperties.lightsStateVersion = lightsStateVersion; if (materialProperties.needsLights) { uniforms.ambientLightColor.value = lights.state.ambient; uniforms.lightProbe.value = lights.state.probe; uniforms.directionalLights.value = lights.state.directional; uniforms.directionalLightShadows.value = lights.state.directionalShadow; uniforms.spotLights.value = lights.state.spot; uniforms.spotLightShadows.value = lights.state.spotShadow; uniforms.rectAreaLights.value = lights.state.rectArea; uniforms.ltc_1.value = lights.state.rectAreaLTC1; uniforms.ltc_2.value = lights.state.rectAreaLTC2; uniforms.pointLights.value = lights.state.point; uniforms.pointLightShadows.value = lights.state.pointShadow; uniforms.hemisphereLights.value = lights.state.hemi; uniforms.directionalShadowMap.value = lights.state.directionalShadowMap; uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix; uniforms.spotShadowMap.value = lights.state.spotShadowMap; uniforms.spotLightMatrix.value = lights.state.spotLightMatrix; uniforms.spotLightMap.value = lights.state.spotLightMap; uniforms.pointShadowMap.value = lights.state.pointShadowMap; uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; } const progUniforms = program.getUniforms(); const uniformsList = WebGLUniforms2.seqWithValue(progUniforms.seq, uniforms); materialProperties.currentProgram = program; materialProperties.uniformsList = uniformsList; return program; } function updateCommonMaterialProperties(material, parameters2) { const materialProperties = properties.get(material); materialProperties.outputColorSpace = parameters2.outputColorSpace; materialProperties.instancing = parameters2.instancing; materialProperties.instancingColor = parameters2.instancingColor; materialProperties.skinning = parameters2.skinning; materialProperties.morphTargets = parameters2.morphTargets; materialProperties.morphNormals = parameters2.morphNormals; materialProperties.morphColors = parameters2.morphColors; materialProperties.morphTargetsCount = parameters2.morphTargetsCount; materialProperties.numClippingPlanes = parameters2.numClippingPlanes; materialProperties.numIntersection = parameters2.numClipIntersection; materialProperties.vertexAlphas = parameters2.vertexAlphas; materialProperties.vertexTangents = parameters2.vertexTangents; materialProperties.toneMapping = parameters2.toneMapping; } function setProgram(camera3, scene3, geometry, material, object) { if (scene3.isScene !== true) scene3 = _emptyScene; textures.resetTextureUnits(); const fog = scene3.fog; const environment = material.isMeshStandardMaterial ? scene3.environment : null; const colorSpace = _currentRenderTarget === null ? _this.outputColorSpace : _currentRenderTarget.isXRRenderTarget === true ? _currentRenderTarget.texture.colorSpace : LinearSRGBColorSpace2; const envMap = (material.isMeshStandardMaterial ? cubeuvmaps : cubemaps).get(material.envMap || environment); const vertexAlphas = material.vertexColors === true && !!geometry.attributes.color && geometry.attributes.color.itemSize === 4; const vertexTangents = !!geometry.attributes.tangent && (!!material.normalMap || material.anisotropy > 0); const morphTargets = !!geometry.morphAttributes.position; const morphNormals = !!geometry.morphAttributes.normal; const morphColors = !!geometry.morphAttributes.color; let toneMapping = NoToneMapping2; if (material.toneMapped) { if (_currentRenderTarget === null || _currentRenderTarget.isXRRenderTarget === true) { toneMapping = _this.toneMapping; } } const morphAttribute = geometry.morphAttributes.position || geometry.morphAttributes.normal || geometry.morphAttributes.color; const morphTargetsCount = morphAttribute !== void 0 ? morphAttribute.length : 0; const materialProperties = properties.get(material); const lights = currentRenderState.state.lights; if (_clippingEnabled === true) { if (_localClippingEnabled === true || camera3 !== _currentCamera) { const useCache = camera3 === _currentCamera && material.id === _currentMaterialId; clipping.setState(material, camera3, useCache); } } let needsProgramChange = false; if (material.version === materialProperties.__version) { if (materialProperties.needsLights && materialProperties.lightsStateVersion !== lights.state.version) { needsProgramChange = true; } else if (materialProperties.outputColorSpace !== colorSpace) { needsProgramChange = true; } else if (object.isInstancedMesh && materialProperties.instancing === false) { needsProgramChange = true; } else if (!object.isInstancedMesh && materialProperties.instancing === true) { needsProgramChange = true; } else if (object.isSkinnedMesh && materialProperties.skinning === false) { needsProgramChange = true; } else if (!object.isSkinnedMesh && materialProperties.skinning === true) { needsProgramChange = true; } else if (object.isInstancedMesh && materialProperties.instancingColor === true && object.instanceColor === null) { needsProgramChange = true; } else if (object.isInstancedMesh && materialProperties.instancingColor === false && object.instanceColor !== null) { needsProgramChange = true; } else if (materialProperties.envMap !== envMap) { needsProgramChange = true; } else if (material.fog === true && materialProperties.fog !== fog) { needsProgramChange = true; } else if (materialProperties.numClippingPlanes !== void 0 && (materialProperties.numClippingPlanes !== clipping.numPlanes || materialProperties.numIntersection !== clipping.numIntersection)) { needsProgramChange = true; } else if (materialProperties.vertexAlphas !== vertexAlphas) { needsProgramChange = true; } else if (materialProperties.vertexTangents !== vertexTangents) { needsProgramChange = true; } else if (materialProperties.morphTargets !== morphTargets) { needsProgramChange = true; } else if (materialProperties.morphNormals !== morphNormals) { needsProgramChange = true; } else if (materialProperties.morphColors !== morphColors) { needsProgramChange = true; } else if (materialProperties.toneMapping !== toneMapping) { needsProgramChange = true; } else if (capabilities.isWebGL2 === true && materialProperties.morphTargetsCount !== morphTargetsCount) { needsProgramChange = true; } } else { needsProgramChange = true; materialProperties.__version = material.version; } let program = materialProperties.currentProgram; if (needsProgramChange === true) { program = getProgram(material, scene3, object); } let refreshProgram = false; let refreshMaterial = false; let refreshLights = false; const p_uniforms = program.getUniforms(), m_uniforms = materialProperties.uniforms; if (state.useProgram(program.program)) { refreshProgram = true; refreshMaterial = true; refreshLights = true; } if (material.id !== _currentMaterialId) { _currentMaterialId = material.id; refreshMaterial = true; } if (refreshProgram || _currentCamera !== camera3) { p_uniforms.setValue(_gl, "projectionMatrix", camera3.projectionMatrix); p_uniforms.setValue(_gl, "viewMatrix", camera3.matrixWorldInverse); const uCamPos = p_uniforms.map.cameraPosition; if (uCamPos !== void 0) { uCamPos.setValue(_gl, _vector3.setFromMatrixPosition(camera3.matrixWorld)); } if (capabilities.logarithmicDepthBuffer) { p_uniforms.setValue( _gl, "logDepthBufFC", 2 / (Math.log(camera3.far + 1) / Math.LN2) ); } if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) { p_uniforms.setValue(_gl, "isOrthographic", camera3.isOrthographicCamera === true); } if (_currentCamera !== camera3) { _currentCamera = camera3; refreshMaterial = true; refreshLights = true; } } if (object.isSkinnedMesh) { p_uniforms.setOptional(_gl, object, "bindMatrix"); p_uniforms.setOptional(_gl, object, "bindMatrixInverse"); const skeleton = object.skeleton; if (skeleton) { if (capabilities.floatVertexTextures) { if (skeleton.boneTexture === null) skeleton.computeBoneTexture(); p_uniforms.setValue(_gl, "boneTexture", skeleton.boneTexture, textures); p_uniforms.setValue(_gl, "boneTextureSize", skeleton.boneTextureSize); } else { console.warn("THREE.WebGLRenderer: SkinnedMesh can only be used with WebGL 2. With WebGL 1 OES_texture_float and vertex textures support is required."); } } } const morphAttributes = geometry.morphAttributes; if (morphAttributes.position !== void 0 || morphAttributes.normal !== void 0 || morphAttributes.color !== void 0 && capabilities.isWebGL2 === true) { morphtargets.update(object, geometry, program); } if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) { materialProperties.receiveShadow = object.receiveShadow; p_uniforms.setValue(_gl, "receiveShadow", object.receiveShadow); } if (material.isMeshGouraudMaterial && material.envMap !== null) { m_uniforms.envMap.value = envMap; m_uniforms.flipEnvMap.value = envMap.isCubeTexture && envMap.isRenderTargetTexture === false ? -1 : 1; } if (refreshMaterial) { p_uniforms.setValue(_gl, "toneMappingExposure", _this.toneMappingExposure); if (materialProperties.needsLights) { markUniformsLightsNeedsUpdate(m_uniforms, refreshLights); } if (fog && material.fog === true) { materials.refreshFogUniforms(m_uniforms, fog); } materials.refreshMaterialUniforms(m_uniforms, material, _pixelRatio, _height, _transmissionRenderTarget); WebGLUniforms2.upload(_gl, materialProperties.uniformsList, m_uniforms, textures); } if (material.isShaderMaterial && material.uniformsNeedUpdate === true) { WebGLUniforms2.upload(_gl, materialProperties.uniformsList, m_uniforms, textures); material.uniformsNeedUpdate = false; } if (material.isSpriteMaterial) { p_uniforms.setValue(_gl, "center", object.center); } p_uniforms.setValue(_gl, "modelViewMatrix", object.modelViewMatrix); p_uniforms.setValue(_gl, "normalMatrix", object.normalMatrix); p_uniforms.setValue(_gl, "modelMatrix", object.matrixWorld); if (material.isShaderMaterial || material.isRawShaderMaterial) { const groups = material.uniformsGroups; for (let i = 0, l = groups.length; i < l; i++) { if (capabilities.isWebGL2) { const group = groups[i]; uniformsGroups.update(group, program); uniformsGroups.bind(group, program); } else { console.warn("THREE.WebGLRenderer: Uniform Buffer Objects can only be used with WebGL 2."); } } } return program; } function markUniformsLightsNeedsUpdate(uniforms, value) { uniforms.ambientLightColor.needsUpdate = value; uniforms.lightProbe.needsUpdate = value; uniforms.directionalLights.needsUpdate = value; uniforms.directionalLightShadows.needsUpdate = value; uniforms.pointLights.needsUpdate = value; uniforms.pointLightShadows.needsUpdate = value; uniforms.spotLights.needsUpdate = value; uniforms.spotLightShadows.needsUpdate = value; uniforms.rectAreaLights.needsUpdate = value; uniforms.hemisphereLights.needsUpdate = value; } function materialNeedsLights(material) { return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial || material.isMeshStandardMaterial || material.isShadowMaterial || material.isShaderMaterial && material.lights === true; } this.getActiveCubeFace = function() { return _currentActiveCubeFace; }; this.getActiveMipmapLevel = function() { return _currentActiveMipmapLevel; }; this.getRenderTarget = function() { return _currentRenderTarget; }; this.setRenderTargetTextures = function(renderTarget, colorTexture, depthTexture) { properties.get(renderTarget.texture).__webglTexture = colorTexture; properties.get(renderTarget.depthTexture).__webglTexture = depthTexture; const renderTargetProperties = properties.get(renderTarget); renderTargetProperties.__hasExternalTextures = true; if (renderTargetProperties.__hasExternalTextures) { renderTargetProperties.__autoAllocateDepthBuffer = depthTexture === void 0; if (!renderTargetProperties.__autoAllocateDepthBuffer) { if (extensions.has("WEBGL_multisampled_render_to_texture") === true) { console.warn("THREE.WebGLRenderer: Render-to-texture extension was disabled because an external texture was provided"); renderTargetProperties.__useRenderToTexture = false; } } } }; this.setRenderTargetFramebuffer = function(renderTarget, defaultFramebuffer) { const renderTargetProperties = properties.get(renderTarget); renderTargetProperties.__webglFramebuffer = defaultFramebuffer; renderTargetProperties.__useDefaultFramebuffer = defaultFramebuffer === void 0; }; this.setRenderTarget = function(renderTarget, activeCubeFace = 0, activeMipmapLevel = 0) { _currentRenderTarget = renderTarget; _currentActiveCubeFace = activeCubeFace; _currentActiveMipmapLevel = activeMipmapLevel; let useDefaultFramebuffer = true; let framebuffer = null; let isCube = false; let isRenderTarget3D = false; if (renderTarget) { const renderTargetProperties = properties.get(renderTarget); if (renderTargetProperties.__useDefaultFramebuffer !== void 0) { state.bindFramebuffer(_gl.FRAMEBUFFER, null); useDefaultFramebuffer = false; } else if (renderTargetProperties.__webglFramebuffer === void 0) { textures.setupRenderTarget(renderTarget); } else if (renderTargetProperties.__hasExternalTextures) { textures.rebindTextures(renderTarget, properties.get(renderTarget.texture).__webglTexture, properties.get(renderTarget.depthTexture).__webglTexture); } const texture = renderTarget.texture; if (texture.isData3DTexture || texture.isDataArrayTexture || texture.isCompressedArrayTexture) { isRenderTarget3D = true; } const __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer; if (renderTarget.isWebGLCubeRenderTarget) { if (Array.isArray(__webglFramebuffer[activeCubeFace])) { framebuffer = __webglFramebuffer[activeCubeFace][activeMipmapLevel]; } else { framebuffer = __webglFramebuffer[activeCubeFace]; } isCube = true; } else if (capabilities.isWebGL2 && renderTarget.samples > 0 && textures.useMultisampledRTT(renderTarget) === false) { framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer; } else { if (Array.isArray(__webglFramebuffer)) { framebuffer = __webglFramebuffer[activeMipmapLevel]; } else { framebuffer = __webglFramebuffer; } } _currentViewport.copy(renderTarget.viewport); _currentScissor.copy(renderTarget.scissor); _currentScissorTest = renderTarget.scissorTest; } else { _currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor(); _currentScissor.copy(_scissor).multiplyScalar(_pixelRatio).floor(); _currentScissorTest = _scissorTest; } const framebufferBound = state.bindFramebuffer(_gl.FRAMEBUFFER, framebuffer); if (framebufferBound && capabilities.drawBuffers && useDefaultFramebuffer) { state.drawBuffers(renderTarget, framebuffer); } state.viewport(_currentViewport); state.scissor(_currentScissor); state.setScissorTest(_currentScissorTest); if (isCube) { const textureProperties = properties.get(renderTarget.texture); _gl.framebufferTexture2D(_gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel); } else if (isRenderTarget3D) { const textureProperties = properties.get(renderTarget.texture); const layer = activeCubeFace || 0; _gl.framebufferTextureLayer(_gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureProperties.__webglTexture, activeMipmapLevel || 0, layer); } _currentMaterialId = -1; }; this.readRenderTargetPixels = function(renderTarget, x3, y3, width, height, buffer, activeCubeFaceIndex) { if (!(renderTarget && renderTarget.isWebGLRenderTarget)) { console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget."); return; } let framebuffer = properties.get(renderTarget).__webglFramebuffer; if (renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== void 0) { framebuffer = framebuffer[activeCubeFaceIndex]; } if (framebuffer) { state.bindFramebuffer(_gl.FRAMEBUFFER, framebuffer); try { const texture = renderTarget.texture; const textureFormat = texture.format; const textureType = texture.type; if (textureFormat !== RGBAFormat2 && utils.convert(textureFormat) !== _gl.getParameter(_gl.IMPLEMENTATION_COLOR_READ_FORMAT)) { console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format."); return; } const halfFloatSupportedByExt = textureType === HalfFloatType2 && (extensions.has("EXT_color_buffer_half_float") || capabilities.isWebGL2 && extensions.has("EXT_color_buffer_float")); if (textureType !== UnsignedByteType2 && utils.convert(textureType) !== _gl.getParameter(_gl.IMPLEMENTATION_COLOR_READ_TYPE) && // Edge and Chrome Mac < 52 (#9513) !(textureType === FloatType2 && (capabilities.isWebGL2 || extensions.has("OES_texture_float") || extensions.has("WEBGL_color_buffer_float"))) && // Chrome Mac >= 52 and Firefox !halfFloatSupportedByExt) { console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type."); return; } if (x3 >= 0 && x3 <= renderTarget.width - width && (y3 >= 0 && y3 <= renderTarget.height - height)) { _gl.readPixels(x3, y3, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer); } } finally { const framebuffer2 = _currentRenderTarget !== null ? properties.get(_currentRenderTarget).__webglFramebuffer : null; state.bindFramebuffer(_gl.FRAMEBUFFER, framebuffer2); } } }; this.copyFramebufferToTexture = function(position, texture, level = 0) { const levelScale = Math.pow(2, -level); const width = Math.floor(texture.image.width * levelScale); const height = Math.floor(texture.image.height * levelScale); textures.setTexture2D(texture, 0); _gl.copyTexSubImage2D(_gl.TEXTURE_2D, level, 0, 0, position.x, position.y, width, height); state.unbindTexture(); }; this.copyTextureToTexture = function(position, srcTexture, dstTexture, level = 0) { const width = srcTexture.image.width; const height = srcTexture.image.height; const glFormat = utils.convert(dstTexture.format); const glType = utils.convert(dstTexture.type); textures.setTexture2D(dstTexture, 0); _gl.pixelStorei(_gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY); _gl.pixelStorei(_gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha); _gl.pixelStorei(_gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment); if (srcTexture.isDataTexture) { _gl.texSubImage2D(_gl.TEXTURE_2D, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data); } else { if (srcTexture.isCompressedTexture) { _gl.compressedTexSubImage2D(_gl.TEXTURE_2D, level, position.x, position.y, srcTexture.mipmaps[0].width, srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data); } else { _gl.texSubImage2D(_gl.TEXTURE_2D, level, position.x, position.y, glFormat, glType, srcTexture.image); } } if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(_gl.TEXTURE_2D); state.unbindTexture(); }; this.copyTextureToTexture3D = function(sourceBox, position, srcTexture, dstTexture, level = 0) { if (_this.isWebGL1Renderer) { console.warn("THREE.WebGLRenderer.copyTextureToTexture3D: can only be used with WebGL2."); return; } const width = sourceBox.max.x - sourceBox.min.x + 1; const height = sourceBox.max.y - sourceBox.min.y + 1; const depth2 = sourceBox.max.z - sourceBox.min.z + 1; const glFormat = utils.convert(dstTexture.format); const glType = utils.convert(dstTexture.type); let glTarget; if (dstTexture.isData3DTexture) { textures.setTexture3D(dstTexture, 0); glTarget = _gl.TEXTURE_3D; } else if (dstTexture.isDataArrayTexture) { textures.setTexture2DArray(dstTexture, 0); glTarget = _gl.TEXTURE_2D_ARRAY; } else { console.warn("THREE.WebGLRenderer.copyTextureToTexture3D: only supports THREE.DataTexture3D and THREE.DataTexture2DArray."); return; } _gl.pixelStorei(_gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY); _gl.pixelStorei(_gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha); _gl.pixelStorei(_gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment); const unpackRowLen = _gl.getParameter(_gl.UNPACK_ROW_LENGTH); const unpackImageHeight = _gl.getParameter(_gl.UNPACK_IMAGE_HEIGHT); const unpackSkipPixels = _gl.getParameter(_gl.UNPACK_SKIP_PIXELS); const unpackSkipRows = _gl.getParameter(_gl.UNPACK_SKIP_ROWS); const unpackSkipImages = _gl.getParameter(_gl.UNPACK_SKIP_IMAGES); const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[0] : srcTexture.image; _gl.pixelStorei(_gl.UNPACK_ROW_LENGTH, image.width); _gl.pixelStorei(_gl.UNPACK_IMAGE_HEIGHT, image.height); _gl.pixelStorei(_gl.UNPACK_SKIP_PIXELS, sourceBox.min.x); _gl.pixelStorei(_gl.UNPACK_SKIP_ROWS, sourceBox.min.y); _gl.pixelStorei(_gl.UNPACK_SKIP_IMAGES, sourceBox.min.z); if (srcTexture.isDataTexture || srcTexture.isData3DTexture) { _gl.texSubImage3D(glTarget, level, position.x, position.y, position.z, width, height, depth2, glFormat, glType, image.data); } else { if (srcTexture.isCompressedArrayTexture) { console.warn("THREE.WebGLRenderer.copyTextureToTexture3D: untested support for compressed srcTexture."); _gl.compressedTexSubImage3D(glTarget, level, position.x, position.y, position.z, width, height, depth2, glFormat, image.data); } else { _gl.texSubImage3D(glTarget, level, position.x, position.y, position.z, width, height, depth2, glFormat, glType, image); } } _gl.pixelStorei(_gl.UNPACK_ROW_LENGTH, unpackRowLen); _gl.pixelStorei(_gl.UNPACK_IMAGE_HEIGHT, unpackImageHeight); _gl.pixelStorei(_gl.UNPACK_SKIP_PIXELS, unpackSkipPixels); _gl.pixelStorei(_gl.UNPACK_SKIP_ROWS, unpackSkipRows); _gl.pixelStorei(_gl.UNPACK_SKIP_IMAGES, unpackSkipImages); if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(glTarget); state.unbindTexture(); }; this.initTexture = function(texture) { if (texture.isCubeTexture) { textures.setTextureCube(texture, 0); } else if (texture.isData3DTexture) { textures.setTexture3D(texture, 0); } else if (texture.isDataArrayTexture || texture.isCompressedArrayTexture) { textures.setTexture2DArray(texture, 0); } else { textures.setTexture2D(texture, 0); } state.unbindTexture(); }; this.resetState = function() { _currentActiveCubeFace = 0; _currentActiveMipmapLevel = 0; _currentRenderTarget = null; state.reset(); bindingStates.reset(); }; if (typeof __THREE_DEVTOOLS__ !== "undefined") { __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe", { detail: this })); } } get coordinateSystem() { return WebGLCoordinateSystem2; } get outputColorSpace() { return this._outputColorSpace; } set outputColorSpace(colorSpace) { this._outputColorSpace = colorSpace; const gl = this.getContext(); gl.drawingBufferColorSpace = colorSpace === DisplayP3ColorSpace2 ? "display-p3" : "srgb"; gl.unpackColorSpace = ColorManagement2.workingColorSpace === LinearDisplayP3ColorSpace2 ? "display-p3" : "srgb"; } get physicallyCorrectLights() { console.warn("THREE.WebGLRenderer: The property .physicallyCorrectLights has been removed. Set renderer.useLegacyLights instead."); return !this.useLegacyLights; } set physicallyCorrectLights(value) { console.warn("THREE.WebGLRenderer: The property .physicallyCorrectLights has been removed. Set renderer.useLegacyLights instead."); this.useLegacyLights = !value; } get outputEncoding() { console.warn("THREE.WebGLRenderer: Property .outputEncoding has been removed. Use .outputColorSpace instead."); return this.outputColorSpace === SRGBColorSpace2 ? sRGBEncoding2 : LinearEncoding2; } set outputEncoding(encoding) { console.warn("THREE.WebGLRenderer: Property .outputEncoding has been removed. Use .outputColorSpace instead."); this.outputColorSpace = encoding === sRGBEncoding2 ? SRGBColorSpace2 : LinearSRGBColorSpace2; } get useLegacyLights() { console.warn("THREE.WebGLRenderer: The property .useLegacyLights has been deprecated. Migrate your lighting according to the following guide: https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733."); return this._useLegacyLights; } set useLegacyLights(value) { console.warn("THREE.WebGLRenderer: The property .useLegacyLights has been deprecated. Migrate your lighting according to the following guide: https://discourse.threejs.org/t/updates-to-lighting-in-three-js-r155/53733."); this._useLegacyLights = value; } }; var WebGL1Renderer2 = class extends WebGLRenderer2 { }; WebGL1Renderer2.prototype.isWebGL1Renderer = true; var Scene = class extends Object3D2 { constructor() { super(); this.isScene = true; this.type = "Scene"; this.background = null; this.environment = null; this.fog = null; this.backgroundBlurriness = 0; this.backgroundIntensity = 1; this.overrideMaterial = null; if (typeof __THREE_DEVTOOLS__ !== "undefined") { __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("observe", { detail: this })); } } copy(source, recursive) { super.copy(source, recursive); if (source.background !== null) this.background = source.background.clone(); if (source.environment !== null) this.environment = source.environment.clone(); if (source.fog !== null) this.fog = source.fog.clone(); this.backgroundBlurriness = source.backgroundBlurriness; this.backgroundIntensity = source.backgroundIntensity; if (source.overrideMaterial !== null) this.overrideMaterial = source.overrideMaterial.clone(); this.matrixAutoUpdate = source.matrixAutoUpdate; return this; } toJSON(meta) { const data = super.toJSON(meta); if (this.fog !== null) data.object.fog = this.fog.toJSON(); if (this.backgroundBlurriness > 0) data.object.backgroundBlurriness = this.backgroundBlurriness; if (this.backgroundIntensity !== 1) data.object.backgroundIntensity = this.backgroundIntensity; return data; } }; var LineBasicMaterial = class extends Material2 { constructor(parameters) { super(); this.isLineBasicMaterial = true; this.type = "LineBasicMaterial"; this.color = new Color2(16777215); this.map = null; this.linewidth = 1; this.linecap = "round"; this.linejoin = "round"; this.fog = true; this.setValues(parameters); } copy(source) { super.copy(source); this.color.copy(source.color); this.map = source.map; this.linewidth = source.linewidth; this.linecap = source.linecap; this.linejoin = source.linejoin; this.fog = source.fog; return this; } }; var _start$1 = /* @__PURE__ */ new Vector32(); var _end$1 = /* @__PURE__ */ new Vector32(); var _inverseMatrix$1 = /* @__PURE__ */ new Matrix42(); var _ray$1 = /* @__PURE__ */ new Ray2(); var _sphere$1 = /* @__PURE__ */ new Sphere2(); var Line = class extends Object3D2 { constructor(geometry = new BufferGeometry2(), material = new LineBasicMaterial()) { super(); this.isLine = true; this.type = "Line"; this.geometry = geometry; this.material = material; this.updateMorphTargets(); } copy(source, recursive) { super.copy(source, recursive); this.material = Array.isArray(source.material) ? source.material.slice() : source.material; this.geometry = source.geometry; return this; } computeLineDistances() { const geometry = this.geometry; if (geometry.index === null) { const positionAttribute = geometry.attributes.position; const lineDistances = [0]; for (let i = 1, l = positionAttribute.count; i < l; i++) { _start$1.fromBufferAttribute(positionAttribute, i - 1); _end$1.fromBufferAttribute(positionAttribute, i); lineDistances[i] = lineDistances[i - 1]; lineDistances[i] += _start$1.distanceTo(_end$1); } geometry.setAttribute("lineDistance", new Float32BufferAttribute2(lineDistances, 1)); } else { console.warn("THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry."); } return this; } raycast(raycaster, intersects) { const geometry = this.geometry; const matrixWorld = this.matrixWorld; const threshold = raycaster.params.Line.threshold; const drawRange = geometry.drawRange; if (geometry.boundingSphere === null) geometry.computeBoundingSphere(); _sphere$1.copy(geometry.boundingSphere); _sphere$1.applyMatrix4(matrixWorld); _sphere$1.radius += threshold; if (raycaster.ray.intersectsSphere(_sphere$1) === false) return; _inverseMatrix$1.copy(matrixWorld).invert(); _ray$1.copy(raycaster.ray).applyMatrix4(_inverseMatrix$1); const localThreshold = threshold / ((this.scale.x + this.scale.y + this.scale.z) / 3); const localThresholdSq = localThreshold * localThreshold; const vStart = new Vector32(); const vEnd = new Vector32(); const interSegment = new Vector32(); const interRay = new Vector32(); const step = this.isLineSegments ? 2 : 1; const index6 = geometry.index; const attributes = geometry.attributes; const positionAttribute = attributes.position; if (index6 !== null) { const start = Math.max(0, drawRange.start); const end = Math.min(index6.count, drawRange.start + drawRange.count); for (let i = start, l = end - 1; i < l; i += step) { const a2 = index6.getX(i); const b = index6.getX(i + 1); vStart.fromBufferAttribute(positionAttribute, a2); vEnd.fromBufferAttribute(positionAttribute, b); const distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment); if (distSq > localThresholdSq) continue; interRay.applyMatrix4(this.matrixWorld); const distance = raycaster.ray.origin.distanceTo(interRay); if (distance < raycaster.near || distance > raycaster.far) continue; intersects.push({ distance, // What do we want? intersection point on the ray or on the segment?? // point: raycaster.ray.at( distance ), point: interSegment.clone().applyMatrix4(this.matrixWorld), index: i, face: null, faceIndex: null, object: this }); } } else { const start = Math.max(0, drawRange.start); const end = Math.min(positionAttribute.count, drawRange.start + drawRange.count); for (let i = start, l = end - 1; i < l; i += step) { vStart.fromBufferAttribute(positionAttribute, i); vEnd.fromBufferAttribute(positionAttribute, i + 1); const distSq = _ray$1.distanceSqToSegment(vStart, vEnd, interRay, interSegment); if (distSq > localThresholdSq) continue; interRay.applyMatrix4(this.matrixWorld); const distance = raycaster.ray.origin.distanceTo(interRay); if (distance < raycaster.near || distance > raycaster.far) continue; intersects.push({ distance, // What do we want? intersection point on the ray or on the segment?? // point: raycaster.ray.at( distance ), point: interSegment.clone().applyMatrix4(this.matrixWorld), index: i, face: null, faceIndex: null, object: this }); } } } updateMorphTargets() { const geometry = this.geometry; const morphAttributes = geometry.morphAttributes; const keys = Object.keys(morphAttributes); if (keys.length > 0) { const morphAttribute = morphAttributes[keys[0]]; if (morphAttribute !== void 0) { this.morphTargetInfluences = []; this.morphTargetDictionary = {}; for (let m2 = 0, ml = morphAttribute.length; m2 < ml; m2++) { const name = morphAttribute[m2].name || String(m2); this.morphTargetInfluences.push(0); this.morphTargetDictionary[name] = m2; } } } } }; var Curve = class { constructor() { this.type = "Curve"; this.arcLengthDivisions = 200; } // Virtual base class method to overwrite and implement in subclasses // - t [0 .. 1] getPoint() { console.warn("THREE.Curve: .getPoint() not implemented."); return null; } // Get point at relative position in curve according to arc length // - u [0 .. 1] getPointAt(u, optionalTarget) { const t = this.getUtoTmapping(u); return this.getPoint(t, optionalTarget); } // Get sequence of points using getPoint( t ) getPoints(divisions = 5) { const points = []; for (let d = 0; d <= divisions; d++) { points.push(this.getPoint(d / divisions)); } return points; } // Get sequence of points using getPointAt( u ) getSpacedPoints(divisions = 5) { const points = []; for (let d = 0; d <= divisions; d++) { points.push(this.getPointAt(d / divisions)); } return points; } // Get total curve arc length getLength() { const lengths = this.getLengths(); return lengths[lengths.length - 1]; } // Get list of cumulative segment lengths getLengths(divisions = this.arcLengthDivisions) { if (this.cacheArcLengths && this.cacheArcLengths.length === divisions + 1 && !this.needsUpdate) { return this.cacheArcLengths; } this.needsUpdate = false; const cache = []; let current, last = this.getPoint(0); let sum = 0; cache.push(0); for (let p = 1; p <= divisions; p++) { current = this.getPoint(p / divisions); sum += current.distanceTo(last); cache.push(sum); last = current; } this.cacheArcLengths = cache; return cache; } updateArcLengths() { this.needsUpdate = true; this.getLengths(); } // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant getUtoTmapping(u, distance) { const arcLengths = this.getLengths(); let i = 0; const il = arcLengths.length; let targetArcLength; if (distance) { targetArcLength = distance; } else { targetArcLength = u * arcLengths[il - 1]; } let low = 0, high = il - 1, comparison; while (low <= high) { i = Math.floor(low + (high - low) / 2); comparison = arcLengths[i] - targetArcLength; if (comparison < 0) { low = i + 1; } else if (comparison > 0) { high = i - 1; } else { high = i; break; } } i = high; if (arcLengths[i] === targetArcLength) { return i / (il - 1); } const lengthBefore = arcLengths[i]; const lengthAfter = arcLengths[i + 1]; const segmentLength = lengthAfter - lengthBefore; const segmentFraction = (targetArcLength - lengthBefore) / segmentLength; const t = (i + segmentFraction) / (il - 1); return t; } // Returns a unit vector tangent at t // In case any sub curve does not implement its tangent derivation, // 2 points a small delta apart will be used to find its gradient // which seems to give a reasonable approximation getTangent(t, optionalTarget) { const delta = 1e-4; let t1 = t - delta; let t2 = t + delta; if (t1 < 0) t1 = 0; if (t2 > 1) t2 = 1; const pt1 = this.getPoint(t1); const pt2 = this.getPoint(t2); const tangent = optionalTarget || (pt1.isVector2 ? new Vector22() : new Vector32()); tangent.copy(pt2).sub(pt1).normalize(); return tangent; } getTangentAt(u, optionalTarget) { const t = this.getUtoTmapping(u); return this.getTangent(t, optionalTarget); } computeFrenetFrames(segments, closed) { const normal = new Vector32(); const tangents = []; const normals = []; const binormals = []; const vec = new Vector32(); const mat = new Matrix42(); for (let i = 0; i <= segments; i++) { const u = i / segments; tangents[i] = this.getTangentAt(u, new Vector32()); } normals[0] = new Vector32(); binormals[0] = new Vector32(); let min2 = Number.MAX_VALUE; const tx = Math.abs(tangents[0].x); const ty = Math.abs(tangents[0].y); const tz = Math.abs(tangents[0].z); if (tx <= min2) { min2 = tx; normal.set(1, 0, 0); } if (ty <= min2) { min2 = ty; normal.set(0, 1, 0); } if (tz <= min2) { normal.set(0, 0, 1); } vec.crossVectors(tangents[0], normal).normalize(); normals[0].crossVectors(tangents[0], vec); binormals[0].crossVectors(tangents[0], normals[0]); for (let i = 1; i <= segments; i++) { normals[i] = normals[i - 1].clone(); binormals[i] = binormals[i - 1].clone(); vec.crossVectors(tangents[i - 1], tangents[i]); if (vec.length() > Number.EPSILON) { vec.normalize(); const theta = Math.acos(clamp2(tangents[i - 1].dot(tangents[i]), -1, 1)); normals[i].applyMatrix4(mat.makeRotationAxis(vec, theta)); } binormals[i].crossVectors(tangents[i], normals[i]); } if (closed === true) { let theta = Math.acos(clamp2(normals[0].dot(normals[segments]), -1, 1)); theta /= segments; if (tangents[0].dot(vec.crossVectors(normals[0], normals[segments])) > 0) { theta = -theta; } for (let i = 1; i <= segments; i++) { normals[i].applyMatrix4(mat.makeRotationAxis(tangents[i], theta * i)); binormals[i].crossVectors(tangents[i], normals[i]); } } return { tangents, normals, binormals }; } clone() { return new this.constructor().copy(this); } copy(source) { this.arcLengthDivisions = source.arcLengthDivisions; return this; } toJSON() { const data = { metadata: { version: 4.6, type: "Curve", generator: "Curve.toJSON" } }; data.arcLengthDivisions = this.arcLengthDivisions; data.type = this.type; return data; } fromJSON(json) { this.arcLengthDivisions = json.arcLengthDivisions; return this; } }; var EllipseCurve = class extends Curve { constructor(aX = 0, aY = 0, xRadius = 1, yRadius = 1, aStartAngle = 0, aEndAngle = Math.PI * 2, aClockwise = false, aRotation = 0) { super(); this.isEllipseCurve = true; this.type = "EllipseCurve"; this.aX = aX; this.aY = aY; this.xRadius = xRadius; this.yRadius = yRadius; this.aStartAngle = aStartAngle; this.aEndAngle = aEndAngle; this.aClockwise = aClockwise; this.aRotation = aRotation; } getPoint(t, optionalTarget) { const point = optionalTarget || new Vector22(); const twoPi = Math.PI * 2; let deltaAngle = this.aEndAngle - this.aStartAngle; const samePoints = Math.abs(deltaAngle) < Number.EPSILON; while (deltaAngle < 0) deltaAngle += twoPi; while (deltaAngle > twoPi) deltaAngle -= twoPi; if (deltaAngle < Number.EPSILON) { if (samePoints) { deltaAngle = 0; } else { deltaAngle = twoPi; } } if (this.aClockwise === true && !samePoints) { if (deltaAngle === twoPi) { deltaAngle = -twoPi; } else { deltaAngle = deltaAngle - twoPi; } } const angle = this.aStartAngle + t * deltaAngle; let x3 = this.aX + this.xRadius * Math.cos(angle); let y3 = this.aY + this.yRadius * Math.sin(angle); if (this.aRotation !== 0) { const cos = Math.cos(this.aRotation); const sin = Math.sin(this.aRotation); const tx = x3 - this.aX; const ty = y3 - this.aY; x3 = tx * cos - ty * sin + this.aX; y3 = tx * sin + ty * cos + this.aY; } return point.set(x3, y3); } copy(source) { super.copy(source); this.aX = source.aX; this.aY = source.aY; this.xRadius = source.xRadius; this.yRadius = source.yRadius; this.aStartAngle = source.aStartAngle; this.aEndAngle = source.aEndAngle; this.aClockwise = source.aClockwise; this.aRotation = source.aRotation; return this; } toJSON() { const data = super.toJSON(); data.aX = this.aX; data.aY = this.aY; data.xRadius = this.xRadius; data.yRadius = this.yRadius; data.aStartAngle = this.aStartAngle; data.aEndAngle = this.aEndAngle; data.aClockwise = this.aClockwise; data.aRotation = this.aRotation; return data; } fromJSON(json) { super.fromJSON(json); this.aX = json.aX; this.aY = json.aY; this.xRadius = json.xRadius; this.yRadius = json.yRadius; this.aStartAngle = json.aStartAngle; this.aEndAngle = json.aEndAngle; this.aClockwise = json.aClockwise; this.aRotation = json.aRotation; return this; } }; var ArcCurve = class extends EllipseCurve { constructor(aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise) { super(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise); this.isArcCurve = true; this.type = "ArcCurve"; } }; function CubicPoly() { let c0 = 0, c1 = 0, c2 = 0, c3 = 0; function init4(x0, x1, t0, t1) { c0 = x0; c1 = t0; c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1; c3 = 2 * x0 - 2 * x1 + t0 + t1; } return { initCatmullRom: function(x0, x1, x22, x3, tension) { init4(x1, x22, tension * (x22 - x0), tension * (x3 - x1)); }, initNonuniformCatmullRom: function(x0, x1, x22, x3, dt0, dt1, dt2) { let t1 = (x1 - x0) / dt0 - (x22 - x0) / (dt0 + dt1) + (x22 - x1) / dt1; let t2 = (x22 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x22) / dt2; t1 *= dt1; t2 *= dt1; init4(x1, x22, t1, t2); }, calc: function(t) { const t2 = t * t; const t3 = t2 * t; return c0 + c1 * t + c2 * t2 + c3 * t3; } }; } var tmp = /* @__PURE__ */ new Vector32(); var px = /* @__PURE__ */ new CubicPoly(); var py = /* @__PURE__ */ new CubicPoly(); var pz = /* @__PURE__ */ new CubicPoly(); var CatmullRomCurve3 = class extends Curve { constructor(points = [], closed = false, curveType = "centripetal", tension = 0.5) { super(); this.isCatmullRomCurve3 = true; this.type = "CatmullRomCurve3"; this.points = points; this.closed = closed; this.curveType = curveType; this.tension = tension; } getPoint(t, optionalTarget = new Vector32()) { const point = optionalTarget; const points = this.points; const l = points.length; const p = (l - (this.closed ? 0 : 1)) * t; let intPoint = Math.floor(p); let weight = p - intPoint; if (this.closed) { intPoint += intPoint > 0 ? 0 : (Math.floor(Math.abs(intPoint) / l) + 1) * l; } else if (weight === 0 && intPoint === l - 1) { intPoint = l - 2; weight = 1; } let p0, p3; if (this.closed || intPoint > 0) { p0 = points[(intPoint - 1) % l]; } else { tmp.subVectors(points[0], points[1]).add(points[0]); p0 = tmp; } const p1 = points[intPoint % l]; const p2 = points[(intPoint + 1) % l]; if (this.closed || intPoint + 2 < l) { p3 = points[(intPoint + 2) % l]; } else { tmp.subVectors(points[l - 1], points[l - 2]).add(points[l - 1]); p3 = tmp; } if (this.curveType === "centripetal" || this.curveType === "chordal") { const pow = this.curveType === "chordal" ? 0.5 : 0.25; let dt0 = Math.pow(p0.distanceToSquared(p1), pow); let dt1 = Math.pow(p1.distanceToSquared(p2), pow); let dt2 = Math.pow(p2.distanceToSquared(p3), pow); if (dt1 < 1e-4) dt1 = 1; if (dt0 < 1e-4) dt0 = dt1; if (dt2 < 1e-4) dt2 = dt1; px.initNonuniformCatmullRom(p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2); py.initNonuniformCatmullRom(p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2); pz.initNonuniformCatmullRom(p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2); } else if (this.curveType === "catmullrom") { px.initCatmullRom(p0.x, p1.x, p2.x, p3.x, this.tension); py.initCatmullRom(p0.y, p1.y, p2.y, p3.y, this.tension); pz.initCatmullRom(p0.z, p1.z, p2.z, p3.z, this.tension); } point.set( px.calc(weight), py.calc(weight), pz.calc(weight) ); return point; } copy(source) { super.copy(source); this.points = []; for (let i = 0, l = source.points.length; i < l; i++) { const point = source.points[i]; this.points.push(point.clone()); } this.closed = source.closed; this.curveType = source.curveType; this.tension = source.tension; return this; } toJSON() { const data = super.toJSON(); data.points = []; for (let i = 0, l = this.points.length; i < l; i++) { const point = this.points[i]; data.points.push(point.toArray()); } data.closed = this.closed; data.curveType = this.curveType; data.tension = this.tension; return data; } fromJSON(json) { super.fromJSON(json); this.points = []; for (let i = 0, l = json.points.length; i < l; i++) { const point = json.points[i]; this.points.push(new Vector32().fromArray(point)); } this.closed = json.closed; this.curveType = json.curveType; this.tension = json.tension; return this; } }; function CatmullRom(t, p0, p1, p2, p3) { const v0 = (p2 - p0) * 0.5; const v1 = (p3 - p1) * 0.5; const t2 = t * t; const t3 = t * t2; return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1; } function QuadraticBezierP0(t, p) { const k = 1 - t; return k * k * p; } function QuadraticBezierP1(t, p) { return 2 * (1 - t) * t * p; } function QuadraticBezierP2(t, p) { return t * t * p; } function QuadraticBezier(t, p0, p1, p2) { return QuadraticBezierP0(t, p0) + QuadraticBezierP1(t, p1) + QuadraticBezierP2(t, p2); } function CubicBezierP0(t, p) { const k = 1 - t; return k * k * k * p; } function CubicBezierP1(t, p) { const k = 1 - t; return 3 * k * k * t * p; } function CubicBezierP2(t, p) { return 3 * (1 - t) * t * t * p; } function CubicBezierP3(t, p) { return t * t * t * p; } function CubicBezier(t, p0, p1, p2, p3) { return CubicBezierP0(t, p0) + CubicBezierP1(t, p1) + CubicBezierP2(t, p2) + CubicBezierP3(t, p3); } var CubicBezierCurve = class extends Curve { constructor(v0 = new Vector22(), v1 = new Vector22(), v2 = new Vector22(), v3 = new Vector22()) { super(); this.isCubicBezierCurve = true; this.type = "CubicBezierCurve"; this.v0 = v0; this.v1 = v1; this.v2 = v2; this.v3 = v3; } getPoint(t, optionalTarget = new Vector22()) { const point = optionalTarget; const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3; point.set( CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y) ); return point; } copy(source) { super.copy(source); this.v0.copy(source.v0); this.v1.copy(source.v1); this.v2.copy(source.v2); this.v3.copy(source.v3); return this; } toJSON() { const data = super.toJSON(); data.v0 = this.v0.toArray(); data.v1 = this.v1.toArray(); data.v2 = this.v2.toArray(); data.v3 = this.v3.toArray(); return data; } fromJSON(json) { super.fromJSON(json); this.v0.fromArray(json.v0); this.v1.fromArray(json.v1); this.v2.fromArray(json.v2); this.v3.fromArray(json.v3); return this; } }; var CubicBezierCurve3 = class extends Curve { constructor(v0 = new Vector32(), v1 = new Vector32(), v2 = new Vector32(), v3 = new Vector32()) { super(); this.isCubicBezierCurve3 = true; this.type = "CubicBezierCurve3"; this.v0 = v0; this.v1 = v1; this.v2 = v2; this.v3 = v3; } getPoint(t, optionalTarget = new Vector32()) { const point = optionalTarget; const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3; point.set( CubicBezier(t, v0.x, v1.x, v2.x, v3.x), CubicBezier(t, v0.y, v1.y, v2.y, v3.y), CubicBezier(t, v0.z, v1.z, v2.z, v3.z) ); return point; } copy(source) { super.copy(source); this.v0.copy(source.v0); this.v1.copy(source.v1); this.v2.copy(source.v2); this.v3.copy(source.v3); return this; } toJSON() { const data = super.toJSON(); data.v0 = this.v0.toArray(); data.v1 = this.v1.toArray(); data.v2 = this.v2.toArray(); data.v3 = this.v3.toArray(); return data; } fromJSON(json) { super.fromJSON(json); this.v0.fromArray(json.v0); this.v1.fromArray(json.v1); this.v2.fromArray(json.v2); this.v3.fromArray(json.v3); return this; } }; var LineCurve = class extends Curve { constructor(v1 = new Vector22(), v2 = new Vector22()) { super(); this.isLineCurve = true; this.type = "LineCurve"; this.v1 = v1; this.v2 = v2; } getPoint(t, optionalTarget = new Vector22()) { const point = optionalTarget; if (t === 1) { point.copy(this.v2); } else { point.copy(this.v2).sub(this.v1); point.multiplyScalar(t).add(this.v1); } return point; } // Line curve is linear, so we can overwrite default getPointAt getPointAt(u, optionalTarget) { return this.getPoint(u, optionalTarget); } getTangent(t, optionalTarget = new Vector22()) { return optionalTarget.subVectors(this.v2, this.v1).normalize(); } getTangentAt(u, optionalTarget) { return this.getTangent(u, optionalTarget); } copy(source) { super.copy(source); this.v1.copy(source.v1); this.v2.copy(source.v2); return this; } toJSON() { const data = super.toJSON(); data.v1 = this.v1.toArray(); data.v2 = this.v2.toArray(); return data; } fromJSON(json) { super.fromJSON(json); this.v1.fromArray(json.v1); this.v2.fromArray(json.v2); return this; } }; var LineCurve3 = class extends Curve { constructor(v1 = new Vector32(), v2 = new Vector32()) { super(); this.isLineCurve3 = true; this.type = "LineCurve3"; this.v1 = v1; this.v2 = v2; } getPoint(t, optionalTarget = new Vector32()) { const point = optionalTarget; if (t === 1) { point.copy(this.v2); } else { point.copy(this.v2).sub(this.v1); point.multiplyScalar(t).add(this.v1); } return point; } // Line curve is linear, so we can overwrite default getPointAt getPointAt(u, optionalTarget) { return this.getPoint(u, optionalTarget); } getTangent(t, optionalTarget = new Vector32()) { return optionalTarget.subVectors(this.v2, this.v1).normalize(); } getTangentAt(u, optionalTarget) { return this.getTangent(u, optionalTarget); } copy(source) { super.copy(source); this.v1.copy(source.v1); this.v2.copy(source.v2); return this; } toJSON() { const data = super.toJSON(); data.v1 = this.v1.toArray(); data.v2 = this.v2.toArray(); return data; } fromJSON(json) { super.fromJSON(json); this.v1.fromArray(json.v1); this.v2.fromArray(json.v2); return this; } }; var QuadraticBezierCurve = class extends Curve { constructor(v0 = new Vector22(), v1 = new Vector22(), v2 = new Vector22()) { super(); this.isQuadraticBezierCurve = true; this.type = "QuadraticBezierCurve"; this.v0 = v0; this.v1 = v1; this.v2 = v2; } getPoint(t, optionalTarget = new Vector22()) { const point = optionalTarget; const v0 = this.v0, v1 = this.v1, v2 = this.v2; point.set( QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y) ); return point; } copy(source) { super.copy(source); this.v0.copy(source.v0); this.v1.copy(source.v1); this.v2.copy(source.v2); return this; } toJSON() { const data = super.toJSON(); data.v0 = this.v0.toArray(); data.v1 = this.v1.toArray(); data.v2 = this.v2.toArray(); return data; } fromJSON(json) { super.fromJSON(json); this.v0.fromArray(json.v0); this.v1.fromArray(json.v1); this.v2.fromArray(json.v2); return this; } }; var QuadraticBezierCurve3 = class extends Curve { constructor(v0 = new Vector32(), v1 = new Vector32(), v2 = new Vector32()) { super(); this.isQuadraticBezierCurve3 = true; this.type = "QuadraticBezierCurve3"; this.v0 = v0; this.v1 = v1; this.v2 = v2; } getPoint(t, optionalTarget = new Vector32()) { const point = optionalTarget; const v0 = this.v0, v1 = this.v1, v2 = this.v2; point.set( QuadraticBezier(t, v0.x, v1.x, v2.x), QuadraticBezier(t, v0.y, v1.y, v2.y), QuadraticBezier(t, v0.z, v1.z, v2.z) ); return point; } copy(source) { super.copy(source); this.v0.copy(source.v0); this.v1.copy(source.v1); this.v2.copy(source.v2); return this; } toJSON() { const data = super.toJSON(); data.v0 = this.v0.toArray(); data.v1 = this.v1.toArray(); data.v2 = this.v2.toArray(); return data; } fromJSON(json) { super.fromJSON(json); this.v0.fromArray(json.v0); this.v1.fromArray(json.v1); this.v2.fromArray(json.v2); return this; } }; var SplineCurve = class extends Curve { constructor(points = []) { super(); this.isSplineCurve = true; this.type = "SplineCurve"; this.points = points; } getPoint(t, optionalTarget = new Vector22()) { const point = optionalTarget; const points = this.points; const p = (points.length - 1) * t; const intPoint = Math.floor(p); const weight = p - intPoint; const p0 = points[intPoint === 0 ? intPoint : intPoint - 1]; const p1 = points[intPoint]; const p2 = points[intPoint > points.length - 2 ? points.length - 1 : intPoint + 1]; const p3 = points[intPoint > points.length - 3 ? points.length - 1 : intPoint + 2]; point.set( CatmullRom(weight, p0.x, p1.x, p2.x, p3.x), CatmullRom(weight, p0.y, p1.y, p2.y, p3.y) ); return point; } copy(source) { super.copy(source); this.points = []; for (let i = 0, l = source.points.length; i < l; i++) { const point = source.points[i]; this.points.push(point.clone()); } return this; } toJSON() { const data = super.toJSON(); data.points = []; for (let i = 0, l = this.points.length; i < l; i++) { const point = this.points[i]; data.points.push(point.toArray()); } return data; } fromJSON(json) { super.fromJSON(json); this.points = []; for (let i = 0, l = json.points.length; i < l; i++) { const point = json.points[i]; this.points.push(new Vector22().fromArray(point)); } return this; } }; var Curves = /* @__PURE__ */ Object.freeze({ __proto__: null, ArcCurve, CatmullRomCurve3, CubicBezierCurve, CubicBezierCurve3, EllipseCurve, LineCurve, LineCurve3, QuadraticBezierCurve, QuadraticBezierCurve3, SplineCurve }); var CylinderGeometry = class extends BufferGeometry2 { constructor(radiusTop = 1, radiusBottom = 1, height = 1, radialSegments = 32, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2) { super(); this.type = "CylinderGeometry"; this.parameters = { radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength }; const scope = this; radialSegments = Math.floor(radialSegments); heightSegments = Math.floor(heightSegments); const indices = []; const vertices = []; const normals = []; const uvs = []; let index6 = 0; const indexArray = []; const halfHeight = height / 2; let groupStart = 0; generateTorso(); if (openEnded === false) { if (radiusTop > 0) generateCap(true); if (radiusBottom > 0) generateCap(false); } this.setIndex(indices); this.setAttribute("position", new Float32BufferAttribute2(vertices, 3)); this.setAttribute("normal", new Float32BufferAttribute2(normals, 3)); this.setAttribute("uv", new Float32BufferAttribute2(uvs, 2)); function generateTorso() { const normal = new Vector32(); const vertex3 = new Vector32(); let groupCount = 0; const slope = (radiusBottom - radiusTop) / height; for (let y3 = 0; y3 <= heightSegments; y3++) { const indexRow = []; const v = y3 / heightSegments; const radius = v * (radiusBottom - radiusTop) + radiusTop; for (let x3 = 0; x3 <= radialSegments; x3++) { const u = x3 / radialSegments; const theta = u * thetaLength + thetaStart; const sinTheta = Math.sin(theta); const cosTheta = Math.cos(theta); vertex3.x = radius * sinTheta; vertex3.y = -v * height + halfHeight; vertex3.z = radius * cosTheta; vertices.push(vertex3.x, vertex3.y, vertex3.z); normal.set(sinTheta, slope, cosTheta).normalize(); normals.push(normal.x, normal.y, normal.z); uvs.push(u, 1 - v); indexRow.push(index6++); } indexArray.push(indexRow); } for (let x3 = 0; x3 < radialSegments; x3++) { for (let y3 = 0; y3 < heightSegments; y3++) { const a2 = indexArray[y3][x3]; const b = indexArray[y3 + 1][x3]; const c2 = indexArray[y3 + 1][x3 + 1]; const d = indexArray[y3][x3 + 1]; indices.push(a2, b, d); indices.push(b, c2, d); groupCount += 6; } } scope.addGroup(groupStart, groupCount, 0); groupStart += groupCount; } function generateCap(top) { const centerIndexStart = index6; const uv = new Vector22(); const vertex3 = new Vector32(); let groupCount = 0; const radius = top === true ? radiusTop : radiusBottom; const sign = top === true ? 1 : -1; for (let x3 = 1; x3 <= radialSegments; x3++) { vertices.push(0, halfHeight * sign, 0); normals.push(0, sign, 0); uvs.push(0.5, 0.5); index6++; } const centerIndexEnd = index6; for (let x3 = 0; x3 <= radialSegments; x3++) { const u = x3 / radialSegments; const theta = u * thetaLength + thetaStart; const cosTheta = Math.cos(theta); const sinTheta = Math.sin(theta); vertex3.x = radius * sinTheta; vertex3.y = halfHeight * sign; vertex3.z = radius * cosTheta; vertices.push(vertex3.x, vertex3.y, vertex3.z); normals.push(0, sign, 0); uv.x = cosTheta * 0.5 + 0.5; uv.y = sinTheta * 0.5 * sign + 0.5; uvs.push(uv.x, uv.y); index6++; } for (let x3 = 0; x3 < radialSegments; x3++) { const c2 = centerIndexStart + x3; const i = centerIndexEnd + x3; if (top === true) { indices.push(i, i + 1, c2); } else { indices.push(i + 1, i, c2); } groupCount += 3; } scope.addGroup(groupStart, groupCount, top === true ? 1 : 2); groupStart += groupCount; } } copy(source) { super.copy(source); this.parameters = Object.assign({}, source.parameters); return this; } static fromJSON(data) { return new CylinderGeometry(data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength); } }; var ConeGeometry = class extends CylinderGeometry { constructor(radius = 1, height = 1, radialSegments = 32, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2) { super(0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength); this.type = "ConeGeometry"; this.parameters = { radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength }; } static fromJSON(data) { return new ConeGeometry(data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength); } }; var SphereGeometry = class extends BufferGeometry2 { constructor(radius = 1, widthSegments = 32, heightSegments = 16, phiStart = 0, phiLength = Math.PI * 2, thetaStart = 0, thetaLength = Math.PI) { super(); this.type = "SphereGeometry"; this.parameters = { radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength }; widthSegments = Math.max(3, Math.floor(widthSegments)); heightSegments = Math.max(2, Math.floor(heightSegments)); const thetaEnd = Math.min(thetaStart + thetaLength, Math.PI); let index6 = 0; const grid = []; const vertex3 = new Vector32(); const normal = new Vector32(); const indices = []; const vertices = []; const normals = []; const uvs = []; for (let iy = 0; iy <= heightSegments; iy++) { const verticesRow = []; const v = iy / heightSegments; let uOffset = 0; if (iy === 0 && thetaStart === 0) { uOffset = 0.5 / widthSegments; } else if (iy === heightSegments && thetaEnd === Math.PI) { uOffset = -0.5 / widthSegments; } for (let ix = 0; ix <= widthSegments; ix++) { const u = ix / widthSegments; vertex3.x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength); vertex3.y = radius * Math.cos(thetaStart + v * thetaLength); vertex3.z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength); vertices.push(vertex3.x, vertex3.y, vertex3.z); normal.copy(vertex3).normalize(); normals.push(normal.x, normal.y, normal.z); uvs.push(u + uOffset, 1 - v); verticesRow.push(index6++); } grid.push(verticesRow); } for (let iy = 0; iy < heightSegments; iy++) { for (let ix = 0; ix < widthSegments; ix++) { const a2 = grid[iy][ix + 1]; const b = grid[iy][ix]; const c2 = grid[iy + 1][ix]; const d = grid[iy + 1][ix + 1]; if (iy !== 0 || thetaStart > 0) indices.push(a2, b, d); if (iy !== heightSegments - 1 || thetaEnd < Math.PI) indices.push(b, c2, d); } } this.setIndex(indices); this.setAttribute("position", new Float32BufferAttribute2(vertices, 3)); this.setAttribute("normal", new Float32BufferAttribute2(normals, 3)); this.setAttribute("uv", new Float32BufferAttribute2(uvs, 2)); } copy(source) { super.copy(source); this.parameters = Object.assign({}, source.parameters); return this; } static fromJSON(data) { return new SphereGeometry(data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength); } }; var TubeGeometry = class extends BufferGeometry2 { constructor(path = new QuadraticBezierCurve3(new Vector32(-1, -1, 0), new Vector32(-1, 1, 0), new Vector32(1, 1, 0)), tubularSegments = 64, radius = 1, radialSegments = 8, closed = false) { super(); this.type = "TubeGeometry"; this.parameters = { path, tubularSegments, radius, radialSegments, closed }; const frames = path.computeFrenetFrames(tubularSegments, closed); this.tangents = frames.tangents; this.normals = frames.normals; this.binormals = frames.binormals; const vertex3 = new Vector32(); const normal = new Vector32(); const uv = new Vector22(); let P = new Vector32(); const vertices = []; const normals = []; const uvs = []; const indices = []; generateBufferData(); this.setIndex(indices); this.setAttribute("position", new Float32BufferAttribute2(vertices, 3)); this.setAttribute("normal", new Float32BufferAttribute2(normals, 3)); this.setAttribute("uv", new Float32BufferAttribute2(uvs, 2)); function generateBufferData() { for (let i = 0; i < tubularSegments; i++) { generateSegment(i); } generateSegment(closed === false ? tubularSegments : 0); generateUVs(); generateIndices(); } function generateSegment(i) { P = path.getPointAt(i / tubularSegments, P); const N = frames.normals[i]; const B = frames.binormals[i]; for (let j = 0; j <= radialSegments; j++) { const v = j / radialSegments * Math.PI * 2; const sin = Math.sin(v); const cos = -Math.cos(v); normal.x = cos * N.x + sin * B.x; normal.y = cos * N.y + sin * B.y; normal.z = cos * N.z + sin * B.z; normal.normalize(); normals.push(normal.x, normal.y, normal.z); vertex3.x = P.x + radius * normal.x; vertex3.y = P.y + radius * normal.y; vertex3.z = P.z + radius * normal.z; vertices.push(vertex3.x, vertex3.y, vertex3.z); } } function generateIndices() { for (let j = 1; j <= tubularSegments; j++) { for (let i = 1; i <= radialSegments; i++) { const a2 = (radialSegments + 1) * (j - 1) + (i - 1); const b = (radialSegments + 1) * j + (i - 1); const c2 = (radialSegments + 1) * j + i; const d = (radialSegments + 1) * (j - 1) + i; indices.push(a2, b, d); indices.push(b, c2, d); } } } function generateUVs() { for (let i = 0; i <= tubularSegments; i++) { for (let j = 0; j <= radialSegments; j++) { uv.x = i / tubularSegments; uv.y = j / radialSegments; uvs.push(uv.x, uv.y); } } } } copy(source) { super.copy(source); this.parameters = Object.assign({}, source.parameters); return this; } toJSON() { const data = super.toJSON(); data.path = this.parameters.path.toJSON(); return data; } static fromJSON(data) { return new TubeGeometry( new Curves[data.path.type]().fromJSON(data.path), data.tubularSegments, data.radius, data.radialSegments, data.closed ); } }; var MeshLambertMaterial = class extends Material2 { constructor(parameters) { super(); this.isMeshLambertMaterial = true; this.type = "MeshLambertMaterial"; this.color = new Color2(16777215); this.map = null; this.lightMap = null; this.lightMapIntensity = 1; this.aoMap = null; this.aoMapIntensity = 1; this.emissive = new Color2(0); this.emissiveIntensity = 1; this.emissiveMap = null; this.bumpMap = null; this.bumpScale = 1; this.normalMap = null; this.normalMapType = TangentSpaceNormalMap2; this.normalScale = new Vector22(1, 1); this.displacementMap = null; this.displacementScale = 1; this.displacementBias = 0; this.specularMap = null; this.alphaMap = null; this.envMap = null; this.combine = MultiplyOperation2; this.reflectivity = 1; this.refractionRatio = 0.98; this.wireframe = false; this.wireframeLinewidth = 1; this.wireframeLinecap = "round"; this.wireframeLinejoin = "round"; this.flatShading = false; this.fog = true; this.setValues(parameters); } copy(source) { super.copy(source); this.color.copy(source.color); this.map = source.map; this.lightMap = source.lightMap; this.lightMapIntensity = source.lightMapIntensity; this.aoMap = source.aoMap; this.aoMapIntensity = source.aoMapIntensity; this.emissive.copy(source.emissive); this.emissiveMap = source.emissiveMap; this.emissiveIntensity = source.emissiveIntensity; this.bumpMap = source.bumpMap; this.bumpScale = source.bumpScale; this.normalMap = source.normalMap; this.normalMapType = source.normalMapType; this.normalScale.copy(source.normalScale); this.displacementMap = source.displacementMap; this.displacementScale = source.displacementScale; this.displacementBias = source.displacementBias; this.specularMap = source.specularMap; this.alphaMap = source.alphaMap; this.envMap = source.envMap; this.combine = source.combine; this.reflectivity = source.reflectivity; this.refractionRatio = source.refractionRatio; this.wireframe = source.wireframe; this.wireframeLinewidth = source.wireframeLinewidth; this.wireframeLinecap = source.wireframeLinecap; this.wireframeLinejoin = source.wireframeLinejoin; this.flatShading = source.flatShading; this.fog = source.fog; return this; } }; function convertArray2(array, type, forceClone) { if (!array || // let 'undefined' and 'null' pass !forceClone && array.constructor === type) return array; if (typeof type.BYTES_PER_ELEMENT === "number") { return new type(array); } return Array.prototype.slice.call(array); } function isTypedArray2(object) { return ArrayBuffer.isView(object) && !(object instanceof DataView); } var Interpolant2 = class { constructor(parameterPositions, sampleValues, sampleSize, resultBuffer) { this.parameterPositions = parameterPositions; this._cachedIndex = 0; this.resultBuffer = resultBuffer !== void 0 ? resultBuffer : new sampleValues.constructor(sampleSize); this.sampleValues = sampleValues; this.valueSize = sampleSize; this.settings = null; this.DefaultSettings_ = {}; } evaluate(t) { const pp = this.parameterPositions; let i1 = this._cachedIndex, t1 = pp[i1], t0 = pp[i1 - 1]; validate_interval: { seek: { let right; linear_scan: { forward_scan: if (!(t < t1)) { for (let giveUpAt = i1 + 2; ; ) { if (t1 === void 0) { if (t < t0) break forward_scan; i1 = pp.length; this._cachedIndex = i1; return this.copySampleValue_(i1 - 1); } if (i1 === giveUpAt) break; t0 = t1; t1 = pp[++i1]; if (t < t1) { break seek; } } right = pp.length; break linear_scan; } if (!(t >= t0)) { const t1global = pp[1]; if (t < t1global) { i1 = 2; t0 = t1global; } for (let giveUpAt = i1 - 2; ; ) { if (t0 === void 0) { this._cachedIndex = 0; return this.copySampleValue_(0); } if (i1 === giveUpAt) break; t1 = t0; t0 = pp[--i1 - 1]; if (t >= t0) { break seek; } } right = i1; i1 = 0; break linear_scan; } break validate_interval; } while (i1 < right) { const mid = i1 + right >>> 1; if (t < pp[mid]) { right = mid; } else { i1 = mid + 1; } } t1 = pp[i1]; t0 = pp[i1 - 1]; if (t0 === void 0) { this._cachedIndex = 0; return this.copySampleValue_(0); } if (t1 === void 0) { i1 = pp.length; this._cachedIndex = i1; return this.copySampleValue_(i1 - 1); } } this._cachedIndex = i1; this.intervalChanged_(i1, t0, t1); } return this.interpolate_(i1, t0, t, t1); } getSettings_() { return this.settings || this.DefaultSettings_; } copySampleValue_(index6) { const result = this.resultBuffer, values = this.sampleValues, stride = this.valueSize, offset = index6 * stride; for (let i = 0; i !== stride; ++i) { result[i] = values[offset + i]; } return result; } // Template methods for derived classes: interpolate_() { throw new Error("call to abstract method"); } intervalChanged_() { } }; var CubicInterpolant2 = class extends Interpolant2 { constructor(parameterPositions, sampleValues, sampleSize, resultBuffer) { super(parameterPositions, sampleValues, sampleSize, resultBuffer); this._weightPrev = -0; this._offsetPrev = -0; this._weightNext = -0; this._offsetNext = -0; this.DefaultSettings_ = { endingStart: ZeroCurvatureEnding2, endingEnd: ZeroCurvatureEnding2 }; } intervalChanged_(i1, t0, t1) { const pp = this.parameterPositions; let iPrev = i1 - 2, iNext = i1 + 1, tPrev = pp[iPrev], tNext = pp[iNext]; if (tPrev === void 0) { switch (this.getSettings_().endingStart) { case ZeroSlopeEnding2: iPrev = i1; tPrev = 2 * t0 - t1; break; case WrapAroundEnding2: iPrev = pp.length - 2; tPrev = t0 + pp[iPrev] - pp[iPrev + 1]; break; default: iPrev = i1; tPrev = t1; } } if (tNext === void 0) { switch (this.getSettings_().endingEnd) { case ZeroSlopeEnding2: iNext = i1; tNext = 2 * t1 - t0; break; case WrapAroundEnding2: iNext = 1; tNext = t1 + pp[1] - pp[0]; break; default: iNext = i1 - 1; tNext = t0; } } const halfDt = (t1 - t0) * 0.5, stride = this.valueSize; this._weightPrev = halfDt / (t0 - tPrev); this._weightNext = halfDt / (tNext - t1); this._offsetPrev = iPrev * stride; this._offsetNext = iNext * stride; } interpolate_(i1, t0, t, t1) { const result = this.resultBuffer, values = this.sampleValues, stride = this.valueSize, o1 = i1 * stride, o0 = o1 - stride, oP = this._offsetPrev, oN = this._offsetNext, wP = this._weightPrev, wN = this._weightNext, p = (t - t0) / (t1 - t0), pp = p * p, ppp = pp * p; const sP = -wP * ppp + 2 * wP * pp - wP * p; const s0 = (1 + wP) * ppp + (-1.5 - 2 * wP) * pp + (-0.5 + wP) * p + 1; const s1 = (-1 - wN) * ppp + (1.5 + wN) * pp + 0.5 * p; const sN = wN * ppp - wN * pp; for (let i = 0; i !== stride; ++i) { result[i] = sP * values[oP + i] + s0 * values[o0 + i] + s1 * values[o1 + i] + sN * values[oN + i]; } return result; } }; var LinearInterpolant2 = class extends Interpolant2 { constructor(parameterPositions, sampleValues, sampleSize, resultBuffer) { super(parameterPositions, sampleValues, sampleSize, resultBuffer); } interpolate_(i1, t0, t, t1) { const result = this.resultBuffer, values = this.sampleValues, stride = this.valueSize, offset1 = i1 * stride, offset0 = offset1 - stride, weight1 = (t - t0) / (t1 - t0), weight0 = 1 - weight1; for (let i = 0; i !== stride; ++i) { result[i] = values[offset0 + i] * weight0 + values[offset1 + i] * weight1; } return result; } }; var DiscreteInterpolant2 = class extends Interpolant2 { constructor(parameterPositions, sampleValues, sampleSize, resultBuffer) { super(parameterPositions, sampleValues, sampleSize, resultBuffer); } interpolate_(i1) { return this.copySampleValue_(i1 - 1); } }; var KeyframeTrack2 = class { constructor(name, times, values, interpolation) { if (name === void 0) throw new Error("THREE.KeyframeTrack: track name is undefined"); if (times === void 0 || times.length === 0) throw new Error("THREE.KeyframeTrack: no keyframes in track named " + name); this.name = name; this.times = convertArray2(times, this.TimeBufferType); this.values = convertArray2(values, this.ValueBufferType); this.setInterpolation(interpolation || this.DefaultInterpolation); } // Serialization (in static context, because of constructor invocation // and automatic invocation of .toJSON): static toJSON(track) { const trackType = track.constructor; let json; if (trackType.toJSON !== this.toJSON) { json = trackType.toJSON(track); } else { json = { "name": track.name, "times": convertArray2(track.times, Array), "values": convertArray2(track.values, Array) }; const interpolation = track.getInterpolation(); if (interpolation !== track.DefaultInterpolation) { json.interpolation = interpolation; } } json.type = track.ValueTypeName; return json; } InterpolantFactoryMethodDiscrete(result) { return new DiscreteInterpolant2(this.times, this.values, this.getValueSize(), result); } InterpolantFactoryMethodLinear(result) { return new LinearInterpolant2(this.times, this.values, this.getValueSize(), result); } InterpolantFactoryMethodSmooth(result) { return new CubicInterpolant2(this.times, this.values, this.getValueSize(), result); } setInterpolation(interpolation) { let factoryMethod; switch (interpolation) { case InterpolateDiscrete2: factoryMethod = this.InterpolantFactoryMethodDiscrete; break; case InterpolateLinear2: factoryMethod = this.InterpolantFactoryMethodLinear; break; case InterpolateSmooth2: factoryMethod = this.InterpolantFactoryMethodSmooth; break; } if (factoryMethod === void 0) { const message = "unsupported interpolation for " + this.ValueTypeName + " keyframe track named " + this.name; if (this.createInterpolant === void 0) { if (interpolation !== this.DefaultInterpolation) { this.setInterpolation(this.DefaultInterpolation); } else { throw new Error(message); } } console.warn("THREE.KeyframeTrack:", message); return this; } this.createInterpolant = factoryMethod; return this; } getInterpolation() { switch (this.createInterpolant) { case this.InterpolantFactoryMethodDiscrete: return InterpolateDiscrete2; case this.InterpolantFactoryMethodLinear: return InterpolateLinear2; case this.InterpolantFactoryMethodSmooth: return InterpolateSmooth2; } } getValueSize() { return this.values.length / this.times.length; } // move all keyframes either forwards or backwards in time shift(timeOffset) { if (timeOffset !== 0) { const times = this.times; for (let i = 0, n = times.length; i !== n; ++i) { times[i] += timeOffset; } } return this; } // scale all keyframe times by a factor (useful for frame <-> seconds conversions) scale(timeScale) { if (timeScale !== 1) { const times = this.times; for (let i = 0, n = times.length; i !== n; ++i) { times[i] *= timeScale; } } return this; } // removes keyframes before and after animation without changing any values within the range [startTime, endTime]. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values trim(startTime, endTime) { const times = this.times, nKeys = times.length; let from = 0, to = nKeys - 1; while (from !== nKeys && times[from] < startTime) { ++from; } while (to !== -1 && times[to] > endTime) { --to; } ++to; if (from !== 0 || to !== nKeys) { if (from >= to) { to = Math.max(to, 1); from = to - 1; } const stride = this.getValueSize(); this.times = times.slice(from, to); this.values = this.values.slice(from * stride, to * stride); } return this; } // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable validate() { let valid = true; const valueSize = this.getValueSize(); if (valueSize - Math.floor(valueSize) !== 0) { console.error("THREE.KeyframeTrack: Invalid value size in track.", this); valid = false; } const times = this.times, values = this.values, nKeys = times.length; if (nKeys === 0) { console.error("THREE.KeyframeTrack: Track is empty.", this); valid = false; } let prevTime = null; for (let i = 0; i !== nKeys; i++) { const currTime = times[i]; if (typeof currTime === "number" && isNaN(currTime)) { console.error("THREE.KeyframeTrack: Time is not a valid number.", this, i, currTime); valid = false; break; } if (prevTime !== null && prevTime > currTime) { console.error("THREE.KeyframeTrack: Out of order keys.", this, i, currTime, prevTime); valid = false; break; } prevTime = currTime; } if (values !== void 0) { if (isTypedArray2(values)) { for (let i = 0, n = values.length; i !== n; ++i) { const value = values[i]; if (isNaN(value)) { console.error("THREE.KeyframeTrack: Value is not a valid number.", this, i, value); valid = false; break; } } } } return valid; } // removes equivalent sequential keys as common in morph target sequences // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0) optimize() { const times = this.times.slice(), values = this.values.slice(), stride = this.getValueSize(), smoothInterpolation = this.getInterpolation() === InterpolateSmooth2, lastIndex = times.length - 1; let writeIndex = 1; for (let i = 1; i < lastIndex; ++i) { let keep = false; const time = times[i]; const timeNext = times[i + 1]; if (time !== timeNext && (i !== 1 || time !== times[0])) { if (!smoothInterpolation) { const offset = i * stride, offsetP = offset - stride, offsetN = offset + stride; for (let j = 0; j !== stride; ++j) { const value = values[offset + j]; if (value !== values[offsetP + j] || value !== values[offsetN + j]) { keep = true; break; } } } else { keep = true; } } if (keep) { if (i !== writeIndex) { times[writeIndex] = times[i]; const readOffset = i * stride, writeOffset = writeIndex * stride; for (let j = 0; j !== stride; ++j) { values[writeOffset + j] = values[readOffset + j]; } } ++writeIndex; } } if (lastIndex > 0) { times[writeIndex] = times[lastIndex]; for (let readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++j) { values[writeOffset + j] = values[readOffset + j]; } ++writeIndex; } if (writeIndex !== times.length) { this.times = times.slice(0, writeIndex); this.values = values.slice(0, writeIndex * stride); } else { this.times = times; this.values = values; } return this; } clone() { const times = this.times.slice(); const values = this.values.slice(); const TypedKeyframeTrack = this.constructor; const track = new TypedKeyframeTrack(this.name, times, values); track.createInterpolant = this.createInterpolant; return track; } }; KeyframeTrack2.prototype.TimeBufferType = Float32Array; KeyframeTrack2.prototype.ValueBufferType = Float32Array; KeyframeTrack2.prototype.DefaultInterpolation = InterpolateLinear2; var BooleanKeyframeTrack2 = class extends KeyframeTrack2 { }; BooleanKeyframeTrack2.prototype.ValueTypeName = "bool"; BooleanKeyframeTrack2.prototype.ValueBufferType = Array; BooleanKeyframeTrack2.prototype.DefaultInterpolation = InterpolateDiscrete2; BooleanKeyframeTrack2.prototype.InterpolantFactoryMethodLinear = void 0; BooleanKeyframeTrack2.prototype.InterpolantFactoryMethodSmooth = void 0; var ColorKeyframeTrack2 = class extends KeyframeTrack2 { }; ColorKeyframeTrack2.prototype.ValueTypeName = "color"; var NumberKeyframeTrack2 = class extends KeyframeTrack2 { }; NumberKeyframeTrack2.prototype.ValueTypeName = "number"; var QuaternionLinearInterpolant2 = class extends Interpolant2 { constructor(parameterPositions, sampleValues, sampleSize, resultBuffer) { super(parameterPositions, sampleValues, sampleSize, resultBuffer); } interpolate_(i1, t0, t, t1) { const result = this.resultBuffer, values = this.sampleValues, stride = this.valueSize, alpha = (t - t0) / (t1 - t0); let offset = i1 * stride; for (let end = offset + stride; offset !== end; offset += 4) { Quaternion2.slerpFlat(result, 0, values, offset - stride, values, offset, alpha); } return result; } }; var QuaternionKeyframeTrack2 = class extends KeyframeTrack2 { InterpolantFactoryMethodLinear(result) { return new QuaternionLinearInterpolant2(this.times, this.values, this.getValueSize(), result); } }; QuaternionKeyframeTrack2.prototype.ValueTypeName = "quaternion"; QuaternionKeyframeTrack2.prototype.DefaultInterpolation = InterpolateLinear2; QuaternionKeyframeTrack2.prototype.InterpolantFactoryMethodSmooth = void 0; var StringKeyframeTrack2 = class extends KeyframeTrack2 { }; StringKeyframeTrack2.prototype.ValueTypeName = "string"; StringKeyframeTrack2.prototype.ValueBufferType = Array; StringKeyframeTrack2.prototype.DefaultInterpolation = InterpolateDiscrete2; StringKeyframeTrack2.prototype.InterpolantFactoryMethodLinear = void 0; StringKeyframeTrack2.prototype.InterpolantFactoryMethodSmooth = void 0; var VectorKeyframeTrack2 = class extends KeyframeTrack2 { }; VectorKeyframeTrack2.prototype.ValueTypeName = "vector"; var Cache = { enabled: false, files: {}, add: function(key, file) { if (this.enabled === false) return; this.files[key] = file; }, get: function(key) { if (this.enabled === false) return; return this.files[key]; }, remove: function(key) { delete this.files[key]; }, clear: function() { this.files = {}; } }; var LoadingManager2 = class { constructor(onLoad, onProgress, onError) { const scope = this; let isLoading = false; let itemsLoaded = 0; let itemsTotal = 0; let urlModifier = void 0; const handlers = []; this.onStart = void 0; this.onLoad = onLoad; this.onProgress = onProgress; this.onError = onError; this.itemStart = function(url) { itemsTotal++; if (isLoading === false) { if (scope.onStart !== void 0) { scope.onStart(url, itemsLoaded, itemsTotal); } } isLoading = true; }; this.itemEnd = function(url) { itemsLoaded++; if (scope.onProgress !== void 0) { scope.onProgress(url, itemsLoaded, itemsTotal); } if (itemsLoaded === itemsTotal) { isLoading = false; if (scope.onLoad !== void 0) { scope.onLoad(); } } }; this.itemError = function(url) { if (scope.onError !== void 0) { scope.onError(url); } }; this.resolveURL = function(url) { if (urlModifier) { return urlModifier(url); } return url; }; this.setURLModifier = function(transform) { urlModifier = transform; return this; }; this.addHandler = function(regex, loader) { handlers.push(regex, loader); return this; }; this.removeHandler = function(regex) { const index6 = handlers.indexOf(regex); if (index6 !== -1) { handlers.splice(index6, 2); } return this; }; this.getHandler = function(file) { for (let i = 0, l = handlers.length; i < l; i += 2) { const regex = handlers[i]; const loader = handlers[i + 1]; if (regex.global) regex.lastIndex = 0; if (regex.test(file)) { return loader; } } return null; }; } }; var DefaultLoadingManager2 = /* @__PURE__ */ new LoadingManager2(); var Loader2 = class { constructor(manager) { this.manager = manager !== void 0 ? manager : DefaultLoadingManager2; this.crossOrigin = "anonymous"; this.withCredentials = false; this.path = ""; this.resourcePath = ""; this.requestHeader = {}; } load() { } loadAsync(url, onProgress) { const scope = this; return new Promise(function(resolve, reject) { scope.load(url, resolve, onProgress, reject); }); } parse() { } setCrossOrigin(crossOrigin) { this.crossOrigin = crossOrigin; return this; } setWithCredentials(value) { this.withCredentials = value; return this; } setPath(path) { this.path = path; return this; } setResourcePath(resourcePath) { this.resourcePath = resourcePath; return this; } setRequestHeader(requestHeader) { this.requestHeader = requestHeader; return this; } }; Loader2.DEFAULT_MATERIAL_NAME = "__DEFAULT"; var ImageLoader = class extends Loader2 { constructor(manager) { super(manager); } load(url, onLoad, onProgress, onError) { if (this.path !== void 0) url = this.path + url; url = this.manager.resolveURL(url); const scope = this; const cached = Cache.get(url); if (cached !== void 0) { scope.manager.itemStart(url); setTimeout(function() { if (onLoad) onLoad(cached); scope.manager.itemEnd(url); }, 0); return cached; } const image = createElementNS2("img"); function onImageLoad() { removeEventListeners(); Cache.add(url, this); if (onLoad) onLoad(this); scope.manager.itemEnd(url); } function onImageError(event) { removeEventListeners(); if (onError) onError(event); scope.manager.itemError(url); scope.manager.itemEnd(url); } function removeEventListeners() { image.removeEventListener("load", onImageLoad, false); image.removeEventListener("error", onImageError, false); } image.addEventListener("load", onImageLoad, false); image.addEventListener("error", onImageError, false); if (url.slice(0, 5) !== "data:") { if (this.crossOrigin !== void 0) image.crossOrigin = this.crossOrigin; } scope.manager.itemStart(url); image.src = url; return image; } }; var TextureLoader = class extends Loader2 { constructor(manager) { super(manager); } load(url, onLoad, onProgress, onError) { const texture = new Texture2(); const loader = new ImageLoader(this.manager); loader.setCrossOrigin(this.crossOrigin); loader.setPath(this.path); loader.load(url, function(image) { texture.image = image; texture.needsUpdate = true; if (onLoad !== void 0) { onLoad(texture); } }, onProgress, onError); return texture; } }; var Clock = class { constructor(autoStart = true) { this.autoStart = autoStart; this.startTime = 0; this.oldTime = 0; this.elapsedTime = 0; this.running = false; } start() { this.startTime = now(); this.oldTime = this.startTime; this.elapsedTime = 0; this.running = true; } stop() { this.getElapsedTime(); this.running = false; this.autoStart = false; } getElapsedTime() { this.getDelta(); return this.elapsedTime; } getDelta() { let diff = 0; if (this.autoStart && !this.running) { this.start(); return 0; } if (this.running) { const newTime = now(); diff = (newTime - this.oldTime) / 1e3; this.oldTime = newTime; this.elapsedTime += diff; } return diff; } }; function now() { return (typeof performance === "undefined" ? Date : performance).now(); } var _RESERVED_CHARS_RE2 = "\\[\\]\\.:\\/"; var _reservedRe2 = new RegExp("[" + _RESERVED_CHARS_RE2 + "]", "g"); var _wordChar2 = "[^" + _RESERVED_CHARS_RE2 + "]"; var _wordCharOrDot2 = "[^" + _RESERVED_CHARS_RE2.replace("\\.", "") + "]"; var _directoryRe2 = /* @__PURE__ */ /((?:WC+[\/:])*)/.source.replace("WC", _wordChar2); var _nodeRe2 = /* @__PURE__ */ /(WCOD+)?/.source.replace("WCOD", _wordCharOrDot2); var _objectRe2 = /* @__PURE__ */ /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace("WC", _wordChar2); var _propertyRe2 = /* @__PURE__ */ /\.(WC+)(?:\[(.+)\])?/.source.replace("WC", _wordChar2); var _trackRe2 = new RegExp( "^" + _directoryRe2 + _nodeRe2 + _objectRe2 + _propertyRe2 + "$" ); var _supportedObjectNames2 = ["material", "materials", "bones", "map"]; var Composite2 = class { constructor(targetGroup, path, optionalParsedPath) { const parsedPath = optionalParsedPath || PropertyBinding2.parseTrackName(path); this._targetGroup = targetGroup; this._bindings = targetGroup.subscribe_(path, parsedPath); } getValue(array, offset) { this.bind(); const firstValidIndex = this._targetGroup.nCachedObjects_, binding = this._bindings[firstValidIndex]; if (binding !== void 0) binding.getValue(array, offset); } setValue(array, offset) { const bindings = this._bindings; for (let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) { bindings[i].setValue(array, offset); } } bind() { const bindings = this._bindings; for (let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) { bindings[i].bind(); } } unbind() { const bindings = this._bindings; for (let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++i) { bindings[i].unbind(); } } }; var PropertyBinding2 = class { constructor(rootNode, path, parsedPath) { this.path = path; this.parsedPath = parsedPath || PropertyBinding2.parseTrackName(path); this.node = PropertyBinding2.findNode(rootNode, this.parsedPath.nodeName); this.rootNode = rootNode; this.getValue = this._getValue_unbound; this.setValue = this._setValue_unbound; } static create(root2, path, parsedPath) { if (!(root2 && root2.isAnimationObjectGroup)) { return new PropertyBinding2(root2, path, parsedPath); } else { return new PropertyBinding2.Composite(root2, path, parsedPath); } } /** * Replaces spaces with underscores and removes unsupported characters from * node names, to ensure compatibility with parseTrackName(). * * @param {string} name Node name to be sanitized. * @return {string} */ static sanitizeNodeName(name) { return name.replace(/\s/g, "_").replace(_reservedRe2, ""); } static parseTrackName(trackName) { const matches = _trackRe2.exec(trackName); if (matches === null) { throw new Error("PropertyBinding: Cannot parse trackName: " + trackName); } const results = { // directoryName: matches[ 1 ], // (tschw) currently unused nodeName: matches[2], objectName: matches[3], objectIndex: matches[4], propertyName: matches[5], // required propertyIndex: matches[6] }; const lastDot = results.nodeName && results.nodeName.lastIndexOf("."); if (lastDot !== void 0 && lastDot !== -1) { const objectName = results.nodeName.substring(lastDot + 1); if (_supportedObjectNames2.indexOf(objectName) !== -1) { results.nodeName = results.nodeName.substring(0, lastDot); results.objectName = objectName; } } if (results.propertyName === null || results.propertyName.length === 0) { throw new Error("PropertyBinding: can not parse propertyName from trackName: " + trackName); } return results; } static findNode(root2, nodeName) { if (nodeName === void 0 || nodeName === "" || nodeName === "." || nodeName === -1 || nodeName === root2.name || nodeName === root2.uuid) { return root2; } if (root2.skeleton) { const bone = root2.skeleton.getBoneByName(nodeName); if (bone !== void 0) { return bone; } } if (root2.children) { const searchNodeSubtree = function(children) { for (let i = 0; i < children.length; i++) { const childNode = children[i]; if (childNode.name === nodeName || childNode.uuid === nodeName) { return childNode; } const result = searchNodeSubtree(childNode.children); if (result) return result; } return null; }; const subTreeNode = searchNodeSubtree(root2.children); if (subTreeNode) { return subTreeNode; } } return null; } // these are used to "bind" a nonexistent property _getValue_unavailable() { } _setValue_unavailable() { } // Getters _getValue_direct(buffer, offset) { buffer[offset] = this.targetObject[this.propertyName]; } _getValue_array(buffer, offset) { const source = this.resolvedProperty; for (let i = 0, n = source.length; i !== n; ++i) { buffer[offset++] = source[i]; } } _getValue_arrayElement(buffer, offset) { buffer[offset] = this.resolvedProperty[this.propertyIndex]; } _getValue_toArray(buffer, offset) { this.resolvedProperty.toArray(buffer, offset); } // Direct _setValue_direct(buffer, offset) { this.targetObject[this.propertyName] = buffer[offset]; } _setValue_direct_setNeedsUpdate(buffer, offset) { this.targetObject[this.propertyName] = buffer[offset]; this.targetObject.needsUpdate = true; } _setValue_direct_setMatrixWorldNeedsUpdate(buffer, offset) { this.targetObject[this.propertyName] = buffer[offset]; this.targetObject.matrixWorldNeedsUpdate = true; } // EntireArray _setValue_array(buffer, offset) { const dest = this.resolvedProperty; for (let i = 0, n = dest.length; i !== n; ++i) { dest[i] = buffer[offset++]; } } _setValue_array_setNeedsUpdate(buffer, offset) { const dest = this.resolvedProperty; for (let i = 0, n = dest.length; i !== n; ++i) { dest[i] = buffer[offset++]; } this.targetObject.needsUpdate = true; } _setValue_array_setMatrixWorldNeedsUpdate(buffer, offset) { const dest = this.resolvedProperty; for (let i = 0, n = dest.length; i !== n; ++i) { dest[i] = buffer[offset++]; } this.targetObject.matrixWorldNeedsUpdate = true; } // ArrayElement _setValue_arrayElement(buffer, offset) { this.resolvedProperty[this.propertyIndex] = buffer[offset]; } _setValue_arrayElement_setNeedsUpdate(buffer, offset) { this.resolvedProperty[this.propertyIndex] = buffer[offset]; this.targetObject.needsUpdate = true; } _setValue_arrayElement_setMatrixWorldNeedsUpdate(buffer, offset) { this.resolvedProperty[this.propertyIndex] = buffer[offset]; this.targetObject.matrixWorldNeedsUpdate = true; } // HasToFromArray _setValue_fromArray(buffer, offset) { this.resolvedProperty.fromArray(buffer, offset); } _setValue_fromArray_setNeedsUpdate(buffer, offset) { this.resolvedProperty.fromArray(buffer, offset); this.targetObject.needsUpdate = true; } _setValue_fromArray_setMatrixWorldNeedsUpdate(buffer, offset) { this.resolvedProperty.fromArray(buffer, offset); this.targetObject.matrixWorldNeedsUpdate = true; } _getValue_unbound(targetArray, offset) { this.bind(); this.getValue(targetArray, offset); } _setValue_unbound(sourceArray, offset) { this.bind(); this.setValue(sourceArray, offset); } // create getter / setter pair for a property in the scene graph bind() { let targetObject = this.node; const parsedPath = this.parsedPath; const objectName = parsedPath.objectName; const propertyName = parsedPath.propertyName; let propertyIndex = parsedPath.propertyIndex; if (!targetObject) { targetObject = PropertyBinding2.findNode(this.rootNode, parsedPath.nodeName); this.node = targetObject; } this.getValue = this._getValue_unavailable; this.setValue = this._setValue_unavailable; if (!targetObject) { console.warn("THREE.PropertyBinding: No target node found for track: " + this.path + "."); return; } if (objectName) { let objectIndex = parsedPath.objectIndex; switch (objectName) { case "materials": if (!targetObject.material) { console.error("THREE.PropertyBinding: Can not bind to material as node does not have a material.", this); return; } if (!targetObject.material.materials) { console.error("THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.", this); return; } targetObject = targetObject.material.materials; break; case "bones": if (!targetObject.skeleton) { console.error("THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.", this); return; } targetObject = targetObject.skeleton.bones; for (let i = 0; i < targetObject.length; i++) { if (targetObject[i].name === objectIndex) { objectIndex = i; break; } } break; case "map": if ("map" in targetObject) { targetObject = targetObject.map; break; } if (!targetObject.material) { console.error("THREE.PropertyBinding: Can not bind to material as node does not have a material.", this); return; } if (!targetObject.material.map) { console.error("THREE.PropertyBinding: Can not bind to material.map as node.material does not have a map.", this); return; } targetObject = targetObject.material.map; break; default: if (targetObject[objectName] === void 0) { console.error("THREE.PropertyBinding: Can not bind to objectName of node undefined.", this); return; } targetObject = targetObject[objectName]; } if (objectIndex !== void 0) { if (targetObject[objectIndex] === void 0) { console.error("THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.", this, targetObject); return; } targetObject = targetObject[objectIndex]; } } const nodeProperty = targetObject[propertyName]; if (nodeProperty === void 0) { const nodeName = parsedPath.nodeName; console.error("THREE.PropertyBinding: Trying to update property for track: " + nodeName + "." + propertyName + " but it wasn't found.", targetObject); return; } let versioning = this.Versioning.None; this.targetObject = targetObject; if (targetObject.needsUpdate !== void 0) { versioning = this.Versioning.NeedsUpdate; } else if (targetObject.matrixWorldNeedsUpdate !== void 0) { versioning = this.Versioning.MatrixWorldNeedsUpdate; } let bindingType = this.BindingType.Direct; if (propertyIndex !== void 0) { if (propertyName === "morphTargetInfluences") { if (!targetObject.geometry) { console.error("THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.", this); return; } if (!targetObject.geometry.morphAttributes) { console.error("THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.", this); return; } if (targetObject.morphTargetDictionary[propertyIndex] !== void 0) { propertyIndex = targetObject.morphTargetDictionary[propertyIndex]; } } bindingType = this.BindingType.ArrayElement; this.resolvedProperty = nodeProperty; this.propertyIndex = propertyIndex; } else if (nodeProperty.fromArray !== void 0 && nodeProperty.toArray !== void 0) { bindingType = this.BindingType.HasFromToArray; this.resolvedProperty = nodeProperty; } else if (Array.isArray(nodeProperty)) { bindingType = this.BindingType.EntireArray; this.resolvedProperty = nodeProperty; } else { this.propertyName = propertyName; } this.getValue = this.GetterByBindingType[bindingType]; this.setValue = this.SetterByBindingTypeAndVersioning[bindingType][versioning]; } unbind() { this.node = null; this.getValue = this._getValue_unbound; this.setValue = this._setValue_unbound; } }; PropertyBinding2.Composite = Composite2; PropertyBinding2.prototype.BindingType = { Direct: 0, EntireArray: 1, ArrayElement: 2, HasFromToArray: 3 }; PropertyBinding2.prototype.Versioning = { None: 0, NeedsUpdate: 1, MatrixWorldNeedsUpdate: 2 }; PropertyBinding2.prototype.GetterByBindingType = [ PropertyBinding2.prototype._getValue_direct, PropertyBinding2.prototype._getValue_array, PropertyBinding2.prototype._getValue_arrayElement, PropertyBinding2.prototype._getValue_toArray ]; PropertyBinding2.prototype.SetterByBindingTypeAndVersioning = [ [ // Direct PropertyBinding2.prototype._setValue_direct, PropertyBinding2.prototype._setValue_direct_setNeedsUpdate, PropertyBinding2.prototype._setValue_direct_setMatrixWorldNeedsUpdate ], [ // EntireArray PropertyBinding2.prototype._setValue_array, PropertyBinding2.prototype._setValue_array_setNeedsUpdate, PropertyBinding2.prototype._setValue_array_setMatrixWorldNeedsUpdate ], [ // ArrayElement PropertyBinding2.prototype._setValue_arrayElement, PropertyBinding2.prototype._setValue_arrayElement_setNeedsUpdate, PropertyBinding2.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate ], [ // HasToFromArray PropertyBinding2.prototype._setValue_fromArray, PropertyBinding2.prototype._setValue_fromArray_setNeedsUpdate, PropertyBinding2.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate ] ]; var _controlInterpolantsResultBuffer2 = new Float32Array(1); var Raycaster2 = class { constructor(origin3, direction, near = 0, far = Infinity) { this.ray = new Ray2(origin3, direction); this.near = near; this.far = far; this.camera = null; this.layers = new Layers2(); this.params = { Mesh: {}, Line: { threshold: 1 }, LOD: {}, Points: { threshold: 1 }, Sprite: {} }; } set(origin3, direction) { this.ray.set(origin3, direction); } setFromCamera(coords, camera3) { if (camera3.isPerspectiveCamera) { this.ray.origin.setFromMatrixPosition(camera3.matrixWorld); this.ray.direction.set(coords.x, coords.y, 0.5).unproject(camera3).sub(this.ray.origin).normalize(); this.camera = camera3; } else if (camera3.isOrthographicCamera) { this.ray.origin.set(coords.x, coords.y, (camera3.near + camera3.far) / (camera3.near - camera3.far)).unproject(camera3); this.ray.direction.set(0, 0, -1).transformDirection(camera3.matrixWorld); this.camera = camera3; } else { console.error("THREE.Raycaster: Unsupported camera type: " + camera3.type); } } intersectObject(object, recursive = true, intersects = []) { intersectObject2(object, this, intersects, recursive); intersects.sort(ascSort2); return intersects; } intersectObjects(objects, recursive = true, intersects = []) { for (let i = 0, l = objects.length; i < l; i++) { intersectObject2(objects[i], this, intersects, recursive); } intersects.sort(ascSort2); return intersects; } }; function ascSort2(a2, b) { return a2.distance - b.distance; } function intersectObject2(object, raycaster, intersects, recursive) { if (object.layers.test(raycaster.layers)) { object.raycast(raycaster, intersects); } if (recursive === true) { const children = object.children; for (let i = 0, l = children.length; i < l; i++) { intersectObject2(children[i], raycaster, intersects, true); } } } var Spherical = class { constructor(radius = 1, phi = 0, theta = 0) { this.radius = radius; this.phi = phi; this.theta = theta; return this; } set(radius, phi, theta) { this.radius = radius; this.phi = phi; this.theta = theta; return this; } copy(other) { this.radius = other.radius; this.phi = other.phi; this.theta = other.theta; return this; } // restrict phi to be between EPS and PI-EPS makeSafe() { const EPS = 1e-6; this.phi = Math.max(EPS, Math.min(Math.PI - EPS, this.phi)); return this; } setFromVector3(v) { return this.setFromCartesianCoords(v.x, v.y, v.z); } setFromCartesianCoords(x3, y3, z4) { this.radius = Math.sqrt(x3 * x3 + y3 * y3 + z4 * z4); if (this.radius === 0) { this.theta = 0; this.phi = 0; } else { this.theta = Math.atan2(x3, z4); this.phi = Math.acos(clamp2(y3 / this.radius, -1, 1)); } return this; } clone() { return new this.constructor().copy(this); } }; var _axis = /* @__PURE__ */ new Vector32(); var _lineGeometry; var _coneGeometry; var ArrowHelper = class extends Object3D2 { // dir is assumed to be normalized constructor(dir = new Vector32(0, 0, 1), origin3 = new Vector32(0, 0, 0), length = 1, color = 16776960, headLength = length * 0.2, headWidth = headLength * 0.2) { super(); this.type = "ArrowHelper"; if (_lineGeometry === void 0) { _lineGeometry = new BufferGeometry2(); _lineGeometry.setAttribute("position", new Float32BufferAttribute2([0, 0, 0, 0, 1, 0], 3)); _coneGeometry = new CylinderGeometry(0, 0.5, 1, 5, 1); _coneGeometry.translate(0, -0.5, 0); } this.position.copy(origin3); this.line = new Line(_lineGeometry, new LineBasicMaterial({ color, toneMapped: false })); this.line.matrixAutoUpdate = false; this.add(this.line); this.cone = new Mesh2(_coneGeometry, new MeshBasicMaterial2({ color, toneMapped: false })); this.cone.matrixAutoUpdate = false; this.add(this.cone); this.setDirection(dir); this.setLength(length, headLength, headWidth); } setDirection(dir) { if (dir.y > 0.99999) { this.quaternion.set(0, 0, 0, 1); } else if (dir.y < -0.99999) { this.quaternion.set(1, 0, 0, 0); } else { _axis.set(dir.z, 0, -dir.x).normalize(); const radians = Math.acos(dir.y); this.quaternion.setFromAxisAngle(_axis, radians); } } setLength(length, headLength = length * 0.2, headWidth = headLength * 0.2) { this.line.scale.set(1, Math.max(1e-4, length - headLength), 1); this.line.updateMatrix(); this.cone.scale.set(headWidth, headLength, headWidth); this.cone.position.y = length; this.cone.updateMatrix(); } setColor(color) { this.line.material.color.set(color); this.cone.material.color.set(color); } copy(source) { super.copy(source, false); this.line.copy(source.line); this.cone.copy(source.cone); return this; } dispose() { this.line.geometry.dispose(); this.line.material.dispose(); this.cone.geometry.dispose(); this.cone.material.dispose(); } }; if (typeof __THREE_DEVTOOLS__ !== "undefined") { __THREE_DEVTOOLS__.dispatchEvent(new CustomEvent("register", { detail: { revision: REVISION2 } })); } if (typeof window !== "undefined") { if (window.__THREE__) { console.warn("WARNING: Multiple instances of Three.js being imported."); } else { window.__THREE__ = REVISION2; } } // node_modules/d3-force-3d/src/center.js function center_default(x3, y3, z4) { var nodes, strength = 1; if (x3 == null) x3 = 0; if (y3 == null) y3 = 0; if (z4 == null) z4 = 0; function force() { var i, n = nodes.length, node, sx = 0, sy = 0, sz = 0; for (i = 0; i < n; ++i) { node = nodes[i], sx += node.x || 0, sy += node.y || 0, sz += node.z || 0; } for (sx = (sx / n - x3) * strength, sy = (sy / n - y3) * strength, sz = (sz / n - z4) * strength, i = 0; i < n; ++i) { node = nodes[i]; if (sx) { node.x -= sx; } if (sy) { node.y -= sy; } if (sz) { node.z -= sz; } } } force.initialize = function(_) { nodes = _; }; force.x = function(_) { return arguments.length ? (x3 = +_, force) : x3; }; force.y = function(_) { return arguments.length ? (y3 = +_, force) : y3; }; force.z = function(_) { return arguments.length ? (z4 = +_, force) : z4; }; force.strength = function(_) { return arguments.length ? (strength = +_, force) : strength; }; return force; } // node_modules/d3-binarytree/src/add.js function add_default(d) { const x3 = +this._x.call(null, d); return add(this.cover(x3), x3, d); } function add(tree, x3, d) { if (isNaN(x3)) return tree; var parent, node = tree._root, leaf = { data: d }, x0 = tree._x0, x1 = tree._x1, xm, xp, right, i, j; if (!node) return tree._root = leaf, tree; while (node.length) { if (right = x3 >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm; if (parent = node, !(node = node[i = +right])) return parent[i] = leaf, tree; } xp = +tree._x.call(null, node.data); if (x3 === xp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree; do { parent = parent ? parent[i] = new Array(2) : tree._root = new Array(2); if (right = x3 >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm; } while ((i = +right) === (j = +(xp >= xm))); return parent[j] = node, parent[i] = leaf, tree; } function addAll(data) { if (!Array.isArray(data)) data = Array.from(data); const n = data.length; const xz = new Float64Array(n); let x0 = Infinity, x1 = -Infinity; for (let i = 0, x3; i < n; ++i) { if (isNaN(x3 = +this._x.call(null, data[i]))) continue; xz[i] = x3; if (x3 < x0) x0 = x3; if (x3 > x1) x1 = x3; } if (x0 > x1) return this; this.cover(x0).cover(x1); for (let i = 0; i < n; ++i) { add(this, xz[i], data[i]); } return this; } // node_modules/d3-binarytree/src/cover.js function cover_default(x3) { if (isNaN(x3 = +x3)) return this; var x0 = this._x0, x1 = this._x1; if (isNaN(x0)) { x1 = (x0 = Math.floor(x3)) + 1; } else { var z4 = x1 - x0 || 1, node = this._root, parent, i; while (x0 > x3 || x3 >= x1) { i = +(x3 < x0); parent = new Array(2), parent[i] = node, node = parent, z4 *= 2; switch (i) { case 0: x1 = x0 + z4; break; case 1: x0 = x1 - z4; break; } } if (this._root && this._root.length) this._root = node; } this._x0 = x0; this._x1 = x1; return this; } // node_modules/d3-binarytree/src/data.js function data_default() { var data = []; this.visit(function(node) { if (!node.length) do data.push(node.data); while (node = node.next); }); return data; } // node_modules/d3-binarytree/src/extent.js function extent_default(_) { return arguments.length ? this.cover(+_[0][0]).cover(+_[1][0]) : isNaN(this._x0) ? void 0 : [[this._x0], [this._x1]]; } // node_modules/d3-binarytree/src/half.js function half_default(node, x0, x1) { this.node = node; this.x0 = x0; this.x1 = x1; } // node_modules/d3-binarytree/src/find.js function find_default(x3, radius) { var data, x0 = this._x0, x1, x22, x32 = this._x1, halves = [], node = this._root, q, i; if (node) halves.push(new half_default(node, x0, x32)); if (radius == null) radius = Infinity; else { x0 = x3 - radius; x32 = x3 + radius; } while (q = halves.pop()) { if (!(node = q.node) || (x1 = q.x0) > x32 || (x22 = q.x1) < x0) continue; if (node.length) { var xm = (x1 + x22) / 2; halves.push( new half_default(node[1], xm, x22), new half_default(node[0], x1, xm) ); if (i = +(x3 >= xm)) { q = halves[halves.length - 1]; halves[halves.length - 1] = halves[halves.length - 1 - i]; halves[halves.length - 1 - i] = q; } } else { var d = Math.abs(x3 - +this._x.call(null, node.data)); if (d < radius) { radius = d; x0 = x3 - d; x32 = x3 + d; data = node.data; } } } return data; } // node_modules/d3-binarytree/src/remove.js function remove_default(d) { if (isNaN(x3 = +this._x.call(null, d))) return this; var parent, node = this._root, retainer, previous, next, x0 = this._x0, x1 = this._x1, x3, xm, right, i, j; if (!node) return this; if (node.length) while (true) { if (right = x3 >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm; if (!(parent = node, node = node[i = +right])) return this; if (!node.length) break; if (parent[i + 1 & 1]) retainer = parent, j = i; } while (node.data !== d) if (!(previous = node, node = node.next)) return this; if (next = node.next) delete node.next; if (previous) return next ? previous.next = next : delete previous.next, this; if (!parent) return this._root = next, this; next ? parent[i] = next : delete parent[i]; if ((node = parent[0] || parent[1]) && node === (parent[1] || parent[0]) && !node.length) { if (retainer) retainer[j] = node; else this._root = node; } return this; } function removeAll(data) { for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]); return this; } // node_modules/d3-binarytree/src/root.js function root_default() { return this._root; } // node_modules/d3-binarytree/src/size.js function size_default() { var size = 0; this.visit(function(node) { if (!node.length) do ++size; while (node = node.next); }); return size; } // node_modules/d3-binarytree/src/visit.js function visit_default(callback) { var halves = [], q, node = this._root, child, x0, x1; if (node) halves.push(new half_default(node, this._x0, this._x1)); while (q = halves.pop()) { if (!callback(node = q.node, x0 = q.x0, x1 = q.x1) && node.length) { var xm = (x0 + x1) / 2; if (child = node[1]) halves.push(new half_default(child, xm, x1)); if (child = node[0]) halves.push(new half_default(child, x0, xm)); } } return this; } // node_modules/d3-binarytree/src/visitAfter.js function visitAfter_default(callback) { var halves = [], next = [], q; if (this._root) halves.push(new half_default(this._root, this._x0, this._x1)); while (q = halves.pop()) { var node = q.node; if (node.length) { var child, x0 = q.x0, x1 = q.x1, xm = (x0 + x1) / 2; if (child = node[0]) halves.push(new half_default(child, x0, xm)); if (child = node[1]) halves.push(new half_default(child, xm, x1)); } next.push(q); } while (q = next.pop()) { callback(q.node, q.x0, q.x1); } return this; } // node_modules/d3-binarytree/src/x.js function defaultX(d) { return d[0]; } function x_default(_) { return arguments.length ? (this._x = _, this) : this._x; } // node_modules/d3-binarytree/src/binarytree.js function binarytree(nodes, x3) { var tree = new Binarytree(x3 == null ? defaultX : x3, NaN, NaN); return nodes == null ? tree : tree.addAll(nodes); } function Binarytree(x3, x0, x1) { this._x = x3; this._x0 = x0; this._x1 = x1; this._root = void 0; } function leaf_copy(leaf) { var copy2 = { data: leaf.data }, next = copy2; while (leaf = leaf.next) next = next.next = { data: leaf.data }; return copy2; } var treeProto = binarytree.prototype = Binarytree.prototype; treeProto.copy = function() { var copy2 = new Binarytree(this._x, this._x0, this._x1), node = this._root, nodes, child; if (!node) return copy2; if (!node.length) return copy2._root = leaf_copy(node), copy2; nodes = [{ source: node, target: copy2._root = new Array(2) }]; while (node = nodes.pop()) { for (var i = 0; i < 2; ++i) { if (child = node.source[i]) { if (child.length) nodes.push({ source: child, target: node.target[i] = new Array(2) }); else node.target[i] = leaf_copy(child); } } } return copy2; }; treeProto.add = add_default; treeProto.addAll = addAll; treeProto.cover = cover_default; treeProto.data = data_default; treeProto.extent = extent_default; treeProto.find = find_default; treeProto.remove = remove_default; treeProto.removeAll = removeAll; treeProto.root = root_default; treeProto.size = size_default; treeProto.visit = visit_default; treeProto.visitAfter = visitAfter_default; treeProto.x = x_default; // node_modules/d3-quadtree/src/add.js function add_default2(d) { const x3 = +this._x.call(null, d), y3 = +this._y.call(null, d); return add2(this.cover(x3, y3), x3, y3, d); } function add2(tree, x3, y3, d) { if (isNaN(x3) || isNaN(y3)) return tree; var parent, node = tree._root, leaf = { data: d }, x0 = tree._x0, y0 = tree._y0, x1 = tree._x1, y1 = tree._y1, xm, ym, xp, yp, right, bottom, i, j; if (!node) return tree._root = leaf, tree; while (node.length) { if (right = x3 >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm; if (bottom = y3 >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym; if (parent = node, !(node = node[i = bottom << 1 | right])) return parent[i] = leaf, tree; } xp = +tree._x.call(null, node.data); yp = +tree._y.call(null, node.data); if (x3 === xp && y3 === yp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree; do { parent = parent ? parent[i] = new Array(4) : tree._root = new Array(4); if (right = x3 >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm; if (bottom = y3 >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym; } while ((i = bottom << 1 | right) === (j = (yp >= ym) << 1 | xp >= xm)); return parent[j] = node, parent[i] = leaf, tree; } function addAll2(data) { var d, i, n = data.length, x3, y3, xz = new Array(n), yz = new Array(n), x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity; for (i = 0; i < n; ++i) { if (isNaN(x3 = +this._x.call(null, d = data[i])) || isNaN(y3 = +this._y.call(null, d))) continue; xz[i] = x3; yz[i] = y3; if (x3 < x0) x0 = x3; if (x3 > x1) x1 = x3; if (y3 < y0) y0 = y3; if (y3 > y1) y1 = y3; } if (x0 > x1 || y0 > y1) return this; this.cover(x0, y0).cover(x1, y1); for (i = 0; i < n; ++i) { add2(this, xz[i], yz[i], data[i]); } return this; } // node_modules/d3-quadtree/src/cover.js function cover_default2(x3, y3) { if (isNaN(x3 = +x3) || isNaN(y3 = +y3)) return this; var x0 = this._x0, y0 = this._y0, x1 = this._x1, y1 = this._y1; if (isNaN(x0)) { x1 = (x0 = Math.floor(x3)) + 1; y1 = (y0 = Math.floor(y3)) + 1; } else { var z4 = x1 - x0 || 1, node = this._root, parent, i; while (x0 > x3 || x3 >= x1 || y0 > y3 || y3 >= y1) { i = (y3 < y0) << 1 | x3 < x0; parent = new Array(4), parent[i] = node, node = parent, z4 *= 2; switch (i) { case 0: x1 = x0 + z4, y1 = y0 + z4; break; case 1: x0 = x1 - z4, y1 = y0 + z4; break; case 2: x1 = x0 + z4, y0 = y1 - z4; break; case 3: x0 = x1 - z4, y0 = y1 - z4; break; } } if (this._root && this._root.length) this._root = node; } this._x0 = x0; this._y0 = y0; this._x1 = x1; this._y1 = y1; return this; } // node_modules/d3-quadtree/src/data.js function data_default2() { var data = []; this.visit(function(node) { if (!node.length) do data.push(node.data); while (node = node.next); }); return data; } // node_modules/d3-quadtree/src/extent.js function extent_default2(_) { return arguments.length ? this.cover(+_[0][0], +_[0][1]).cover(+_[1][0], +_[1][1]) : isNaN(this._x0) ? void 0 : [[this._x0, this._y0], [this._x1, this._y1]]; } // node_modules/d3-quadtree/src/quad.js function quad_default(node, x0, y0, x1, y1) { this.node = node; this.x0 = x0; this.y0 = y0; this.x1 = x1; this.y1 = y1; } // node_modules/d3-quadtree/src/find.js function find_default2(x3, y3, radius) { var data, x0 = this._x0, y0 = this._y0, x1, y1, x22, y22, x32 = this._x1, y32 = this._y1, quads = [], node = this._root, q, i; if (node) quads.push(new quad_default(node, x0, y0, x32, y32)); if (radius == null) radius = Infinity; else { x0 = x3 - radius, y0 = y3 - radius; x32 = x3 + radius, y32 = y3 + radius; radius *= radius; } while (q = quads.pop()) { if (!(node = q.node) || (x1 = q.x0) > x32 || (y1 = q.y0) > y32 || (x22 = q.x1) < x0 || (y22 = q.y1) < y0) continue; if (node.length) { var xm = (x1 + x22) / 2, ym = (y1 + y22) / 2; quads.push( new quad_default(node[3], xm, ym, x22, y22), new quad_default(node[2], x1, ym, xm, y22), new quad_default(node[1], xm, y1, x22, ym), new quad_default(node[0], x1, y1, xm, ym) ); if (i = (y3 >= ym) << 1 | x3 >= xm) { q = quads[quads.length - 1]; quads[quads.length - 1] = quads[quads.length - 1 - i]; quads[quads.length - 1 - i] = q; } } else { var dx = x3 - +this._x.call(null, node.data), dy = y3 - +this._y.call(null, node.data), d2 = dx * dx + dy * dy; if (d2 < radius) { var d = Math.sqrt(radius = d2); x0 = x3 - d, y0 = y3 - d; x32 = x3 + d, y32 = y3 + d; data = node.data; } } } return data; } // node_modules/d3-quadtree/src/remove.js function remove_default2(d) { if (isNaN(x3 = +this._x.call(null, d)) || isNaN(y3 = +this._y.call(null, d))) return this; var parent, node = this._root, retainer, previous, next, x0 = this._x0, y0 = this._y0, x1 = this._x1, y1 = this._y1, x3, y3, xm, ym, right, bottom, i, j; if (!node) return this; if (node.length) while (true) { if (right = x3 >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm; if (bottom = y3 >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym; if (!(parent = node, node = node[i = bottom << 1 | right])) return this; if (!node.length) break; if (parent[i + 1 & 3] || parent[i + 2 & 3] || parent[i + 3 & 3]) retainer = parent, j = i; } while (node.data !== d) if (!(previous = node, node = node.next)) return this; if (next = node.next) delete node.next; if (previous) return next ? previous.next = next : delete previous.next, this; if (!parent) return this._root = next, this; next ? parent[i] = next : delete parent[i]; if ((node = parent[0] || parent[1] || parent[2] || parent[3]) && node === (parent[3] || parent[2] || parent[1] || parent[0]) && !node.length) { if (retainer) retainer[j] = node; else this._root = node; } return this; } function removeAll2(data) { for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]); return this; } // node_modules/d3-quadtree/src/root.js function root_default2() { return this._root; } // node_modules/d3-quadtree/src/size.js function size_default2() { var size = 0; this.visit(function(node) { if (!node.length) do ++size; while (node = node.next); }); return size; } // node_modules/d3-quadtree/src/visit.js function visit_default2(callback) { var quads = [], q, node = this._root, child, x0, y0, x1, y1; if (node) quads.push(new quad_default(node, this._x0, this._y0, this._x1, this._y1)); while (q = quads.pop()) { if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1) && node.length) { var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2; if (child = node[3]) quads.push(new quad_default(child, xm, ym, x1, y1)); if (child = node[2]) quads.push(new quad_default(child, x0, ym, xm, y1)); if (child = node[1]) quads.push(new quad_default(child, xm, y0, x1, ym)); if (child = node[0]) quads.push(new quad_default(child, x0, y0, xm, ym)); } } return this; } // node_modules/d3-quadtree/src/visitAfter.js function visitAfter_default2(callback) { var quads = [], next = [], q; if (this._root) quads.push(new quad_default(this._root, this._x0, this._y0, this._x1, this._y1)); while (q = quads.pop()) { var node = q.node; if (node.length) { var child, x0 = q.x0, y0 = q.y0, x1 = q.x1, y1 = q.y1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2; if (child = node[0]) quads.push(new quad_default(child, x0, y0, xm, ym)); if (child = node[1]) quads.push(new quad_default(child, xm, y0, x1, ym)); if (child = node[2]) quads.push(new quad_default(child, x0, ym, xm, y1)); if (child = node[3]) quads.push(new quad_default(child, xm, ym, x1, y1)); } next.push(q); } while (q = next.pop()) { callback(q.node, q.x0, q.y0, q.x1, q.y1); } return this; } // node_modules/d3-quadtree/src/x.js function defaultX2(d) { return d[0]; } function x_default2(_) { return arguments.length ? (this._x = _, this) : this._x; } // node_modules/d3-quadtree/src/y.js function defaultY(d) { return d[1]; } function y_default(_) { return arguments.length ? (this._y = _, this) : this._y; } // node_modules/d3-quadtree/src/quadtree.js function quadtree(nodes, x3, y3) { var tree = new Quadtree(x3 == null ? defaultX2 : x3, y3 == null ? defaultY : y3, NaN, NaN, NaN, NaN); return nodes == null ? tree : tree.addAll(nodes); } function Quadtree(x3, y3, x0, y0, x1, y1) { this._x = x3; this._y = y3; this._x0 = x0; this._y0 = y0; this._x1 = x1; this._y1 = y1; this._root = void 0; } function leaf_copy2(leaf) { var copy2 = { data: leaf.data }, next = copy2; while (leaf = leaf.next) next = next.next = { data: leaf.data }; return copy2; } var treeProto2 = quadtree.prototype = Quadtree.prototype; treeProto2.copy = function() { var copy2 = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1), node = this._root, nodes, child; if (!node) return copy2; if (!node.length) return copy2._root = leaf_copy2(node), copy2; nodes = [{ source: node, target: copy2._root = new Array(4) }]; while (node = nodes.pop()) { for (var i = 0; i < 4; ++i) { if (child = node.source[i]) { if (child.length) nodes.push({ source: child, target: node.target[i] = new Array(4) }); else node.target[i] = leaf_copy2(child); } } } return copy2; }; treeProto2.add = add_default2; treeProto2.addAll = addAll2; treeProto2.cover = cover_default2; treeProto2.data = data_default2; treeProto2.extent = extent_default2; treeProto2.find = find_default2; treeProto2.remove = remove_default2; treeProto2.removeAll = removeAll2; treeProto2.root = root_default2; treeProto2.size = size_default2; treeProto2.visit = visit_default2; treeProto2.visitAfter = visitAfter_default2; treeProto2.x = x_default2; treeProto2.y = y_default; // node_modules/d3-octree/src/add.js function add_default3(d) { const x3 = +this._x.call(null, d), y3 = +this._y.call(null, d), z4 = +this._z.call(null, d); return add3(this.cover(x3, y3, z4), x3, y3, z4, d); } function add3(tree, x3, y3, z4, d) { if (isNaN(x3) || isNaN(y3) || isNaN(z4)) return tree; var parent, node = tree._root, leaf = { data: d }, x0 = tree._x0, y0 = tree._y0, z0 = tree._z0, x1 = tree._x1, y1 = tree._y1, z1 = tree._z1, xm, ym, zm, xp, yp, zp, right, bottom, deep, i, j; if (!node) return tree._root = leaf, tree; while (node.length) { if (right = x3 >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm; if (bottom = y3 >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym; if (deep = z4 >= (zm = (z0 + z1) / 2)) z0 = zm; else z1 = zm; if (parent = node, !(node = node[i = deep << 2 | bottom << 1 | right])) return parent[i] = leaf, tree; } xp = +tree._x.call(null, node.data); yp = +tree._y.call(null, node.data); zp = +tree._z.call(null, node.data); if (x3 === xp && y3 === yp && z4 === zp) return leaf.next = node, parent ? parent[i] = leaf : tree._root = leaf, tree; do { parent = parent ? parent[i] = new Array(8) : tree._root = new Array(8); if (right = x3 >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm; if (bottom = y3 >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym; if (deep = z4 >= (zm = (z0 + z1) / 2)) z0 = zm; else z1 = zm; } while ((i = deep << 2 | bottom << 1 | right) === (j = (zp >= zm) << 2 | (yp >= ym) << 1 | xp >= xm)); return parent[j] = node, parent[i] = leaf, tree; } function addAll3(data) { if (!Array.isArray(data)) data = Array.from(data); const n = data.length; const xz = new Float64Array(n); const yz = new Float64Array(n); const zz = new Float64Array(n); let x0 = Infinity, y0 = Infinity, z0 = Infinity, x1 = -Infinity, y1 = -Infinity, z1 = -Infinity; for (let i = 0, d, x3, y3, z4; i < n; ++i) { if (isNaN(x3 = +this._x.call(null, d = data[i])) || isNaN(y3 = +this._y.call(null, d)) || isNaN(z4 = +this._z.call(null, d))) continue; xz[i] = x3; yz[i] = y3; zz[i] = z4; if (x3 < x0) x0 = x3; if (x3 > x1) x1 = x3; if (y3 < y0) y0 = y3; if (y3 > y1) y1 = y3; if (z4 < z0) z0 = z4; if (z4 > z1) z1 = z4; } if (x0 > x1 || y0 > y1 || z0 > z1) return this; this.cover(x0, y0, z0).cover(x1, y1, z1); for (let i = 0; i < n; ++i) { add3(this, xz[i], yz[i], zz[i], data[i]); } return this; } // node_modules/d3-octree/src/cover.js function cover_default3(x3, y3, z4) { if (isNaN(x3 = +x3) || isNaN(y3 = +y3) || isNaN(z4 = +z4)) return this; var x0 = this._x0, y0 = this._y0, z0 = this._z0, x1 = this._x1, y1 = this._y1, z1 = this._z1; if (isNaN(x0)) { x1 = (x0 = Math.floor(x3)) + 1; y1 = (y0 = Math.floor(y3)) + 1; z1 = (z0 = Math.floor(z4)) + 1; } else { var t = x1 - x0 || 1, node = this._root, parent, i; while (x0 > x3 || x3 >= x1 || y0 > y3 || y3 >= y1 || z0 > z4 || z4 >= z1) { i = (z4 < z0) << 2 | (y3 < y0) << 1 | x3 < x0; parent = new Array(8), parent[i] = node, node = parent, t *= 2; switch (i) { case 0: x1 = x0 + t, y1 = y0 + t, z1 = z0 + t; break; case 1: x0 = x1 - t, y1 = y0 + t, z1 = z0 + t; break; case 2: x1 = x0 + t, y0 = y1 - t, z1 = z0 + t; break; case 3: x0 = x1 - t, y0 = y1 - t, z1 = z0 + t; break; case 4: x1 = x0 + t, y1 = y0 + t, z0 = z1 - t; break; case 5: x0 = x1 - t, y1 = y0 + t, z0 = z1 - t; break; case 6: x1 = x0 + t, y0 = y1 - t, z0 = z1 - t; break; case 7: x0 = x1 - t, y0 = y1 - t, z0 = z1 - t; break; } } if (this._root && this._root.length) this._root = node; } this._x0 = x0; this._y0 = y0; this._z0 = z0; this._x1 = x1; this._y1 = y1; this._z1 = z1; return this; } // node_modules/d3-octree/src/data.js function data_default3() { var data = []; this.visit(function(node) { if (!node.length) do data.push(node.data); while (node = node.next); }); return data; } // node_modules/d3-octree/src/extent.js function extent_default3(_) { return arguments.length ? this.cover(+_[0][0], +_[0][1], +_[0][2]).cover(+_[1][0], +_[1][1], +_[1][2]) : isNaN(this._x0) ? void 0 : [[this._x0, this._y0, this._z0], [this._x1, this._y1, this._z1]]; } // node_modules/d3-octree/src/octant.js function octant_default(node, x0, y0, z0, x1, y1, z1) { this.node = node; this.x0 = x0; this.y0 = y0; this.z0 = z0; this.x1 = x1; this.y1 = y1; this.z1 = z1; } // node_modules/d3-octree/src/find.js function find_default3(x3, y3, z4, radius) { var data, x0 = this._x0, y0 = this._y0, z0 = this._z0, x1, y1, z1, x22, y22, z22, x32 = this._x1, y32 = this._y1, z32 = this._z1, octs = [], node = this._root, q, i; if (node) octs.push(new octant_default(node, x0, y0, z0, x32, y32, z32)); if (radius == null) radius = Infinity; else { x0 = x3 - radius, y0 = y3 - radius, z0 = z4 - radius; x32 = x3 + radius, y32 = y3 + radius, z32 = z4 + radius; radius *= radius; } while (q = octs.pop()) { if (!(node = q.node) || (x1 = q.x0) > x32 || (y1 = q.y0) > y32 || (z1 = q.z0) > z32 || (x22 = q.x1) < x0 || (y22 = q.y1) < y0 || (z22 = q.z1) < z0) continue; if (node.length) { var xm = (x1 + x22) / 2, ym = (y1 + y22) / 2, zm = (z1 + z22) / 2; octs.push( new octant_default(node[7], xm, ym, zm, x22, y22, z22), new octant_default(node[6], x1, ym, zm, xm, y22, z22), new octant_default(node[5], xm, y1, zm, x22, ym, z22), new octant_default(node[4], x1, y1, zm, xm, ym, z22), new octant_default(node[3], xm, ym, z1, x22, y22, zm), new octant_default(node[2], x1, ym, z1, xm, y22, zm), new octant_default(node[1], xm, y1, z1, x22, ym, zm), new octant_default(node[0], x1, y1, z1, xm, ym, zm) ); if (i = (z4 >= zm) << 2 | (y3 >= ym) << 1 | x3 >= xm) { q = octs[octs.length - 1]; octs[octs.length - 1] = octs[octs.length - 1 - i]; octs[octs.length - 1 - i] = q; } } else { var dx = x3 - +this._x.call(null, node.data), dy = y3 - +this._y.call(null, node.data), dz = z4 - +this._z.call(null, node.data), d2 = dx * dx + dy * dy + dz * dz; if (d2 < radius) { var d = Math.sqrt(radius = d2); x0 = x3 - d, y0 = y3 - d, z0 = z4 - d; x32 = x3 + d, y32 = y3 + d, z32 = z4 + d; data = node.data; } } } return data; } // node_modules/d3-octree/src/remove.js function remove_default3(d) { if (isNaN(x3 = +this._x.call(null, d)) || isNaN(y3 = +this._y.call(null, d)) || isNaN(z4 = +this._z.call(null, d))) return this; var parent, node = this._root, retainer, previous, next, x0 = this._x0, y0 = this._y0, z0 = this._z0, x1 = this._x1, y1 = this._y1, z1 = this._z1, x3, y3, z4, xm, ym, zm, right, bottom, deep, i, j; if (!node) return this; if (node.length) while (true) { if (right = x3 >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm; if (bottom = y3 >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym; if (deep = z4 >= (zm = (z0 + z1) / 2)) z0 = zm; else z1 = zm; if (!(parent = node, node = node[i = deep << 2 | bottom << 1 | right])) return this; if (!node.length) break; if (parent[i + 1 & 7] || parent[i + 2 & 7] || parent[i + 3 & 7] || parent[i + 4 & 7] || parent[i + 5 & 7] || parent[i + 6 & 7] || parent[i + 7 & 7]) retainer = parent, j = i; } while (node.data !== d) if (!(previous = node, node = node.next)) return this; if (next = node.next) delete node.next; if (previous) return next ? previous.next = next : delete previous.next, this; if (!parent) return this._root = next, this; next ? parent[i] = next : delete parent[i]; if ((node = parent[0] || parent[1] || parent[2] || parent[3] || parent[4] || parent[5] || parent[6] || parent[7]) && node === (parent[7] || parent[6] || parent[5] || parent[4] || parent[3] || parent[2] || parent[1] || parent[0]) && !node.length) { if (retainer) retainer[j] = node; else this._root = node; } return this; } function removeAll3(data) { for (var i = 0, n = data.length; i < n; ++i) this.remove(data[i]); return this; } // node_modules/d3-octree/src/root.js function root_default3() { return this._root; } // node_modules/d3-octree/src/size.js function size_default3() { var size = 0; this.visit(function(node) { if (!node.length) do ++size; while (node = node.next); }); return size; } // node_modules/d3-octree/src/visit.js function visit_default3(callback) { var octs = [], q, node = this._root, child, x0, y0, z0, x1, y1, z1; if (node) octs.push(new octant_default(node, this._x0, this._y0, this._z0, this._x1, this._y1, this._z1)); while (q = octs.pop()) { if (!callback(node = q.node, x0 = q.x0, y0 = q.y0, z0 = q.z0, x1 = q.x1, y1 = q.y1, z1 = q.z1) && node.length) { var xm = (x0 + x1) / 2, ym = (y0 + y1) / 2, zm = (z0 + z1) / 2; if (child = node[7]) octs.push(new octant_default(child, xm, ym, zm, x1, y1, z1)); if (child = node[6]) octs.push(new octant_default(child, x0, ym, zm, xm, y1, z1)); if (child = node[5]) octs.push(new octant_default(child, xm, y0, zm, x1, ym, z1)); if (child = node[4]) octs.push(new octant_default(child, x0, y0, zm, xm, ym, z1)); if (child = node[3]) octs.push(new octant_default(child, xm, ym, z0, x1, y1, zm)); if (child = node[2]) octs.push(new octant_default(child, x0, ym, z0, xm, y1, zm)); if (child = node[1]) octs.push(new octant_default(child, xm, y0, z0, x1, ym, zm)); if (child = node[0]) octs.push(new octant_default(child, x0, y0, z0, xm, ym, zm)); } } return this; } // node_modules/d3-octree/src/visitAfter.js function visitAfter_default3(callback) { var octs = [], next = [], q; if (this._root) octs.push(new octant_default(this._root, this._x0, this._y0, this._z0, this._x1, this._y1, this._z1)); while (q = octs.pop()) { var node = q.node; if (node.length) { var child, x0 = q.x0, y0 = q.y0, z0 = q.z0, x1 = q.x1, y1 = q.y1, z1 = q.z1, xm = (x0 + x1) / 2, ym = (y0 + y1) / 2, zm = (z0 + z1) / 2; if (child = node[0]) octs.push(new octant_default(child, x0, y0, z0, xm, ym, zm)); if (child = node[1]) octs.push(new octant_default(child, xm, y0, z0, x1, ym, zm)); if (child = node[2]) octs.push(new octant_default(child, x0, ym, z0, xm, y1, zm)); if (child = node[3]) octs.push(new octant_default(child, xm, ym, z0, x1, y1, zm)); if (child = node[4]) octs.push(new octant_default(child, x0, y0, zm, xm, ym, z1)); if (child = node[5]) octs.push(new octant_default(child, xm, y0, zm, x1, ym, z1)); if (child = node[6]) octs.push(new octant_default(child, x0, ym, zm, xm, y1, z1)); if (child = node[7]) octs.push(new octant_default(child, xm, ym, zm, x1, y1, z1)); } next.push(q); } while (q = next.pop()) { callback(q.node, q.x0, q.y0, q.z0, q.x1, q.y1, q.z1); } return this; } // node_modules/d3-octree/src/x.js function defaultX3(d) { return d[0]; } function x_default3(_) { return arguments.length ? (this._x = _, this) : this._x; } // node_modules/d3-octree/src/y.js function defaultY2(d) { return d[1]; } function y_default2(_) { return arguments.length ? (this._y = _, this) : this._y; } // node_modules/d3-octree/src/z.js function defaultZ(d) { return d[2]; } function z_default(_) { return arguments.length ? (this._z = _, this) : this._z; } // node_modules/d3-octree/src/octree.js function octree(nodes, x3, y3, z4) { var tree = new Octree(x3 == null ? defaultX3 : x3, y3 == null ? defaultY2 : y3, z4 == null ? defaultZ : z4, NaN, NaN, NaN, NaN, NaN, NaN); return nodes == null ? tree : tree.addAll(nodes); } function Octree(x3, y3, z4, x0, y0, z0, x1, y1, z1) { this._x = x3; this._y = y3; this._z = z4; this._x0 = x0; this._y0 = y0; this._z0 = z0; this._x1 = x1; this._y1 = y1; this._z1 = z1; this._root = void 0; } function leaf_copy3(leaf) { var copy2 = { data: leaf.data }, next = copy2; while (leaf = leaf.next) next = next.next = { data: leaf.data }; return copy2; } var treeProto3 = octree.prototype = Octree.prototype; treeProto3.copy = function() { var copy2 = new Octree(this._x, this._y, this._z, this._x0, this._y0, this._z0, this._x1, this._y1, this._z1), node = this._root, nodes, child; if (!node) return copy2; if (!node.length) return copy2._root = leaf_copy3(node), copy2; nodes = [{ source: node, target: copy2._root = new Array(8) }]; while (node = nodes.pop()) { for (var i = 0; i < 8; ++i) { if (child = node.source[i]) { if (child.length) nodes.push({ source: child, target: node.target[i] = new Array(8) }); else node.target[i] = leaf_copy3(child); } } } return copy2; }; treeProto3.add = add_default3; treeProto3.addAll = addAll3; treeProto3.cover = cover_default3; treeProto3.data = data_default3; treeProto3.extent = extent_default3; treeProto3.find = find_default3; treeProto3.remove = remove_default3; treeProto3.removeAll = removeAll3; treeProto3.root = root_default3; treeProto3.size = size_default3; treeProto3.visit = visit_default3; treeProto3.visitAfter = visitAfter_default3; treeProto3.x = x_default3; treeProto3.y = y_default2; treeProto3.z = z_default; // node_modules/d3-force-3d/src/constant.js function constant_default(x3) { return function() { return x3; }; } // node_modules/d3-force-3d/src/jiggle.js function jiggle_default(random) { return (random() - 0.5) * 1e-6; } // node_modules/d3-force-3d/src/collide.js function x(d) { return d.x + d.vx; } function y(d) { return d.y + d.vy; } function z2(d) { return d.z + d.vz; } function collide_default(radius) { var nodes, nDim, radii, random, strength = 1, iterations = 1; if (typeof radius !== "function") radius = constant_default(radius == null ? 1 : +radius); function force() { var i, n = nodes.length, tree, node, xi, yi, zi, ri, ri2; for (var k = 0; k < iterations; ++k) { tree = (nDim === 1 ? binarytree(nodes, x) : nDim === 2 ? quadtree(nodes, x, y) : nDim === 3 ? octree(nodes, x, y, z2) : null).visitAfter(prepare); for (i = 0; i < n; ++i) { node = nodes[i]; ri = radii[node.index], ri2 = ri * ri; xi = node.x + node.vx; if (nDim > 1) { yi = node.y + node.vy; } if (nDim > 2) { zi = node.z + node.vz; } tree.visit(apply); } } function apply(treeNode, arg1, arg2, arg3, arg4, arg5, arg6) { var args = [arg1, arg2, arg3, arg4, arg5, arg6]; var x0 = args[0], y0 = args[1], z0 = args[2], x1 = args[nDim], y1 = args[nDim + 1], z1 = args[nDim + 2]; var data = treeNode.data, rj = treeNode.r, r = ri + rj; if (data) { if (data.index > node.index) { var x3 = xi - data.x - data.vx, y3 = nDim > 1 ? yi - data.y - data.vy : 0, z4 = nDim > 2 ? zi - data.z - data.vz : 0, l = x3 * x3 + y3 * y3 + z4 * z4; if (l < r * r) { if (x3 === 0) x3 = jiggle_default(random), l += x3 * x3; if (nDim > 1 && y3 === 0) y3 = jiggle_default(random), l += y3 * y3; if (nDim > 2 && z4 === 0) z4 = jiggle_default(random), l += z4 * z4; l = (r - (l = Math.sqrt(l))) / l * strength; node.vx += (x3 *= l) * (r = (rj *= rj) / (ri2 + rj)); if (nDim > 1) { node.vy += (y3 *= l) * r; } if (nDim > 2) { node.vz += (z4 *= l) * r; } data.vx -= x3 * (r = 1 - r); if (nDim > 1) { data.vy -= y3 * r; } if (nDim > 2) { data.vz -= z4 * r; } } } return; } return x0 > xi + r || x1 < xi - r || nDim > 1 && (y0 > yi + r || y1 < yi - r) || nDim > 2 && (z0 > zi + r || z1 < zi - r); } } function prepare(treeNode) { if (treeNode.data) return treeNode.r = radii[treeNode.data.index]; for (var i = treeNode.r = 0; i < Math.pow(2, nDim); ++i) { if (treeNode[i] && treeNode[i].r > treeNode.r) { treeNode.r = treeNode[i].r; } } } function initialize() { if (!nodes) return; var i, n = nodes.length, node; radii = new Array(n); for (i = 0; i < n; ++i) node = nodes[i], radii[node.index] = +radius(node, i, nodes); } force.initialize = function(_nodes, ...args) { nodes = _nodes; random = args.find((arg) => typeof arg === "function") || Math.random; nDim = args.find((arg) => [1, 2, 3].includes(arg)) || 2; initialize(); }; force.iterations = function(_) { return arguments.length ? (iterations = +_, force) : iterations; }; force.strength = function(_) { return arguments.length ? (strength = +_, force) : strength; }; force.radius = function(_) { return arguments.length ? (radius = typeof _ === "function" ? _ : constant_default(+_), initialize(), force) : radius; }; return force; } // node_modules/d3-force-3d/src/link.js function index(d) { return d.index; } function find(nodeById, nodeId) { var node = nodeById.get(nodeId); if (!node) throw new Error("node not found: " + nodeId); return node; } function link_default(links) { var id = index, strength = defaultStrength, strengths, distance = constant_default(30), distances, nodes, nDim, count, bias, random, iterations = 1; if (links == null) links = []; function defaultStrength(link) { return 1 / Math.min(count[link.source.index], count[link.target.index]); } function force(alpha) { for (var k = 0, n = links.length; k < iterations; ++k) { for (var i = 0, link, source, target, x3 = 0, y3 = 0, z4 = 0, l, b; i < n; ++i) { link = links[i], source = link.source, target = link.target; x3 = target.x + target.vx - source.x - source.vx || jiggle_default(random); if (nDim > 1) { y3 = target.y + target.vy - source.y - source.vy || jiggle_default(random); } if (nDim > 2) { z4 = target.z + target.vz - source.z - source.vz || jiggle_default(random); } l = Math.sqrt(x3 * x3 + y3 * y3 + z4 * z4); l = (l - distances[i]) / l * alpha * strengths[i]; x3 *= l, y3 *= l, z4 *= l; target.vx -= x3 * (b = bias[i]); if (nDim > 1) { target.vy -= y3 * b; } if (nDim > 2) { target.vz -= z4 * b; } source.vx += x3 * (b = 1 - b); if (nDim > 1) { source.vy += y3 * b; } if (nDim > 2) { source.vz += z4 * b; } } } } function initialize() { if (!nodes) return; var i, n = nodes.length, m2 = links.length, nodeById = new Map(nodes.map((d, i2) => [id(d, i2, nodes), d])), link; for (i = 0, count = new Array(n); i < m2; ++i) { link = links[i], link.index = i; if (typeof link.source !== "object") link.source = find(nodeById, link.source); if (typeof link.target !== "object") link.target = find(nodeById, link.target); count[link.source.index] = (count[link.source.index] || 0) + 1; count[link.target.index] = (count[link.target.index] || 0) + 1; } for (i = 0, bias = new Array(m2); i < m2; ++i) { link = links[i], bias[i] = count[link.source.index] / (count[link.source.index] + count[link.target.index]); } strengths = new Array(m2), initializeStrength(); distances = new Array(m2), initializeDistance(); } function initializeStrength() { if (!nodes) return; for (var i = 0, n = links.length; i < n; ++i) { strengths[i] = +strength(links[i], i, links); } } function initializeDistance() { if (!nodes) return; for (var i = 0, n = links.length; i < n; ++i) { distances[i] = +distance(links[i], i, links); } } force.initialize = function(_nodes, ...args) { nodes = _nodes; random = args.find((arg) => typeof arg === "function") || Math.random; nDim = args.find((arg) => [1, 2, 3].includes(arg)) || 2; initialize(); }; force.links = function(_) { return arguments.length ? (links = _, initialize(), force) : links; }; force.id = function(_) { return arguments.length ? (id = _, force) : id; }; force.iterations = function(_) { return arguments.length ? (iterations = +_, force) : iterations; }; force.strength = function(_) { return arguments.length ? (strength = typeof _ === "function" ? _ : constant_default(+_), initializeStrength(), force) : strength; }; force.distance = function(_) { return arguments.length ? (distance = typeof _ === "function" ? _ : constant_default(+_), initializeDistance(), force) : distance; }; return force; } // node_modules/d3-dispatch/src/dispatch.js var noop = { value: () => { } }; function dispatch() { for (var i = 0, n = arguments.length, _ = {}, t; i < n; ++i) { if (!(t = arguments[i] + "") || t in _ || /[\s.]/.test(t)) throw new Error("illegal type: " + t); _[t] = []; } return new Dispatch(_); } function Dispatch(_) { this._ = _; } function parseTypenames(typenames, types) { return typenames.trim().split(/^|\s+/).map(function(t) { var name = "", i = t.indexOf("."); if (i >= 0) name = t.slice(i + 1), t = t.slice(0, i); if (t && !types.hasOwnProperty(t)) throw new Error("unknown type: " + t); return { type: t, name }; }); } Dispatch.prototype = dispatch.prototype = { constructor: Dispatch, on: function(typename, callback) { var _ = this._, T = parseTypenames(typename + "", _), t, i = -1, n = T.length; if (arguments.length < 2) { while (++i < n) if ((t = (typename = T[i]).type) && (t = get(_[t], typename.name))) return t; return; } if (callback != null && typeof callback !== "function") throw new Error("invalid callback: " + callback); while (++i < n) { if (t = (typename = T[i]).type) _[t] = set(_[t], typename.name, callback); else if (callback == null) for (t in _) _[t] = set(_[t], typename.name, null); } return this; }, copy: function() { var copy2 = {}, _ = this._; for (var t in _) copy2[t] = _[t].slice(); return new Dispatch(copy2); }, call: function(type, that) { if ((n = arguments.length - 2) > 0) for (var args = new Array(n), i = 0, n, t; i < n; ++i) args[i] = arguments[i + 2]; if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type); for (t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args); }, apply: function(type, that, args) { if (!this._.hasOwnProperty(type)) throw new Error("unknown type: " + type); for (var t = this._[type], i = 0, n = t.length; i < n; ++i) t[i].value.apply(that, args); } }; function get(type, name) { for (var i = 0, n = type.length, c2; i < n; ++i) { if ((c2 = type[i]).name === name) { return c2.value; } } } function set(type, name, callback) { for (var i = 0, n = type.length; i < n; ++i) { if (type[i].name === name) { type[i] = noop, type = type.slice(0, i).concat(type.slice(i + 1)); break; } } if (callback != null) type.push({ name, value: callback }); return type; } var dispatch_default = dispatch; // node_modules/d3-timer/src/timer.js var frame = 0; var timeout = 0; var interval = 0; var pokeDelay = 1e3; var taskHead; var taskTail; var clockLast = 0; var clockNow = 0; var clockSkew = 0; var clock = typeof performance === "object" && performance.now ? performance : Date; var setFrame = typeof window === "object" && window.requestAnimationFrame ? window.requestAnimationFrame.bind(window) : function(f) { setTimeout(f, 17); }; function now2() { return clockNow || (setFrame(clearNow), clockNow = clock.now() + clockSkew); } function clearNow() { clockNow = 0; } function Timer() { this._call = this._time = this._next = null; } Timer.prototype = timer.prototype = { constructor: Timer, restart: function(callback, delay, time) { if (typeof callback !== "function") throw new TypeError("callback is not a function"); time = (time == null ? now2() : +time) + (delay == null ? 0 : +delay); if (!this._next && taskTail !== this) { if (taskTail) taskTail._next = this; else taskHead = this; taskTail = this; } this._call = callback; this._time = time; sleep(); }, stop: function() { if (this._call) { this._call = null; this._time = Infinity; sleep(); } } }; function timer(callback, delay, time) { var t = new Timer(); t.restart(callback, delay, time); return t; } function timerFlush() { now2(); ++frame; var t = taskHead, e; while (t) { if ((e = clockNow - t._time) >= 0) t._call.call(void 0, e); t = t._next; } --frame; } function wake() { clockNow = (clockLast = clock.now()) + clockSkew; frame = timeout = 0; try { timerFlush(); } finally { frame = 0; nap(); clockNow = 0; } } function poke() { var now5 = clock.now(), delay = now5 - clockLast; if (delay > pokeDelay) clockSkew -= delay, clockLast = now5; } function nap() { var t0, t1 = taskHead, t2, time = Infinity; while (t1) { if (t1._call) { if (time > t1._time) time = t1._time; t0 = t1, t1 = t1._next; } else { t2 = t1._next, t1._next = null; t1 = t0 ? t0._next = t2 : taskHead = t2; } } taskTail = t0; sleep(time); } function sleep(time) { if (frame) return; if (timeout) timeout = clearTimeout(timeout); var delay = time - clockNow; if (delay > 24) { if (time < Infinity) timeout = setTimeout(wake, time - clock.now() - clockSkew); if (interval) interval = clearInterval(interval); } else { if (!interval) clockLast = clock.now(), interval = setInterval(poke, pokeDelay); frame = 1, setFrame(wake); } } // node_modules/d3-force-3d/src/lcg.js var a = 1664525; var c = 1013904223; var m = 4294967296; function lcg_default() { let s = 1; return () => (s = (a * s + c) % m) / m; } // node_modules/d3-force-3d/src/simulation.js var MAX_DIMENSIONS = 3; function x2(d) { return d.x; } function y2(d) { return d.y; } function z3(d) { return d.z; } var initialRadius = 10; var initialAngleRoll = Math.PI * (3 - Math.sqrt(5)); var initialAngleYaw = Math.PI * 20 / (9 + Math.sqrt(221)); function simulation_default(nodes, numDimensions) { numDimensions = numDimensions || 2; var nDim = Math.min(MAX_DIMENSIONS, Math.max(1, Math.round(numDimensions))), simulation, alpha = 1, alphaMin = 1e-3, alphaDecay = 1 - Math.pow(alphaMin, 1 / 300), alphaTarget = 0, velocityDecay = 0.6, forces = /* @__PURE__ */ new Map(), stepper = timer(step), event = dispatch_default("tick", "end"), random = lcg_default(); if (nodes == null) nodes = []; function step() { tick2(); event.call("tick", simulation); if (alpha < alphaMin) { stepper.stop(); event.call("end", simulation); } } function tick2(iterations) { var i, n = nodes.length, node; if (iterations === void 0) iterations = 1; for (var k = 0; k < iterations; ++k) { alpha += (alphaTarget - alpha) * alphaDecay; forces.forEach(function(force) { force(alpha); }); for (i = 0; i < n; ++i) { node = nodes[i]; if (node.fx == null) node.x += node.vx *= velocityDecay; else node.x = node.fx, node.vx = 0; if (nDim > 1) { if (node.fy == null) node.y += node.vy *= velocityDecay; else node.y = node.fy, node.vy = 0; } if (nDim > 2) { if (node.fz == null) node.z += node.vz *= velocityDecay; else node.z = node.fz, node.vz = 0; } } } return simulation; } function initializeNodes() { for (var i = 0, n = nodes.length, node; i < n; ++i) { node = nodes[i], node.index = i; if (node.fx != null) node.x = node.fx; if (node.fy != null) node.y = node.fy; if (node.fz != null) node.z = node.fz; if (isNaN(node.x) || nDim > 1 && isNaN(node.y) || nDim > 2 && isNaN(node.z)) { var radius = initialRadius * (nDim > 2 ? Math.cbrt(0.5 + i) : nDim > 1 ? Math.sqrt(0.5 + i) : i), rollAngle = i * initialAngleRoll, yawAngle = i * initialAngleYaw; if (nDim === 1) { node.x = radius; } else if (nDim === 2) { node.x = radius * Math.cos(rollAngle); node.y = radius * Math.sin(rollAngle); } else { node.x = radius * Math.sin(rollAngle) * Math.cos(yawAngle); node.y = radius * Math.cos(rollAngle); node.z = radius * Math.sin(rollAngle) * Math.sin(yawAngle); } } if (isNaN(node.vx) || nDim > 1 && isNaN(node.vy) || nDim > 2 && isNaN(node.vz)) { node.vx = 0; if (nDim > 1) { node.vy = 0; } if (nDim > 2) { node.vz = 0; } } } } function initializeForce(force) { if (force.initialize) force.initialize(nodes, random, nDim); return force; } initializeNodes(); return simulation = { tick: tick2, restart: function() { return stepper.restart(step), simulation; }, stop: function() { return stepper.stop(), simulation; }, numDimensions: function(_) { return arguments.length ? (nDim = Math.min(MAX_DIMENSIONS, Math.max(1, Math.round(_))), forces.forEach(initializeForce), simulation) : nDim; }, nodes: function(_) { return arguments.length ? (nodes = _, initializeNodes(), forces.forEach(initializeForce), simulation) : nodes; }, alpha: function(_) { return arguments.length ? (alpha = +_, simulation) : alpha; }, alphaMin: function(_) { return arguments.length ? (alphaMin = +_, simulation) : alphaMin; }, alphaDecay: function(_) { return arguments.length ? (alphaDecay = +_, simulation) : +alphaDecay; }, alphaTarget: function(_) { return arguments.length ? (alphaTarget = +_, simulation) : alphaTarget; }, velocityDecay: function(_) { return arguments.length ? (velocityDecay = 1 - _, simulation) : 1 - velocityDecay; }, randomSource: function(_) { return arguments.length ? (random = _, forces.forEach(initializeForce), simulation) : random; }, force: function(name, _) { return arguments.length > 1 ? (_ == null ? forces.delete(name) : forces.set(name, initializeForce(_)), simulation) : forces.get(name); }, find: function() { var args = Array.prototype.slice.call(arguments); var x3 = args.shift() || 0, y3 = (nDim > 1 ? args.shift() : null) || 0, z4 = (nDim > 2 ? args.shift() : null) || 0, radius = args.shift() || Infinity; var i = 0, n = nodes.length, dx, dy, dz, d2, node, closest; radius *= radius; for (i = 0; i < n; ++i) { node = nodes[i]; dx = x3 - node.x; dy = y3 - (node.y || 0); dz = z4 - (node.z || 0); d2 = dx * dx + dy * dy + dz * dz; if (d2 < radius) closest = node, radius = d2; } return closest; }, on: function(name, _) { return arguments.length > 1 ? (event.on(name, _), simulation) : event.on(name); } }; } // node_modules/d3-force-3d/src/manyBody.js function manyBody_default() { var nodes, nDim, node, random, alpha, strength = constant_default(-30), strengths, distanceMin2 = 1, distanceMax2 = Infinity, theta2 = 0.81; function force(_) { var i, n = nodes.length, tree = (nDim === 1 ? binarytree(nodes, x2) : nDim === 2 ? quadtree(nodes, x2, y2) : nDim === 3 ? octree(nodes, x2, y2, z3) : null).visitAfter(accumulate); for (alpha = _, i = 0; i < n; ++i) node = nodes[i], tree.visit(apply); } function initialize() { if (!nodes) return; var i, n = nodes.length, node2; strengths = new Array(n); for (i = 0; i < n; ++i) node2 = nodes[i], strengths[node2.index] = +strength(node2, i, nodes); } function accumulate(treeNode) { var strength2 = 0, q, c2, weight = 0, x3, y3, z4, i; var numChildren = treeNode.length; if (numChildren) { for (x3 = y3 = z4 = i = 0; i < numChildren; ++i) { if ((q = treeNode[i]) && (c2 = Math.abs(q.value))) { strength2 += q.value, weight += c2, x3 += c2 * (q.x || 0), y3 += c2 * (q.y || 0), z4 += c2 * (q.z || 0); } } strength2 *= Math.sqrt(4 / numChildren); treeNode.x = x3 / weight; if (nDim > 1) { treeNode.y = y3 / weight; } if (nDim > 2) { treeNode.z = z4 / weight; } } else { q = treeNode; q.x = q.data.x; if (nDim > 1) { q.y = q.data.y; } if (nDim > 2) { q.z = q.data.z; } do strength2 += strengths[q.data.index]; while (q = q.next); } treeNode.value = strength2; } function apply(treeNode, x1, arg1, arg2, arg3) { if (!treeNode.value) return true; var x22 = [arg1, arg2, arg3][nDim - 1]; var x3 = treeNode.x - node.x, y3 = nDim > 1 ? treeNode.y - node.y : 0, z4 = nDim > 2 ? treeNode.z - node.z : 0, w = x22 - x1, l = x3 * x3 + y3 * y3 + z4 * z4; if (w * w / theta2 < l) { if (l < distanceMax2) { if (x3 === 0) x3 = jiggle_default(random), l += x3 * x3; if (nDim > 1 && y3 === 0) y3 = jiggle_default(random), l += y3 * y3; if (nDim > 2 && z4 === 0) z4 = jiggle_default(random), l += z4 * z4; if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l); node.vx += x3 * treeNode.value * alpha / l; if (nDim > 1) { node.vy += y3 * treeNode.value * alpha / l; } if (nDim > 2) { node.vz += z4 * treeNode.value * alpha / l; } } return true; } else if (treeNode.length || l >= distanceMax2) return; if (treeNode.data !== node || treeNode.next) { if (x3 === 0) x3 = jiggle_default(random), l += x3 * x3; if (nDim > 1 && y3 === 0) y3 = jiggle_default(random), l += y3 * y3; if (nDim > 2 && z4 === 0) z4 = jiggle_default(random), l += z4 * z4; if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l); } do if (treeNode.data !== node) { w = strengths[treeNode.data.index] * alpha / l; node.vx += x3 * w; if (nDim > 1) { node.vy += y3 * w; } if (nDim > 2) { node.vz += z4 * w; } } while (treeNode = treeNode.next); } force.initialize = function(_nodes, ...args) { nodes = _nodes; random = args.find((arg) => typeof arg === "function") || Math.random; nDim = args.find((arg) => [1, 2, 3].includes(arg)) || 2; initialize(); }; force.strength = function(_) { return arguments.length ? (strength = typeof _ === "function" ? _ : constant_default(+_), initialize(), force) : strength; }; force.distanceMin = function(_) { return arguments.length ? (distanceMin2 = _ * _, force) : Math.sqrt(distanceMin2); }; force.distanceMax = function(_) { return arguments.length ? (distanceMax2 = _ * _, force) : Math.sqrt(distanceMax2); }; force.theta = function(_) { return arguments.length ? (theta2 = _ * _, force) : Math.sqrt(theta2); }; return force; } // node_modules/d3-force-3d/src/radial.js function radial_default(radius, x3, y3, z4) { var nodes, nDim, strength = constant_default(0.1), strengths, radiuses; if (typeof radius !== "function") radius = constant_default(+radius); if (x3 == null) x3 = 0; if (y3 == null) y3 = 0; if (z4 == null) z4 = 0; function force(alpha) { for (var i = 0, n = nodes.length; i < n; ++i) { var node = nodes[i], dx = node.x - x3 || 1e-6, dy = (node.y || 0) - y3 || 1e-6, dz = (node.z || 0) - z4 || 1e-6, r = Math.sqrt(dx * dx + dy * dy + dz * dz), k = (radiuses[i] - r) * strengths[i] * alpha / r; node.vx += dx * k; if (nDim > 1) { node.vy += dy * k; } if (nDim > 2) { node.vz += dz * k; } } } function initialize() { if (!nodes) return; var i, n = nodes.length; strengths = new Array(n); radiuses = new Array(n); for (i = 0; i < n; ++i) { radiuses[i] = +radius(nodes[i], i, nodes); strengths[i] = isNaN(radiuses[i]) ? 0 : +strength(nodes[i], i, nodes); } } force.initialize = function(initNodes, ...args) { nodes = initNodes; nDim = args.find((arg) => [1, 2, 3].includes(arg)) || 2; initialize(); }; force.strength = function(_) { return arguments.length ? (strength = typeof _ === "function" ? _ : constant_default(+_), initialize(), force) : strength; }; force.radius = function(_) { return arguments.length ? (radius = typeof _ === "function" ? _ : constant_default(+_), initialize(), force) : radius; }; force.x = function(_) { return arguments.length ? (x3 = +_, force) : x3; }; force.y = function(_) { return arguments.length ? (y3 = +_, force) : y3; }; force.z = function(_) { return arguments.length ? (z4 = +_, force) : z4; }; return force; } // node_modules/d3-force-3d/src/x.js function x_default4(x3) { var strength = constant_default(0.1), nodes, strengths, xz; if (typeof x3 !== "function") x3 = constant_default(x3 == null ? 0 : +x3); function force(alpha) { for (var i = 0, n = nodes.length, node; i < n; ++i) { node = nodes[i], node.vx += (xz[i] - node.x) * strengths[i] * alpha; } } function initialize() { if (!nodes) return; var i, n = nodes.length; strengths = new Array(n); xz = new Array(n); for (i = 0; i < n; ++i) { strengths[i] = isNaN(xz[i] = +x3(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes); } } force.initialize = function(_) { nodes = _; initialize(); }; force.strength = function(_) { return arguments.length ? (strength = typeof _ === "function" ? _ : constant_default(+_), initialize(), force) : strength; }; force.x = function(_) { return arguments.length ? (x3 = typeof _ === "function" ? _ : constant_default(+_), initialize(), force) : x3; }; return force; } // node_modules/d3-force-3d/src/y.js function y_default3(y3) { var strength = constant_default(0.1), nodes, strengths, yz; if (typeof y3 !== "function") y3 = constant_default(y3 == null ? 0 : +y3); function force(alpha) { for (var i = 0, n = nodes.length, node; i < n; ++i) { node = nodes[i], node.vy += (yz[i] - node.y) * strengths[i] * alpha; } } function initialize() { if (!nodes) return; var i, n = nodes.length; strengths = new Array(n); yz = new Array(n); for (i = 0; i < n; ++i) { strengths[i] = isNaN(yz[i] = +y3(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes); } } force.initialize = function(_) { nodes = _; initialize(); }; force.strength = function(_) { return arguments.length ? (strength = typeof _ === "function" ? _ : constant_default(+_), initialize(), force) : strength; }; force.y = function(_) { return arguments.length ? (y3 = typeof _ === "function" ? _ : constant_default(+_), initialize(), force) : y3; }; return force; } // node_modules/d3-force-3d/src/z.js function z_default2(z4) { var strength = constant_default(0.1), nodes, strengths, zz; if (typeof z4 !== "function") z4 = constant_default(z4 == null ? 0 : +z4); function force(alpha) { for (var i = 0, n = nodes.length, node; i < n; ++i) { node = nodes[i], node.vz += (zz[i] - node.z) * strengths[i] * alpha; } } function initialize() { if (!nodes) return; var i, n = nodes.length; strengths = new Array(n); zz = new Array(n); for (i = 0; i < n; ++i) { strengths[i] = isNaN(zz[i] = +z4(nodes[i], i, nodes)) ? 0 : +strength(nodes[i], i, nodes); } } force.initialize = function(_) { nodes = _; initialize(); }; force.strength = function(_) { return arguments.length ? (strength = typeof _ === "function" ? _ : constant_default(+_), initialize(), force) : strength; }; force.z = function(_) { return arguments.length ? (z4 = typeof _ === "function" ? _ : constant_default(+_), initialize(), force) : z4; }; return force; } // node_modules/three-forcegraph/dist/three-forcegraph.mjs var import_ngraph = __toESM(require_ngraph2(), 1); var import_ngraph2 = __toESM(require_ngraph5(), 1); // node_modules/lodash-es/_freeGlobal.js var freeGlobal = typeof global == "object" && global && global.Object === Object && global; var freeGlobal_default = freeGlobal; // node_modules/lodash-es/_root.js var freeSelf = typeof self == "object" && self && self.Object === Object && self; var root = freeGlobal_default || freeSelf || Function("return this")(); var root_default4 = root; // node_modules/lodash-es/_Symbol.js var Symbol2 = root_default4.Symbol; var Symbol_default = Symbol2; // node_modules/lodash-es/_getRawTag.js var objectProto = Object.prototype; var hasOwnProperty = objectProto.hasOwnProperty; var nativeObjectToString = objectProto.toString; var symToStringTag = Symbol_default ? Symbol_default.toStringTag : void 0; function getRawTag(value) { var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag]; try { value[symToStringTag] = void 0; var unmasked = true; } catch (e) { } var result = nativeObjectToString.call(value); if (unmasked) { if (isOwn) { value[symToStringTag] = tag; } else { delete value[symToStringTag]; } } return result; } var getRawTag_default = getRawTag; // node_modules/lodash-es/_objectToString.js var objectProto2 = Object.prototype; var nativeObjectToString2 = objectProto2.toString; function objectToString(value) { return nativeObjectToString2.call(value); } var objectToString_default = objectToString; // node_modules/lodash-es/_baseGetTag.js var nullTag = "[object Null]"; var undefinedTag = "[object Undefined]"; var symToStringTag2 = Symbol_default ? Symbol_default.toStringTag : void 0; function baseGetTag(value) { if (value == null) { return value === void 0 ? undefinedTag : nullTag; } return symToStringTag2 && symToStringTag2 in Object(value) ? getRawTag_default(value) : objectToString_default(value); } var baseGetTag_default = baseGetTag; // node_modules/lodash-es/isObjectLike.js function isObjectLike(value) { return value != null && typeof value == "object"; } var isObjectLike_default = isObjectLike; // node_modules/lodash-es/isSymbol.js var symbolTag = "[object Symbol]"; function isSymbol(value) { return typeof value == "symbol" || isObjectLike_default(value) && baseGetTag_default(value) == symbolTag; } var isSymbol_default = isSymbol; // node_modules/lodash-es/_trimmedEndIndex.js var reWhitespace = /\s/; function trimmedEndIndex(string) { var index6 = string.length; while (index6-- && reWhitespace.test(string.charAt(index6))) { } return index6; } var trimmedEndIndex_default = trimmedEndIndex; // node_modules/lodash-es/_baseTrim.js var reTrimStart = /^\s+/; function baseTrim(string) { return string ? string.slice(0, trimmedEndIndex_default(string) + 1).replace(reTrimStart, "") : string; } var baseTrim_default = baseTrim; // node_modules/lodash-es/isObject.js function isObject(value) { var type = typeof value; return value != null && (type == "object" || type == "function"); } var isObject_default = isObject; // node_modules/lodash-es/toNumber.js var NAN = 0 / 0; var reIsBadHex = /^[-+]0x[0-9a-f]+$/i; var reIsBinary = /^0b[01]+$/i; var reIsOctal = /^0o[0-7]+$/i; var freeParseInt = parseInt; function toNumber(value) { if (typeof value == "number") { return value; } if (isSymbol_default(value)) { return NAN; } if (isObject_default(value)) { var other = typeof value.valueOf == "function" ? value.valueOf() : value; value = isObject_default(other) ? other + "" : other; } if (typeof value != "string") { return value === 0 ? value : +value; } value = baseTrim_default(value); var isBinary = reIsBinary.test(value); return isBinary || reIsOctal.test(value) ? freeParseInt(value.slice(2), isBinary ? 2 : 8) : reIsBadHex.test(value) ? NAN : +value; } var toNumber_default = toNumber; // node_modules/lodash-es/now.js var now3 = function() { return root_default4.Date.now(); }; var now_default = now3; // node_modules/lodash-es/debounce.js var FUNC_ERROR_TEXT = "Expected a function"; var nativeMax = Math.max; var nativeMin = Math.min; function debounce(func, wait, options) { var lastArgs, lastThis, maxWait, result, timerId, lastCallTime, lastInvokeTime = 0, leading = false, maxing = false, trailing = true; if (typeof func != "function") { throw new TypeError(FUNC_ERROR_TEXT); } wait = toNumber_default(wait) || 0; if (isObject_default(options)) { leading = !!options.leading; maxing = "maxWait" in options; maxWait = maxing ? nativeMax(toNumber_default(options.maxWait) || 0, wait) : maxWait; trailing = "trailing" in options ? !!options.trailing : trailing; } function invokeFunc(time) { var args = lastArgs, thisArg = lastThis; lastArgs = lastThis = void 0; lastInvokeTime = time; result = func.apply(thisArg, args); return result; } function leadingEdge(time) { lastInvokeTime = time; timerId = setTimeout(timerExpired, wait); return leading ? invokeFunc(time) : result; } function remainingWait(time) { var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime, timeWaiting = wait - timeSinceLastCall; return maxing ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting; } function shouldInvoke(time) { var timeSinceLastCall = time - lastCallTime, timeSinceLastInvoke = time - lastInvokeTime; return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait; } function timerExpired() { var time = now_default(); if (shouldInvoke(time)) { return trailingEdge(time); } timerId = setTimeout(timerExpired, remainingWait(time)); } function trailingEdge(time) { timerId = void 0; if (trailing && lastArgs) { return invokeFunc(time); } lastArgs = lastThis = void 0; return result; } function cancel() { if (timerId !== void 0) { clearTimeout(timerId); } lastInvokeTime = 0; lastArgs = lastCallTime = lastThis = timerId = void 0; } function flush() { return timerId === void 0 ? result : trailingEdge(now_default()); } function debounced() { var time = now_default(), isInvoking = shouldInvoke(time); lastArgs = arguments; lastThis = this; lastCallTime = time; if (isInvoking) { if (timerId === void 0) { return leadingEdge(lastCallTime); } if (maxing) { clearTimeout(timerId); timerId = setTimeout(timerExpired, wait); return invokeFunc(lastCallTime); } } if (timerId === void 0) { timerId = setTimeout(timerExpired, wait); } return result; } debounced.cancel = cancel; debounced.flush = flush; return debounced; } var debounce_default = debounce; // node_modules/three-forcegraph/node_modules/kapsule/dist/kapsule.mjs function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x3, _r, _arr = [], _n = true, _d2 = false; try { if (_x3 = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = false; } else for (; !(_n = (_s = _x3.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = true) ; } catch (err) { _d2 = true, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d2) throw _e; } } return _arr; } } 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, _toPropertyKey(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 _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== void 0) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); } var Prop = /* @__PURE__ */ _createClass(function Prop2(name, _ref) { var _ref$default = _ref["default"], defaultVal = _ref$default === void 0 ? null : _ref$default, _ref$triggerUpdate = _ref.triggerUpdate, triggerUpdate = _ref$triggerUpdate === void 0 ? true : _ref$triggerUpdate, _ref$onChange = _ref.onChange, onChange13 = _ref$onChange === void 0 ? function(newVal, state) { } : _ref$onChange; _classCallCheck(this, Prop2); this.name = name; this.defaultVal = defaultVal; this.triggerUpdate = triggerUpdate; this.onChange = onChange13; }); function index2(_ref2) { var _ref2$stateInit = _ref2.stateInit, stateInit4 = _ref2$stateInit === void 0 ? function() { return {}; } : _ref2$stateInit, _ref2$props = _ref2.props, rawProps = _ref2$props === void 0 ? {} : _ref2$props, _ref2$methods = _ref2.methods, methods = _ref2$methods === void 0 ? {} : _ref2$methods, _ref2$aliases = _ref2.aliases, aliases = _ref2$aliases === void 0 ? {} : _ref2$aliases, _ref2$init = _ref2.init, initFn = _ref2$init === void 0 ? function() { } : _ref2$init, _ref2$update = _ref2.update, updateFn = _ref2$update === void 0 ? function() { } : _ref2$update; var props = Object.keys(rawProps).map(function(propName) { return new Prop(propName, rawProps[propName]); }); return function() { var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}; var state = Object.assign( {}, stateInit4 instanceof Function ? stateInit4(options) : stateInit4, // Support plain objects for backwards compatibility { initialised: false } ); var changedProps = {}; function comp(nodeElement) { initStatic(nodeElement, options); digest(); return comp; } var initStatic = function initStatic2(nodeElement, options2) { initFn.call(comp, nodeElement, state, options2); state.initialised = true; }; var digest = debounce_default(function() { if (!state.initialised) { return; } updateFn.call(comp, state, changedProps); changedProps = {}; }, 1); props.forEach(function(prop) { comp[prop.name] = getSetProp(prop); function getSetProp(_ref3) { var prop2 = _ref3.name, _ref3$triggerUpdate = _ref3.triggerUpdate, redigest = _ref3$triggerUpdate === void 0 ? false : _ref3$triggerUpdate, _ref3$onChange = _ref3.onChange, onChange13 = _ref3$onChange === void 0 ? function(newVal, state2) { } : _ref3$onChange, _ref3$defaultVal = _ref3.defaultVal, defaultVal = _ref3$defaultVal === void 0 ? null : _ref3$defaultVal; return function(_) { var curVal = state[prop2]; if (!arguments.length) { return curVal; } var val = _ === void 0 ? defaultVal : _; state[prop2] = val; onChange13.call(comp, val, state, curVal); !changedProps.hasOwnProperty(prop2) && (changedProps[prop2] = curVal); if (redigest) { digest(); } return comp; }; } }); Object.keys(methods).forEach(function(methodName) { comp[methodName] = function() { var _methods$methodName; for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return (_methods$methodName = methods[methodName]).call.apply(_methods$methodName, [comp, state].concat(args)); }; }); Object.entries(aliases).forEach(function(_ref4) { var _ref5 = _slicedToArray(_ref4, 2), alias = _ref5[0], target = _ref5[1]; return comp[alias] = comp[target]; }); comp.resetProps = function() { props.forEach(function(prop) { comp[prop.name](prop.defaultVal); }); return comp; }; comp.resetProps(); state._rerender = digest; return comp; }; } // node_modules/accessor-fn/dist/accessor-fn.mjs var index3 = function(p) { return typeof p === "function" ? p : typeof p === "string" ? function(obj) { return obj[p]; } : function(obj) { return p; }; }; // node_modules/internmap/src/index.js var InternMap = class extends Map { constructor(entries, key = keyof) { super(); Object.defineProperties(this, { _intern: { value: /* @__PURE__ */ new Map() }, _key: { value: key } }); if (entries != null) for (const [key2, value] of entries) this.set(key2, value); } get(key) { return super.get(intern_get(this, key)); } has(key) { return super.has(intern_get(this, key)); } set(key, value) { return super.set(intern_set(this, key), value); } delete(key) { return super.delete(intern_delete(this, key)); } }; function intern_get({ _intern, _key }, value) { const key = _key(value); return _intern.has(key) ? _intern.get(key) : value; } function intern_set({ _intern, _key }, value) { const key = _key(value); if (_intern.has(key)) return _intern.get(key); _intern.set(key, value); return value; } function intern_delete({ _intern, _key }, value) { const key = _key(value); if (_intern.has(key)) { value = _intern.get(key); _intern.delete(key); } return value; } function keyof(value) { return value !== null && typeof value === "object" ? value.valueOf() : value; } // node_modules/d3-array/src/max.js function max(values, valueof) { let max2; if (valueof === void 0) { for (const value of values) { if (value != null && (max2 < value || max2 === void 0 && value >= value)) { max2 = value; } } } else { let index6 = -1; for (let value of values) { if ((value = valueof(value, ++index6, values)) != null && (max2 < value || max2 === void 0 && value >= value)) { max2 = value; } } } return max2; } // node_modules/d3-array/src/min.js function min(values, valueof) { let min2; if (valueof === void 0) { for (const value of values) { if (value != null && (min2 > value || min2 === void 0 && value >= value)) { min2 = value; } } } else { let index6 = -1; for (let value of values) { if ((value = valueof(value, ++index6, values)) != null && (min2 > value || min2 === void 0 && value >= value)) { min2 = value; } } } return min2; } // node_modules/index-array-by/dist/index-array-by.mjs function _iterableToArrayLimit2(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x3, _r, _arr = [], _n = true, _d2 = false; try { if (_x3 = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = false; } else for (; !(_n = (_s = _x3.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = true) ; } catch (err) { _d2 = true, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d2) throw _e; } } return _arr; } } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _slicedToArray2(arr, i) { return _arrayWithHoles2(arr) || _iterableToArrayLimit2(arr, i) || _unsupportedIterableToArray2(arr, i) || _nonIterableRest2(); } function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray2(arr) || _nonIterableSpread(); } function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray2(arr); } function _arrayWithHoles2(arr) { if (Array.isArray(arr)) return arr; } function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _unsupportedIterableToArray2(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray2(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray2(o, minLen); } function _arrayLikeToArray2(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _nonIterableRest2() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _toPrimitive2(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== void 0) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _toPropertyKey2(arg) { var key = _toPrimitive2(arg, "string"); return typeof key === "symbol" ? key : String(key); } var index4 = function() { var list = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : []; var keyAccessors = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : []; var multiItem = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : true; var flattenKeys = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : false; var keys = (keyAccessors instanceof Array ? keyAccessors.length ? keyAccessors : [void 0] : [keyAccessors]).map(function(key) { return { keyAccessor: key, isProp: !(key instanceof Function) }; }); var indexedResult = list.reduce(function(res, item) { var iterObj = res; var itemVal = item; keys.forEach(function(_ref, idx) { var keyAccessor = _ref.keyAccessor, isProp = _ref.isProp; var key; if (isProp) { var _itemVal = itemVal, propVal = _itemVal[keyAccessor], rest = _objectWithoutProperties(_itemVal, [keyAccessor].map(_toPropertyKey2)); key = propVal; itemVal = rest; } else { key = keyAccessor(itemVal, idx); } if (idx + 1 < keys.length) { if (!iterObj.hasOwnProperty(key)) { iterObj[key] = {}; } iterObj = iterObj[key]; } else { if (multiItem) { if (!iterObj.hasOwnProperty(key)) { iterObj[key] = []; } iterObj[key].push(itemVal); } else { iterObj[key] = itemVal; } } }); return res; }, {}); if (multiItem instanceof Function) { (function reduce(node) { var level = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 1; if (level === keys.length) { Object.keys(node).forEach(function(k) { return node[k] = multiItem(node[k]); }); } else { Object.values(node).forEach(function(child) { return reduce(child, level + 1); }); } })(indexedResult); } var result = indexedResult; if (flattenKeys) { result = []; (function flatten3(node) { var accKeys = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : []; if (accKeys.length === keys.length) { result.push({ keys: accKeys, vals: node }); } else { Object.entries(node).forEach(function(_ref2) { var _ref3 = _slicedToArray2(_ref2, 2), key = _ref3[0], val = _ref3[1]; return flatten3(val, [].concat(_toConsumableArray(accKeys), [key])); }); } })(indexedResult); if (keyAccessors instanceof Array && keyAccessors.length === 0 && result.length === 1) { result[0].keys = []; } } return result; }; // node_modules/data-joint/dist/data-joint.mjs function _iterableToArrayLimit3(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x3, _r, _arr = [], _n = true, _d2 = false; try { if (_x3 = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = false; } else for (; !(_n = (_s = _x3.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = true) ; } catch (err) { _d2 = true, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d2) throw _e; } } return _arr; } } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function(sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread2(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), true).forEach(function(key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } function _defineProperty(obj, key, value) { key = _toPropertyKey3(key); if (key in obj) { Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _objectWithoutPropertiesLoose2(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } function _objectWithoutProperties2(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose2(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _slicedToArray3(arr, i) { return _arrayWithHoles3(arr) || _iterableToArrayLimit3(arr, i) || _unsupportedIterableToArray3(arr, i) || _nonIterableRest3(); } function _toConsumableArray2(arr) { return _arrayWithoutHoles2(arr) || _iterableToArray2(arr) || _unsupportedIterableToArray3(arr) || _nonIterableSpread2(); } function _arrayWithoutHoles2(arr) { if (Array.isArray(arr)) return _arrayLikeToArray3(arr); } function _arrayWithHoles3(arr) { if (Array.isArray(arr)) return arr; } function _iterableToArray2(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _unsupportedIterableToArray3(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray3(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray3(o, minLen); } function _arrayLikeToArray3(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _nonIterableSpread2() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _nonIterableRest3() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _toPrimitive3(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== void 0) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _toPropertyKey3(arg) { var key = _toPrimitive3(arg, "string"); return typeof key === "symbol" ? key : String(key); } var _excluded = ["createObj", "updateObj", "exitObj", "objBindAttr", "dataBindAttr"]; function diffArrays(prev, next, idAccessor) { var result = { enter: [], update: [], exit: [] }; if (!idAccessor) { var prevSet = new Set(prev); var nextSet = new Set(next); new Set([].concat(_toConsumableArray2(prevSet), _toConsumableArray2(nextSet))).forEach(function(item) { var type = !prevSet.has(item) ? "enter" : !nextSet.has(item) ? "exit" : "update"; result[type].push(type === "update" ? [item, item] : item); }); } else { var prevById = index4(prev, idAccessor, false); var nextById = index4(next, idAccessor, false); var byId = Object.assign({}, prevById, nextById); Object.entries(byId).forEach(function(_ref) { var _ref2 = _slicedToArray3(_ref, 2), id = _ref2[0], item = _ref2[1]; var type = !prevById.hasOwnProperty(id) ? "enter" : !nextById.hasOwnProperty(id) ? "exit" : "update"; result[type].push(type === "update" ? [prevById[id], nextById[id]] : item); }); } return result; } function dataBindDiff(data, existingObjs, _ref3) { var _ref3$objBindAttr = _ref3.objBindAttr, objBindAttr = _ref3$objBindAttr === void 0 ? "__obj" : _ref3$objBindAttr, _ref3$dataBindAttr = _ref3.dataBindAttr, dataBindAttr = _ref3$dataBindAttr === void 0 ? "__data" : _ref3$dataBindAttr, idAccessor = _ref3.idAccessor, _ref3$purge = _ref3.purge, purge = _ref3$purge === void 0 ? false : _ref3$purge; var isObjValid = function isObjValid2(obj) { return obj.hasOwnProperty(dataBindAttr); }; var removeObjs = existingObjs.filter(function(obj) { return !isObjValid(obj); }); var prevD = existingObjs.filter(isObjValid).map(function(obj) { return obj[dataBindAttr]; }); var nextD = data; var diff = purge ? { enter: nextD, exit: prevD, update: [] } : diffArrays(prevD, nextD, idAccessor); diff.update = diff.update.map(function(_ref4) { var _ref5 = _slicedToArray3(_ref4, 2), prevD2 = _ref5[0], nextD2 = _ref5[1]; if (prevD2 !== nextD2) { nextD2[objBindAttr] = prevD2[objBindAttr]; nextD2[objBindAttr][dataBindAttr] = nextD2; } return nextD2; }); diff.exit = diff.exit.concat(removeObjs.map(function(obj) { return _defineProperty({}, objBindAttr, obj); })); return diff; } function viewDigest(data, existingObjs, appendObj, removeObj, _ref7) { var _ref7$createObj = _ref7.createObj, createObj = _ref7$createObj === void 0 ? function(d) { return {}; } : _ref7$createObj, _ref7$updateObj = _ref7.updateObj, updateObj = _ref7$updateObj === void 0 ? function(obj, d) { } : _ref7$updateObj, _ref7$exitObj = _ref7.exitObj, exitObj = _ref7$exitObj === void 0 ? function(obj) { } : _ref7$exitObj, _ref7$objBindAttr = _ref7.objBindAttr, objBindAttr = _ref7$objBindAttr === void 0 ? "__obj" : _ref7$objBindAttr, _ref7$dataBindAttr = _ref7.dataBindAttr, dataBindAttr = _ref7$dataBindAttr === void 0 ? "__data" : _ref7$dataBindAttr, dataDiffOptions = _objectWithoutProperties2(_ref7, _excluded); var _dataBindDiff = dataBindDiff(data, existingObjs, _objectSpread2({ objBindAttr, dataBindAttr }, dataDiffOptions)), enter = _dataBindDiff.enter, update4 = _dataBindDiff.update, exit = _dataBindDiff.exit; exit.forEach(function(d) { var obj = d[objBindAttr]; delete d[objBindAttr]; exitObj(obj); removeObj(obj); }); var newObjs = createObjs(enter); var pointsData = [].concat(_toConsumableArray2(enter), _toConsumableArray2(update4)); updateObjs(pointsData); newObjs.forEach(appendObj); function createObjs(data2) { var newObjs2 = []; data2.forEach(function(d) { var obj = createObj(d); if (obj) { obj[dataBindAttr] = d; d[objBindAttr] = obj; newObjs2.push(obj); } }); return newObjs2; } function updateObjs(data2) { data2.forEach(function(d) { var obj = d[objBindAttr]; if (obj) { obj[dataBindAttr] = d; updateObj(obj, d); } }); } } // node_modules/d3-scale/src/init.js function initRange(domain, range) { switch (arguments.length) { case 0: break; case 1: this.range(domain); break; default: this.range(range).domain(domain); break; } return this; } // node_modules/d3-scale/src/ordinal.js var implicit = Symbol("implicit"); function ordinal() { var index6 = new InternMap(), domain = [], range = [], unknown = implicit; function scale(d) { let i = index6.get(d); if (i === void 0) { if (unknown !== implicit) return unknown; index6.set(d, i = domain.push(d) - 1); } return range[i % range.length]; } scale.domain = function(_) { if (!arguments.length) return domain.slice(); domain = [], index6 = new InternMap(); for (const value of _) { if (index6.has(value)) continue; index6.set(value, domain.push(value) - 1); } return scale; }; scale.range = function(_) { return arguments.length ? (range = Array.from(_), scale) : range.slice(); }; scale.unknown = function(_) { return arguments.length ? (unknown = _, scale) : unknown; }; scale.copy = function() { return ordinal(domain, range).unknown(unknown); }; initRange.apply(scale, arguments); return scale; } // node_modules/d3-scale-chromatic/src/colors.js function colors_default(specifier) { var n = specifier.length / 6 | 0, colors = new Array(n), i = 0; while (i < n) colors[i] = "#" + specifier.slice(i * 6, ++i * 6); return colors; } // node_modules/d3-scale-chromatic/src/categorical/Paired.js var Paired_default = colors_default("a6cee31f78b4b2df8a33a02cfb9a99e31a1cfdbf6fff7f00cab2d66a3d9affff99b15928"); // node_modules/tinycolor2/esm/tinycolor.js function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) { return typeof obj2; } : function(obj2) { return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2; }, _typeof(obj); } var trimLeft = /^\s+/; var trimRight = /\s+$/; function tinycolor(color, opts) { color = color ? color : ""; opts = opts || {}; if (color instanceof tinycolor) { return color; } if (!(this instanceof tinycolor)) { return new tinycolor(color, opts); } var rgb2 = inputToRGB(color); this._originalInput = color, this._r = rgb2.r, this._g = rgb2.g, this._b = rgb2.b, this._a = rgb2.a, this._roundA = Math.round(100 * this._a) / 100, this._format = opts.format || rgb2.format; this._gradientType = opts.gradientType; if (this._r < 1) this._r = Math.round(this._r); if (this._g < 1) this._g = Math.round(this._g); if (this._b < 1) this._b = Math.round(this._b); this._ok = rgb2.ok; } tinycolor.prototype = { isDark: function isDark() { return this.getBrightness() < 128; }, isLight: function isLight() { return !this.isDark(); }, isValid: function isValid2() { return this._ok; }, getOriginalInput: function getOriginalInput() { return this._originalInput; }, getFormat: function getFormat() { return this._format; }, getAlpha: function getAlpha() { return this._a; }, getBrightness: function getBrightness() { var rgb2 = this.toRgb(); return (rgb2.r * 299 + rgb2.g * 587 + rgb2.b * 114) / 1e3; }, getLuminance: function getLuminance() { var rgb2 = this.toRgb(); var RsRGB, GsRGB, BsRGB, R, G, B; RsRGB = rgb2.r / 255; GsRGB = rgb2.g / 255; BsRGB = rgb2.b / 255; if (RsRGB <= 0.03928) R = RsRGB / 12.92; else R = Math.pow((RsRGB + 0.055) / 1.055, 2.4); if (GsRGB <= 0.03928) G = GsRGB / 12.92; else G = Math.pow((GsRGB + 0.055) / 1.055, 2.4); if (BsRGB <= 0.03928) B = BsRGB / 12.92; else B = Math.pow((BsRGB + 0.055) / 1.055, 2.4); return 0.2126 * R + 0.7152 * G + 0.0722 * B; }, setAlpha: function setAlpha(value) { this._a = boundAlpha(value); this._roundA = Math.round(100 * this._a) / 100; return this; }, toHsv: function toHsv() { var hsv = rgbToHsv(this._r, this._g, this._b); return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this._a }; }, toHsvString: function toHsvString() { var hsv = rgbToHsv(this._r, this._g, this._b); var h = Math.round(hsv.h * 360), s = Math.round(hsv.s * 100), v = Math.round(hsv.v * 100); return this._a == 1 ? "hsv(" + h + ", " + s + "%, " + v + "%)" : "hsva(" + h + ", " + s + "%, " + v + "%, " + this._roundA + ")"; }, toHsl: function toHsl() { var hsl = rgbToHsl(this._r, this._g, this._b); return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this._a }; }, toHslString: function toHslString() { var hsl = rgbToHsl(this._r, this._g, this._b); var h = Math.round(hsl.h * 360), s = Math.round(hsl.s * 100), l = Math.round(hsl.l * 100); return this._a == 1 ? "hsl(" + h + ", " + s + "%, " + l + "%)" : "hsla(" + h + ", " + s + "%, " + l + "%, " + this._roundA + ")"; }, toHex: function toHex(allow3Char) { return rgbToHex(this._r, this._g, this._b, allow3Char); }, toHexString: function toHexString(allow3Char) { return "#" + this.toHex(allow3Char); }, toHex8: function toHex8(allow4Char) { return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char); }, toHex8String: function toHex8String(allow4Char) { return "#" + this.toHex8(allow4Char); }, toRgb: function toRgb() { return { r: Math.round(this._r), g: Math.round(this._g), b: Math.round(this._b), a: this._a }; }, toRgbString: function toRgbString() { return this._a == 1 ? "rgb(" + Math.round(this._r) + ", " + Math.round(this._g) + ", " + Math.round(this._b) + ")" : "rgba(" + Math.round(this._r) + ", " + Math.round(this._g) + ", " + Math.round(this._b) + ", " + this._roundA + ")"; }, toPercentageRgb: function toPercentageRgb() { return { r: Math.round(bound01(this._r, 255) * 100) + "%", g: Math.round(bound01(this._g, 255) * 100) + "%", b: Math.round(bound01(this._b, 255) * 100) + "%", a: this._a }; }, toPercentageRgbString: function toPercentageRgbString() { return this._a == 1 ? "rgb(" + Math.round(bound01(this._r, 255) * 100) + "%, " + Math.round(bound01(this._g, 255) * 100) + "%, " + Math.round(bound01(this._b, 255) * 100) + "%)" : "rgba(" + Math.round(bound01(this._r, 255) * 100) + "%, " + Math.round(bound01(this._g, 255) * 100) + "%, " + Math.round(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")"; }, toName: function toName() { if (this._a === 0) { return "transparent"; } if (this._a < 1) { return false; } return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false; }, toFilter: function toFilter(secondColor) { var hex8String = "#" + rgbaToArgbHex(this._r, this._g, this._b, this._a); var secondHex8String = hex8String; var gradientType = this._gradientType ? "GradientType = 1, " : ""; if (secondColor) { var s = tinycolor(secondColor); secondHex8String = "#" + rgbaToArgbHex(s._r, s._g, s._b, s._a); } return "progid:DXImageTransform.Microsoft.gradient(" + gradientType + "startColorstr=" + hex8String + ",endColorstr=" + secondHex8String + ")"; }, toString: function toString(format2) { var formatSet = !!format2; format2 = format2 || this._format; var formattedString = false; var hasAlpha = this._a < 1 && this._a >= 0; var needsAlphaFormat = !formatSet && hasAlpha && (format2 === "hex" || format2 === "hex6" || format2 === "hex3" || format2 === "hex4" || format2 === "hex8" || format2 === "name"); if (needsAlphaFormat) { if (format2 === "name" && this._a === 0) { return this.toName(); } return this.toRgbString(); } if (format2 === "rgb") { formattedString = this.toRgbString(); } if (format2 === "prgb") { formattedString = this.toPercentageRgbString(); } if (format2 === "hex" || format2 === "hex6") { formattedString = this.toHexString(); } if (format2 === "hex3") { formattedString = this.toHexString(true); } if (format2 === "hex4") { formattedString = this.toHex8String(true); } if (format2 === "hex8") { formattedString = this.toHex8String(); } if (format2 === "name") { formattedString = this.toName(); } if (format2 === "hsl") { formattedString = this.toHslString(); } if (format2 === "hsv") { formattedString = this.toHsvString(); } return formattedString || this.toHexString(); }, clone: function clone() { return tinycolor(this.toString()); }, _applyModification: function _applyModification(fn, args) { var color = fn.apply(null, [this].concat([].slice.call(args))); this._r = color._r; this._g = color._g; this._b = color._b; this.setAlpha(color._a); return this; }, lighten: function lighten() { return this._applyModification(_lighten, arguments); }, brighten: function brighten() { return this._applyModification(_brighten, arguments); }, darken: function darken() { return this._applyModification(_darken, arguments); }, desaturate: function desaturate() { return this._applyModification(_desaturate, arguments); }, saturate: function saturate() { return this._applyModification(_saturate, arguments); }, greyscale: function greyscale() { return this._applyModification(_greyscale, arguments); }, spin: function spin() { return this._applyModification(_spin, arguments); }, _applyCombination: function _applyCombination(fn, args) { return fn.apply(null, [this].concat([].slice.call(args))); }, analogous: function analogous() { return this._applyCombination(_analogous, arguments); }, complement: function complement() { return this._applyCombination(_complement, arguments); }, monochromatic: function monochromatic() { return this._applyCombination(_monochromatic, arguments); }, splitcomplement: function splitcomplement() { return this._applyCombination(_splitcomplement, arguments); }, // Disabled until https://github.com/bgrins/TinyColor/issues/254 // polyad: function (number) { // return this._applyCombination(polyad, [number]); // }, triad: function triad() { return this._applyCombination(polyad, [3]); }, tetrad: function tetrad() { return this._applyCombination(polyad, [4]); } }; tinycolor.fromRatio = function(color, opts) { if (_typeof(color) == "object") { var newColor = {}; for (var i in color) { if (color.hasOwnProperty(i)) { if (i === "a") { newColor[i] = color[i]; } else { newColor[i] = convertToPercentage(color[i]); } } } color = newColor; } return tinycolor(color, opts); }; function inputToRGB(color) { var rgb2 = { r: 0, g: 0, b: 0 }; var a2 = 1; var s = null; var v = null; var l = null; var ok = false; var format2 = false; if (typeof color == "string") { color = stringInputToObject(color); } if (_typeof(color) == "object") { if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) { rgb2 = rgbToRgb(color.r, color.g, color.b); ok = true; format2 = String(color.r).substr(-1) === "%" ? "prgb" : "rgb"; } else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) { s = convertToPercentage(color.s); v = convertToPercentage(color.v); rgb2 = hsvToRgb(color.h, s, v); ok = true; format2 = "hsv"; } else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) { s = convertToPercentage(color.s); l = convertToPercentage(color.l); rgb2 = hslToRgb(color.h, s, l); ok = true; format2 = "hsl"; } if (color.hasOwnProperty("a")) { a2 = color.a; } } a2 = boundAlpha(a2); return { ok, format: color.format || format2, r: Math.min(255, Math.max(rgb2.r, 0)), g: Math.min(255, Math.max(rgb2.g, 0)), b: Math.min(255, Math.max(rgb2.b, 0)), a: a2 }; } function rgbToRgb(r, g, b) { return { r: bound01(r, 255) * 255, g: bound01(g, 255) * 255, b: bound01(b, 255) * 255 }; } function rgbToHsl(r, g, b) { r = bound01(r, 255); g = bound01(g, 255); b = bound01(b, 255); var max2 = Math.max(r, g, b), min2 = Math.min(r, g, b); var h, s, l = (max2 + min2) / 2; if (max2 == min2) { h = s = 0; } else { var d = max2 - min2; s = l > 0.5 ? d / (2 - max2 - min2) : d / (max2 + min2); switch (max2) { case r: h = (g - b) / d + (g < b ? 6 : 0); break; case g: h = (b - r) / d + 2; break; case b: h = (r - g) / d + 4; break; } h /= 6; } return { h, s, l }; } function hslToRgb(h, s, l) { var r, g, b; h = bound01(h, 360); s = bound01(s, 100); l = bound01(l, 100); function hue2rgb3(p2, q2, t) { if (t < 0) t += 1; if (t > 1) t -= 1; if (t < 1 / 6) return p2 + (q2 - p2) * 6 * t; if (t < 1 / 2) return q2; if (t < 2 / 3) return p2 + (q2 - p2) * (2 / 3 - t) * 6; return p2; } if (s === 0) { r = g = b = l; } else { var q = l < 0.5 ? l * (1 + s) : l + s - l * s; var p = 2 * l - q; r = hue2rgb3(p, q, h + 1 / 3); g = hue2rgb3(p, q, h); b = hue2rgb3(p, q, h - 1 / 3); } return { r: r * 255, g: g * 255, b: b * 255 }; } function rgbToHsv(r, g, b) { r = bound01(r, 255); g = bound01(g, 255); b = bound01(b, 255); var max2 = Math.max(r, g, b), min2 = Math.min(r, g, b); var h, s, v = max2; var d = max2 - min2; s = max2 === 0 ? 0 : d / max2; if (max2 == min2) { h = 0; } else { switch (max2) { case r: h = (g - b) / d + (g < b ? 6 : 0); break; case g: h = (b - r) / d + 2; break; case b: h = (r - g) / d + 4; break; } h /= 6; } return { h, s, v }; } function hsvToRgb(h, s, v) { h = bound01(h, 360) * 6; s = bound01(s, 100); v = bound01(v, 100); var i = Math.floor(h), f = h - i, p = v * (1 - s), q = v * (1 - f * s), t = v * (1 - (1 - f) * s), mod = i % 6, r = [v, q, p, p, t, v][mod], g = [t, v, v, q, p, p][mod], b = [p, p, t, v, v, q][mod]; return { r: r * 255, g: g * 255, b: b * 255 }; } function rgbToHex(r, g, b, allow3Char) { var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))]; if (allow3Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1)) { return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0); } return hex.join(""); } function rgbaToHex(r, g, b, a2, allow4Char) { var hex = [pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16)), pad2(convertDecimalToHex(a2))]; if (allow4Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1) && hex[3].charAt(0) == hex[3].charAt(1)) { return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0); } return hex.join(""); } function rgbaToArgbHex(r, g, b, a2) { var hex = [pad2(convertDecimalToHex(a2)), pad2(Math.round(r).toString(16)), pad2(Math.round(g).toString(16)), pad2(Math.round(b).toString(16))]; return hex.join(""); } tinycolor.equals = function(color1, color2) { if (!color1 || !color2) return false; return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString(); }; tinycolor.random = function() { return tinycolor.fromRatio({ r: Math.random(), g: Math.random(), b: Math.random() }); }; function _desaturate(color, amount) { amount = amount === 0 ? 0 : amount || 10; var hsl = tinycolor(color).toHsl(); hsl.s -= amount / 100; hsl.s = clamp01(hsl.s); return tinycolor(hsl); } function _saturate(color, amount) { amount = amount === 0 ? 0 : amount || 10; var hsl = tinycolor(color).toHsl(); hsl.s += amount / 100; hsl.s = clamp01(hsl.s); return tinycolor(hsl); } function _greyscale(color) { return tinycolor(color).desaturate(100); } function _lighten(color, amount) { amount = amount === 0 ? 0 : amount || 10; var hsl = tinycolor(color).toHsl(); hsl.l += amount / 100; hsl.l = clamp01(hsl.l); return tinycolor(hsl); } function _brighten(color, amount) { amount = amount === 0 ? 0 : amount || 10; var rgb2 = tinycolor(color).toRgb(); rgb2.r = Math.max(0, Math.min(255, rgb2.r - Math.round(255 * -(amount / 100)))); rgb2.g = Math.max(0, Math.min(255, rgb2.g - Math.round(255 * -(amount / 100)))); rgb2.b = Math.max(0, Math.min(255, rgb2.b - Math.round(255 * -(amount / 100)))); return tinycolor(rgb2); } function _darken(color, amount) { amount = amount === 0 ? 0 : amount || 10; var hsl = tinycolor(color).toHsl(); hsl.l -= amount / 100; hsl.l = clamp01(hsl.l); return tinycolor(hsl); } function _spin(color, amount) { var hsl = tinycolor(color).toHsl(); var hue = (hsl.h + amount) % 360; hsl.h = hue < 0 ? 360 + hue : hue; return tinycolor(hsl); } function _complement(color) { var hsl = tinycolor(color).toHsl(); hsl.h = (hsl.h + 180) % 360; return tinycolor(hsl); } function polyad(color, number) { if (isNaN(number) || number <= 0) { throw new Error("Argument to polyad must be a positive number"); } var hsl = tinycolor(color).toHsl(); var result = [tinycolor(color)]; var step = 360 / number; for (var i = 1; i < number; i++) { result.push(tinycolor({ h: (hsl.h + i * step) % 360, s: hsl.s, l: hsl.l })); } return result; } function _splitcomplement(color) { var hsl = tinycolor(color).toHsl(); var h = hsl.h; return [tinycolor(color), tinycolor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l }), tinycolor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l })]; } function _analogous(color, results, slices) { results = results || 6; slices = slices || 30; var hsl = tinycolor(color).toHsl(); var part = 360 / slices; var ret = [tinycolor(color)]; for (hsl.h = (hsl.h - (part * results >> 1) + 720) % 360; --results; ) { hsl.h = (hsl.h + part) % 360; ret.push(tinycolor(hsl)); } return ret; } function _monochromatic(color, results) { results = results || 6; var hsv = tinycolor(color).toHsv(); var h = hsv.h, s = hsv.s, v = hsv.v; var ret = []; var modification = 1 / results; while (results--) { ret.push(tinycolor({ h, s, v })); v = (v + modification) % 1; } return ret; } tinycolor.mix = function(color1, color2, amount) { amount = amount === 0 ? 0 : amount || 50; var rgb1 = tinycolor(color1).toRgb(); var rgb2 = tinycolor(color2).toRgb(); var p = amount / 100; var rgba2 = { r: (rgb2.r - rgb1.r) * p + rgb1.r, g: (rgb2.g - rgb1.g) * p + rgb1.g, b: (rgb2.b - rgb1.b) * p + rgb1.b, a: (rgb2.a - rgb1.a) * p + rgb1.a }; return tinycolor(rgba2); }; tinycolor.readability = function(color1, color2) { var c1 = tinycolor(color1); var c2 = tinycolor(color2); return (Math.max(c1.getLuminance(), c2.getLuminance()) + 0.05) / (Math.min(c1.getLuminance(), c2.getLuminance()) + 0.05); }; tinycolor.isReadable = function(color1, color2, wcag2) { var readability = tinycolor.readability(color1, color2); var wcag2Parms, out; out = false; wcag2Parms = validateWCAG2Parms(wcag2); switch (wcag2Parms.level + wcag2Parms.size) { case "AAsmall": case "AAAlarge": out = readability >= 4.5; break; case "AAlarge": out = readability >= 3; break; case "AAAsmall": out = readability >= 7; break; } return out; }; tinycolor.mostReadable = function(baseColor, colorList, args) { var bestColor = null; var bestScore = 0; var readability; var includeFallbackColors, level, size; args = args || {}; includeFallbackColors = args.includeFallbackColors; level = args.level; size = args.size; for (var i = 0; i < colorList.length; i++) { readability = tinycolor.readability(baseColor, colorList[i]); if (readability > bestScore) { bestScore = readability; bestColor = tinycolor(colorList[i]); } } if (tinycolor.isReadable(baseColor, bestColor, { level, size }) || !includeFallbackColors) { return bestColor; } else { args.includeFallbackColors = false; return tinycolor.mostReadable(baseColor, ["#fff", "#000"], args); } }; var names = tinycolor.names = { aliceblue: "f0f8ff", antiquewhite: "faebd7", aqua: "0ff", aquamarine: "7fffd4", azure: "f0ffff", beige: "f5f5dc", bisque: "ffe4c4", black: "000", blanchedalmond: "ffebcd", blue: "00f", blueviolet: "8a2be2", brown: "a52a2a", burlywood: "deb887", burntsienna: "ea7e5d", cadetblue: "5f9ea0", chartreuse: "7fff00", chocolate: "d2691e", coral: "ff7f50", cornflowerblue: "6495ed", cornsilk: "fff8dc", crimson: "dc143c", cyan: "0ff", darkblue: "00008b", darkcyan: "008b8b", darkgoldenrod: "b8860b", darkgray: "a9a9a9", darkgreen: "006400", darkgrey: "a9a9a9", darkkhaki: "bdb76b", darkmagenta: "8b008b", darkolivegreen: "556b2f", darkorange: "ff8c00", darkorchid: "9932cc", darkred: "8b0000", darksalmon: "e9967a", darkseagreen: "8fbc8f", darkslateblue: "483d8b", darkslategray: "2f4f4f", darkslategrey: "2f4f4f", darkturquoise: "00ced1", darkviolet: "9400d3", deeppink: "ff1493", deepskyblue: "00bfff", dimgray: "696969", dimgrey: "696969", dodgerblue: "1e90ff", firebrick: "b22222", floralwhite: "fffaf0", forestgreen: "228b22", fuchsia: "f0f", gainsboro: "dcdcdc", ghostwhite: "f8f8ff", gold: "ffd700", goldenrod: "daa520", gray: "808080", green: "008000", greenyellow: "adff2f", grey: "808080", honeydew: "f0fff0", hotpink: "ff69b4", indianred: "cd5c5c", indigo: "4b0082", ivory: "fffff0", khaki: "f0e68c", lavender: "e6e6fa", lavenderblush: "fff0f5", lawngreen: "7cfc00", lemonchiffon: "fffacd", lightblue: "add8e6", lightcoral: "f08080", lightcyan: "e0ffff", lightgoldenrodyellow: "fafad2", lightgray: "d3d3d3", lightgreen: "90ee90", lightgrey: "d3d3d3", lightpink: "ffb6c1", lightsalmon: "ffa07a", lightseagreen: "20b2aa", lightskyblue: "87cefa", lightslategray: "789", lightslategrey: "789", lightsteelblue: "b0c4de", lightyellow: "ffffe0", lime: "0f0", limegreen: "32cd32", linen: "faf0e6", magenta: "f0f", maroon: "800000", mediumaquamarine: "66cdaa", mediumblue: "0000cd", mediumorchid: "ba55d3", mediumpurple: "9370db", mediumseagreen: "3cb371", mediumslateblue: "7b68ee", mediumspringgreen: "00fa9a", mediumturquoise: "48d1cc", mediumvioletred: "c71585", midnightblue: "191970", mintcream: "f5fffa", mistyrose: "ffe4e1", moccasin: "ffe4b5", navajowhite: "ffdead", navy: "000080", oldlace: "fdf5e6", olive: "808000", olivedrab: "6b8e23", orange: "ffa500", orangered: "ff4500", orchid: "da70d6", palegoldenrod: "eee8aa", palegreen: "98fb98", paleturquoise: "afeeee", palevioletred: "db7093", papayawhip: "ffefd5", peachpuff: "ffdab9", peru: "cd853f", pink: "ffc0cb", plum: "dda0dd", powderblue: "b0e0e6", purple: "800080", rebeccapurple: "663399", red: "f00", rosybrown: "bc8f8f", royalblue: "4169e1", saddlebrown: "8b4513", salmon: "fa8072", sandybrown: "f4a460", seagreen: "2e8b57", seashell: "fff5ee", sienna: "a0522d", silver: "c0c0c0", skyblue: "87ceeb", slateblue: "6a5acd", slategray: "708090", slategrey: "708090", snow: "fffafa", springgreen: "00ff7f", steelblue: "4682b4", tan: "d2b48c", teal: "008080", thistle: "d8bfd8", tomato: "ff6347", turquoise: "40e0d0", violet: "ee82ee", wheat: "f5deb3", white: "fff", whitesmoke: "f5f5f5", yellow: "ff0", yellowgreen: "9acd32" }; var hexNames = tinycolor.hexNames = flip(names); function flip(o) { var flipped = {}; for (var i in o) { if (o.hasOwnProperty(i)) { flipped[o[i]] = i; } } return flipped; } function boundAlpha(a2) { a2 = parseFloat(a2); if (isNaN(a2) || a2 < 0 || a2 > 1) { a2 = 1; } return a2; } function bound01(n, max2) { if (isOnePointZero(n)) n = "100%"; var processPercent = isPercentage(n); n = Math.min(max2, Math.max(0, parseFloat(n))); if (processPercent) { n = parseInt(n * max2, 10) / 100; } if (Math.abs(n - max2) < 1e-6) { return 1; } return n % max2 / parseFloat(max2); } function clamp01(val) { return Math.min(1, Math.max(0, val)); } function parseIntFromHex(val) { return parseInt(val, 16); } function isOnePointZero(n) { return typeof n == "string" && n.indexOf(".") != -1 && parseFloat(n) === 1; } function isPercentage(n) { return typeof n === "string" && n.indexOf("%") != -1; } function pad2(c2) { return c2.length == 1 ? "0" + c2 : "" + c2; } function convertToPercentage(n) { if (n <= 1) { n = n * 100 + "%"; } return n; } function convertDecimalToHex(d) { return Math.round(parseFloat(d) * 255).toString(16); } function convertHexToDecimal(h) { return parseIntFromHex(h) / 255; } var matchers = function() { var CSS_INTEGER = "[-\\+]?\\d+%?"; var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?"; var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")"; var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?"; var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?"; return { CSS_UNIT: new RegExp(CSS_UNIT), rgb: new RegExp("rgb" + PERMISSIVE_MATCH3), rgba: new RegExp("rgba" + PERMISSIVE_MATCH4), hsl: new RegExp("hsl" + PERMISSIVE_MATCH3), hsla: new RegExp("hsla" + PERMISSIVE_MATCH4), hsv: new RegExp("hsv" + PERMISSIVE_MATCH3), hsva: new RegExp("hsva" + PERMISSIVE_MATCH4), hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/, hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/, hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/, hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/ }; }(); function isValidCSSUnit(color) { return !!matchers.CSS_UNIT.exec(color); } function stringInputToObject(color) { color = color.replace(trimLeft, "").replace(trimRight, "").toLowerCase(); var named = false; if (names[color]) { color = names[color]; named = true; } else if (color == "transparent") { return { r: 0, g: 0, b: 0, a: 0, format: "name" }; } var match; if (match = matchers.rgb.exec(color)) { return { r: match[1], g: match[2], b: match[3] }; } if (match = matchers.rgba.exec(color)) { return { r: match[1], g: match[2], b: match[3], a: match[4] }; } if (match = matchers.hsl.exec(color)) { return { h: match[1], s: match[2], l: match[3] }; } if (match = matchers.hsla.exec(color)) { return { h: match[1], s: match[2], l: match[3], a: match[4] }; } if (match = matchers.hsv.exec(color)) { return { h: match[1], s: match[2], v: match[3] }; } if (match = matchers.hsva.exec(color)) { return { h: match[1], s: match[2], v: match[3], a: match[4] }; } if (match = matchers.hex8.exec(color)) { return { r: parseIntFromHex(match[1]), g: parseIntFromHex(match[2]), b: parseIntFromHex(match[3]), a: convertHexToDecimal(match[4]), format: named ? "name" : "hex8" }; } if (match = matchers.hex6.exec(color)) { return { r: parseIntFromHex(match[1]), g: parseIntFromHex(match[2]), b: parseIntFromHex(match[3]), format: named ? "name" : "hex" }; } if (match = matchers.hex4.exec(color)) { return { r: parseIntFromHex(match[1] + "" + match[1]), g: parseIntFromHex(match[2] + "" + match[2]), b: parseIntFromHex(match[3] + "" + match[3]), a: convertHexToDecimal(match[4] + "" + match[4]), format: named ? "name" : "hex8" }; } if (match = matchers.hex3.exec(color)) { return { r: parseIntFromHex(match[1] + "" + match[1]), g: parseIntFromHex(match[2] + "" + match[2]), b: parseIntFromHex(match[3] + "" + match[3]), format: named ? "name" : "hex" }; } return false; } function validateWCAG2Parms(parms) { var level, size; parms = parms || { level: "AA", size: "small" }; level = (parms.level || "AA").toUpperCase(); size = (parms.size || "small").toLowerCase(); if (level !== "AA" && level !== "AAA") { level = "AA"; } if (size !== "small" && size !== "large") { size = "small"; } return { level, size }; } // node_modules/three-forcegraph/dist/three-forcegraph.mjs function _iterableToArrayLimit4(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x3, _r, _arr = [], _n = true, _d2 = false; try { if (_x3 = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = false; } else for (; !(_n = (_s = _x3.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = true) ; } catch (err) { _d2 = true, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d2) throw _e; } } return _arr; } } function ownKeys2(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function(sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread22(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys2(Object(source), true).forEach(function(key) { _defineProperty2(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys2(Object(source)).forEach(function(key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } function _typeof2(obj) { "@babel/helpers - typeof"; return _typeof2 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(obj2) { return typeof obj2; } : function(obj2) { return obj2 && "function" == typeof Symbol && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2; }, _typeof2(obj); } function _classCallCheck2(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties2(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, _toPropertyKey4(descriptor.key), descriptor); } } function _createClass2(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties2(Constructor.prototype, protoProps); if (staticProps) _defineProperties2(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _defineProperty2(obj, key, value) { key = _toPropertyKey4(key); if (key in obj) { Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf3(o2) { return o2.__proto__ || Object.getPrototypeOf(o2); }; return _getPrototypeOf(o); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf3(o2, p2) { o2.__proto__ = p2; return o2; }; return _setPrototypeOf(o, p); } 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 _construct(Parent, args, Class) { if (_isNativeReflectConstruct()) { _construct = Reflect.construct.bind(); } else { _construct = function _construct3(Parent2, args2, Class2) { var a2 = [null]; a2.push.apply(a2, args2); var Constructor = Function.bind.apply(Parent2, a2); var instance = new Constructor(); if (Class2) _setPrototypeOf(instance, Class2.prototype); return instance; }; } return _construct.apply(null, arguments); } function _objectWithoutPropertiesLoose3(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } function _objectWithoutProperties3(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose3(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _assertThisInitialized(self2) { if (self2 === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self2; } function _possibleConstructorReturn(self2, 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(self2); } 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 _slicedToArray4(arr, i) { return _arrayWithHoles4(arr) || _iterableToArrayLimit4(arr, i) || _unsupportedIterableToArray4(arr, i) || _nonIterableRest4(); } function _toConsumableArray3(arr) { return _arrayWithoutHoles3(arr) || _iterableToArray3(arr) || _unsupportedIterableToArray4(arr) || _nonIterableSpread3(); } function _arrayWithoutHoles3(arr) { if (Array.isArray(arr)) return _arrayLikeToArray4(arr); } function _arrayWithHoles4(arr) { if (Array.isArray(arr)) return arr; } function _iterableToArray3(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _unsupportedIterableToArray4(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray4(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray4(o, minLen); } function _arrayLikeToArray4(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _nonIterableSpread3() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _nonIterableRest4() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _toPrimitive4(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== void 0) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _toPropertyKey4(arg) { var key = _toPrimitive4(arg, "string"); return typeof key === "symbol" ? key : String(key); } var materialDispose = function materialDispose2(material) { if (material instanceof Array) { material.forEach(materialDispose2); } else { if (material.map) { material.map.dispose(); } material.dispose(); } }; var deallocate = function deallocate2(obj) { if (obj.geometry) { obj.geometry.dispose(); } if (obj.material) { materialDispose(obj.material); } if (obj.texture) { obj.texture.dispose(); } if (obj.children) { obj.children.forEach(deallocate2); } }; var emptyObject = function emptyObject2(obj) { while (obj.children.length) { var childObj = obj.children[0]; obj.remove(childObj); deallocate(childObj); } }; var _excluded2 = ["objFilter"]; function threeDigest(data, scene3) { var _ref = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, _ref$objFilter = _ref.objFilter, objFilter = _ref$objFilter === void 0 ? function() { return true; } : _ref$objFilter, options = _objectWithoutProperties3(_ref, _excluded2); return viewDigest(data, scene3.children.filter(objFilter), function(obj) { return scene3.add(obj); }, function(obj) { scene3.remove(obj); emptyObject(obj); }, _objectSpread22({ objBindAttr: "__threeObj" }, options)); } var colorStr2Hex = function colorStr2Hex2(str) { return isNaN(str) ? parseInt(tinycolor(str).toHex(), 16) : str; }; var colorAlpha = function colorAlpha2(str) { return isNaN(str) ? tinycolor(str).getAlpha() : 1; }; var autoColorScale = ordinal(Paired_default); function autoColorObjects(objects, colorByAccessor, colorField) { if (!colorByAccessor || typeof colorField !== "string") return; objects.filter(function(obj) { return !obj[colorField]; }).forEach(function(obj) { obj[colorField] = autoColorScale(colorByAccessor(obj)); }); } function getDagDepths(_ref, idAccessor) { var nodes = _ref.nodes, links = _ref.links; var _ref2 = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, _ref2$nodeFilter = _ref2.nodeFilter, nodeFilter = _ref2$nodeFilter === void 0 ? function() { return true; } : _ref2$nodeFilter, _ref2$onLoopError = _ref2.onLoopError, onLoopError = _ref2$onLoopError === void 0 ? function(loopIds) { throw "Invalid DAG structure! Found cycle in node path: ".concat(loopIds.join(" -> "), "."); } : _ref2$onLoopError; var graph2 = {}; nodes.forEach(function(node) { return graph2[idAccessor(node)] = { data: node, out: [], depth: -1, skip: !nodeFilter(node) }; }); links.forEach(function(_ref3) { var source = _ref3.source, target = _ref3.target; var sourceId = getNodeId(source); var targetId = getNodeId(target); if (!graph2.hasOwnProperty(sourceId)) throw "Missing source node with id: ".concat(sourceId); if (!graph2.hasOwnProperty(targetId)) throw "Missing target node with id: ".concat(targetId); var sourceNode = graph2[sourceId]; var targetNode = graph2[targetId]; sourceNode.out.push(targetNode); function getNodeId(node) { return _typeof2(node) === "object" ? idAccessor(node) : node; } }); var foundLoops = []; traverse(Object.values(graph2)); var nodeDepths = Object.assign.apply(Object, [{}].concat(_toConsumableArray3(Object.entries(graph2).filter(function(_ref4) { var _ref5 = _slicedToArray4(_ref4, 2), node = _ref5[1]; return !node.skip; }).map(function(_ref6) { var _ref7 = _slicedToArray4(_ref6, 2), id = _ref7[0], node = _ref7[1]; return _defineProperty2({}, id, node.depth); })))); return nodeDepths; function traverse(nodes2) { var nodeStack = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : []; var currentDepth = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 0; var _loop = function _loop2() { var node = nodes2[i]; if (nodeStack.indexOf(node) !== -1) { var loop = [].concat(_toConsumableArray3(nodeStack.slice(nodeStack.indexOf(node))), [node]).map(function(d) { return idAccessor(d.data); }); if (!foundLoops.some(function(foundLoop) { return foundLoop.length === loop.length && foundLoop.every(function(id, idx) { return id === loop[idx]; }); })) { foundLoops.push(loop); onLoopError(loop); } return "continue"; } if (currentDepth > node.depth) { node.depth = currentDepth; traverse(node.out, [].concat(_toConsumableArray3(nodeStack), [node]), currentDepth + (node.skip ? 0 : 1)); } }; for (var i = 0, l = nodes2.length; i < l; i++) { var _ret = _loop(); if (_ret === "continue") continue; } } } var three$1 = window.THREE ? window.THREE : { Group: Group2, Mesh: Mesh2, MeshLambertMaterial, Color: Color2, BufferGeometry: BufferGeometry2, BufferAttribute: BufferAttribute2, Matrix4: Matrix42, Vector3: Vector32, SphereGeometry, CylinderGeometry, TubeGeometry, ConeGeometry, Line, LineBasicMaterial, QuadraticBezierCurve3, CubicBezierCurve3, Box3: Box32 }; var ngraph = { graph: import_ngraph.default, forcelayout: import_ngraph2.default }; var DAG_LEVEL_NODE_RATIO = 2; var setAttributeFn = new three$1.BufferGeometry().setAttribute ? "setAttribute" : "addAttribute"; var applyMatrix4Fn = new three$1.BufferGeometry().applyMatrix4 ? "applyMatrix4" : "applyMatrix"; var ForceGraph = index2({ props: { jsonUrl: { onChange: function onChange(jsonUrl, state) { var _this = this; if (jsonUrl && !state.fetchingJson) { state.fetchingJson = true; state.onLoading(); fetch(jsonUrl).then(function(r) { return r.json(); }).then(function(json) { state.fetchingJson = false; state.onFinishLoading(json); _this.graphData(json); }); } }, triggerUpdate: false }, graphData: { "default": { nodes: [], links: [] }, onChange: function onChange2(graphData, state) { state.engineRunning = false; } }, numDimensions: { "default": 3, onChange: function onChange3(numDim, state) { var chargeForce = state.d3ForceLayout.force("charge"); if (chargeForce) { chargeForce.strength(numDim > 2 ? -60 : -30); } if (numDim < 3) { eraseDimension(state.graphData.nodes, "z"); } if (numDim < 2) { eraseDimension(state.graphData.nodes, "y"); } function eraseDimension(nodes, dim) { nodes.forEach(function(d) { delete d[dim]; delete d["v".concat(dim)]; }); } } }, dagMode: { onChange: function onChange4(dagMode, state) { !dagMode && state.forceEngine === "d3" && (state.graphData.nodes || []).forEach(function(n) { return n.fx = n.fy = n.fz = void 0; }); } }, dagLevelDistance: {}, dagNodeFilter: { "default": function _default(node) { return true; } }, onDagError: { triggerUpdate: false }, nodeRelSize: { "default": 4 }, // volume per val unit nodeId: { "default": "id" }, nodeVal: { "default": "val" }, nodeResolution: { "default": 8 }, // how many slice segments in the sphere's circumference nodeColor: { "default": "color" }, nodeAutoColorBy: {}, nodeOpacity: { "default": 0.75 }, nodeVisibility: { "default": true }, nodeThreeObject: {}, nodeThreeObjectExtend: { "default": false }, nodePositionUpdate: { triggerUpdate: false }, // custom function to call for updating the node's position. Signature: (threeObj, { x, y, z}, node). If the function returns a truthy value, the regular node position update will not run. linkSource: { "default": "source" }, linkTarget: { "default": "target" }, linkVisibility: { "default": true }, linkColor: { "default": "color" }, linkAutoColorBy: {}, linkOpacity: { "default": 0.2 }, linkWidth: {}, // Rounded to nearest decimal. For falsy values use dimensionless line with 1px regardless of distance. linkResolution: { "default": 6 }, // how many radial segments in each line tube's geometry linkCurvature: { "default": 0, triggerUpdate: false }, // line curvature radius (0: straight, 1: semi-circle) linkCurveRotation: { "default": 0, triggerUpdate: false }, // line curve rotation along the line axis (0: interection with XY plane, PI: upside down) linkMaterial: {}, linkThreeObject: {}, linkThreeObjectExtend: { "default": false }, linkPositionUpdate: { triggerUpdate: false }, // custom function to call for updating the link's position. Signature: (threeObj, { start: { x, y, z}, end: { x, y, z }}, link). If the function returns a truthy value, the regular link position update will not run. linkDirectionalArrowLength: { "default": 0 }, linkDirectionalArrowColor: {}, linkDirectionalArrowRelPos: { "default": 0.5, triggerUpdate: false }, // value between 0<>1 indicating the relative pos along the (exposed) line linkDirectionalArrowResolution: { "default": 8 }, // how many slice segments in the arrow's conic circumference linkDirectionalParticles: { "default": 0 }, // animate photons travelling in the link direction linkDirectionalParticleSpeed: { "default": 0.01, triggerUpdate: false }, // in link length ratio per frame linkDirectionalParticleWidth: { "default": 0.5 }, linkDirectionalParticleColor: {}, linkDirectionalParticleResolution: { "default": 4 }, // how many slice segments in the particle sphere's circumference forceEngine: { "default": "d3" }, // d3 or ngraph d3AlphaMin: { "default": 0 }, d3AlphaDecay: { "default": 0.0228, triggerUpdate: false, onChange: function onChange5(alphaDecay, state) { state.d3ForceLayout.alphaDecay(alphaDecay); } }, d3AlphaTarget: { "default": 0, triggerUpdate: false, onChange: function onChange6(alphaTarget, state) { state.d3ForceLayout.alphaTarget(alphaTarget); } }, d3VelocityDecay: { "default": 0.4, triggerUpdate: false, onChange: function onChange7(velocityDecay, state) { state.d3ForceLayout.velocityDecay(velocityDecay); } }, ngraphPhysics: { "default": { // defaults from https://github.com/anvaka/ngraph.physics.simulator/blob/master/index.js timeStep: 20, gravity: -1.2, theta: 0.8, springLength: 30, springCoefficient: 8e-4, dragCoefficient: 0.02 } }, warmupTicks: { "default": 0, triggerUpdate: false }, // how many times to tick the force engine at init before starting to render cooldownTicks: { "default": Infinity, triggerUpdate: false }, cooldownTime: { "default": 15e3, triggerUpdate: false }, // ms onLoading: { "default": function _default2() { }, triggerUpdate: false }, onFinishLoading: { "default": function _default3() { }, triggerUpdate: false }, onUpdate: { "default": function _default4() { }, triggerUpdate: false }, onFinishUpdate: { "default": function _default5() { }, triggerUpdate: false }, onEngineTick: { "default": function _default6() { }, triggerUpdate: false }, onEngineStop: { "default": function _default7() { }, triggerUpdate: false } }, methods: { refresh: function refresh(state) { state._flushObjects = true; state._rerender(); return this; }, // Expose d3 forces for external manipulation d3Force: function d3Force(state, forceName, forceFn) { if (forceFn === void 0) { return state.d3ForceLayout.force(forceName); } state.d3ForceLayout.force(forceName, forceFn); return this; }, d3ReheatSimulation: function d3ReheatSimulation(state) { state.d3ForceLayout.alpha(1); this.resetCountdown(); return this; }, // reset cooldown state resetCountdown: function resetCountdown(state) { state.cntTicks = 0; state.startTickTime = new Date(); state.engineRunning = true; return this; }, tickFrame: function tickFrame(state) { var isD3Sim = state.forceEngine !== "ngraph"; if (state.engineRunning) { layoutTick(); } updateArrows(); updatePhotons(); return this; function layoutTick() { if (++state.cntTicks > state.cooldownTicks || new Date() - state.startTickTime > state.cooldownTime || isD3Sim && state.d3AlphaMin > 0 && state.d3ForceLayout.alpha() < state.d3AlphaMin) { state.engineRunning = false; state.onEngineStop(); } else { state.layout[isD3Sim ? "tick" : "step"](); state.onEngineTick(); } var nodeThreeObjectExtendAccessor = index3(state.nodeThreeObjectExtend); state.graphData.nodes.forEach(function(node) { var obj = node.__threeObj; if (!obj) return; var pos = isD3Sim ? node : state.layout.getNodePosition(node[state.nodeId]); var extendedObj = nodeThreeObjectExtendAccessor(node); if (!state.nodePositionUpdate || !state.nodePositionUpdate(extendedObj ? obj.children[0] : obj, { x: pos.x, y: pos.y, z: pos.z }, node) || extendedObj) { obj.position.x = pos.x; obj.position.y = pos.y || 0; obj.position.z = pos.z || 0; } }); var linkWidthAccessor = index3(state.linkWidth); var linkCurvatureAccessor = index3(state.linkCurvature); var linkCurveRotationAccessor = index3(state.linkCurveRotation); var linkThreeObjectExtendAccessor = index3(state.linkThreeObjectExtend); state.graphData.links.forEach(function(link) { var lineObj = link.__lineObj; if (!lineObj) return; var pos = isD3Sim ? link : state.layout.getLinkPosition(state.layout.graph.getLink(link.source, link.target).id); var start = pos[isD3Sim ? "source" : "from"]; var end = pos[isD3Sim ? "target" : "to"]; if (!start || !end || !start.hasOwnProperty("x") || !end.hasOwnProperty("x")) return; calcLinkCurve(link); var extendedObj = linkThreeObjectExtendAccessor(link); if (state.linkPositionUpdate && state.linkPositionUpdate( extendedObj ? lineObj.children[1] : lineObj, // pass child custom object if extending the default { start: { x: start.x, y: start.y, z: start.z }, end: { x: end.x, y: end.y, z: end.z } }, link ) && !extendedObj) { return; } var curveResolution = 30; var curve = link.__curve; var line = lineObj.children.length ? lineObj.children[0] : lineObj; if (line.type === "Line") { if (!curve) { var linePos = line.geometry.getAttribute("position"); if (!linePos || !linePos.array || linePos.array.length !== 6) { line.geometry[setAttributeFn]("position", linePos = new three$1.BufferAttribute(new Float32Array(2 * 3), 3)); } linePos.array[0] = start.x; linePos.array[1] = start.y || 0; linePos.array[2] = start.z || 0; linePos.array[3] = end.x; linePos.array[4] = end.y || 0; linePos.array[5] = end.z || 0; linePos.needsUpdate = true; } else { line.geometry.setFromPoints(curve.getPoints(curveResolution)); } line.geometry.computeBoundingSphere(); } else if (line.type === "Mesh") { if (!curve) { if (!line.geometry.type.match(/^Cylinder(Buffer)?Geometry$/)) { var linkWidth = Math.ceil(linkWidthAccessor(link) * 10) / 10; var r = linkWidth / 2; var geometry = new three$1.CylinderGeometry(r, r, 1, state.linkResolution, 1, false); geometry[applyMatrix4Fn](new three$1.Matrix4().makeTranslation(0, 1 / 2, 0)); geometry[applyMatrix4Fn](new three$1.Matrix4().makeRotationX(Math.PI / 2)); line.geometry.dispose(); line.geometry = geometry; } var vStart = new three$1.Vector3(start.x, start.y || 0, start.z || 0); var vEnd = new three$1.Vector3(end.x, end.y || 0, end.z || 0); var distance = vStart.distanceTo(vEnd); line.position.x = vStart.x; line.position.y = vStart.y; line.position.z = vStart.z; line.scale.z = distance; line.parent.localToWorld(vEnd); line.lookAt(vEnd); } else { if (!line.geometry.type.match(/^Tube(Buffer)?Geometry$/)) { line.position.set(0, 0, 0); line.rotation.set(0, 0, 0); line.scale.set(1, 1, 1); } var _linkWidth = Math.ceil(linkWidthAccessor(link) * 10) / 10; var _r = _linkWidth / 2; var _geometry2 = new three$1.TubeGeometry(curve, curveResolution, _r, state.linkResolution, false); line.geometry.dispose(); line.geometry = _geometry2; } } }); function calcLinkCurve(link) { var pos = isD3Sim ? link : state.layout.getLinkPosition(state.layout.graph.getLink(link.source, link.target).id); var start = pos[isD3Sim ? "source" : "from"]; var end = pos[isD3Sim ? "target" : "to"]; if (!start || !end || !start.hasOwnProperty("x") || !end.hasOwnProperty("x")) return; var curvature = linkCurvatureAccessor(link); if (!curvature) { link.__curve = null; } else { var vStart = new three$1.Vector3(start.x, start.y || 0, start.z || 0); var vEnd = new three$1.Vector3(end.x, end.y || 0, end.z || 0); var l = vStart.distanceTo(vEnd); var curve; var curveRotation = linkCurveRotationAccessor(link); if (l > 0) { var dx = end.x - start.x; var dy = end.y - start.y || 0; var vLine = new three$1.Vector3().subVectors(vEnd, vStart); var cp = vLine.clone().multiplyScalar(curvature).cross(dx !== 0 || dy !== 0 ? new three$1.Vector3(0, 0, 1) : new three$1.Vector3(0, 1, 0)).applyAxisAngle(vLine.normalize(), curveRotation).add(new three$1.Vector3().addVectors(vStart, vEnd).divideScalar(2)); curve = new three$1.QuadraticBezierCurve3(vStart, cp, vEnd); } else { var d = curvature * 70; var endAngle = -curveRotation; var startAngle = endAngle + Math.PI / 2; curve = new three$1.CubicBezierCurve3(vStart, new three$1.Vector3(d * Math.cos(startAngle), d * Math.sin(startAngle), 0).add(vStart), new three$1.Vector3(d * Math.cos(endAngle), d * Math.sin(endAngle), 0).add(vStart), vEnd); } link.__curve = curve; } } } function updateArrows() { var arrowRelPosAccessor = index3(state.linkDirectionalArrowRelPos); var arrowLengthAccessor = index3(state.linkDirectionalArrowLength); var nodeValAccessor = index3(state.nodeVal); state.graphData.links.forEach(function(link) { var arrowObj = link.__arrowObj; if (!arrowObj) return; var pos = isD3Sim ? link : state.layout.getLinkPosition(state.layout.graph.getLink(link.source, link.target).id); var start = pos[isD3Sim ? "source" : "from"]; var end = pos[isD3Sim ? "target" : "to"]; if (!start || !end || !start.hasOwnProperty("x") || !end.hasOwnProperty("x")) return; var startR = Math.cbrt(Math.max(0, nodeValAccessor(start) || 1)) * state.nodeRelSize; var endR = Math.cbrt(Math.max(0, nodeValAccessor(end) || 1)) * state.nodeRelSize; var arrowLength = arrowLengthAccessor(link); var arrowRelPos = arrowRelPosAccessor(link); var getPosAlongLine = link.__curve ? function(t) { return link.__curve.getPoint(t); } : function(t) { var iplt = function iplt2(dim, start2, end2, t2) { return start2[dim] + (end2[dim] - start2[dim]) * t2 || 0; }; return { x: iplt("x", start, end, t), y: iplt("y", start, end, t), z: iplt("z", start, end, t) }; }; var lineLen = link.__curve ? link.__curve.getLength() : Math.sqrt(["x", "y", "z"].map(function(dim) { return Math.pow((end[dim] || 0) - (start[dim] || 0), 2); }).reduce(function(acc, v) { return acc + v; }, 0)); var posAlongLine = startR + arrowLength + (lineLen - startR - endR - arrowLength) * arrowRelPos; var arrowHead = getPosAlongLine(posAlongLine / lineLen); var arrowTail = getPosAlongLine((posAlongLine - arrowLength) / lineLen); ["x", "y", "z"].forEach(function(dim) { return arrowObj.position[dim] = arrowTail[dim]; }); var headVec = _construct(three$1.Vector3, _toConsumableArray3(["x", "y", "z"].map(function(c2) { return arrowHead[c2]; }))); arrowObj.parent.localToWorld(headVec); arrowObj.lookAt(headVec); }); } function updatePhotons() { var particleSpeedAccessor = index3(state.linkDirectionalParticleSpeed); state.graphData.links.forEach(function(link) { var cyclePhotons = link.__photonsObj && link.__photonsObj.children; var singleHopPhotons = link.__singleHopPhotonsObj && link.__singleHopPhotonsObj.children; if ((!singleHopPhotons || !singleHopPhotons.length) && (!cyclePhotons || !cyclePhotons.length)) return; var pos = isD3Sim ? link : state.layout.getLinkPosition(state.layout.graph.getLink(link.source, link.target).id); var start = pos[isD3Sim ? "source" : "from"]; var end = pos[isD3Sim ? "target" : "to"]; if (!start || !end || !start.hasOwnProperty("x") || !end.hasOwnProperty("x")) return; var particleSpeed = particleSpeedAccessor(link); var getPhotonPos = link.__curve ? function(t) { return link.__curve.getPoint(t); } : function(t) { var iplt = function iplt2(dim, start2, end2, t2) { return start2[dim] + (end2[dim] - start2[dim]) * t2 || 0; }; return { x: iplt("x", start, end, t), y: iplt("y", start, end, t), z: iplt("z", start, end, t) }; }; var photons = [].concat(_toConsumableArray3(cyclePhotons || []), _toConsumableArray3(singleHopPhotons || [])); photons.forEach(function(photon, idx) { var singleHop = photon.parent.__linkThreeObjType === "singleHopPhotons"; if (!photon.hasOwnProperty("__progressRatio")) { photon.__progressRatio = singleHop ? 0 : idx / cyclePhotons.length; } photon.__progressRatio += particleSpeed; if (photon.__progressRatio >= 1) { if (!singleHop) { photon.__progressRatio = photon.__progressRatio % 1; } else { photon.parent.remove(photon); emptyObject(photon); return; } } var photonPosRatio = photon.__progressRatio; var pos2 = getPhotonPos(photonPosRatio); ["x", "y", "z"].forEach(function(dim) { return photon.position[dim] = pos2[dim]; }); }); }); } }, emitParticle: function emitParticle(state, link) { if (link && state.graphData.links.includes(link)) { if (!link.__singleHopPhotonsObj) { var obj = new three$1.Group(); obj.__linkThreeObjType = "singleHopPhotons"; link.__singleHopPhotonsObj = obj; state.graphScene.add(obj); } var particleWidthAccessor = index3(state.linkDirectionalParticleWidth); var photonR = Math.ceil(particleWidthAccessor(link) * 10) / 10 / 2; var numSegments = state.linkDirectionalParticleResolution; var particleGeometry = new three$1.SphereGeometry(photonR, numSegments, numSegments); var linkColorAccessor = index3(state.linkColor); var particleColorAccessor = index3(state.linkDirectionalParticleColor); var photonColor = particleColorAccessor(link) || linkColorAccessor(link) || "#f0f0f0"; var materialColor = new three$1.Color(colorStr2Hex(photonColor)); var opacity = state.linkOpacity * 3; var particleMaterial = new three$1.MeshLambertMaterial({ color: materialColor, transparent: true, opacity }); link.__singleHopPhotonsObj.add(new three$1.Mesh(particleGeometry, particleMaterial)); } return this; }, getGraphBbox: function getGraphBbox(state) { var nodeFilter = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : function() { return true; }; if (!state.initialised) return null; var bboxes = function getBboxes(obj) { var bboxes2 = []; if (obj.geometry) { obj.geometry.computeBoundingBox(); var box = new three$1.Box3(); box.copy(obj.geometry.boundingBox).applyMatrix4(obj.matrixWorld); bboxes2.push(box); } return bboxes2.concat.apply(bboxes2, _toConsumableArray3((obj.children || []).filter( function(obj2) { return !obj2.hasOwnProperty("__graphObjType") || obj2.__graphObjType === "node" && nodeFilter(obj2.__data); } // exclude filtered out nodes ).map(getBboxes))); }(state.graphScene); if (!bboxes.length) return null; return Object.assign.apply(Object, _toConsumableArray3(["x", "y", "z"].map(function(c2) { return _defineProperty2({}, c2, [min(bboxes, function(bb) { return bb.min[c2]; }), max(bboxes, function(bb) { return bb.max[c2]; })]); }))); } }, stateInit: function stateInit() { return { d3ForceLayout: simulation_default().force("link", link_default()).force("charge", manyBody_default()).force("center", center_default()).force("dagRadial", null).stop(), engineRunning: false }; }, init: function init(threeObj, state) { state.graphScene = threeObj; }, update: function update(state, changedProps) { var hasAnyPropChanged = function hasAnyPropChanged2(propList) { return propList.some(function(p) { return changedProps.hasOwnProperty(p); }); }; state.engineRunning = false; state.onUpdate(); if (state.nodeAutoColorBy !== null && hasAnyPropChanged(["nodeAutoColorBy", "graphData", "nodeColor"])) { autoColorObjects(state.graphData.nodes, index3(state.nodeAutoColorBy), state.nodeColor); } if (state.linkAutoColorBy !== null && hasAnyPropChanged(["linkAutoColorBy", "graphData", "linkColor"])) { autoColorObjects(state.graphData.links, index3(state.linkAutoColorBy), state.linkColor); } if (state._flushObjects || hasAnyPropChanged(["graphData", "nodeThreeObject", "nodeThreeObjectExtend", "nodeVal", "nodeColor", "nodeVisibility", "nodeRelSize", "nodeResolution", "nodeOpacity"])) { var customObjectAccessor = index3(state.nodeThreeObject); var customObjectExtendAccessor = index3(state.nodeThreeObjectExtend); var valAccessor = index3(state.nodeVal); var colorAccessor = index3(state.nodeColor); var visibilityAccessor = index3(state.nodeVisibility); var sphereGeometries = {}; var sphereMaterials = {}; threeDigest(state.graphData.nodes.filter(visibilityAccessor), state.graphScene, { purge: state._flushObjects || hasAnyPropChanged([ // recreate objects if any of these props have changed "nodeThreeObject", "nodeThreeObjectExtend" ]), objFilter: function objFilter(obj) { return obj.__graphObjType === "node"; }, createObj: function createObj(node) { var customObj = customObjectAccessor(node); var extendObj = customObjectExtendAccessor(node); if (customObj && state.nodeThreeObject === customObj) { customObj = customObj.clone(); } var obj; if (customObj && !extendObj) { obj = customObj; } else { obj = new three$1.Mesh(); obj.__graphDefaultObj = true; if (customObj && extendObj) { obj.add(customObj); } } obj.__graphObjType = "node"; return obj; }, updateObj: function updateObj(obj, node) { if (obj.__graphDefaultObj) { var val = valAccessor(node) || 1; var radius = Math.cbrt(val) * state.nodeRelSize; var numSegments = state.nodeResolution; if (!obj.geometry.type.match(/^Sphere(Buffer)?Geometry$/) || obj.geometry.parameters.radius !== radius || obj.geometry.parameters.widthSegments !== numSegments) { if (!sphereGeometries.hasOwnProperty(val)) { sphereGeometries[val] = new three$1.SphereGeometry(radius, numSegments, numSegments); } obj.geometry.dispose(); obj.geometry = sphereGeometries[val]; } var color = colorAccessor(node); var materialColor = new three$1.Color(colorStr2Hex(color || "#ffffaa")); var opacity = state.nodeOpacity * colorAlpha(color); if (obj.material.type !== "MeshLambertMaterial" || !obj.material.color.equals(materialColor) || obj.material.opacity !== opacity) { if (!sphereMaterials.hasOwnProperty(color)) { sphereMaterials[color] = new three$1.MeshLambertMaterial({ color: materialColor, transparent: true, opacity }); } obj.material.dispose(); obj.material = sphereMaterials[color]; } } } }); } if (state._flushObjects || hasAnyPropChanged(["graphData", "linkThreeObject", "linkThreeObjectExtend", "linkMaterial", "linkColor", "linkWidth", "linkVisibility", "linkResolution", "linkOpacity", "linkDirectionalArrowLength", "linkDirectionalArrowColor", "linkDirectionalArrowResolution", "linkDirectionalParticles", "linkDirectionalParticleWidth", "linkDirectionalParticleColor", "linkDirectionalParticleResolution"])) { var _customObjectAccessor = index3(state.linkThreeObject); var _customObjectExtendAccessor = index3(state.linkThreeObjectExtend); var customMaterialAccessor = index3(state.linkMaterial); var _visibilityAccessor = index3(state.linkVisibility); var _colorAccessor = index3(state.linkColor); var widthAccessor = index3(state.linkWidth); var cylinderGeometries = {}; var lambertLineMaterials = {}; var basicLineMaterials = {}; var visibleLinks = state.graphData.links.filter(_visibilityAccessor); threeDigest(visibleLinks, state.graphScene, { objBindAttr: "__lineObj", purge: state._flushObjects || hasAnyPropChanged([ // recreate objects if any of these props have changed "linkThreeObject", "linkThreeObjectExtend", "linkWidth" ]), objFilter: function objFilter(obj) { return obj.__graphObjType === "link"; }, exitObj: function exitObj(obj) { var singlePhotonsObj = obj.__data && obj.__data.__singleHopPhotonsObj; if (singlePhotonsObj) { singlePhotonsObj.parent.remove(singlePhotonsObj); emptyObject(singlePhotonsObj); delete obj.__data.__singleHopPhotonsObj; } }, createObj: function createObj(link) { var customObj = _customObjectAccessor(link); var extendObj = _customObjectExtendAccessor(link); if (customObj && state.linkThreeObject === customObj) { customObj = customObj.clone(); } var defaultObj; if (!customObj || extendObj) { var useCylinder = !!widthAccessor(link); if (useCylinder) { defaultObj = new three$1.Mesh(); } else { var lineGeometry = new three$1.BufferGeometry(); lineGeometry[setAttributeFn]("position", new three$1.BufferAttribute(new Float32Array(2 * 3), 3)); defaultObj = new three$1.Line(lineGeometry); } } var obj; if (!customObj) { obj = defaultObj; obj.__graphDefaultObj = true; } else { if (!extendObj) { obj = customObj; } else { obj = new three$1.Group(); obj.__graphDefaultObj = true; obj.add(defaultObj); obj.add(customObj); } } obj.renderOrder = 10; obj.__graphObjType = "link"; return obj; }, updateObj: function updateObj(updObj, link) { if (updObj.__graphDefaultObj) { var obj = updObj.children.length ? updObj.children[0] : updObj; var linkWidth = Math.ceil(widthAccessor(link) * 10) / 10; var useCylinder = !!linkWidth; if (useCylinder) { var r = linkWidth / 2; var numSegments = state.linkResolution; if (!obj.geometry.type.match(/^Cylinder(Buffer)?Geometry$/) || obj.geometry.parameters.radiusTop !== r || obj.geometry.parameters.radialSegments !== numSegments) { if (!cylinderGeometries.hasOwnProperty(linkWidth)) { var geometry = new three$1.CylinderGeometry(r, r, 1, numSegments, 1, false); geometry[applyMatrix4Fn](new three$1.Matrix4().makeTranslation(0, 1 / 2, 0)); geometry[applyMatrix4Fn](new three$1.Matrix4().makeRotationX(Math.PI / 2)); cylinderGeometries[linkWidth] = geometry; } obj.geometry.dispose(); obj.geometry = cylinderGeometries[linkWidth]; } } var customMaterial = customMaterialAccessor(link); if (customMaterial) { obj.material = customMaterial; } else { var color = _colorAccessor(link); var materialColor = new three$1.Color(colorStr2Hex(color || "#f0f0f0")); var opacity = state.linkOpacity * colorAlpha(color); var materialType = useCylinder ? "MeshLambertMaterial" : "LineBasicMaterial"; if (obj.material.type !== materialType || !obj.material.color.equals(materialColor) || obj.material.opacity !== opacity) { var lineMaterials = useCylinder ? lambertLineMaterials : basicLineMaterials; if (!lineMaterials.hasOwnProperty(color)) { lineMaterials[color] = new three$1[materialType]({ color: materialColor, transparent: opacity < 1, opacity, depthWrite: opacity >= 1 // Prevent transparency issues }); } obj.material.dispose(); obj.material = lineMaterials[color]; } } } } }); if (state.linkDirectionalArrowLength || changedProps.hasOwnProperty("linkDirectionalArrowLength")) { var arrowLengthAccessor = index3(state.linkDirectionalArrowLength); var arrowColorAccessor = index3(state.linkDirectionalArrowColor); threeDigest(visibleLinks.filter(arrowLengthAccessor), state.graphScene, { objBindAttr: "__arrowObj", objFilter: function objFilter(obj) { return obj.__linkThreeObjType === "arrow"; }, createObj: function createObj() { var obj = new three$1.Mesh(void 0, new three$1.MeshLambertMaterial({ transparent: true })); obj.__linkThreeObjType = "arrow"; return obj; }, updateObj: function updateObj(obj, link) { var arrowLength = arrowLengthAccessor(link); var numSegments = state.linkDirectionalArrowResolution; if (!obj.geometry.type.match(/^Cone(Buffer)?Geometry$/) || obj.geometry.parameters.height !== arrowLength || obj.geometry.parameters.radialSegments !== numSegments) { var coneGeometry = new three$1.ConeGeometry(arrowLength * 0.25, arrowLength, numSegments); coneGeometry.translate(0, arrowLength / 2, 0); coneGeometry.rotateX(Math.PI / 2); obj.geometry.dispose(); obj.geometry = coneGeometry; } var arrowColor = arrowColorAccessor(link) || _colorAccessor(link) || "#f0f0f0"; obj.material.color = new three$1.Color(colorStr2Hex(arrowColor)); obj.material.opacity = state.linkOpacity * 3 * colorAlpha(arrowColor); } }); } if (state.linkDirectionalParticles || changedProps.hasOwnProperty("linkDirectionalParticles")) { var particlesAccessor = index3(state.linkDirectionalParticles); var particleWidthAccessor = index3(state.linkDirectionalParticleWidth); var particleColorAccessor = index3(state.linkDirectionalParticleColor); var particleMaterials = {}; var particleGeometries = {}; threeDigest(visibleLinks.filter(particlesAccessor), state.graphScene, { objBindAttr: "__photonsObj", objFilter: function objFilter(obj) { return obj.__linkThreeObjType === "photons"; }, createObj: function createObj() { var obj = new three$1.Group(); obj.__linkThreeObjType = "photons"; return obj; }, updateObj: function updateObj(obj, link) { var numPhotons = Math.round(Math.abs(particlesAccessor(link))); var curPhoton = !!obj.children.length && obj.children[0]; var photonR = Math.ceil(particleWidthAccessor(link) * 10) / 10 / 2; var numSegments = state.linkDirectionalParticleResolution; var particleGeometry; if (curPhoton && curPhoton.geometry.parameters.radius === photonR && curPhoton.geometry.parameters.widthSegments === numSegments) { particleGeometry = curPhoton.geometry; } else { if (!particleGeometries.hasOwnProperty(photonR)) { particleGeometries[photonR] = new three$1.SphereGeometry(photonR, numSegments, numSegments); } particleGeometry = particleGeometries[photonR]; curPhoton && curPhoton.geometry.dispose(); } var photonColor = particleColorAccessor(link) || _colorAccessor(link) || "#f0f0f0"; var materialColor = new three$1.Color(colorStr2Hex(photonColor)); var opacity = state.linkOpacity * 3; var particleMaterial; if (curPhoton && curPhoton.material.color.equals(materialColor) && curPhoton.material.opacity === opacity) { particleMaterial = curPhoton.material; } else { if (!particleMaterials.hasOwnProperty(photonColor)) { particleMaterials[photonColor] = new three$1.MeshLambertMaterial({ color: materialColor, transparent: true, opacity }); } particleMaterial = particleMaterials[photonColor]; curPhoton && curPhoton.material.dispose(); } threeDigest(_toConsumableArray3(new Array(numPhotons)).map(function(_, idx) { return { idx }; }), obj, { idAccessor: function idAccessor(d) { return d.idx; }, createObj: function createObj() { return new three$1.Mesh(particleGeometry, particleMaterial); }, updateObj: function updateObj2(obj2) { obj2.geometry = particleGeometry; obj2.material = particleMaterial; } }); } }); } } state._flushObjects = false; if (hasAnyPropChanged(["graphData", "nodeId", "linkSource", "linkTarget", "numDimensions", "forceEngine", "dagMode", "dagNodeFilter", "dagLevelDistance"])) { state.engineRunning = false; state.graphData.links.forEach(function(link) { link.source = link[state.linkSource]; link.target = link[state.linkTarget]; }); var isD3Sim = state.forceEngine !== "ngraph"; var layout; if (isD3Sim) { (layout = state.d3ForceLayout).stop().alpha(1).numDimensions(state.numDimensions).nodes(state.graphData.nodes); var linkForce = state.d3ForceLayout.force("link"); if (linkForce) { linkForce.id(function(d) { return d[state.nodeId]; }).links(state.graphData.links); } var nodeDepths = state.dagMode && getDagDepths(state.graphData, function(node) { return node[state.nodeId]; }, { nodeFilter: state.dagNodeFilter, onLoopError: state.onDagError || void 0 }); var maxDepth = Math.max.apply(Math, _toConsumableArray3(Object.values(nodeDepths || []))); var dagLevelDistance = state.dagLevelDistance || state.graphData.nodes.length / (maxDepth || 1) * DAG_LEVEL_NODE_RATIO * (["radialin", "radialout"].indexOf(state.dagMode) !== -1 ? 0.7 : 1); if (state.dagMode) { var getFFn = function getFFn2(fix, invert) { return function(node) { return !fix ? void 0 : (nodeDepths[node[state.nodeId]] - maxDepth / 2) * dagLevelDistance * (invert ? -1 : 1); }; }; var fxFn = getFFn(["lr", "rl"].indexOf(state.dagMode) !== -1, state.dagMode === "rl"); var fyFn = getFFn(["td", "bu"].indexOf(state.dagMode) !== -1, state.dagMode === "td"); var fzFn = getFFn(["zin", "zout"].indexOf(state.dagMode) !== -1, state.dagMode === "zout"); state.graphData.nodes.filter(state.dagNodeFilter).forEach(function(node) { node.fx = fxFn(node); node.fy = fyFn(node); node.fz = fzFn(node); }); } state.d3ForceLayout.force("dagRadial", ["radialin", "radialout"].indexOf(state.dagMode) !== -1 ? radial_default(function(node) { var nodeDepth = nodeDepths[node[state.nodeId]] || -1; return (state.dagMode === "radialin" ? maxDepth - nodeDepth : nodeDepth) * dagLevelDistance; }).strength(function(node) { return state.dagNodeFilter(node) ? 1 : 0; }) : null); } else { var _graph = ngraph.graph(); state.graphData.nodes.forEach(function(node) { _graph.addNode(node[state.nodeId]); }); state.graphData.links.forEach(function(link) { _graph.addLink(link.source, link.target); }); layout = ngraph.forcelayout(_graph, _objectSpread22({ dimensions: state.numDimensions }, state.ngraphPhysics)); layout.graph = _graph; } for (var i = 0; i < state.warmupTicks && !(isD3Sim && state.d3AlphaMin > 0 && state.d3ForceLayout.alpha() < state.d3AlphaMin); i++) { layout[isD3Sim ? "tick" : "step"](); } state.layout = layout; this.resetCountdown(); } state.engineRunning = true; state.onFinishUpdate(); } }); function fromKapsule(kapsule) { var baseClass = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : Object; var initKapsuleWithSelf = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : false; var FromKapsule = /* @__PURE__ */ function(_baseClass) { _inherits(FromKapsule2, _baseClass); var _super = _createSuper(FromKapsule2); function FromKapsule2() { var _this; _classCallCheck2(this, FromKapsule2); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _super.call.apply(_super, [this].concat(args)); _this.__kapsuleInstance = kapsule().apply(void 0, [].concat(_toConsumableArray3(initKapsuleWithSelf ? [_assertThisInitialized(_this)] : []), args)); return _this; } return _createClass2(FromKapsule2); }(baseClass); Object.keys(kapsule()).forEach(function(m2) { return FromKapsule.prototype[m2] = function() { var _this$__kapsuleInstan; var returnVal = (_this$__kapsuleInstan = this.__kapsuleInstance)[m2].apply(_this$__kapsuleInstan, arguments); return returnVal === this.__kapsuleInstance ? this : returnVal; }; }); return FromKapsule; } var three = window.THREE ? window.THREE : { Group: Group2 }; var threeForcegraph = fromKapsule(ForceGraph, three.Group, true); // node_modules/three/examples/jsm/controls/TrackballControls.js var _changeEvent = { type: "change" }; var _startEvent = { type: "start" }; var _endEvent = { type: "end" }; var TrackballControls = class extends EventDispatcher2 { constructor(object, domElement) { super(); const scope = this; const STATE = { NONE: -1, ROTATE: 0, ZOOM: 1, PAN: 2, TOUCH_ROTATE: 3, TOUCH_ZOOM_PAN: 4 }; this.object = object; this.domElement = domElement; this.domElement.style.touchAction = "none"; this.enabled = true; this.screen = { left: 0, top: 0, width: 0, height: 0 }; this.rotateSpeed = 1; this.zoomSpeed = 1.2; this.panSpeed = 0.3; this.noRotate = false; this.noZoom = false; this.noPan = false; this.staticMoving = false; this.dynamicDampingFactor = 0.2; this.minDistance = 0; this.maxDistance = Infinity; this.minZoom = 0; this.maxZoom = Infinity; this.keys = [ "KeyA", "KeyS", "KeyD" /*D*/ ]; this.mouseButtons = { LEFT: MOUSE.ROTATE, MIDDLE: MOUSE.DOLLY, RIGHT: MOUSE.PAN }; this.target = new Vector32(); const EPS = 1e-6; const lastPosition = new Vector32(); let lastZoom = 1; let _state = STATE.NONE, _keyState = STATE.NONE, _touchZoomDistanceStart = 0, _touchZoomDistanceEnd = 0, _lastAngle = 0; const _eye = new Vector32(), _movePrev = new Vector22(), _moveCurr = new Vector22(), _lastAxis = new Vector32(), _zoomStart = new Vector22(), _zoomEnd = new Vector22(), _panStart = new Vector22(), _panEnd = new Vector22(), _pointers = [], _pointerPositions = {}; this.target0 = this.target.clone(); this.position0 = this.object.position.clone(); this.up0 = this.object.up.clone(); this.zoom0 = this.object.zoom; this.handleResize = function() { const box = scope.domElement.getBoundingClientRect(); const d = scope.domElement.ownerDocument.documentElement; scope.screen.left = box.left + window.pageXOffset - d.clientLeft; scope.screen.top = box.top + window.pageYOffset - d.clientTop; scope.screen.width = box.width; scope.screen.height = box.height; }; const getMouseOnScreen = function() { const vector = new Vector22(); return function getMouseOnScreen2(pageX, pageY) { vector.set( (pageX - scope.screen.left) / scope.screen.width, (pageY - scope.screen.top) / scope.screen.height ); return vector; }; }(); const getMouseOnCircle = function() { const vector = new Vector22(); return function getMouseOnCircle2(pageX, pageY) { vector.set( (pageX - scope.screen.width * 0.5 - scope.screen.left) / (scope.screen.width * 0.5), (scope.screen.height + 2 * (scope.screen.top - pageY)) / scope.screen.width // screen.width intentional ); return vector; }; }(); this.rotateCamera = function() { const axis = new Vector32(), quaternion = new Quaternion2(), eyeDirection = new Vector32(), objectUpDirection = new Vector32(), objectSidewaysDirection = new Vector32(), moveDirection = new Vector32(); return function rotateCamera() { moveDirection.set(_moveCurr.x - _movePrev.x, _moveCurr.y - _movePrev.y, 0); let angle = moveDirection.length(); if (angle) { _eye.copy(scope.object.position).sub(scope.target); eyeDirection.copy(_eye).normalize(); objectUpDirection.copy(scope.object.up).normalize(); objectSidewaysDirection.crossVectors(objectUpDirection, eyeDirection).normalize(); objectUpDirection.setLength(_moveCurr.y - _movePrev.y); objectSidewaysDirection.setLength(_moveCurr.x - _movePrev.x); moveDirection.copy(objectUpDirection.add(objectSidewaysDirection)); axis.crossVectors(moveDirection, _eye).normalize(); angle *= scope.rotateSpeed; quaternion.setFromAxisAngle(axis, angle); _eye.applyQuaternion(quaternion); scope.object.up.applyQuaternion(quaternion); _lastAxis.copy(axis); _lastAngle = angle; } else if (!scope.staticMoving && _lastAngle) { _lastAngle *= Math.sqrt(1 - scope.dynamicDampingFactor); _eye.copy(scope.object.position).sub(scope.target); quaternion.setFromAxisAngle(_lastAxis, _lastAngle); _eye.applyQuaternion(quaternion); scope.object.up.applyQuaternion(quaternion); } _movePrev.copy(_moveCurr); }; }(); this.zoomCamera = function() { let factor; if (_state === STATE.TOUCH_ZOOM_PAN) { factor = _touchZoomDistanceStart / _touchZoomDistanceEnd; _touchZoomDistanceStart = _touchZoomDistanceEnd; if (scope.object.isPerspectiveCamera) { _eye.multiplyScalar(factor); } else if (scope.object.isOrthographicCamera) { scope.object.zoom = MathUtils.clamp(scope.object.zoom / factor, scope.minZoom, scope.maxZoom); if (lastZoom !== scope.object.zoom) { scope.object.updateProjectionMatrix(); } } else { console.warn("THREE.TrackballControls: Unsupported camera type"); } } else { factor = 1 + (_zoomEnd.y - _zoomStart.y) * scope.zoomSpeed; if (factor !== 1 && factor > 0) { if (scope.object.isPerspectiveCamera) { _eye.multiplyScalar(factor); } else if (scope.object.isOrthographicCamera) { scope.object.zoom = MathUtils.clamp(scope.object.zoom / factor, scope.minZoom, scope.maxZoom); if (lastZoom !== scope.object.zoom) { scope.object.updateProjectionMatrix(); } } else { console.warn("THREE.TrackballControls: Unsupported camera type"); } } if (scope.staticMoving) { _zoomStart.copy(_zoomEnd); } else { _zoomStart.y += (_zoomEnd.y - _zoomStart.y) * this.dynamicDampingFactor; } } }; this.panCamera = function() { const mouseChange = new Vector22(), objectUp = new Vector32(), pan = new Vector32(); return function panCamera() { mouseChange.copy(_panEnd).sub(_panStart); if (mouseChange.lengthSq()) { if (scope.object.isOrthographicCamera) { const scale_x = (scope.object.right - scope.object.left) / scope.object.zoom / scope.domElement.clientWidth; const scale_y = (scope.object.top - scope.object.bottom) / scope.object.zoom / scope.domElement.clientWidth; mouseChange.x *= scale_x; mouseChange.y *= scale_y; } mouseChange.multiplyScalar(_eye.length() * scope.panSpeed); pan.copy(_eye).cross(scope.object.up).setLength(mouseChange.x); pan.add(objectUp.copy(scope.object.up).setLength(mouseChange.y)); scope.object.position.add(pan); scope.target.add(pan); if (scope.staticMoving) { _panStart.copy(_panEnd); } else { _panStart.add(mouseChange.subVectors(_panEnd, _panStart).multiplyScalar(scope.dynamicDampingFactor)); } } }; }(); this.checkDistances = function() { if (!scope.noZoom || !scope.noPan) { if (_eye.lengthSq() > scope.maxDistance * scope.maxDistance) { scope.object.position.addVectors(scope.target, _eye.setLength(scope.maxDistance)); _zoomStart.copy(_zoomEnd); } if (_eye.lengthSq() < scope.minDistance * scope.minDistance) { scope.object.position.addVectors(scope.target, _eye.setLength(scope.minDistance)); _zoomStart.copy(_zoomEnd); } } }; this.update = function() { _eye.subVectors(scope.object.position, scope.target); if (!scope.noRotate) { scope.rotateCamera(); } if (!scope.noZoom) { scope.zoomCamera(); } if (!scope.noPan) { scope.panCamera(); } scope.object.position.addVectors(scope.target, _eye); if (scope.object.isPerspectiveCamera) { scope.checkDistances(); scope.object.lookAt(scope.target); if (lastPosition.distanceToSquared(scope.object.position) > EPS) { scope.dispatchEvent(_changeEvent); lastPosition.copy(scope.object.position); } } else if (scope.object.isOrthographicCamera) { scope.object.lookAt(scope.target); if (lastPosition.distanceToSquared(scope.object.position) > EPS || lastZoom !== scope.object.zoom) { scope.dispatchEvent(_changeEvent); lastPosition.copy(scope.object.position); lastZoom = scope.object.zoom; } } else { console.warn("THREE.TrackballControls: Unsupported camera type"); } }; this.reset = function() { _state = STATE.NONE; _keyState = STATE.NONE; scope.target.copy(scope.target0); scope.object.position.copy(scope.position0); scope.object.up.copy(scope.up0); scope.object.zoom = scope.zoom0; scope.object.updateProjectionMatrix(); _eye.subVectors(scope.object.position, scope.target); scope.object.lookAt(scope.target); scope.dispatchEvent(_changeEvent); lastPosition.copy(scope.object.position); lastZoom = scope.object.zoom; }; function onPointerDown(event) { if (scope.enabled === false) return; if (_pointers.length === 0) { scope.domElement.setPointerCapture(event.pointerId); scope.domElement.addEventListener("pointermove", onPointerMove); scope.domElement.addEventListener("pointerup", onPointerUp); } addPointer(event); if (event.pointerType === "touch") { onTouchStart(event); } else { onMouseDown(event); } } function onPointerMove(event) { if (scope.enabled === false) return; if (event.pointerType === "touch") { onTouchMove(event); } else { onMouseMove(event); } } function onPointerUp(event) { if (scope.enabled === false) return; if (event.pointerType === "touch") { onTouchEnd(event); } else { onMouseUp(); } removePointer(event); if (_pointers.length === 0) { scope.domElement.releasePointerCapture(event.pointerId); scope.domElement.removeEventListener("pointermove", onPointerMove); scope.domElement.removeEventListener("pointerup", onPointerUp); } } function onPointerCancel(event) { removePointer(event); } function keydown(event) { if (scope.enabled === false) return; window.removeEventListener("keydown", keydown); if (_keyState !== STATE.NONE) { return; } else if (event.code === scope.keys[STATE.ROTATE] && !scope.noRotate) { _keyState = STATE.ROTATE; } else if (event.code === scope.keys[STATE.ZOOM] && !scope.noZoom) { _keyState = STATE.ZOOM; } else if (event.code === scope.keys[STATE.PAN] && !scope.noPan) { _keyState = STATE.PAN; } } function keyup() { if (scope.enabled === false) return; _keyState = STATE.NONE; window.addEventListener("keydown", keydown); } function onMouseDown(event) { if (_state === STATE.NONE) { switch (event.button) { case scope.mouseButtons.LEFT: _state = STATE.ROTATE; break; case scope.mouseButtons.MIDDLE: _state = STATE.ZOOM; break; case scope.mouseButtons.RIGHT: _state = STATE.PAN; break; } } const state = _keyState !== STATE.NONE ? _keyState : _state; if (state === STATE.ROTATE && !scope.noRotate) { _moveCurr.copy(getMouseOnCircle(event.pageX, event.pageY)); _movePrev.copy(_moveCurr); } else if (state === STATE.ZOOM && !scope.noZoom) { _zoomStart.copy(getMouseOnScreen(event.pageX, event.pageY)); _zoomEnd.copy(_zoomStart); } else if (state === STATE.PAN && !scope.noPan) { _panStart.copy(getMouseOnScreen(event.pageX, event.pageY)); _panEnd.copy(_panStart); } scope.dispatchEvent(_startEvent); } function onMouseMove(event) { const state = _keyState !== STATE.NONE ? _keyState : _state; if (state === STATE.ROTATE && !scope.noRotate) { _movePrev.copy(_moveCurr); _moveCurr.copy(getMouseOnCircle(event.pageX, event.pageY)); } else if (state === STATE.ZOOM && !scope.noZoom) { _zoomEnd.copy(getMouseOnScreen(event.pageX, event.pageY)); } else if (state === STATE.PAN && !scope.noPan) { _panEnd.copy(getMouseOnScreen(event.pageX, event.pageY)); } } function onMouseUp() { _state = STATE.NONE; scope.dispatchEvent(_endEvent); } function onMouseWheel(event) { if (scope.enabled === false) return; if (scope.noZoom === true) return; event.preventDefault(); switch (event.deltaMode) { case 2: _zoomStart.y -= event.deltaY * 0.025; break; case 1: _zoomStart.y -= event.deltaY * 0.01; break; default: _zoomStart.y -= event.deltaY * 25e-5; break; } scope.dispatchEvent(_startEvent); scope.dispatchEvent(_endEvent); } function onTouchStart(event) { trackPointer(event); switch (_pointers.length) { case 1: _state = STATE.TOUCH_ROTATE; _moveCurr.copy(getMouseOnCircle(_pointers[0].pageX, _pointers[0].pageY)); _movePrev.copy(_moveCurr); break; default: _state = STATE.TOUCH_ZOOM_PAN; const dx = _pointers[0].pageX - _pointers[1].pageX; const dy = _pointers[0].pageY - _pointers[1].pageY; _touchZoomDistanceEnd = _touchZoomDistanceStart = Math.sqrt(dx * dx + dy * dy); const x3 = (_pointers[0].pageX + _pointers[1].pageX) / 2; const y3 = (_pointers[0].pageY + _pointers[1].pageY) / 2; _panStart.copy(getMouseOnScreen(x3, y3)); _panEnd.copy(_panStart); break; } scope.dispatchEvent(_startEvent); } function onTouchMove(event) { trackPointer(event); switch (_pointers.length) { case 1: _movePrev.copy(_moveCurr); _moveCurr.copy(getMouseOnCircle(event.pageX, event.pageY)); break; default: const position = getSecondPointerPosition(event); const dx = event.pageX - position.x; const dy = event.pageY - position.y; _touchZoomDistanceEnd = Math.sqrt(dx * dx + dy * dy); const x3 = (event.pageX + position.x) / 2; const y3 = (event.pageY + position.y) / 2; _panEnd.copy(getMouseOnScreen(x3, y3)); break; } } function onTouchEnd(event) { switch (_pointers.length) { case 0: _state = STATE.NONE; break; case 1: _state = STATE.TOUCH_ROTATE; _moveCurr.copy(getMouseOnCircle(event.pageX, event.pageY)); _movePrev.copy(_moveCurr); break; case 2: _state = STATE.TOUCH_ZOOM_PAN; for (let i = 0; i < _pointers.length; i++) { if (_pointers[i].pointerId !== event.pointerId) { const position = _pointerPositions[_pointers[i].pointerId]; _moveCurr.copy(getMouseOnCircle(position.x, position.y)); _movePrev.copy(_moveCurr); break; } } break; } scope.dispatchEvent(_endEvent); } function contextmenu(event) { if (scope.enabled === false) return; event.preventDefault(); } function addPointer(event) { _pointers.push(event); } function removePointer(event) { delete _pointerPositions[event.pointerId]; for (let i = 0; i < _pointers.length; i++) { if (_pointers[i].pointerId == event.pointerId) { _pointers.splice(i, 1); return; } } } function trackPointer(event) { let position = _pointerPositions[event.pointerId]; if (position === void 0) { position = new Vector22(); _pointerPositions[event.pointerId] = position; } position.set(event.pageX, event.pageY); } function getSecondPointerPosition(event) { const pointer = event.pointerId === _pointers[0].pointerId ? _pointers[1] : _pointers[0]; return _pointerPositions[pointer.pointerId]; } this.dispose = function() { scope.domElement.removeEventListener("contextmenu", contextmenu); scope.domElement.removeEventListener("pointerdown", onPointerDown); scope.domElement.removeEventListener("pointercancel", onPointerCancel); scope.domElement.removeEventListener("wheel", onMouseWheel); scope.domElement.removeEventListener("pointermove", onPointerMove); scope.domElement.removeEventListener("pointerup", onPointerUp); window.removeEventListener("keydown", keydown); window.removeEventListener("keyup", keyup); }; this.domElement.addEventListener("contextmenu", contextmenu); this.domElement.addEventListener("pointerdown", onPointerDown); this.domElement.addEventListener("pointercancel", onPointerCancel); this.domElement.addEventListener("wheel", onMouseWheel, { passive: false }); window.addEventListener("keydown", keydown); window.addEventListener("keyup", keyup); this.handleResize(); this.update(); } }; // node_modules/three/examples/jsm/controls/OrbitControls.js var _changeEvent2 = { type: "change" }; var _startEvent2 = { type: "start" }; var _endEvent2 = { type: "end" }; var _ray = new Ray2(); var _plane2 = new Plane2(); var TILT_LIMIT = Math.cos(70 * MathUtils.DEG2RAD); var OrbitControls = class extends EventDispatcher2 { constructor(object, domElement) { super(); this.object = object; this.domElement = domElement; this.domElement.style.touchAction = "none"; this.enabled = true; this.target = new Vector32(); this.minDistance = 0; this.maxDistance = Infinity; this.minZoom = 0; this.maxZoom = Infinity; this.minPolarAngle = 0; this.maxPolarAngle = Math.PI; this.minAzimuthAngle = -Infinity; this.maxAzimuthAngle = Infinity; this.enableDamping = false; this.dampingFactor = 0.05; this.enableZoom = true; this.zoomSpeed = 1; this.enableRotate = true; this.rotateSpeed = 1; this.enablePan = true; this.panSpeed = 1; this.screenSpacePanning = true; this.keyPanSpeed = 7; this.zoomToCursor = false; this.autoRotate = false; this.autoRotateSpeed = 2; this.keys = { LEFT: "ArrowLeft", UP: "ArrowUp", RIGHT: "ArrowRight", BOTTOM: "ArrowDown" }; this.mouseButtons = { LEFT: MOUSE.ROTATE, MIDDLE: MOUSE.DOLLY, RIGHT: MOUSE.PAN }; this.touches = { ONE: TOUCH.ROTATE, TWO: TOUCH.DOLLY_PAN }; this.target0 = this.target.clone(); this.position0 = this.object.position.clone(); this.zoom0 = this.object.zoom; this._domElementKeyEvents = null; this.getPolarAngle = function() { return spherical.phi; }; this.getAzimuthalAngle = function() { return spherical.theta; }; this.getDistance = function() { return this.object.position.distanceTo(this.target); }; this.listenToKeyEvents = function(domElement2) { domElement2.addEventListener("keydown", onKeyDown); this._domElementKeyEvents = domElement2; }; this.stopListenToKeyEvents = function() { this._domElementKeyEvents.removeEventListener("keydown", onKeyDown); this._domElementKeyEvents = null; }; this.saveState = function() { scope.target0.copy(scope.target); scope.position0.copy(scope.object.position); scope.zoom0 = scope.object.zoom; }; this.reset = function() { scope.target.copy(scope.target0); scope.object.position.copy(scope.position0); scope.object.zoom = scope.zoom0; scope.object.updateProjectionMatrix(); scope.dispatchEvent(_changeEvent2); scope.update(); state = STATE.NONE; }; this.update = function() { const offset = new Vector32(); const quat = new Quaternion2().setFromUnitVectors(object.up, new Vector32(0, 1, 0)); const quatInverse = quat.clone().invert(); const lastPosition = new Vector32(); const lastQuaternion = new Quaternion2(); const lastTargetPosition = new Vector32(); const twoPI = 2 * Math.PI; return function update4(deltaTime = null) { const position = scope.object.position; offset.copy(position).sub(scope.target); offset.applyQuaternion(quat); spherical.setFromVector3(offset); if (scope.autoRotate && state === STATE.NONE) { rotateLeft(getAutoRotationAngle(deltaTime)); } if (scope.enableDamping) { spherical.theta += sphericalDelta.theta * scope.dampingFactor; spherical.phi += sphericalDelta.phi * scope.dampingFactor; } else { spherical.theta += sphericalDelta.theta; spherical.phi += sphericalDelta.phi; } let min2 = scope.minAzimuthAngle; let max2 = scope.maxAzimuthAngle; if (isFinite(min2) && isFinite(max2)) { if (min2 < -Math.PI) min2 += twoPI; else if (min2 > Math.PI) min2 -= twoPI; if (max2 < -Math.PI) max2 += twoPI; else if (max2 > Math.PI) max2 -= twoPI; if (min2 <= max2) { spherical.theta = Math.max(min2, Math.min(max2, spherical.theta)); } else { spherical.theta = spherical.theta > (min2 + max2) / 2 ? Math.max(min2, spherical.theta) : Math.min(max2, spherical.theta); } } spherical.phi = Math.max(scope.minPolarAngle, Math.min(scope.maxPolarAngle, spherical.phi)); spherical.makeSafe(); if (scope.enableDamping === true) { scope.target.addScaledVector(panOffset, scope.dampingFactor); } else { scope.target.add(panOffset); } if (scope.zoomToCursor && performCursorZoom || scope.object.isOrthographicCamera) { spherical.radius = clampDistance(spherical.radius); } else { spherical.radius = clampDistance(spherical.radius * scale); } offset.setFromSpherical(spherical); offset.applyQuaternion(quatInverse); position.copy(scope.target).add(offset); scope.object.lookAt(scope.target); if (scope.enableDamping === true) { sphericalDelta.theta *= 1 - scope.dampingFactor; sphericalDelta.phi *= 1 - scope.dampingFactor; panOffset.multiplyScalar(1 - scope.dampingFactor); } else { sphericalDelta.set(0, 0, 0); panOffset.set(0, 0, 0); } let zoomChanged = false; if (scope.zoomToCursor && performCursorZoom) { let newRadius = null; if (scope.object.isPerspectiveCamera) { const prevRadius = offset.length(); newRadius = clampDistance(prevRadius * scale); const radiusDelta = prevRadius - newRadius; scope.object.position.addScaledVector(dollyDirection, radiusDelta); scope.object.updateMatrixWorld(); } else if (scope.object.isOrthographicCamera) { const mouseBefore = new Vector32(mouse.x, mouse.y, 0); mouseBefore.unproject(scope.object); scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom / scale)); scope.object.updateProjectionMatrix(); zoomChanged = true; const mouseAfter = new Vector32(mouse.x, mouse.y, 0); mouseAfter.unproject(scope.object); scope.object.position.sub(mouseAfter).add(mouseBefore); scope.object.updateMatrixWorld(); newRadius = offset.length(); } else { console.warn("WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled."); scope.zoomToCursor = false; } if (newRadius !== null) { if (this.screenSpacePanning) { scope.target.set(0, 0, -1).transformDirection(scope.object.matrix).multiplyScalar(newRadius).add(scope.object.position); } else { _ray.origin.copy(scope.object.position); _ray.direction.set(0, 0, -1).transformDirection(scope.object.matrix); if (Math.abs(scope.object.up.dot(_ray.direction)) < TILT_LIMIT) { object.lookAt(scope.target); } else { _plane2.setFromNormalAndCoplanarPoint(scope.object.up, scope.target); _ray.intersectPlane(_plane2, scope.target); } } } } else if (scope.object.isOrthographicCamera) { scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom / scale)); scope.object.updateProjectionMatrix(); zoomChanged = true; } scale = 1; performCursorZoom = false; if (zoomChanged || lastPosition.distanceToSquared(scope.object.position) > EPS || 8 * (1 - lastQuaternion.dot(scope.object.quaternion)) > EPS || lastTargetPosition.distanceToSquared(scope.target) > 0) { scope.dispatchEvent(_changeEvent2); lastPosition.copy(scope.object.position); lastQuaternion.copy(scope.object.quaternion); lastTargetPosition.copy(scope.target); zoomChanged = false; return true; } return false; }; }(); this.dispose = function() { scope.domElement.removeEventListener("contextmenu", onContextMenu); scope.domElement.removeEventListener("pointerdown", onPointerDown); scope.domElement.removeEventListener("pointercancel", onPointerUp); scope.domElement.removeEventListener("wheel", onMouseWheel); scope.domElement.removeEventListener("pointermove", onPointerMove); scope.domElement.removeEventListener("pointerup", onPointerUp); if (scope._domElementKeyEvents !== null) { scope._domElementKeyEvents.removeEventListener("keydown", onKeyDown); scope._domElementKeyEvents = null; } }; const scope = this; const STATE = { NONE: -1, ROTATE: 0, DOLLY: 1, PAN: 2, TOUCH_ROTATE: 3, TOUCH_PAN: 4, TOUCH_DOLLY_PAN: 5, TOUCH_DOLLY_ROTATE: 6 }; let state = STATE.NONE; const EPS = 1e-6; const spherical = new Spherical(); const sphericalDelta = new Spherical(); let scale = 1; const panOffset = new Vector32(); const rotateStart = new Vector22(); const rotateEnd = new Vector22(); const rotateDelta = new Vector22(); const panStart = new Vector22(); const panEnd = new Vector22(); const panDelta = new Vector22(); const dollyStart = new Vector22(); const dollyEnd = new Vector22(); const dollyDelta = new Vector22(); const dollyDirection = new Vector32(); const mouse = new Vector22(); let performCursorZoom = false; const pointers = []; const pointerPositions = {}; function getAutoRotationAngle(deltaTime) { if (deltaTime !== null) { return 2 * Math.PI / 60 * scope.autoRotateSpeed * deltaTime; } else { return 2 * Math.PI / 60 / 60 * scope.autoRotateSpeed; } } function getZoomScale() { return Math.pow(0.95, scope.zoomSpeed); } function rotateLeft(angle) { sphericalDelta.theta -= angle; } function rotateUp(angle) { sphericalDelta.phi -= angle; } const panLeft = function() { const v = new Vector32(); return function panLeft2(distance, objectMatrix) { v.setFromMatrixColumn(objectMatrix, 0); v.multiplyScalar(-distance); panOffset.add(v); }; }(); const panUp = function() { const v = new Vector32(); return function panUp2(distance, objectMatrix) { if (scope.screenSpacePanning === true) { v.setFromMatrixColumn(objectMatrix, 1); } else { v.setFromMatrixColumn(objectMatrix, 0); v.crossVectors(scope.object.up, v); } v.multiplyScalar(distance); panOffset.add(v); }; }(); const pan = function() { const offset = new Vector32(); return function pan2(deltaX, deltaY) { const element = scope.domElement; if (scope.object.isPerspectiveCamera) { const position = scope.object.position; offset.copy(position).sub(scope.target); let targetDistance = offset.length(); targetDistance *= Math.tan(scope.object.fov / 2 * Math.PI / 180); panLeft(2 * deltaX * targetDistance / element.clientHeight, scope.object.matrix); panUp(2 * deltaY * targetDistance / element.clientHeight, scope.object.matrix); } else if (scope.object.isOrthographicCamera) { panLeft(deltaX * (scope.object.right - scope.object.left) / scope.object.zoom / element.clientWidth, scope.object.matrix); panUp(deltaY * (scope.object.top - scope.object.bottom) / scope.object.zoom / element.clientHeight, scope.object.matrix); } else { console.warn("WARNING: OrbitControls.js encountered an unknown camera type - pan disabled."); scope.enablePan = false; } }; }(); function dollyOut(dollyScale) { if (scope.object.isPerspectiveCamera || scope.object.isOrthographicCamera) { scale /= dollyScale; } else { console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."); scope.enableZoom = false; } } function dollyIn(dollyScale) { if (scope.object.isPerspectiveCamera || scope.object.isOrthographicCamera) { scale *= dollyScale; } else { console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."); scope.enableZoom = false; } } function updateMouseParameters(event) { if (!scope.zoomToCursor) { return; } performCursorZoom = true; const rect = scope.domElement.getBoundingClientRect(); const x3 = event.clientX - rect.left; const y3 = event.clientY - rect.top; const w = rect.width; const h = rect.height; mouse.x = x3 / w * 2 - 1; mouse.y = -(y3 / h) * 2 + 1; dollyDirection.set(mouse.x, mouse.y, 1).unproject(scope.object).sub(scope.object.position).normalize(); } function clampDistance(dist) { return Math.max(scope.minDistance, Math.min(scope.maxDistance, dist)); } function handleMouseDownRotate(event) { rotateStart.set(event.clientX, event.clientY); } function handleMouseDownDolly(event) { updateMouseParameters(event); dollyStart.set(event.clientX, event.clientY); } function handleMouseDownPan(event) { panStart.set(event.clientX, event.clientY); } function handleMouseMoveRotate(event) { rotateEnd.set(event.clientX, event.clientY); rotateDelta.subVectors(rotateEnd, rotateStart).multiplyScalar(scope.rotateSpeed); const element = scope.domElement; rotateLeft(2 * Math.PI * rotateDelta.x / element.clientHeight); rotateUp(2 * Math.PI * rotateDelta.y / element.clientHeight); rotateStart.copy(rotateEnd); scope.update(); } function handleMouseMoveDolly(event) { dollyEnd.set(event.clientX, event.clientY); dollyDelta.subVectors(dollyEnd, dollyStart); if (dollyDelta.y > 0) { dollyOut(getZoomScale()); } else if (dollyDelta.y < 0) { dollyIn(getZoomScale()); } dollyStart.copy(dollyEnd); scope.update(); } function handleMouseMovePan(event) { panEnd.set(event.clientX, event.clientY); panDelta.subVectors(panEnd, panStart).multiplyScalar(scope.panSpeed); pan(panDelta.x, panDelta.y); panStart.copy(panEnd); scope.update(); } function handleMouseWheel(event) { updateMouseParameters(event); if (event.deltaY < 0) { dollyIn(getZoomScale()); } else if (event.deltaY > 0) { dollyOut(getZoomScale()); } scope.update(); } function handleKeyDown(event) { let needsUpdate = false; switch (event.code) { case scope.keys.UP: if (event.ctrlKey || event.metaKey || event.shiftKey) { rotateUp(2 * Math.PI * scope.rotateSpeed / scope.domElement.clientHeight); } else { pan(0, scope.keyPanSpeed); } needsUpdate = true; break; case scope.keys.BOTTOM: if (event.ctrlKey || event.metaKey || event.shiftKey) { rotateUp(-2 * Math.PI * scope.rotateSpeed / scope.domElement.clientHeight); } else { pan(0, -scope.keyPanSpeed); } needsUpdate = true; break; case scope.keys.LEFT: if (event.ctrlKey || event.metaKey || event.shiftKey) { rotateLeft(2 * Math.PI * scope.rotateSpeed / scope.domElement.clientHeight); } else { pan(scope.keyPanSpeed, 0); } needsUpdate = true; break; case scope.keys.RIGHT: if (event.ctrlKey || event.metaKey || event.shiftKey) { rotateLeft(-2 * Math.PI * scope.rotateSpeed / scope.domElement.clientHeight); } else { pan(-scope.keyPanSpeed, 0); } needsUpdate = true; break; } if (needsUpdate) { event.preventDefault(); scope.update(); } } function handleTouchStartRotate() { if (pointers.length === 1) { rotateStart.set(pointers[0].pageX, pointers[0].pageY); } else { const x3 = 0.5 * (pointers[0].pageX + pointers[1].pageX); const y3 = 0.5 * (pointers[0].pageY + pointers[1].pageY); rotateStart.set(x3, y3); } } function handleTouchStartPan() { if (pointers.length === 1) { panStart.set(pointers[0].pageX, pointers[0].pageY); } else { const x3 = 0.5 * (pointers[0].pageX + pointers[1].pageX); const y3 = 0.5 * (pointers[0].pageY + pointers[1].pageY); panStart.set(x3, y3); } } function handleTouchStartDolly() { const dx = pointers[0].pageX - pointers[1].pageX; const dy = pointers[0].pageY - pointers[1].pageY; const distance = Math.sqrt(dx * dx + dy * dy); dollyStart.set(0, distance); } function handleTouchStartDollyPan() { if (scope.enableZoom) handleTouchStartDolly(); if (scope.enablePan) handleTouchStartPan(); } function handleTouchStartDollyRotate() { if (scope.enableZoom) handleTouchStartDolly(); if (scope.enableRotate) handleTouchStartRotate(); } function handleTouchMoveRotate(event) { if (pointers.length == 1) { rotateEnd.set(event.pageX, event.pageY); } else { const position = getSecondPointerPosition(event); const x3 = 0.5 * (event.pageX + position.x); const y3 = 0.5 * (event.pageY + position.y); rotateEnd.set(x3, y3); } rotateDelta.subVectors(rotateEnd, rotateStart).multiplyScalar(scope.rotateSpeed); const element = scope.domElement; rotateLeft(2 * Math.PI * rotateDelta.x / element.clientHeight); rotateUp(2 * Math.PI * rotateDelta.y / element.clientHeight); rotateStart.copy(rotateEnd); } function handleTouchMovePan(event) { if (pointers.length === 1) { panEnd.set(event.pageX, event.pageY); } else { const position = getSecondPointerPosition(event); const x3 = 0.5 * (event.pageX + position.x); const y3 = 0.5 * (event.pageY + position.y); panEnd.set(x3, y3); } panDelta.subVectors(panEnd, panStart).multiplyScalar(scope.panSpeed); pan(panDelta.x, panDelta.y); panStart.copy(panEnd); } function handleTouchMoveDolly(event) { const position = getSecondPointerPosition(event); const dx = event.pageX - position.x; const dy = event.pageY - position.y; const distance = Math.sqrt(dx * dx + dy * dy); dollyEnd.set(0, distance); dollyDelta.set(0, Math.pow(dollyEnd.y / dollyStart.y, scope.zoomSpeed)); dollyOut(dollyDelta.y); dollyStart.copy(dollyEnd); } function handleTouchMoveDollyPan(event) { if (scope.enableZoom) handleTouchMoveDolly(event); if (scope.enablePan) handleTouchMovePan(event); } function handleTouchMoveDollyRotate(event) { if (scope.enableZoom) handleTouchMoveDolly(event); if (scope.enableRotate) handleTouchMoveRotate(event); } function onPointerDown(event) { if (scope.enabled === false) return; if (pointers.length === 0) { scope.domElement.setPointerCapture(event.pointerId); scope.domElement.addEventListener("pointermove", onPointerMove); scope.domElement.addEventListener("pointerup", onPointerUp); } addPointer(event); if (event.pointerType === "touch") { onTouchStart(event); } else { onMouseDown(event); } } function onPointerMove(event) { if (scope.enabled === false) return; if (event.pointerType === "touch") { onTouchMove(event); } else { onMouseMove(event); } } function onPointerUp(event) { removePointer(event); if (pointers.length === 0) { scope.domElement.releasePointerCapture(event.pointerId); scope.domElement.removeEventListener("pointermove", onPointerMove); scope.domElement.removeEventListener("pointerup", onPointerUp); } scope.dispatchEvent(_endEvent2); state = STATE.NONE; } function onMouseDown(event) { let mouseAction; switch (event.button) { case 0: mouseAction = scope.mouseButtons.LEFT; break; case 1: mouseAction = scope.mouseButtons.MIDDLE; break; case 2: mouseAction = scope.mouseButtons.RIGHT; break; default: mouseAction = -1; } switch (mouseAction) { case MOUSE.DOLLY: if (scope.enableZoom === false) return; handleMouseDownDolly(event); state = STATE.DOLLY; break; case MOUSE.ROTATE: if (event.ctrlKey || event.metaKey || event.shiftKey) { if (scope.enablePan === false) return; handleMouseDownPan(event); state = STATE.PAN; } else { if (scope.enableRotate === false) return; handleMouseDownRotate(event); state = STATE.ROTATE; } break; case MOUSE.PAN: if (event.ctrlKey || event.metaKey || event.shiftKey) { if (scope.enableRotate === false) return; handleMouseDownRotate(event); state = STATE.ROTATE; } else { if (scope.enablePan === false) return; handleMouseDownPan(event); state = STATE.PAN; } break; default: state = STATE.NONE; } if (state !== STATE.NONE) { scope.dispatchEvent(_startEvent2); } } function onMouseMove(event) { switch (state) { case STATE.ROTATE: if (scope.enableRotate === false) return; handleMouseMoveRotate(event); break; case STATE.DOLLY: if (scope.enableZoom === false) return; handleMouseMoveDolly(event); break; case STATE.PAN: if (scope.enablePan === false) return; handleMouseMovePan(event); break; } } function onMouseWheel(event) { if (scope.enabled === false || scope.enableZoom === false || state !== STATE.NONE) return; event.preventDefault(); scope.dispatchEvent(_startEvent2); handleMouseWheel(event); scope.dispatchEvent(_endEvent2); } function onKeyDown(event) { if (scope.enabled === false || scope.enablePan === false) return; handleKeyDown(event); } function onTouchStart(event) { trackPointer(event); switch (pointers.length) { case 1: switch (scope.touches.ONE) { case TOUCH.ROTATE: if (scope.enableRotate === false) return; handleTouchStartRotate(); state = STATE.TOUCH_ROTATE; break; case TOUCH.PAN: if (scope.enablePan === false) return; handleTouchStartPan(); state = STATE.TOUCH_PAN; break; default: state = STATE.NONE; } break; case 2: switch (scope.touches.TWO) { case TOUCH.DOLLY_PAN: if (scope.enableZoom === false && scope.enablePan === false) return; handleTouchStartDollyPan(); state = STATE.TOUCH_DOLLY_PAN; break; case TOUCH.DOLLY_ROTATE: if (scope.enableZoom === false && scope.enableRotate === false) return; handleTouchStartDollyRotate(); state = STATE.TOUCH_DOLLY_ROTATE; break; default: state = STATE.NONE; } break; default: state = STATE.NONE; } if (state !== STATE.NONE) { scope.dispatchEvent(_startEvent2); } } function onTouchMove(event) { trackPointer(event); switch (state) { case STATE.TOUCH_ROTATE: if (scope.enableRotate === false) return; handleTouchMoveRotate(event); scope.update(); break; case STATE.TOUCH_PAN: if (scope.enablePan === false) return; handleTouchMovePan(event); scope.update(); break; case STATE.TOUCH_DOLLY_PAN: if (scope.enableZoom === false && scope.enablePan === false) return; handleTouchMoveDollyPan(event); scope.update(); break; case STATE.TOUCH_DOLLY_ROTATE: if (scope.enableZoom === false && scope.enableRotate === false) return; handleTouchMoveDollyRotate(event); scope.update(); break; default: state = STATE.NONE; } } function onContextMenu(event) { if (scope.enabled === false) return; event.preventDefault(); } function addPointer(event) { pointers.push(event); } function removePointer(event) { delete pointerPositions[event.pointerId]; for (let i = 0; i < pointers.length; i++) { if (pointers[i].pointerId == event.pointerId) { pointers.splice(i, 1); return; } } } function trackPointer(event) { let position = pointerPositions[event.pointerId]; if (position === void 0) { position = new Vector22(); pointerPositions[event.pointerId] = position; } position.set(event.pageX, event.pageY); } function getSecondPointerPosition(event) { const pointer = event.pointerId === pointers[0].pointerId ? pointers[1] : pointers[0]; return pointerPositions[pointer.pointerId]; } scope.domElement.addEventListener("contextmenu", onContextMenu); scope.domElement.addEventListener("pointerdown", onPointerDown); scope.domElement.addEventListener("pointercancel", onPointerUp); scope.domElement.addEventListener("wheel", onMouseWheel, { passive: false }); this.update(); } }; // node_modules/three/examples/jsm/controls/FlyControls.js var _changeEvent3 = { type: "change" }; var FlyControls = class extends EventDispatcher2 { constructor(object, domElement) { super(); this.object = object; this.domElement = domElement; this.enabled = true; this.movementSpeed = 1; this.rollSpeed = 5e-3; this.dragToLook = false; this.autoForward = false; const scope = this; const EPS = 1e-6; const lastQuaternion = new Quaternion2(); const lastPosition = new Vector32(); this.tmpQuaternion = new Quaternion2(); this.status = 0; this.moveState = { up: 0, down: 0, left: 0, right: 0, forward: 0, back: 0, pitchUp: 0, pitchDown: 0, yawLeft: 0, yawRight: 0, rollLeft: 0, rollRight: 0 }; this.moveVector = new Vector32(0, 0, 0); this.rotationVector = new Vector32(0, 0, 0); this.keydown = function(event) { if (event.altKey || this.enabled === false) { return; } switch (event.code) { case "ShiftLeft": case "ShiftRight": this.movementSpeedMultiplier = 0.1; break; case "KeyW": this.moveState.forward = 1; break; case "KeyS": this.moveState.back = 1; break; case "KeyA": this.moveState.left = 1; break; case "KeyD": this.moveState.right = 1; break; case "KeyR": this.moveState.up = 1; break; case "KeyF": this.moveState.down = 1; break; case "ArrowUp": this.moveState.pitchUp = 1; break; case "ArrowDown": this.moveState.pitchDown = 1; break; case "ArrowLeft": this.moveState.yawLeft = 1; break; case "ArrowRight": this.moveState.yawRight = 1; break; case "KeyQ": this.moveState.rollLeft = 1; break; case "KeyE": this.moveState.rollRight = 1; break; } this.updateMovementVector(); this.updateRotationVector(); }; this.keyup = function(event) { if (this.enabled === false) return; switch (event.code) { case "ShiftLeft": case "ShiftRight": this.movementSpeedMultiplier = 1; break; case "KeyW": this.moveState.forward = 0; break; case "KeyS": this.moveState.back = 0; break; case "KeyA": this.moveState.left = 0; break; case "KeyD": this.moveState.right = 0; break; case "KeyR": this.moveState.up = 0; break; case "KeyF": this.moveState.down = 0; break; case "ArrowUp": this.moveState.pitchUp = 0; break; case "ArrowDown": this.moveState.pitchDown = 0; break; case "ArrowLeft": this.moveState.yawLeft = 0; break; case "ArrowRight": this.moveState.yawRight = 0; break; case "KeyQ": this.moveState.rollLeft = 0; break; case "KeyE": this.moveState.rollRight = 0; break; } this.updateMovementVector(); this.updateRotationVector(); }; this.pointerdown = function(event) { if (this.enabled === false) return; if (this.dragToLook) { this.status++; } else { switch (event.button) { case 0: this.moveState.forward = 1; break; case 2: this.moveState.back = 1; break; } this.updateMovementVector(); } }; this.pointermove = function(event) { if (this.enabled === false) return; if (!this.dragToLook || this.status > 0) { const container = this.getContainerDimensions(); const halfWidth = container.size[0] / 2; const halfHeight = container.size[1] / 2; this.moveState.yawLeft = -(event.pageX - container.offset[0] - halfWidth) / halfWidth; this.moveState.pitchDown = (event.pageY - container.offset[1] - halfHeight) / halfHeight; this.updateRotationVector(); } }; this.pointerup = function(event) { if (this.enabled === false) return; if (this.dragToLook) { this.status--; this.moveState.yawLeft = this.moveState.pitchDown = 0; } else { switch (event.button) { case 0: this.moveState.forward = 0; break; case 2: this.moveState.back = 0; break; } this.updateMovementVector(); } this.updateRotationVector(); }; this.contextMenu = function(event) { if (this.enabled === false) return; event.preventDefault(); }; this.update = function(delta) { if (this.enabled === false) return; const moveMult = delta * scope.movementSpeed; const rotMult = delta * scope.rollSpeed; scope.object.translateX(scope.moveVector.x * moveMult); scope.object.translateY(scope.moveVector.y * moveMult); scope.object.translateZ(scope.moveVector.z * moveMult); scope.tmpQuaternion.set(scope.rotationVector.x * rotMult, scope.rotationVector.y * rotMult, scope.rotationVector.z * rotMult, 1).normalize(); scope.object.quaternion.multiply(scope.tmpQuaternion); if (lastPosition.distanceToSquared(scope.object.position) > EPS || 8 * (1 - lastQuaternion.dot(scope.object.quaternion)) > EPS) { scope.dispatchEvent(_changeEvent3); lastQuaternion.copy(scope.object.quaternion); lastPosition.copy(scope.object.position); } }; this.updateMovementVector = function() { const forward = this.moveState.forward || this.autoForward && !this.moveState.back ? 1 : 0; this.moveVector.x = -this.moveState.left + this.moveState.right; this.moveVector.y = -this.moveState.down + this.moveState.up; this.moveVector.z = -forward + this.moveState.back; }; this.updateRotationVector = function() { this.rotationVector.x = -this.moveState.pitchDown + this.moveState.pitchUp; this.rotationVector.y = -this.moveState.yawRight + this.moveState.yawLeft; this.rotationVector.z = -this.moveState.rollRight + this.moveState.rollLeft; }; this.getContainerDimensions = function() { if (this.domElement != document) { return { size: [this.domElement.offsetWidth, this.domElement.offsetHeight], offset: [this.domElement.offsetLeft, this.domElement.offsetTop] }; } else { return { size: [window.innerWidth, window.innerHeight], offset: [0, 0] }; } }; this.dispose = function() { this.domElement.removeEventListener("contextmenu", _contextmenu); this.domElement.removeEventListener("pointerdown", _pointerdown); this.domElement.removeEventListener("pointermove", _pointermove); this.domElement.removeEventListener("pointerup", _pointerup); window.removeEventListener("keydown", _keydown); window.removeEventListener("keyup", _keyup); }; const _contextmenu = this.contextMenu.bind(this); const _pointermove = this.pointermove.bind(this); const _pointerdown = this.pointerdown.bind(this); const _pointerup = this.pointerup.bind(this); const _keydown = this.keydown.bind(this); const _keyup = this.keyup.bind(this); this.domElement.addEventListener("contextmenu", _contextmenu); this.domElement.addEventListener("pointerdown", _pointerdown); this.domElement.addEventListener("pointermove", _pointermove); this.domElement.addEventListener("pointerup", _pointerup); window.addEventListener("keydown", _keydown); window.addEventListener("keyup", _keyup); this.updateMovementVector(); this.updateRotationVector(); } }; // node_modules/three/examples/jsm/shaders/CopyShader.js var CopyShader = { name: "CopyShader", uniforms: { "tDiffuse": { value: null }, "opacity": { value: 1 } }, vertexShader: ( /* glsl */ ` varying vec2 vUv; void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); }` ), fragmentShader: ( /* glsl */ ` uniform float opacity; uniform sampler2D tDiffuse; varying vec2 vUv; void main() { vec4 texel = texture2D( tDiffuse, vUv ); gl_FragColor = opacity * texel; }` ) }; // node_modules/three/examples/jsm/postprocessing/Pass.js var Pass = class { constructor() { this.isPass = true; this.enabled = true; this.needsSwap = true; this.clear = false; this.renderToScreen = false; } setSize() { } render() { console.error("THREE.Pass: .render() must be implemented in derived pass."); } dispose() { } }; var _camera = new OrthographicCamera2(-1, 1, 1, -1, 0, 1); var _geometry = new BufferGeometry2(); _geometry.setAttribute("position", new Float32BufferAttribute2([-1, 3, 0, -1, -1, 0, 3, -1, 0], 3)); _geometry.setAttribute("uv", new Float32BufferAttribute2([0, 2, 0, 0, 2, 0], 2)); var FullScreenQuad = class { constructor(material) { this._mesh = new Mesh2(_geometry, material); } dispose() { this._mesh.geometry.dispose(); } render(renderer3) { renderer3.render(this._mesh, _camera); } get material() { return this._mesh.material; } set material(value) { this._mesh.material = value; } }; // node_modules/three/examples/jsm/postprocessing/ShaderPass.js var ShaderPass = class extends Pass { constructor(shader, textureID) { super(); this.textureID = textureID !== void 0 ? textureID : "tDiffuse"; if (shader instanceof ShaderMaterial2) { this.uniforms = shader.uniforms; this.material = shader; } else if (shader) { this.uniforms = UniformsUtils2.clone(shader.uniforms); this.material = new ShaderMaterial2({ name: shader.name !== void 0 ? shader.name : "unspecified", defines: Object.assign({}, shader.defines), uniforms: this.uniforms, vertexShader: shader.vertexShader, fragmentShader: shader.fragmentShader }); } this.fsQuad = new FullScreenQuad(this.material); } render(renderer3, writeBuffer, readBuffer) { if (this.uniforms[this.textureID]) { this.uniforms[this.textureID].value = readBuffer.texture; } this.fsQuad.material = this.material; if (this.renderToScreen) { renderer3.setRenderTarget(null); this.fsQuad.render(renderer3); } else { renderer3.setRenderTarget(writeBuffer); if (this.clear) renderer3.clear(renderer3.autoClearColor, renderer3.autoClearDepth, renderer3.autoClearStencil); this.fsQuad.render(renderer3); } } dispose() { this.material.dispose(); this.fsQuad.dispose(); } }; // node_modules/three/examples/jsm/postprocessing/MaskPass.js var MaskPass = class extends Pass { constructor(scene3, camera3) { super(); this.scene = scene3; this.camera = camera3; this.clear = true; this.needsSwap = false; this.inverse = false; } render(renderer3, writeBuffer, readBuffer) { const context = renderer3.getContext(); const state = renderer3.state; state.buffers.color.setMask(false); state.buffers.depth.setMask(false); state.buffers.color.setLocked(true); state.buffers.depth.setLocked(true); let writeValue, clearValue; if (this.inverse) { writeValue = 0; clearValue = 1; } else { writeValue = 1; clearValue = 0; } state.buffers.stencil.setTest(true); state.buffers.stencil.setOp(context.REPLACE, context.REPLACE, context.REPLACE); state.buffers.stencil.setFunc(context.ALWAYS, writeValue, 4294967295); state.buffers.stencil.setClear(clearValue); state.buffers.stencil.setLocked(true); renderer3.setRenderTarget(readBuffer); if (this.clear) renderer3.clear(); renderer3.render(this.scene, this.camera); renderer3.setRenderTarget(writeBuffer); if (this.clear) renderer3.clear(); renderer3.render(this.scene, this.camera); state.buffers.color.setLocked(false); state.buffers.depth.setLocked(false); state.buffers.color.setMask(true); state.buffers.depth.setMask(true); state.buffers.stencil.setLocked(false); state.buffers.stencil.setFunc(context.EQUAL, 1, 4294967295); state.buffers.stencil.setOp(context.KEEP, context.KEEP, context.KEEP); state.buffers.stencil.setLocked(true); } }; var ClearMaskPass = class extends Pass { constructor() { super(); this.needsSwap = false; } render(renderer3) { renderer3.state.buffers.stencil.setLocked(false); renderer3.state.buffers.stencil.setTest(false); } }; // node_modules/three/examples/jsm/postprocessing/EffectComposer.js var EffectComposer = class { constructor(renderer3, renderTarget) { this.renderer = renderer3; this._pixelRatio = renderer3.getPixelRatio(); if (renderTarget === void 0) { const size = renderer3.getSize(new Vector22()); this._width = size.width; this._height = size.height; renderTarget = new WebGLRenderTarget2(this._width * this._pixelRatio, this._height * this._pixelRatio, { type: HalfFloatType2 }); renderTarget.texture.name = "EffectComposer.rt1"; } else { this._width = renderTarget.width; this._height = renderTarget.height; } this.renderTarget1 = renderTarget; this.renderTarget2 = renderTarget.clone(); this.renderTarget2.texture.name = "EffectComposer.rt2"; this.writeBuffer = this.renderTarget1; this.readBuffer = this.renderTarget2; this.renderToScreen = true; this.passes = []; this.copyPass = new ShaderPass(CopyShader); this.copyPass.material.blending = NoBlending2; this.clock = new Clock(); } swapBuffers() { const tmp2 = this.readBuffer; this.readBuffer = this.writeBuffer; this.writeBuffer = tmp2; } addPass(pass) { this.passes.push(pass); pass.setSize(this._width * this._pixelRatio, this._height * this._pixelRatio); } insertPass(pass, index6) { this.passes.splice(index6, 0, pass); pass.setSize(this._width * this._pixelRatio, this._height * this._pixelRatio); } removePass(pass) { const index6 = this.passes.indexOf(pass); if (index6 !== -1) { this.passes.splice(index6, 1); } } isLastEnabledPass(passIndex) { for (let i = passIndex + 1; i < this.passes.length; i++) { if (this.passes[i].enabled) { return false; } } return true; } render(deltaTime) { if (deltaTime === void 0) { deltaTime = this.clock.getDelta(); } const currentRenderTarget = this.renderer.getRenderTarget(); let maskActive = false; for (let i = 0, il = this.passes.length; i < il; i++) { const pass = this.passes[i]; if (pass.enabled === false) continue; pass.renderToScreen = this.renderToScreen && this.isLastEnabledPass(i); pass.render(this.renderer, this.writeBuffer, this.readBuffer, deltaTime, maskActive); if (pass.needsSwap) { if (maskActive) { const context = this.renderer.getContext(); const stencil = this.renderer.state.buffers.stencil; stencil.setFunc(context.NOTEQUAL, 1, 4294967295); this.copyPass.render(this.renderer, this.writeBuffer, this.readBuffer, deltaTime); stencil.setFunc(context.EQUAL, 1, 4294967295); } this.swapBuffers(); } if (MaskPass !== void 0) { if (pass instanceof MaskPass) { maskActive = true; } else if (pass instanceof ClearMaskPass) { maskActive = false; } } } this.renderer.setRenderTarget(currentRenderTarget); } reset(renderTarget) { if (renderTarget === void 0) { const size = this.renderer.getSize(new Vector22()); this._pixelRatio = this.renderer.getPixelRatio(); this._width = size.width; this._height = size.height; renderTarget = this.renderTarget1.clone(); renderTarget.setSize(this._width * this._pixelRatio, this._height * this._pixelRatio); } this.renderTarget1.dispose(); this.renderTarget2.dispose(); this.renderTarget1 = renderTarget; this.renderTarget2 = renderTarget.clone(); this.writeBuffer = this.renderTarget1; this.readBuffer = this.renderTarget2; } setSize(width, height) { this._width = width; this._height = height; const effectiveWidth = this._width * this._pixelRatio; const effectiveHeight = this._height * this._pixelRatio; this.renderTarget1.setSize(effectiveWidth, effectiveHeight); this.renderTarget2.setSize(effectiveWidth, effectiveHeight); for (let i = 0; i < this.passes.length; i++) { this.passes[i].setSize(effectiveWidth, effectiveHeight); } } setPixelRatio(pixelRatio) { this._pixelRatio = pixelRatio; this.setSize(this._width, this._height); } dispose() { this.renderTarget1.dispose(); this.renderTarget2.dispose(); this.copyPass.dispose(); } }; // node_modules/three/examples/jsm/postprocessing/RenderPass.js var RenderPass = class extends Pass { constructor(scene3, camera3, overrideMaterial = null, clearColor = null, clearAlpha = null) { super(); this.scene = scene3; this.camera = camera3; this.overrideMaterial = overrideMaterial; this.clearColor = clearColor; this.clearAlpha = clearAlpha; this.clear = true; this.clearDepth = false; this.needsSwap = false; this._oldClearColor = new Color2(); } render(renderer3, writeBuffer, readBuffer) { const oldAutoClear = renderer3.autoClear; renderer3.autoClear = false; let oldClearAlpha, oldOverrideMaterial; if (this.overrideMaterial !== null) { oldOverrideMaterial = this.scene.overrideMaterial; this.scene.overrideMaterial = this.overrideMaterial; } if (this.clearColor !== null) { renderer3.getClearColor(this._oldClearColor); renderer3.setClearColor(this.clearColor); } if (this.clearAlpha !== null) { oldClearAlpha = renderer3.getClearAlpha(); renderer3.setClearAlpha(this.clearAlpha); } if (this.clearDepth == true) { renderer3.clearDepth(); } renderer3.setRenderTarget(this.renderToScreen ? null : readBuffer); if (this.clear === true) { renderer3.clear(renderer3.autoClearColor, renderer3.autoClearDepth, renderer3.autoClearStencil); } renderer3.render(this.scene, this.camera); if (this.clearColor !== null) { renderer3.setClearColor(this._oldClearColor); } if (this.clearAlpha !== null) { renderer3.setClearAlpha(oldClearAlpha); } if (this.overrideMaterial !== null) { this.scene.overrideMaterial = oldOverrideMaterial; } renderer3.autoClear = oldAutoClear; } }; // node_modules/@babel/runtime/helpers/esm/extends.js function _extends() { _extends = Object.assign ? Object.assign.bind() : function(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } // node_modules/@babel/runtime/helpers/esm/assertThisInitialized.js function _assertThisInitialized2(self2) { if (self2 === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self2; } // node_modules/@babel/runtime/helpers/esm/setPrototypeOf.js function _setPrototypeOf2(o, p) { _setPrototypeOf2 = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf3(o2, p2) { o2.__proto__ = p2; return o2; }; return _setPrototypeOf2(o, p); } // node_modules/@babel/runtime/helpers/esm/inheritsLoose.js function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; _setPrototypeOf2(subClass, superClass); } // node_modules/@babel/runtime/helpers/esm/getPrototypeOf.js function _getPrototypeOf2(o) { _getPrototypeOf2 = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf3(o2) { return o2.__proto__ || Object.getPrototypeOf(o2); }; return _getPrototypeOf2(o); } // node_modules/@babel/runtime/helpers/esm/isNativeFunction.js function _isNativeFunction(fn) { try { return Function.toString.call(fn).indexOf("[native code]") !== -1; } catch (e) { return typeof fn === "function"; } } // node_modules/@babel/runtime/helpers/esm/isNativeReflectConstruct.js function _isNativeReflectConstruct2() { 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; } } // node_modules/@babel/runtime/helpers/esm/construct.js function _construct2(Parent, args, Class) { if (_isNativeReflectConstruct2()) { _construct2 = Reflect.construct.bind(); } else { _construct2 = function _construct3(Parent2, args2, Class2) { var a2 = [null]; a2.push.apply(a2, args2); var Constructor = Function.bind.apply(Parent2, a2); var instance = new Constructor(); if (Class2) _setPrototypeOf2(instance, Class2.prototype); return instance; }; } return _construct2.apply(null, arguments); } // node_modules/@babel/runtime/helpers/esm/wrapNativeSuper.js function _wrapNativeSuper(Class) { var _cache3 = typeof Map === "function" ? /* @__PURE__ */ new Map() : void 0; _wrapNativeSuper = function _wrapNativeSuper2(Class2) { if (Class2 === null || !_isNativeFunction(Class2)) return Class2; if (typeof Class2 !== "function") { throw new TypeError("Super expression must either be null or a function"); } if (typeof _cache3 !== "undefined") { if (_cache3.has(Class2)) return _cache3.get(Class2); _cache3.set(Class2, Wrapper); } function Wrapper() { return _construct2(Class2, arguments, _getPrototypeOf2(this).constructor); } Wrapper.prototype = Object.create(Class2.prototype, { constructor: { value: Wrapper, enumerable: false, writable: true, configurable: true } }); return _setPrototypeOf2(Wrapper, Class2); }; return _wrapNativeSuper(Class); } // node_modules/polished/dist/polished.esm.js var ERRORS = { "1": "Passed invalid arguments to hsl, please pass multiple numbers e.g. hsl(360, 0.75, 0.4) or an object e.g. rgb({ hue: 255, saturation: 0.4, lightness: 0.75 }).\n\n", "2": "Passed invalid arguments to hsla, please pass multiple numbers e.g. hsla(360, 0.75, 0.4, 0.7) or an object e.g. rgb({ hue: 255, saturation: 0.4, lightness: 0.75, alpha: 0.7 }).\n\n", "3": "Passed an incorrect argument to a color function, please pass a string representation of a color.\n\n", "4": "Couldn't generate valid rgb string from %s, it returned %s.\n\n", "5": "Couldn't parse the color string. Please provide the color as a string in hex, rgb, rgba, hsl or hsla notation.\n\n", "6": "Passed invalid arguments to rgb, please pass multiple numbers e.g. rgb(255, 205, 100) or an object e.g. rgb({ red: 255, green: 205, blue: 100 }).\n\n", "7": "Passed invalid arguments to rgba, please pass multiple numbers e.g. rgb(255, 205, 100, 0.75) or an object e.g. rgb({ red: 255, green: 205, blue: 100, alpha: 0.75 }).\n\n", "8": "Passed invalid argument to toColorString, please pass a RgbColor, RgbaColor, HslColor or HslaColor object.\n\n", "9": "Please provide a number of steps to the modularScale helper.\n\n", "10": "Please pass a number or one of the predefined scales to the modularScale helper as the ratio.\n\n", "11": 'Invalid value passed as base to modularScale, expected number or em string but got "%s"\n\n', "12": 'Expected a string ending in "px" or a number passed as the first argument to %s(), got "%s" instead.\n\n', "13": 'Expected a string ending in "px" or a number passed as the second argument to %s(), got "%s" instead.\n\n', "14": 'Passed invalid pixel value ("%s") to %s(), please pass a value like "12px" or 12.\n\n', "15": 'Passed invalid base value ("%s") to %s(), please pass a value like "12px" or 12.\n\n', "16": "You must provide a template to this method.\n\n", "17": "You passed an unsupported selector state to this method.\n\n", "18": "minScreen and maxScreen must be provided as stringified numbers with the same units.\n\n", "19": "fromSize and toSize must be provided as stringified numbers with the same units.\n\n", "20": "expects either an array of objects or a single object with the properties prop, fromSize, and toSize.\n\n", "21": "expects the objects in the first argument array to have the properties `prop`, `fromSize`, and `toSize`.\n\n", "22": "expects the first argument object to have the properties `prop`, `fromSize`, and `toSize`.\n\n", "23": "fontFace expects a name of a font-family.\n\n", "24": "fontFace expects either the path to the font file(s) or a name of a local copy.\n\n", "25": "fontFace expects localFonts to be an array.\n\n", "26": "fontFace expects fileFormats to be an array.\n\n", "27": "radialGradient requries at least 2 color-stops to properly render.\n\n", "28": "Please supply a filename to retinaImage() as the first argument.\n\n", "29": "Passed invalid argument to triangle, please pass correct pointingDirection e.g. 'right'.\n\n", "30": "Passed an invalid value to `height` or `width`. Please provide a pixel based unit.\n\n", "31": "The animation shorthand only takes 8 arguments. See the specification for more information: http://mdn.io/animation\n\n", "32": "To pass multiple animations please supply them in arrays, e.g. animation(['rotate', '2s'], ['move', '1s'])\nTo pass a single animation please supply them in simple values, e.g. animation('rotate', '2s')\n\n", "33": "The animation shorthand arrays can only have 8 elements. See the specification for more information: http://mdn.io/animation\n\n", "34": "borderRadius expects a radius value as a string or number as the second argument.\n\n", "35": 'borderRadius expects one of "top", "bottom", "left" or "right" as the first argument.\n\n', "36": "Property must be a string value.\n\n", "37": "Syntax Error at %s.\n\n", "38": "Formula contains a function that needs parentheses at %s.\n\n", "39": "Formula is missing closing parenthesis at %s.\n\n", "40": "Formula has too many closing parentheses at %s.\n\n", "41": "All values in a formula must have the same unit or be unitless.\n\n", "42": "Please provide a number of steps to the modularScale helper.\n\n", "43": "Please pass a number or one of the predefined scales to the modularScale helper as the ratio.\n\n", "44": "Invalid value passed as base to modularScale, expected number or em/rem string but got %s.\n\n", "45": "Passed invalid argument to hslToColorString, please pass a HslColor or HslaColor object.\n\n", "46": "Passed invalid argument to rgbToColorString, please pass a RgbColor or RgbaColor object.\n\n", "47": "minScreen and maxScreen must be provided as stringified numbers with the same units.\n\n", "48": "fromSize and toSize must be provided as stringified numbers with the same units.\n\n", "49": "Expects either an array of objects or a single object with the properties prop, fromSize, and toSize.\n\n", "50": "Expects the objects in the first argument array to have the properties prop, fromSize, and toSize.\n\n", "51": "Expects the first argument object to have the properties prop, fromSize, and toSize.\n\n", "52": "fontFace expects either the path to the font file(s) or a name of a local copy.\n\n", "53": "fontFace expects localFonts to be an array.\n\n", "54": "fontFace expects fileFormats to be an array.\n\n", "55": "fontFace expects a name of a font-family.\n\n", "56": "linearGradient requries at least 2 color-stops to properly render.\n\n", "57": "radialGradient requries at least 2 color-stops to properly render.\n\n", "58": "Please supply a filename to retinaImage() as the first argument.\n\n", "59": "Passed invalid argument to triangle, please pass correct pointingDirection e.g. 'right'.\n\n", "60": "Passed an invalid value to `height` or `width`. Please provide a pixel based unit.\n\n", "61": "Property must be a string value.\n\n", "62": "borderRadius expects a radius value as a string or number as the second argument.\n\n", "63": 'borderRadius expects one of "top", "bottom", "left" or "right" as the first argument.\n\n', "64": "The animation shorthand only takes 8 arguments. See the specification for more information: http://mdn.io/animation.\n\n", "65": "To pass multiple animations please supply them in arrays, e.g. animation(['rotate', '2s'], ['move', '1s'])\\nTo pass a single animation please supply them in simple values, e.g. animation('rotate', '2s').\n\n", "66": "The animation shorthand arrays can only have 8 elements. See the specification for more information: http://mdn.io/animation.\n\n", "67": "You must provide a template to this method.\n\n", "68": "You passed an unsupported selector state to this method.\n\n", "69": 'Expected a string ending in "px" or a number passed as the first argument to %s(), got %s instead.\n\n', "70": 'Expected a string ending in "px" or a number passed as the second argument to %s(), got %s instead.\n\n', "71": 'Passed invalid pixel value %s to %s(), please pass a value like "12px" or 12.\n\n', "72": 'Passed invalid base value %s to %s(), please pass a value like "12px" or 12.\n\n', "73": "Please provide a valid CSS variable.\n\n", "74": "CSS variable not found and no default was provided.\n\n", "75": "important requires a valid style object, got a %s instead.\n\n", "76": "fromSize and toSize must be provided as stringified numbers with the same units as minScreen and maxScreen.\n\n", "77": 'remToPx expects a value in "rem" but you provided it in "%s".\n\n', "78": 'base must be set in "px" or "%" but you set it in "%s".\n' }; function format() { for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } var a2 = args[0]; var b = []; var c2; for (c2 = 1; c2 < args.length; c2 += 1) { b.push(args[c2]); } b.forEach(function(d) { a2 = a2.replace(/%[a-z]/, d); }); return a2; } var PolishedError = /* @__PURE__ */ function(_Error) { _inheritsLoose(PolishedError2, _Error); function PolishedError2(code) { var _this; if (false) { _this = _Error.call(this, "An error occurred. See https://github.com/styled-components/polished/blob/main/src/internalHelpers/errors.md#" + code + " for more information.") || this; } else { for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { args[_key2 - 1] = arguments[_key2]; } _this = _Error.call(this, format.apply(void 0, [ERRORS[code]].concat(args))) || this; } return _assertThisInitialized2(_this); } return PolishedError2; }(/* @__PURE__ */ _wrapNativeSuper(Error)); function colorToInt(color) { return Math.round(color * 255); } function convertToInt(red, green, blue) { return colorToInt(red) + "," + colorToInt(green) + "," + colorToInt(blue); } function hslToRgb2(hue, saturation, lightness, convert) { if (convert === void 0) { convert = convertToInt; } if (saturation === 0) { return convert(lightness, lightness, lightness); } var huePrime = (hue % 360 + 360) % 360 / 60; var chroma = (1 - Math.abs(2 * lightness - 1)) * saturation; var secondComponent = chroma * (1 - Math.abs(huePrime % 2 - 1)); var red = 0; var green = 0; var blue = 0; if (huePrime >= 0 && huePrime < 1) { red = chroma; green = secondComponent; } else if (huePrime >= 1 && huePrime < 2) { red = secondComponent; green = chroma; } else if (huePrime >= 2 && huePrime < 3) { green = chroma; blue = secondComponent; } else if (huePrime >= 3 && huePrime < 4) { green = secondComponent; blue = chroma; } else if (huePrime >= 4 && huePrime < 5) { red = secondComponent; blue = chroma; } else if (huePrime >= 5 && huePrime < 6) { red = chroma; blue = secondComponent; } var lightnessModification = lightness - chroma / 2; var finalRed = red + lightnessModification; var finalGreen = green + lightnessModification; var finalBlue = blue + lightnessModification; return convert(finalRed, finalGreen, finalBlue); } var namedColorMap = { aliceblue: "f0f8ff", antiquewhite: "faebd7", aqua: "00ffff", aquamarine: "7fffd4", azure: "f0ffff", beige: "f5f5dc", bisque: "ffe4c4", black: "000", blanchedalmond: "ffebcd", blue: "0000ff", blueviolet: "8a2be2", brown: "a52a2a", burlywood: "deb887", cadetblue: "5f9ea0", chartreuse: "7fff00", chocolate: "d2691e", coral: "ff7f50", cornflowerblue: "6495ed", cornsilk: "fff8dc", crimson: "dc143c", cyan: "00ffff", darkblue: "00008b", darkcyan: "008b8b", darkgoldenrod: "b8860b", darkgray: "a9a9a9", darkgreen: "006400", darkgrey: "a9a9a9", darkkhaki: "bdb76b", darkmagenta: "8b008b", darkolivegreen: "556b2f", darkorange: "ff8c00", darkorchid: "9932cc", darkred: "8b0000", darksalmon: "e9967a", darkseagreen: "8fbc8f", darkslateblue: "483d8b", darkslategray: "2f4f4f", darkslategrey: "2f4f4f", darkturquoise: "00ced1", darkviolet: "9400d3", deeppink: "ff1493", deepskyblue: "00bfff", dimgray: "696969", dimgrey: "696969", dodgerblue: "1e90ff", firebrick: "b22222", floralwhite: "fffaf0", forestgreen: "228b22", fuchsia: "ff00ff", gainsboro: "dcdcdc", ghostwhite: "f8f8ff", gold: "ffd700", goldenrod: "daa520", gray: "808080", green: "008000", greenyellow: "adff2f", grey: "808080", honeydew: "f0fff0", hotpink: "ff69b4", indianred: "cd5c5c", indigo: "4b0082", ivory: "fffff0", khaki: "f0e68c", lavender: "e6e6fa", lavenderblush: "fff0f5", lawngreen: "7cfc00", lemonchiffon: "fffacd", lightblue: "add8e6", lightcoral: "f08080", lightcyan: "e0ffff", lightgoldenrodyellow: "fafad2", lightgray: "d3d3d3", lightgreen: "90ee90", lightgrey: "d3d3d3", lightpink: "ffb6c1", lightsalmon: "ffa07a", lightseagreen: "20b2aa", lightskyblue: "87cefa", lightslategray: "789", lightslategrey: "789", lightsteelblue: "b0c4de", lightyellow: "ffffe0", lime: "0f0", limegreen: "32cd32", linen: "faf0e6", magenta: "f0f", maroon: "800000", mediumaquamarine: "66cdaa", mediumblue: "0000cd", mediumorchid: "ba55d3", mediumpurple: "9370db", mediumseagreen: "3cb371", mediumslateblue: "7b68ee", mediumspringgreen: "00fa9a", mediumturquoise: "48d1cc", mediumvioletred: "c71585", midnightblue: "191970", mintcream: "f5fffa", mistyrose: "ffe4e1", moccasin: "ffe4b5", navajowhite: "ffdead", navy: "000080", oldlace: "fdf5e6", olive: "808000", olivedrab: "6b8e23", orange: "ffa500", orangered: "ff4500", orchid: "da70d6", palegoldenrod: "eee8aa", palegreen: "98fb98", paleturquoise: "afeeee", palevioletred: "db7093", papayawhip: "ffefd5", peachpuff: "ffdab9", peru: "cd853f", pink: "ffc0cb", plum: "dda0dd", powderblue: "b0e0e6", purple: "800080", rebeccapurple: "639", red: "f00", rosybrown: "bc8f8f", royalblue: "4169e1", saddlebrown: "8b4513", salmon: "fa8072", sandybrown: "f4a460", seagreen: "2e8b57", seashell: "fff5ee", sienna: "a0522d", silver: "c0c0c0", skyblue: "87ceeb", slateblue: "6a5acd", slategray: "708090", slategrey: "708090", snow: "fffafa", springgreen: "00ff7f", steelblue: "4682b4", tan: "d2b48c", teal: "008080", thistle: "d8bfd8", tomato: "ff6347", turquoise: "40e0d0", violet: "ee82ee", wheat: "f5deb3", white: "fff", whitesmoke: "f5f5f5", yellow: "ff0", yellowgreen: "9acd32" }; function nameToHex(color) { if (typeof color !== "string") return color; var normalizedColorName = color.toLowerCase(); return namedColorMap[normalizedColorName] ? "#" + namedColorMap[normalizedColorName] : color; } var hexRegex = /^#[a-fA-F0-9]{6}$/; var hexRgbaRegex = /^#[a-fA-F0-9]{8}$/; var reducedHexRegex = /^#[a-fA-F0-9]{3}$/; var reducedRgbaHexRegex = /^#[a-fA-F0-9]{4}$/; var rgbRegex = /^rgb\(\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*\)$/i; var rgbaRegex = /^rgb(?:a)?\(\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,)?\s*(\d{1,3})\s*(?:,|\/)\s*([-+]?\d*[.]?\d+[%]?)\s*\)$/i; var hslRegex = /^hsl\(\s*(\d{0,3}[.]?[0-9]+(?:deg)?)\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*\)$/i; var hslaRegex = /^hsl(?:a)?\(\s*(\d{0,3}[.]?[0-9]+(?:deg)?)\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*(?:,)?\s*(\d{1,3}[.]?[0-9]?)%\s*(?:,|\/)\s*([-+]?\d*[.]?\d+[%]?)\s*\)$/i; function parseToRgb(color) { if (typeof color !== "string") { throw new PolishedError(3); } var normalizedColor = nameToHex(color); if (normalizedColor.match(hexRegex)) { return { red: parseInt("" + normalizedColor[1] + normalizedColor[2], 16), green: parseInt("" + normalizedColor[3] + normalizedColor[4], 16), blue: parseInt("" + normalizedColor[5] + normalizedColor[6], 16) }; } if (normalizedColor.match(hexRgbaRegex)) { var alpha = parseFloat((parseInt("" + normalizedColor[7] + normalizedColor[8], 16) / 255).toFixed(2)); return { red: parseInt("" + normalizedColor[1] + normalizedColor[2], 16), green: parseInt("" + normalizedColor[3] + normalizedColor[4], 16), blue: parseInt("" + normalizedColor[5] + normalizedColor[6], 16), alpha }; } if (normalizedColor.match(reducedHexRegex)) { return { red: parseInt("" + normalizedColor[1] + normalizedColor[1], 16), green: parseInt("" + normalizedColor[2] + normalizedColor[2], 16), blue: parseInt("" + normalizedColor[3] + normalizedColor[3], 16) }; } if (normalizedColor.match(reducedRgbaHexRegex)) { var _alpha = parseFloat((parseInt("" + normalizedColor[4] + normalizedColor[4], 16) / 255).toFixed(2)); return { red: parseInt("" + normalizedColor[1] + normalizedColor[1], 16), green: parseInt("" + normalizedColor[2] + normalizedColor[2], 16), blue: parseInt("" + normalizedColor[3] + normalizedColor[3], 16), alpha: _alpha }; } var rgbMatched = rgbRegex.exec(normalizedColor); if (rgbMatched) { return { red: parseInt("" + rgbMatched[1], 10), green: parseInt("" + rgbMatched[2], 10), blue: parseInt("" + rgbMatched[3], 10) }; } var rgbaMatched = rgbaRegex.exec(normalizedColor.substring(0, 50)); if (rgbaMatched) { return { red: parseInt("" + rgbaMatched[1], 10), green: parseInt("" + rgbaMatched[2], 10), blue: parseInt("" + rgbaMatched[3], 10), alpha: parseFloat("" + rgbaMatched[4]) > 1 ? parseFloat("" + rgbaMatched[4]) / 100 : parseFloat("" + rgbaMatched[4]) }; } var hslMatched = hslRegex.exec(normalizedColor); if (hslMatched) { var hue = parseInt("" + hslMatched[1], 10); var saturation = parseInt("" + hslMatched[2], 10) / 100; var lightness = parseInt("" + hslMatched[3], 10) / 100; var rgbColorString = "rgb(" + hslToRgb2(hue, saturation, lightness) + ")"; var hslRgbMatched = rgbRegex.exec(rgbColorString); if (!hslRgbMatched) { throw new PolishedError(4, normalizedColor, rgbColorString); } return { red: parseInt("" + hslRgbMatched[1], 10), green: parseInt("" + hslRgbMatched[2], 10), blue: parseInt("" + hslRgbMatched[3], 10) }; } var hslaMatched = hslaRegex.exec(normalizedColor.substring(0, 50)); if (hslaMatched) { var _hue = parseInt("" + hslaMatched[1], 10); var _saturation = parseInt("" + hslaMatched[2], 10) / 100; var _lightness = parseInt("" + hslaMatched[3], 10) / 100; var _rgbColorString = "rgb(" + hslToRgb2(_hue, _saturation, _lightness) + ")"; var _hslRgbMatched = rgbRegex.exec(_rgbColorString); if (!_hslRgbMatched) { throw new PolishedError(4, normalizedColor, _rgbColorString); } return { red: parseInt("" + _hslRgbMatched[1], 10), green: parseInt("" + _hslRgbMatched[2], 10), blue: parseInt("" + _hslRgbMatched[3], 10), alpha: parseFloat("" + hslaMatched[4]) > 1 ? parseFloat("" + hslaMatched[4]) / 100 : parseFloat("" + hslaMatched[4]) }; } throw new PolishedError(5); } var reduceHexValue = function reduceHexValue2(value) { if (value.length === 7 && value[1] === value[2] && value[3] === value[4] && value[5] === value[6]) { return "#" + value[1] + value[3] + value[5]; } return value; }; var reduceHexValue$1 = reduceHexValue; function numberToHex(value) { var hex = value.toString(16); return hex.length === 1 ? "0" + hex : hex; } function rgb(value, green, blue) { if (typeof value === "number" && typeof green === "number" && typeof blue === "number") { return reduceHexValue$1("#" + numberToHex(value) + numberToHex(green) + numberToHex(blue)); } else if (typeof value === "object" && green === void 0 && blue === void 0) { return reduceHexValue$1("#" + numberToHex(value.red) + numberToHex(value.green) + numberToHex(value.blue)); } throw new PolishedError(6); } function rgba(firstValue, secondValue, thirdValue, fourthValue) { if (typeof firstValue === "string" && typeof secondValue === "number") { var rgbValue = parseToRgb(firstValue); return "rgba(" + rgbValue.red + "," + rgbValue.green + "," + rgbValue.blue + "," + secondValue + ")"; } else if (typeof firstValue === "number" && typeof secondValue === "number" && typeof thirdValue === "number" && typeof fourthValue === "number") { return fourthValue >= 1 ? rgb(firstValue, secondValue, thirdValue) : "rgba(" + firstValue + "," + secondValue + "," + thirdValue + "," + fourthValue + ")"; } else if (typeof firstValue === "object" && secondValue === void 0 && thirdValue === void 0 && fourthValue === void 0) { return firstValue.alpha >= 1 ? rgb(firstValue.red, firstValue.green, firstValue.blue) : "rgba(" + firstValue.red + "," + firstValue.green + "," + firstValue.blue + "," + firstValue.alpha + ")"; } throw new PolishedError(7); } function curried(f, length, acc) { return function fn() { var combined = acc.concat(Array.prototype.slice.call(arguments)); return combined.length >= length ? f.apply(this, combined) : curried(f, length, combined); }; } function curry(f) { return curried(f, f.length, []); } function guard(lowerBoundary, upperBoundary, value) { return Math.max(lowerBoundary, Math.min(upperBoundary, value)); } function opacify(amount, color) { if (color === "transparent") return color; var parsedColor = parseToRgb(color); var alpha = typeof parsedColor.alpha === "number" ? parsedColor.alpha : 1; var colorWithAlpha = _extends({}, parsedColor, { alpha: guard(0, 1, (alpha * 100 + parseFloat(amount) * 100) / 100) }); return rgba(colorWithAlpha); } var curriedOpacify = /* @__PURE__ */ curry(opacify); var curriedOpacify$1 = curriedOpacify; // node_modules/@tweenjs/tween.js/dist/tween.esm.js var Easing = Object.freeze({ Linear: Object.freeze({ None: function(amount) { return amount; }, In: function(amount) { return this.None(amount); }, Out: function(amount) { return this.None(amount); }, InOut: function(amount) { return this.None(amount); } }), Quadratic: Object.freeze({ In: function(amount) { return amount * amount; }, Out: function(amount) { return amount * (2 - amount); }, InOut: function(amount) { if ((amount *= 2) < 1) { return 0.5 * amount * amount; } return -0.5 * (--amount * (amount - 2) - 1); } }), Cubic: Object.freeze({ In: function(amount) { return amount * amount * amount; }, Out: function(amount) { return --amount * amount * amount + 1; }, InOut: function(amount) { if ((amount *= 2) < 1) { return 0.5 * amount * amount * amount; } return 0.5 * ((amount -= 2) * amount * amount + 2); } }), Quartic: Object.freeze({ In: function(amount) { return amount * amount * amount * amount; }, Out: function(amount) { return 1 - --amount * amount * amount * amount; }, InOut: function(amount) { if ((amount *= 2) < 1) { return 0.5 * amount * amount * amount * amount; } return -0.5 * ((amount -= 2) * amount * amount * amount - 2); } }), Quintic: Object.freeze({ In: function(amount) { return amount * amount * amount * amount * amount; }, Out: function(amount) { return --amount * amount * amount * amount * amount + 1; }, InOut: function(amount) { if ((amount *= 2) < 1) { return 0.5 * amount * amount * amount * amount * amount; } return 0.5 * ((amount -= 2) * amount * amount * amount * amount + 2); } }), Sinusoidal: Object.freeze({ In: function(amount) { return 1 - Math.sin((1 - amount) * Math.PI / 2); }, Out: function(amount) { return Math.sin(amount * Math.PI / 2); }, InOut: function(amount) { return 0.5 * (1 - Math.sin(Math.PI * (0.5 - amount))); } }), Exponential: Object.freeze({ In: function(amount) { return amount === 0 ? 0 : Math.pow(1024, amount - 1); }, Out: function(amount) { return amount === 1 ? 1 : 1 - Math.pow(2, -10 * amount); }, InOut: function(amount) { if (amount === 0) { return 0; } if (amount === 1) { return 1; } if ((amount *= 2) < 1) { return 0.5 * Math.pow(1024, amount - 1); } return 0.5 * (-Math.pow(2, -10 * (amount - 1)) + 2); } }), Circular: Object.freeze({ In: function(amount) { return 1 - Math.sqrt(1 - amount * amount); }, Out: function(amount) { return Math.sqrt(1 - --amount * amount); }, InOut: function(amount) { if ((amount *= 2) < 1) { return -0.5 * (Math.sqrt(1 - amount * amount) - 1); } return 0.5 * (Math.sqrt(1 - (amount -= 2) * amount) + 1); } }), Elastic: Object.freeze({ In: function(amount) { if (amount === 0) { return 0; } if (amount === 1) { return 1; } return -Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI); }, Out: function(amount) { if (amount === 0) { return 0; } if (amount === 1) { return 1; } return Math.pow(2, -10 * amount) * Math.sin((amount - 0.1) * 5 * Math.PI) + 1; }, InOut: function(amount) { if (amount === 0) { return 0; } if (amount === 1) { return 1; } amount *= 2; if (amount < 1) { return -0.5 * Math.pow(2, 10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI); } return 0.5 * Math.pow(2, -10 * (amount - 1)) * Math.sin((amount - 1.1) * 5 * Math.PI) + 1; } }), Back: Object.freeze({ In: function(amount) { var s = 1.70158; return amount === 1 ? 1 : amount * amount * ((s + 1) * amount - s); }, Out: function(amount) { var s = 1.70158; return amount === 0 ? 0 : --amount * amount * ((s + 1) * amount + s) + 1; }, InOut: function(amount) { var s = 1.70158 * 1.525; if ((amount *= 2) < 1) { return 0.5 * (amount * amount * ((s + 1) * amount - s)); } return 0.5 * ((amount -= 2) * amount * ((s + 1) * amount + s) + 2); } }), Bounce: Object.freeze({ In: function(amount) { return 1 - Easing.Bounce.Out(1 - amount); }, Out: function(amount) { if (amount < 1 / 2.75) { return 7.5625 * amount * amount; } else if (amount < 2 / 2.75) { return 7.5625 * (amount -= 1.5 / 2.75) * amount + 0.75; } else if (amount < 2.5 / 2.75) { return 7.5625 * (amount -= 2.25 / 2.75) * amount + 0.9375; } else { return 7.5625 * (amount -= 2.625 / 2.75) * amount + 0.984375; } }, InOut: function(amount) { if (amount < 0.5) { return Easing.Bounce.In(amount * 2) * 0.5; } return Easing.Bounce.Out(amount * 2 - 1) * 0.5 + 0.5; } }), generatePow: function(power) { if (power === void 0) { power = 4; } power = power < Number.EPSILON ? Number.EPSILON : power; power = power > 1e4 ? 1e4 : power; return { In: function(amount) { return Math.pow(amount, power); }, Out: function(amount) { return 1 - Math.pow(1 - amount, power); }, InOut: function(amount) { if (amount < 0.5) { return Math.pow(amount * 2, power) / 2; } return (1 - Math.pow(2 - amount * 2, power)) / 2 + 0.5; } }; } }); var now4 = function() { return performance.now(); }; var Group3 = ( /** @class */ function() { function Group4() { this._tweens = {}; this._tweensAddedDuringUpdate = {}; } Group4.prototype.getAll = function() { var _this = this; return Object.keys(this._tweens).map(function(tweenId) { return _this._tweens[tweenId]; }); }; Group4.prototype.removeAll = function() { this._tweens = {}; }; Group4.prototype.add = function(tween) { this._tweens[tween.getId()] = tween; this._tweensAddedDuringUpdate[tween.getId()] = tween; }; Group4.prototype.remove = function(tween) { delete this._tweens[tween.getId()]; delete this._tweensAddedDuringUpdate[tween.getId()]; }; Group4.prototype.update = function(time, preserve) { if (time === void 0) { time = now4(); } if (preserve === void 0) { preserve = false; } var tweenIds = Object.keys(this._tweens); if (tweenIds.length === 0) { return false; } while (tweenIds.length > 0) { this._tweensAddedDuringUpdate = {}; for (var i = 0; i < tweenIds.length; i++) { var tween = this._tweens[tweenIds[i]]; var autoStart = !preserve; if (tween && tween.update(time, autoStart) === false && !preserve) { delete this._tweens[tweenIds[i]]; } } tweenIds = Object.keys(this._tweensAddedDuringUpdate); } return true; }; return Group4; }() ); var Interpolation = { Linear: function(v, k) { var m2 = v.length - 1; var f = m2 * k; var i = Math.floor(f); var fn = Interpolation.Utils.Linear; if (k < 0) { return fn(v[0], v[1], f); } if (k > 1) { return fn(v[m2], v[m2 - 1], m2 - f); } return fn(v[i], v[i + 1 > m2 ? m2 : i + 1], f - i); }, Bezier: function(v, k) { var b = 0; var n = v.length - 1; var pw = Math.pow; var bn = Interpolation.Utils.Bernstein; for (var i = 0; i <= n; i++) { b += pw(1 - k, n - i) * pw(k, i) * v[i] * bn(n, i); } return b; }, CatmullRom: function(v, k) { var m2 = v.length - 1; var f = m2 * k; var i = Math.floor(f); var fn = Interpolation.Utils.CatmullRom; if (v[0] === v[m2]) { if (k < 0) { i = Math.floor(f = m2 * (1 + k)); } return fn(v[(i - 1 + m2) % m2], v[i], v[(i + 1) % m2], v[(i + 2) % m2], f - i); } else { if (k < 0) { return v[0] - (fn(v[0], v[0], v[1], v[1], -f) - v[0]); } if (k > 1) { return v[m2] - (fn(v[m2], v[m2], v[m2 - 1], v[m2 - 1], f - m2) - v[m2]); } return fn(v[i ? i - 1 : 0], v[i], v[m2 < i + 1 ? m2 : i + 1], v[m2 < i + 2 ? m2 : i + 2], f - i); } }, Utils: { Linear: function(p0, p1, t) { return (p1 - p0) * t + p0; }, Bernstein: function(n, i) { var fc = Interpolation.Utils.Factorial; return fc(n) / fc(i) / fc(n - i); }, Factorial: function() { var a2 = [1]; return function(n) { var s = 1; if (a2[n]) { return a2[n]; } for (var i = n; i > 1; i--) { s *= i; } a2[n] = s; return s; }; }(), CatmullRom: function(p0, p1, p2, p3, t) { var v0 = (p2 - p0) * 0.5; var v1 = (p3 - p1) * 0.5; var t2 = t * t; var t3 = t * t2; return (2 * p1 - 2 * p2 + v0 + v1) * t3 + (-3 * p1 + 3 * p2 - 2 * v0 - v1) * t2 + v0 * t + p1; } } }; var Sequence = ( /** @class */ function() { function Sequence2() { } Sequence2.nextId = function() { return Sequence2._nextId++; }; Sequence2._nextId = 0; return Sequence2; }() ); var mainGroup = new Group3(); var Tween = ( /** @class */ function() { function Tween2(_object, _group) { if (_group === void 0) { _group = mainGroup; } this._object = _object; this._group = _group; this._isPaused = false; this._pauseStart = 0; this._valuesStart = {}; this._valuesEnd = {}; this._valuesStartRepeat = {}; this._duration = 1e3; this._isDynamic = false; this._initialRepeat = 0; this._repeat = 0; this._yoyo = false; this._isPlaying = false; this._reversed = false; this._delayTime = 0; this._startTime = 0; this._easingFunction = Easing.Linear.None; this._interpolationFunction = Interpolation.Linear; this._chainedTweens = []; this._onStartCallbackFired = false; this._onEveryStartCallbackFired = false; this._id = Sequence.nextId(); this._isChainStopped = false; this._propertiesAreSetUp = false; this._goToEnd = false; } Tween2.prototype.getId = function() { return this._id; }; Tween2.prototype.isPlaying = function() { return this._isPlaying; }; Tween2.prototype.isPaused = function() { return this._isPaused; }; Tween2.prototype.to = function(target, duration) { if (duration === void 0) { duration = 1e3; } if (this._isPlaying) throw new Error("Can not call Tween.to() while Tween is already started or paused. Stop the Tween first."); this._valuesEnd = target; this._propertiesAreSetUp = false; this._duration = duration; return this; }; Tween2.prototype.duration = function(duration) { if (duration === void 0) { duration = 1e3; } this._duration = duration; return this; }; Tween2.prototype.dynamic = function(dynamic) { if (dynamic === void 0) { dynamic = false; } this._isDynamic = dynamic; return this; }; Tween2.prototype.start = function(time, overrideStartingValues) { if (time === void 0) { time = now4(); } if (overrideStartingValues === void 0) { overrideStartingValues = false; } if (this._isPlaying) { return this; } this._group && this._group.add(this); this._repeat = this._initialRepeat; if (this._reversed) { this._reversed = false; for (var property in this._valuesStartRepeat) { this._swapEndStartRepeatValues(property); this._valuesStart[property] = this._valuesStartRepeat[property]; } } this._isPlaying = true; this._isPaused = false; this._onStartCallbackFired = false; this._onEveryStartCallbackFired = false; this._isChainStopped = false; this._startTime = time; this._startTime += this._delayTime; if (!this._propertiesAreSetUp || overrideStartingValues) { this._propertiesAreSetUp = true; if (!this._isDynamic) { var tmp2 = {}; for (var prop in this._valuesEnd) tmp2[prop] = this._valuesEnd[prop]; this._valuesEnd = tmp2; } this._setupProperties(this._object, this._valuesStart, this._valuesEnd, this._valuesStartRepeat, overrideStartingValues); } return this; }; Tween2.prototype.startFromCurrentValues = function(time) { return this.start(time, true); }; Tween2.prototype._setupProperties = function(_object, _valuesStart, _valuesEnd, _valuesStartRepeat, overrideStartingValues) { for (var property in _valuesEnd) { var startValue = _object[property]; var startValueIsArray = Array.isArray(startValue); var propType = startValueIsArray ? "array" : typeof startValue; var isInterpolationList = !startValueIsArray && Array.isArray(_valuesEnd[property]); if (propType === "undefined" || propType === "function") { continue; } if (isInterpolationList) { var endValues = _valuesEnd[property]; if (endValues.length === 0) { continue; } var temp = [startValue]; for (var i = 0, l = endValues.length; i < l; i += 1) { var value = this._handleRelativeValue(startValue, endValues[i]); if (isNaN(value)) { isInterpolationList = false; console.warn("Found invalid interpolation list. Skipping."); break; } temp.push(value); } if (isInterpolationList) { _valuesEnd[property] = temp; } } if ((propType === "object" || startValueIsArray) && startValue && !isInterpolationList) { _valuesStart[property] = startValueIsArray ? [] : {}; var nestedObject = startValue; for (var prop in nestedObject) { _valuesStart[property][prop] = nestedObject[prop]; } _valuesStartRepeat[property] = startValueIsArray ? [] : {}; var endValues = _valuesEnd[property]; if (!this._isDynamic) { var tmp2 = {}; for (var prop in endValues) tmp2[prop] = endValues[prop]; _valuesEnd[property] = endValues = tmp2; } this._setupProperties(nestedObject, _valuesStart[property], endValues, _valuesStartRepeat[property], overrideStartingValues); } else { if (typeof _valuesStart[property] === "undefined" || overrideStartingValues) { _valuesStart[property] = startValue; } if (!startValueIsArray) { _valuesStart[property] *= 1; } if (isInterpolationList) { _valuesStartRepeat[property] = _valuesEnd[property].slice().reverse(); } else { _valuesStartRepeat[property] = _valuesStart[property] || 0; } } } }; Tween2.prototype.stop = function() { if (!this._isChainStopped) { this._isChainStopped = true; this.stopChainedTweens(); } if (!this._isPlaying) { return this; } this._group && this._group.remove(this); this._isPlaying = false; this._isPaused = false; if (this._onStopCallback) { this._onStopCallback(this._object); } return this; }; Tween2.prototype.end = function() { this._goToEnd = true; this.update(Infinity); return this; }; Tween2.prototype.pause = function(time) { if (time === void 0) { time = now4(); } if (this._isPaused || !this._isPlaying) { return this; } this._isPaused = true; this._pauseStart = time; this._group && this._group.remove(this); return this; }; Tween2.prototype.resume = function(time) { if (time === void 0) { time = now4(); } if (!this._isPaused || !this._isPlaying) { return this; } this._isPaused = false; this._startTime += time - this._pauseStart; this._pauseStart = 0; this._group && this._group.add(this); return this; }; Tween2.prototype.stopChainedTweens = function() { for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) { this._chainedTweens[i].stop(); } return this; }; Tween2.prototype.group = function(group) { if (group === void 0) { group = mainGroup; } this._group = group; return this; }; Tween2.prototype.delay = function(amount) { if (amount === void 0) { amount = 0; } this._delayTime = amount; return this; }; Tween2.prototype.repeat = function(times) { if (times === void 0) { times = 0; } this._initialRepeat = times; this._repeat = times; return this; }; Tween2.prototype.repeatDelay = function(amount) { this._repeatDelayTime = amount; return this; }; Tween2.prototype.yoyo = function(yoyo) { if (yoyo === void 0) { yoyo = false; } this._yoyo = yoyo; return this; }; Tween2.prototype.easing = function(easingFunction) { if (easingFunction === void 0) { easingFunction = Easing.Linear.None; } this._easingFunction = easingFunction; return this; }; Tween2.prototype.interpolation = function(interpolationFunction) { if (interpolationFunction === void 0) { interpolationFunction = Interpolation.Linear; } this._interpolationFunction = interpolationFunction; return this; }; Tween2.prototype.chain = function() { var tweens = []; for (var _i = 0; _i < arguments.length; _i++) { tweens[_i] = arguments[_i]; } this._chainedTweens = tweens; return this; }; Tween2.prototype.onStart = function(callback) { this._onStartCallback = callback; return this; }; Tween2.prototype.onEveryStart = function(callback) { this._onEveryStartCallback = callback; return this; }; Tween2.prototype.onUpdate = function(callback) { this._onUpdateCallback = callback; return this; }; Tween2.prototype.onRepeat = function(callback) { this._onRepeatCallback = callback; return this; }; Tween2.prototype.onComplete = function(callback) { this._onCompleteCallback = callback; return this; }; Tween2.prototype.onStop = function(callback) { this._onStopCallback = callback; return this; }; Tween2.prototype.update = function(time, autoStart) { if (time === void 0) { time = now4(); } if (autoStart === void 0) { autoStart = true; } if (this._isPaused) return true; var property; var elapsed; var endTime = this._startTime + this._duration; if (!this._goToEnd && !this._isPlaying) { if (time > endTime) return false; if (autoStart) this.start(time, true); } this._goToEnd = false; if (time < this._startTime) { return true; } if (this._onStartCallbackFired === false) { if (this._onStartCallback) { this._onStartCallback(this._object); } this._onStartCallbackFired = true; } if (this._onEveryStartCallbackFired === false) { if (this._onEveryStartCallback) { this._onEveryStartCallback(this._object); } this._onEveryStartCallbackFired = true; } elapsed = (time - this._startTime) / this._duration; elapsed = this._duration === 0 || elapsed > 1 ? 1 : elapsed; var value = this._easingFunction(elapsed); this._updateProperties(this._object, this._valuesStart, this._valuesEnd, value); if (this._onUpdateCallback) { this._onUpdateCallback(this._object, elapsed); } if (elapsed === 1) { if (this._repeat > 0) { if (isFinite(this._repeat)) { this._repeat--; } for (property in this._valuesStartRepeat) { if (!this._yoyo && typeof this._valuesEnd[property] === "string") { this._valuesStartRepeat[property] = // eslint-disable-next-line // @ts-ignore FIXME? this._valuesStartRepeat[property] + parseFloat(this._valuesEnd[property]); } if (this._yoyo) { this._swapEndStartRepeatValues(property); } this._valuesStart[property] = this._valuesStartRepeat[property]; } if (this._yoyo) { this._reversed = !this._reversed; } if (this._repeatDelayTime !== void 0) { this._startTime = time + this._repeatDelayTime; } else { this._startTime = time + this._delayTime; } if (this._onRepeatCallback) { this._onRepeatCallback(this._object); } this._onEveryStartCallbackFired = false; return true; } else { if (this._onCompleteCallback) { this._onCompleteCallback(this._object); } for (var i = 0, numChainedTweens = this._chainedTweens.length; i < numChainedTweens; i++) { this._chainedTweens[i].start(this._startTime + this._duration, false); } this._isPlaying = false; return false; } } return true; }; Tween2.prototype._updateProperties = function(_object, _valuesStart, _valuesEnd, value) { for (var property in _valuesEnd) { if (_valuesStart[property] === void 0) { continue; } var start = _valuesStart[property] || 0; var end = _valuesEnd[property]; var startIsArray = Array.isArray(_object[property]); var endIsArray = Array.isArray(end); var isInterpolationList = !startIsArray && endIsArray; if (isInterpolationList) { _object[property] = this._interpolationFunction(end, value); } else if (typeof end === "object" && end) { this._updateProperties(_object[property], start, end, value); } else { end = this._handleRelativeValue(start, end); if (typeof end === "number") { _object[property] = start + (end - start) * value; } } } }; Tween2.prototype._handleRelativeValue = function(start, end) { if (typeof end !== "string") { return end; } if (end.charAt(0) === "+" || end.charAt(0) === "-") { return start + parseFloat(end); } return parseFloat(end); }; Tween2.prototype._swapEndStartRepeatValues = function(property) { var tmp2 = this._valuesStartRepeat[property]; var endValue = this._valuesEnd[property]; if (typeof endValue === "string") { this._valuesStartRepeat[property] = this._valuesStartRepeat[property] + parseFloat(endValue); } else { this._valuesStartRepeat[property] = this._valuesEnd[property]; } this._valuesEnd[property] = tmp2; }; return Tween2; }() ); var nextId = Sequence.nextId; var TWEEN = mainGroup; var getAll = TWEEN.getAll.bind(TWEEN); var removeAll4 = TWEEN.removeAll.bind(TWEEN); var add4 = TWEEN.add.bind(TWEEN); var remove = TWEEN.remove.bind(TWEEN); var update2 = TWEEN.update.bind(TWEEN); // node_modules/kapsule/dist/kapsule.mjs function _iterableToArrayLimit5(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a2 = [], f = true, o = false; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = false; } else for (; !(f = (e = i.call(t)).done) && (a2.push(e.value), a2.length !== l); f = true) ; } catch (r2) { o = true, n = r2; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a2; } } function _classCallCheck3(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties3(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, _toPropertyKey5(descriptor.key), descriptor); } } function _createClass3(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties3(Constructor.prototype, protoProps); if (staticProps) _defineProperties3(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _slicedToArray5(arr, i) { return _arrayWithHoles5(arr) || _iterableToArrayLimit5(arr, i) || _unsupportedIterableToArray5(arr, i) || _nonIterableRest5(); } function _arrayWithHoles5(arr) { if (Array.isArray(arr)) return arr; } function _unsupportedIterableToArray5(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray5(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray5(o, minLen); } function _arrayLikeToArray5(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _nonIterableRest5() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _toPrimitive5(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== void 0) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _toPropertyKey5(arg) { var key = _toPrimitive5(arg, "string"); return typeof key === "symbol" ? key : String(key); } var Prop3 = /* @__PURE__ */ _createClass3(function Prop4(name, _ref) { var _ref$default = _ref["default"], defaultVal = _ref$default === void 0 ? null : _ref$default, _ref$triggerUpdate = _ref.triggerUpdate, triggerUpdate = _ref$triggerUpdate === void 0 ? true : _ref$triggerUpdate, _ref$onChange = _ref.onChange, onChange13 = _ref$onChange === void 0 ? function(newVal, state) { } : _ref$onChange; _classCallCheck3(this, Prop4); this.name = name; this.defaultVal = defaultVal; this.triggerUpdate = triggerUpdate; this.onChange = onChange13; }); function index5(_ref2) { var _ref2$stateInit = _ref2.stateInit, stateInit4 = _ref2$stateInit === void 0 ? function() { return {}; } : _ref2$stateInit, _ref2$props = _ref2.props, rawProps = _ref2$props === void 0 ? {} : _ref2$props, _ref2$methods = _ref2.methods, methods = _ref2$methods === void 0 ? {} : _ref2$methods, _ref2$aliases = _ref2.aliases, aliases = _ref2$aliases === void 0 ? {} : _ref2$aliases, _ref2$init = _ref2.init, initFn = _ref2$init === void 0 ? function() { } : _ref2$init, _ref2$update = _ref2.update, updateFn = _ref2$update === void 0 ? function() { } : _ref2$update; var props = Object.keys(rawProps).map(function(propName) { return new Prop3(propName, rawProps[propName]); }); return function() { var options = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}; var state = Object.assign( {}, stateInit4 instanceof Function ? stateInit4(options) : stateInit4, // Support plain objects for backwards compatibility { initialised: false } ); var changedProps = {}; function comp(nodeElement) { initStatic(nodeElement, options); digest(); return comp; } var initStatic = function initStatic2(nodeElement, options2) { initFn.call(comp, nodeElement, state, options2); state.initialised = true; }; var digest = debounce_default(function() { if (!state.initialised) { return; } updateFn.call(comp, state, changedProps); changedProps = {}; }, 1); props.forEach(function(prop) { comp[prop.name] = getSetProp(prop); function getSetProp(_ref3) { var prop2 = _ref3.name, _ref3$triggerUpdate = _ref3.triggerUpdate, redigest = _ref3$triggerUpdate === void 0 ? false : _ref3$triggerUpdate, _ref3$onChange = _ref3.onChange, onChange13 = _ref3$onChange === void 0 ? function(newVal, state2) { } : _ref3$onChange, _ref3$defaultVal = _ref3.defaultVal, defaultVal = _ref3$defaultVal === void 0 ? null : _ref3$defaultVal; return function(_) { var curVal = state[prop2]; if (!arguments.length) { return curVal; } var val = _ === void 0 ? defaultVal : _; state[prop2] = val; onChange13.call(comp, val, state, curVal); !changedProps.hasOwnProperty(prop2) && (changedProps[prop2] = curVal); if (redigest) { digest(); } return comp; }; } }); Object.keys(methods).forEach(function(methodName) { comp[methodName] = function() { var _methods$methodName; for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return (_methods$methodName = methods[methodName]).call.apply(_methods$methodName, [comp, state].concat(args)); }; }); Object.entries(aliases).forEach(function(_ref4) { var _ref5 = _slicedToArray5(_ref4, 2), alias = _ref5[0], target = _ref5[1]; return comp[alias] = comp[target]; }); comp.resetProps = function() { props.forEach(function(prop) { comp[prop.name](prop.defaultVal); }); return comp; }; comp.resetProps(); state._rerender = digest; return comp; }; } // node_modules/three-render-objects/dist/three-render-objects.mjs function styleInject(css, ref) { if (ref === void 0) ref = {}; var insertAt = ref.insertAt; if (!css || typeof document === "undefined") { return; } var head = document.head || document.getElementsByTagName("head")[0]; var style = document.createElement("style"); style.type = "text/css"; if (insertAt === "top") { if (head.firstChild) { head.insertBefore(style, head.firstChild); } else { head.appendChild(style); } } else { head.appendChild(style); } if (style.styleSheet) { style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); } } var css_248z = ".scene-nav-info {\n bottom: 5px;\n width: 100%;\n text-align: center;\n color: slategrey;\n opacity: 0.7;\n font-size: 10px;\n}\n\n.scene-tooltip {\n top: 0;\n color: lavender;\n font-size: 15px;\n}\n\n.scene-nav-info, .scene-tooltip {\n position: absolute;\n font-family: sans-serif;\n pointer-events: none;\n user-select: none;\n}\n\n.scene-container canvas:focus {\n outline: none;\n}"; styleInject(css_248z); function _iterableToArrayLimit6(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a2 = [], f = true, o = false; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = false; } else for (; !(f = (e = i.call(t)).done) && (a2.push(e.value), a2.length !== l); f = true) ; } catch (r2) { o = true, n = r2; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a2; } } function _defineProperty3(obj, key, value) { key = _toPropertyKey6(key); if (key in obj) { Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _slicedToArray6(arr, i) { return _arrayWithHoles6(arr) || _iterableToArrayLimit6(arr, i) || _unsupportedIterableToArray6(arr, i) || _nonIterableRest6(); } function _toConsumableArray4(arr) { return _arrayWithoutHoles4(arr) || _iterableToArray4(arr) || _unsupportedIterableToArray6(arr) || _nonIterableSpread4(); } function _arrayWithoutHoles4(arr) { if (Array.isArray(arr)) return _arrayLikeToArray6(arr); } function _arrayWithHoles6(arr) { if (Array.isArray(arr)) return arr; } function _iterableToArray4(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _unsupportedIterableToArray6(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray6(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray6(o, minLen); } function _arrayLikeToArray6(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _nonIterableSpread4() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _nonIterableRest6() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _toPrimitive6(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== void 0) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _toPropertyKey6(arg) { var key = _toPrimitive6(arg, "string"); return typeof key === "symbol" ? key : String(key); } var three2 = window.THREE ? window.THREE : { WebGLRenderer: WebGLRenderer2, Scene, PerspectiveCamera: PerspectiveCamera2, Raycaster: Raycaster2, SRGBColorSpace: SRGBColorSpace2, TextureLoader, Vector2: Vector22, Vector3: Vector32, Box3: Box32, Color: Color2, Mesh: Mesh2, SphereGeometry, MeshBasicMaterial: MeshBasicMaterial2, BackSide: BackSide2, EventDispatcher: EventDispatcher2, MOUSE, Quaternion: Quaternion2, Spherical, Clock }; var threeRenderObjects = index5({ props: { width: { "default": window.innerWidth, onChange: function onChange8(width, state, prevWidth) { isNaN(width) && (state.width = prevWidth); } }, height: { "default": window.innerHeight, onChange: function onChange9(height, state, prevHeight) { isNaN(height) && (state.height = prevHeight); } }, backgroundColor: { "default": "#000011" }, backgroundImageUrl: {}, onBackgroundImageLoaded: {}, showNavInfo: { "default": true }, skyRadius: { "default": 5e4 }, objects: { "default": [] }, lights: { "default": [] }, enablePointerInteraction: { "default": true, onChange: function onChange10(_, state) { state.hoverObj = null; if (state.toolTipElem) state.toolTipElem.innerHTML = ""; }, triggerUpdate: false }, lineHoverPrecision: { "default": 1, triggerUpdate: false }, hoverOrderComparator: { "default": function _default8() { return -1; }, triggerUpdate: false }, // keep existing order by default hoverFilter: { "default": function _default9() { return true; }, triggerUpdate: false }, // exclude objects from interaction tooltipContent: { triggerUpdate: false }, hoverDuringDrag: { "default": false, triggerUpdate: false }, clickAfterDrag: { "default": false, triggerUpdate: false }, onHover: { "default": function _default10() { }, triggerUpdate: false }, onClick: { "default": function _default11() { }, triggerUpdate: false }, onRightClick: { triggerUpdate: false } }, methods: { tick: function tick(state) { if (state.initialised) { state.controls.update && state.controls.update(state.clock.getDelta()); state.postProcessingComposer ? state.postProcessingComposer.render() : state.renderer.render(state.scene, state.camera); state.extraRenderers.forEach(function(r) { return r.render(state.scene, state.camera); }); if (state.enablePointerInteraction) { var topObject = null; if (state.hoverDuringDrag || !state.isPointerDragging) { var intersects = this.intersectingObjects(state.pointerPos.x, state.pointerPos.y).filter(function(d) { return state.hoverFilter(d.object); }).sort(function(a2, b) { return state.hoverOrderComparator(a2.object, b.object); }); var topIntersect = intersects.length ? intersects[0] : null; topObject = topIntersect ? topIntersect.object : null; state.intersectionPoint = topIntersect ? topIntersect.point : null; } if (topObject !== state.hoverObj) { state.onHover(topObject, state.hoverObj); state.toolTipElem.innerHTML = topObject ? index3(state.tooltipContent)(topObject) || "" : ""; state.hoverObj = topObject; } } update2(); } return this; }, getPointerPos: function getPointerPos(state) { var _state$pointerPos = state.pointerPos, x3 = _state$pointerPos.x, y3 = _state$pointerPos.y; return { x: x3, y: y3 }; }, cameraPosition: function cameraPosition(state, position, lookAt, transitionDuration) { var camera3 = state.camera; if (position && state.initialised) { var finalPos = position; var finalLookAt = lookAt || { x: 0, y: 0, z: 0 }; if (!transitionDuration) { setCameraPos(finalPos); setLookAt(finalLookAt); } else { var camPos = Object.assign({}, camera3.position); var camLookAt = getLookAt(); new Tween(camPos).to(finalPos, transitionDuration).easing(Easing.Quadratic.Out).onUpdate(setCameraPos).start(); new Tween(camLookAt).to(finalLookAt, transitionDuration / 3).easing(Easing.Quadratic.Out).onUpdate(setLookAt).start(); } return this; } return Object.assign({}, camera3.position, { lookAt: getLookAt() }); function setCameraPos(pos) { var x3 = pos.x, y3 = pos.y, z4 = pos.z; if (x3 !== void 0) camera3.position.x = x3; if (y3 !== void 0) camera3.position.y = y3; if (z4 !== void 0) camera3.position.z = z4; } function setLookAt(lookAt2) { var lookAtVect = new three2.Vector3(lookAt2.x, lookAt2.y, lookAt2.z); if (state.controls.target) { state.controls.target = lookAtVect; } else { camera3.lookAt(lookAtVect); } } function getLookAt() { return Object.assign(new three2.Vector3(0, 0, -1e3).applyQuaternion(camera3.quaternion).add(camera3.position)); } }, zoomToFit: function zoomToFit(state) { var transitionDuration = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0; var padding = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 10; for (var _len = arguments.length, bboxArgs = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) { bboxArgs[_key - 3] = arguments[_key]; } return this.fitToBbox(this.getBbox.apply(this, bboxArgs), transitionDuration, padding); }, fitToBbox: function fitToBbox(state, bbox) { var transitionDuration = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 0; var padding = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 10; var camera3 = state.camera; if (bbox) { var center = new three2.Vector3(0, 0, 0); var maxBoxSide = Math.max.apply(Math, _toConsumableArray4(Object.entries(bbox).map(function(_ref) { var _ref2 = _slicedToArray6(_ref, 2), coordType = _ref2[0], coords = _ref2[1]; return Math.max.apply(Math, _toConsumableArray4(coords.map(function(c2) { return Math.abs(center[coordType] - c2); }))); }))) * 2; var paddedFov = (1 - padding * 2 / state.height) * camera3.fov; var fitHeightDistance = maxBoxSide / Math.atan(paddedFov * Math.PI / 180); var fitWidthDistance = fitHeightDistance / camera3.aspect; var distance = Math.max(fitHeightDistance, fitWidthDistance); if (distance > 0) { var newCameraPosition = center.clone().sub(camera3.position).normalize().multiplyScalar(-distance); this.cameraPosition(newCameraPosition, center, transitionDuration); } } return this; }, getBbox: function getBbox(state) { var objFilter = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : function() { return true; }; var box = new three2.Box3(new three2.Vector3(0, 0, 0), new three2.Vector3(0, 0, 0)); var objs = state.objects.filter(objFilter); if (!objs.length) return null; objs.forEach(function(obj) { return box.expandByObject(obj); }); return Object.assign.apply(Object, _toConsumableArray4(["x", "y", "z"].map(function(c2) { return _defineProperty3({}, c2, [box.min[c2], box.max[c2]]); }))); }, getScreenCoords: function getScreenCoords(state, x3, y3, z4) { var vec = new three2.Vector3(x3, y3, z4); vec.project(this.camera()); return { // align relative pos to canvas dimensions x: (vec.x + 1) * state.width / 2, y: -(vec.y - 1) * state.height / 2 }; }, getSceneCoords: function getSceneCoords(state, screenX, screenY) { var distance = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 0; var relCoords = new three2.Vector2(screenX / state.width * 2 - 1, -(screenY / state.height) * 2 + 1); var raycaster = new three2.Raycaster(); raycaster.setFromCamera(relCoords, state.camera); return Object.assign({}, raycaster.ray.at(distance, new three2.Vector3())); }, intersectingObjects: function intersectingObjects(state, x3, y3) { var relCoords = new three2.Vector2(x3 / state.width * 2 - 1, -(y3 / state.height) * 2 + 1); var raycaster = new three2.Raycaster(); raycaster.params.Line.threshold = state.lineHoverPrecision; raycaster.setFromCamera(relCoords, state.camera); return raycaster.intersectObjects(state.objects, true); }, renderer: function renderer(state) { return state.renderer; }, scene: function scene(state) { return state.scene; }, camera: function camera(state) { return state.camera; }, postProcessingComposer: function postProcessingComposer(state) { return state.postProcessingComposer; }, controls: function controls(state) { return state.controls; }, tbControls: function tbControls(state) { return state.controls; } // to be deprecated }, stateInit: function stateInit2() { return { scene: new three2.Scene(), camera: new three2.PerspectiveCamera(), clock: new three2.Clock() }; }, init: function init2(domNode, state) { var _ref4 = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, _ref4$controlType = _ref4.controlType, controlType = _ref4$controlType === void 0 ? "trackball" : _ref4$controlType, _ref4$rendererConfig = _ref4.rendererConfig, rendererConfig = _ref4$rendererConfig === void 0 ? {} : _ref4$rendererConfig, _ref4$extraRenderers = _ref4.extraRenderers, extraRenderers = _ref4$extraRenderers === void 0 ? [] : _ref4$extraRenderers, _ref4$waitForLoadComp = _ref4.waitForLoadComplete, waitForLoadComplete = _ref4$waitForLoadComp === void 0 ? true : _ref4$waitForLoadComp; domNode.innerHTML = ""; domNode.appendChild(state.container = document.createElement("div")); state.container.className = "scene-container"; state.container.style.position = "relative"; state.container.appendChild(state.navInfo = document.createElement("div")); state.navInfo.className = "scene-nav-info"; state.navInfo.textContent = { orbit: "Left-click: rotate, Mouse-wheel/middle-click: zoom, Right-click: pan", trackball: "Left-click: rotate, Mouse-wheel/middle-click: zoom, Right-click: pan", fly: "WASD: move, R|F: up | down, Q|E: roll, up|down: pitch, left|right: yaw" }[controlType] || ""; state.navInfo.style.display = state.showNavInfo ? null : "none"; state.toolTipElem = document.createElement("div"); state.toolTipElem.classList.add("scene-tooltip"); state.container.appendChild(state.toolTipElem); state.pointerPos = new three2.Vector2(); state.pointerPos.x = -2; state.pointerPos.y = -2; ["pointermove", "pointerdown"].forEach(function(evType) { return state.container.addEventListener(evType, function(ev) { evType === "pointerdown" && (state.isPointerPressed = true); !state.isPointerDragging && ev.type === "pointermove" && (ev.pressure > 0 || state.isPointerPressed) && (ev.pointerType !== "touch" || ev.movementX === void 0 || [ev.movementX, ev.movementY].some(function(m2) { return Math.abs(m2) > 1; })) && (state.isPointerDragging = true); if (state.enablePointerInteraction) { var offset = getOffset(state.container); state.pointerPos.x = ev.pageX - offset.left; state.pointerPos.y = ev.pageY - offset.top; state.toolTipElem.style.top = "".concat(state.pointerPos.y, "px"); state.toolTipElem.style.left = "".concat(state.pointerPos.x, "px"); state.toolTipElem.style.transform = "translate(-".concat(state.pointerPos.x / state.width * 100, "%, ").concat( // flip to above if near bottom state.height - state.pointerPos.y < 100 ? "calc(-100% - 8px)" : "21px", ")" ); } function getOffset(el) { var rect = el.getBoundingClientRect(), scrollLeft = window.pageXOffset || document.documentElement.scrollLeft, scrollTop = window.pageYOffset || document.documentElement.scrollTop; return { top: rect.top + scrollTop, left: rect.left + scrollLeft }; } }, { passive: true }); }); state.container.addEventListener("pointerup", function(ev) { state.isPointerPressed = false; if (state.isPointerDragging) { state.isPointerDragging = false; if (!state.clickAfterDrag) return; } requestAnimationFrame(function() { if (ev.button === 0) { state.onClick(state.hoverObj || null, ev, state.intersectionPoint); } if (ev.button === 2 && state.onRightClick) { state.onRightClick(state.hoverObj || null, ev, state.intersectionPoint); } }); }, { passive: true, capture: true }); state.container.addEventListener("contextmenu", function(ev) { if (state.onRightClick) ev.preventDefault(); }); state.renderer = new three2.WebGLRenderer(Object.assign({ antialias: true, alpha: true }, rendererConfig)); state.renderer.setPixelRatio(Math.min(2, window.devicePixelRatio)); state.container.appendChild(state.renderer.domElement); state.extraRenderers = extraRenderers; state.extraRenderers.forEach(function(r) { r.domElement.style.position = "absolute"; r.domElement.style.top = "0px"; r.domElement.style.pointerEvents = "none"; state.container.appendChild(r.domElement); }); state.postProcessingComposer = new EffectComposer(state.renderer); state.postProcessingComposer.addPass(new RenderPass(state.scene, state.camera)); state.controls = new { trackball: TrackballControls, orbit: OrbitControls, fly: FlyControls }[controlType](state.camera, state.renderer.domElement); if (controlType === "fly") { state.controls.movementSpeed = 300; state.controls.rollSpeed = Math.PI / 6; state.controls.dragToLook = true; } if (controlType === "trackball" || controlType === "orbit") { state.controls.minDistance = 0.1; state.controls.maxDistance = state.skyRadius; state.controls.addEventListener("start", function() { state.controlsEngaged = true; }); state.controls.addEventListener("change", function() { if (state.controlsEngaged) { state.controlsDragging = true; } }); state.controls.addEventListener("end", function() { state.controlsEngaged = false; state.controlsDragging = false; }); } [state.renderer, state.postProcessingComposer].concat(_toConsumableArray4(state.extraRenderers)).forEach(function(r) { return r.setSize(state.width, state.height); }); state.camera.aspect = state.width / state.height; state.camera.updateProjectionMatrix(); state.camera.position.z = 1e3; state.scene.add(state.skysphere = new three2.Mesh()); state.skysphere.visible = false; state.loadComplete = state.scene.visible = !waitForLoadComplete; window.scene = state.scene; }, update: function update3(state, changedProps) { if (state.width && state.height && (changedProps.hasOwnProperty("width") || changedProps.hasOwnProperty("height"))) { state.container.style.width = "".concat(state.width, "px"); state.container.style.height = "".concat(state.height, "px"); [state.renderer, state.postProcessingComposer].concat(_toConsumableArray4(state.extraRenderers)).forEach(function(r) { return r.setSize(state.width, state.height); }); state.camera.aspect = state.width / state.height; state.camera.updateProjectionMatrix(); } if (changedProps.hasOwnProperty("skyRadius") && state.skyRadius) { state.controls.hasOwnProperty("maxDistance") && changedProps.skyRadius && (state.controls.maxDistance = Math.min(state.controls.maxDistance, state.skyRadius)); state.camera.far = state.skyRadius * 2.5; state.camera.updateProjectionMatrix(); state.skysphere.geometry = new three2.SphereGeometry(state.skyRadius); } if (changedProps.hasOwnProperty("backgroundColor")) { var alpha = parseToRgb(state.backgroundColor).alpha; if (alpha === void 0) alpha = 1; state.renderer.setClearColor(new three2.Color(curriedOpacify$1(1, state.backgroundColor)), alpha); } if (changedProps.hasOwnProperty("backgroundImageUrl")) { if (!state.backgroundImageUrl) { state.skysphere.visible = false; state.skysphere.material.map = null; !state.loadComplete && finishLoad(); } else { new three2.TextureLoader().load(state.backgroundImageUrl, function(texture) { texture.colorSpace = three2.SRGBColorSpace; state.skysphere.material = new three2.MeshBasicMaterial({ map: texture, side: three2.BackSide }); state.skysphere.visible = true; state.onBackgroundImageLoaded && setTimeout(state.onBackgroundImageLoaded); !state.loadComplete && finishLoad(); }); } } changedProps.hasOwnProperty("showNavInfo") && (state.navInfo.style.display = state.showNavInfo ? null : "none"); if (changedProps.hasOwnProperty("lights")) { (changedProps.lights || []).forEach(function(light) { return state.scene.remove(light); }); state.lights.forEach(function(light) { return state.scene.add(light); }); } if (changedProps.hasOwnProperty("objects")) { (changedProps.objects || []).forEach(function(obj) { return state.scene.remove(obj); }); state.objects.forEach(function(obj) { return state.scene.add(obj); }); } function finishLoad() { state.loadComplete = state.scene.visible = true; } } }); // node_modules/3d-force-graph/dist/3d-force-graph.mjs function styleInject2(css, ref) { if (ref === void 0) ref = {}; var insertAt = ref.insertAt; if (!css || typeof document === "undefined") { return; } var head = document.head || document.getElementsByTagName("head")[0]; var style = document.createElement("style"); style.type = "text/css"; if (insertAt === "top") { if (head.firstChild) { head.insertBefore(style, head.firstChild); } else { head.appendChild(style); } } else { head.appendChild(style); } if (style.styleSheet) { style.styleSheet.cssText = css; } else { style.appendChild(document.createTextNode(css)); } } var css_248z2 = ".graph-info-msg {\n top: 50%;\n width: 100%;\n text-align: center;\n color: lavender;\n opacity: 0.7;\n font-size: 22px;\n position: absolute;\n font-family: Sans-serif;\n}\n\n.scene-container .clickable {\n cursor: pointer;\n}\n\n.scene-container .grabbable {\n cursor: move;\n cursor: grab;\n cursor: -moz-grab;\n cursor: -webkit-grab;\n}\n\n.scene-container .grabbable:active {\n cursor: grabbing;\n cursor: -moz-grabbing;\n cursor: -webkit-grabbing;\n}"; styleInject2(css_248z2); function ownKeys3(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function(r2) { return Object.getOwnPropertyDescriptor(e, r2).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread23(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys3(Object(t), true).forEach(function(r2) { _defineProperty4(e, r2, t[r2]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys3(Object(t)).forEach(function(r2) { Object.defineProperty(e, r2, Object.getOwnPropertyDescriptor(t, r2)); }); } return e; } function _defineProperty4(obj, key, value) { key = _toPropertyKey7(key); if (key in obj) { Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toConsumableArray5(arr) { return _arrayWithoutHoles5(arr) || _iterableToArray5(arr) || _unsupportedIterableToArray7(arr) || _nonIterableSpread5(); } function _arrayWithoutHoles5(arr) { if (Array.isArray(arr)) return _arrayLikeToArray7(arr); } function _iterableToArray5(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } function _unsupportedIterableToArray7(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray7(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray7(o, minLen); } function _arrayLikeToArray7(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _nonIterableSpread5() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _toPrimitive7(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== void 0) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } function _toPropertyKey7(arg) { var key = _toPrimitive7(arg, "string"); return typeof key === "symbol" ? key : String(key); } function linkKapsule(kapsulePropName, kapsuleType) { var dummyK = new kapsuleType(); dummyK._destructor && dummyK._destructor(); return { linkProp: function linkProp(prop) { return { "default": dummyK[prop](), onChange: function onChange13(v, state) { state[kapsulePropName][prop](v); }, triggerUpdate: false }; }, linkMethod: function linkMethod(method) { return function(state) { var kapsuleInstance = state[kapsulePropName]; for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { args[_key - 1] = arguments[_key]; } var returnVal = kapsuleInstance[method].apply(kapsuleInstance, args); return returnVal === kapsuleInstance ? this : returnVal; }; } }; } var three3 = window.THREE ? window.THREE : { AmbientLight, DirectionalLight, Vector3 }; var CAMERA_DISTANCE2NODES_FACTOR = 170; var bindFG = linkKapsule("forceGraph", threeForcegraph); var linkedFGProps = Object.assign.apply(Object, _toConsumableArray5(["jsonUrl", "graphData", "numDimensions", "dagMode", "dagLevelDistance", "dagNodeFilter", "onDagError", "nodeRelSize", "nodeId", "nodeVal", "nodeResolution", "nodeColor", "nodeAutoColorBy", "nodeOpacity", "nodeVisibility", "nodeThreeObject", "nodeThreeObjectExtend", "linkSource", "linkTarget", "linkVisibility", "linkColor", "linkAutoColorBy", "linkOpacity", "linkWidth", "linkResolution", "linkCurvature", "linkCurveRotation", "linkMaterial", "linkThreeObject", "linkThreeObjectExtend", "linkPositionUpdate", "linkDirectionalArrowLength", "linkDirectionalArrowColor", "linkDirectionalArrowRelPos", "linkDirectionalArrowResolution", "linkDirectionalParticles", "linkDirectionalParticleSpeed", "linkDirectionalParticleWidth", "linkDirectionalParticleColor", "linkDirectionalParticleResolution", "forceEngine", "d3AlphaDecay", "d3VelocityDecay", "d3AlphaMin", "ngraphPhysics", "warmupTicks", "cooldownTicks", "cooldownTime", "onEngineTick", "onEngineStop"].map(function(p) { return _defineProperty4({}, p, bindFG.linkProp(p)); }))); var linkedFGMethods = Object.assign.apply(Object, _toConsumableArray5(["refresh", "getGraphBbox", "d3Force", "d3ReheatSimulation", "emitParticle"].map(function(p) { return _defineProperty4({}, p, bindFG.linkMethod(p)); }))); var bindRenderObjs = linkKapsule("renderObjs", threeRenderObjects); var linkedRenderObjsProps = Object.assign.apply(Object, _toConsumableArray5(["width", "height", "backgroundColor", "showNavInfo", "enablePointerInteraction"].map(function(p) { return _defineProperty4({}, p, bindRenderObjs.linkProp(p)); }))); var linkedRenderObjsMethods = Object.assign.apply(Object, _toConsumableArray5(["lights", "cameraPosition", "postProcessingComposer"].map(function(p) { return _defineProperty4({}, p, bindRenderObjs.linkMethod(p)); })).concat([{ graph2ScreenCoords: bindRenderObjs.linkMethod("getScreenCoords"), screen2GraphCoords: bindRenderObjs.linkMethod("getSceneCoords") }])); var _3dForceGraph = index5({ props: _objectSpread23(_objectSpread23({ nodeLabel: { "default": "name", triggerUpdate: false }, linkLabel: { "default": "name", triggerUpdate: false }, linkHoverPrecision: { "default": 1, onChange: function onChange11(p, state) { return state.renderObjs.lineHoverPrecision(p); }, triggerUpdate: false }, enableNavigationControls: { "default": true, onChange: function onChange12(enable, state) { var controls3 = state.renderObjs.controls(); if (controls3) { controls3.enabled = enable; enable && controls3.domElement && controls3.domElement.dispatchEvent(new PointerEvent("pointerup")); } }, triggerUpdate: false }, enableNodeDrag: { "default": true, triggerUpdate: false }, onNodeDrag: { "default": function _default12() { }, triggerUpdate: false }, onNodeDragEnd: { "default": function _default13() { }, triggerUpdate: false }, onNodeClick: { triggerUpdate: false }, onNodeRightClick: { triggerUpdate: false }, onNodeHover: { triggerUpdate: false }, onLinkClick: { triggerUpdate: false }, onLinkRightClick: { triggerUpdate: false }, onLinkHover: { triggerUpdate: false }, onBackgroundClick: { triggerUpdate: false }, onBackgroundRightClick: { triggerUpdate: false } }, linkedFGProps), linkedRenderObjsProps), methods: _objectSpread23(_objectSpread23({ zoomToFit: function zoomToFit2(state, transitionDuration, padding) { var _state$forceGraph; for (var _len = arguments.length, bboxArgs = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) { bboxArgs[_key - 3] = arguments[_key]; } state.renderObjs.fitToBbox((_state$forceGraph = state.forceGraph).getGraphBbox.apply(_state$forceGraph, bboxArgs), transitionDuration, padding); return this; }, pauseAnimation: function pauseAnimation(state) { if (state.animationFrameRequestId !== null) { cancelAnimationFrame(state.animationFrameRequestId); state.animationFrameRequestId = null; } return this; }, resumeAnimation: function resumeAnimation(state) { if (state.animationFrameRequestId === null) { this._animationCycle(); } return this; }, _animationCycle: function _animationCycle(state) { if (state.enablePointerInteraction) { this.renderer().domElement.style.cursor = null; } state.forceGraph.tickFrame(); state.renderObjs.tick(); state.animationFrameRequestId = requestAnimationFrame(this._animationCycle); }, scene: function scene2(state) { return state.renderObjs.scene(); }, // Expose scene camera: function camera2(state) { return state.renderObjs.camera(); }, // Expose camera renderer: function renderer2(state) { return state.renderObjs.renderer(); }, // Expose renderer controls: function controls2(state) { return state.renderObjs.controls(); }, // Expose controls tbControls: function tbControls2(state) { return state.renderObjs.tbControls(); }, // To be deprecated _destructor: function _destructor() { this.pauseAnimation(); this.graphData({ nodes: [], links: [] }); } }, linkedFGMethods), linkedRenderObjsMethods), stateInit: function stateInit3(_ref5) { var controlType = _ref5.controlType, rendererConfig = _ref5.rendererConfig, extraRenderers = _ref5.extraRenderers; var forceGraph = new threeForcegraph(); return { forceGraph, renderObjs: threeRenderObjects({ controlType, rendererConfig, extraRenderers }).objects([forceGraph]).lights([new three3.AmbientLight(13421772, Math.PI), new three3.DirectionalLight(16777215, 0.6 * Math.PI)]) }; }, init: function init3(domNode, state) { domNode.innerHTML = ""; domNode.appendChild(state.container = document.createElement("div")); state.container.style.position = "relative"; var roDomNode = document.createElement("div"); state.container.appendChild(roDomNode); state.renderObjs(roDomNode); var camera3 = state.renderObjs.camera(); var renderer3 = state.renderObjs.renderer(); var controls3 = state.renderObjs.controls(); controls3.enabled = !!state.enableNavigationControls; state.lastSetCameraZ = camera3.position.z; var infoElem; state.container.appendChild(infoElem = document.createElement("div")); infoElem.className = "graph-info-msg"; infoElem.textContent = ""; state.forceGraph.onLoading(function() { infoElem.textContent = "Loading..."; }).onFinishLoading(function() { infoElem.textContent = ""; }).onUpdate(function() { state.graphData = state.forceGraph.graphData(); if (camera3.position.x === 0 && camera3.position.y === 0 && camera3.position.z === state.lastSetCameraZ && state.graphData.nodes.length) { camera3.lookAt(state.forceGraph.position); state.lastSetCameraZ = camera3.position.z = Math.cbrt(state.graphData.nodes.length) * CAMERA_DISTANCE2NODES_FACTOR; } }).onFinishUpdate(function() { if (state._dragControls) { var curNodeDrag = state.graphData.nodes.find(function(node) { return node.__initialFixedPos && !node.__disposeControlsAfterDrag; }); if (curNodeDrag) { curNodeDrag.__disposeControlsAfterDrag = true; } else { state._dragControls.dispose(); } state._dragControls = void 0; } if (state.enableNodeDrag && state.enablePointerInteraction && state.forceEngine === "d3") { var dragControls = state._dragControls = new DragControls(state.graphData.nodes.map(function(node) { return node.__threeObj; }).filter(function(obj) { return obj; }), camera3, renderer3.domElement); dragControls.addEventListener("dragstart", function(event) { controls3.enabled = false; event.object.__initialPos = event.object.position.clone(); event.object.__prevPos = event.object.position.clone(); var node = getGraphObj(event.object).__data; !node.__initialFixedPos && (node.__initialFixedPos = { fx: node.fx, fy: node.fy, fz: node.fz }); !node.__initialPos && (node.__initialPos = { x: node.x, y: node.y, z: node.z }); ["x", "y", "z"].forEach(function(c2) { return node["f".concat(c2)] = node[c2]; }); renderer3.domElement.classList.add("grabbable"); }); dragControls.addEventListener("drag", function(event) { var nodeObj = getGraphObj(event.object); if (!event.object.hasOwnProperty("__graphObjType")) { var initPos = event.object.__initialPos; var prevPos = event.object.__prevPos; var _newPos = event.object.position; nodeObj.position.add(_newPos.clone().sub(prevPos)); prevPos.copy(_newPos); _newPos.copy(initPos); } var node = nodeObj.__data; var newPos = nodeObj.position; var translate = { x: newPos.x - node.x, y: newPos.y - node.y, z: newPos.z - node.z }; ["x", "y", "z"].forEach(function(c2) { return node["f".concat(c2)] = node[c2] = newPos[c2]; }); state.forceGraph.d3AlphaTarget(0.3).resetCountdown(); node.__dragged = true; state.onNodeDrag(node, translate); }); dragControls.addEventListener("dragend", function(event) { delete event.object.__initialPos; delete event.object.__prevPos; var node = getGraphObj(event.object).__data; if (node.__disposeControlsAfterDrag) { dragControls.dispose(); delete node.__disposeControlsAfterDrag; } var initFixedPos = node.__initialFixedPos; var initPos = node.__initialPos; var translate = { x: initPos.x - node.x, y: initPos.y - node.y, z: initPos.z - node.z }; if (initFixedPos) { ["x", "y", "z"].forEach(function(c2) { var fc = "f".concat(c2); if (initFixedPos[fc] === void 0) { delete node[fc]; } }); delete node.__initialFixedPos; delete node.__initialPos; if (node.__dragged) { delete node.__dragged; state.onNodeDragEnd(node, translate); } } state.forceGraph.d3AlphaTarget(0).resetCountdown(); if (state.enableNavigationControls) { controls3.enabled = true; controls3.domElement && controls3.domElement.ownerDocument && controls3.domElement.ownerDocument.dispatchEvent( // simulate mouseup to ensure the controls don't take over after dragend new PointerEvent("pointerup", { pointerType: "touch" }) ); } renderer3.domElement.classList.remove("grabbable"); }); } }); state.renderObjs.renderer().useLegacyLights = false; state.renderObjs.hoverOrderComparator(function(a2, b) { var aObj = getGraphObj(a2); if (!aObj) return 1; var bObj = getGraphObj(b); if (!bObj) return -1; var isNode = function isNode2(o) { return o.__graphObjType === "node"; }; return isNode(bObj) - isNode(aObj); }).tooltipContent(function(obj) { var graphObj = getGraphObj(obj); return graphObj ? index3(state["".concat(graphObj.__graphObjType, "Label")])(graphObj.__data) || "" : ""; }).hoverDuringDrag(false).onHover(function(obj) { var hoverObj = getGraphObj(obj); if (hoverObj !== state.hoverObj) { var prevObjType = state.hoverObj ? state.hoverObj.__graphObjType : null; var prevObjData = state.hoverObj ? state.hoverObj.__data : null; var objType = hoverObj ? hoverObj.__graphObjType : null; var objData = hoverObj ? hoverObj.__data : null; if (prevObjType && prevObjType !== objType) { var fn = state["on".concat(prevObjType === "node" ? "Node" : "Link", "Hover")]; fn && fn(null, prevObjData); } if (objType) { var _fn = state["on".concat(objType === "node" ? "Node" : "Link", "Hover")]; _fn && _fn(objData, prevObjType === objType ? prevObjData : null); } renderer3.domElement.classList[hoverObj && state["on".concat(objType === "node" ? "Node" : "Link", "Click")] || !hoverObj && state.onBackgroundClick ? "add" : "remove"]("clickable"); state.hoverObj = hoverObj; } }).clickAfterDrag(false).onClick(function(obj, ev) { var graphObj = getGraphObj(obj); if (graphObj) { var fn = state["on".concat(graphObj.__graphObjType === "node" ? "Node" : "Link", "Click")]; fn && fn(graphObj.__data, ev); } else { state.onBackgroundClick && state.onBackgroundClick(ev); } }).onRightClick(function(obj, ev) { var graphObj = getGraphObj(obj); if (graphObj) { var fn = state["on".concat(graphObj.__graphObjType === "node" ? "Node" : "Link", "RightClick")]; fn && fn(graphObj.__data, ev); } else { state.onBackgroundRightClick && state.onBackgroundRightClick(ev); } }); this._animationCycle(); } }); function getGraphObj(object) { var obj = object; while (obj && !obj.hasOwnProperty("__graphObjType")) { obj = obj.parent; } return obj; } // src/views/graph/CenterCoordinates.ts var origin = new Vector32(0, 0, 0); var CenterCoordinates = class { constructor(visibility = false) { this.arrowsGroup = new Group2(); const xDir = new Vector32(1, 0, 0); const yDir = new Vector32(0, 1, 0); const zDir = new Vector32(0, 0, 1); xDir.normalize(); yDir.normalize(); zDir.normalize(); const length = 100; const xArrow = new ArrowHelper(xDir, origin, length, 16711680); const yArrow = new ArrowHelper(yDir, origin, length, 65280); const zArrow = new ArrowHelper(zDir, origin, length, 255); this.arrowsGroup.add(xArrow, yArrow, zArrow); this.arrowsGroup.visible = visibility; } setVisibility(visibility) { this.arrowsGroup.visible = visibility; } setLength(length) { this.arrowsGroup.children.forEach((arrow) => { arrow.setLength(length); }); } }; // src/util/hexToRGBA.ts function hexToRGBA(hex, alpha) { hex = hex.replace("#", ""); const r = parseInt(hex.substring(0, 2), 16); const g = parseInt(hex.substring(2, 4), 16); const b = parseInt(hex.substring(4, 6), 16); const rgba2 = `rgba(${r}, ${g}, ${b}, ${alpha})`; return rgba2; } // node_modules/three/examples/jsm/renderers/CSS2DRenderer.js var CSS2DObject = class extends Object3D2 { constructor(element = document.createElement("div")) { super(); this.isCSS2DObject = true; this.element = element; this.element.style.position = "absolute"; this.element.style.userSelect = "none"; this.element.setAttribute("draggable", false); this.center = new Vector22(0.5, 0.5); this.addEventListener("removed", function() { this.traverse(function(object) { if (object.element instanceof Element && object.element.parentNode !== null) { object.element.parentNode.removeChild(object.element); } }); }); } copy(source, recursive) { super.copy(source, recursive); this.element = source.element.cloneNode(true); this.center = source.center; return this; } }; var _vector = new Vector32(); var _viewMatrix = new Matrix42(); var _viewProjectionMatrix = new Matrix42(); var _a = new Vector32(); var _b = new Vector32(); var CSS2DRenderer = class { constructor(parameters = {}) { const _this = this; let _width, _height; let _widthHalf, _heightHalf; const cache = { objects: /* @__PURE__ */ new WeakMap() }; const domElement = parameters.element !== void 0 ? parameters.element : document.createElement("div"); domElement.style.overflow = "hidden"; this.domElement = domElement; this.getSize = function() { return { width: _width, height: _height }; }; this.render = function(scene3, camera3) { if (scene3.matrixWorldAutoUpdate === true) scene3.updateMatrixWorld(); if (camera3.parent === null && camera3.matrixWorldAutoUpdate === true) camera3.updateMatrixWorld(); _viewMatrix.copy(camera3.matrixWorldInverse); _viewProjectionMatrix.multiplyMatrices(camera3.projectionMatrix, _viewMatrix); renderObject(scene3, scene3, camera3); zOrder(scene3); }; this.setSize = function(width, height) { _width = width; _height = height; _widthHalf = _width / 2; _heightHalf = _height / 2; domElement.style.width = width + "px"; domElement.style.height = height + "px"; }; function renderObject(object, scene3, camera3) { if (object.isCSS2DObject) { _vector.setFromMatrixPosition(object.matrixWorld); _vector.applyMatrix4(_viewProjectionMatrix); const visible = object.visible === true && (_vector.z >= -1 && _vector.z <= 1) && object.layers.test(camera3.layers) === true; object.element.style.display = visible === true ? "" : "none"; if (visible === true) { object.onBeforeRender(_this, scene3, camera3); const element = object.element; element.style.transform = "translate(" + -100 * object.center.x + "%," + -100 * object.center.y + "%)translate(" + (_vector.x * _widthHalf + _widthHalf) + "px," + (-_vector.y * _heightHalf + _heightHalf) + "px)"; if (element.parentNode !== domElement) { domElement.appendChild(element); } object.onAfterRender(_this, scene3, camera3); } const objectData = { distanceToCameraSquared: getDistanceToSquared(camera3, object) }; cache.objects.set(object, objectData); } for (let i = 0, l = object.children.length; i < l; i++) { renderObject(object.children[i], scene3, camera3); } } function getDistanceToSquared(object1, object2) { _a.setFromMatrixPosition(object1.matrixWorld); _b.setFromMatrixPosition(object2.matrixWorld); return _a.distanceToSquared(_b); } function filterAndFlatten(scene3) { const result = []; scene3.traverse(function(object) { if (object.isCSS2DObject) result.push(object); }); return result; } function zOrder(scene3) { const sorted = filterAndFlatten(scene3).sort(function(a2, b) { if (a2.renderOrder !== b.renderOrder) { return b.renderOrder - a2.renderOrder; } const distanceA = cache.objects.get(a2).distanceToCameraSquared; const distanceB = cache.objects.get(b).distanceToCameraSquared; return distanceA - distanceB; }); const zMax = sorted.length; for (let i = 0, l = sorted.length; i < l; i++) { sorted[i].element.style.zIndex = zMax - i; } } } }; // src/commands/CommandModal.ts var import_obsidian4 = require("obsidian"); // src/commands/deleteNote.ts var deleteNote = (view, nodes) => { const vault = view.plugin.app.vault; for (const node of nodes) { const file = vault.getAbstractFileByPath(node.path); if (file) { vault.trash(file, vault.config.trashOption === "system"); } } }; // src/commands/showShortestPath.ts var getShortestPath = (node1, node2) => { const visited = /* @__PURE__ */ new Set(); const queue = [{ node: node1, path: [node1] }]; while (queue.length > 0) { const { node, path } = queue.shift(); if (node === node2) { return path; } visited.add(node); for (const neighbor of node.neighbors) { if (!visited.has(neighbor)) { queue.push({ node: neighbor, path: [...path, neighbor] }); } } } console.error("No path found between the two nodes"); return null; }; var showShortestPath = (view, nodes) => { const [node1, node2] = [...nodes].filter(Boolean); if (!node1 || !node2) { console.error("Invalid nodes provided"); return null; } const path = getShortestPath(node1, node2); if (!path) { createNotice("Shortest path not found"); return; } const interval2 = setInterval(() => { if (path.length > 0) { const node = path.shift(); view.getForceGraph().interactionManager.focusOnNodeByPath(node.path); } else { clearInterval(interval2); } }, 5e3); }; // src/commands/Command.ts var commands = [ { title: "Delete Note", function: deleteNote }, { title: "Test Command", function: (view, nodes) => { for (const node of nodes) { const file = view.plugin.app.vault.getAbstractFileByPath(node.path); if (file) createNotice(`run on ${file.name}`); } } }, { title: "Shortest Path", showConditon: (view, nodes) => nodes.size === 2, function: showShortestPath } ]; // src/commands/CommandModal.ts var CommandModal = class extends import_obsidian4.FuzzySuggestModal { constructor(view, selectedNodes) { super(view.plugin.app); this.nodes = selectedNodes; this.view = view; } getItems() { return commands.filter((command) => { var _a3, _b3; return (_b3 = (_a3 = command.showConditon) == null ? void 0 : _a3.call(command, this.view, this.nodes)) != null ? _b3 : true; }); } getItemText(command) { return command.title; } onChooseItem(command, evt) { command.function(this.view, this.nodes); } }; // src/views/graph/ForceGraphEngine.ts var origin2 = new Vector32(0, 0, 0); var cameraLookAtCenterTransitionDuration = 1e3; var LINK_PARTICLE_MULTIPLIER = 2; var FOCAL_FROM_CAMERA = 400; var selectedColor = "#CCA700"; var PARTICLE_FREQUECY = 4; var LINK_ARROW_WIDTH_MULTIPLIER = 5; var ForceGraphEngine = class { constructor(forceGraph) { // eslint-disable-next-line @typescript-eslint/no-explicit-any this.tween = {}; this.spaceDown = false; this.commandDown = false; this.selectedNodes = /* @__PURE__ */ new Set(); /** * the node connected to the hover node */ this.highlightedNodes = /* @__PURE__ */ new Set(); /** * the links connected to the hover node */ this.highlightedLinks = /* @__PURE__ */ new Set(); // zooming this.isZooming = false; this.onZoomStart = () => { const tweens = Object.keys(this.tween); if (tweens) { Object.values(this.tween).forEach((tween) => { if (tween) { tween.stop(); } }); this.tween = {}; } }; this.onNodeDrag = (node, translate) => { if (this.forceGraph.view.settingManager.getCurrentSetting().display.dontMoveWhenDrag) this.forceGraph.instance.cooldownTicks(0); if (this.selectedNodes.has(node)) { [...this.selectedNodes].filter((selNode) => selNode !== node).forEach( (node2) => ["x", "y", "z"].forEach( // @ts-ignore (coord) => node2[`f${coord}`] = node2[coord] + translate[coord] ) ); } }; this.onNodeDragEnd = (node) => { const setting = this.forceGraph.view.settingManager.getCurrentSetting(); if (setting.display.dontMoveWhenDrag) this.forceGraph.instance.cooldownTicks(Infinity); if (this.selectedNodes.has(node)) { [...this.selectedNodes].filter((selNode) => selNode !== node).forEach((node2) => ["x", "y", "z"].forEach((coord) => node2[`f${coord}`] = void 0)); } }; this.onNodeRightClick = (node, event) => { const plugin = this.forceGraph.view.plugin; const pluginSetting = plugin.settingManager.getSettings().pluginSetting; if (this.commandDown || event.ctrlKey) { const clickedNodeFile = this.findFileByNode(node); if (pluginSetting.commandRightClickNode === "openNodeInNewTab" /* openNodeInNewTab */ && clickedNodeFile) { this.openFileInNewTab(clickedNodeFile); } else if (pluginSetting.commandRightClickNode === "focusNode" /* focusNode */) this.focusOnCoords(node); return; } if (!this.selectedNodes.has(node)) { this.selectedNodes.clear(); this.selectedNodes.add(node); } const modal = new CommandModal(this.forceGraph.view, this.selectedNodes); const promptEl = modal.containerEl.querySelector(".prompt"); const dv = promptEl == null ? void 0 : promptEl.createDiv({ text: `Commands will be run for ${this.selectedNodes.size} nodes.` }); dv == null ? void 0 : dv.setAttribute("style", "padding: var(--size-4-3); font-size: var(--font-smaller);"); modal.open(); }; this.onNodeClick = (node, event) => { const plugin = this.forceGraph.view.plugin; const pluginSetting = plugin.settingManager.getSettings().pluginSetting; if (event.shiftKey) { const isSelected = this.selectedNodes.has(node); isSelected ? this.selectedNodes.delete(node) : this.selectedNodes.add(node); return; } const clickedNodeFile = this.findFileByNode(node); if (this.commandDown || event.ctrlKey) { if (pluginSetting.commandLeftClickNode === "openNodeInNewTab" /* openNodeInNewTab */ && clickedNodeFile) { this.openFileInNewTab(clickedNodeFile); } else if (pluginSetting.commandLeftClickNode === "focusNode" /* focusNode */) this.focusOnCoords(node); return; } if (clickedNodeFile) { if (this.forceGraph.view.graphType === "local" /* local */) { this.openFileInNewTab(clickedNodeFile); } else { this.forceGraph.view.itemView.leaf.openFile(clickedNodeFile); } } }; this.onNodeHover = (node) => { if (!node && !this.highlightedNodes.size || node && this.hoveredNode === node) return; if (node) { const text = this.getNodeLabelText(node); this.forceGraph.nodeLabelEl.textContent = text; this.forceGraph.nodeLabelEl.style.color = node.color; this.forceGraph.nodeLabelEl.style.opacity = "1"; } else { this.forceGraph.nodeLabelEl.style.opacity = "0"; } this.clearHighlights(); if (node) { this.highlightedNodes.add(node.id); node.neighbors.forEach((neighbor) => this.highlightedNodes.add(neighbor.id)); const nodeLinks = this.forceGraph.instance.graphData().getLinksWithNode(node.id); if (nodeLinks) nodeLinks.forEach((link) => this.highlightedLinks.add(link)); } this.hoveredNode = node != null ? node : null; this.updateColor(); }; this.clearHighlights = () => { this.highlightedNodes.clear(); this.highlightedLinks.clear(); }; this.getLinkColor = (link) => { const color = this.isHighlightedLink(link) ? this.forceGraph.view.settingManager.getCurrentSetting().display.linkHoverColor : this.forceGraph.view.theme.graphLine; return hexToRGBA(color, this.getIsAnyHighlighted() && !this.isHighlightedLink(link) ? 0.2 : 1); }; this.getLinkWidth = (link) => { const setting = this.forceGraph.view.settingManager.getCurrentSetting(); return this.isHighlightedLink(link) ? setting.display.linkThickness * 1.5 : setting.display.linkThickness; }; this.getLinkDirectionalParticles = (link) => { return this.isHighlightedLink(link) ? PARTICLE_FREQUECY : 0; }; this.getLinkDirectionalParticleWidth = () => { const setting = this.forceGraph.view.settingManager.getCurrentSetting(); return setting.display.linkThickness * LINK_PARTICLE_MULTIPLIER; }; this.onLinkHover = (link) => { this.clearHighlights(); if (link) { this.highlightedLinks.add(link); this.highlightedNodes.add(link.source.id); this.highlightedNodes.add(link.target.id); } this.updateColor(); }; this.findFileByNode = (node) => { return this.forceGraph.view.plugin.app.vault.getFiles().find((f) => f.path === node.path); }; this.getNodeOpacityEasedValue = (node) => { const obj = node.__threeObj; if (!obj) return 0; const nodePosition = obj.position; const distance = nodePosition.distanceTo(this.forceGraph.myCube.position); const distanceFromFocal2 = this.forceGraph.view.settingManager.getCurrentSetting().display.distanceFromFocal; const normalizedDistance = Math.min(distance, distanceFromFocal2) / distanceFromFocal2; const easedValue = 0.5 - 0.5 * Math.cos(normalizedDistance * Math.PI); return easedValue; }; this.getLinkDirectionalArrowLength = () => { const settings = this.forceGraph.view.settingManager.getCurrentSetting(); return settings.display.linkThickness * LINK_ARROW_WIDTH_MULTIPLIER * (settings.display.showLinkArrow ? 1 : 0); }; this.isHighlightedLink = (link) => { return this.highlightedLinks.has(link); }; this.getNodeLabelText = (node) => { const settings = this.forceGraph.view.settingManager.getCurrentSetting(); const fullPath = node.path; const fileNameWithExtension = node.name; const fullPathWithoutExtension = fullPath.substring(0, fullPath.lastIndexOf(".")); const fileNameWithoutExtension = fileNameWithExtension.substring( 0, fileNameWithExtension.lastIndexOf(".") ); const text = !settings.display.showExtension ? settings.display.showFullPath ? fullPathWithoutExtension : fileNameWithoutExtension : settings.display.showFullPath ? fullPath : fileNameWithExtension; return text; }; /** * this will force the camera to look at the center of the graph */ this.cameraLookAtCenter = () => { const cameraPosition2 = this.forceGraph.instance.camera().position; this.cameraPosition(cameraPosition2, { x: 0, y: 0, z: 0 }, cameraLookAtCenterTransitionDuration); }; this.focusOnNodeByPath = (path) => { const node = this.forceGraph.instance.graphData().nodes.find( (n) => n.path === path ); if (node) { this.focusOnCoords(node, 1e3); } }; this.focusOnCoords = (coords, duration = 3e3) => { const distance = FOCAL_FROM_CAMERA; const distRatio = 1 + distance / Math.hypot(coords.x, coords.y, coords.z); const newPos = coords.x || coords.y || coords.z ? { x: coords.x * distRatio, y: coords.y * distRatio, z: coords.z * distRatio } : { x: 0, y: 0, z: distance }; this.cameraPosition( newPos, // new position coords, // lookAt ({ x, y, z }) duration // ms transition duration ); }; this.isHighlightedNode = (node) => { return this.highlightedNodes.has(node.id); }; this.getNodeColor = (node) => { let color; const settings = this.forceGraph.view.settingManager.getCurrentSetting(); const theme = this.forceGraph.view.theme; const searchResult = this.forceGraph.view.settingManager.searchResult; if (this.selectedNodes.has(node)) { color = selectedColor; } else if (this.isHighlightedNode(node)) { color = node === this.hoveredNode ? settings.display.nodeHoverColor : settings.display.nodeHoverNeighbourColor; } else { color = theme.graphNode; settings.groups.forEach((group, index6) => { if (group.query.trim().length === 0) return; const searchStateGroup = searchResult.value.groups[index6]; if (searchStateGroup) { const searchGroupfilePaths = searchStateGroup.files.map((file) => file.path); if (searchGroupfilePaths.includes(node.path)) color = group.color; } }); } const rgba2 = hexToRGBA( color, this.getIsAnyHighlighted() && !this.isHighlightedNode(node) ? 0.5 : 1 ); return rgba2; }; this.getIsAnyHighlighted = () => { return this.highlightedNodes.size !== 0 || this.highlightedLinks.size !== 0; }; this.forceGraph = forceGraph; this.initListeners(); } onZoom(event) { const camera3 = this.forceGraph.instance.camera(); if (!this.isZooming && !this.startZoomTimeout) { this.startZoomTimeout = setTimeout(() => { if (!this.isZooming) { clearTimeout(this.startZoomTimeout); this.startZoomTimeout = void 0; this.isZooming = true; this.onZoomStart(); } return; }, 100); } const distanceToCenter = camera3.position.distanceTo(origin2); camera3.updateProjectionMatrix(); this.forceGraph.centerCoordinates.setLength(distanceToCenter / 10); if (this.isZooming) { clearTimeout(this.endZoomTimeout); this.endZoomTimeout = setTimeout(() => { this.endZoomTimeout = void 0; this.isZooming = false; this.onZoomEnd(); }, 100); } } onZoomEnd() { } updateNodeLabelDiv() { this.forceGraph.instance.nodeThreeObject(this.forceGraph.instance.nodeThreeObject()); } /** * this will update the color of the nodes and links */ updateColor() { this.forceGraph.instance.nodeColor(this.forceGraph.instance.nodeColor()).linkColor(this.forceGraph.instance.linkColor()).linkDirectionalParticles(this.forceGraph.instance.linkDirectionalParticles()); } initListeners() { document.addEventListener("keydown", (e) => { if (e.code === "Space") { this.spaceDown = true; } if (e.metaKey) this.commandDown = true; }); document.addEventListener("keyup", (e) => { if (e.code === "Space") { this.spaceDown = false; } if (!e.metaKey) this.commandDown = false; }); } /** * * if the input is undefined, return the current camera position. else this will move the camera to a specific position. */ cameraPosition(position, lookAt, transitionDuration) { const instance = this.forceGraph.instance; const camera3 = instance.camera(); const controls3 = instance.controls(); const tween = this.tween; if (position === void 0 && lookAt === void 0 && transitionDuration === void 0) { return { x: camera3.position.x, y: camera3.position.y, z: camera3.position.z }; } if (position) { let setCameraPos = function(pos) { const { x: x3, y: y3, z: z4 } = pos; if (x3 !== void 0) camera3.position.x = x3; if (y3 !== void 0) camera3.position.y = y3; if (z4 !== void 0) camera3.position.z = z4; }, setLookAt = function(lookAt2) { const lookAtVect = new Vector32(lookAt2.x, lookAt2.y, lookAt2.z); if (controls3.target) { controls3.target = lookAtVect; } else { camera3.lookAt(lookAtVect); } }, getLookAt = function() { return Object.assign( new Vector32(0, 0, -1e3).applyQuaternion(camera3.quaternion).add(camera3.position) ); }; const finalPos = position; const finalLookAt = lookAt || { x: 0, y: 0, z: 0 }; if (!transitionDuration) { setCameraPos(finalPos); setLookAt(finalLookAt); } else { const camPos = Object.assign({}, camera3.position); const camLookAt = getLookAt(); const posTweenId = Math.random().toString(36).substring(2, 15); tween[posTweenId] = new Tween(camPos).to(finalPos, transitionDuration).easing(Easing.Quadratic.Out).onUpdate(setCameraPos).onComplete(() => { tween[posTweenId] = void 0; }).start(); const lookAtTweenId = Math.random().toString(36).substring(2, 15); tween[lookAtTweenId] = new Tween(camLookAt).to(finalLookAt, transitionDuration / 3).easing(Easing.Quadratic.Out).onUpdate(setLookAt).onComplete(() => { tween[lookAtTweenId] = void 0; }).start(); } } } /** * this will force the camera to look at a specific position * @param lookAt * @param transitionDuration */ cameraLookAt(lookAt, transitionDuration) { this.cameraPosition(void 0, lookAt, transitionDuration); } removeSelection() { this.selectedNodes.clear(); this.updateColor(); } searchNode(path) { const targetNode = this.forceGraph.instance.graphData().getNodeByPath(path); if (targetNode) this.focusOnCoords(targetNode); else createNotice("The node doesn't exist in the graph"); } openFileInNewTab(file) { this.forceGraph.view.plugin.app.workspace.getLeaf(false).openFile(file); } }; // src/views/graph/ForceGraph.ts var ForceGraph2 = class { /** * * this will create a new force graph instance and render it to the view * @param view * @param config you have to provide the full config here!! */ constructor(view, _graph) { /** * given the changed things, update the instance */ this.updateInstance = (graph2, config2) => { var _a3, _b3, _c2, _d2, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s; if (graph2 !== void 0) this.instance.graphData(graph2); if (((_a3 = config2 == null ? void 0 : config2.display) == null ? void 0 : _a3.nodeSize) !== void 0) this.instance.nodeRelSize((_b3 = config2.display) == null ? void 0 : _b3.nodeSize); if (((_c2 = config2 == null ? void 0 : config2.display) == null ? void 0 : _c2.linkDistance) !== void 0) { (_e = this.instance.d3Force("link")) == null ? void 0 : _e.distance((_d2 = config2.display) == null ? void 0 : _d2.linkDistance); } if (((_f = config2 == null ? void 0 : config2.display) == null ? void 0 : _f.nodeRepulsion) !== void 0) { (_h = this.instance.d3Force("charge")) == null ? void 0 : _h.strength(-((_g = config2.display) == null ? void 0 : _g.nodeRepulsion)); this.instance.d3Force("x", x_default4(0).strength(1 - ((_i = config2.display) == null ? void 0 : _i.nodeRepulsion) / 3e3 + 1e-3)).d3Force("y", y_default3(0).strength(1 - ((_j = config2.display) == null ? void 0 : _j.nodeRepulsion) / 3e3 + 1e-3)).d3Force("z", z_default2(0).strength(1 - ((_k = config2.display) == null ? void 0 : _k.nodeRepulsion) / 3e3 + 1e-3)); } if (((_l = config2 == null ? void 0 : config2.display) == null ? void 0 : _l.showCenterCoordinates) !== void 0) { this.centerCoordinates.setVisibility(config2.display.showCenterCoordinates); } if (((_m = config2 == null ? void 0 : config2.display) == null ? void 0 : _m.dagOrientation) !== void 0) { let dagOrientation = (_o = (_n = config2 == null ? void 0 : config2.display) == null ? void 0 : _n.dagOrientation) != null ? _o : "null" /* null */; if (!this.instance.graphData().isAcyclic() && this.view.settingManager.getCurrentSetting().display.dagOrientation !== "null" /* null */) { createNotice("The graph is cyclic, dag orientation will be ignored"); dagOrientation = "null" /* null */; } const noDag = dagOrientation === "null" /* null */; this.instance.dagMode(noDag ? null : config2 == null ? void 0 : config2.display.dagOrientation).dagLevelDistance(75); } const needReheat = ((_p = config2 == null ? void 0 : config2.display) == null ? void 0 : _p.nodeRepulsion) !== void 0 || ((_q = config2 == null ? void 0 : config2.display) == null ? void 0 : _q.linkDistance) !== void 0 || ((_r = config2 == null ? void 0 : config2.display) == null ? void 0 : _r.linkThickness) !== void 0 || ((_s = config2 == null ? void 0 : config2.display) == null ? void 0 : _s.dagOrientation) !== void 0; if (needReheat) { this.instance.numDimensions(3); this.instance.refresh(); } }; var _a3; this.view = view; this.interactionManager = new ForceGraphEngine(this); const pluginSetting = this.view.plugin.settingManager.getSettings().pluginSetting; const rootHtmlElement = view.contentEl; const tooMany = _graph.nodes.length > view.plugin.settingManager.getSettings().pluginSetting.maxNodeNumber; const graph2 = _graph; if (tooMany) createNotice(`Too many nodes, there are ${_graph.nodes.length} nodes`); const divEl = this.createNodeLabel(); this.instance = _3dForceGraph({ controlType: pluginSetting.rightClickToPan ? void 0 : "orbit", extraRenderers: [ // @ts-ignore https://github.com/vasturiano/3d-force-graph/blob/522d19a831e92015ff77fb18574c6b79acfc89ba/example/html-nodes/index.html#L27C9-L29 new CSS2DRenderer({ element: divEl }) ] })(rootHtmlElement).graphData(graph2).nodeColor(this.interactionManager.getNodeColor).nodeLabel((node) => null).nodeVal((node) => { var _a4; return (node.links.length + 1) * // if the view has a currentFile, then it can be either local graph view or post processor view ("currentFile" in this.view && ((_a4 = this.view.currentFile) == null ? void 0 : _a4.path) === node.path ? 3 : 1); }).onBackgroundRightClick(() => { this.interactionManager.removeSelection(); }).nodeOpacity(0.9).linkOpacity(0.3).onNodeHover(this.interactionManager.onNodeHover).onNodeDrag(this.interactionManager.onNodeDrag).onNodeDragEnd(this.interactionManager.onNodeDragEnd).onNodeRightClick(this.interactionManager.onNodeRightClick).onNodeClick(this.interactionManager.onNodeClick).linkColor(this.interactionManager.getLinkColor).linkWidth(this.interactionManager.getLinkWidth).linkDirectionalParticles(this.interactionManager.getLinkDirectionalParticles).linkDirectionalParticleWidth(this.interactionManager.getLinkDirectionalParticleWidth).linkDirectionalArrowLength(this.interactionManager.getLinkDirectionalArrowLength).linkDirectionalArrowRelPos(1).width(rootHtmlElement.innerWidth).height(rootHtmlElement.innerHeight).d3Force("collide", collide_default(5)).backgroundColor(hexToRGBA("#000000", 0)); const scene3 = this.instance.scene(); const renderer3 = this.instance.renderer(); renderer3.domElement.addEventListener("wheel", (e) => this.interactionManager.onZoom(e)); this.centerCoordinates = new CenterCoordinates( this.view.settingManager.getCurrentSetting().display.showCenterCoordinates ); scene3.add(this.centerCoordinates.arrowsGroup); this.myCube = this.createCube(); scene3.add(this.myCube); this.instance.nodeThreeObject((node) => { const nodeEl = document.createElement("div"); const text = this.interactionManager.getNodeLabelText(node); nodeEl.textContent = text; nodeEl.style.color = node.color; nodeEl.className = "node-label"; nodeEl.style.top = "20px"; nodeEl.style.fontSize = "12px"; nodeEl.style.padding = "1px 4px"; nodeEl.style.borderRadius = "4px"; nodeEl.style.backgroundColor = rgba(0, 0, 0, 0.5); nodeEl.style.userSelect = "none"; const cssObject = new CSS2DObject(nodeEl); cssObject.onAfterRender = (renderer4, scene4, camera3) => { const value = 1 - this.interactionManager.getNodeOpacityEasedValue(node); nodeEl.style.opacity = `${this.interactionManager.getIsAnyHighlighted() && !this.interactionManager.isHighlightedNode(node) ? Math.clamp(value, 0, 0.2) : this.interactionManager.hoveredNode === node ? 1 : value}`; }; return cssObject; }).nodeThreeObjectExtend(true); this.updateConfig(this.view.settingManager.getCurrentSetting()); if (!pluginSetting.rightClickToPan) { const controls3 = this.instance.controls(); controls3.mouseButtons.RIGHT = void 0; } (_a3 = this.view.contentEl.querySelector(".scene-nav-info")) == null ? void 0 : _a3.setText( `Left-click: rotate, Mouse-wheel/middle-click: zoom, ${pluginSetting.rightClickToPan ? "Right click" : "Cmd + left click"}: pan` ); } createNodeLabel() { const divEl = document.createElement("div"); divEl.style.zIndex = "0"; this.nodeLabelEl = divEl.createDiv({ cls: "node-label", text: "" }); this.nodeLabelEl.style.opacity = "0"; return divEl; } createCube() { const myCube = new Mesh2( new BoxGeometry2(30, 30, 30), new MeshBasicMaterial2({ color: 16711680 }) ); myCube.position.set(0, 0, -FOCAL_FROM_CAMERA); const oldOnBeforeRender = this.instance.scene().onBeforeRender; this.instance.scene().onBeforeRender = (renderer3, scene3, camera3, geometry, material, group) => { oldOnBeforeRender(renderer3, scene3, camera3, geometry, material, group); const cwd = new Vector32(); camera3.getWorldDirection(cwd); cwd.multiplyScalar(FOCAL_FROM_CAMERA); cwd.add(camera3.position); myCube.position.set(cwd.x, cwd.y, cwd.z); myCube.setRotationFromQuaternion(camera3.quaternion); }; myCube.visible = false; return myCube; } /** * update the dimensions of the graph */ updateDimensions(dimension) { if (dimension) this.instance.width(dimension[0]).height(dimension[1]); else { const rootHtmlElement = this.view.contentEl; const [width, height] = [rootHtmlElement.offsetWidth, rootHtmlElement.offsetHeight]; this.instance.width(width).height(height); } } updateConfig(config2) { this.updateInstance(void 0, config2); } /** * given a new force Graph, the update the graph and the instance */ updateGraph(graph2) { const same = Graph.compare(this.instance.graphData(), graph2); if (!same) this.updateInstance(graph2, void 0); else console.log("same graph, no need to update"); } }; // src/views/atomics/TreeItem.ts var TreeItem = class { constructor($inner, children) { this.$inner = $inner; this.childrenBuilders = children; this.$treeItem = document.createElement("div"); this.toggleCollapse(true); this.$self = document.createElement("div"); this.$innerWrapper = document.createElement("div"); } async render(containerEl) { this.$treeItem.classList.add("graph-control-section", "tree-item"); this.$self.classList.add("tree-item-self"); this.$self.addEventListener("click", () => { this.toggleCollapse(); }); this.$innerWrapper.classList.add("tree-item-inner"); this.$innerWrapper.appendChild(this.$inner); this.$self.appendChild(this.$innerWrapper); this.$treeItem.appendChild(this.$self); containerEl.appendChild(this.$treeItem); await this.renderChildren(); } async renderChildren() { const $children = document.createElement("div"); $children.classList.add("tree-item-children"); this.$treeItem.appendChild($children); const promises = this.childrenBuilders.map((build) => build($children)); await Promise.all(promises); } toggleCollapse(doCollapse) { if (doCollapse === void 0) { doCollapse = !this.$treeItem.classList.contains("is-collapsed"); } this.$treeItem.classList.toggle("is-collapsed", doCollapse); } }; // src/views/settings/GraphSettingsManager.ts var import_obsidian17 = require("obsidian"); // src/views/settings/categories/UtilitySettingsView.ts var import_obsidian5 = require("obsidian"); // src/views/settings/categories/getMySwitcher.ts var getMySwitcher = (view) => { const switcherInstance = view.plugin.app.internalPlugins.plugins.switcher.instance; const QuickSwitcherModal = switcherInstance == null ? void 0 : switcherInstance.QuickSwitcherModal; if (!QuickSwitcherModal) return; const MySwitcher = class extends QuickSwitcherModal { constructor(app2, plugin) { super(app2, switcherInstance.options); this.plugin = plugin; } async getSuggestions(query) { var _a3; const suggestions = await super.getSuggestions(query); const allFilePaths = (_a3 = view.getForceGraph()) == null ? void 0 : _a3.instance.graphData().nodes.map((n) => n.path); return suggestions.filter(Boolean).filter((s) => { return s.file ? allFilePaths == null ? void 0 : allFilePaths.includes(s.file.path) : false; }); } // @ts-ignore onChooseSuggestion(item, evt) { var _a3; (_a3 = view.getForceGraph()) == null ? void 0 : _a3.interactionManager.searchNode(item.file.path); } }; return MySwitcher; }; // src/views/settings/categories/UtilitySettingsView.ts var UtilitySettingsView = async (containerEl, view) => { const plugin = view.plugin; const div = containerEl.createDiv(); div.style.display = "flex"; div.style.flexDirection = "column"; div.style.gap = "4px"; new import_obsidian5.ButtonComponent(div).setButtonText("Search").onClick(() => { const MySwitcher = getMySwitcher(view); if (MySwitcher === void 0) return; const modal = new MySwitcher(plugin.app, plugin); modal.open(); }); new import_obsidian5.ButtonComponent(div).setButtonText("Look at center").onClick(() => { var _a3; (_a3 = view.getForceGraph()) == null ? void 0 : _a3.interactionManager.cameraLookAtCenter(); }); new import_obsidian5.ButtonComponent(div).setButtonText("Remove selection").onClick(() => { var _a3; (_a3 = view.getForceGraph()) == null ? void 0 : _a3.interactionManager.removeSelection(); }); }; // src/util/generateUUID.ts function generateUUID3() { let d = new Date().getTime(); if (typeof performance !== "undefined" && typeof performance.now === "function") { d += performance.now(); } const uuid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c2) { const r = (d + Math.random() * 16) % 16 | 0; d = Math.floor(d / 16); return (c2 === "x" ? r : r & 3 | 8).toString(16); }); return uuid; } // src/views/settings/categories/SaveSettingGroupItem.ts var import_obsidian6 = require("obsidian"); var addSaveSettingGroupItem = (containerEl, savedSetting, view) => { const innerEl = containerEl.createDiv({ attr: { style: "display: flex; flex-direction: row; justify-content: space-between; align-items: center;" } }); const nameSetting = new import_obsidian6.TextComponent(innerEl); nameSetting.setValue(savedSetting.title).onChange(async (value) => { view.plugin.settingManager.updateSettings((settings) => { const setting = settings.value.savedSettings.find( (setting2) => setting2.id === savedSetting.id ); if (setting) { setting.title = value; } return settings; }); }); const checkButton = new import_obsidian6.ExtraButtonComponent(innerEl); checkButton.setIcon("undo-2").setTooltip("Apply").onClick(async () => { view.settingManager.applySettings(savedSetting.setting); }); const updateButton = new import_obsidian6.ExtraButtonComponent(innerEl); updateButton.setIcon("pencil").setTooltip("Update").onClick(async () => { if (confirm(`Are you sure you want to update: ${savedSetting.title}?`)) { createNotice(`Updating saved settings ${savedSetting.title}`); view.plugin.settingManager.updateSettings((settings) => { const targetSavedSetting = settings.value.savedSettings.find( (setting) => setting.id === savedSetting.id ); if (targetSavedSetting) targetSavedSetting.setting = view.settingManager.getCurrentSetting(); }); } }); const trashButton = new import_obsidian6.ExtraButtonComponent(innerEl); trashButton.setIcon("trash").setTooltip("Delete").onClick(async () => { if (confirm(`Are you sure you want to delete: ${savedSetting.title}?`)) { innerEl.remove(); view.plugin.settingManager.updateSettings((settings) => { settings.value.savedSettings = settings.value.savedSettings.filter( (setting) => setting.id !== savedSetting.id ); }); } }); trashButton.extraSettingsEl.style.color = "red"; }; // src/views/settings/categories/SavedSettingsView.ts var import_obsidian7 = require("obsidian"); var SavedSettingsView = (containerEl, view) => { const div = containerEl.createDiv({ cls: "saved-settings-view", attr: { style: "display: flex; flex-direction: column; gap: 4px;" } }); view.plugin.settingManager.getSettings().savedSettings.filter((setting) => setting.type === view.graphType).forEach((setting) => { addSaveSettingGroupItem(div, setting, view); }); const _button = new import_obsidian7.Setting(div).addButton((button) => { button.setButtonText("Save current settings").onClick(async () => { const newSetting = { id: generateUUID3(), title: "New", setting: view.settingManager.getCurrentSetting(), type: view.graphType }; addSaveSettingGroupItem(div, newSetting, view); div.append(_button.settingEl); view.plugin.settingManager.updateSettings((settings) => { settings.value.savedSettings.push(newSetting); }); }); }); }; // src/views/settings/categories/FilterSettingsView.ts var import_obsidian10 = require("obsidian"); // src/views/leafView.ts var import_obsidian8 = require("obsidian"); var PREFIX = "graph-3d"; var popovers = /* @__PURE__ */ new WeakMap(); function genId(size) { const chars = []; for (let n = 0; n < size; n++) chars.push((16 * Math.random() | 0).toString(16)); return chars.join(""); } function nosuper(base) { const derived = function() { return Object.setPrototypeOf(new import_obsidian8.Component(), new.target.prototype); }; derived.prototype = base.prototype; return Object.setPrototypeOf(derived, base); } var spawnLeafView = (plugin, initiatingEl, leaf, onShowCallback, props) => { let parent = app.workspace.activeLeaf; if (!parent) parent = leaf; if (!initiatingEl) initiatingEl = parent == null ? void 0 : parent.containerEl; const hoverPopover = new EmbeddedView( parent, initiatingEl, plugin, void 0, onShowCallback, props ); return [hoverPopover.attachLeaf(), hoverPopover]; }; var _a2, _b2, _c, _d; var EmbeddedView = class extends nosuper(import_obsidian8.HoverPopover) { constructor(parent, targetEl, plugin, waitTime, onShowCallback, props) { super(); this.targetEl = targetEl; this.plugin = plugin; this.onShowCallback = onShowCallback; this.abortController = this.addChild(new import_obsidian8.Component()); this.detaching = false; this.opening = false; this.rootSplit = new import_obsidian8.WorkspaceSplit( window.app.workspace, "vertical" ); this.isPinned = true; // It is currently not useful. // leafInHoverEl: WorkspaceLeaf; this.oldPopover = (_a2 = this.parent) == null ? void 0 : _a2.hoverPopover; this.document = (_d = (_c = (_b2 = this.targetEl) == null ? void 0 : _b2.ownerDocument) != null ? _c : window.activeDocument) != null ? _d : window.document; this.id = genId(8); this.hoverEl = this.document.defaultView.createDiv({ cls: `${PREFIX}-block ${PREFIX}-leaf-view`, attr: { id: `${PREFIX}-` + this.id } }); if (waitTime === void 0) { waitTime = 300; } this.onTarget = true; this.parent = parent; this.waitTime = waitTime; this.state = import_obsidian8.PopoverState.Showing; this.abortController.load(); this.show(); this.onShow(); this.setActive = this._setActive.bind(this); popovers.set(this.hoverEl, this); if (props == null ? void 0 : props.hoverElClasses) { this.hoverEl.addClass(...props.hoverElClasses); } this.containerEl = this.hoverEl.createDiv({ cls: props == null ? void 0 : props.containerElClasses }); this.buildWindowControls(); this.setInitialDimensions(); } static activeWindows() { const windows = [window]; const { floatingSplit } = app.workspace; if (floatingSplit) { for (const split of floatingSplit.children) { if (split.win) windows.push(split.win); } } return windows; } static containerForDocument(doc) { if (doc !== document && app.workspace.floatingSplit) for (const container of app.workspace.floatingSplit.children) { if (container.doc === doc) return container; } return app.workspace.rootSplit; } static activePopovers() { return this.activeWindows().flatMap(this.popoversForWindow); } static popoversForWindow(win) { var _a3, _b3; return Array.prototype.slice.call( (_b3 = (_a3 = win == null ? void 0 : win.document) == null ? void 0 : _a3.body.querySelectorAll(`.${PREFIX}-leaf-view`)) != null ? _b3 : [] ).map((el) => popovers.get(el)).filter((he) => he); } static forLeaf(leaf) { const el = leaf && document.body.matchParent.call(leaf.containerEl, `.${PREFIX}-leaf-view`); return el ? popovers.get(el) : void 0; } static iteratePopoverLeaves(ws, cb) { for (const popover of this.activePopovers()) { if (popover.rootSplit && ws.iterateLeaves(cb, popover.rootSplit)) return true; } return false; } _setActive(evt) { evt.preventDefault(); evt.stopPropagation(); this.plugin.app.workspace.setActiveLeaf(this.leaves()[0], { focus: true }); } getDefaultMode() { return "source"; } updateLeaves() { if (this.onTarget && this.targetEl && !this.document.contains(this.targetEl)) { this.onTarget = false; this.transition(); } let leafCount = 0; this.plugin.app.workspace.iterateLeaves((leaf) => { leafCount++; }, this.rootSplit); if (leafCount === 0) { this.hide(); } this.hoverEl.setAttribute("data-leaf-count", leafCount.toString()); } leaves() { const leaves = []; this.plugin.app.workspace.iterateLeaves((leaf) => { leaves.push(leaf); }, this.rootSplit); return leaves; } setInitialDimensions() { this.hoverEl.style.height = "auto"; this.hoverEl.style.width = "100%"; } transition() { if (this.shouldShow()) { if (this.state === import_obsidian8.PopoverState.Hiding) { this.state = import_obsidian8.PopoverState.Shown; clearTimeout(this.timer); } } else { if (this.state === import_obsidian8.PopoverState.Showing) { this.hide(); } else { if (this.state === import_obsidian8.PopoverState.Shown) { this.state = import_obsidian8.PopoverState.Hiding; this.timer = window.setTimeout(() => { if (this.shouldShow()) { this.transition(); } else { this.hide(); } }, this.waitTime); } } } } buildWindowControls() { this.titleEl = this.document.defaultView.createDiv("popover-titlebar"); this.titleEl.createDiv("popover-title"); this.containerEl.prepend(this.titleEl); } attachLeaf() { this.rootSplit.getRoot = () => this.plugin.app.workspace[this.document === document ? "rootSplit" : "floatingSplit"]; this.rootSplit.getContainer = () => EmbeddedView.containerForDocument(this.document); this.titleEl.insertAdjacentElement("afterend", this.rootSplit.containerEl); const leaf = this.plugin.app.workspace.createLeafInParent(this.rootSplit, 0); this.updateLeaves(); return leaf; } onload() { super.onload(); this.registerEvent(this.plugin.app.workspace.on("layout-change", this.updateLeaves, this)); this.registerEvent( app.workspace.on("layout-change", () => { this.rootSplit.children.forEach((item, index6) => { if (item instanceof import_obsidian8.WorkspaceTabs) { this.rootSplit.replaceChild(index6, item.children[0]); } }); }) ); } onShow() { var _a3, _b3; const closeDelay = 600; setTimeout(() => this.waitTime = closeDelay, closeDelay); (_a3 = this.oldPopover) == null ? void 0 : _a3.hide(); this.oldPopover = null; this.hoverEl.toggleClass("is-new", true); this.document.body.addEventListener( "click", () => { this.hoverEl.toggleClass("is-new", false); }, { once: true, capture: true } ); if (this.parent) { this.parent.hoverPopover = this; } const viewHeaderEl = this.hoverEl.querySelector(".view-header"); viewHeaderEl == null ? void 0 : viewHeaderEl.remove(); const sizer = this.hoverEl.querySelector(".workspace-leaf"); if (sizer) this.hoverEl.appendChild(sizer); const inlineTitle = this.hoverEl.querySelector(".inline-title"); if (inlineTitle) inlineTitle.remove(); (_b3 = this.onShowCallback) == null ? void 0 : _b3.call(this); this.onShowCallback = void 0; } detect(el) { const { targetEl } = this; if (targetEl) { this.onTarget = el === targetEl || targetEl.contains(el); } } shouldShow() { return this.shouldShowSelf() || this.shouldShowChild(); } shouldShowChild() { return EmbeddedView.activePopovers().some((popover) => { if (popover !== this && popover.targetEl && this.hoverEl.contains(popover.targetEl)) { return popover.shouldShow(); } return false; }); } shouldShowSelf() { return !this.detaching && !!(this.onTarget || this.state == import_obsidian8.PopoverState.Shown || this.document.querySelector( `body>.modal-container, body > #he${this.id} ~ .menu, body > #he${this.id} ~ .suggestion-container` )); } show() { this.state = import_obsidian8.PopoverState.Shown; this.timer = 0; this.targetEl.appendChild(this.hoverEl); this.onShow(); app.workspace.onLayoutChange(); this.load(); if (this.hoverEl.dataset.imgHeight && this.hoverEl.dataset.imgWidth) { this.hoverEl.style.height = parseFloat(this.hoverEl.dataset.imgHeight) + this.titleEl.offsetHeight + "px"; this.hoverEl.style.width = parseFloat(this.hoverEl.dataset.imgWidth) + "px"; } } onHide() { var _a3; this.oldPopover = null; if (((_a3 = this.parent) == null ? void 0 : _a3.hoverPopover) === this) { this.parent.hoverPopover = null; } } hide() { var _a3; this.onTarget = false; this.detaching = true; if (this.timer) { clearTimeout(this.timer); this.timer = 0; } this.hoverEl.hide(); if (this.opening) return; const leaves = this.leaves(); if (leaves.length) { this.targetEl.empty(); } else { this.parent = null; (_a3 = this.abortController) == null ? void 0 : _a3.unload(); this.abortController = void 0; return this.nativeHide(); } } nativeHide() { var _a3; const { hoverEl, targetEl } = this; this.state = import_obsidian8.PopoverState.Hidden; hoverEl.detach(); if (targetEl) { const parent = targetEl.matchParent(`.${PREFIX}-leaf-view`); if (parent) (_a3 = popovers.get(parent)) == null ? void 0 : _a3.transition(); } this.onHide(); this.unload(); } resolveLink(linkText, sourcePath) { const link = (0, import_obsidian8.parseLinktext)(linkText); const tFile = link ? this.plugin.app.metadataCache.getFirstLinkpathDest(link.path, sourcePath) : null; return tFile; } async openLink(linkText, sourcePath, eState, createInLeaf) { var _a3, _b3, _c2; let file = this.resolveLink(linkText, sourcePath); const link = (0, import_obsidian8.parseLinktext)(linkText); if (!file && createInLeaf) { const folder = this.plugin.app.fileManager.getNewFileParent(sourcePath); file = await this.plugin.app.fileManager.createNewMarkdownFile(folder, link.path); } if (!file) { return; } const { viewRegistry } = this.plugin.app; const viewType = viewRegistry.typeByExtension[file.extension]; if (!viewType || !viewRegistry.viewByType[viewType]) { return; } eState = Object.assign(this.buildEphemeralState(file, link), eState); const parentMode = this.getDefaultMode(); const state = this.buildState(parentMode, eState); const leaf = await this.openFile(file, state, createInLeaf); const leafViewType = (_a3 = leaf == null ? void 0 : leaf.view) == null ? void 0 : _a3.getViewType(); if (leafViewType === "image") { if (((_b3 = this.parent) == null ? void 0 : _b3.hasOwnProperty("editorEl")) && this.parent.editorEl.hasClass("is-live-preview")) { this.waitTime = 3e3; } const img = leaf.view.contentEl.querySelector("img"); this.hoverEl.dataset.imgHeight = String(img.naturalHeight); this.hoverEl.dataset.imgWidth = String(img.naturalWidth); this.hoverEl.dataset.imgRatio = String(img.naturalWidth / img.naturalHeight); } else if (leafViewType === "pdf") { this.hoverEl.style.height = "800px"; this.hoverEl.style.width = "600px"; } if (((_c2 = state.state) == null ? void 0 : _c2.mode) === "source") { this.whenShown(() => { var _a4, _b4, _c3, _d2; if ((0, import_obsidian8.requireApiVersion)("1.0")) (_c3 = (_b4 = (_a4 = leaf == null ? void 0 : leaf.view) == null ? void 0 : _a4.editMode) == null ? void 0 : _b4.reinit) == null ? void 0 : _c3.call(_b4); (_d2 = leaf == null ? void 0 : leaf.view) == null ? void 0 : _d2.setEphemeralState(state.eState); }); } } whenShown(callback) { if (this.detaching) return; const existingCallback = this.onShowCallback; this.onShowCallback = () => { if (this.detaching) return; callback(); if (typeof existingCallback === "function") existingCallback(); }; if (this.state === import_obsidian8.PopoverState.Shown) { this.onShowCallback(); this.onShowCallback = void 0; } } async openFile(file, openState, useLeaf) { if (this.detaching) return; const leaf = useLeaf != null ? useLeaf : this.attachLeaf(); this.opening = true; try { await leaf.openFile(file, openState); } catch (e) { console.error(e); } finally { this.opening = false; if (this.detaching) this.hide(); } this.plugin.app.workspace.setActiveLeaf(leaf); return leaf; } buildState(parentMode, eState) { return { active: false, // Don't let Obsidian force focus if we have autofocus off state: { mode: "source" }, // Don't set any state for the view, because this leaf is stayed on another view. eState }; } buildEphemeralState(file, link) { const cache = this.plugin.app.metadataCache.getFileCache(file); const subpath = cache ? (0, import_obsidian8.resolveSubpath)(cache, (link == null ? void 0 : link.subpath) || "") : void 0; const eState = { subpath: link == null ? void 0 : link.subpath }; if (subpath) { eState.line = subpath.start.line; eState.startLoc = subpath.start; eState.endLoc = subpath.end || void 0; } return eState; } }; // src/views/atomics/addSearchInput.ts var import_obsidian9 = require("obsidian"); var addSearchInput = async (containerEl, value, onChange13, view) => { var _a3; const searchEl = containerEl.createDiv({ // cls : }); if (!view.plugin.fileManager.searchEngine.useBuiltInSearchInput) { const text = new import_obsidian9.TextComponent(searchEl).setValue(value).onChange((value2) => { onChange13(value2); }); (_a3 = text.inputEl.parentElement) == null ? void 0 : _a3.addClasses([ "search-input-container", "global-search-input-container" ]); return; } const [searchLeaf] = spawnLeafView(view.plugin, searchEl); await searchLeaf.setViewState({ type: "search" }); containerEl.appendChild(searchEl); const searchElement = searchLeaf.containerEl.querySelector( ".workspace-leaf-content[data-type='search']" ); const searchRowEl = searchElement.querySelector(".search-row"); const searchResultContainerEl = searchElement.querySelector( ".search-result-container" ); const searchResultInfoEl = searchElement.querySelector(".search-results-info"); const extraSettingButtonEl = searchRowEl.querySelector( ".setting-editor-extra-setting-button" ); extraSettingButtonEl == null ? void 0 : extraSettingButtonEl.remove(); searchResultContainerEl.style.visibility = "hidden"; searchResultContainerEl.style.height = "0px"; searchResultContainerEl.style.position = "absolute"; searchResultInfoEl.style.visibility = "hidden"; searchResultInfoEl.style.height = "0px"; searchResultInfoEl.style.position = "absolute"; searchRowEl.style.margin = "0px"; containerEl.appendChild(searchRowEl); const inputEl = searchRowEl.getElementsByTagName("input")[0]; const settingIconEl = searchRowEl.querySelector( ".clickable-icon[aria-label='Search settings']" ); const matchCaseIconEl = searchRowEl.querySelector( "div.search-input-container > div[aria-label='Match case'] " ); const clearButtonEl = searchRowEl.querySelector(".search-input-clear-button"); settingIconEl == null ? void 0 : settingIconEl.remove(); matchCaseIconEl == null ? void 0 : matchCaseIconEl.remove(); inputEl.value = value; inputEl.oninput = async (e) => { var _a4; onChange13((_a4 = e.currentTarget) == null ? void 0 : _a4.value); }; clearButtonEl.onclick = () => { onChange13(""); }; if (view.itemView) view.itemView.containerEl.appendChild(searchResultContainerEl); const addMutationObserver = (callback, data) => { if (view.plugin.fileManager.searchEngine instanceof IActiveSearchEngine) throw new Error( "you don't need mutation observer for active search engine, this function should not be called" ); view.plugin.fileManager.searchEngine.addMutationObserver( searchResultContainerEl, searchLeaf.view, callback, data ); }; const triggerSearch = () => { if (inputEl.value === "") return; inputEl.dispatchEvent( new KeyboardEvent("keypress", { key: "Enter" }) ); }; return { searchRowEl, addMutationObserver, triggerSearch }; }; // src/views/settings/categories/FilterSettingsView.ts var FilterSettingsView = async (filterSettings, containerEl, settingManager) => { const graphView = settingManager.getGraphView(); const searchInput = await addSearchInput( containerEl, filterSettings.searchQuery, (value) => { settingManager.updateCurrentSettings((setting) => { setting.value.filter.searchQuery = value; }); }, graphView ); if (searchInput && settingManager.getGraphView().plugin.fileManager.searchEngine instanceof DefaultSearchEngine) searchInput.addMutationObserver((files) => { settingManager.searchResult.value.filter.files = files.map((file) => ({ name: file.name, path: file.path })); }); new import_obsidian10.Setting(containerEl).setName("Show attachments").addToggle((toggle) => { toggle.setValue(filterSettings.showAttachments || false).onChange(async (value) => { settingManager.updateCurrentSettings((setting) => { setting.value.filter.showAttachments = value; }); }); }); new import_obsidian10.Setting(containerEl).setName("Show orphans").addToggle((toggle) => { toggle.setValue(filterSettings.showOrphans || false).onChange(async (value) => { settingManager.updateCurrentSettings((setting) => { setting.value.filter.showOrphans = value; }); }); }); if (graphView.graphType === "local" /* local */) { const localFilterSettings = filterSettings; let latestValue = localFilterSettings.depth; let activeCallId = 0; new import_obsidian10.Setting(containerEl).setName("Depth").addSlider((slider) => { slider.setLimits(1, 5, 1).setValue(localFilterSettings.depth).setDynamicTooltip().onChange((value) => { latestValue = value; const currentCallId = ++activeCallId; waitForStable(() => latestValue, { timeout: 3e3, // wait for a max of 3 seconds for stability minDelay: 300, // start checking after 300ms interval: 100, // check every 100ms rehitCount: 3 // require 3 consecutive checks with the same value }).then((stableValue) => { if (stableValue !== void 0 && currentCallId === activeCallId) { settingManager.updateCurrentSettings((setting) => { setting.value.filter.depth = stableValue; }); } }); }); }); new import_obsidian10.Setting(containerEl).setName("Show Incoming Links").addDropdown((dropdown) => { dropdown.addOptions({ both: "Both", inlinks: "Inlinks", outlinks: "Outlinks" }).setValue(localFilterSettings.linkType).onChange(async (value) => { settingManager.updateCurrentSettings((setting) => { setting.value.filter.linkType = value; }); }); }); } const triggerSearch = async () => { searchInput == null ? void 0 : searchInput.triggerSearch(); }; return { searchInput, triggerSearch }; }; // src/views/settings/categories/AddGroupSettingItem.ts var import_obsidian11 = require("obsidian"); // src/views/atomics/addColorPicker.ts var addColorPicker = (containerEl, value, onChange13) => { const input = document.createElement("input"); input.type = "color"; input.value = value; input.addEventListener("input", () => { onChange13(input.value); }); containerEl.appendChild(input); }; // src/views/settings/categories/AddGroupSettingItem.ts var AddNodeGroupItem = async (newGroup, containerEl, view, index6, searchInputs) => { const groupEl = containerEl.createDiv({ cls: "graph-color-group" }); const searchInput = await addSearchInput( groupEl, newGroup.query, (value) => { view.settingManager.updateCurrentSettings((setting) => { setting.value.groups[index6].query = value; }); }, view ); if (searchInput && view.plugin.fileManager.searchEngine instanceof DefaultSearchEngine) { searchInput.addMutationObserver((files) => { if (view.settingManager.searchResult.value.groups[index6] === void 0) view.settingManager.searchResult.value.groups[index6] = { files: [] }; view.settingManager.searchResult.value.groups[index6].files = files.map((file) => ({ name: file.name, path: file.path })); }, `Group ${index6}`); } searchInputs.push(searchInput); addColorPicker(groupEl, newGroup.color, (value) => { view.settingManager.updateCurrentSettings((setting) => { setting.value.groups[index6].color = value; }); }); new import_obsidian11.ExtraButtonComponent(groupEl).setIcon("cross").setTooltip("Delete Group").onClick(() => { groupEl.remove(); view.settingManager.updateCurrentSettings((setting) => { setting.value.groups.splice(index6, 1); }); view.settingManager.searchResult.value.groups.splice(index6, 1); searchInputs.splice(index6, 1); }); return { searchInput }; }; // src/views/settings/categories/addNodeGroups.ts var addNodeGroups = async (groupSettings, containerEl, view, nodeGroups) => { var _a3; (_a3 = containerEl.querySelector(".node-group-container")) == null ? void 0 : _a3.remove(); const nodeGroupContainerEl = containerEl.createDiv({ cls: "graph-color-groups-container" }); groupSettings.forEach(async (group, index6) => { await AddNodeGroupItem(group, nodeGroupContainerEl, view, index6, nodeGroups); }); }; // src/views/settings/categories/AddNodeGroupButton.ts var import_obsidian12 = require("obsidian"); var getRandomColor = () => { return "#" + Math.floor(Math.random() * 16777215).toString(16); }; var addNodeGroupButton = (containerEl, view, searchInputs) => { var _a3; (_a3 = containerEl.querySelector(".graph-color-button-container")) == null ? void 0 : _a3.remove(); const buttonContainerEl = containerEl.createDiv({ cls: "graph-color-button-container" }); const nodeGroupButton = { groupItems: [] }; new import_obsidian12.ButtonComponent(buttonContainerEl).setClass("mod-cta").setButtonText("Add Group").onClick(async () => { const newGroup = { query: "", color: getRandomColor() }; view.settingManager.updateCurrentSettings((setting) => { setting.value.groups.push(newGroup); }); const index6 = view.settingManager.getCurrentSetting().groups.length - 1; view.settingManager.searchResult.value.groups[index6] = { files: [] }; await AddNodeGroupItem(newGroup, containerEl, view, index6, searchInputs); containerEl.append(buttonContainerEl); }); return nodeGroupButton; }; // src/views/settings/categories/GroupSettingsView.ts var GroupSettingsView = async (groupSettings, containerEl, view) => { const searchInputs = []; await addNodeGroups(groupSettings, containerEl, view, searchInputs); addNodeGroupButton(containerEl, view, searchInputs); const triggerSearch = () => { searchInputs.forEach((nodeGroup) => { nodeGroup == null ? void 0 : nodeGroup.triggerSearch(); }); }; return { searchInputs, triggerSearch }; }; // src/views/atomics/addSimpleSliderSetting.ts var import_obsidian13 = require("obsidian"); var addSimpleSliderSetting = (containerEl, options, onChange13) => { const slider = new import_obsidian13.Setting(containerEl).setName(options.name).setClass("mod-slider").addSlider((slider2) => { return slider2.setLimits(options.stepOptions.min, options.stepOptions.max, options.stepOptions.step).setValue(options.value).setDynamicTooltip().onChange(async (value) => { onChange13(value); }); }); return slider; }; // src/views/atomics/addColorPickerSetting.ts var import_obsidian14 = require("obsidian"); var addColorPickerSetting = (containerEl, options, onChange13) => { const setting = new import_obsidian14.Setting(containerEl).setName(options.name).setClass("mod-color-picker"); addColorPicker(setting.settingEl, options.value, (value) => onChange13(value)); }; // src/views/atomics/addToggle.ts var import_obsidian15 = require("obsidian"); var addToggle = (containerEl, options, onChange13) => { const settings = new import_obsidian15.Setting(containerEl).setName(options.name).addToggle((toggle) => { return toggle.setValue(options.value).onChange(async (value) => { onChange13(value); }); }); return settings; }; // src/views/settings/categories/DisplaySettingsView.ts var import_obsidian16 = require("obsidian"); var DisplaySettingsView = (graphSetting, containerEl, settingManager) => { var _a3; const displaySettings = graphSetting.display; addSimpleSliderSetting( containerEl, { name: "Node size", value: displaySettings.nodeSize, stepOptions: nodeSize }, (value) => { settingManager.updateCurrentSettings((setting) => { setting.value.display.nodeSize = value; }); } ); addSimpleSliderSetting( containerEl, { name: "Link thickness", value: displaySettings.linkThickness, stepOptions: linkThickness }, (value) => { settingManager.updateCurrentSettings((setting) => { setting.value.display.linkThickness = value; }); } ); addSimpleSliderSetting( containerEl, { name: "Link distance", value: displaySettings.linkDistance, stepOptions: linkDistance }, (value) => { settingManager.updateCurrentSettings((setting) => { setting.value.display.linkDistance = value; }); } ); addSimpleSliderSetting( containerEl, { name: "Node repulsion", value: displaySettings.nodeRepulsion, stepOptions: nodeRepulsion }, (value) => { settingManager.updateCurrentSettings((setting) => { setting.value.display.nodeRepulsion = value; }); } ); addSimpleSliderSetting( containerEl, { name: "Distance from focal", value: displaySettings.distanceFromFocal, stepOptions: distanceFromFocal }, (value) => { settingManager.updateCurrentSettings((setting) => { setting.value.display.distanceFromFocal = value; }); } ); addColorPickerSetting( containerEl, { name: "Node hover color", value: displaySettings.nodeHoverColor }, (value) => { settingManager.updateCurrentSettings((setting) => { setting.value.display.nodeHoverColor = value; }); } ); addColorPickerSetting( containerEl, { name: "Node hover neighbour color", value: displaySettings.nodeHoverNeighbourColor }, (value) => { settingManager.updateCurrentSettings((setting) => { setting.value.display.nodeHoverNeighbourColor = value; }); } ); addColorPickerSetting( containerEl, { name: "Link hover color", value: displaySettings.linkHoverColor }, (value) => { settingManager.updateCurrentSettings((setting) => { setting.value.display.linkHoverColor = value; }); } ); addToggle( containerEl, { name: "Show file extension", value: displaySettings.showExtension }, (value) => { settingManager.updateCurrentSettings((setting) => { setting.value.display.showExtension = value; }); } ); addToggle( containerEl, { name: "Show note full path", value: displaySettings.showFullPath }, (value) => { settingManager.updateCurrentSettings((setting) => { setting.value.display.showFullPath = value; }); } ); addToggle( containerEl, { name: "Show center coordinates", value: displaySettings.showCenterCoordinates }, (value) => { settingManager.updateCurrentSettings((setting) => { setting.value.display.showCenterCoordinates = value; }); } ); addToggle( containerEl, { name: "Show link arrow", value: displaySettings.showLinkArrow }, (value) => { settingManager.updateCurrentSettings((setting) => { setting.value.display.showLinkArrow = value; }); } ); addToggle( containerEl, { name: "Don't move when drag", value: displaySettings.dontMoveWhenDrag }, (value) => { settingManager.updateCurrentSettings((setting) => { setting.value.display.dontMoveWhenDrag = value; }); } ); const localDisplaySettings = displaySettings; const dagDropDown = new import_obsidian16.Setting(containerEl).setName("Dag orientation"); const dropdown = new import_obsidian16.DropdownComponent(dagDropDown.settingEl).addOptions(DagOrientation).setValue((_a3 = localDisplaySettings.dagOrientation) != null ? _a3 : "null" /* null */).onChange(async (value) => { settingManager.updateCurrentSettings((setting) => { if (!settingManager.getGraphView().getForceGraph().instance.graphData().isAcyclic() && value !== "null" /* null */) { createNotice("The graph is cyclic, dag orientation will be ignored"); } else { setting.value.display.dagOrientation = value; } }); }); const hideDagOrientationSetting = () => { dagDropDown.settingEl.hide(); settingManager.updateCurrentSettings((setting) => { setting.value.display.dagOrientation = "null" /* null */; }); dropdown.setValue("null" /* null */); }; const showDagOrientationSetting = () => { dagDropDown.settingEl.show(); settingManager.updateCurrentSettings((setting) => { setting.value.display.dagOrientation = "null" /* null */; }); dropdown.setValue("null" /* null */); }; const isDropdownHidden = () => { return dagDropDown.settingEl.style.display === "none"; }; return { hideDagOrientationSetting, showDagOrientationSetting, isDropdownHidden }; }; // src/views/settings/GraphSettingsManager.ts var GraphSettingManager = class { constructor(parentView) { this.settingChanges = []; this.searchResult = new State({ filter: { files: [] }, groups: [] }); this.searchResultChanges = []; this.asyncQueue = new AsyncQueue(); this.onSettingsButtonClicked = () => { this.toggleCollapsed(false); }; this.graphView = parentView; this.containerEl = document.createElement("div"); this.containerEl.classList.add("graph-settings-view"); const pluginSetting = this.graphView.plugin.settingManager.getSettings(); this.currentSetting = new State( this.graphView.graphType === "local" /* local */ ? pluginSetting.temporaryLocalGraphSetting : pluginSetting.temporaryGlobalGraphSetting ); this.settingsButton = new import_obsidian17.ExtraButtonComponent(this.containerEl).setIcon("settings").setTooltip("Open graph settings").onClick(this.onSettingsButtonClicked); this.graphView.contentEl.appendChild(this.containerEl); this.initNewView(true); this.currentSetting.onChange( (change) => this.settingChanges.push(change) ); this.searchResult.onChange((change) => { this.searchResultChanges.push(change); if (change.currentPath === "filter.files") { this.graphView.handleSearchResultChange(); } else if (change.currentPath.startsWith("groups")) { this.graphView.handleGroupColorSearchResultChange(); } }); } initNewView(collapsed = false) { var _a3; (_a3 = this.graphControlsEl) == null ? void 0 : _a3.remove(); this.graphView.itemView.containerEl.querySelectorAll(".search-result-container").forEach((el) => el.remove()); this.graphControlsEl = document.createElement("div"); this.graphControlsEl.classList.add("graph-controls"); this.containerEl.appendChild(this.graphControlsEl); this.appendGraphControlsItems(this.graphControlsEl.createDiv({ cls: "control-buttons" })); this.appendSettingGroup( this.graphControlsEl, this.currentSetting.value.filter, "Filters", async (...args) => { this.filterSettingView = await FilterSettingsView(...args, this); return this.filterSettingView; } ); this.appendSettingGroup( this.graphControlsEl, this.currentSetting.value.groups, "Groups", async (...args) => { this.groupSettingView = await GroupSettingsView(...args, this.graphView); return this.groupSettingView; } ); this.appendSettingGroup( this.graphControlsEl, this.currentSetting.value, "Display", (...args) => { this.displaySettingView = DisplaySettingsView(...args, this); return this.displaySettingView; } ); this.appendSettingGroup( this.graphControlsEl, void 0, "Utils", (_, containerEl) => UtilitySettingsView(containerEl, this.graphView) ); this.appendSettingGroup( this.graphControlsEl, void 0, "Saved settings", (_, containerEl) => SavedSettingsView(containerEl, this.graphView) ); this.toggleCollapsed(collapsed); waitFor(() => { return this.triggerSearch(); }, {}); } // toggle the view to collapsed or expanded toggleCollapsed(collapsed) { if (collapsed) { this.settingsButton.setDisabled(false); this.settingsButton.extraSettingsEl.classList.remove("hidden"); this.graphControlsEl.classList.add("hidden"); } else { this.settingsButton.setDisabled(true); this.settingsButton.extraSettingsEl.classList.add("hidden"); this.graphControlsEl.classList.remove("hidden"); } } appendGraphControlsItems(containerEl) { new import_obsidian17.ExtraButtonComponent(containerEl).setIcon("refresh-cw").setTooltip("Refresh").onClick(() => { this.graphView.refreshGraph(); }); new import_obsidian17.ExtraButtonComponent(containerEl).setIcon("eraser").setTooltip("Clear setting").onClick(() => this.resetSettings()); new import_obsidian17.ExtraButtonComponent(containerEl).setIcon("x").setTooltip("Close").onClick(() => { this.toggleCollapsed(true); }); } // utility function to append a setting appendSettingGroup(containerEl, setting, title, view) { const header = document.createElement("header"); header.classList.add("graph-control-section-header"); header.innerHTML = title; const item = new TreeItem(header, [(containerEl2) => view(setting, containerEl2)]); item.render(containerEl); } /** * this will reset the settings to the default settings. This will reset the setting view. */ resetSettings() { this.searchResult.value.filter.files = []; this.searchResult.value.groups = []; this.updateCurrentSettings((setting) => { setting.value = MySettingManager.getNewSetting(this.graphView.graphType); }); this.initNewView(false); } applySettings(newSetting) { this.searchResult.value.filter.files = []; this.searchResult.value.groups = newSetting.groups.map((g) => ({ files: [] })); this.updateCurrentSettings((setting) => { setting.value = newSetting; }); this.initNewView(false); } triggerSearch() { var _a3, _b3; (_a3 = this.filterSettingView) == null ? void 0 : _a3.triggerSearch(); (_b3 = this.groupSettingView) == null ? void 0 : _b3.triggerSearch(); return Boolean(this.filterSettingView && this.groupSettingView); } /** * this will update the current setting and return the updated setting */ updateCurrentSettings(updateFunc, shouldUpdateGraphView = true) { updateFunc(this.currentSetting); this.graphView.plugin.settingManager.updateSettings((setting) => { if (this.graphView.graphType === "local" /* local */) setting.value.temporaryLocalGraphSetting = this.currentSetting.value; else setting.value.temporaryGlobalGraphSetting = this.currentSetting.value; }); if (shouldUpdateGraphView) this.unpackStateChanges(); return this.currentSetting.value; } /** * this will get all the changes in the state and unpack it to the graph view. * Then reset the state changes */ unpackStateChanges() { const changes = [ ...new Set(this.settingChanges.map((c2) => c2.currentPath)) ]; this.graphView.handleSettingUpdate( this.currentSetting.value, ...changes ); this.settingChanges = []; } /** * return the current setting. This is useful for saving the setting */ getCurrentSetting() { return this.currentSetting.value; } getGraphView() { return this.graphView; } }; // src/views/graph/Graph3dView.ts var Graph3dView = class { constructor(contentEl, plugin, graphType, graph2, itemView) { this.contentEl = contentEl; this.plugin = plugin; this.graphType = graphType; this.itemView = itemView; this.settingManager = new GraphSettingManager(this); this.contentEl.classList.add("graph-3d-view"); this.theme = new ObsidianTheme(this.plugin.app.workspace.containerEl); this.forceGraph = new ForceGraph2(this, graph2); this.contentEl.appendChild(this.settingManager.containerEl); } /** * get the current force graph object */ getForceGraph() { return this.forceGraph; } /** * destroy the old graph, remove the old graph completely from the DOM. * reassign a new graph base on setting like the constructor, * then render it. */ refreshGraph() { var _a3; const graph2 = (_a3 = this.forceGraph) == null ? void 0 : _a3.instance.graphData(); const forceGraphEl = this.contentEl.firstChild; forceGraphEl == null ? void 0 : forceGraphEl.remove(); this.forceGraph.instance._destructor(); this.forceGraph = null; this.theme = new ObsidianTheme(this.plugin.app.workspace.containerEl); this.updateGraphData(graph2); } /** * given some files, update the graph data. */ updateGraphData(graph2) { const tooLarge = graph2.nodes.length > this.plugin.settingManager.getSettings().pluginSetting.maxNodeNumber; if (tooLarge) { createNotice(`Graph is too large to be rendered. Have ${graph2.nodes.length} nodes.`); } if (!this.forceGraph) this.forceGraph = new ForceGraph2(this, tooLarge ? Graph.createEmpty() : graph2); else this.forceGraph.updateGraph(tooLarge ? Graph.createEmpty() : graph2); const focusEl = document.activeElement; this.contentEl.appendChild(this.settingManager.containerEl); try { focusEl == null ? void 0 : focusEl.focus(); } catch (e) { console.error(e.message); } if (this.itemView) this.itemView.onResize(); } /** * when the setting is updated, the graph view need to know how to response to this. */ handleSettingUpdate(newSetting, ...path) { var _a3, _b3, _c2, _d2, _e, _f, _g, _h, _i; if (path.includes("")) { (_a3 = this.forceGraph) == null ? void 0 : _a3.interactionManager.updateNodeLabelDiv(); } if (path.some((p) => p === "filter.showAttachments" || p === "filter.showOrphans")) { this.updateGraphData(this.getNewGraphData()); } if (path.some((p) => p.startsWith("groups"))) { (_b3 = this.forceGraph) == null ? void 0 : _b3.interactionManager.updateColor(); } if (path.includes("display.nodeSize")) { (_c2 = this.forceGraph) == null ? void 0 : _c2.updateConfig({ display: { nodeSize: newSetting.display.nodeSize } }); } if (path.includes("display.linkDistance")) { (_d2 = this.forceGraph) == null ? void 0 : _d2.updateConfig({ display: { linkDistance: newSetting.display.linkDistance } }); } if (path.includes("display.linkThickness")) { (_e = this.forceGraph) == null ? void 0 : _e.updateConfig({ display: { linkThickness: newSetting.display.linkThickness } }); } if (path.includes("display.nodeRepulsion")) { (_f = this.forceGraph) == null ? void 0 : _f.updateConfig({ display: { nodeRepulsion: newSetting.display.nodeRepulsion } }); } if (path.includes("display.showCenterCoordinates")) { (_g = this.forceGraph) == null ? void 0 : _g.updateConfig({ display: { showCenterCoordinates: newSetting.display.showCenterCoordinates } }); } if (path.includes("display.showExtension") || path.includes("display.showFullPath")) { (_h = this.forceGraph) == null ? void 0 : _h.interactionManager.updateNodeLabelDiv(); } if (path.includes("display.dagOrientation")) { (_i = this.forceGraph) == null ? void 0 : _i.updateConfig({ display: { dagOrientation: newSetting.display.dagOrientation } }); } } }; // src/views/graph/GlobalGraph3dView.ts var getNewGlobalGraph = (plugin, config2) => { if (!config2) return plugin.globalGraph; return plugin.globalGraph.clone().filter((node) => { if (!node.path.endsWith(".md") && !config2.filterSetting.showAttachments) return false; if (config2.searchResults.length === 0 && config2.filterSetting.searchQuery === "") return true; return config2.searchResults.some((file) => file.path === node.path); }).filter((node) => { if (node.links.length === 0 && !config2.filterSetting.showOrphans) return false; return true; }); }; var GlobalGraph3dView = class extends Graph3dView { constructor(plugin, contentEl, itemView) { super(contentEl, plugin, "global" /* global */, plugin.globalGraph, itemView); } handleGroupColorSearchResultChange() { var _a3; (_a3 = this.forceGraph) == null ? void 0 : _a3.interactionManager.updateColor(); } handleSearchResultChange() { this.updateGraphData(); } getNewGraphData() { return getNewGlobalGraph(this.plugin, { searchResults: this.settingManager.searchResult.value.filter.files, filterSetting: this.settingManager.getCurrentSetting().filter }); } updateGraphData() { super.updateGraphData(this.getNewGraphData()); } handleMetadataCacheChange() { this.updateGraphData(); } }; // src/views/graph/LocalGraph3dView.ts var traverseNode = (graph2, id, depth, linkType) => { const visitedNodes = /* @__PURE__ */ new Set(); const visitedLinks = /* @__PURE__ */ new Set(); const validLinks = /* @__PURE__ */ new Set(); const queue = []; const startNode = graph2.getNodeById(id); if (startNode) { queue.push({ node: startNode, depth: 0 }); } while (queue.length > 0) { const { node, depth: currentDepth } = queue.shift(); if (!node) continue; visitedNodes.add(node.id); if (currentDepth < depth) { node.links.forEach((link) => { if (visitedLinks.has(link)) { return; } const neighbor = link.source === node ? link.target : link.source; const isOutlink = link.source === node; const isInlink = link.target === node; if (linkType === "both" || linkType === "outlinks" && isOutlink || linkType === "inlinks" && isInlink) { let linkValid = false; visitedLinks.add(link); if (linkType == "both") { linkValid = true; } else { if (!visitedNodes.has(neighbor.id)) { linkValid = true; } } if (linkValid) validLinks.add(link); if (!visitedNodes.has(neighbor.id) && linkValid) { queue.push({ node: neighbor, depth: currentDepth + 1 }); } } }); } } return { nodes: [...visitedNodes].map((nodeId) => graph2.getNodeById(nodeId)).filter(Boolean), links: [...validLinks] }; }; var getNewLocalGraph = (plugin, config2) => { var _a3; const centerFile = (_a3 = config2 == null ? void 0 : config2.centerFile) != null ? _a3 : plugin.app.workspace.getActiveFile(); if (!centerFile || !config2) return Graph.createEmpty(); const { nodes, links } = traverseNode( plugin.globalGraph, centerFile.path, config2.filterSetting.depth, config2.filterSetting.linkType ); const graph2 = plugin.globalGraph.filter( (node) => { if (node.path === centerFile.path) return true; return nodes.some((n) => n.path === node.path); }, (link) => { return links.some( (l) => l.source.path === link.source.path && l.target.path === link.target.path ); } ).filter((node) => { if (node.path === centerFile.path) return true; if (!node.path.endsWith(".md") && !config2.filterSetting.showAttachments) return false; if (config2.searchResults.length === 0 && config2.filterSetting.searchQuery === "") return true; return config2.searchResults.some((file) => file.path === node.path); }).filter((node) => { if (node.path === centerFile.path) return true; if (node.links.length === 0 && !config2.filterSetting.showOrphans) return false; return true; }); return graph2; }; var LocalGraph3dView = class extends Graph3dView { constructor(plugin, contentEl, itemView) { super(contentEl, plugin, "local" /* local */, getNewLocalGraph(plugin), itemView); this.handleFileChange = (file) => { if (!file) return; this.currentFile = file; this.updateGraphData(); }; this.currentFile = this.plugin.app.workspace.getActiveFile(); this.itemView.registerEvent( this.plugin.app.workspace.on("file-open", this.handleFileChange.bind(this)) ); } handleSearchResultChange() { this.updateGraphData(); } handleMetadataCacheChange() { this.updateGraphData(); } getNewGraphData() { const graph2 = getNewLocalGraph(this.plugin, { centerFile: this.currentFile, searchResults: this.settingManager.searchResult.value.filter.files, filterSetting: this.settingManager.getCurrentSetting().filter }); return graph2; } updateGraphData() { super.updateGraphData(this.getNewGraphData()); } handleGroupColorSearchResultChange() { var _a3; (_a3 = this.forceGraph) == null ? void 0 : _a3.interactionManager.updateColor(); } handleSettingUpdate(newSetting, ...path) { super.handleSettingUpdate(newSetting, ...path); if (path.some((p) => p === "filter.depth" || p === "filter.linkType")) { this.updateGraphData(); } } }; // src/views/graph/GraphItemView.ts var import_obsidian18 = require("obsidian"); var GraphItemView = class extends import_obsidian18.ItemView { constructor(leaf, plugin, graphType) { super(leaf); this.plugin = plugin; this.graphType = graphType; this.graph3dView = graphType === "local" /* local */ ? new LocalGraph3dView(this.plugin, this.contentEl, this) : new GlobalGraph3dView(this.plugin, this.contentEl, this); } onload() { super.onload(); this.plugin.activeGraphViews.push(this.graph3dView); } onunload() { super.onunload(); this.graph3dView.getForceGraph().instance._destructor(); this.plugin.activeGraphViews = this.plugin.activeGraphViews.filter( (view) => view !== this.graph3dView ); } getDisplayText() { return config.displayText[this.graphType === "local" /* local */ ? "local" : "global"]; } getViewType() { return config.viewType[this.graphType === "local" /* local */ ? "local" : "global"]; } getIcon() { return config.icon; } onResize() { super.onResize(); if (this.graph3dView) this.graph3dView.getForceGraph().updateDimensions(); } }; // src/views/graph/GlobalGraphItemView.ts var GlobalGraphItemView = class extends GraphItemView { constructor(leaf, plugin) { super(leaf, plugin, "global" /* global */); } }; // src/views/graph/LocalGraphItemView.ts var LocalGraphItemView = class extends GraphItemView { constructor(leaf, plugin) { super(leaf, plugin, "local" /* local */); } }; // src/views/graph/PostProcessorGraph3dView.ts var import_obsidian19 = require("obsidian"); var Test = class extends import_obsidian19.MarkdownRenderChild { constructor(contentEl, plugin, source, ctx, markdownView) { super(contentEl); this.plugin = plugin; this.source = source; this.ctx = ctx; this.markdownView = markdownView; this.resizeObserver = new ResizeObserver((entries) => { this.onResize(entries[0]); }); this.resizeObserver.observe(contentEl); this.graph3dView = new PostProcessorGraph3dView( this.plugin, this.containerEl, this.markdownView, this ); } onload() { super.onload(); this.plugin.activeGraphViews.push(this.graph3dView); } onunload() { super.unload(); console.log("unload"); this.resizeObserver.disconnect(); this.graph3dView.getForceGraph().instance._destructor(); this.plugin.activeGraphViews = this.plugin.activeGraphViews.filter( (view) => view !== this.graph3dView ); } // The method to be called when contentEl is resized onResize(entry) { const { width } = entry.contentRect; this.graph3dView.getForceGraph().updateDimensions([width, 300]); } }; var PostProcessorGraph3dView = class extends Graph3dView { constructor(plugin, contentEl, markdownView, parent) { super( contentEl, plugin, "postProcessor" /* postProcessor */, getNewLocalGraph(plugin), // @ts-ignore markdownView ); this.parent = parent; this.currentFile = this.parent.markdownView.file; } handleSearchResultChange() { this.updateGraphData(); } handleGroupColorSearchResultChange() { this.forceGraph.interactionManager.updateColor(); } handleMetadataCacheChange() { this.updateGraphData(); } updateGraphData() { super.updateGraphData(this.getNewGraphData()); } getNewGraphData() { const graph2 = getNewLocalGraph(this.plugin, { centerFile: this.parent.markdownView.file, searchResults: this.settingManager.searchResult.value.filter.files, filterSetting: { // TODO: since this `getNewLocalGraph` function is originally for local graph, the setting is a bit different, we have to manually set it for now ...this.settingManager.getCurrentSetting().filter, depth: 1, linkType: "both" } }); return graph2; } }; // src/main.ts var Graph3dPlugin = class extends import_obsidian20.Plugin { constructor() { super(...arguments); this.cacheIsReady = new State( this.app.metadataCache.resolvedLinks !== void 0 ); this.isCacheReadyOnce = false; this.activeGraphViews = []; /** * this will be called the when the cache is ready. * And this will hit the else clause of the `onGraphCacheChanged` function */ this.onGraphCacheReady = () => { this.cacheIsReady.value = true; this.onGraphCacheChanged(); }; /** * check if the cache is ready and if it is, update the global graph */ this.onGraphCacheChanged = () => { if (this.cacheIsReady.value && !deepCompare(this._resolvedCache, this.app.metadataCache.resolvedLinks)) { this._resolvedCache = structuredClone(this.app.metadataCache.resolvedLinks); this.globalGraph = Graph.createFromApp(this.app); if (this.isCacheReadyOnce) { this.activeGraphViews.forEach((view) => { view.handleMetadataCacheChange(); }); } } else { this.isCacheReadyOnce = true; this.activeGraphViews.forEach((view) => { view.handleMetadataCacheChange(); }); } }; /** * Opens a local graph view in a new leaf */ this.openLocalGraph = () => { const localGraphItemView = this.app.workspace.getActiveViewOfType(LocalGraphItemView); if (localGraphItemView) { this.app.workspace.setActiveLeaf(localGraphItemView.leaf); } else this.openGraph("local" /* local */); }; /** * Opens a global graph view in the current leaf */ this.openGlobalGraph = () => { const globalGraphView = this.app.workspace.getActiveViewOfType(GlobalGraphItemView); if (globalGraphView) { this.app.workspace.setActiveLeaf(globalGraphView.leaf); } else this.openGraph("global" /* global */); }; /** * this function will open a graph view in the current leaf */ this.openGraph = async (graphType) => { eventBus.trigger("open-graph"); const leaf = this.app.workspace.getLeaf(graphType === "local" /* local */ ? "split" : false); await leaf.setViewState({ type: graphType === "local" /* local */ ? config.viewType.local : config.viewType.global, active: true }); }; } /** * initialize all the things here */ async onload() { this.settingManager = new MySettingManager(this); await this.settingManager.loadSettings(); this.fileManager = new MyFileManager(this); this.cacheIsReady.value = this.app.metadataCache.resolvedLinks !== void 0; this.onGraphCacheChanged(); this.initListeners(); this.addRibbonIcon(config.icon, config.displayText.global, this.openGlobalGraph); this.addCommand({ id: "open-3d-graph-global", name: "Open Global 3D Graph", callback: this.openGlobalGraph }); this.addCommand({ id: "open-3d-graph-local", name: "Open Local 3D Graph", callback: this.openLocalGraph }); this.addSettingTab(new SettingTab(this.app, this)); this.registerView(config.viewType.global, (leaf) => { return new GlobalGraphItemView(leaf, this); }); this.registerView(config.viewType.local, (leaf) => { return new LocalGraphItemView(leaf, this); }); this.registerMarkdownCodeBlockProcessor("3d-graph", (source, el, ctx) => { const markdownView = this.app.workspace.getActiveViewOfType(import_obsidian20.MarkdownView); ctx.addChild(new Test(el, this, source, ctx, markdownView)); }); } onunload() { super.unload(); this.app.metadataCache.off("resolved", this.onGraphCacheReady); this.app.metadataCache.off("resolve", this.onGraphCacheChanged); } initListeners() { this.app.metadataCache.on("resolved", this.onGraphCacheReady); this.app.metadataCache.on("resolve", this.onGraphCacheChanged); this.registerEvent( this.app.workspace.on("file-menu", (menu, file) => { if (!file) return; menu.addItem((item) => { item.setTitle("Open in local 3D Graph").setIcon(config.icon).onClick(() => this.openLocalGraph()); }); }) ); } }; /*! Bundled license information: three/build/three.module.js: (** * @license * Copyright 2010-2023 Three.js Authors * SPDX-License-Identifier: MIT *) three/build/three.module.js: (** * @license * Copyright 2010-2023 Three.js Authors * SPDX-License-Identifier: MIT *) lodash-es/lodash.js: (** * @license * Lodash (Custom Build) * Build: `lodash modularize exports="es" -o ./` * Copyright OpenJS Foundation and other contributors * Released under MIT license * Based on Underscore.js 1.8.3 * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors *) */ /* nosourcemap */