/* 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(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod)); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // node_modules/ngraph.events/index.js var require_ngraph = __commonJS({ "node_modules/ngraph.events/index.js"(exports2, 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"(exports2, 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 = { version: 20, addNode, addLink, removeLink, removeNode, getNode, getNodeCount, getLinkCount, getEdgeCount: getLinkCount, getLinksCount: getLinkCount, getNodesCount: getNodeCount, getLinks, forEachNode, forEachLinkedNode, forEachLink, beginUpdate: enterModification, endUpdate: exitModification, clear, hasLink: getLink, hasNode: getNode, 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"(exports2, module2) { module2.exports = function getVariableName(index5) { if (index5 === 0) return "x"; if (index5 === 1) return "y"; if (index5 === 2) return "z"; return "c" + (index5 + 1); }; } }); // node_modules/ngraph.forcelayout/lib/codeGenerators/createPatternBuilder.js var require_createPatternBuilder = __commonJS({ "node_modules/ngraph.forcelayout/lib/codeGenerators/createPatternBuilder.js"(exports2, module2) { var getVariableName = require_getVariableName(); module2.exports = function createPatternBuilder(dimension) { return pattern; function pattern(template, config) { let indent = config && config.indent || 0; let join = config && config.join !== void 0 ? config.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"(exports2, 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"(exports2, 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"(exports2, 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"(exports2, 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"(exports2, 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"(exports2, 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"(exports2, 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"(exports2, 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"(exports2, 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, x2, y2; do { x2 = this.nextDouble() * 2 - 1; y2 = this.nextDouble() * 2 - 1; r = x2 * x2 + y2 * y2; } while (r >= 1 || r === 0); return x2 * 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(z2) { return Math.sqrt(2 * Math.PI / z2) * Math.pow(1 / Math.E * (z2 + 1 / (12 * z2 - 1 / (10 * z2))), z2); } 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, 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"(exports2, 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, { springLength: 10, springCoefficient: 0.8, gravity: -12, theta: 0.8, dragCoefficient: 0.9, timeStep: 0.5, adaptiveTimeStepWeight: 0, dimensions: 2, 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 = { bodies, quadTree, springs, settings, addForce, removeForce, getForces, 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; }, addBody: function(body) { if (!body) { throw new Error("Body is required"); } bodies.push(body); return body; }, addBodyAt: function(pos) { if (!pos) { throw new Error("Body position is required"); } var body = createBody(pos); bodies.push(body); return body; }, 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; }, 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; }, getTotalMovement: function() { return totalMovement; }, 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); }, getBBox: getBoundingBox, getBoundingBox, invalidateBBox: function() { console.warn("invalidateBBox() is deprecated, bounds always recomputed on `getBBox()` call"); }, 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; } }, 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"(exports2, 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 = { 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; }, getNodePosition: function(nodeId) { return getInitializedBody(nodeId).pos; }, setNodePosition: function(nodeId) { var body = getInitializedBody(nodeId); body.setPosition.apply(body, Array.prototype.slice.call(arguments, 1)); }, getLinkPosition: function(linkId) { var spring = springs[linkId]; if (spring) { return { from: spring.from.pos, to: spring.to.pos }; } }, getGraphRect: function() { return physicsSimulator.getBBox(); }, forEachBody, pinNode: function(node, isPinned) { var body = getInitializedBody(node.id); body.isPinned = !!isPinned; }, isNodePinned: function(node) { return getInitializedBody(node.id).isPinned; }, dispose: function() { graph2.off("changed", onGraphChanged); api.fire("disposed"); }, getBody, getSpring, getForceVectorLength, simulator: physicsSimulator, graph: graph2, 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() { } } }); // node_modules/debounce/index.js var require_debounce = __commonJS({ "node_modules/debounce/index.js"(exports2, module2) { function debounce2(func, wait, immediate) { var timeout2, args, context, timestamp, result; if (wait == null) wait = 100; function later() { var last = Date.now() - timestamp; if (last < wait && last >= 0) { timeout2 = setTimeout(later, wait - last); } else { timeout2 = null; if (!immediate) { result = func.apply(context, args); context = args = null; } } } ; var debounced = function() { context = this; args = arguments; timestamp = Date.now(); var callNow = immediate && !timeout2; if (!timeout2) timeout2 = setTimeout(later, wait); if (callNow) { result = func.apply(context, args); context = args = null; } return result; }; debounced.clear = function() { if (timeout2) { clearTimeout(timeout2); timeout2 = null; } }; debounced.flush = function() { if (timeout2) { result = func.apply(context, args); context = args = null; clearTimeout(timeout2); timeout2 = null; } }; return debounced; } debounce2.debounce = debounce2; module2.exports = debounce2; } }); // node_modules/tinycolor2/tinycolor.js var require_tinycolor = __commonJS({ "node_modules/tinycolor2/tinycolor.js"(exports2, module2) { (function(Math2) { var trimLeft = /^\s+/, trimRight = /\s+$/, tinyCounter = 0, mathRound = Math2.round, mathMin = Math2.min, mathMax = Math2.max, mathRandom = Math2.random; 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 = mathRound(100 * this._a) / 100, this._format = opts.format || rgb2.format; this._gradientType = opts.gradientType; if (this._r < 1) { this._r = mathRound(this._r); } if (this._g < 1) { this._g = mathRound(this._g); } if (this._b < 1) { this._b = mathRound(this._b); } this._ok = rgb2.ok; this._tc_id = tinyCounter++; } tinycolor.prototype = { isDark: function() { return this.getBrightness() < 128; }, isLight: function() { return !this.isDark(); }, isValid: function() { return this._ok; }, getOriginalInput: function() { return this._originalInput; }, getFormat: function() { return this._format; }, getAlpha: function() { return this._a; }, getBrightness: function() { var rgb2 = this.toRgb(); return (rgb2.r * 299 + rgb2.g * 587 + rgb2.b * 114) / 1e3; }, getLuminance: function() { 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 = Math2.pow((RsRGB + 0.055) / 1.055, 2.4); } if (GsRGB <= 0.03928) { G = GsRGB / 12.92; } else { G = Math2.pow((GsRGB + 0.055) / 1.055, 2.4); } if (BsRGB <= 0.03928) { B = BsRGB / 12.92; } else { B = Math2.pow((BsRGB + 0.055) / 1.055, 2.4); } return 0.2126 * R + 0.7152 * G + 0.0722 * B; }, setAlpha: function(value) { this._a = boundAlpha(value); this._roundA = mathRound(100 * this._a) / 100; return this; }, toHsv: function() { 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() { var hsv = rgbToHsv(this._r, this._g, this._b); var h = mathRound(hsv.h * 360), s = mathRound(hsv.s * 100), v = mathRound(hsv.v * 100); return this._a == 1 ? "hsv(" + h + ", " + s + "%, " + v + "%)" : "hsva(" + h + ", " + s + "%, " + v + "%, " + this._roundA + ")"; }, toHsl: function() { 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() { var hsl = rgbToHsl(this._r, this._g, this._b); var h = mathRound(hsl.h * 360), s = mathRound(hsl.s * 100), l = mathRound(hsl.l * 100); return this._a == 1 ? "hsl(" + h + ", " + s + "%, " + l + "%)" : "hsla(" + h + ", " + s + "%, " + l + "%, " + this._roundA + ")"; }, toHex: function(allow3Char) { return rgbToHex(this._r, this._g, this._b, allow3Char); }, toHexString: function(allow3Char) { return "#" + this.toHex(allow3Char); }, toHex8: function(allow4Char) { return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char); }, toHex8String: function(allow4Char) { return "#" + this.toHex8(allow4Char); }, toRgb: function() { return { r: mathRound(this._r), g: mathRound(this._g), b: mathRound(this._b), a: this._a }; }, toRgbString: function() { return this._a == 1 ? "rgb(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ")" : "rgba(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ", " + this._roundA + ")"; }, toPercentageRgb: function() { return { r: mathRound(bound01(this._r, 255) * 100) + "%", g: mathRound(bound01(this._g, 255) * 100) + "%", b: mathRound(bound01(this._b, 255) * 100) + "%", a: this._a }; }, toPercentageRgbString: function() { return this._a == 1 ? "rgb(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%)" : "rgba(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")"; }, toName: function() { 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(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(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() { return tinycolor(this.toString()); }, _applyModification: function(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() { return this._applyModification(lighten, arguments); }, brighten: function() { return this._applyModification(brighten, arguments); }, darken: function() { return this._applyModification(darken, arguments); }, desaturate: function() { return this._applyModification(desaturate, arguments); }, saturate: function() { return this._applyModification(saturate, arguments); }, greyscale: function() { return this._applyModification(greyscale, arguments); }, spin: function() { return this._applyModification(spin, arguments); }, _applyCombination: function(fn, args) { return fn.apply(null, [this].concat([].slice.call(args))); }, analogous: function() { return this._applyCombination(analogous, arguments); }, complement: function() { return this._applyCombination(complement, arguments); }, monochromatic: function() { return this._applyCombination(monochromatic, arguments); }, splitcomplement: function() { return this._applyCombination(splitcomplement, arguments); }, triad: function() { return this._applyCombination(triad, arguments); }, tetrad: function() { return this._applyCombination(tetrad, arguments); } }; 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 = hslToRgb2(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: mathMin(255, mathMax(rgb2.r, 0)), g: mathMin(255, mathMax(rgb2.g, 0)), b: mathMin(255, mathMax(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 = mathMax(r, g, b), min2 = mathMin(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 hslToRgb2(h, s, l) { var r, g, b; h = bound01(h, 360); s = bound01(s, 100); l = bound01(l, 100); function hue2rgb2(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 = hue2rgb2(p, q, h + 1 / 3); g = hue2rgb2(p, q, h); b = hue2rgb2(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 = mathMax(r, g, b), min2 = mathMin(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 = Math2.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(mathRound(r).toString(16)), pad2(mathRound(g).toString(16)), pad2(mathRound(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(mathRound(r).toString(16)), pad2(mathRound(g).toString(16)), pad2(mathRound(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(mathRound(r).toString(16)), pad2(mathRound(g).toString(16)), pad2(mathRound(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: mathRandom(), g: mathRandom(), b: mathRandom() }); }; 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 = mathMax(0, mathMin(255, rgb2.r - mathRound(255 * -(amount / 100)))); rgb2.g = mathMax(0, mathMin(255, rgb2.g - mathRound(255 * -(amount / 100)))); rgb2.b = mathMax(0, mathMin(255, rgb2.b - mathRound(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 triad(color) { var hsl = tinycolor(color).toHsl(); var h = hsl.h; return [ tinycolor(color), tinycolor({ h: (h + 120) % 360, s: hsl.s, l: hsl.l }), tinycolor({ h: (h + 240) % 360, s: hsl.s, l: hsl.l }) ]; } function tetrad(color) { var hsl = tinycolor(color).toHsl(); var h = hsl.h; return [ tinycolor(color), tinycolor({ h: (h + 90) % 360, s: hsl.s, l: hsl.l }), tinycolor({ h: (h + 180) % 360, s: hsl.s, l: hsl.l }), tinycolor({ h: (h + 270) % 360, s: hsl.s, l: hsl.l }) ]; } 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 (Math2.max(c1.getLuminance(), c2.getLuminance()) + 0.05) / (Math2.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": level, "size": 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 = mathMin(max2, mathMax(0, parseFloat(n))); if (processPercent) { n = parseInt(n * max2, 10) / 100; } if (Math2.abs(n - max2) < 1e-6) { return 1; } return n % max2 / parseFloat(max2); } function clamp01(val) { return mathMin(1, mathMax(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 Math2.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": level, "size": size }; } if (typeof module2 !== "undefined" && module2.exports) { module2.exports = tinycolor; } else if (typeof define === "function" && define.amd) { define(function() { return tinycolor; }); } else { window.tinycolor = tinycolor; } })(Math); } }); // node_modules/observable-slim/observable-slim.js var require_observable_slim = __commonJS({ "node_modules/observable-slim/observable-slim.js"(exports2, 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 z2 = targetsProxy[targetPosition].length; while (z2--) { if (observable === targetsProxy[targetPosition][z2].observable) { if (targets[targetsProxy[targetPosition][z2].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: 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; }, observe: function(proxy, observer) { var i = observables.length; while (i--) { if (observables[i].parentProxy === proxy) { observables[i].observers.push(observer); break; } } ; }, 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: 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."); }, 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."); }, 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: 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) { } } }); // src/main.ts var main_exports = {}; __export(main_exports, { default: () => Graph3dPlugin }); module.exports = __toCommonJS(main_exports); var import_obsidian7 = require("obsidian"); // src/views/graph/Graph3dView.ts var import_obsidian6 = require("obsidian"); // node_modules/three/build/three.module.js var REVISION = "143"; 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 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 FlatShading = 1; 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 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 RGBFormat = 1022; 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 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 SRGBColorSpace = "srgb"; var LinearSRGBColorSpace = "srgb-linear"; var KeepStencilOp = 7680; var AlwaysStencilFunc = 519; var StaticDrawUsage = 35044; var GLSL3 = "300 es"; var _SRGBAFormat = 1035; 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 index5 = listenerArray.indexOf(listener); if (index5 !== -1) { listenerArray.splice(index5, 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(x2, y2, t) { return (1 - t) * x2 + t * y2; } function isPowerOfTwo(value) { return (value & value - 1) === 0 && value !== 0; } function floorPowerOfTwo(value) { return Math.pow(2, Math.floor(Math.log(value) / Math.LN2)); } var Vector2 = class { constructor(x2 = 0, y2 = 0) { Vector2.prototype.isVector2 = true; this.x = x2; this.y = y2; } get width() { return this.x; } set width(value) { this.x = value; } get height() { return this.y; } set height(value) { this.y = value; } set(x2, y2) { this.x = x2; this.y = y2; return this; } setScalar(scalar) { this.x = scalar; this.y = scalar; return this; } setX(x2) { this.x = x2; return this; } setY(y2) { this.y = y2; return this; } setComponent(index5, value) { switch (index5) { case 0: this.x = value; break; case 1: this.y = value; break; default: throw new Error("index is out of range: " + index5); } return this; } getComponent(index5) { switch (index5) { case 0: return this.x; case 1: return this.y; default: throw new Error("index is out of range: " + index5); } } 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 x2 = this.x, y2 = this.y; const e = m2.elements; this.x = e[0] * x2 + e[3] * y2 + e[6]; this.y = e[1] * x2 + e[4] * y2 + 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 = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x); this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(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; } 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, index5) { this.x = attribute.getX(index5); this.y = attribute.getY(index5); return this; } rotateAround(center, angle) { const c2 = Math.cos(angle), s = Math.sin(angle); const x2 = this.x - center.x; const y2 = this.y - center.y; this.x = x2 * c2 - y2 * s + center.x; this.y = x2 * s + y2 * 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() { Matrix3.prototype.isMatrix3 = true; this.elements = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ]; } 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) { const te = this.elements; te[0] *= sx; te[3] *= sx; te[6] *= sx; te[1] *= sy; te[4] *= sy; te[7] *= sy; return this; } rotate(theta) { const c2 = Math.cos(theta); const s = Math.sin(theta); const te = this.elements; const a11 = te[0], a12 = te[3], a13 = te[6]; const a21 = te[1], a22 = te[4], a23 = te[7]; te[0] = c2 * a11 + s * a21; te[3] = c2 * a12 + s * a22; te[6] = c2 * a13 + s * a23; te[1] = -s * a11 + c2 * a21; te[4] = -s * a12 + c2 * a22; te[7] = -s * a13 + c2 * a23; return this; } translate(tx, ty) { const te = this.elements; te[0] += tx * te[2]; te[3] += tx * te[5]; te[6] += tx * te[8]; te[1] += ty * te[2]; te[4] += ty * te[5]; te[7] += ty * te[8]; 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); } }; 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 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 FN = { [SRGBColorSpace]: { [LinearSRGBColorSpace]: SRGBToLinear }, [LinearSRGBColorSpace]: { [SRGBColorSpace]: LinearToSRGB } }; var ColorManagement = { legacyMode: true, get workingColorSpace() { return LinearSRGBColorSpace; }, set workingColorSpace(colorSpace) { console.warn("THREE.ColorManagement: .workingColorSpace is readonly."); }, convert: function(color, sourceColorSpace, targetColorSpace) { if (this.legacyMode || sourceColorSpace === targetColorSpace || !sourceColorSpace || !targetColorSpace) { return color; } if (FN[sourceColorSpace] && FN[sourceColorSpace][targetColorSpace] !== void 0) { const fn = FN[sourceColorSpace][targetColorSpace]; color.r = fn(color.r); color.g = fn(color.g); color.b = fn(color.b); return color; } throw new Error("Unsupported color space conversion."); }, fromWorkingColorSpace: function(color, targetColorSpace) { return this.convert(color, this.workingColorSpace, targetColorSpace); }, toWorkingColorSpace: function(color, sourceColorSpace) { return this.convert(color, sourceColorSpace, this.workingColorSpace); } }; 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 _rgb = { r: 0, g: 0, b: 0 }; 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; } function toComponents(source, target) { target.r = source.r; target.g = source.g; target.b = source.b; return target; } var Color = class { constructor(r, g, b) { this.isColor = true; this.r = 1; this.g = 1; this.b = 1; if (g === void 0 && b === void 0) { return this.set(r); } return this.setRGB(r, g, b); } set(value) { if (value && value.isColor) { this.copy(value); } else if (typeof value === "number") { this.setHex(value); } else if (typeof value === "string") { this.setStyle(value); } 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 = LinearSRGBColorSpace) { this.r = r; this.g = g; this.b = b; ColorManagement.toWorkingColorSpace(this, colorSpace); return this; } setHSL(h, s, l, colorSpace = LinearSRGBColorSpace) { 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 = /^((?:rgb|hsl)a?)\(([^\)]*)\)/.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)) { this.r = Math.min(255, parseInt(color[1], 10)) / 255; this.g = Math.min(255, parseInt(color[2], 10)) / 255; this.b = Math.min(255, parseInt(color[3], 10)) / 255; ColorManagement.toWorkingColorSpace(this, colorSpace); handleAlpha(color[4]); return this; } if (color = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) { this.r = Math.min(100, parseInt(color[1], 10)) / 100; this.g = Math.min(100, parseInt(color[2], 10)) / 100; this.b = Math.min(100, parseInt(color[3], 10)) / 100; ColorManagement.toWorkingColorSpace(this, colorSpace); handleAlpha(color[4]); return this; } break; case "hsl": case "hsla": if (color = /^\s*(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components)) { const h = parseFloat(color[1]) / 360; const s = parseInt(color[2], 10) / 100; const l = parseInt(color[3], 10) / 100; handleAlpha(color[4]); return this.setHSL(h, s, l, colorSpace); } break; } } else if (m2 = /^\#([A-Fa-f\d]+)$/.exec(style)) { const hex = m2[1]; const size = hex.length; if (size === 3) { this.r = parseInt(hex.charAt(0) + hex.charAt(0), 16) / 255; this.g = parseInt(hex.charAt(1) + hex.charAt(1), 16) / 255; this.b = parseInt(hex.charAt(2) + hex.charAt(2), 16) / 255; ColorManagement.toWorkingColorSpace(this, colorSpace); return this; } else if (size === 6) { this.r = parseInt(hex.charAt(0) + hex.charAt(1), 16) / 255; this.g = parseInt(hex.charAt(2) + hex.charAt(3), 16) / 255; this.b = parseInt(hex.charAt(4) + hex.charAt(5), 16) / 255; ColorManagement.toWorkingColorSpace(this, colorSpace); return this; } } 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(toComponents(this, _rgb), colorSpace); return clamp(_rgb.r * 255, 0, 255) << 16 ^ clamp(_rgb.g * 255, 0, 255) << 8 ^ clamp(_rgb.b * 255, 0, 255) << 0; } getHexString(colorSpace = SRGBColorSpace) { return ("000000" + this.getHex(colorSpace).toString(16)).slice(-6); } getHSL(target, colorSpace = LinearSRGBColorSpace) { ColorManagement.fromWorkingColorSpace(toComponents(this, _rgb), colorSpace); const r = _rgb.r, g = _rgb.g, b = _rgb.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 = LinearSRGBColorSpace) { ColorManagement.fromWorkingColorSpace(toComponents(this, _rgb), colorSpace); target.r = _rgb.r; target.g = _rgb.g; target.b = _rgb.b; return target; } getStyle(colorSpace = SRGBColorSpace) { ColorManagement.fromWorkingColorSpace(toComponents(this, _rgb), colorSpace); if (colorSpace !== SRGBColorSpace) { return `color(${colorSpace} ${_rgb.r} ${_rgb.g} ${_rgb.b})`; } return `rgb(${_rgb.r * 255 | 0},${_rgb.g * 255 | 0},${_rgb.b * 255 | 0})`; } offsetHSL(h, s, l) { this.getHSL(_hslA); _hslA.h += h; _hslA.s += s; _hslA.l += l; this.setHSL(_hslA.h, _hslA.s, _hslA.l); return this; } 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; } 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, index5) { this.r = attribute.getX(index5); this.g = attribute.getY(index5); this.b = attribute.getZ(index5); if (attribute.normalized === true) { this.r /= 255; this.g /= 255; this.b /= 255; } return this; } toJSON() { return this.getHex(); } *[Symbol.iterator]() { yield this.r; yield this.g; yield this.b; } }; Color.NAMES = _colorKeywords; 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 Source = class { constructor(data = null) { this.isSource = true; 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 = 1, encoding = LinearEncoding) { 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.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; this.encoding = encoding; this.userData = {}; this.version = 0; this.onUpdate = null; this.isRenderTargetTexture = false; this.needsPMREMUpdate = false; } get image() { return this.source.data; } set image(value) { 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.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.encoding = source.encoding; 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.5, type: "Texture", generator: "Texture.toJSON" }, uuid: this.uuid, name: this.name, image: this.source.toJSON(meta).uuid, mapping: this.mapping, 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, type: this.type, encoding: this.encoding, minFilter: this.minFilter, magFilter: this.magFilter, anisotropy: this.anisotropy, flipY: this.flipY, premultiplyAlpha: this.premultiplyAlpha, unpackAlignment: this.unpackAlignment }; if (JSON.stringify(this.userData) !== "{}") 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; } } }; Texture.DEFAULT_IMAGE = null; Texture.DEFAULT_MAPPING = UVMapping; var Vector4 = class { constructor(x2 = 0, y2 = 0, z2 = 0, w = 1) { Vector4.prototype.isVector4 = true; this.x = x2; this.y = y2; this.z = z2; 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(x2, y2, z2, w) { this.x = x2; this.y = y2; this.z = z2; this.w = w; return this; } setScalar(scalar) { this.x = scalar; this.y = scalar; this.z = scalar; this.w = scalar; return this; } setX(x2) { this.x = x2; return this; } setY(y2) { this.y = y2; return this; } setZ(z2) { this.z = z2; return this; } setW(w) { this.w = w; return this; } setComponent(index5, value) { switch (index5) { 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: " + index5); } return this; } getComponent(index5) { switch (index5) { 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: " + index5); } } 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 x2 = this.x, y2 = this.y, z2 = this.z, w = this.w; const e = m2.elements; this.x = e[0] * x2 + e[4] * y2 + e[8] * z2 + e[12] * w; this.y = e[1] * x2 + e[5] * y2 + e[9] * z2 + e[13] * w; this.z = e[2] * x2 + e[6] * y2 + e[10] * z2 + e[14] * w; this.w = e[3] * x2 + e[7] * y2 + e[11] * z2 + 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, x2, y2, z2; 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) { x2 = 0; y2 = 0.707106781; z2 = 0.707106781; } else { x2 = Math.sqrt(xx); y2 = xy / x2; z2 = xz / x2; } } else if (yy > zz) { if (yy < epsilon) { x2 = 0.707106781; y2 = 0; z2 = 0.707106781; } else { y2 = Math.sqrt(yy); x2 = xy / y2; z2 = yz / y2; } } else { if (zz < epsilon) { x2 = 0.707106781; y2 = 0.707106781; z2 = 0; } else { z2 = Math.sqrt(zz); x2 = xz / z2; y2 = yz / z2; } } this.set(x2, y2, z2, 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 = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x); this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y); this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(this.z); this.w = this.w < 0 ? Math.ceil(this.w) : Math.floor(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, index5) { this.x = attribute.getX(index5); this.y = attribute.getY(index5); this.z = attribute.getZ(index5); this.w = attribute.getW(index5); 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 WebGLRenderTarget = class extends EventDispatcher { constructor(width, height, options = {}) { super(); this.isWebGLRenderTarget = 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 }; this.texture = new Texture(image, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding); this.texture.isRenderTargetTexture = true; this.texture.flipY = false; this.texture.generateMipmaps = options.generateMipmaps !== void 0 ? options.generateMipmaps : false; this.texture.internalFormat = options.internalFormat !== void 0 ? options.internalFormat : null; this.texture.minFilter = options.minFilter !== void 0 ? options.minFilter : LinearFilter; this.depthBuffer = options.depthBuffer !== void 0 ? options.depthBuffer : true; this.stencilBuffer = options.stencilBuffer !== void 0 ? options.stencilBuffer : false; this.depthTexture = options.depthTexture !== void 0 ? options.depthTexture : null; this.samples = options.samples !== void 0 ? options.samples : 0; } 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.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 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(x2 = 0, y2 = 0, z2 = 0, w = 1) { this.isQuaternion = true; this._x = x2; this._y = y2; this._z = z2; 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(x2, y2, z2, w) { this._x = x2; this._y = y2; this._z = z2; 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) { if (!(euler && euler.isEuler)) { throw new Error("THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order."); } const x2 = euler._x, y2 = euler._y, z2 = euler._z, order = euler._order; const cos = Math.cos; const sin = Math.sin; const c1 = cos(x2 / 2); const c2 = cos(y2 / 2); const c3 = cos(z2 / 2); const s1 = sin(x2 / 2); const s2 = sin(y2 / 2); const s3 = sin(z2 / 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 x2 = this._x, y2 = this._y, z2 = this._z, w = this._w; let cosHalfTheta = w * qb._w + x2 * qb._x + y2 * qb._y + z2 * 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 = x2; this._y = y2; this._z = z2; 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 * x2 + t * this._x; this._y = s * y2 + t * this._y; this._z = s * z2 + 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 = x2 * ratioA + this._x * ratioB; this._y = y2 * ratioA + this._y * ratioB; this._z = z2 * 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, index5) { this._x = attribute.getX(index5); this._y = attribute.getY(index5); this._z = attribute.getZ(index5); this._w = attribute.getW(index5); return this; } _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(x2 = 0, y2 = 0, z2 = 0) { Vector3.prototype.isVector3 = true; this.x = x2; this.y = y2; this.z = z2; } set(x2, y2, z2) { if (z2 === void 0) z2 = this.z; this.x = x2; this.y = y2; this.z = z2; return this; } setScalar(scalar) { this.x = scalar; this.y = scalar; this.z = scalar; return this; } setX(x2) { this.x = x2; return this; } setY(y2) { this.y = y2; return this; } setZ(z2) { this.z = z2; return this; } setComponent(index5, value) { switch (index5) { 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: " + index5); } return this; } getComponent(index5) { switch (index5) { case 0: return this.x; case 1: return this.y; case 2: return this.z; default: throw new Error("index is out of range: " + index5); } } 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 x2 = this.x, y2 = this.y, z2 = this.z; const e = m2.elements; this.x = e[0] * x2 + e[3] * y2 + e[6] * z2; this.y = e[1] * x2 + e[4] * y2 + e[7] * z2; this.z = e[2] * x2 + e[5] * y2 + e[8] * z2; return this; } applyNormalMatrix(m2) { return this.applyMatrix3(m2).normalize(); } applyMatrix4(m2) { const x2 = this.x, y2 = this.y, z2 = this.z; const e = m2.elements; const w = 1 / (e[3] * x2 + e[7] * y2 + e[11] * z2 + e[15]); this.x = (e[0] * x2 + e[4] * y2 + e[8] * z2 + e[12]) * w; this.y = (e[1] * x2 + e[5] * y2 + e[9] * z2 + e[13]) * w; this.z = (e[2] * x2 + e[6] * y2 + e[10] * z2 + e[14]) * w; return this; } applyQuaternion(q) { const x2 = this.x, y2 = this.y, z2 = this.z; const qx = q.x, qy = q.y, qz = q.z, qw = q.w; const ix = qw * x2 + qy * z2 - qz * y2; const iy = qw * y2 + qz * x2 - qx * z2; const iz = qw * z2 + qx * y2 - qy * x2; const iw = -qx * x2 - qy * y2 - qz * z2; 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 x2 = this.x, y2 = this.y, z2 = this.z; const e = m2.elements; this.x = e[0] * x2 + e[4] * y2 + e[8] * z2; this.y = e[1] * x2 + e[5] * y2 + e[9] * z2; this.z = e[2] * x2 + e[6] * y2 + e[10] * z2; 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 = this.x < 0 ? Math.ceil(this.x) : Math.floor(this.x); this.y = this.y < 0 ? Math.ceil(this.y) : Math.floor(this.y); this.z = this.z < 0 ? Math.ceil(this.z) : Math.floor(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; } 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$c.copy(this).projectOnVector(planeNormal); return this.sub(_vector$c); } reflect(normal) { return this.sub(_vector$c.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, y2) { this.x = radius * Math.sin(theta); this.y = y2; 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, index5) { return this.fromArray(m2.elements, index5 * 4); } setFromMatrix3Column(m2, index5) { return this.fromArray(m2.elements, index5 * 3); } setFromEuler(e) { this.x = e._x; this.y = e._y; this.z = e._z; 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, index5) { this.x = attribute.getX(index5); this.y = attribute.getY(index5); this.z = attribute.getZ(index5); 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$c = /* @__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) { let minX = Infinity; let minY = Infinity; let minZ = Infinity; let maxX = -Infinity; let maxY = -Infinity; let maxZ = -Infinity; for (let i = 0, l = array.length; i < l; i += 3) { const x2 = array[i]; const y2 = array[i + 1]; const z2 = array[i + 2]; if (x2 < minX) minX = x2; if (y2 < minY) minY = y2; if (z2 < minZ) minZ = z2; if (x2 > maxX) maxX = x2; if (y2 > maxY) maxY = y2; if (z2 > maxZ) maxZ = z2; } this.min.set(minX, minY, minZ); this.max.set(maxX, maxY, maxZ); return this; } setFromBufferAttribute(attribute) { let minX = Infinity; let minY = Infinity; let minZ = Infinity; let maxX = -Infinity; let maxY = -Infinity; let maxZ = -Infinity; for (let i = 0, l = attribute.count; i < l; i++) { const x2 = attribute.getX(i); const y2 = attribute.getY(i); const z2 = attribute.getZ(i); if (x2 < minX) minX = x2; if (y2 < minY) minY = y2; if (z2 < minZ) minZ = z2; if (x2 > maxX) maxX = x2; if (y2 > maxY) maxY = y2; if (z2 > maxZ) maxZ = z2; } this.min.set(minX, minY, minZ); this.max.set(maxX, maxY, maxZ); 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$b.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) { 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$b.fromBufferAttribute(position, i).applyMatrix4(object.matrixWorld); this.expandByPoint(_vector$b); } } 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$b); return _vector$b.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$3.subVectors(triangle.c, _center); _f0.subVectors(_v1$7, _v0$2); _f1.subVectors(_v2$3, _v1$7); _f2.subVectors(_v0$2, _v2$3); 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$3, _extents)) { return false; } axes = [1, 0, 0, 0, 1, 0, 0, 0, 1]; if (!satForAxes(axes, _v0$2, _v1$7, _v2$3, _extents)) { return false; } _triangleNormal.crossVectors(_f0, _f1); axes = [_triangleNormal.x, _triangleNormal.y, _triangleNormal.z]; return satForAxes(axes, _v0$2, _v1$7, _v2$3, _extents); } clampPoint(point, target) { return target.copy(point).clamp(this.min, this.max); } distanceToPoint(point) { const clampedPoint = _vector$b.copy(point).clamp(this.min, this.max); return clampedPoint.sub(point).length(); } getBoundingSphere(target) { this.getCenter(target.center); target.radius = this.getSize(_vector$b).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$b = /* @__PURE__ */ new Vector3(); var _box$3 = /* @__PURE__ */ new Box3(); var _v0$2 = /* @__PURE__ */ new Vector3(); var _v1$7 = /* @__PURE__ */ new Vector3(); var _v2$3 = /* @__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 _toFarthestPoint = /* @__PURE__ */ new Vector3(); var _toPoint = /* @__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) { _toPoint.subVectors(point, this.center); const lengthSq = _toPoint.lengthSq(); if (lengthSq > this.radius * this.radius) { const length = Math.sqrt(lengthSq); const missingRadiusHalf = (length - this.radius) * 0.5; this.center.add(_toPoint.multiplyScalar(missingRadiusHalf / length)); this.radius += missingRadiusHalf; } return this; } union(sphere) { if (this.center.equals(sphere.center) === true) { _toFarthestPoint.set(0, 0, 1).multiplyScalar(sphere.radius); } else { _toFarthestPoint.subVectors(sphere.center, this.center).normalize().multiplyScalar(sphere.radius); } this.expandByPoint(_v1$6.copy(sphere.center).add(_toFarthestPoint)); this.expandByPoint(_v1$6.copy(sphere.center).sub(_toFarthestPoint)); return this; } equals(sphere) { return sphere.center.equals(this.center) && sphere.radius === this.radius; } clone() { return new this.constructor().copy(this); } }; var _vector$a = /* @__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(origin = new Vector3(), direction = new Vector3(0, 0, -1)) { this.origin = origin; this.direction = direction; } set(origin, direction) { this.origin.copy(origin); 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.direction).multiplyScalar(t).add(this.origin); } lookAt(v) { this.direction.copy(v).sub(this.origin).normalize(); return this; } recast(t) { this.origin.copy(this.at(t, _vector$a)); 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.direction).multiplyScalar(directionDistance).add(this.origin); } distanceToPoint(point) { return Math.sqrt(this.distanceSqToPoint(point)); } distanceSqToPoint(point) { const directionDistance = _vector$a.subVectors(point, this.origin).dot(this.direction); if (directionDistance < 0) { return this.origin.distanceToSquared(point); } _vector$a.copy(this.direction).multiplyScalar(directionDistance).add(this.origin); return _vector$a.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.direction).multiplyScalar(s0).add(this.origin); } if (optionalPointOnSegment) { optionalPointOnSegment.copy(_segDir).multiplyScalar(s1).add(_segCenter); } return sqrDist; } intersectSphere(sphere, target) { _vector$a.subVectors(sphere.center, this.origin); const tca = _vector$a.dot(this.direction); const d2 = _vector$a.dot(_vector$a) - 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 (t0 < 0 && 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 origin = this.origin; if (invdirx >= 0) { tmin = (box.min.x - origin.x) * invdirx; tmax = (box.max.x - origin.x) * invdirx; } else { tmin = (box.max.x - origin.x) * invdirx; tmax = (box.min.x - origin.x) * invdirx; } if (invdiry >= 0) { tymin = (box.min.y - origin.y) * invdiry; tymax = (box.max.y - origin.y) * invdiry; } else { tymin = (box.max.y - origin.y) * invdiry; tymax = (box.min.y - origin.y) * invdiry; } if (tmin > tymax || tymin > tmax) return null; if (tymin > tmin || tmin !== tmin) tmin = tymin; if (tymax < tmax || tmax !== tmax) tmax = tymax; if (invdirz >= 0) { tzmin = (box.min.z - origin.z) * invdirz; tzmax = (box.max.z - origin.z) * invdirz; } else { tzmin = (box.max.z - origin.z) * invdirz; tzmax = (box.min.z - origin.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$a) !== 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() { Matrix4.prototype.isMatrix4 = true; this.elements = [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]; } 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 x2 = euler.x, y2 = euler.y, z2 = euler.z; const a2 = Math.cos(x2), b = Math.sin(x2); const c2 = Math.cos(y2), d = Math.sin(y2); const e = Math.cos(z2), f = Math.sin(z2); 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(x2, y2, z2) { const te = this.elements; if (x2.isVector3) { te[12] = x2.x; te[13] = x2.y; te[14] = x2.z; } else { te[12] = x2; te[13] = y2; te[14] = z2; } 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 x2 = v.x, y2 = v.y, z2 = v.z; te[0] *= x2; te[4] *= y2; te[8] *= z2; te[1] *= x2; te[5] *= y2; te[9] *= z2; te[2] *= x2; te[6] *= y2; te[10] *= z2; te[3] *= x2; te[7] *= y2; te[11] *= z2; 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(x2, y2, z2) { this.set(1, 0, 0, x2, 0, 1, 0, y2, 0, 0, 1, z2, 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 x2 = axis.x, y2 = axis.y, z2 = axis.z; const tx = t * x2, ty = t * y2; this.set(tx * x2 + c2, tx * y2 - s * z2, tx * z2 + s * y2, 0, tx * y2 + s * z2, ty * y2 + c2, ty * z2 - s * x2, 0, tx * z2 - s * y2, ty * z2 + s * x2, t * z2 * z2 + c2, 0, 0, 0, 0, 1); return this; } makeScale(x2, y2, z2) { this.set(x2, 0, 0, 0, 0, y2, 0, 0, 0, 0, z2, 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 x2 = quaternion._x, y2 = quaternion._y, z2 = quaternion._z, w = quaternion._w; const x22 = x2 + x2, y22 = y2 + y2, z22 = z2 + z2; const xx = x2 * x22, xy = x2 * y22, xz = x2 * z22; const yy = y2 * y22, yz = y2 * z22, zz = z2 * 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) { const te = this.elements; const x2 = 2 * near / (right - left); const y2 = 2 * near / (top - bottom); const a2 = (right + left) / (right - left); const b = (top + bottom) / (top - bottom); const c2 = -(far + near) / (far - near); const d = -2 * far * near / (far - near); te[0] = x2; te[4] = 0; te[8] = a2; te[12] = 0; te[1] = 0; te[5] = y2; 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) { const te = this.elements; const w = 1 / (right - left); const h = 1 / (top - bottom); const p = 1 / (far - near); const x2 = (right + left) * w; const y2 = (top + bottom) * h; const z2 = (far + near) * p; te[0] = 2 * w; te[4] = 0; te[8] = 0; te[12] = -x2; te[1] = 0; te[5] = 2 * h; te[9] = 0; te[13] = -y2; te[2] = 0; te[6] = 0; te[10] = -2 * p; te[14] = -z2; 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$1 = /* @__PURE__ */ new Matrix4(); var _quaternion$3 = /* @__PURE__ */ new Quaternion(); var Euler = class { constructor(x2 = 0, y2 = 0, z2 = 0, order = Euler.DefaultOrder) { this.isEuler = true; this._x = x2; this._y = y2; this._z = z2; 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(x2, y2, z2, order = this._order) { this._x = x2; this._y = y2; this._z = z2; 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$1.makeRotationFromQuaternion(q); return this.setFromRotationMatrix(_matrix$1, 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; } toVector3() { console.error("THREE.Euler: .toVector3() has been removed. Use Vector3.setFromEuler() instead"); } }; Euler.DefaultOrder = "XYZ"; Euler.RotationOrders = ["XYZ", "YZX", "ZXY", "XZY", "YXZ", "ZYX"]; 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.DefaultUp.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.DefaultMatrixAutoUpdate; this.matrixWorldNeedsUpdate = false; 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) { return vector.applyMatrix4(this.matrixWorld); } worldToLocal(vector) { return vector.applyMatrix4(_m1$1.copy(this.matrixWorld).invert()); } lookAt(x2, y2, z2) { if (x2.isVector3) { _target.copy(x2); } else { _target.set(x2, y2, z2); } 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 index5 = this.children.indexOf(object); if (index5 !== -1) { object.parent = null; this.children.splice(index5, 1); object.dispatchEvent(_removedEvent); } return this; } removeFromParent() { const parent = this.parent; if (parent !== null) { parent.remove(this); } return this; } clear() { for (let i = 0; i < this.children.length; i++) { const object = this.children[i]; object.parent = null; object.dispatchEvent(_removedEvent); } this.children.length = 0; return this; } 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; } 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++) { children[i].updateMatrixWorld(force); } } updateWorldMatrix(updateParents, updateChildren) { const parent = this.parent; if (updateParents === true && parent !== null) { 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++) { children[i].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.5, 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 (JSON.stringify(this.userData) !== "{}") object.userData = this.userData; object.layers = this.layers.mask; object.matrix = this.matrix.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.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.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.DefaultUp = /* @__PURE__ */ new Vector3(0, 1, 0); Object3D.DefaultMatrixAutoUpdate = 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 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 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) { this.getBarycoord(point, p1, p2, p3, _v3$1); target.set(0, 0); target.addScaledVector(uv1, _v3$1.x); target.addScaledVector(uv2, _v3$1.y); target.addScaledVector(uv3, _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) { return Triangle.getUV(point, this.a, this.b, this.c, uv1, uv2, uv3, 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 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.blendSrc = SrcAlphaFactor; this.blendDst = OneMinusSrcAlphaFactor; this.blendEquation = AddEquation; this.blendSrcAlpha = null; this.blendDstAlpha = null; this.blendEquationAlpha = null; 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.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: '" + key + "' parameter is undefined."); continue; } if (key === "shading") { console.warn("THREE." + this.type + ": .shading has been removed. Use the boolean .flatShading instead."); this.flatShading = newValue === FlatShading ? true : false; continue; } const currentValue = this[key]; if (currentValue === void 0) { console.warn("THREE." + this.type + ": '" + key + "' is not a property of this material."); 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.5, 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.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) 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) data.vertexColors = true; if (this.opacity < 1) data.opacity = this.opacity; if (this.transparent === true) data.transparent = this.transparent; 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.alphaToCoverage === true) data.alphaToCoverage = this.alphaToCoverage; if (this.premultipliedAlpha === true) data.premultipliedAlpha = this.premultipliedAlpha; if (this.wireframe === true) data.wireframe = this.wireframe; 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 = this.flatShading; if (this.visible === false) data.visible = false; if (this.toneMapped === false) data.toneMapped = false; if (this.fog === false) data.fog = false; if (JSON.stringify(this.userData) !== "{}") 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.alphaToCoverage = source.alphaToCoverage; this.premultipliedAlpha = source.premultipliedAlpha; 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$9 = /* @__PURE__ */ new Vector3(); var _vector2$1 = /* @__PURE__ */ new Vector2(); var BufferAttribute = class { constructor(array, itemSize, normalized) { 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 === true; this.usage = StaticDrawUsage; this.updateRange = { offset: 0, count: -1 }; 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; 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; } copyColorsArray(colors) { const array = this.array; let offset = 0; for (let i = 0, l = colors.length; i < l; i++) { let color = colors[i]; if (color === void 0) { console.warn("THREE.BufferAttribute.copyColorsArray(): color is undefined", i); color = new Color(); } array[offset++] = color.r; array[offset++] = color.g; array[offset++] = color.b; } return this; } copyVector2sArray(vectors) { const array = this.array; let offset = 0; for (let i = 0, l = vectors.length; i < l; i++) { let vector = vectors[i]; if (vector === void 0) { console.warn("THREE.BufferAttribute.copyVector2sArray(): vector is undefined", i); vector = new Vector2(); } array[offset++] = vector.x; array[offset++] = vector.y; } return this; } copyVector3sArray(vectors) { const array = this.array; let offset = 0; for (let i = 0, l = vectors.length; i < l; i++) { let vector = vectors[i]; if (vector === void 0) { console.warn("THREE.BufferAttribute.copyVector3sArray(): vector is undefined", i); vector = new Vector3(); } array[offset++] = vector.x; array[offset++] = vector.y; array[offset++] = vector.z; } return this; } copyVector4sArray(vectors) { const array = this.array; let offset = 0; for (let i = 0, l = vectors.length; i < l; i++) { let vector = vectors[i]; if (vector === void 0) { console.warn("THREE.BufferAttribute.copyVector4sArray(): vector is undefined", i); vector = new Vector4(); } array[offset++] = vector.x; array[offset++] = vector.y; array[offset++] = vector.z; array[offset++] = vector.w; } 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$9.fromBufferAttribute(this, i); _vector$9.applyMatrix3(m2); this.setXYZ(i, _vector$9.x, _vector$9.y, _vector$9.z); } } return this; } applyMatrix4(m2) { for (let i = 0, l = this.count; i < l; i++) { _vector$9.fromBufferAttribute(this, i); _vector$9.applyMatrix4(m2); this.setXYZ(i, _vector$9.x, _vector$9.y, _vector$9.z); } return this; } applyNormalMatrix(m2) { for (let i = 0, l = this.count; i < l; i++) { _vector$9.fromBufferAttribute(this, i); _vector$9.applyNormalMatrix(m2); this.setXYZ(i, _vector$9.x, _vector$9.y, _vector$9.z); } return this; } transformDirection(m2) { for (let i = 0, l = this.count; i < l; i++) { _vector$9.fromBufferAttribute(this, i); _vector$9.transformDirection(m2); this.setXYZ(i, _vector$9.x, _vector$9.y, _vector$9.z); } return this; } set(value, offset = 0) { this.array.set(value, offset); return this; } getX(index5) { return this.array[index5 * this.itemSize]; } setX(index5, x2) { this.array[index5 * this.itemSize] = x2; return this; } getY(index5) { return this.array[index5 * this.itemSize + 1]; } setY(index5, y2) { this.array[index5 * this.itemSize + 1] = y2; return this; } getZ(index5) { return this.array[index5 * this.itemSize + 2]; } setZ(index5, z2) { this.array[index5 * this.itemSize + 2] = z2; return this; } getW(index5) { return this.array[index5 * this.itemSize + 3]; } setW(index5, w) { this.array[index5 * this.itemSize + 3] = w; return this; } setXY(index5, x2, y2) { index5 *= this.itemSize; this.array[index5 + 0] = x2; this.array[index5 + 1] = y2; return this; } setXYZ(index5, x2, y2, z2) { index5 *= this.itemSize; this.array[index5 + 0] = x2; this.array[index5 + 1] = y2; this.array[index5 + 2] = z2; return this; } setXYZW(index5, x2, y2, z2, w) { index5 *= this.itemSize; this.array[index5 + 0] = x2; this.array[index5 + 1] = y2; this.array[index5 + 2] = z2; this.array[index5 + 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$1 = 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$8 = /* @__PURE__ */ new Vector3(); var BufferGeometry = class extends EventDispatcher { constructor() { super(); this.isBufferGeometry = true; Object.defineProperty(this, "id", { value: _id$1++ }); 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(index5) { if (Array.isArray(index5)) { this.index = new (arrayNeedsUint32(index5) ? Uint32BufferAttribute : Uint16BufferAttribute)(index5, 1); } else { this.index = index5; } 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(x2, y2, z2) { _m1.makeTranslation(x2, y2, z2); this.applyMatrix4(_m1); return this; } scale(x2, y2, z2) { _m1.makeScale(x2, y2, z2); 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$8.addVectors(this.boundingBox.min, _box$1.min); this.boundingBox.expandByPoint(_vector$8); _vector$8.addVectors(this.boundingBox.max, _box$1.max); this.boundingBox.expandByPoint(_vector$8); } 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$8.addVectors(_box$1.min, _boxMorphTargets.min); _box$1.expandByPoint(_vector$8); _vector$8.addVectors(_box$1.max, _boxMorphTargets.max); _box$1.expandByPoint(_vector$8); } 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$8.fromBufferAttribute(position, i); maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$8)); } 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$8.fromBufferAttribute(morphAttribute, j); if (morphTargetsRelative) { _offset.fromBufferAttribute(position, j); _vector$8.add(_offset); } maxRadiusSq = Math.max(maxRadiusSq, center.distanceToSquared(_vector$8)); } } } 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 index5 = this.index; const attributes = this.attributes; if (index5 === 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 = index5.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 index5 = 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 (index5) { for (let i = 0, il = index5.count; i < il; i += 3) { const vA = index5.getX(i + 0); const vB = index5.getX(i + 1); const vC = index5.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; } } merge(geometry, offset) { if (!(geometry && geometry.isBufferGeometry)) { console.error("THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.", geometry); return; } if (offset === void 0) { offset = 0; console.warn("THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge."); } const attributes = this.attributes; for (const key in attributes) { if (geometry.attributes[key] === void 0) continue; const attribute1 = attributes[key]; const attributeArray1 = attribute1.array; const attribute2 = geometry.attributes[key]; const attributeArray2 = attribute2.array; const attributeOffset = attribute2.itemSize * offset; const length = Math.min(attributeArray2.length, attributeArray1.length - attributeOffset); for (let i = 0, j = attributeOffset; i < length; i++, j++) { attributeArray1[j] = attributeArray2[i]; } } return this; } normalizeNormals() { const normals = this.attributes.normal; for (let i = 0, il = normals.count; i < il; i++) { _vector$8.fromBufferAttribute(normals, i); _vector$8.normalize(); normals.setXYZ(i, _vector$8.x, _vector$8.y, _vector$8.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 index5 = 0, index22 = 0; for (let i = 0, l = indices2.length; i < l; i++) { if (attribute.isInterleavedBufferAttribute) { index5 = indices2[i] * attribute.data.stride + attribute.offset; } else { index5 = indices2[i] * itemSize; } for (let j = 0; j < itemSize; j++) { array2[index22++] = array[index5++]; } } 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.5, 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 index5 = this.index; if (index5 !== null) { data.data.index = { type: index5.array.constructor.name, array: Array.prototype.slice.call(index5.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 index5 = source.index; if (index5 !== null) { this.setIndex(index5.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; if (source.parameters !== void 0) this.parameters = Object.assign({}, source.parameters); return this; } dispose() { this.dispatchEvent({ type: "dispose" }); } }; var _inverseMatrix$2 = /* @__PURE__ */ new Matrix4(); var _ray$2 = /* @__PURE__ */ new Ray(); var _sphere$3 = /* @__PURE__ */ new Sphere(); var _vA$1 = /* @__PURE__ */ new Vector3(); var _vB$1 = /* @__PURE__ */ new Vector3(); var _vC$1 = /* @__PURE__ */ new Vector3(); var _tempA = /* @__PURE__ */ new Vector3(); var _tempB = /* @__PURE__ */ new Vector3(); var _tempC = /* @__PURE__ */ new Vector3(); var _morphA = /* @__PURE__ */ new Vector3(); var _morphB = /* @__PURE__ */ new Vector3(); var _morphC = /* @__PURE__ */ new Vector3(); var _uvA$1 = /* @__PURE__ */ new Vector2(); var _uvB$1 = /* @__PURE__ */ new Vector2(); var _uvC$1 = /* @__PURE__ */ new Vector2(); 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 = 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; } } } } 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$3.copy(geometry.boundingSphere); _sphere$3.applyMatrix4(matrixWorld); if (raycaster.ray.intersectsSphere(_sphere$3) === false) return; _inverseMatrix$2.copy(matrixWorld).invert(); _ray$2.copy(raycaster.ray).applyMatrix4(_inverseMatrix$2); if (geometry.boundingBox !== null) { if (_ray$2.intersectsBox(geometry.boundingBox) === false) return; } let intersection; const index5 = geometry.index; const position = geometry.attributes.position; const morphPosition = geometry.morphAttributes.position; const morphTargetsRelative = geometry.morphTargetsRelative; const uv = geometry.attributes.uv; const uv2 = geometry.attributes.uv2; const groups = geometry.groups; const drawRange = geometry.drawRange; if (index5 !== 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(index5.count, Math.min(group.start + group.count, drawRange.start + drawRange.count)); for (let j = start, jl = end; j < jl; j += 3) { const a2 = index5.getX(j); const b = index5.getX(j + 1); const c2 = index5.getX(j + 2); intersection = checkBufferGeometryIntersection(this, groupMaterial, raycaster, _ray$2, position, morphPosition, morphTargetsRelative, uv, uv2, 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(index5.count, drawRange.start + drawRange.count); for (let i = start, il = end; i < il; i += 3) { const a2 = index5.getX(i); const b = index5.getX(i + 1); const c2 = index5.getX(i + 2); intersection = checkBufferGeometryIntersection(this, material, raycaster, _ray$2, position, morphPosition, morphTargetsRelative, uv, uv2, 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 = checkBufferGeometryIntersection(this, groupMaterial, raycaster, _ray$2, position, morphPosition, morphTargetsRelative, uv, uv2, 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 = checkBufferGeometryIntersection(this, material, raycaster, _ray$2, position, morphPosition, morphTargetsRelative, uv, uv2, 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 !== DoubleSide, 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 checkBufferGeometryIntersection(object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a2, b, c2) { _vA$1.fromBufferAttribute(position, a2); _vB$1.fromBufferAttribute(position, b); _vC$1.fromBufferAttribute(position, c2); const morphInfluences = object.morphTargetInfluences; if (morphPosition && morphInfluences) { _morphA.set(0, 0, 0); _morphB.set(0, 0, 0); _morphC.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, a2); _tempB.fromBufferAttribute(morphAttribute, b); _tempC.fromBufferAttribute(morphAttribute, c2); if (morphTargetsRelative) { _morphA.addScaledVector(_tempA, influence); _morphB.addScaledVector(_tempB, influence); _morphC.addScaledVector(_tempC, influence); } else { _morphA.addScaledVector(_tempA.sub(_vA$1), influence); _morphB.addScaledVector(_tempB.sub(_vB$1), influence); _morphC.addScaledVector(_tempC.sub(_vC$1), influence); } } _vA$1.add(_morphA); _vB$1.add(_morphB); _vC$1.add(_morphC); } if (object.isSkinnedMesh) { object.boneTransform(a2, _vA$1); object.boneTransform(b, _vB$1); object.boneTransform(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.getUV(_intersectionPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()); } if (uv2) { _uvA$1.fromBufferAttribute(uv2, a2); _uvB$1.fromBufferAttribute(uv2, b); _uvC$1.fromBufferAttribute(uv2, c2); intersection.uv2 = Triangle.getUV(_intersectionPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2()); } 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 y2 = iy * segmentHeight - heightHalf; for (let ix = 0; ix < gridX1; ix++) { const x2 = ix * segmentWidth - widthHalf; vector[u] = x2 * udir; vector[v] = y2 * 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; } } 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)) { 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; } 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.extensions = { derivatives: false, fragDepth: false, drawBuffers: false, shaderTextureLOD: false }; this.defaultAttributeValues = { "color": [1, 1, 1], "uv": [0, 0], "uv2": [0, 0] }; this.index0AttributeName = void 0; this.uniformsNeedUpdate = false; this.glslVersion = null; if (parameters !== void 0) { if (parameters.attributes !== void 0) { console.error("THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead."); } 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; 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(); } copy(source, recursive) { super.copy(source, recursive); this.matrixWorldInverse.copy(source.matrixWorldInverse); this.projectionMatrix.copy(source.projectionMatrix); this.projectionMatrixInverse.copy(source.projectionMatrixInverse); return this; } getWorldDirection(target) { this.updateWorldMatrix(true, false); const e = this.matrixWorld.elements; return target.set(-e[8], -e[9], -e[10]).normalize(); } 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(fov2 = 50, aspect2 = 1, near = 0.1, far = 2e3) { super(); this.isPerspectiveCamera = true; this.type = "PerspectiveCamera"; this.fov = fov2; this.zoom = 1; this.near = near; this.far = far; this.focus = 10; this.aspect = aspect2; 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; } setFocalLength(focalLength) { const vExtentSlope = 0.5 * this.getFilmHeight() / focalLength; this.fov = RAD2DEG * 2 * Math.atan(vExtentSlope); this.updateProjectionMatrix(); } 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); } setViewOffset(fullWidth, fullHeight, x2, y2, 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 = x2; this.view.offsetY = y2; 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.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"; if (renderTarget.isWebGLCubeRenderTarget !== true) { console.error("THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter."); return; } this.renderTarget = renderTarget; const cameraPX = new PerspectiveCamera(fov, aspect, near, far); cameraPX.layers = this.layers; cameraPX.up.set(0, -1, 0); cameraPX.lookAt(new Vector3(1, 0, 0)); this.add(cameraPX); const cameraNX = new PerspectiveCamera(fov, aspect, near, far); cameraNX.layers = this.layers; cameraNX.up.set(0, -1, 0); cameraNX.lookAt(new Vector3(-1, 0, 0)); this.add(cameraNX); const cameraPY = new PerspectiveCamera(fov, aspect, near, far); cameraPY.layers = this.layers; cameraPY.up.set(0, 0, 1); cameraPY.lookAt(new Vector3(0, 1, 0)); this.add(cameraPY); const cameraNY = new PerspectiveCamera(fov, aspect, near, far); cameraNY.layers = this.layers; cameraNY.up.set(0, 0, -1); cameraNY.lookAt(new Vector3(0, -1, 0)); this.add(cameraNY); const cameraPZ = new PerspectiveCamera(fov, aspect, near, far); cameraPZ.layers = this.layers; cameraPZ.up.set(0, -1, 0); cameraPZ.lookAt(new Vector3(0, 0, 1)); this.add(cameraPZ); const cameraNZ = new PerspectiveCamera(fov, aspect, near, far); cameraNZ.layers = this.layers; cameraNZ.up.set(0, -1, 0); cameraNZ.lookAt(new Vector3(0, 0, -1)); this.add(cameraNZ); } update(renderer3, scene3) { if (this.parent === null) this.updateMatrixWorld(); const renderTarget = this.renderTarget; const [cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ] = this.children; const currentRenderTarget = renderer3.getRenderTarget(); const currentToneMapping = renderer3.toneMapping; const currentXrEnabled = renderer3.xr.enabled; renderer3.toneMapping = NoToneMapping; renderer3.xr.enabled = false; const generateMipmaps = renderTarget.texture.generateMipmaps; renderTarget.texture.generateMipmaps = false; renderer3.setRenderTarget(renderTarget, 0); renderer3.render(scene3, cameraPX); renderer3.setRenderTarget(renderTarget, 1); renderer3.render(scene3, cameraNX); renderer3.setRenderTarget(renderTarget, 2); renderer3.render(scene3, cameraPY); renderer3.setRenderTarget(renderTarget, 3); renderer3.render(scene3, cameraNY); renderer3.setRenderTarget(renderTarget, 4); renderer3.render(scene3, cameraPZ); renderTarget.texture.generateMipmaps = generateMipmaps; renderer3.setRenderTarget(renderTarget, 5); renderer3.render(scene3, cameraNZ); renderer3.setRenderTarget(currentRenderTarget); renderer3.toneMapping = currentToneMapping; renderer3.xr.enabled = currentXrEnabled; renderTarget.texture.needsPMREMUpdate = true; } }; var CubeTexture = class extends Texture { constructor(images, mapping, wrapS, wrapT, magFilter, minFilter, format2, type, anisotropy, encoding) { images = images !== void 0 ? images : []; mapping = mapping !== void 0 ? mapping : CubeReflectionMapping; super(images, mapping, wrapS, wrapT, magFilter, minFilter, format2, type, anisotropy, encoding); this.isCubeTexture = true; this.flipY = false; } get images() { return this.image; } set images(value) { this.image = value; } }; var WebGLCubeRenderTarget = class extends WebGLRenderTarget { constructor(size, options = {}) { super(size, size, options); this.isWebGLCubeRenderTarget = true; const image = { width: size, height: size, depth: 1 }; const images = [image, image, image, image, image, image]; this.texture = new CubeTexture(images, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding); 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.encoding = texture.encoding; this.texture.generateMipmaps = texture.generateMipmaps; this.texture.minFilter = texture.minFilter; this.texture.magFilter = texture.magFilter; const shader = { uniforms: { tEquirect: { value: null } }, vertexShader: ` 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: ` 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(x2, y2, z2, w) { this.normal.set(x2, y2, z2); 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(this.normal).multiplyScalar(-this.distanceToPoint(point)).add(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(direction).multiplyScalar(t).add(line.start); } 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$2 = /* @__PURE__ */ new Sphere(); var _vector$7 = /* @__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) { 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(); planes[5].setComponents(me3 + me2, me7 + me6, me11 + me10, me15 + me14).normalize(); return this; } intersectsObject(object) { const geometry = object.geometry; if (geometry.boundingSphere === null) geometry.computeBoundingSphere(); _sphere$2.copy(geometry.boundingSphere).applyMatrix4(object.matrixWorld); return this.intersectsSphere(_sphere$2); } intersectsSprite(sprite) { _sphere$2.center.set(0, 0, 0); _sphere$2.radius = 0.7071067811865476; _sphere$2.applyMatrix4(sprite.matrixWorld); return this.intersectsSphere(_sphere$2); } 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$7.x = plane.normal.x > 0 ? box.max.x : box.min.x; _vector$7.y = plane.normal.y > 0 ? box.max.y : box.min.y; _vector$7.z = plane.normal.z > 0 ? box.max.z : box.min.z; if (plane.distanceToPoint(_vector$7) < 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 = 5126; } else if (array instanceof Uint16Array) { if (attribute.isFloat16BufferAttribute) { if (isWebGL2) { type = 5131; } else { throw new Error("THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2."); } } else { type = 5123; } } else if (array instanceof Int16Array) { type = 5122; } else if (array instanceof Uint32Array) { type = 5125; } else if (array instanceof Int32Array) { type = 5124; } else if (array instanceof Int8Array) { type = 5120; } else if (array instanceof Uint8Array) { type = 5121; } else if (array instanceof Uint8ClampedArray) { type = 5121; } 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; } } 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 y2 = iy * segment_height - height_half; for (let ix = 0; ix < gridX1; ix++) { const x2 = ix * segment_width - width_half; vertices.push(x2, -y2, 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)); } static fromJSON(data) { return new PlaneGeometry(data.width, data.height, data.widthSegments, data.heightSegments); } }; var alphamap_fragment = "#ifdef USE_ALPHAMAP\n diffuseColor.a *= texture2D( alphaMap, vUv ).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, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n reflectedLight.indirectDiffuse *= ambientOcclusion;\n #if defined( USE_ENVMAP ) && defined( STANDARD )\n float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\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 );"; var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n vec3 objectTangent = vec3( tangent.xyz );\n#endif"; var bsdfs = "vec3 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}\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}\nvec3 BRDF_GGX( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 f0, const in float f90, const in float 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 float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n float D = D_GGX( alpha, dotNH );\n return F * ( V * D );\n}\n#ifdef USE_IRIDESCENCE\n vec3 BRDF_GGX_Iridescence( const in vec3 lightDir, const in vec3 viewDir, const in vec3 normal, const in vec3 f0, const in float f90, const in float iridescence, const in vec3 iridescenceFresnel, const in float 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 = mix( F_Schlick( f0, f90, dotVH ), iridescenceFresnel, iridescence );\n float V = V_GGX_SmithCorrelated( alpha, dotNL, dotNV );\n float D = D_GGX( alpha, dotNH );\n return F * ( V * D );\n }\n#endif\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}\nfloat 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}\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"; 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 R21 = R12;\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( vUv );\n vec2 dSTdy = dFdy( vUv );\n float Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n float dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n float dBy = bumpScale * texture2D( bumpMap, vUv + 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_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};\nstruct GeometricContext {\n vec3 position;\n vec3 normal;\n vec3 viewDir;\n#ifdef USE_CLEARCOAT\n vec3 clearcoatNormal;\n#endif\n};\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}"; 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 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 r0 1.0\n #define v0 0.339\n #define m0 - 2.0\n #define r1 0.8\n #define v1 0.276\n #define m1 - 1.0\n #define r4 0.4\n #define v4 0.046\n #define m4 2.0\n #define r5 0.305\n #define v5 0.016\n #define m5 3.0\n #define r6 0.21\n #define v6 0.0038\n #define m6 4.0\n float roughnessToMip( float roughness ) {\n float mip = 0.0;\n if ( roughness >= r1 ) {\n mip = ( r0 - roughness ) * ( m1 - m0 ) / ( r0 - r1 ) + m0;\n } else if ( roughness >= r4 ) {\n mip = ( r1 - roughness ) * ( m4 - m1 ) / ( r1 - r4 ) + m1;\n } else if ( roughness >= r5 ) {\n mip = ( r4 - roughness ) * ( m5 - m4 ) / ( r4 - r5 ) + m4;\n } else if ( roughness >= r6 ) {\n mip = ( r5 - roughness ) * ( m6 - m5 ) / ( r5 - r6 ) + 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 ), 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, vUv ).x * displacementScale + displacementBias );\n#endif"; var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n vec4 emissiveColor = texture2D( emissiveMap, vUv );\n totalEmissiveRadiance *= emissiveColor.rgb;\n#endif"; var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n uniform sampler2D emissiveMap;\n#endif"; var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );"; var encodings_pars_fragment = "vec4 LinearToLinear( in vec4 value ) {\n return value;\n}\nvec4 LinearTosRGB( 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}"; 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 #elif defined( ENVMAP_TYPE_CUBE_UV )\n vec4 envColor = textureCubeUV( envMap, reflectVec, 0.0 );\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 )\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 )\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 return ( coord.x < 0.7 ) ? vec3( 0.7 ) : vec3( 1.0 );\n #endif\n}"; var lightmap_fragment = "#ifdef USE_LIGHTMAP\n vec4 lightMapTexel = texture2D( lightMap, vUv2 );\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_vertex = "vec3 diffuse = vec3( 1.0 );\nGeometricContext geometry;\ngeometry.position = mvPosition.xyz;\ngeometry.normal = normalize( transformedNormal );\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( -mvPosition.xyz );\nGeometricContext backGeometry;\nbackGeometry.position = geometry.position;\nbackGeometry.normal = -geometry.normal;\nbackGeometry.viewDir = geometry.viewDir;\nvLightFront = vec3( 0.0 );\nvIndirectFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\n vLightBack = vec3( 0.0 );\n vIndirectBack = vec3( 0.0 );\n#endif\nIncidentLight directLight;\nfloat dotNL;\nvec3 directLightColor_Diffuse;\nvIndirectFront += getAmbientLightIrradiance( ambientLightColor );\nvIndirectFront += getLightProbeIrradiance( lightProbe, geometry.normal );\n#ifdef DOUBLE_SIDED\n vIndirectBack += getAmbientLightIrradiance( ambientLightColor );\n vIndirectBack += getLightProbeIrradiance( lightProbe, backGeometry.normal );\n#endif\n#if NUM_POINT_LIGHTS > 0\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n getPointLightInfo( pointLights[ i ], geometry, directLight );\n dotNL = dot( geometry.normal, directLight.direction );\n directLightColor_Diffuse = directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( - dotNL ) * directLightColor_Diffuse;\n #endif\n }\n #pragma unroll_loop_end\n#endif\n#if NUM_SPOT_LIGHTS > 0\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n getSpotLightInfo( spotLights[ i ], geometry, directLight );\n dotNL = dot( geometry.normal, directLight.direction );\n directLightColor_Diffuse = directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( - dotNL ) * directLightColor_Diffuse;\n #endif\n }\n #pragma unroll_loop_end\n#endif\n#if NUM_DIR_LIGHTS > 0\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n getDirectionalLightInfo( directionalLights[ i ], geometry, directLight );\n dotNL = dot( geometry.normal, directLight.direction );\n directLightColor_Diffuse = directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( - dotNL ) * directLightColor_Diffuse;\n #endif\n }\n #pragma unroll_loop_end\n#endif\n#if NUM_HEMI_LIGHTS > 0\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n vIndirectFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry.normal );\n #ifdef DOUBLE_SIDED\n vIndirectBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry.normal );\n #endif\n }\n #pragma unroll_loop_end\n#endif"; var lights_pars_begin = "uniform bool receiveShadow;\nuniform vec3 ambientLightColor;\nuniform vec3 lightProbe[ 9 ];\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 ( PHYSICALLY_CORRECT_LIGHTS )\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 #else\n if ( cutoffDistance > 0.0 && decayExponent > 0.0 ) {\n return pow( saturate( - lightDistance / cutoffDistance + 1.0 ), decayExponent );\n }\n return 1.0;\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, const in GeometricContext geometry, 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 GeometricContext geometry, out IncidentLight light ) {\n vec3 lVector = pointLight.position - geometry.position;\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 GeometricContext geometry, out IncidentLight light ) {\n vec3 lVector = spotLight.position - geometry.position;\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 = "#if defined( USE_ENVMAP )\n vec3 getIBLIrradiance( const in vec3 normal ) {\n #if defined( 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 #if defined( 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#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 GeometricContext geometry, const in ToonMaterial material, inout ReflectedLight reflectedLight ) {\n vec3 irradiance = getGradientIrradiance( geometry.normal, directLight.direction ) * directLight.color;\n reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Toon( const in vec3 irradiance, const in GeometricContext geometry, 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\n#define Material_LightProbeLOD( material ) (0)"; 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 GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n float dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n vec3 irradiance = dotNL * directLight.color;\n reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n reflectedLight.directSpecular += irradiance * BRDF_BlinnPhong( directLight.direction, geometry.viewDir, geometry.normal, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in GeometricContext geometry, 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\n#define Material_LightProbeLOD( material ) (0)"; var lights_physical_fragment = "PhysicalMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nvec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );\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 #ifdef SPECULAR\n float specularIntensityFactor = specularIntensity;\n vec3 specularColorFactor = specularColor;\n #ifdef USE_SPECULARINTENSITYMAP\n specularIntensityFactor *= texture2D( specularIntensityMap, vUv ).a;\n #endif\n #ifdef USE_SPECULARCOLORMAP\n specularColorFactor *= texture2D( specularColorMap, vUv ).rgb;\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( ( ior - 1.0 ) / ( 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, vUv ).x;\n #endif\n #ifdef USE_CLEARCOAT_ROUGHNESSMAP\n material.clearcoatRoughness *= texture2D( clearcoatRoughnessMap, vUv ).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, vUv ).r;\n #endif\n #ifdef USE_IRIDESCENCE_THICKNESSMAP\n material.iridescenceThickness = (iridescenceThicknessMaximum - iridescenceThicknessMinimum) * texture2D( iridescenceThicknessMap, vUv ).g + iridescenceThicknessMinimum;\n #else\n material.iridescenceThickness = iridescenceThicknessMaximum;\n #endif\n#endif\n#ifdef USE_SHEEN\n material.sheenColor = sheenColor;\n #ifdef USE_SHEENCOLORMAP\n material.sheenColor *= texture2D( sheenColorMap, vUv ).rgb;\n #endif\n material.sheenRoughness = clamp( sheenRoughness, 0.07, 1.0 );\n #ifdef USE_SHEENROUGHNESSMAP\n material.sheenRoughness *= texture2D( sheenRoughnessMap, vUv ).a;\n #endif\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};\nvec3 clearcoatSpecular = vec3( 0.0 );\nvec3 sheenSpecular = vec3( 0.0 );\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 GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n vec3 normal = geometry.normal;\n vec3 viewDir = geometry.viewDir;\n vec3 position = geometry.position;\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 GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight ) {\n float dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n vec3 irradiance = dotNL * directLight.color;\n #ifdef USE_CLEARCOAT\n float dotNLcc = saturate( dot( geometry.clearcoatNormal, directLight.direction ) );\n vec3 ccIrradiance = dotNLcc * directLight.color;\n clearcoatSpecular += ccIrradiance * BRDF_GGX( directLight.direction, geometry.viewDir, geometry.clearcoatNormal, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n #endif\n #ifdef USE_SHEEN\n sheenSpecular += irradiance * BRDF_Sheen( directLight.direction, geometry.viewDir, geometry.normal, material.sheenColor, material.sheenRoughness );\n #endif\n #ifdef USE_IRIDESCENCE\n reflectedLight.directSpecular += irradiance * BRDF_GGX_Iridescence( directLight.direction, geometry.viewDir, geometry.normal, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnel, material.roughness );\n #else\n reflectedLight.directSpecular += irradiance * BRDF_GGX( directLight.direction, geometry.viewDir, geometry.normal, material.specularColor, material.specularF90, material.roughness );\n #endif\n reflectedLight.directDiffuse += irradiance * BRDF_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectDiffuse_Physical( const in vec3 irradiance, const in GeometricContext geometry, 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 GeometricContext geometry, const in PhysicalMaterial material, inout ReflectedLight reflectedLight) {\n #ifdef USE_CLEARCOAT\n clearcoatSpecular += clearcoatRadiance * EnvironmentBRDF( geometry.clearcoatNormal, geometry.viewDir, material.clearcoatF0, material.clearcoatF90, material.clearcoatRoughness );\n #endif\n #ifdef USE_SHEEN\n sheenSpecular += irradiance * material.sheenColor * IBLSheenBRDF( geometry.normal, geometry.viewDir, 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( geometry.normal, geometry.viewDir, material.specularColor, material.specularF90, material.iridescence, material.iridescenceFresnel, material.roughness, singleScattering, multiScattering );\n #else\n computeMultiscattering( geometry.normal, geometry.viewDir, 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 = "\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );\n#ifdef USE_CLEARCOAT\n geometry.clearcoatNormal = clearcoatNormal;\n#endif\n#ifdef USE_IRIDESCENCE\n float dotNVi = saturate( dot( normal, geometry.viewDir ) );\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, geometry, directLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_POINT_LIGHT_SHADOWS )\n pointLightShadow = pointLightShadows[ i ];\n directLight.color *= all( bvec2( 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, geometry, material, reflectedLight );\n }\n #pragma unroll_loop_end\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n SpotLight spotLight;\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, geometry, directLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_SPOT_LIGHT_SHADOWS )\n spotLightShadow = spotLightShadows[ i ];\n directLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( spotShadowMap[ i ], spotLightShadow.shadowMapSize, spotLightShadow.shadowBias, spotLightShadow.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( directLight, geometry, 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, geometry, directLight );\n #if defined( USE_SHADOWMAP ) && ( UNROLLED_LOOP_INDEX < NUM_DIR_LIGHT_SHADOWS )\n directionalLightShadow = directionalLightShadows[ i ];\n directLight.color *= all( bvec2( directLight.visible, receiveShadow ) ) ? getShadow( directionalShadowMap[ i ], directionalLightShadow.shadowMapSize, directionalLightShadow.shadowBias, directionalLightShadow.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( directLight, geometry, 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, geometry, 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 irradiance += getLightProbeIrradiance( lightProbe, geometry.normal );\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 ], geometry.normal );\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, vUv2 );\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( geometry.normal );\n #endif\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n radiance += getIBLRadiance( geometry.viewDir, geometry.normal, material.roughness );\n #ifdef USE_CLEARCOAT\n clearcoatRadiance += getIBLRadiance( geometry.viewDir, geometry.clearcoatNormal, material.clearcoatRoughness );\n #endif\n#endif"; var lights_fragment_end = "#if defined( RE_IndirectDiffuse )\n RE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n#endif\n#if defined( RE_IndirectSpecular )\n RE_IndirectSpecular( radiance, iblIrradiance, clearcoatRadiance, geometry, 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, vUv );\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 #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 vec2 uv = ( uvTransform * vec3( gl_PointCoord.x, 1.0 - gl_PointCoord.y, 1 ) ).xy;\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_MAP ) || defined( USE_ALPHAMAP )\n uniform mat3 uvTransform;\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, vUv );\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 = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n vec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n vec3 normal = normalize( cross( fdx, fdy ) );\n#else\n vec3 normal = normalize( vNormal );\n #ifdef DOUBLE_SIDED\n normal = normal * faceDirection;\n #endif\n #ifdef USE_TANGENT\n vec3 tangent = normalize( vTangent );\n vec3 bitangent = normalize( vBitangent );\n #ifdef DOUBLE_SIDED\n tangent = tangent * faceDirection;\n bitangent = bitangent * faceDirection;\n #endif\n #if defined( TANGENTSPACE_NORMALMAP ) || defined( USE_CLEARCOAT_NORMALMAP )\n mat3 vTBN = mat3( tangent, bitangent, normal );\n #endif\n #endif\n#endif\nvec3 geometryNormal = normal;"; var normal_fragment_maps = "#ifdef OBJECTSPACE_NORMALMAP\n normal = texture2D( normalMap, vUv ).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( TANGENTSPACE_NORMALMAP )\n vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n mapN.xy *= normalScale;\n #ifdef USE_TANGENT\n normal = normalize( vTBN * mapN );\n #else\n normal = perturbNormal2Arb( - vViewPosition, normal, mapN, faceDirection );\n #endif\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 OBJECTSPACE_NORMALMAP\n uniform mat3 normalMatrix;\n#endif\n#if ! defined ( USE_TANGENT ) && ( defined ( TANGENTSPACE_NORMALMAP ) || defined ( USE_CLEARCOAT_NORMALMAP ) )\n vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm, vec3 mapN, float faceDirection ) {\n vec3 q0 = dFdx( eye_pos.xyz );\n vec3 q1 = dFdy( eye_pos.xyz );\n vec2 st0 = dFdx( vUv.st );\n vec2 st1 = dFdy( vUv.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 : faceDirection * inversesqrt( det );\n return normalize( T * ( mapN.x * scale ) + B * ( mapN.y * scale ) + N * mapN.z );\n }\n#endif"; var clearcoat_normal_fragment_begin = "#ifdef USE_CLEARCOAT\n vec3 clearcoatNormal = geometryNormal;\n#endif"; var clearcoat_normal_fragment_maps = "#ifdef USE_CLEARCOAT_NORMALMAP\n vec3 clearcoatMapN = texture2D( clearcoatNormalMap, vUv ).xyz * 2.0 - 1.0;\n clearcoatMapN.xy *= clearcoatNormalScale;\n #ifdef USE_TANGENT\n clearcoatNormal = normalize( vTBN * clearcoatMapN );\n #else\n clearcoatNormal = perturbNormal2Arb( - vViewPosition, clearcoatNormal, clearcoatMapN, faceDirection );\n #endif\n#endif"; var clearcoat_pars_fragment = "#ifdef USE_CLEARCOATMAP\n uniform sampler2D clearcoatMap;\n#endif\n#ifdef USE_CLEARCOAT_ROUGHNESSMAP\n uniform sampler2D clearcoatRoughnessMap;\n#endif\n#ifdef USE_CLEARCOAT_NORMALMAP\n uniform sampler2D clearcoatNormalMap;\n uniform vec2 clearcoatNormalScale;\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 output_fragment = "#ifdef OPAQUE\ndiffuseColor.a = 1.0;\n#endif\n#ifdef USE_TRANSMISSION\ndiffuseColor.a *= transmissionAlpha + 0.1;\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}\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 linearClipZ, const in float near, const in float far ) {\n return linearClipZ * ( 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 invClipZ, const in float near, const in float far ) {\n return ( near * far ) / ( ( far - near ) * invClipZ - 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, vUv );\n roughnessFactor *= texelRoughness.g;\n#endif"; var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n uniform sampler2D roughnessMap;\n#endif"; var shadowmap_pars_fragment = "#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 varying vec4 vSpotShadowCoord[ 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 bvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n bool inFrustum = all( inFrustumVec );\n bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n bool frustumTest = all( frustumTestVec );\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 = "#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 uniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHT_SHADOWS ];\n varying vec4 vSpotShadowCoord[ 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 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 = "#ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHT_SHADOWS > 0 || NUM_SPOT_LIGHT_SHADOWS > 0 || NUM_POINT_LIGHT_SHADOWS > 0\n vec3 shadowWorldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n vec4 shadowWorldPosition;\n #endif\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_SPOT_LIGHT_SHADOWS > 0\n #pragma unroll_loop_start\n for ( int i = 0; i < NUM_SPOT_LIGHT_SHADOWS; i ++ ) {\n shadowWorldPosition = worldPosition + vec4( shadowWorldNormal * spotLightShadows[ i ].shadowNormalBias, 0 );\n vSpotShadowCoord[ i ] = spotShadowMatrix[ 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"; 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, vSpotShadowCoord[ 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, vUv );\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 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 float transmissionAlpha = 1.0;\n float transmissionFactor = transmission;\n float thicknessFactor = thickness;\n #ifdef USE_TRANSMISSIONMAP\n transmissionFactor *= texture2D( transmissionMap, vUv ).r;\n #endif\n #ifdef USE_THICKNESSMAP\n thicknessFactor *= texture2D( thicknessMap, vUv ).g;\n #endif\n vec3 pos = vWorldPosition;\n vec3 v = normalize( cameraPosition - pos );\n vec3 n = inverseTransformDirection( normal, viewMatrix );\n vec4 transmission = getIBLVolumeRefraction(\n n, v, roughnessFactor, material.diffuseColor, material.specularColor, material.specularF90,\n pos, modelMatrix, viewMatrix, projectionMatrix, ior, thicknessFactor,\n attenuationColor, attenuationDistance );\n totalDiffuse = mix( totalDiffuse, transmission.rgb, transmissionFactor );\n transmissionAlpha = mix( transmissionAlpha, transmission.a, transmissionFactor );\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 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 framebufferLod = log2( transmissionSamplerSize.x ) * applyIorToRoughness( roughness, ior );\n #ifdef texture2DLodEXT\n return texture2DLodEXT( transmissionSamplerMap, fragCoord.xy, framebufferLod );\n #else\n return texture2D( transmissionSamplerMap, fragCoord.xy, framebufferLod );\n #endif\n }\n vec3 applyVolumeAttenuation( const in vec3 radiance, const in float transmissionDistance, const in vec3 attenuationColor, const in float attenuationDistance ) {\n if ( attenuationDistance == 0.0 ) {\n return radiance;\n } else {\n vec3 attenuationCoefficient = -log( attenuationColor ) / attenuationDistance;\n vec3 transmittance = exp( - attenuationCoefficient * transmissionDistance ); return transmittance * radiance;\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 attenuatedColor = applyVolumeAttenuation( transmittedLight.rgb, length( transmissionRay ), attenuationColor, attenuationDistance );\n vec3 F = EnvironmentBRDF( n, v, specularColor, specularF90, roughness );\n return vec4( ( 1.0 - F ) * attenuatedColor * diffuseColor, transmittedLight.a );\n }\n#endif"; var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n varying vec2 vUv;\n#endif"; var uv_pars_vertex = "#ifdef USE_UV\n #ifdef UVS_VERTEX_ONLY\n vec2 vUv;\n #else\n varying vec2 vUv;\n #endif\n uniform mat3 uvTransform;\n#endif"; var uv_vertex = "#ifdef USE_UV\n vUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif"; var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n varying vec2 vUv2;\n#endif"; var uv2_pars_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n attribute vec2 uv2;\n varying vec2 vUv2;\n uniform mat3 uv2Transform;\n#endif"; var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n vUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif"; var worldpos_vertex = "#if defined( USE_ENVMAP ) || defined( DISTANCE ) || defined ( USE_SHADOWMAP ) || defined ( USE_TRANSMISSION )\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$g = "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$g = "uniform sampler2D t2D;\nvarying vec2 vUv;\nvoid main() {\n gl_FragColor = texture2D( t2D, vUv );\n #ifdef DECODE_VIDEO_TEXTURE\n gl_FragColor = vec4( mix( pow( gl_FragColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), gl_FragColor.rgb * 0.0773993808, vec3( lessThanEqual( gl_FragColor.rgb, vec3( 0.04045 ) ) ) ), gl_FragColor.w );\n #endif\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 = "#include \nuniform float opacity;\nvarying vec3 vWorldDirection;\n#include \nvoid main() {\n vec3 vReflect = vWorldDirection;\n #include \n gl_FragColor = envColor;\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 \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 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 \nvoid main () {\n #include \n vec4 diffuseColor = vec4( 1.0 );\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 \nvoid main() {\n vLineDistance = scale * lineDistance;\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 \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 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 \n#include \nvoid main() {\n #include \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 \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 ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );\n #ifdef USE_LIGHTMAP\n vec4 lightMapTexel = texture2D( lightMap, vUv2 );\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 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n varying vec3 vLightBack;\n varying vec3 vIndirectBack;\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 \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 #include \n #include \n #include \n}"; var fragment$9 = "uniform vec3 diffuse;\nuniform vec3 emissive;\nuniform float opacity;\nvarying vec3 vLightFront;\nvarying vec3 vIndirectFront;\n#ifdef DOUBLE_SIDED\n varying vec3 vLightBack;\n varying vec3 vIndirectBack;\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 \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 #ifdef DOUBLE_SIDED\n reflectedLight.indirectDiffuse += ( gl_FrontFacing ) ? vIndirectFront : vIndirectBack;\n #else\n reflectedLight.indirectDiffuse += vIndirectFront;\n #endif\n #include \n reflectedLight.indirectDiffuse *= BRDF_Lambert( diffuseColor.rgb );\n #ifdef DOUBLE_SIDED\n reflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;\n #else\n reflectedLight.directDiffuse = vLightFront;\n #endif\n reflectedLight.directDiffuse *= BRDF_Lambert( diffuseColor.rgb ) * getShadowMask();\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 \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 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( TANGENTSPACE_NORMALMAP )\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( TANGENTSPACE_NORMALMAP )\n vViewPosition = - mvPosition.xyz;\n#endif\n}"; var fragment$7 = "#define NORMAL\nuniform float opacity;\n#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP )\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 \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 #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 \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 + 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 \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 #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 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 SPECULAR\n uniform float specularIntensity;\n uniform vec3 specularColor;\n #ifdef USE_SPECULARINTENSITYMAP\n uniform sampler2D specularIntensityMap;\n #endif\n #ifdef USE_SPECULARCOLORMAP\n uniform sampler2D specularColorMap;\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_SHEENCOLORMAP\n uniform sampler2D sheenColorMap;\n #endif\n #ifdef USE_SHEENROUGHNESSMAP\n uniform sampler2D sheenRoughnessMap;\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 \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 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( geometry.clearcoatNormal, geometry.viewDir ) );\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$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 \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 #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 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 \nvoid main() {\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 \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 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 \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}"; var fragment$2 = "uniform vec3 color;\nuniform float opacity;\n#include \n#include \n#include \n#include \n#include \n#include \n#include \nvoid main() {\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 \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 outgoingLight = diffuseColor.rgb;\n #include \n #include \n #include \n #include \n}"; var ShaderChunk = { 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, encodings_fragment, encodings_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_vertex, 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, output_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, uv2_pars_fragment, uv2_pars_vertex, uv2_vertex, worldpos_vertex, background_vert: vertex$g, background_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 }, uvTransform: { value: /* @__PURE__ */ new Matrix3() }, uv2Transform: { value: /* @__PURE__ */ new Matrix3() }, alphaMap: { value: null }, alphaTest: { value: 0 } }, specularmap: { specularMap: { value: null } }, envmap: { envMap: { value: null }, flipEnvMap: { value: -1 }, reflectivity: { value: 1 }, ior: { value: 1.5 }, refractionRatio: { value: 0.98 } }, aomap: { aoMap: { value: null }, aoMapIntensity: { value: 1 } }, lightmap: { lightMap: { value: null }, lightMapIntensity: { value: 1 } }, emissivemap: { emissiveMap: { value: null } }, bumpmap: { bumpMap: { value: null }, bumpScale: { value: 1 } }, normalmap: { normalMap: { value: null }, normalScale: { value: /* @__PURE__ */ new Vector2(1, 1) } }, displacementmap: { displacementMap: { value: null }, displacementScale: { value: 1 }, displacementBias: { value: 0 } }, roughnessmap: { roughnessMap: { value: null } }, metalnessmap: { metalnessMap: { value: null } }, 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: {} } }, spotShadowMap: { value: [] }, spotShadowMatrix: { 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: {} } }, 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 }, 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 }, alphaMap: { value: null }, alphaTest: { value: 0 }, uvTransform: { value: /* @__PURE__ */ new Matrix3() } } }; 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.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 } } ]), 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 } }, vertexShader: ShaderChunk.background_vert, fragmentShader: ShaderChunk.background_frag }, cube: { uniforms: /* @__PURE__ */ mergeUniforms([ UniformsLib.envmap, { 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 }, clearcoatRoughness: { value: 0 }, clearcoatRoughnessMap: { value: null }, clearcoatNormalScale: { value: /* @__PURE__ */ new Vector2(1, 1) }, clearcoatNormalMap: { value: null }, iridescence: { value: 0 }, iridescenceMap: { value: null }, iridescenceIOR: { value: 1.3 }, iridescenceThicknessMinimum: { value: 100 }, iridescenceThicknessMaximum: { value: 400 }, iridescenceThicknessMap: { value: null }, sheen: { value: 0 }, sheenColor: { value: /* @__PURE__ */ new Color(0) }, sheenColorMap: { value: null }, sheenRoughness: { value: 1 }, sheenRoughnessMap: { value: null }, transmission: { value: 0 }, transmissionMap: { value: null }, transmissionSamplerSize: { value: /* @__PURE__ */ new Vector2() }, transmissionSamplerMap: { value: null }, thickness: { value: 0 }, thicknessMap: { value: null }, attenuationDistance: { value: 0 }, attenuationColor: { value: /* @__PURE__ */ new Color(0) }, specularIntensity: { value: 1 }, specularIntensityMap: { value: null }, specularColor: { value: /* @__PURE__ */ new Color(1, 1, 1) }, specularColorMap: { value: null } } ]), vertexShader: ShaderChunk.meshphysical_vert, fragmentShader: ShaderChunk.meshphysical_frag }; function WebGLBackground(renderer3, cubemaps, 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) { background = cubemaps.get(background); } const xr = renderer3.xr; const session = xr.getSession && xr.getSession(); if (session && session.environmentBlendMode === "additive") { background = null; } if (background === null) { setClear(clearColor, clearAlpha); } else if (background && background.isColor) { setClear(background, 1); forceClear = true; } 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.cube.uniforms), vertexShader: ShaderLib.cube.vertexShader, fragmentShader: ShaderLib.cube.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; 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; 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) { state.buffers.color.setClear(color.r, color.g, color.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(34921); 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, index5) { let updateBuffers = false; if (vaoAvailable) { const state = getBindingState(geometry, program, material); if (currentState !== state) { currentState = state; bindVertexArrayObject(currentState.object); } updateBuffers = needsUpdate(object, geometry, program, index5); if (updateBuffers) saveCache(object, geometry, program, index5); } 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 (index5 !== null) { attributes.update(index5, 34963); } if (updateBuffers || forceUpdate) { forceUpdate = false; setupVertexAttributes(object, material, program, geometry); if (index5 !== null) { gl.bindBuffer(34963, attributes.get(index5).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 { geometry: null, program: null, wireframe: false, newAttributes, enabledAttributes, attributeDivisors, object: vao, attributes: {}, index: null }; } function needsUpdate(object, geometry, program, index5) { 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 !== index5) return true; return false; } function saveCache(object, geometry, program, index5) { 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 = index5; } 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(index5, size, type, normalized, stride, offset) { if (capabilities.isWebGL2 === true && (type === 5124 || type === 5125)) { gl.vertexAttribIPointer(index5, size, type, stride, offset); } else { gl.vertexAttribPointer(index5, 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; 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(34962, 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); } } 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(34962, 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); } } } 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(35633, 36338).precision > 0 && gl.getShaderPrecisionFormat(35632, 36338).precision > 0) { return "highp"; } precision2 = "mediump"; } if (precision2 === "mediump") { if (gl.getShaderPrecisionFormat(35633, 36337).precision > 0 && gl.getShaderPrecisionFormat(35632, 36337).precision > 0) { return "mediump"; } } return "lowp"; } const isWebGL2 = typeof WebGL2RenderingContext !== "undefined" && gl instanceof WebGL2RenderingContext || typeof WebGL2ComputeRenderingContext !== "undefined" && gl instanceof WebGL2ComputeRenderingContext; 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(34930); const maxVertexTextures = gl.getParameter(35660); const maxTextureSize = gl.getParameter(3379); const maxCubemapSize = gl.getParameter(34076); const maxAttributes = gl.getParameter(34921); const maxVertexUniforms = gl.getParameter(36347); const maxVaryings = gl.getParameter(36348); const maxFragmentUniforms = gl.getParameter(36349); const vertexTextures = maxVertexTextures > 0; const floatFragmentTextures = isWebGL2 || extensions.has("OES_texture_float"); const floatVertexTextures = vertexTextures && floatFragmentTextures; const maxSamples = isWebGL2 ? gl.getParameter(36183) : 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, camera3) { const enabled = planes.length !== 0 || enableLocalClipping || numGlobalPlanes !== 0 || localClippingEnabled; localClippingEnabled = enableLocalClipping; globalState = projectPlanes(planes, camera3, 0); numGlobalPlanes = planes.length; return enabled; }; this.beginShadows = function() { renderingShadows = true; projectPlanes(null); }; this.endShadows = function() { renderingShadows = false; resetGlobalState(); }; 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, x2, y2, 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 = x2; this.view.offsetY = y2; 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.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 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); } fromScene(scene3, sigma = 0, near = 0.1, far = 100) { _oldTarget = 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; } fromEquirectangular(equirectangular, renderTarget = null) { return this._fromTexture(equirectangular, renderTarget); } fromCubemap(cubemap, renderTarget = null) { return this._fromTexture(cubemap, renderTarget); } compileCubemapShader() { if (this._cubemapMaterial === null) { this._cubemapMaterial = _getCubemapMaterial(); this._compileMaterial(this._cubemapMaterial); } } compileEquirectangularShader() { if (this._equirectMaterial === null) { this._equirectMaterial = _getEquirectMaterial(); this._compileMaterial(this._equirectMaterial); } } dispose() { this._dispose(); if (this._cubemapMaterial !== null) this._cubemapMaterial.dispose(); if (this._equirectMaterial !== null) this._equirectMaterial.dispose(); } _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); 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(); 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, encoding: LinearEncoding, depthBuffer: false }; const cubeUVRenderTarget = _createRenderTarget(width, height, params); if (this._pingPongRenderTarget === null || this._pingPongRenderTarget.width !== width) { 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 fov2 = 90; const aspect2 = 1; const cubeCamera = new PerspectiveCamera(fov2, aspect2, 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; } _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 x3 = i / sigmaPixels; const weight = Math.exp(-x3 * x3 / 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 x2 = 3 * outputSize * (lodOut > _lodMax - LOD_MIN ? lodOut - _lodMax + LOD_MIN : 0); const y2 = 4 * (this._cubeSize - outputSize); _setViewport(targetOut, x2, y2, 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 x2 = face % 3 * 2 / 3 - 1; const y2 = face > 2 ? 0 : -1; const coordinates = [ x2, y2, 0, x2 + 2 / 3, y2, 0, x2 + 2 / 3, y2 + 1, 0, x2, y2, 0, x2 + 2 / 3, y2 + 1, 0, x2, y2 + 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, x2, y2, width, height) { target.viewport.set(x2, y2, width, height); target.scissor.set(x2, y2, 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: ` 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: ` 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: ` 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 ` 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]); } 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], 34962); } 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], 34962); } } } 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 { 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); } } 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 4: render.triangles += instanceCount * (count / 3); break; case 1: render.lines += instanceCount * (count / 2); break; case 3: render.lines += instanceCount * (count - 1); break; case 2: render.lines += instanceCount * count; break; case 0: render.points += instanceCount * count; break; default: console.error("THREE.WebGLInfo: Unknown draw mode:", mode); break; } } function reset() { render.frame++; 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 denormalize(morph, attribute) { let denominator = 1; const array = attribute.isInterleavedBufferAttribute ? attribute.data.array : attribute.array; if (array instanceof Int8Array) denominator = 127; else if (array instanceof Uint8Array) denominator = 255; else if (array instanceof Uint16Array) denominator = 65535; else if (array instanceof Int16Array) denominator = 32767; else if (array instanceof Int32Array) denominator = 2147483647; else console.error("THREE.WebGLMorphtargets: Unsupported morph attribute data type: ", array); morph.divideScalar(denominator); } 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, material, 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); if (morphTarget.normalized === true) denormalize(morph, morphTarget); 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); if (morphNormal.normalized === true) denormalize(morph, morphNormal); 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); if (morphColor.normalized === true) denormalize(morph, morphColor); 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 index5 = influence[0]; const value = influence[1]; if (index5 !== Number.MAX_SAFE_INTEGER && value) { if (morphTargets && geometry.getAttribute("morphTarget" + i) !== morphTargets[index5]) { geometry.setAttribute("morphTarget" + i, morphTargets[index5]); } if (morphNormals && geometry.getAttribute("morphNormal" + i) !== morphNormals[index5]) { geometry.setAttribute("morphNormal" + i, morphNormals[index5]); } 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); } attributes.update(object.instanceMatrix, 34962); if (object.instanceColor !== null) { attributes.update(object.instanceColor, 34962); } } 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 (arraysEqual(cache, v)) return; gl.uniform2iv(this.addr, v); copyArray(cache, v); } function setValueV3i(gl, v) { const cache = this.cache; if (arraysEqual(cache, v)) return; gl.uniform3iv(this.addr, v); copyArray(cache, v); } function setValueV4i(gl, v) { const cache = this.cache; 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 (arraysEqual(cache, v)) return; gl.uniform2uiv(this.addr, v); copyArray(cache, v); } function setValueV3ui(gl, v) { const cache = this.cache; if (arraysEqual(cache, v)) return; gl.uniform3uiv(this.addr, v); copyArray(cache, v); } function setValueV4ui(gl, v) { const cache = this.cache; 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 n = v.length; const units = allocTexUnits(textures, n); gl.uniform1iv(this.addr, units); for (let i = 0; i !== n; ++i) { textures.setTexture2D(v[i] || emptyTexture, units[i]); } } function setValueT3DArray(gl, v, textures) { const n = v.length; const units = allocTexUnits(textures, n); gl.uniform1iv(this.addr, units); for (let i = 0; i !== n; ++i) { textures.setTexture3D(v[i] || empty3dTexture, units[i]); } } function setValueT6Array(gl, v, textures) { const n = v.length; const units = allocTexUnits(textures, n); gl.uniform1iv(this.addr, units); for (let i = 0; i !== n; ++i) { textures.setTextureCube(v[i] || emptyCubeTexture, units[i]); } } function setValueT2DArrayArray(gl, v, textures) { const n = v.length; const units = allocTexUnits(textures, n); gl.uniform1iv(this.addr, 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, 35718); 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 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(encoding) { switch (encoding) { case LinearEncoding: return ["Linear", "( value )"]; case sRGBEncoding: return ["sRGB", "( value )"]; default: console.warn("THREE.WebGLProgram: Unsupported encoding:", encoding); return ["Linear", "( value )"]; } } function getShaderErrors(gl, shader, type) { const status = gl.getShaderParameter(shader, 35713); 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, encoding) { const components = getEncodingComponents(encoding); return "vec4 " + functionName + "( vec4 value ) { return LinearTo" + components[0] + components[1] + "; }"; } 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.tangentSpaceNormalMap || 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, 35721); for (let i = 0; i < n; i++) { const info = gl.getActiveAttrib(program, i); const name = info.name; let locationSize = 1; if (info.type === 35674) locationSize = 2; if (info.type === 35675) locationSize = 3; if (info.type === 35676) locationSize = 4; attributes[name] = { type: info.type, location: gl.getAttribLocation(program, name), locationSize }; } return attributes; } function filterEmptyLine(string) { return string !== ""; } function replaceLightNums(string, parameters) { return string.replace(/NUM_DIR_LIGHTS/g, parameters.numDirLights).replace(/NUM_SPOT_LIGHTS/g, parameters.numSpotLights).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/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); } function includeReplacer(match, include) { const string = ShaderChunk[include]; if (string === void 0) { throw new Error("Can not resolve #include <" + include + ">"); } return resolveIncludes(string); } var deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g; 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).replace(deprecatedUnrollLoopPattern, deprecatedLoopReplacer); } function deprecatedLoopReplacer(match, start, end, snippet) { console.warn("WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead."); return loopReplacer(match, start, end, snippet); } 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 = [ customDefines ].filter(filterEmptyLine).join("\n"); if (prefixVertex.length > 0) { prefixVertex += "\n"; } prefixFragment = [ customExtensions, customDefines ].filter(filterEmptyLine).join("\n"); if (prefixFragment.length > 0) { prefixFragment += "\n"; } } else { prefixVertex = [ generatePrecision(parameters), "#define SHADER_NAME " + parameters.shaderName, customDefines, parameters.instancing ? "#define USE_INSTANCING" : "", parameters.instancingColor ? "#define USE_INSTANCING_COLOR" : "", parameters.supportsVertexTextures ? "#define VERTEX_TEXTURES" : "", 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.emissiveMap ? "#define USE_EMISSIVEMAP" : "", parameters.bumpMap ? "#define USE_BUMPMAP" : "", parameters.normalMap ? "#define USE_NORMALMAP" : "", parameters.normalMap && parameters.objectSpaceNormalMap ? "#define OBJECTSPACE_NORMALMAP" : "", parameters.normalMap && parameters.tangentSpaceNormalMap ? "#define TANGENTSPACE_NORMALMAP" : "", 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.displacementMap && parameters.supportsVertexTextures ? "#define USE_DISPLACEMENTMAP" : "", parameters.specularMap ? "#define USE_SPECULARMAP" : "", parameters.specularIntensityMap ? "#define USE_SPECULARINTENSITYMAP" : "", parameters.specularColorMap ? "#define USE_SPECULARCOLORMAP" : "", parameters.roughnessMap ? "#define USE_ROUGHNESSMAP" : "", parameters.metalnessMap ? "#define USE_METALNESSMAP" : "", parameters.alphaMap ? "#define USE_ALPHAMAP" : "", parameters.transmission ? "#define USE_TRANSMISSION" : "", parameters.transmissionMap ? "#define USE_TRANSMISSIONMAP" : "", parameters.thicknessMap ? "#define USE_THICKNESSMAP" : "", parameters.sheenColorMap ? "#define USE_SHEENCOLORMAP" : "", parameters.sheenRoughnessMap ? "#define USE_SHEENROUGHNESSMAP" : "", parameters.vertexTangents ? "#define USE_TANGENT" : "", parameters.vertexColors ? "#define USE_COLOR" : "", parameters.vertexAlphas ? "#define USE_COLOR_ALPHA" : "", parameters.vertexUvs ? "#define USE_UV" : "", parameters.uvsVertexOnly ? "#define UVS_VERTEX_ONLY" : "", 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.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_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_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.emissiveMap ? "#define USE_EMISSIVEMAP" : "", parameters.bumpMap ? "#define USE_BUMPMAP" : "", parameters.normalMap ? "#define USE_NORMALMAP" : "", parameters.normalMap && parameters.objectSpaceNormalMap ? "#define OBJECTSPACE_NORMALMAP" : "", parameters.normalMap && parameters.tangentSpaceNormalMap ? "#define TANGENTSPACE_NORMALMAP" : "", 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.specularIntensityMap ? "#define USE_SPECULARINTENSITYMAP" : "", parameters.specularColorMap ? "#define USE_SPECULARCOLORMAP" : "", parameters.roughnessMap ? "#define USE_ROUGHNESSMAP" : "", parameters.metalnessMap ? "#define USE_METALNESSMAP" : "", parameters.alphaMap ? "#define USE_ALPHAMAP" : "", parameters.alphaTest ? "#define USE_ALPHATEST" : "", parameters.sheen ? "#define USE_SHEEN" : "", parameters.sheenColorMap ? "#define USE_SHEENCOLORMAP" : "", parameters.sheenRoughnessMap ? "#define USE_SHEENROUGHNESSMAP" : "", parameters.transmission ? "#define USE_TRANSMISSION" : "", parameters.transmissionMap ? "#define USE_TRANSMISSIONMAP" : "", parameters.thicknessMap ? "#define USE_THICKNESSMAP" : "", parameters.decodeVideoTexture ? "#define DECODE_VIDEO_TEXTURE" : "", parameters.vertexTangents ? "#define USE_TANGENT" : "", parameters.vertexColors || parameters.instancingColor ? "#define USE_COLOR" : "", parameters.vertexAlphas ? "#define USE_COLOR_ALPHA" : "", parameters.vertexUvs ? "#define USE_UV" : "", parameters.uvsVertexOnly ? "#define UVS_VERTEX_ONLY" : "", 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.physicallyCorrectLights ? "#define PHYSICALLY_CORRECT_LIGHTS" : "", 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"] : "", parameters.toneMapping !== NoToneMapping ? getToneMappingFunction("toneMapping", parameters.toneMapping) : "", parameters.dithering ? "#define DITHERING" : "", parameters.opaque ? "#define OPAQUE" : "", ShaderChunk["encodings_pars_fragment"], getTexelEncodingFunction("linearToOutputTexel", parameters.outputEncoding), 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 = [ "#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, 35633, vertexGlsl); const glFragmentShader = WebGLShader(gl, 35632, 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, 35714) === false) { runnable = false; 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, 35715) + "\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 WebGLUniforms(gl, program); } return cachedUniforms; }; let cachedAttributes; this.getAttributes = function() { if (cachedAttributes === void 0) { cachedAttributes = fetchAttributeLocations(gl, program); } return cachedAttributes; }; this.destroy = function() { bindingStates.releaseStatesOfProgram(this); gl.deleteProgram(program); this.program = void 0; }; 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 = 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; if (cache.has(material) === false) { cache.set(material, /* @__PURE__ */ new Set()); } return cache.get(material); } _getShaderStage(code) { const cache = this.shaderCache; if (cache.has(code) === false) { const stage = new WebGLShaderStage(code); cache.set(code, stage); } return cache.get(code); } }; var WebGLShaderStage = class { constructor(code) { this.id = _id++; 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 isWebGL2 = capabilities.isWebGL2; const logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer; const vertexTextures = 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 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 useAlphaTest = material.alphaTest > 0; const useClearcoat = material.clearcoat > 0; const useIridescence = material.iridescence > 0; const parameters = { isWebGL2, shaderID, shaderName: material.type, vertexShader, fragmentShader, defines: material.defines, customVertexShaderID, customFragmentShaderID, isRawShaderMaterial: material.isRawShaderMaterial === true, glslVersion: material.glslVersion, precision, instancing: object.isInstancedMesh === true, instancingColor: object.isInstancedMesh === true && object.instanceColor !== null, supportsVertexTextures: vertexTextures, outputEncoding: currentRenderTarget === null ? renderer3.outputEncoding : currentRenderTarget.isXRRenderTarget === true ? currentRenderTarget.texture.encoding : LinearEncoding, map: !!material.map, matcap: !!material.matcap, envMap: !!envMap, envMapMode: envMap && envMap.mapping, envMapCubeUVHeight, lightMap: !!material.lightMap, aoMap: !!material.aoMap, emissiveMap: !!material.emissiveMap, bumpMap: !!material.bumpMap, normalMap: !!material.normalMap, objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap, tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap, decodeVideoTexture: !!material.map && material.map.isVideoTexture === true && material.map.encoding === sRGBEncoding, clearcoat: useClearcoat, clearcoatMap: useClearcoat && !!material.clearcoatMap, clearcoatRoughnessMap: useClearcoat && !!material.clearcoatRoughnessMap, clearcoatNormalMap: useClearcoat && !!material.clearcoatNormalMap, iridescence: useIridescence, iridescenceMap: useIridescence && !!material.iridescenceMap, iridescenceThicknessMap: useIridescence && !!material.iridescenceThicknessMap, displacementMap: !!material.displacementMap, roughnessMap: !!material.roughnessMap, metalnessMap: !!material.metalnessMap, specularMap: !!material.specularMap, specularIntensityMap: !!material.specularIntensityMap, specularColorMap: !!material.specularColorMap, opaque: material.transparent === false && material.blending === NormalBlending, alphaMap: !!material.alphaMap, alphaTest: useAlphaTest, gradientMap: !!material.gradientMap, sheen: material.sheen > 0, sheenColorMap: !!material.sheenColorMap, sheenRoughnessMap: !!material.sheenRoughnessMap, transmission: material.transmission > 0, transmissionMap: !!material.transmissionMap, thicknessMap: !!material.thicknessMap, combine: material.combine, vertexTangents: !!material.normalMap && !!geometry.attributes.tangent, vertexColors: material.vertexColors, vertexAlphas: material.vertexColors === true && !!geometry.attributes.color && geometry.attributes.color.itemSize === 4, vertexUvs: !!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatMap || !!material.clearcoatRoughnessMap || !!material.clearcoatNormalMap || !!material.iridescenceMap || !!material.iridescenceThicknessMap || !!material.displacementMap || !!material.transmissionMap || !!material.thicknessMap || !!material.specularIntensityMap || !!material.specularColorMap || !!material.sheenColorMap || !!material.sheenRoughnessMap, uvsVertexOnly: !(!!material.map || !!material.bumpMap || !!material.normalMap || !!material.specularMap || !!material.alphaMap || !!material.emissiveMap || !!material.roughnessMap || !!material.metalnessMap || !!material.clearcoatNormalMap || !!material.iridescenceMap || !!material.iridescenceThicknessMap || material.transmission > 0 || !!material.transmissionMap || !!material.thicknessMap || !!material.specularIntensityMap || !!material.specularColorMap || material.sheen > 0 || !!material.sheenColorMap || !!material.sheenRoughnessMap) && !!material.displacementMap, fog: !!fog, useFog: material.fog === true, fogExp2: fog && fog.isFogExp2, flatShading: !!material.flatShading, sizeAttenuation: material.sizeAttenuation, 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, numRectAreaLights: lights.rectArea.length, numHemiLights: lights.hemi.length, numDirLightShadows: lights.directionalShadowMap.length, numPointLightShadows: lights.pointShadowMap.length, numSpotLightShadows: lights.spotShadowMap.length, numClippingPlanes: clipping.numPlanes, numClipIntersection: clipping.numIntersection, dithering: material.dithering, shadowMapEnabled: renderer3.shadowMap.enabled && shadows.length > 0, shadowMapType: renderer3.shadowMap.type, toneMapping: material.toneMapped ? renderer3.toneMapping : NoToneMapping, physicallyCorrectLights: renderer3.physicallyCorrectLights, premultipliedAlpha: material.premultipliedAlpha, doubleSided: material.side === DoubleSide, flipSided: material.side === BackSide, useDepthPacking: !!material.depthPacking, depthPacking: material.depthPacking || 0, index0AttributeName: material.index0AttributeName, extensionDerivatives: material.extensions && material.extensions.derivatives, extensionFragDepth: material.extensions && material.extensions.fragDepth, extensionDrawBuffers: material.extensions && material.extensions.drawBuffers, extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD, rendererExtensionFragDepth: isWebGL2 || extensions.has("EXT_frag_depth"), rendererExtensionDrawBuffers: isWebGL2 || extensions.has("WEBGL_draw_buffers"), rendererExtensionShaderTextureLod: isWebGL2 || 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.outputEncoding); } array.push(parameters.customProgramCacheKey); return array.join(); } function getProgramCacheKeyParameters(array, parameters) { array.push(parameters.precision); array.push(parameters.outputEncoding); array.push(parameters.envMapMode); array.push(parameters.envMapCubeUVHeight); array.push(parameters.combine); array.push(parameters.vertexUvs); 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.numHemiLights); array.push(parameters.numRectAreaLights); array.push(parameters.numDirLightShadows); array.push(parameters.numPointLightShadows); array.push(parameters.numSpotLightShadows); 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.map) _programLayers.enable(4); if (parameters.matcap) _programLayers.enable(5); if (parameters.envMap) _programLayers.enable(6); if (parameters.lightMap) _programLayers.enable(7); if (parameters.aoMap) _programLayers.enable(8); if (parameters.emissiveMap) _programLayers.enable(9); if (parameters.bumpMap) _programLayers.enable(10); if (parameters.normalMap) _programLayers.enable(11); if (parameters.objectSpaceNormalMap) _programLayers.enable(12); if (parameters.tangentSpaceNormalMap) _programLayers.enable(13); if (parameters.clearcoat) _programLayers.enable(14); if (parameters.clearcoatMap) _programLayers.enable(15); if (parameters.clearcoatRoughnessMap) _programLayers.enable(16); if (parameters.clearcoatNormalMap) _programLayers.enable(17); if (parameters.iridescence) _programLayers.enable(18); if (parameters.iridescenceMap) _programLayers.enable(19); if (parameters.iridescenceThicknessMap) _programLayers.enable(20); if (parameters.displacementMap) _programLayers.enable(21); if (parameters.specularMap) _programLayers.enable(22); if (parameters.roughnessMap) _programLayers.enable(23); if (parameters.metalnessMap) _programLayers.enable(24); if (parameters.gradientMap) _programLayers.enable(25); if (parameters.alphaMap) _programLayers.enable(26); if (parameters.alphaTest) _programLayers.enable(27); if (parameters.vertexColors) _programLayers.enable(28); if (parameters.vertexAlphas) _programLayers.enable(29); if (parameters.vertexUvs) _programLayers.enable(30); if (parameters.vertexTangents) _programLayers.enable(31); if (parameters.uvsVertexOnly) _programLayers.enable(32); if (parameters.fog) _programLayers.enable(33); array.push(_programLayers.mask); _programLayers.disableAll(); if (parameters.useFog) _programLayers.enable(0); if (parameters.flatShading) _programLayers.enable(1); if (parameters.logarithmicDepthBuffer) _programLayers.enable(2); if (parameters.skinning) _programLayers.enable(3); if (parameters.morphTargets) _programLayers.enable(4); if (parameters.morphNormals) _programLayers.enable(5); if (parameters.morphColors) _programLayers.enable(6); if (parameters.premultipliedAlpha) _programLayers.enable(7); if (parameters.shadowMapEnabled) _programLayers.enable(8); if (parameters.physicallyCorrectLights) _programLayers.enable(9); if (parameters.doubleSided) _programLayers.enable(10); if (parameters.flipSided) _programLayers.enable(11); if (parameters.useDepthPacking) _programLayers.enable(12); if (parameters.dithering) _programLayers.enable(13); if (parameters.specularIntensityMap) _programLayers.enable(14); if (parameters.specularColorMap) _programLayers.enable(15); if (parameters.transmission) _programLayers.enable(16); if (parameters.transmissionMap) _programLayers.enable(17); if (parameters.thicknessMap) _programLayers.enable(18); if (parameters.sheen) _programLayers.enable(19); if (parameters.sheenColorMap) _programLayers.enable(20); if (parameters.sheenRoughnessMap) _programLayers.enable(21); if (parameters.decodeVideoTexture) _programLayers.enable(22); if (parameters.opaque) _programLayers.enable(23); 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, 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, z2, group) { let renderItem = renderItems[renderItemsIndex]; if (renderItem === void 0) { renderItem = { id: object.id, object, geometry, material, groupOrder, renderOrder: object.renderOrder, z: z2, 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 = z2; renderItem.group = group; } renderItemsIndex++; return renderItem; } function push(object, geometry, material, groupOrder, z2, group) { const renderItem = getNextRenderItem(object, geometry, material, groupOrder, z2, 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, z2, group) { const renderItem = getNextRenderItem(object, geometry, material, groupOrder, z2, 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) { let list; if (lists.has(scene3) === false) { list = new WebGLRenderList(); lists.set(scene3, [list]); } else { if (renderCallDepth >= lists.get(scene3).length) { list = new WebGLRenderList(); lists.get(scene3).push(list); } else { list = lists.get(scene3)[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 shadowCastingLightsFirst(lightA, lightB) { return (lightB.castShadow ? 1 : 0) - (lightA.castShadow ? 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 }, ambient: [0, 0, 0], probe: [], directional: [], directionalShadow: [], directionalShadowMap: [], directionalShadowMatrix: [], spot: [], spotShadow: [], spotShadowMap: [], spotShadowMatrix: [], rectArea: [], rectAreaLTC1: null, rectAreaLTC2: null, point: [], pointShadow: [], pointShadowMap: [], pointShadowMatrix: [], hemi: [] }; 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, physicallyCorrectLights) { 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; lights.sort(shadowCastingLightsFirst); const scaleFactor = physicallyCorrectLights !== 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); } } 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; 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.spotShadow[spotLength] = shadowUniforms; state.spotShadowMap[spotLength] = shadowMap; state.spotShadowMatrix[spotLength] = light.shadow.matrix; numSpotShadows++; } state.spot[spotLength] = uniforms; 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) { 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.spotShadowMatrix.length = numSpotShadows; hash.directionalLength = directionalLength; hash.pointLength = pointLength; hash.spotLength = spotLength; hash.rectAreaLength = rectAreaLength; hash.hemiLength = hemiLength; hash.numDirectionalShadows = numDirectionalShadows; hash.numPointShadows = numPointShadows; hash.numSpotShadows = numSpotShadows; 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(physicallyCorrectLights) { lights.setup(lightsArray, physicallyCorrectLights); } 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) { let renderState; if (renderStates.has(scene3) === false) { renderState = new WebGLRenderState(extensions, capabilities); renderStates.set(scene3, [renderState]); } else { if (renderCallDepth >= renderStates.get(scene3).length) { renderState = new WebGLRenderState(extensions, capabilities); renderStates.get(scene3).push(renderState); } else { renderState = renderStates.get(scene3)[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.referencePosition = new Vector3(); this.nearDistance = 1; this.farDistance = 1e3; this.map = null; this.alphaMap = null; this.displacementMap = null; this.displacementScale = 1; this.displacementBias = 0; this.setValues(parameters); } copy(source) { super.copy(source); this.referencePosition.copy(source.referencePosition); this.nearDistance = source.nearDistance; this.farDistance = source.farDistance; 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 = { 0: BackSide, 1: FrontSide, 2: 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; 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); 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) { const pars = this.type !== VSMShadowMap ? { minFilter: NearestFilter, magFilter: NearestFilter } : {}; 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; } 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, shadowCameraNear, shadowCameraFar, 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) { 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.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) { result.referencePosition.setFromMatrixPosition(light.matrixWorld); result.nearDistance = shadowCameraNear; result.farDistance = shadowCameraFar; } 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, shadowCamera.near, shadowCamera.far, type); _renderer.renderBufferDirect(shadowCamera, null, geometry, depthMaterial, object, group); } } } else if (material.visible) { const depthMaterial = getDepthMaterial(object, material, light, shadowCamera.near, shadowCamera.far, 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(2929); } else { disable(2929); } }, setMask: function(depthMask) { if (currentDepthMask !== depthMask && !locked) { gl.depthMask(depthMask); currentDepthMask = depthMask; } }, setFunc: function(depthFunc) { if (currentDepthFunc !== depthFunc) { if (depthFunc) { switch (depthFunc) { case NeverDepth: gl.depthFunc(512); break; case AlwaysDepth: gl.depthFunc(519); break; case LessDepth: gl.depthFunc(513); break; case LessEqualDepth: gl.depthFunc(515); break; case EqualDepth: gl.depthFunc(514); break; case GreaterEqualDepth: gl.depthFunc(518); break; case GreaterDepth: gl.depthFunc(516); break; case NotEqualDepth: gl.depthFunc(517); break; default: gl.depthFunc(515); } } else { gl.depthFunc(515); } 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(2960); } else { disable(2960); } } }, 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 uboProgamMap = /* @__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(35661); let lineWidthAvailable = false; let version = 0; const glVersion = gl.getParameter(7938); 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(3088); const viewportParam = gl.getParameter(2978); const currentScissor = new Vector4().fromArray(scissorParam); const currentViewport = new Vector4().fromArray(viewportParam); function createTexture(type, target, count) { const data = new Uint8Array(4); const texture = gl.createTexture(); gl.bindTexture(type, texture); gl.texParameteri(type, 10241, 9728); gl.texParameteri(type, 10240, 9728); for (let i = 0; i < count; i++) { gl.texImage2D(target + i, 0, 6408, 1, 1, 0, 6408, 5121, data); } return texture; } const emptyTextures = {}; emptyTextures[3553] = createTexture(3553, 3553, 1); emptyTextures[34067] = createTexture(34067, 34069, 6); colorBuffer.setClear(0, 0, 0, 1); depthBuffer.setClear(1); stencilBuffer.setClear(0); enable(2929); depthBuffer.setFunc(LessEqualDepth); setFlipSided(false); setCullFace(CullFaceBack); enable(2884); 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 === 36009) { currentBoundFramebuffers[36160] = framebuffer; } if (target === 36160) { currentBoundFramebuffers[36009] = 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] !== 36064) { for (let i = 0, il = textures.length; i < il; i++) { drawBuffers2[i] = 36064 + i; } drawBuffers2.length = textures.length; needsUpdate = true; } } else { if (drawBuffers2[0] !== 36064) { drawBuffers2[0] = 36064; needsUpdate = true; } } } else { if (drawBuffers2[0] !== 1029) { drawBuffers2[0] = 1029; 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]: 32774, [SubtractEquation]: 32778, [ReverseSubtractEquation]: 32779 }; if (isWebGL2) { equationToGL[MinEquation] = 32775; equationToGL[MaxEquation] = 32776; } else { const extension = extensions.get("EXT_blend_minmax"); if (extension !== null) { equationToGL[MinEquation] = extension.MIN_EXT; equationToGL[MaxEquation] = extension.MAX_EXT; } } const factorToGL = { [ZeroFactor]: 0, [OneFactor]: 1, [SrcColorFactor]: 768, [SrcAlphaFactor]: 770, [SrcAlphaSaturateFactor]: 776, [DstColorFactor]: 774, [DstAlphaFactor]: 772, [OneMinusSrcColorFactor]: 769, [OneMinusSrcAlphaFactor]: 771, [OneMinusDstColorFactor]: 775, [OneMinusDstAlphaFactor]: 773 }; function setBlending(blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha) { if (blending === NoBlending) { if (currentBlendingEnabled === true) { disable(3042); currentBlendingEnabled = false; } return; } if (currentBlendingEnabled === false) { enable(3042); currentBlendingEnabled = true; } if (blending !== CustomBlending) { if (blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha) { if (currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation) { gl.blendEquation(32774); currentBlendEquation = AddEquation; currentBlendEquationAlpha = AddEquation; } if (premultipliedAlpha) { switch (blending) { case NormalBlending: gl.blendFuncSeparate(1, 771, 1, 771); break; case AdditiveBlending: gl.blendFunc(1, 1); break; case SubtractiveBlending: gl.blendFuncSeparate(0, 769, 0, 1); break; case MultiplyBlending: gl.blendFuncSeparate(0, 768, 0, 770); break; default: console.error("THREE.WebGLState: Invalid blending: ", blending); break; } } else { switch (blending) { case NormalBlending: gl.blendFuncSeparate(770, 771, 1, 771); break; case AdditiveBlending: gl.blendFunc(770, 1); break; case SubtractiveBlending: gl.blendFuncSeparate(0, 769, 0, 1); break; case MultiplyBlending: gl.blendFunc(0, 768); 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 = null; } function setMaterial(material, frontFaceCW) { material.side === DoubleSide ? disable(2884) : enable(2884); 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.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(32926) : disable(32926); } function setFlipSided(flipSided) { if (currentFlipSided !== flipSided) { if (flipSided) { gl.frontFace(2304); } else { gl.frontFace(2305); } currentFlipSided = flipSided; } } function setCullFace(cullFace) { if (cullFace !== CullFaceNone) { enable(2884); if (cullFace !== currentCullFace) { if (cullFace === CullFaceBack) { gl.cullFace(1029); } else if (cullFace === CullFaceFront) { gl.cullFace(1028); } else { gl.cullFace(1032); } } } else { disable(2884); } currentCullFace = cullFace; } function setLineWidth(width) { if (width !== currentLineWidth) { if (lineWidthAvailable) gl.lineWidth(width); currentLineWidth = width; } } function setPolygonOffset(polygonOffset, factor, units) { if (polygonOffset) { enable(32823); if (currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units) { gl.polygonOffset(factor, units); currentPolygonOffsetFactor = factor; currentPolygonOffsetUnits = units; } } else { disable(32823); } } function setScissorTest(scissorTest) { if (scissorTest) { enable(3089); } else { disable(3089); } } function activeTexture(webglSlot) { if (webglSlot === void 0) webglSlot = 33984 + maxTextures - 1; if (currentTextureSlot !== webglSlot) { gl.activeTexture(webglSlot); currentTextureSlot = webglSlot; } } function bindTexture(webglType, webglTexture) { if (currentTextureSlot === null) { activeTexture(); } let boundTexture = currentBoundTextures[currentTextureSlot]; if (boundTexture === void 0) { boundTexture = { type: void 0, texture: void 0 }; currentBoundTextures[currentTextureSlot] = boundTexture; } if (boundTexture.type !== webglType || boundTexture.texture !== webglTexture) { 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 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 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 = uboProgamMap.get(program); if (mapping === void 0) { mapping = /* @__PURE__ */ new WeakMap(); uboProgamMap.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 = uboProgamMap.get(program); const blockIndex = mapping.get(uniformsGroup); if (uboBindings.get(uniformsGroup) !== blockIndex) { gl.uniformBlockBinding(program, blockIndex, uniformsGroup.__bindingPointIndex); uboBindings.set(uniformsGroup, blockIndex); } } function reset() { gl.disable(3042); gl.disable(2884); gl.disable(2929); gl.disable(32823); gl.disable(3089); gl.disable(2960); gl.disable(32926); gl.blendEquation(32774); gl.blendFunc(1, 0); gl.blendFuncSeparate(1, 0, 1, 0); gl.colorMask(true, true, true, true); gl.clearColor(0, 0, 0, 0); gl.depthMask(true); gl.depthFunc(513); gl.clearDepth(1); gl.stencilMask(4294967295); gl.stencilFunc(519, 0, 4294967295); gl.stencilOp(7680, 7680, 7680); gl.clearStencil(0); gl.cullFace(1029); gl.frontFace(2305); gl.polygonOffset(0, 0); gl.activeTexture(33984); gl.bindFramebuffer(36160, null); if (isWebGL2 === true) { gl.bindFramebuffer(36009, null); gl.bindFramebuffer(36008, 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, texImage2D, texImage3D, updateUBOMapping, uniformBlockBinding, texStorage2D, texStorage3D, texSubImage2D, texSubImage3D, compressedTexSubImage2D, 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 = /OculusBrowser/g.test(navigator.userAgent); const _videoTextures = /* @__PURE__ */ new WeakMap(); let _canvas2; 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 ? 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 (_canvas2 === void 0) _canvas2 = createCanvas(width, height); const canvas = needsNewCanvas ? createCanvas(width, height) : _canvas2; 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, encoding, isVideoTexture = 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 === 6403) { if (glType === 5126) internalFormat = 33326; if (glType === 5131) internalFormat = 33325; if (glType === 5121) internalFormat = 33321; } if (glFormat === 33319) { if (glType === 5126) internalFormat = 33328; if (glType === 5131) internalFormat = 33327; if (glType === 5121) internalFormat = 33323; } if (glFormat === 6408) { if (glType === 5126) internalFormat = 34836; if (glType === 5131) internalFormat = 34842; if (glType === 5121) internalFormat = encoding === sRGBEncoding && isVideoTexture === false ? 35907 : 32856; if (glType === 32819) internalFormat = 32854; if (glType === 32820) internalFormat = 32855; } if (internalFormat === 33325 || internalFormat === 33326 || internalFormat === 33327 || internalFormat === 33328 || internalFormat === 34842 || internalFormat === 34836) { 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 9728; } return 9729; } 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++) { _gl.deleteFramebuffer(renderTargetProperties.__webglFramebuffer[i]); if (renderTargetProperties.__webglDepthbuffer) _gl.deleteRenderbuffer(renderTargetProperties.__webglDepthbuffer[i]); } } 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.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.encoding); 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.activeTexture(33984 + slot); state.bindTexture(3553, textureProperties.__webglTexture); } function setTexture2DArray(texture, slot) { const textureProperties = properties.get(texture); if (texture.version > 0 && textureProperties.__version !== texture.version) { uploadTexture(textureProperties, texture, slot); return; } state.activeTexture(33984 + slot); state.bindTexture(35866, textureProperties.__webglTexture); } function setTexture3D(texture, slot) { const textureProperties = properties.get(texture); if (texture.version > 0 && textureProperties.__version !== texture.version) { uploadTexture(textureProperties, texture, slot); return; } state.activeTexture(33984 + slot); state.bindTexture(32879, textureProperties.__webglTexture); } function setTextureCube(texture, slot) { const textureProperties = properties.get(texture); if (texture.version > 0 && textureProperties.__version !== texture.version) { uploadCubeTexture(textureProperties, texture, slot); return; } state.activeTexture(33984 + slot); state.bindTexture(34067, textureProperties.__webglTexture); } const wrappingToGL = { [RepeatWrapping]: 10497, [ClampToEdgeWrapping]: 33071, [MirroredRepeatWrapping]: 33648 }; const filterToGL = { [NearestFilter]: 9728, [NearestMipmapNearestFilter]: 9984, [NearestMipmapLinearFilter]: 9986, [LinearFilter]: 9729, [LinearMipmapNearestFilter]: 9985, [LinearMipmapLinearFilter]: 9987 }; function setTextureParameters(textureType, texture, supportsMips) { if (supportsMips) { _gl.texParameteri(textureType, 10242, wrappingToGL[texture.wrapS]); _gl.texParameteri(textureType, 10243, wrappingToGL[texture.wrapT]); if (textureType === 32879 || textureType === 35866) { _gl.texParameteri(textureType, 32882, wrappingToGL[texture.wrapR]); } _gl.texParameteri(textureType, 10240, filterToGL[texture.magFilter]); _gl.texParameteri(textureType, 10241, filterToGL[texture.minFilter]); } else { _gl.texParameteri(textureType, 10242, 33071); _gl.texParameteri(textureType, 10243, 33071); if (textureType === 32879 || textureType === 35866) { _gl.texParameteri(textureType, 32882, 33071); } 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, 10240, filterFallback(texture.magFilter)); _gl.texParameteri(textureType, 10241, 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 (extensions.has("EXT_texture_filter_anisotropic") === true) { const extension = extensions.get("EXT_texture_filter_anisotropic"); 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 = 3553; if (texture.isDataArrayTexture) textureType = 35866; if (texture.isData3DTexture) textureType = 32879; const forceUpload = initTexture(textureProperties, texture); const source = texture.source; state.activeTexture(33984 + slot); state.bindTexture(textureType, textureProperties.__webglTexture); if (source.version !== source.__currentVersion || forceUpload === true) { _gl.pixelStorei(37440, texture.flipY); _gl.pixelStorei(37441, texture.premultiplyAlpha); _gl.pixelStorei(3317, texture.unpackAlignment); _gl.pixelStorei(37443, 0); 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.encoding); let glType = utils.convert(texture.type), glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.encoding, texture.isVideoTexture); setTextureParameters(textureType, texture, supportsMips); let mipmap; const mipmaps = texture.mipmaps; const useTexStorage = isWebGL2 && texture.isVideoTexture !== true; const allocateMemory = source.__currentVersion === void 0 || forceUpload === true; const levels = getMipLevels(texture, image, supportsMips); if (texture.isDepthTexture) { glInternalFormat = 6402; if (isWebGL2) { if (texture.type === FloatType) { glInternalFormat = 36012; } else if (texture.type === UnsignedIntType) { glInternalFormat = 33190; } else if (texture.type === UnsignedInt248Type) { glInternalFormat = 35056; } else { glInternalFormat = 33189; } } else { if (texture.type === FloatType) { console.error("WebGLRenderer: Floating point depth texture requires WebGL2."); } } if (texture.format === DepthFormat && glInternalFormat === 6402) { 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 === 6402) { glInternalFormat = 34041; 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(3553, 1, glInternalFormat, image.width, image.height); } else { state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null); } } } else if (texture.isDataTexture) { if (mipmaps.length > 0 && supportsMips) { if (useTexStorage && allocateMemory) { state.texStorage2D(3553, 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(3553, i, 0, 0, mipmap.width, mipmap.height, glFormat, glType, mipmap.data); } else { state.texImage2D(3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data); } } texture.generateMipmaps = false; } else { if (useTexStorage) { if (allocateMemory) { state.texStorage2D(3553, levels, glInternalFormat, image.width, image.height); } state.texSubImage2D(3553, 0, 0, 0, image.width, image.height, glFormat, glType, image.data); } else { state.texImage2D(3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data); } } } else if (texture.isCompressedTexture) { if (useTexStorage && allocateMemory) { state.texStorage2D(3553, 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(3553, i, 0, 0, mipmap.width, mipmap.height, glFormat, mipmap.data); } else { state.compressedTexImage2D(3553, 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(3553, i, 0, 0, mipmap.width, mipmap.height, glFormat, glType, mipmap.data); } else { state.texImage2D(3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data); } } } } else if (texture.isDataArrayTexture) { if (useTexStorage) { if (allocateMemory) { state.texStorage3D(35866, levels, glInternalFormat, image.width, image.height, image.depth); } state.texSubImage3D(35866, 0, 0, 0, 0, image.width, image.height, image.depth, glFormat, glType, image.data); } else { state.texImage3D(35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data); } } else if (texture.isData3DTexture) { if (useTexStorage) { if (allocateMemory) { state.texStorage3D(32879, levels, glInternalFormat, image.width, image.height, image.depth); } state.texSubImage3D(32879, 0, 0, 0, 0, image.width, image.height, image.depth, glFormat, glType, image.data); } else { state.texImage3D(32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data); } } else if (texture.isFramebufferTexture) { if (allocateMemory) { if (useTexStorage) { state.texStorage2D(3553, levels, glInternalFormat, image.width, image.height); } else { let width = image.width, height = image.height; for (let i = 0; i < levels; i++) { state.texImage2D(3553, i, glInternalFormat, width, height, 0, glFormat, glType, null); width >>= 1; height >>= 1; } } } } else { if (mipmaps.length > 0 && supportsMips) { if (useTexStorage && allocateMemory) { state.texStorage2D(3553, 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(3553, i, 0, 0, glFormat, glType, mipmap); } else { state.texImage2D(3553, i, glInternalFormat, glFormat, glType, mipmap); } } texture.generateMipmaps = false; } else { if (useTexStorage) { if (allocateMemory) { state.texStorage2D(3553, levels, glInternalFormat, image.width, image.height); } state.texSubImage2D(3553, 0, 0, 0, glFormat, glType, image); } else { state.texImage2D(3553, 0, glInternalFormat, glFormat, glType, image); } } } if (textureNeedsGenerateMipmaps(texture, supportsMips)) { generateMipmap(textureType); } source.__currentVersion = 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.activeTexture(33984 + slot); state.bindTexture(34067, textureProperties.__webglTexture); if (source.version !== source.__currentVersion || forceUpload === true) { _gl.pixelStorei(37440, texture.flipY); _gl.pixelStorei(37441, texture.premultiplyAlpha); _gl.pixelStorei(3317, texture.unpackAlignment); _gl.pixelStorei(37443, 0); 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.encoding), glType = utils.convert(texture.type), glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.encoding); const useTexStorage = isWebGL2 && texture.isVideoTexture !== true; const allocateMemory = source.__currentVersion === void 0 || forceUpload === true; let levels = getMipLevels(texture, image, supportsMips); setTextureParameters(34067, texture, supportsMips); let mipmaps; if (isCompressed) { if (useTexStorage && allocateMemory) { state.texStorage2D(34067, 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(34069 + i, j, 0, 0, mipmap.width, mipmap.height, glFormat, mipmap.data); } else { state.compressedTexImage2D(34069 + 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(34069 + i, j, 0, 0, mipmap.width, mipmap.height, glFormat, glType, mipmap.data); } else { state.texImage2D(34069 + 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(34067, levels, glInternalFormat, cubeImage[0].width, cubeImage[0].height); } for (let i = 0; i < 6; i++) { if (isDataTexture) { if (useTexStorage) { state.texSubImage2D(34069 + i, 0, 0, 0, cubeImage[i].width, cubeImage[i].height, glFormat, glType, cubeImage[i].data); } else { state.texImage2D(34069 + 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(34069 + i, j + 1, 0, 0, mipmapImage.width, mipmapImage.height, glFormat, glType, mipmapImage.data); } else { state.texImage2D(34069 + i, j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data); } } } else { if (useTexStorage) { state.texSubImage2D(34069 + i, 0, 0, 0, glFormat, glType, cubeImage[i]); } else { state.texImage2D(34069 + i, 0, glInternalFormat, glFormat, glType, cubeImage[i]); } for (let j = 0; j < mipmaps.length; j++) { const mipmap = mipmaps[j]; if (useTexStorage) { state.texSubImage2D(34069 + i, j + 1, 0, 0, glFormat, glType, mipmap.image[i]); } else { state.texImage2D(34069 + i, j + 1, glInternalFormat, glFormat, glType, mipmap.image[i]); } } } } } if (textureNeedsGenerateMipmaps(texture, supportsMips)) { generateMipmap(34067); } source.__currentVersion = source.version; if (texture.onUpdate) texture.onUpdate(texture); } textureProperties.__version = texture.version; } function setupFrameBufferTexture(framebuffer, renderTarget, texture, attachment, textureTarget) { const glFormat = utils.convert(texture.format, texture.encoding); const glType = utils.convert(texture.type); const glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.encoding); const renderTargetProperties = properties.get(renderTarget); if (!renderTargetProperties.__hasExternalTextures) { if (textureTarget === 32879 || textureTarget === 35866) { state.texImage3D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, renderTarget.depth, 0, glFormat, glType, null); } else { state.texImage2D(textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null); } } state.bindFramebuffer(36160, framebuffer); if (useMultisampledRTT(renderTarget)) { multisampledRTTExt.framebufferTexture2DMultisampleEXT(36160, attachment, textureTarget, properties.get(texture).__webglTexture, 0, getRenderTargetSamples(renderTarget)); } else { _gl.framebufferTexture2D(36160, attachment, textureTarget, properties.get(texture).__webglTexture, 0); } state.bindFramebuffer(36160, null); } function setupRenderBufferStorage(renderbuffer, renderTarget, isMultisample) { _gl.bindRenderbuffer(36161, renderbuffer); if (renderTarget.depthBuffer && !renderTarget.stencilBuffer) { let glInternalFormat = 33189; if (isMultisample || useMultisampledRTT(renderTarget)) { const depthTexture = renderTarget.depthTexture; if (depthTexture && depthTexture.isDepthTexture) { if (depthTexture.type === FloatType) { glInternalFormat = 36012; } else if (depthTexture.type === UnsignedIntType) { glInternalFormat = 33190; } } const samples = getRenderTargetSamples(renderTarget); if (useMultisampledRTT(renderTarget)) { multisampledRTTExt.renderbufferStorageMultisampleEXT(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height); } else { _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height); } } else { _gl.renderbufferStorage(36161, glInternalFormat, renderTarget.width, renderTarget.height); } _gl.framebufferRenderbuffer(36160, 36096, 36161, renderbuffer); } else if (renderTarget.depthBuffer && renderTarget.stencilBuffer) { const samples = getRenderTargetSamples(renderTarget); if (isMultisample && useMultisampledRTT(renderTarget) === false) { _gl.renderbufferStorageMultisample(36161, samples, 35056, renderTarget.width, renderTarget.height); } else if (useMultisampledRTT(renderTarget)) { multisampledRTTExt.renderbufferStorageMultisampleEXT(36161, samples, 35056, renderTarget.width, renderTarget.height); } else { _gl.renderbufferStorage(36161, 34041, renderTarget.width, renderTarget.height); } _gl.framebufferRenderbuffer(36160, 33306, 36161, 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.encoding); const glType = utils.convert(texture.type); const glInternalFormat = getInternalFormat(texture.internalFormat, glFormat, glType, texture.encoding); const samples = getRenderTargetSamples(renderTarget); if (isMultisample && useMultisampledRTT(renderTarget) === false) { _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height); } else if (useMultisampledRTT(renderTarget)) { multisampledRTTExt.renderbufferStorageMultisampleEXT(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height); } else { _gl.renderbufferStorage(36161, glInternalFormat, renderTarget.width, renderTarget.height); } } } _gl.bindRenderbuffer(36161, 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(36160, 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(36160, 36096, 3553, webglDepthTexture, 0, samples); } else { _gl.framebufferTexture2D(36160, 36096, 3553, webglDepthTexture, 0); } } else if (renderTarget.depthTexture.format === DepthStencilFormat) { if (useMultisampledRTT(renderTarget)) { multisampledRTTExt.framebufferTexture2DMultisampleEXT(36160, 33306, 3553, webglDepthTexture, 0, samples); } else { _gl.framebufferTexture2D(36160, 33306, 3553, 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(36160, renderTargetProperties.__webglFramebuffer[i]); renderTargetProperties.__webglDepthbuffer[i] = _gl.createRenderbuffer(); setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer[i], renderTarget, false); } } else { state.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer); renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer(); setupRenderBufferStorage(renderTargetProperties.__webglDepthbuffer, renderTarget, false); } } state.bindFramebuffer(36160, null); } function rebindTextures(renderTarget, colorTexture, depthTexture) { const renderTargetProperties = properties.get(renderTarget); if (colorTexture !== void 0) { setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, renderTarget.texture, 36064, 3553); } 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++) { renderTargetProperties.__webglFramebuffer[i] = _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(36160, renderTargetProperties.__webglMultisampledFramebuffer); for (let i = 0; i < textures.length; i++) { const texture2 = textures[i]; renderTargetProperties.__webglColorRenderbuffer[i] = _gl.createRenderbuffer(); _gl.bindRenderbuffer(36161, renderTargetProperties.__webglColorRenderbuffer[i]); const glFormat = utils.convert(texture2.format, texture2.encoding); const glType = utils.convert(texture2.type); const glInternalFormat = getInternalFormat(texture2.internalFormat, glFormat, glType, texture2.encoding); const samples = getRenderTargetSamples(renderTarget); _gl.renderbufferStorageMultisample(36161, samples, glInternalFormat, renderTarget.width, renderTarget.height); _gl.framebufferRenderbuffer(36160, 36064 + i, 36161, renderTargetProperties.__webglColorRenderbuffer[i]); } _gl.bindRenderbuffer(36161, null); if (renderTarget.depthBuffer) { renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer(); setupRenderBufferStorage(renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true); } state.bindFramebuffer(36160, null); } } if (isCube) { state.bindTexture(34067, textureProperties.__webglTexture); setTextureParameters(34067, texture, supportsMips); for (let i = 0; i < 6; i++) { setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer[i], renderTarget, texture, 36064, 34069 + i); } if (textureNeedsGenerateMipmaps(texture, supportsMips)) { generateMipmap(34067); } 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(3553, attachmentProperties.__webglTexture); setTextureParameters(3553, attachment, supportsMips); setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, attachment, 36064 + i, 3553); if (textureNeedsGenerateMipmaps(attachment, supportsMips)) { generateMipmap(3553); } } state.unbindTexture(); } else { let glTextureType = 3553; if (renderTarget.isWebGL3DRenderTarget || renderTarget.isWebGLArrayRenderTarget) { if (isWebGL2) { glTextureType = renderTarget.isWebGL3DRenderTarget ? 32879 : 35866; } else { console.error("THREE.WebGLTextures: THREE.Data3DTexture and THREE.DataArrayTexture only supported with WebGL2."); } } state.bindTexture(glTextureType, textureProperties.__webglTexture); setTextureParameters(glTextureType, texture, supportsMips); setupFrameBufferTexture(renderTargetProperties.__webglFramebuffer, renderTarget, texture, 36064, glTextureType); 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 ? 34067 : 3553; 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 = 16384; const invalidationArray = []; const depthStyle = renderTarget.stencilBuffer ? 33306 : 36096; const renderTargetProperties = properties.get(renderTarget); const isMultipleRenderTargets = renderTarget.isWebGLMultipleRenderTargets === true; if (isMultipleRenderTargets) { for (let i = 0; i < textures.length; i++) { state.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer); _gl.framebufferRenderbuffer(36160, 36064 + i, 36161, null); state.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer); _gl.framebufferTexture2D(36009, 36064 + i, 3553, null, 0); } } state.bindFramebuffer(36008, renderTargetProperties.__webglMultisampledFramebuffer); state.bindFramebuffer(36009, renderTargetProperties.__webglFramebuffer); for (let i = 0; i < textures.length; i++) { invalidationArray.push(36064 + i); if (renderTarget.depthBuffer) { invalidationArray.push(depthStyle); } const ignoreDepthValues = renderTargetProperties.__ignoreDepthValues !== void 0 ? renderTargetProperties.__ignoreDepthValues : false; if (ignoreDepthValues === false) { if (renderTarget.depthBuffer) mask |= 256; if (renderTarget.stencilBuffer) mask |= 1024; } if (isMultipleRenderTargets) { _gl.framebufferRenderbuffer(36008, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer[i]); } if (ignoreDepthValues === true) { _gl.invalidateFramebuffer(36008, [depthStyle]); _gl.invalidateFramebuffer(36009, [depthStyle]); } if (isMultipleRenderTargets) { const webglTexture = properties.get(textures[i]).__webglTexture; _gl.framebufferTexture2D(36009, 36064, 3553, webglTexture, 0); } _gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, mask, 9728); if (supportsInvalidateFramebuffer) { _gl.invalidateFramebuffer(36008, invalidationArray); } } state.bindFramebuffer(36008, null); state.bindFramebuffer(36009, null); if (isMultipleRenderTargets) { for (let i = 0; i < textures.length; i++) { state.bindFramebuffer(36160, renderTargetProperties.__webglMultisampledFramebuffer); _gl.framebufferRenderbuffer(36160, 36064 + i, 36161, renderTargetProperties.__webglColorRenderbuffer[i]); const webglTexture = properties.get(textures[i]).__webglTexture; state.bindFramebuffer(36160, renderTargetProperties.__webglFramebuffer); _gl.framebufferTexture2D(36009, 36064 + i, 3553, webglTexture, 0); } } state.bindFramebuffer(36009, 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 encoding = texture.encoding; const format2 = texture.format; const type = texture.type; if (texture.isCompressedTexture === true || texture.isVideoTexture === true || texture.format === _SRGBAFormat) return image; if (encoding !== LinearEncoding) { if (encoding === sRGBEncoding) { 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 encoding:", encoding); } } 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, encoding = null) { let extension; if (p === UnsignedByteType) return 5121; if (p === UnsignedShort4444Type) return 32819; if (p === UnsignedShort5551Type) return 32820; if (p === ByteType) return 5120; if (p === ShortType) return 5122; if (p === UnsignedShortType) return 5123; if (p === IntType) return 5124; if (p === UnsignedIntType) return 5125; if (p === FloatType) return 5126; if (p === HalfFloatType) { if (isWebGL2) return 5131; extension = extensions.get("OES_texture_half_float"); if (extension !== null) { return extension.HALF_FLOAT_OES; } else { return null; } } if (p === AlphaFormat) return 6406; if (p === RGBAFormat) return 6408; if (p === LuminanceFormat) return 6409; if (p === LuminanceAlphaFormat) return 6410; if (p === DepthFormat) return 6402; if (p === DepthStencilFormat) return 34041; if (p === RedFormat) return 6403; if (p === RGBFormat) { console.warn("THREE.WebGLRenderer: THREE.RGBFormat has been removed. Use THREE.RGBAFormat instead. https://github.com/mrdoob/three.js/pull/23228"); return 6408; } if (p === _SRGBAFormat) { extension = extensions.get("EXT_sRGB"); if (extension !== null) { return extension.SRGB_ALPHA_EXT; } else { return null; } } if (p === RedIntegerFormat) return 36244; if (p === RGFormat) return 33319; if (p === RGIntegerFormat) return 33320; if (p === RGBAIntegerFormat) return 36249; if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format || p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) { if (encoding === sRGBEncoding) { 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 encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ETC2 : extension.COMPRESSED_RGB8_ETC2; if (p === RGBA_ETC2_EAC_Format) return encoding === sRGBEncoding ? 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 encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR : extension.COMPRESSED_RGBA_ASTC_4x4_KHR; if (p === RGBA_ASTC_5x4_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR : extension.COMPRESSED_RGBA_ASTC_5x4_KHR; if (p === RGBA_ASTC_5x5_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR : extension.COMPRESSED_RGBA_ASTC_5x5_KHR; if (p === RGBA_ASTC_6x5_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR : extension.COMPRESSED_RGBA_ASTC_6x5_KHR; if (p === RGBA_ASTC_6x6_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR : extension.COMPRESSED_RGBA_ASTC_6x6_KHR; if (p === RGBA_ASTC_8x5_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR : extension.COMPRESSED_RGBA_ASTC_8x5_KHR; if (p === RGBA_ASTC_8x6_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR : extension.COMPRESSED_RGBA_ASTC_8x6_KHR; if (p === RGBA_ASTC_8x8_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR : extension.COMPRESSED_RGBA_ASTC_8x8_KHR; if (p === RGBA_ASTC_10x5_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR : extension.COMPRESSED_RGBA_ASTC_10x5_KHR; if (p === RGBA_ASTC_10x6_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR : extension.COMPRESSED_RGBA_ASTC_10x6_KHR; if (p === RGBA_ASTC_10x8_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR : extension.COMPRESSED_RGBA_ASTC_10x8_KHR; if (p === RGBA_ASTC_10x10_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR : extension.COMPRESSED_RGBA_ASTC_10x10_KHR; if (p === RGBA_ASTC_12x10_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR : extension.COMPRESSED_RGBA_ASTC_12x10_KHR; if (p === RGBA_ASTC_12x12_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR : extension.COMPRESSED_RGBA_ASTC_12x12_KHR; } else { return null; } } if (p === RGBA_BPTC_Format) { extension = extensions.get("EXT_texture_compression_bptc"); if (extension !== null) { if (p === RGBA_BPTC_Format) return encoding === sRGBEncoding ? extension.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT : extension.COMPRESSED_RGBA_BPTC_UNORM_EXT; } else { return null; } } if (p === UnsignedInt248Type) { if (isWebGL2) return 34042; 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; } 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); if (hand.joints[inputjoint.jointName] === void 0) { const joint2 = new Group(); joint2.matrixAutoUpdate = false; joint2.visible = false; hand.joints[inputjoint.jointName] = joint2; hand.add(joint2); } const joint = hand.joints[inputjoint.jointName]; if (jointPose !== null) { joint.matrix.fromArray(jointPose.transform.matrix); joint.matrix.decompose(joint.position, joint.rotation, joint.scale); 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); 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); 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; } }; 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; } }; 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 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 cameraVR = new ArrayCamera(); cameraVR.layers.enable(1); cameraVR.layers.enable(2); let _currentDepthNear = null; let _currentDepthFar = null; this.cameraAutoUpdate = true; this.enabled = false; this.isPresenting = false; this.getController = function(index5) { let controller = controllers[index5]; if (controller === void 0) { controller = new WebXRController(); controllers[index5] = controller; } return controller.getTargetRaySpace(); }; this.getControllerGrip = function(index5) { let controller = controllers[index5]; if (controller === void 0) { controller = new WebXRController(); controllers[index5] = controller; } return controller.getGripSpace(); }; this.getHand = function(index5) { let controller = controllers[index5]; if (controller === void 0) { controller = new WebXRController(); controllers[index5] = 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.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: attributes.alpha, 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, encoding: renderer3.outputEncoding }); } else { let depthFormat = null; let depthType = null; let glDepthFormat = null; if (attributes.depth) { glDepthFormat = attributes.stencil ? 35056 : 33190; depthFormat = attributes.stencil ? DepthStencilFormat : DepthFormat; depthType = attributes.stencil ? UnsignedInt248Type : UnsignedIntType; } const projectionlayerInit = { colorFormat: 32856, 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, encoding: renderer3.outputEncoding, samples: attributes.antialias ? 4 : 0 }); const renderTargetProperties = renderer3.properties.get(newRenderTarget); renderTargetProperties.__ignoreDepthValues = glProjLayer.ignoreDepthValues; } newRenderTarget.isXRRenderTarget = true; this.setFoveation(1); customReferenceSpace = null; referenceSpace = await session.requestReferenceSpace(referenceSpaceType); animation.setContext(session); animation.start(); scope.isPresenting = true; scope.dispatchEvent({ type: "sessionstart" }); } }; function onInputSourcesChange(event) { for (let i = 0; i < event.removed.length; i++) { const inputSource = event.removed[i]; const index5 = controllerInputSources.indexOf(inputSource); if (index5 >= 0) { controllerInputSources[index5] = null; controllers[index5].dispatchEvent({ type: "disconnected", data: 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.dispatchEvent({ type: "connected", data: 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); } 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; cameraVR.near = cameraR.near = cameraL.near = camera3.near; cameraVR.far = cameraR.far = cameraL.far = camera3.far; if (_currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far) { session.updateRenderState({ depthNear: cameraVR.near, depthFar: cameraVR.far }); _currentDepthNear = cameraVR.near; _currentDepthFar = cameraVR.far; } const parent = camera3.parent; const cameras2 = cameraVR.cameras; updateCamera(cameraVR, parent); for (let i = 0; i < cameras2.length; i++) { updateCamera(cameras2[i], parent); } cameraVR.matrixWorld.decompose(cameraVR.position, cameraVR.quaternion, cameraVR.scale); camera3.position.copy(cameraVR.position); camera3.quaternion.copy(cameraVR.quaternion); camera3.scale.copy(cameraVR.scale); camera3.matrix.copy(cameraVR.matrix); camera3.matrixWorld.copy(cameraVR.matrixWorld); const children = camera3.children; for (let i = 0, l = children.length; i < l; i++) { children[i].updateMatrixWorld(true); } if (cameras2.length === 2) { setProjectionFromUnion(cameraVR, cameraL, cameraR); } else { cameraVR.projectionMatrix.copy(cameraL.projectionMatrix); } }; this.getCamera = function() { return cameraVR; }; this.getFoveation = function() { if (glProjLayer !== null) { return glProjLayer.fixedFoveation; } if (glBaseLayer !== null) { return glBaseLayer.fixedFoveation; } return void 0; }; this.setFoveation = function(foveation) { if (glProjLayer !== null) { glProjLayer.fixedFoveation = foveation; } if (glBaseLayer !== null && glBaseLayer.fixedFoveation !== void 0) { glBaseLayer.fixedFoveation = foveation; } }; 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 cameraVRNeedsUpdate = false; if (views.length !== cameraVR.cameras.length) { cameraVR.cameras.length = 0; cameraVRNeedsUpdate = 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.projectionMatrix.fromArray(view.projectionMatrix); camera3.viewport.set(viewport.x, viewport.y, viewport.width, viewport.height); if (i === 0) { cameraVR.matrix.copy(camera3.matrix); } if (cameraVRNeedsUpdate === true) { cameraVR.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); xrFrame = null; } const animation = new WebGLAnimation(); animation.setAnimationLoop(onAnimationFrame); this.setAnimationLoop = function(callback) { onAnimationFrameCallback = callback; }; this.dispose = function() { }; } }; function WebGLMaterials(renderer3, properties) { function refreshFogUniforms(uniforms, fog) { uniforms.fogColor.value.copy(fog.color); 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; } if (material.alphaMap) { uniforms.alphaMap.value = material.alphaMap; } if (material.bumpMap) { uniforms.bumpMap.value = material.bumpMap; uniforms.bumpScale.value = material.bumpScale; if (material.side === BackSide) uniforms.bumpScale.value *= -1; } if (material.displacementMap) { uniforms.displacementMap.value = material.displacementMap; uniforms.displacementScale.value = material.displacementScale; uniforms.displacementBias.value = material.displacementBias; } if (material.emissiveMap) { uniforms.emissiveMap.value = material.emissiveMap; } if (material.normalMap) { uniforms.normalMap.value = material.normalMap; uniforms.normalScale.value.copy(material.normalScale); if (material.side === BackSide) uniforms.normalScale.value.negate(); } if (material.specularMap) { uniforms.specularMap.value = material.specularMap; } 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.physicallyCorrectLights !== true ? Math.PI : 1; uniforms.lightMapIntensity.value = material.lightMapIntensity * scaleFactor; } if (material.aoMap) { uniforms.aoMap.value = material.aoMap; uniforms.aoMapIntensity.value = material.aoMapIntensity; } let uvScaleMap; if (material.map) { uvScaleMap = material.map; } else if (material.specularMap) { uvScaleMap = material.specularMap; } else if (material.displacementMap) { uvScaleMap = material.displacementMap; } else if (material.normalMap) { uvScaleMap = material.normalMap; } else if (material.bumpMap) { uvScaleMap = material.bumpMap; } else if (material.roughnessMap) { uvScaleMap = material.roughnessMap; } else if (material.metalnessMap) { uvScaleMap = material.metalnessMap; } else if (material.alphaMap) { uvScaleMap = material.alphaMap; } else if (material.emissiveMap) { uvScaleMap = material.emissiveMap; } else if (material.clearcoatMap) { uvScaleMap = material.clearcoatMap; } else if (material.clearcoatNormalMap) { uvScaleMap = material.clearcoatNormalMap; } else if (material.clearcoatRoughnessMap) { uvScaleMap = material.clearcoatRoughnessMap; } else if (material.iridescenceMap) { uvScaleMap = material.iridescenceMap; } else if (material.iridescenceThicknessMap) { uvScaleMap = material.iridescenceThicknessMap; } else if (material.specularIntensityMap) { uvScaleMap = material.specularIntensityMap; } else if (material.specularColorMap) { uvScaleMap = material.specularColorMap; } else if (material.transmissionMap) { uvScaleMap = material.transmissionMap; } else if (material.thicknessMap) { uvScaleMap = material.thicknessMap; } else if (material.sheenColorMap) { uvScaleMap = material.sheenColorMap; } else if (material.sheenRoughnessMap) { uvScaleMap = material.sheenRoughnessMap; } if (uvScaleMap !== void 0) { if (uvScaleMap.isWebGLRenderTarget) { uvScaleMap = uvScaleMap.texture; } if (uvScaleMap.matrixAutoUpdate === true) { uvScaleMap.updateMatrix(); } uniforms.uvTransform.value.copy(uvScaleMap.matrix); } let uv2ScaleMap; if (material.aoMap) { uv2ScaleMap = material.aoMap; } else if (material.lightMap) { uv2ScaleMap = material.lightMap; } if (uv2ScaleMap !== void 0) { if (uv2ScaleMap.isWebGLRenderTarget) { uv2ScaleMap = uv2ScaleMap.texture; } if (uv2ScaleMap.matrixAutoUpdate === true) { uv2ScaleMap.updateMatrix(); } uniforms.uv2Transform.value.copy(uv2ScaleMap.matrix); } } function refreshUniformsLine(uniforms, material) { uniforms.diffuse.value.copy(material.color); uniforms.opacity.value = material.opacity; } 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; } if (material.alphaMap) { uniforms.alphaMap.value = material.alphaMap; } if (material.alphaTest > 0) { uniforms.alphaTest.value = material.alphaTest; } let uvScaleMap; if (material.map) { uvScaleMap = material.map; } else if (material.alphaMap) { uvScaleMap = material.alphaMap; } if (uvScaleMap !== void 0) { if (uvScaleMap.matrixAutoUpdate === true) { uvScaleMap.updateMatrix(); } uniforms.uvTransform.value.copy(uvScaleMap.matrix); } } 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; } if (material.alphaMap) { uniforms.alphaMap.value = material.alphaMap; } if (material.alphaTest > 0) { uniforms.alphaTest.value = material.alphaTest; } let uvScaleMap; if (material.map) { uvScaleMap = material.map; } else if (material.alphaMap) { uvScaleMap = material.alphaMap; } if (uvScaleMap !== void 0) { if (uvScaleMap.matrixAutoUpdate === true) { uvScaleMap.updateMatrix(); } uniforms.uvTransform.value.copy(uvScaleMap.matrix); } } 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.roughness.value = material.roughness; uniforms.metalness.value = material.metalness; if (material.roughnessMap) { uniforms.roughnessMap.value = material.roughnessMap; } if (material.metalnessMap) { uniforms.metalnessMap.value = material.metalnessMap; } 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; } if (material.sheenRoughnessMap) { uniforms.sheenRoughnessMap.value = material.sheenRoughnessMap; } } if (material.clearcoat > 0) { uniforms.clearcoat.value = material.clearcoat; uniforms.clearcoatRoughness.value = material.clearcoatRoughness; if (material.clearcoatMap) { uniforms.clearcoatMap.value = material.clearcoatMap; } if (material.clearcoatRoughnessMap) { uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap; } if (material.clearcoatNormalMap) { uniforms.clearcoatNormalScale.value.copy(material.clearcoatNormalScale); uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap; 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; } if (material.iridescenceThicknessMap) { uniforms.iridescenceThicknessMap.value = material.iridescenceThicknessMap; } } 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; } uniforms.thickness.value = material.thickness; if (material.thicknessMap) { uniforms.thicknessMap.value = material.thicknessMap; } uniforms.attenuationDistance.value = material.attenuationDistance; uniforms.attenuationColor.value.copy(material.attenuationColor); } uniforms.specularIntensity.value = material.specularIntensity; uniforms.specularColor.value.copy(material.specularColor); if (material.specularIntensityMap) { uniforms.specularIntensityMap.value = material.specularIntensityMap; } if (material.specularColorMap) { uniforms.specularColorMap.value = material.specularColorMap; } } function refreshUniformsMatcap(uniforms, material) { if (material.matcap) { uniforms.matcap.value = material.matcap; } } function refreshUniformsDistance(uniforms, material) { uniforms.referencePosition.value.copy(material.referencePosition); uniforms.nearDistance.value = material.nearDistance; uniforms.farDistance.value = material.farDistance; } return { refreshFogUniforms, refreshMaterialUniforms }; } function WebGLUniformsGroups(gl, info, capabilities, state) { let buffers = {}; let updateList = {}; let allocatedBindingPoints = []; const maxBindingPoints = capabilities.isWebGL2 ? gl.getParameter(35375) : 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(35345, buffer); gl.bufferData(35345, size, usage); gl.bindBuffer(35345, null); gl.bindBufferBase(35345, 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(35345, buffer); for (let i = 0, il = uniforms.length; i < il; i++) { const uniform = uniforms[i]; if (hasUniformChanged(uniform, i, cache) === true) { const value = uniform.value; const offset = uniform.__offset; if (typeof value === "number") { uniform.__data[0] = value; gl.bufferSubData(35345, offset, uniform.__data); } else { if (uniform.value.isMatrix3) { uniform.__data[0] = uniform.value.elements[0]; uniform.__data[1] = uniform.value.elements[1]; uniform.__data[2] = uniform.value.elements[2]; uniform.__data[3] = uniform.value.elements[0]; uniform.__data[4] = uniform.value.elements[3]; uniform.__data[5] = uniform.value.elements[4]; uniform.__data[6] = uniform.value.elements[5]; uniform.__data[7] = uniform.value.elements[0]; uniform.__data[8] = uniform.value.elements[6]; uniform.__data[9] = uniform.value.elements[7]; uniform.__data[10] = uniform.value.elements[8]; uniform.__data[11] = uniform.value.elements[0]; } else { value.toArray(uniform.__data); } gl.bufferSubData(35345, offset, uniform.__data); } } } gl.bindBuffer(35345, null); } function hasUniformChanged(uniform, index5, cache) { const value = uniform.value; if (cache[index5] === void 0) { if (typeof value === "number") { cache[index5] = value; } else { cache[index5] = value.clone(); } return true; } else { if (typeof value === "number") { if (cache[index5] !== value) { cache[index5] = value; return true; } } else { const cachedObject = cache[index5]; if (cachedObject.equals(value) === false) { cachedObject.copy(value); 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 info2 = getUniformSize(uniform); uniform.__data = new Float32Array(info2.storage / Float32Array.BYTES_PER_ELEMENT); uniform.__offset = offset; if (i > 0) { chunkOffset = offset % chunkSize; const remainingSizeInChunk = chunkSize - chunkOffset; if (chunkOffset !== 0 && remainingSizeInChunk - info2.boundary < 0) { offset += chunkSize - chunkOffset; uniform.__offset = offset; } } offset += info2.storage; } chunkOffset = offset % chunkSize; if (chunkOffset > 0) offset += chunkSize - chunkOffset; uniformsGroup.__size = offset; uniformsGroup.__cache = {}; return this; } function getUniformSize(uniform) { const value = uniform.value; const info2 = { boundary: 0, storage: 0 }; 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 index5 = allocatedBindingPoints.indexOf(uniformsGroup.__bindingPointIndex); allocatedBindingPoints.splice(index5, 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 }; } function createCanvasElement() { const canvas = createElementNS("canvas"); canvas.style.display = "block"; return canvas; } function WebGLRenderer(parameters = {}) { this.isWebGLRenderer = true; const _canvas2 = parameters.canvas !== void 0 ? parameters.canvas : createCanvasElement(), _context = parameters.context !== void 0 ? parameters.context : null, _depth = parameters.depth !== void 0 ? parameters.depth : true, _stencil = parameters.stencil !== void 0 ? parameters.stencil : true, _antialias = parameters.antialias !== void 0 ? parameters.antialias : false, _premultipliedAlpha = parameters.premultipliedAlpha !== void 0 ? parameters.premultipliedAlpha : true, _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== void 0 ? parameters.preserveDrawingBuffer : false, _powerPreference = parameters.powerPreference !== void 0 ? parameters.powerPreference : "default", _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== void 0 ? parameters.failIfMajorPerformanceCaveat : false; let _alpha; if (_context !== null) { _alpha = _context.getContextAttributes().alpha; } else { _alpha = parameters.alpha !== void 0 ? parameters.alpha : false; } let currentRenderList = null; let currentRenderState = null; const renderListStack = []; const renderStateStack = []; this.domElement = _canvas2; this.debug = { checkShaderErrors: true }; this.autoClear = true; this.autoClearColor = true; this.autoClearDepth = true; this.autoClearStencil = true; this.sortObjects = true; this.clippingPlanes = []; this.localClippingEnabled = false; this.outputEncoding = LinearEncoding; this.physicallyCorrectLights = false; this.toneMapping = NoToneMapping; this.toneMappingExposure = 1; Object.defineProperties(this, { gammaFactor: { get: function() { console.warn("THREE.WebGLRenderer: .gammaFactor has been removed."); return 2; }, set: function() { console.warn("THREE.WebGLRenderer: .gammaFactor has been removed."); } } }); 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; let _width = _canvas2.width; let _height = _canvas2.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 _vector22 = 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 context = _canvas2.getContext(contextName, contextAttributes); if (context !== null) return context; } return null; } try { const contextAttributes = { alpha: true, depth: _depth, stencil: _stencil, antialias: _antialias, premultipliedAlpha: _premultipliedAlpha, preserveDrawingBuffer: _preserveDrawingBuffer, powerPreference: _powerPreference, failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat }; if ("setAttribute" in _canvas2) _canvas2.setAttribute("data-engine", `three.js r${REVISION}`); _canvas2.addEventListener("webglcontextlost", onContextLost, false); _canvas2.addEventListener("webglcontextrestored", onContextRestore, false); _canvas2.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 (_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(); 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, 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) { if (xr.isPresenting) { console.warn("THREE.WebGLRenderer: Can't change size while VR device is presenting."); return; } _width = width; _height = height; _canvas2.width = Math.floor(width * _pixelRatio); _canvas2.height = Math.floor(height * _pixelRatio); if (updateStyle !== false) { _canvas2.style.width = width + "px"; _canvas2.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; _canvas2.width = Math.floor(width * pixelRatio); _canvas2.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(x2, y2, width, height) { if (x2.isVector4) { _viewport.set(x2.x, x2.y, x2.z, x2.w); } else { _viewport.set(x2, y2, width, height); } state.viewport(_currentViewport.copy(_viewport).multiplyScalar(_pixelRatio).floor()); }; this.getScissor = function(target) { return target.copy(_scissor); }; this.setScissor = function(x2, y2, width, height) { if (x2.isVector4) { _scissor.set(x2.x, x2.y, x2.z, x2.w); } else { _scissor.set(x2, y2, 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, depth = true, stencil = true) { let bits = 0; if (color) bits |= 16384; if (depth) bits |= 256; if (stencil) bits |= 1024; _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() { _canvas2.removeEventListener("webglcontextlost", onContextLost, false); _canvas2.removeEventListener("webglcontextrestored", onContextRestore, false); _canvas2.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 index5 = geometry.index; const position = geometry.attributes.position; if (index5 === null) { if (position === void 0 || position.count === 0) return; } else if (index5.count === 0) { return; } let rangeFactor = 1; if (material.wireframe === true) { index5 = geometries.getWireframeAttribute(geometry); rangeFactor = 2; } bindingStates.setup(object, material, program, geometry, index5); let attribute; let renderer3 = bufferRenderer; if (index5 !== null) { attribute = attributes.get(index5); renderer3 = indexedBufferRenderer; renderer3.setIndex(attribute); } const dataCount = index5 !== null ? index5.count : position.count; const rangeStart = geometry.drawRange.start * rangeFactor; const rangeCount = geometry.drawRange.count * rangeFactor; const groupStart = group !== null ? group.start * rangeFactor : 0; const groupCount = group !== null ? group.count * rangeFactor : Infinity; const drawStart = Math.max(rangeStart, groupStart); const drawEnd = Math.min(dataCount, rangeStart + rangeCount, groupStart + groupCount) - 1; const drawCount = Math.max(0, drawEnd - drawStart + 1); if (drawCount === 0) return; if (object.isMesh) { if (material.wireframe === true) { state.setLineWidth(material.wireframeLinewidth * getTargetPixelRatio()); renderer3.setMode(1); } else { renderer3.setMode(4); } } else if (object.isLine) { let lineWidth = material.linewidth; if (lineWidth === void 0) lineWidth = 1; state.setLineWidth(lineWidth * getTargetPixelRatio()); if (object.isLineSegments) { renderer3.setMode(1); } else if (object.isLineLoop) { renderer3.setMode(2); } else { renderer3.setMode(3); } } else if (object.isPoints) { renderer3.setMode(0); } else if (object.isSprite) { renderer3.setMode(4); } if (object.isInstancedMesh) { renderer3.renderInstances(drawStart, drawCount, object.count); } else if (geometry.isInstancedBufferGeometry) { const instanceCount = Math.min(geometry.instanceCount, geometry._maxInstanceCount); renderer3.renderInstances(drawStart, drawCount, instanceCount); } else { renderer3.render(drawStart, drawCount); } }; this.compile = function(scene3, camera3) { 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.physicallyCorrectLights); 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]; getProgram(material2, scene3, object); } } else { getProgram(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 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.autoUpdate === true) scene3.updateMatrixWorld(); if (camera3.parent === null) 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, camera3); 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); } 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.physicallyCorrectLights); 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.isSkinnedMesh) { if (object.skeleton.frame !== info.render.frame) { object.skeleton.update(); object.skeleton.frame = info.render.frame; } } if (!object.frustumCulled || _frustum.intersectsObject(object)) { if (sortObjects) { _vector3.setFromMatrixPosition(object.matrixWorld).applyMatrix4(_projScreenMatrix); } const geometry = objects.update(object); const material = object.material; 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 (transmissiveObjects.length > 0) renderTransmissionPass(opaqueObjects, 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, scene3, camera3) { 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 && _antialias === true ? 4 : 0 }); } _this.getDrawingBufferSize(_vector22); if (isWebGL2) { _transmissionRenderTarget.setSize(_vector22.x, _vector22.y); } else { _transmissionRenderTarget.setSize(floorPowerOfTwo(_vector22.x), floorPowerOfTwo(_vector22.y)); } const currentRenderTarget = _this.getRenderTarget(); _this.setRenderTarget(_transmissionRenderTarget); _this.clear(); const currentToneMapping = _this.toneMapping; _this.toneMapping = NoToneMapping; renderObjects(opaqueObjects, scene3, camera3); _this.toneMapping = currentToneMapping; textures.updateMultisampleRenderTarget(_transmissionRenderTarget); textures.updateRenderTargetMipmap(_transmissionRenderTarget); _this.setRenderTarget(currentRenderTarget); } 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.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.spotShadowMatrix.value = lights.state.spotShadowMatrix; uniforms.pointShadowMap.value = lights.state.pointShadowMap; uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix; } const progUniforms = program.getUniforms(); const uniformsList = WebGLUniforms.seqWithValue(progUniforms.seq, uniforms); materialProperties.currentProgram = program; materialProperties.uniformsList = uniformsList; return program; } function updateCommonMaterialProperties(material, parameters2) { const materialProperties = properties.get(material); materialProperties.outputEncoding = parameters2.outputEncoding; materialProperties.instancing = parameters2.instancing; 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 encoding = _currentRenderTarget === null ? _this.outputEncoding : _currentRenderTarget.isXRRenderTarget === true ? _currentRenderTarget.texture.encoding : LinearEncoding; 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 = !!material.normalMap && !!geometry.attributes.tangent; const morphTargets = !!geometry.morphAttributes.position; const morphNormals = !!geometry.morphAttributes.normal; const morphColors = !!geometry.morphAttributes.color; const toneMapping = material.toneMapped ? _this.toneMapping : NoToneMapping; 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.outputEncoding !== encoding) { 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 (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); if (capabilities.logarithmicDepthBuffer) { p_uniforms.setValue(_gl, "logDepthBufFC", 2 / (Math.log(camera3.far + 1) / Math.LN2)); } if (_currentCamera !== camera3) { _currentCamera = camera3; refreshMaterial = true; refreshLights = true; } if (material.isShaderMaterial || material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshStandardMaterial || material.envMap) { const uCamPos = p_uniforms.map.cameraPosition; if (uCamPos !== void 0) { uCamPos.setValue(_gl, _vector3.setFromMatrixPosition(camera3.matrixWorld)); } } if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial) { p_uniforms.setValue(_gl, "isOrthographic", camera3.isOrthographicCamera === true); } if (material.isMeshPhongMaterial || material.isMeshToonMaterial || material.isMeshLambertMaterial || material.isMeshBasicMaterial || material.isMeshStandardMaterial || material.isShaderMaterial || material.isShadowMaterial || object.isSkinnedMesh) { p_uniforms.setValue(_gl, "viewMatrix", camera3.matrixWorldInverse); } } 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, material, program); } if (refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow) { materialProperties.receiveShadow = object.receiveShadow; p_uniforms.setValue(_gl, "receiveShadow", object.receiveShadow); } 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, materialProperties.uniformsList, m_uniforms, textures); } if (material.isShaderMaterial && material.uniformsNeedUpdate === true) { WebGLUniforms.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; if (renderTarget) { const renderTargetProperties = properties.get(renderTarget); if (renderTargetProperties.__useDefaultFramebuffer !== void 0) { state.bindFramebuffer(36160, 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); } } let framebuffer = null; let isCube = false; let isRenderTarget3D = false; if (renderTarget) { const texture = renderTarget.texture; if (texture.isData3DTexture || texture.isDataArrayTexture) { isRenderTarget3D = true; } const __webglFramebuffer = properties.get(renderTarget).__webglFramebuffer; if (renderTarget.isWebGLCubeRenderTarget) { framebuffer = __webglFramebuffer[activeCubeFace]; isCube = true; } else if (capabilities.isWebGL2 && renderTarget.samples > 0 && textures.useMultisampledRTT(renderTarget) === false) { framebuffer = properties.get(renderTarget).__webglMultisampledFramebuffer; } 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(36160, 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(36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel); } else if (isRenderTarget3D) { const textureProperties = properties.get(renderTarget.texture); const layer = activeCubeFace || 0; _gl.framebufferTextureLayer(36160, 36064, textureProperties.__webglTexture, activeMipmapLevel || 0, layer); } _currentMaterialId = -1; }; this.readRenderTargetPixels = function(renderTarget, x2, y2, 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(36160, framebuffer); try { const texture = renderTarget.texture; const textureFormat = texture.format; const textureType = texture.type; if (textureFormat !== RGBAFormat && utils.convert(textureFormat) !== _gl.getParameter(35739)) { 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(35738) && !(textureType === FloatType && (capabilities.isWebGL2 || extensions.has("OES_texture_float") || extensions.has("WEBGL_color_buffer_float"))) && !halfFloatSupportedByExt) { console.error("THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type."); return; } if (x2 >= 0 && x2 <= renderTarget.width - width && (y2 >= 0 && y2 <= renderTarget.height - height)) { _gl.readPixels(x2, y2, width, height, utils.convert(textureFormat), utils.convert(textureType), buffer); } } finally { const framebuffer2 = _currentRenderTarget !== null ? properties.get(_currentRenderTarget).__webglFramebuffer : null; state.bindFramebuffer(36160, 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(3553, 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(37440, dstTexture.flipY); _gl.pixelStorei(37441, dstTexture.premultiplyAlpha); _gl.pixelStorei(3317, dstTexture.unpackAlignment); if (srcTexture.isDataTexture) { _gl.texSubImage2D(3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data); } else { if (srcTexture.isCompressedTexture) { _gl.compressedTexSubImage2D(3553, level, position.x, position.y, srcTexture.mipmaps[0].width, srcTexture.mipmaps[0].height, glFormat, srcTexture.mipmaps[0].data); } else { _gl.texSubImage2D(3553, level, position.x, position.y, glFormat, glType, srcTexture.image); } } if (level === 0 && dstTexture.generateMipmaps) _gl.generateMipmap(3553); 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 depth = 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 = 32879; } else if (dstTexture.isDataArrayTexture) { textures.setTexture2DArray(dstTexture, 0); glTarget = 35866; } else { console.warn("THREE.WebGLRenderer.copyTextureToTexture3D: only supports THREE.DataTexture3D and THREE.DataTexture2DArray."); return; } _gl.pixelStorei(37440, dstTexture.flipY); _gl.pixelStorei(37441, dstTexture.premultiplyAlpha); _gl.pixelStorei(3317, dstTexture.unpackAlignment); const unpackRowLen = _gl.getParameter(3314); const unpackImageHeight = _gl.getParameter(32878); const unpackSkipPixels = _gl.getParameter(3316); const unpackSkipRows = _gl.getParameter(3315); const unpackSkipImages = _gl.getParameter(32877); const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[0] : srcTexture.image; _gl.pixelStorei(3314, image.width); _gl.pixelStorei(32878, image.height); _gl.pixelStorei(3316, sourceBox.min.x); _gl.pixelStorei(3315, sourceBox.min.y); _gl.pixelStorei(32877, sourceBox.min.z); if (srcTexture.isDataTexture || srcTexture.isData3DTexture) { _gl.texSubImage3D(glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, glType, image.data); } else { if (srcTexture.isCompressedTexture) { console.warn("THREE.WebGLRenderer.copyTextureToTexture3D: untested support for compressed srcTexture."); _gl.compressedTexSubImage3D(glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, image.data); } else { _gl.texSubImage3D(glTarget, level, position.x, position.y, position.z, width, height, depth, glFormat, glType, image); } } _gl.pixelStorei(3314, unpackRowLen); _gl.pixelStorei(32878, unpackImageHeight); _gl.pixelStorei(3316, unpackSkipPixels); _gl.pixelStorei(3315, unpackSkipRows); _gl.pixelStorei(32877, 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) { 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 })); } } var WebGL1Renderer = class extends WebGLRenderer { }; WebGL1Renderer.prototype.isWebGL1Renderer = true; var Scene = class extends Object3D { constructor() { super(); this.isScene = true; this.type = "Scene"; this.background = null; this.environment = null; this.fog = null; this.overrideMaterial = null; this.autoUpdate = true; 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(); if (source.overrideMaterial !== null) this.overrideMaterial = source.overrideMaterial.clone(); this.autoUpdate = source.autoUpdate; this.matrixAutoUpdate = source.matrixAutoUpdate; return this; } toJSON(meta) { const data = super.toJSON(meta); if (this.fog !== null) data.object.fog = this.fog.toJSON(); return data; } }; var LineBasicMaterial = class extends Material { constructor(parameters) { super(); this.isLineBasicMaterial = true; this.type = "LineBasicMaterial"; this.color = new Color(16777215); 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.linewidth = source.linewidth; this.linecap = source.linecap; this.linejoin = source.linejoin; this.fog = source.fog; return this; } }; var _start$1 = /* @__PURE__ */ new Vector3(); var _end$1 = /* @__PURE__ */ new Vector3(); var _inverseMatrix$1 = /* @__PURE__ */ new Matrix4(); var _ray$1 = /* @__PURE__ */ new Ray(); var _sphere$1 = /* @__PURE__ */ new Sphere(); var Line = class extends Object3D { constructor(geometry = new BufferGeometry(), 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 = 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 Float32BufferAttribute(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 Vector3(); const vEnd = new Vector3(); const interSegment = new Vector3(); const interRay = new Vector3(); const step = this.isLineSegments ? 2 : 1; const index5 = geometry.index; const attributes = geometry.attributes; const positionAttribute = attributes.position; if (index5 !== null) { const start = Math.max(0, drawRange.start); const end = Math.min(index5.count, drawRange.start + drawRange.count); for (let i = start, l = end - 1; i < l; i += step) { const a2 = index5.getX(i); const b = index5.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, 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, 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; } getPoint() { console.warn("THREE.Curve: .getPoint() not implemented."); return null; } getPointAt(u, optionalTarget) { const t = this.getUtoTmapping(u); return this.getPoint(t, optionalTarget); } getPoints(divisions = 5) { const points = []; for (let d = 0; d <= divisions; d++) { points.push(this.getPoint(d / divisions)); } return points; } getSpacedPoints(divisions = 5) { const points = []; for (let d = 0; d <= divisions; d++) { points.push(this.getPointAt(d / divisions)); } return points; } getLength() { const lengths = this.getLengths(); return lengths[lengths.length - 1]; } 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(); } 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; } 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 Vector2() : new Vector3()); 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 Vector3(); const tangents = []; const normals = []; const binormals = []; const vec = new Vector3(); const mat = new Matrix4(); for (let i = 0; i <= segments; i++) { const u = i / segments; tangents[i] = this.getTangentAt(u, new Vector3()); } normals[0] = new Vector3(); binormals[0] = new Vector3(); 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(clamp(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(clamp(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.5, 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 Vector2(); 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 x2 = this.aX + this.xRadius * Math.cos(angle); let y2 = 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 = x2 - this.aX; const ty = y2 - this.aY; x2 = tx * cos - ty * sin + this.aX; y2 = tx * sin + ty * cos + this.aY; } return point.set(x2, y2); } 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, x2, x3, tension) { init4(x1, x2, tension * (x2 - x0), tension * (x3 - x1)); }, initNonuniformCatmullRom: function(x0, x1, x2, x3, dt0, dt1, dt2) { let t1 = (x1 - x0) / dt0 - (x2 - x0) / (dt0 + dt1) + (x2 - x1) / dt1; let t2 = (x2 - x1) / dt1 - (x3 - x1) / (dt1 + dt2) + (x3 - x2) / dt2; t1 *= dt1; t2 *= dt1; init4(x1, x2, 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 Vector3(); 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 Vector3()) { 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 Vector3().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 Vector2(), v1 = new Vector2(), v2 = new Vector2(), v3 = new Vector2()) { super(); this.isCubicBezierCurve = true; this.type = "CubicBezierCurve"; this.v0 = v0; this.v1 = v1; this.v2 = v2; this.v3 = v3; } getPoint(t, optionalTarget = new Vector2()) { 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 Vector3(), v1 = new Vector3(), v2 = new Vector3(), v3 = new Vector3()) { super(); this.isCubicBezierCurve3 = true; this.type = "CubicBezierCurve3"; this.v0 = v0; this.v1 = v1; this.v2 = v2; this.v3 = v3; } getPoint(t, optionalTarget = new Vector3()) { 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 Vector2(), v2 = new Vector2()) { super(); this.isLineCurve = true; this.type = "LineCurve"; this.v1 = v1; this.v2 = v2; } getPoint(t, optionalTarget = new Vector2()) { 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; } getPointAt(u, optionalTarget) { return this.getPoint(u, optionalTarget); } getTangent(t, optionalTarget) { const tangent = optionalTarget || new Vector2(); tangent.copy(this.v2).sub(this.v1).normalize(); return tangent; } 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 Vector3(), v2 = new Vector3()) { super(); this.isLineCurve3 = true; this.type = "LineCurve3"; this.v1 = v1; this.v2 = v2; } getPoint(t, optionalTarget = new Vector3()) { 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; } getPointAt(u, optionalTarget) { return this.getPoint(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 Vector2(), v1 = new Vector2(), v2 = new Vector2()) { super(); this.isQuadraticBezierCurve = true; this.type = "QuadraticBezierCurve"; this.v0 = v0; this.v1 = v1; this.v2 = v2; } getPoint(t, optionalTarget = new Vector2()) { 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 Vector3(), v1 = new Vector3(), v2 = new Vector3()) { super(); this.isQuadraticBezierCurve3 = true; this.type = "QuadraticBezierCurve3"; this.v0 = v0; this.v1 = v1; this.v2 = v2; } getPoint(t, optionalTarget = new Vector3()) { 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 Vector2()) { 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 Vector2().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 BufferGeometry { constructor(radiusTop = 1, radiusBottom = 1, height = 1, radialSegments = 8, 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 index5 = 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 Float32BufferAttribute(vertices, 3)); this.setAttribute("normal", new Float32BufferAttribute(normals, 3)); this.setAttribute("uv", new Float32BufferAttribute(uvs, 2)); function generateTorso() { const normal = new Vector3(); const vertex2 = new Vector3(); let groupCount = 0; const slope = (radiusBottom - radiusTop) / height; for (let y2 = 0; y2 <= heightSegments; y2++) { const indexRow = []; const v = y2 / heightSegments; const radius = v * (radiusBottom - radiusTop) + radiusTop; for (let x2 = 0; x2 <= radialSegments; x2++) { const u = x2 / radialSegments; const theta = u * thetaLength + thetaStart; const sinTheta = Math.sin(theta); const cosTheta = Math.cos(theta); vertex2.x = radius * sinTheta; vertex2.y = -v * height + halfHeight; vertex2.z = radius * cosTheta; vertices.push(vertex2.x, vertex2.y, vertex2.z); normal.set(sinTheta, slope, cosTheta).normalize(); normals.push(normal.x, normal.y, normal.z); uvs.push(u, 1 - v); indexRow.push(index5++); } indexArray.push(indexRow); } for (let x2 = 0; x2 < radialSegments; x2++) { for (let y2 = 0; y2 < heightSegments; y2++) { const a2 = indexArray[y2][x2]; const b = indexArray[y2 + 1][x2]; const c2 = indexArray[y2 + 1][x2 + 1]; const d = indexArray[y2][x2 + 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 = index5; const uv = new Vector2(); const vertex2 = new Vector3(); let groupCount = 0; const radius = top === true ? radiusTop : radiusBottom; const sign = top === true ? 1 : -1; for (let x2 = 1; x2 <= radialSegments; x2++) { vertices.push(0, halfHeight * sign, 0); normals.push(0, sign, 0); uvs.push(0.5, 0.5); index5++; } const centerIndexEnd = index5; for (let x2 = 0; x2 <= radialSegments; x2++) { const u = x2 / radialSegments; const theta = u * thetaLength + thetaStart; const cosTheta = Math.cos(theta); const sinTheta = Math.sin(theta); vertex2.x = radius * sinTheta; vertex2.y = halfHeight * sign; vertex2.z = radius * cosTheta; vertices.push(vertex2.x, vertex2.y, vertex2.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); index5++; } for (let x2 = 0; x2 < radialSegments; x2++) { const c2 = centerIndexStart + x2; const i = centerIndexEnd + x2; 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; } } 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 = 8, 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 BufferGeometry { 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 index5 = 0; const grid = []; const vertex2 = new Vector3(); const normal = new Vector3(); 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; vertex2.x = -radius * Math.cos(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength); vertex2.y = radius * Math.cos(thetaStart + v * thetaLength); vertex2.z = radius * Math.sin(phiStart + u * phiLength) * Math.sin(thetaStart + v * thetaLength); vertices.push(vertex2.x, vertex2.y, vertex2.z); normal.copy(vertex2).normalize(); normals.push(normal.x, normal.y, normal.z); uvs.push(u + uOffset, 1 - v); verticesRow.push(index5++); } 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 Float32BufferAttribute(vertices, 3)); this.setAttribute("normal", new Float32BufferAttribute(normals, 3)); this.setAttribute("uv", new Float32BufferAttribute(uvs, 2)); } static fromJSON(data) { return new SphereGeometry(data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength); } }; var TubeGeometry = class extends BufferGeometry { constructor(path = new QuadraticBezierCurve3(new Vector3(-1, -1, 0), new Vector3(-1, 1, 0), new Vector3(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 vertex2 = new Vector3(); const normal = new Vector3(); const uv = new Vector2(); let P = new Vector3(); const vertices = []; const normals = []; const uvs = []; const indices = []; generateBufferData(); 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 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); vertex2.x = P.x + radius * normal.x; vertex2.y = P.y + radius * normal.y; vertex2.z = P.z + radius * normal.z; vertices.push(vertex2.x, vertex2.y, vertex2.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); } } } } 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 Material { constructor(parameters) { super(); this.isMeshLambertMaterial = true; this.type = "MeshLambertMaterial"; this.color = new Color(16777215); this.map = null; this.lightMap = null; this.lightMapIntensity = 1; this.aoMap = null; this.aoMapIntensity = 1; this.emissive = new Color(0); this.emissiveIntensity = 1; this.emissiveMap = null; 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.emissive.copy(source.emissive); this.emissiveMap = source.emissiveMap; this.emissiveIntensity = source.emissiveIntensity; 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; } }; function arraySlice(array, from, to) { if (isTypedArray(array)) { return new array.constructor(array.subarray(from, to !== void 0 ? to : array.length)); } return array.slice(from, to); } function convertArray(array, type, forceClone) { if (!array || !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_(index5) { const result = this.resultBuffer, values = this.sampleValues, stride = this.valueSize, offset = index5 * stride; for (let i = 0; i !== stride; ++i) { result[i] = values[offset + i]; } return result; } 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); } 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; } 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(timeScale) { if (timeScale !== 1) { const times = this.times; for (let i = 0, n = times.length; i !== n; ++i) { times[i] *= timeScale; } } return this; } 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 = arraySlice(times, from, to); this.values = arraySlice(this.values, from * stride, to * stride); } return this; } 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; } optimize() { const times = arraySlice(this.times), values = arraySlice(this.values), 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 = arraySlice(times, 0, writeIndex); this.values = arraySlice(values, 0, writeIndex * stride); } else { this.times = times; this.values = values; } return this; } clone() { const times = arraySlice(this.times, 0); const values = arraySlice(this.values, 0); 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 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 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 index5 = handlers.indexOf(regex); if (index5 !== -1) { handlers.splice(index5, 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; } }; var ImageLoader = class extends Loader { 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 = createElementNS("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 Loader { constructor(manager) { super(manager); } load(url, onLoad, onProgress, onError) { const texture = new Texture(); 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 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(shadowCamera.projectionMatrix); shadowMatrix.multiply(shadowCamera.matrixWorldInverse); } 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.DefaultUp); 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 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_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"]; 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) || rootNode; this.rootNode = rootNode; this.getValue = this._getValue_unbound; this.setValue = this._setValue_unbound; } static create(root, path, parsedPath) { if (!(root && root.isAnimationObjectGroup)) { return new PropertyBinding(root, path, parsedPath); } else { return new PropertyBinding.Composite(root, path, parsedPath); } } 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 = { nodeName: matches[2], objectName: matches[3], objectIndex: matches[4], propertyName: matches[5], 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(root, nodeName) { if (nodeName === void 0 || nodeName === "" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid) { return root; } if (root.skeleton) { const bone = root.skeleton.getBoneByName(nodeName); if (bone !== void 0) { return bone; } } if (root.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(root.children); if (subTreeNode) { return subTreeNode; } } return null; } _getValue_unavailable() { } _setValue_unavailable() { } _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); } _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; } _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; } _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; } _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); } 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.rootNode; this.node = targetObject; } this.getValue = this._getValue_unavailable; this.setValue = this._setValue_unavailable; if (!targetObject) { console.error("THREE.PropertyBinding: Trying to update node for track: " + this.path + " but it wasn't found."); 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; 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 = [ [ PropertyBinding.prototype._setValue_direct, PropertyBinding.prototype._setValue_direct_setNeedsUpdate, PropertyBinding.prototype._setValue_direct_setMatrixWorldNeedsUpdate ], [ PropertyBinding.prototype._setValue_array, PropertyBinding.prototype._setValue_array_setNeedsUpdate, PropertyBinding.prototype._setValue_array_setMatrixWorldNeedsUpdate ], [ PropertyBinding.prototype._setValue_arrayElement, PropertyBinding.prototype._setValue_arrayElement_setNeedsUpdate, PropertyBinding.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate ], [ PropertyBinding.prototype._setValue_fromArray, PropertyBinding.prototype._setValue_fromArray_setNeedsUpdate, PropertyBinding.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate ] ]; var _controlInterpolantsResultBuffer = new Float32Array(1); var Raycaster = class { constructor(origin, direction, near = 0, far = Infinity) { this.ray = new Ray(origin, 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(origin, direction) { this.ray.set(origin, 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); } } } 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; } 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(x2, y2, z2) { this.radius = Math.sqrt(x2 * x2 + y2 * y2 + z2 * z2); if (this.radius === 0) { this.theta = 0; this.phi = 0; } else { this.theta = Math.atan2(x2, z2); this.phi = Math.acos(clamp(y2 / this.radius, -1, 1)); } return this; } clone() { return new this.constructor().copy(this); } }; 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/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, _camera3, _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, _camera3); 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, _camera3); _raycaster.intersectObjects(_objects, true, _intersections); if (_intersections.length > 0) { const object = _intersections[0].object; _plane.setFromNormalAndCoplanarPoint(_camera3.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, _camera3); _raycaster.intersectObjects(_objects, true, _intersections); if (_intersections.length > 0) { _selected = scope.transformGroup === true ? _objects[0] : _intersections[0].object; _plane.setFromNormalAndCoplanarPoint(_camera3.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.transformGroup = false; this.activate = activate; this.deactivate = deactivate; this.dispose = dispose; this.getObjects = getObjects; this.getRaycaster = getRaycaster; } }; // node_modules/d3-force-3d/src/center.js function center_default(x2, y2, z2) { var nodes, strength = 1; if (x2 == null) x2 = 0; if (y2 == null) y2 = 0; if (z2 == null) z2 = 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 - x2) * strength, sy = (sy / n - y2) * strength, sz = (sz / n - z2) * 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 ? (x2 = +_, force) : x2; }; force.y = function(_) { return arguments.length ? (y2 = +_, force) : y2; }; force.z = function(_) { return arguments.length ? (z2 = +_, force) : z2; }; force.strength = function(_) { return arguments.length ? (strength = +_, force) : strength; }; return force; } // node_modules/d3-binarytree/src/add.js function add_default(d) { var x2 = +this._x.call(null, d); return add(this.cover(x2), x2, d); } function add(tree, x2, d) { if (isNaN(x2)) 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 = x2 >= (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 (x2 === 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 = x2 >= (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) { var i, n = data.length, x2, xz = new Array(n), x0 = Infinity, x1 = -Infinity; for (i = 0; i < n; ++i) { if (isNaN(x2 = +this._x.call(null, data[i]))) continue; xz[i] = x2; if (x2 < x0) x0 = x2; if (x2 > x1) x1 = x2; } if (x0 > x1) return this; this.cover(x0).cover(x1); for (i = 0; i < n; ++i) { add(this, xz[i], data[i]); } return this; } // node_modules/d3-binarytree/src/cover.js function cover_default(x2) { if (isNaN(x2 = +x2)) return this; var x0 = this._x0, x1 = this._x1; if (isNaN(x0)) { x1 = (x0 = Math.floor(x2)) + 1; } else { var z2 = x1 - x0 || 1, node = this._root, parent, i; while (x0 > x2 || x2 >= x1) { i = +(x2 < x0); parent = new Array(2), parent[i] = node, node = parent, z2 *= 2; switch (i) { case 0: x1 = x0 + z2; break; case 1: x0 = x1 - z2; 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(x2, radius) { var data, x0 = this._x0, x1, x22, x3 = this._x1, halves = [], node = this._root, q, i; if (node) halves.push(new half_default(node, x0, x3)); if (radius == null) radius = Infinity; else { x0 = x2 - radius; x3 = x2 + radius; } while (q = halves.pop()) { if (!(node = q.node) || (x1 = q.x0) > x3 || (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 = +(x2 >= 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(x2 - +this._x.call(null, node.data)); if (d < radius) { radius = d; x0 = x2 - d; x3 = x2 + d; data = node.data; } } } return data; } // node_modules/d3-binarytree/src/remove.js function remove_default(d) { if (isNaN(x2 = +this._x.call(null, d))) return this; var parent, node = this._root, retainer, previous, next, x0 = this._x0, x1 = this._x1, x2, xm, right, i, j; if (!node) return this; if (node.length) while (true) { if (right = x2 >= (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, x2) { var tree = new Binarytree(x2 == null ? defaultX : x2, NaN, NaN); return nodes == null ? tree : tree.addAll(nodes); } function Binarytree(x2, x0, x1) { this._x = x2; this._x0 = x0; this._x1 = x1; this._root = void 0; } function leaf_copy(leaf) { var copy = { data: leaf.data }, next = copy; while (leaf = leaf.next) next = next.next = { data: leaf.data }; return copy; } var treeProto = binarytree.prototype = Binarytree.prototype; treeProto.copy = function() { var copy = new Binarytree(this._x, this._x0, this._x1), node = this._root, nodes, child; if (!node) return copy; if (!node.length) return copy._root = leaf_copy(node), copy; nodes = [{ source: node, target: copy._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 copy; }; 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 x2 = +this._x.call(null, d), y2 = +this._y.call(null, d); return add2(this.cover(x2, y2), x2, y2, d); } function add2(tree, x2, y2, d) { if (isNaN(x2) || isNaN(y2)) 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 = x2 >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm; if (bottom = y2 >= (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 (x2 === xp && y2 === 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 = x2 >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm; if (bottom = y2 >= (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, x2, y2, xz = new Array(n), yz = new Array(n), x0 = Infinity, y0 = Infinity, x1 = -Infinity, y1 = -Infinity; for (i = 0; i < n; ++i) { if (isNaN(x2 = +this._x.call(null, d = data[i])) || isNaN(y2 = +this._y.call(null, d))) continue; xz[i] = x2; yz[i] = y2; if (x2 < x0) x0 = x2; if (x2 > x1) x1 = x2; if (y2 < y0) y0 = y2; if (y2 > y1) y1 = y2; } 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(x2, y2) { if (isNaN(x2 = +x2) || isNaN(y2 = +y2)) return this; var x0 = this._x0, y0 = this._y0, x1 = this._x1, y1 = this._y1; if (isNaN(x0)) { x1 = (x0 = Math.floor(x2)) + 1; y1 = (y0 = Math.floor(y2)) + 1; } else { var z2 = x1 - x0 || 1, node = this._root, parent, i; while (x0 > x2 || x2 >= x1 || y0 > y2 || y2 >= y1) { i = (y2 < y0) << 1 | x2 < x0; parent = new Array(4), parent[i] = node, node = parent, z2 *= 2; switch (i) { case 0: x1 = x0 + z2, y1 = y0 + z2; break; case 1: x0 = x1 - z2, y1 = y0 + z2; break; case 2: x1 = x0 + z2, y0 = y1 - z2; break; case 3: x0 = x1 - z2, y0 = y1 - z2; 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(x2, y2, radius) { var data, x0 = this._x0, y0 = this._y0, x1, y1, x22, y22, x3 = this._x1, y3 = this._y1, quads = [], node = this._root, q, i; if (node) quads.push(new quad_default(node, x0, y0, x3, y3)); if (radius == null) radius = Infinity; else { x0 = x2 - radius, y0 = y2 - radius; x3 = x2 + radius, y3 = y2 + radius; radius *= radius; } while (q = quads.pop()) { if (!(node = q.node) || (x1 = q.x0) > x3 || (y1 = q.y0) > y3 || (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 = (y2 >= ym) << 1 | x2 >= xm) { q = quads[quads.length - 1]; quads[quads.length - 1] = quads[quads.length - 1 - i]; quads[quads.length - 1 - i] = q; } } else { var dx = x2 - +this._x.call(null, node.data), dy = y2 - +this._y.call(null, node.data), d2 = dx * dx + dy * dy; if (d2 < radius) { var d = Math.sqrt(radius = d2); x0 = x2 - d, y0 = y2 - d; x3 = x2 + d, y3 = y2 + d; data = node.data; } } } return data; } // node_modules/d3-quadtree/src/remove.js function remove_default2(d) { if (isNaN(x2 = +this._x.call(null, d)) || isNaN(y2 = +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, x2, y2, xm, ym, right, bottom, i, j; if (!node) return this; if (node.length) while (true) { if (right = x2 >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm; if (bottom = y2 >= (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, x2, y2) { var tree = new Quadtree(x2 == null ? defaultX2 : x2, y2 == null ? defaultY : y2, NaN, NaN, NaN, NaN); return nodes == null ? tree : tree.addAll(nodes); } function Quadtree(x2, y2, x0, y0, x1, y1) { this._x = x2; this._y = y2; this._x0 = x0; this._y0 = y0; this._x1 = x1; this._y1 = y1; this._root = void 0; } function leaf_copy2(leaf) { var copy = { data: leaf.data }, next = copy; while (leaf = leaf.next) next = next.next = { data: leaf.data }; return copy; } var treeProto2 = quadtree.prototype = Quadtree.prototype; treeProto2.copy = function() { var copy = new Quadtree(this._x, this._y, this._x0, this._y0, this._x1, this._y1), node = this._root, nodes, child; if (!node) return copy; if (!node.length) return copy._root = leaf_copy2(node), copy; nodes = [{ source: node, target: copy._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 copy; }; 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) { var x2 = +this._x.call(null, d), y2 = +this._y.call(null, d), z2 = +this._z.call(null, d); return add3(this.cover(x2, y2, z2), x2, y2, z2, d); } function add3(tree, x2, y2, z2, d) { if (isNaN(x2) || isNaN(y2) || isNaN(z2)) 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 = x2 >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm; if (bottom = y2 >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym; if (deep = z2 >= (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 (x2 === xp && y2 === yp && z2 === 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 = x2 >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm; if (bottom = y2 >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym; if (deep = z2 >= (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) { var d, i, n = data.length, x2, y2, z2, xz = new Array(n), yz = new Array(n), zz = new Array(n), x0 = Infinity, y0 = Infinity, z0 = Infinity, x1 = -Infinity, y1 = -Infinity, z1 = -Infinity; for (i = 0; i < n; ++i) { if (isNaN(x2 = +this._x.call(null, d = data[i])) || isNaN(y2 = +this._y.call(null, d)) || isNaN(z2 = +this._z.call(null, d))) continue; xz[i] = x2; yz[i] = y2; zz[i] = z2; if (x2 < x0) x0 = x2; if (x2 > x1) x1 = x2; if (y2 < y0) y0 = y2; if (y2 > y1) y1 = y2; if (z2 < z0) z0 = z2; if (z2 > z1) z1 = z2; } if (x0 > x1 || y0 > y1 || z0 > z1) return this; this.cover(x0, y0, z0).cover(x1, y1, z1); for (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(x2, y2, z2) { if (isNaN(x2 = +x2) || isNaN(y2 = +y2) || isNaN(z2 = +z2)) 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(x2)) + 1; y1 = (y0 = Math.floor(y2)) + 1; z1 = (z0 = Math.floor(z2)) + 1; } else { var t = x1 - x0 || 1, node = this._root, parent, i; while (x0 > x2 || x2 >= x1 || y0 > y2 || y2 >= y1 || z0 > z2 || z2 >= z1) { i = (z2 < z0) << 2 | (y2 < y0) << 1 | x2 < 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(x2, y2, z2, radius) { var data, x0 = this._x0, y0 = this._y0, z0 = this._z0, x1, y1, z1, x22, y22, z22, x3 = this._x1, y3 = this._y1, z3 = this._z1, octs = [], node = this._root, q, i; if (node) octs.push(new octant_default(node, x0, y0, z0, x3, y3, z3)); if (radius == null) radius = Infinity; else { x0 = x2 - radius, y0 = y2 - radius, z0 = z2 - radius; x3 = x2 + radius, y3 = y2 + radius, z3 = z2 + radius; radius *= radius; } while (q = octs.pop()) { if (!(node = q.node) || (x1 = q.x0) > x3 || (y1 = q.y0) > y3 || (z1 = q.z0) > z3 || (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 = (z2 >= zm) << 2 | (y2 >= ym) << 1 | x2 >= xm) { q = octs[octs.length - 1]; octs[octs.length - 1] = octs[octs.length - 1 - i]; octs[octs.length - 1 - i] = q; } } else { var dx = x2 - +this._x.call(null, node.data), dy = y2 - +this._y.call(null, node.data), dz = z2 - +this._z.call(null, node.data), d2 = dx * dx + dy * dy + dz * dz; if (d2 < radius) { var d = Math.sqrt(radius = d2); x0 = x2 - d, y0 = y2 - d, z0 = z2 - d; x3 = x2 + d, y3 = y2 + d, z3 = z2 + d; data = node.data; } } } return data; } // node_modules/d3-octree/src/remove.js function remove_default3(d) { if (isNaN(x2 = +this._x.call(null, d)) || isNaN(y2 = +this._y.call(null, d)) || isNaN(z2 = +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, x2, y2, z2, xm, ym, zm, right, bottom, deep, i, j; if (!node) return this; if (node.length) while (true) { if (right = x2 >= (xm = (x0 + x1) / 2)) x0 = xm; else x1 = xm; if (bottom = y2 >= (ym = (y0 + y1) / 2)) y0 = ym; else y1 = ym; if (deep = z2 >= (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, x2, y2, z2) { var tree = new Octree(x2 == null ? defaultX3 : x2, y2 == null ? defaultY2 : y2, z2 == null ? defaultZ : z2, NaN, NaN, NaN, NaN, NaN, NaN); return nodes == null ? tree : tree.addAll(nodes); } function Octree(x2, y2, z2, x0, y0, z0, x1, y1, z1) { this._x = x2; this._y = y2; this._z = z2; 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 copy = { data: leaf.data }, next = copy; while (leaf = leaf.next) next = next.next = { data: leaf.data }; return copy; } var treeProto3 = octree.prototype = Octree.prototype; treeProto3.copy = function() { var copy = 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 copy; if (!node.length) return copy._root = leaf_copy3(node), copy; nodes = [{ source: node, target: copy._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 copy; }; 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(x2) { return function() { return x2; }; } // node_modules/d3-force-3d/src/jiggle.js function jiggle_default(random) { return (random() - 0.5) * 1e-6; } // 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, x2 = 0, y2 = 0, z2 = 0, l, b; i < n; ++i) { link = links[i], source = link.source, target = link.target; x2 = target.x + target.vx - source.x - source.vx || jiggle_default(random); if (nDim > 1) { y2 = target.y + target.vy - source.y - source.vy || jiggle_default(random); } if (nDim > 2) { z2 = target.z + target.vz - source.z - source.vz || jiggle_default(random); } l = Math.sqrt(x2 * x2 + y2 * y2 + z2 * z2); l = (l - distances[i]) / l * alpha * strengths[i]; x2 *= l, y2 *= l, z2 *= l; target.vx -= x2 * (b = bias[i]); if (nDim > 1) { target.vy -= y2 * b; } if (nDim > 2) { target.vz -= z2 * b; } source.vx += x2 * (b = 1 - b); if (nDim > 1) { source.vy += y2 * b; } if (nDim > 2) { source.vz += z2 * 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 copy = {}, _ = this._; for (var t in _) copy[t] = _[t].slice(); return new Dispatch(copy); }, 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 now4 = clock.now(), delay = now4 - clockLast; if (delay > pokeDelay) clockSkew -= delay, clockLast = now4; } 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 x(d) { return d.x; } function y(d) { return d.y; } function z(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 x2 = args.shift() || 0, y2 = (nDim > 1 ? args.shift() : null) || 0, z2 = (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 = x2 - node.x; dy = y2 - (node.y || 0); dz = z2 - (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, x) : nDim === 2 ? quadtree(nodes, x, y) : nDim === 3 ? octree(nodes, x, y, z) : 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, x2, y2, z2, i; var numChildren = treeNode.length; if (numChildren) { for (x2 = y2 = z2 = i = 0; i < numChildren; ++i) { if ((q = treeNode[i]) && (c2 = Math.abs(q.value))) { strength2 += q.value, weight += c2, x2 += c2 * (q.x || 0), y2 += c2 * (q.y || 0), z2 += c2 * (q.z || 0); } } strength2 *= Math.sqrt(4 / numChildren); treeNode.x = x2 / weight; if (nDim > 1) { treeNode.y = y2 / weight; } if (nDim > 2) { treeNode.z = z2 / 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 x2 = [arg1, arg2, arg3][nDim - 1]; var x3 = treeNode.x - node.x, y2 = nDim > 1 ? treeNode.y - node.y : 0, z2 = nDim > 2 ? treeNode.z - node.z : 0, w = x2 - x1, l = x3 * x3 + y2 * y2 + z2 * z2; if (w * w / theta2 < l) { if (l < distanceMax2) { if (x3 === 0) x3 = jiggle_default(random), l += x3 * x3; if (nDim > 1 && y2 === 0) y2 = jiggle_default(random), l += y2 * y2; if (nDim > 2 && z2 === 0) z2 = jiggle_default(random), l += z2 * z2; if (l < distanceMin2) l = Math.sqrt(distanceMin2 * l); node.vx += x3 * treeNode.value * alpha / l; if (nDim > 1) { node.vy += y2 * treeNode.value * alpha / l; } if (nDim > 2) { node.vz += z2 * 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 && y2 === 0) y2 = jiggle_default(random), l += y2 * y2; if (nDim > 2 && z2 === 0) z2 = jiggle_default(random), l += z2 * z2; 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 += y2 * w; } if (nDim > 2) { node.vz += z2 * 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, x2, y2, z2) { var nodes, nDim, strength = constant_default(0.1), strengths, radiuses; if (typeof radius !== "function") radius = constant_default(+radius); if (x2 == null) x2 = 0; if (y2 == null) y2 = 0; if (z2 == null) z2 = 0; function force(alpha) { for (var i = 0, n = nodes.length; i < n; ++i) { var node = nodes[i], dx = node.x - x2 || 1e-6, dy = (node.y || 0) - y2 || 1e-6, dz = (node.z || 0) - z2 || 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 ? (x2 = +_, force) : x2; }; force.y = function(_) { return arguments.length ? (y2 = +_, force) : y2; }; force.z = function(_) { return arguments.length ? (z2 = +_, force) : z2; }; return force; } // node_modules/three-forcegraph/dist/three-forcegraph.module.js var import_ngraph = __toESM(require_ngraph2()); var import_ngraph2 = __toESM(require_ngraph5()); // node_modules/kapsule/dist/kapsule.module.js var import_debounce = __toESM(require_debounce()); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } 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."); } 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, { 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 = (0, import_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.module.js var index3 = function(p) { return p instanceof Function ? p : typeof p === "string" ? function(obj) { return obj[p]; } : function(obj) { return p; }; }; var accessor_fn_module_default = index3; // 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 index5 = -1; for (let value of values) { if ((value = valueof(value, ++index5, 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 index5 = -1; for (let value of values) { if ((value = valueof(value, ++index5, values)) != null && (min2 > value || min2 === void 0 && value >= value)) { min2 = value; } } } return min2; } // node_modules/index-array-by/dist/index-array-by.module.js 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 _iterableToArrayLimit2(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } 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 _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 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(_toPropertyKey)); 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 flatten2(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 flatten2(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.module.js 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 = arguments[i] != null ? 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) { 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 _iterableToArrayLimit3(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } 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."); } 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 index5 = new InternMap(), domain = [], range = [], unknown = implicit; function scale(d) { let i = index5.get(d); if (i === void 0) { if (unknown !== implicit) return unknown; index5.set(d, i = domain.push(d) - 1); } return range[i % range.length]; } scale.domain = function(_) { if (!arguments.length) return domain.slice(); domain = [], index5 = new InternMap(); for (const value of _) { if (index5.has(value)) continue; index5.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/three-forcegraph/dist/three-forcegraph.module.js var import_tinycolor2 = __toESM(require_tinycolor()); 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 = arguments[i] != null ? 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 _typeof(obj) { "@babel/helpers - typeof"; return _typeof = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(obj2) { return typeof obj2; } : function(obj2) { return obj2 && typeof Symbol == "function" && obj2.constructor === Symbol && obj2 !== Symbol.prototype ? "symbol" : typeof obj2; }, _typeof(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, 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) { 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 _iterableToArrayLimit4(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } 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."); } 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] : {}; var _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((0, import_tinycolor2.default)(str).toHex(), 16) : str; }; var colorAlpha = function colorAlpha2(str) { return isNaN(str) ? (0, import_tinycolor2.default)(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 _typeof(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; for (var i = 0, l = nodes2.length; i < l; i++) { var node = nodes2[i]; if (nodeStack.indexOf(node) !== -1) { var _ret = function() { 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 (_ret === "continue") continue; } if (currentDepth > node.depth) { node.depth = currentDepth; traverse(node.out, [].concat(_toConsumableArray3(nodeStack), [node]), currentDepth + (node.skip ? 0 : 1)); } } } } var three$1 = window.THREE ? window.THREE : { Group, Mesh, MeshLambertMaterial, Color, BufferGeometry, BufferAttribute, Matrix4, Vector3, SphereBufferGeometry: SphereGeometry, CylinderBufferGeometry: CylinderGeometry, TubeBufferGeometry: TubeGeometry, ConeBufferGeometry: ConeGeometry, Line, LineBasicMaterial, QuadraticBezierCurve3, CubicBezierCurve3, Box3 }; 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 }, nodeId: { "default": "id" }, nodeVal: { "default": "val" }, nodeResolution: { "default": 8 }, nodeColor: { "default": "color" }, nodeAutoColorBy: {}, nodeOpacity: { "default": 0.75 }, nodeVisibility: { "default": true }, nodeThreeObject: {}, nodeThreeObjectExtend: { "default": false }, linkSource: { "default": "source" }, linkTarget: { "default": "target" }, linkVisibility: { "default": true }, linkColor: { "default": "color" }, linkAutoColorBy: {}, linkOpacity: { "default": 0.2 }, linkWidth: {}, linkResolution: { "default": 6 }, linkCurvature: { "default": 0, triggerUpdate: false }, linkCurveRotation: { "default": 0, triggerUpdate: false }, linkMaterial: {}, linkThreeObject: {}, linkThreeObjectExtend: { "default": false }, linkPositionUpdate: { triggerUpdate: false }, linkDirectionalArrowLength: { "default": 0 }, linkDirectionalArrowColor: {}, linkDirectionalArrowRelPos: { "default": 0.5, triggerUpdate: false }, linkDirectionalArrowResolution: { "default": 8 }, linkDirectionalParticles: { "default": 0 }, linkDirectionalParticleSpeed: { "default": 0.01, triggerUpdate: false }, linkDirectionalParticleWidth: { "default": 0.5 }, linkDirectionalParticleColor: {}, linkDirectionalParticleResolution: { "default": 4 }, forceEngine: { "default": "d3" }, 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": { timeStep: 20, gravity: -1.2, theta: 0.8, springLength: 30, springCoefficient: 8e-4, dragCoefficient: 0.02 } }, warmupTicks: { "default": 0, triggerUpdate: false }, cooldownTicks: { "default": Infinity, triggerUpdate: false }, cooldownTime: { "default": 15e3, triggerUpdate: false }, 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; }, 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; }, 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(); } state.graphData.nodes.forEach(function(node) { var obj = node.__threeObj; if (!obj) return; var pos = isD3Sim ? node : state.layout.getNodePosition(node[state.nodeId]); obj.position.x = pos.x; obj.position.y = pos.y || 0; obj.position.z = pos.z || 0; }); var linkWidthAccessor = accessor_fn_module_default(state.linkWidth); var linkCurvatureAccessor = accessor_fn_module_default(state.linkCurvature); var linkCurveRotationAccessor = accessor_fn_module_default(state.linkCurveRotation); var linkThreeObjectExtendAccessor = accessor_fn_module_default(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, { 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.CylinderBufferGeometry(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 _geometry3 = new three$1.TubeBufferGeometry(curve, curveResolution, _r, state.linkResolution, false); line.geometry.dispose(); line.geometry = _geometry3; } } }); 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 = accessor_fn_module_default(state.linkDirectionalArrowRelPos); var arrowLengthAccessor = accessor_fn_module_default(state.linkDirectionalArrowLength); var nodeValAccessor = accessor_fn_module_default(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.sqrt(Math.max(0, nodeValAccessor(start) || 1)) * state.nodeRelSize; var endR = Math.sqrt(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 = accessor_fn_module_default(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) { if (!link.__singleHopPhotonsObj) { var obj = new three$1.Group(); obj.__linkThreeObjType = "singleHopPhotons"; link.__singleHopPhotonsObj = obj; state.graphScene.add(obj); } var particleWidthAccessor = accessor_fn_module_default(state.linkDirectionalParticleWidth); var photonR = Math.ceil(particleWidthAccessor(link) * 10) / 10 / 2; var numSegments = state.linkDirectionalParticleResolution; var particleGeometry = new three$1.SphereBufferGeometry(photonR, numSegments, numSegments); var linkColorAccessor = accessor_fn_module_default(state.linkColor); var particleColorAccessor = accessor_fn_module_default(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); }).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, accessor_fn_module_default(state.nodeAutoColorBy), state.nodeColor); } if (state.linkAutoColorBy !== null && hasAnyPropChanged(["linkAutoColorBy", "graphData", "linkColor"])) { autoColorObjects(state.graphData.links, accessor_fn_module_default(state.linkAutoColorBy), state.linkColor); } if (state._flushObjects || hasAnyPropChanged(["graphData", "nodeThreeObject", "nodeThreeObjectExtend", "nodeVal", "nodeColor", "nodeVisibility", "nodeRelSize", "nodeResolution", "nodeOpacity"])) { var customObjectAccessor = accessor_fn_module_default(state.nodeThreeObject); var customObjectExtendAccessor = accessor_fn_module_default(state.nodeThreeObjectExtend); var valAccessor = accessor_fn_module_default(state.nodeVal); var colorAccessor = accessor_fn_module_default(state.nodeColor); var visibilityAccessor = accessor_fn_module_default(state.nodeVisibility); var sphereGeometries = {}; var sphereMaterials = {}; threeDigest(state.graphData.nodes.filter(visibilityAccessor), state.graphScene, { purge: state._flushObjects || hasAnyPropChanged([ "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.SphereBufferGeometry(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 = accessor_fn_module_default(state.linkThreeObject); var _customObjectExtendAccessor = accessor_fn_module_default(state.linkThreeObjectExtend); var customMaterialAccessor = accessor_fn_module_default(state.linkMaterial); var _visibilityAccessor = accessor_fn_module_default(state.linkVisibility); var _colorAccessor = accessor_fn_module_default(state.linkColor); var widthAccessor = accessor_fn_module_default(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([ "linkThreeObject", "linkThreeObjectExtend", "linkWidth" ]), objFilter: function objFilter(obj) { return obj.__graphObjType === "link"; }, 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.CylinderBufferGeometry(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 }); } obj.material.dispose(); obj.material = lineMaterials[color]; } } } } }); if (state.linkDirectionalArrowLength || changedProps.hasOwnProperty("linkDirectionalArrowLength")) { var arrowLengthAccessor = accessor_fn_module_default(state.linkDirectionalArrowLength); var arrowColorAccessor = accessor_fn_module_default(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.ConeBufferGeometry(arrowLength * 0.25, arrowLength, numSegments); coneGeometry.translate(0, arrowLength / 2, 0); coneGeometry.rotateX(Math.PI / 2); obj.geometry.dispose(); obj.geometry = coneGeometry; } obj.material.color = new three$1.Color(arrowColorAccessor(link) || _colorAccessor(link) || "#f0f0f0"); obj.material.opacity = state.linkOpacity * 3; } }); } if (state.linkDirectionalParticles || changedProps.hasOwnProperty("linkDirectionalParticles")) { var particlesAccessor = accessor_fn_module_default(state.linkDirectionalParticles); var particleWidthAccessor = accessor_fn_module_default(state.linkDirectionalParticleWidth); var particleColorAccessor = accessor_fn_module_default(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.SphereBufferGeometry(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 }; 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 EventDispatcher { constructor(object, domElement) { super(); if (domElement === void 0) console.warn('THREE.TrackballControls: The second parameter "domElement" is now mandatory.'); if (domElement === document) console.error('THREE.TrackballControls: "document" should not be used as the target "domElement". Please use "renderer.domElement" instead.'); 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.keys = ["KeyA", "KeyS", "KeyD"]; this.mouseButtons = { LEFT: MOUSE.ROTATE, MIDDLE: MOUSE.DOLLY, RIGHT: MOUSE.PAN }; this.target = new Vector3(); const EPS = 1e-6; const lastPosition = new Vector3(); let lastZoom = 1; let _state = STATE.NONE, _keyState = STATE.NONE, _touchZoomDistanceStart = 0, _touchZoomDistanceEnd = 0, _lastAngle = 0; const _eye = new Vector3(), _movePrev = new Vector2(), _moveCurr = new Vector2(), _lastAxis = new Vector3(), _zoomStart = new Vector2(), _zoomEnd = new Vector2(), _panStart = new Vector2(), _panEnd = new Vector2(), _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 Vector2(); 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 Vector2(); 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); return vector; }; }(); this.rotateCamera = function() { const axis = new Vector3(), quaternion = new Quaternion(), eyeDirection = new Vector3(), objectUpDirection = new Vector3(), objectSidewaysDirection = new Vector3(), moveDirection = new Vector3(); 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 /= factor; 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 /= factor; 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 Vector2(), objectUp = new Vector3(), pan = new Vector3(); 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 x2 = (_pointers[0].pageX + _pointers[1].pageX) / 2; const y2 = (_pointers[0].pageY + _pointers[1].pageY) / 2; _panStart.copy(getMouseOnScreen(x2, y2)); _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 x2 = (event.pageX + position.x) / 2; const y2 = (event.pageY + position.y) / 2; _panEnd.copy(getMouseOnScreen(x2, y2)); 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; _moveCurr.copy(getMouseOnCircle(event.pageX - _movePrev.x, event.pageY - _movePrev.y)); _movePrev.copy(_moveCurr); break; } scope.dispatchEvent(_endEvent); } function contextmenu2(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 Vector2(); _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", contextmenu2); 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", contextmenu2); 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 OrbitControls = class extends EventDispatcher { constructor(object, domElement) { super(); if (domElement === void 0) console.warn('THREE.OrbitControls: The second parameter "domElement" is now mandatory.'); if (domElement === document) console.error('THREE.OrbitControls: "document" should not be used as the target "domElement". Please use "renderer.domElement" instead.'); this.object = object; this.domElement = domElement; this.domElement.style.touchAction = "none"; this.enabled = true; this.target = new Vector3(); 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.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.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 Vector3(); const quat = new Quaternion().setFromUnitVectors(object.up, new Vector3(0, 1, 0)); const quatInverse = quat.clone().invert(); const lastPosition = new Vector3(); const lastQuaternion = new Quaternion(); const twoPI = 2 * Math.PI; return function update4() { 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()); } 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(); spherical.radius *= scale; spherical.radius = Math.max(scope.minDistance, Math.min(scope.maxDistance, spherical.radius)); if (scope.enableDamping === true) { scope.target.addScaledVector(panOffset, scope.dampingFactor); } else { scope.target.add(panOffset); } 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); } scale = 1; if (zoomChanged || lastPosition.distanceToSquared(scope.object.position) > EPS || 8 * (1 - lastQuaternion.dot(scope.object.quaternion)) > EPS) { scope.dispatchEvent(_changeEvent2); lastPosition.copy(scope.object.position); lastQuaternion.copy(scope.object.quaternion); zoomChanged = false; return true; } return false; }; }(); this.dispose = function() { scope.domElement.removeEventListener("contextmenu", onContextMenu); 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); if (scope._domElementKeyEvents !== null) { scope._domElementKeyEvents.removeEventListener("keydown", onKeyDown); } }; 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 Vector3(); let zoomChanged = false; const rotateStart = new Vector2(); const rotateEnd = new Vector2(); const rotateDelta = new Vector2(); const panStart = new Vector2(); const panEnd = new Vector2(); const panDelta = new Vector2(); const dollyStart = new Vector2(); const dollyEnd = new Vector2(); const dollyDelta = new Vector2(); const pointers = []; const pointerPositions = {}; function getAutoRotationAngle() { 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 Vector3(); return function panLeft2(distance, objectMatrix) { v.setFromMatrixColumn(objectMatrix, 0); v.multiplyScalar(-distance); panOffset.add(v); }; }(); const panUp = function() { const v = new Vector3(); 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 Vector3(); 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) { scale /= dollyScale; } else if (scope.object.isOrthographicCamera) { scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom * dollyScale)); scope.object.updateProjectionMatrix(); zoomChanged = true; } else { console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."); scope.enableZoom = false; } } function dollyIn(dollyScale) { if (scope.object.isPerspectiveCamera) { scale *= dollyScale; } else if (scope.object.isOrthographicCamera) { scope.object.zoom = Math.max(scope.minZoom, Math.min(scope.maxZoom, scope.object.zoom / dollyScale)); scope.object.updateProjectionMatrix(); zoomChanged = true; } else { console.warn("WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled."); scope.enableZoom = false; } } function handleMouseDownRotate(event) { rotateStart.set(event.clientX, event.clientY); } function handleMouseDownDolly(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) { 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: pan(0, scope.keyPanSpeed); needsUpdate = true; break; case scope.keys.BOTTOM: pan(0, -scope.keyPanSpeed); needsUpdate = true; break; case scope.keys.LEFT: pan(scope.keyPanSpeed, 0); needsUpdate = true; break; case scope.keys.RIGHT: 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 x2 = 0.5 * (pointers[0].pageX + pointers[1].pageX); const y2 = 0.5 * (pointers[0].pageY + pointers[1].pageY); rotateStart.set(x2, y2); } } function handleTouchStartPan() { if (pointers.length === 1) { panStart.set(pointers[0].pageX, pointers[0].pageY); } else { const x2 = 0.5 * (pointers[0].pageX + pointers[1].pageX); const y2 = 0.5 * (pointers[0].pageY + pointers[1].pageY); panStart.set(x2, y2); } } 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 x2 = 0.5 * (event.pageX + position.x); const y2 = 0.5 * (event.pageY + position.y); rotateEnd.set(x2, y2); } 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 x2 = 0.5 * (event.pageX + position.x); const y2 = 0.5 * (event.pageY + position.y); panEnd.set(x2, y2); } 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 onPointerCancel(event) { removePointer(event); } 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 Vector2(); 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", onPointerCancel); 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 EventDispatcher { constructor(object, domElement) { super(); if (domElement === void 0) { console.warn('THREE.FlyControls: The second parameter "domElement" is now mandatory.'); domElement = document; } this.object = object; this.domElement = domElement; this.movementSpeed = 1; this.rollSpeed = 5e-3; this.dragToLook = false; this.autoForward = false; const scope = this; const EPS = 1e-6; const lastQuaternion = new Quaternion(); const lastPosition = new Vector3(); this.tmpQuaternion = new Quaternion(); this.mouseStatus = 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 Vector3(0, 0, 0); this.rotationVector = new Vector3(0, 0, 0); this.keydown = function(event) { if (event.altKey) { 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) { 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.mousedown = function(event) { if (this.dragToLook) { this.mouseStatus++; } else { switch (event.button) { case 0: this.moveState.forward = 1; break; case 2: this.moveState.back = 1; break; } this.updateMovementVector(); } }; this.mousemove = function(event) { if (!this.dragToLook || this.mouseStatus > 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.mouseup = function(event) { if (this.dragToLook) { this.mouseStatus--; 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.update = function(delta) { 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("mousedown", _mousedown); this.domElement.removeEventListener("mousemove", _mousemove); this.domElement.removeEventListener("mouseup", _mouseup); window.removeEventListener("keydown", _keydown); window.removeEventListener("keyup", _keyup); }; const _mousemove = this.mousemove.bind(this); const _mousedown = this.mousedown.bind(this); const _mouseup = this.mouseup.bind(this); const _keydown = this.keydown.bind(this); const _keyup = this.keyup.bind(this); this.domElement.addEventListener("contextmenu", contextmenu); this.domElement.addEventListener("mousemove", _mousemove); this.domElement.addEventListener("mousedown", _mousedown); this.domElement.addEventListener("mouseup", _mouseup); window.addEventListener("keydown", _keydown); window.addEventListener("keyup", _keyup); this.updateMovementVector(); this.updateRotationVector(); } }; function contextmenu(event) { event.preventDefault(); } // node_modules/three/examples/jsm/shaders/CopyShader.js var CopyShader = { uniforms: { "tDiffuse": { value: null }, "opacity": { value: 1 } }, vertexShader: ` varying vec2 vUv; void main() { vUv = uv; gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 ); }`, fragmentShader: ` uniform float opacity; uniform sampler2D tDiffuse; varying vec2 vUv; void main() { gl_FragColor = texture2D( tDiffuse, vUv ); gl_FragColor.a *= opacity; }` }; // node_modules/three/examples/jsm/postprocessing/Pass.js var Pass = class { constructor() { 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."); } }; var _camera = new OrthographicCamera(-1, 1, 1, -1, 0, 1); var _geometry = new BufferGeometry(); _geometry.setAttribute("position", new Float32BufferAttribute([-1, 3, 0, -1, -1, 0, 3, -1, 0], 3)); _geometry.setAttribute("uv", new Float32BufferAttribute([0, 2, 0, 0, 2, 0], 2)); var FullScreenQuad = class { constructor(material) { this._mesh = new Mesh(_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 ShaderMaterial) { this.uniforms = shader.uniforms; this.material = shader; } else if (shader) { this.uniforms = UniformsUtils.clone(shader.uniforms); this.material = new ShaderMaterial({ 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); } } }; // 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.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; if (renderTarget === void 0) { const size = renderer3.getSize(new Vector2()); this._pixelRatio = renderer3.getPixelRatio(); this._width = size.width; this._height = size.height; renderTarget = new WebGLRenderTarget(this._width * this._pixelRatio, this._height * this._pixelRatio); renderTarget.texture.name = "EffectComposer.rt1"; } else { this._pixelRatio = 1; 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 = []; if (CopyShader === void 0) { console.error("THREE.EffectComposer relies on CopyShader"); } if (ShaderPass === void 0) { console.error("THREE.EffectComposer relies on ShaderPass"); } this.copyPass = new ShaderPass(CopyShader); 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, index5) { this.passes.splice(index5, 0, pass); pass.setSize(this._width * this._pixelRatio, this._height * this._pixelRatio); } removePass(pass) { const index5 = this.passes.indexOf(pass); if (index5 !== -1) { this.passes.splice(index5, 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 Vector2()); 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); } }; var _camera2 = new OrthographicCamera(-1, 1, 1, -1, 0, 1); var _geometry2 = new BufferGeometry(); _geometry2.setAttribute("position", new Float32BufferAttribute([-1, 3, 0, -1, -1, 0, 3, -1, 0], 3)); _geometry2.setAttribute("uv", new Float32BufferAttribute([0, 2, 0, 0, 2, 0], 2)); // node_modules/three/examples/jsm/postprocessing/RenderPass.js var RenderPass = class extends Pass { constructor(scene3, camera3, overrideMaterial, clearColor, clearAlpha) { super(); this.scene = scene3; this.camera = camera3; this.overrideMaterial = overrideMaterial; this.clearColor = clearColor; this.clearAlpha = clearAlpha !== void 0 ? clearAlpha : 0; this.clear = true; this.clearDepth = false; this.needsSwap = false; this._oldClearColor = new Color(); } render(renderer3, writeBuffer, readBuffer) { const oldAutoClear = renderer3.autoClear; renderer3.autoClear = false; let oldClearAlpha, oldOverrideMaterial; if (this.overrideMaterial !== void 0) { oldOverrideMaterial = this.scene.overrideMaterial; this.scene.overrideMaterial = this.overrideMaterial; } if (this.clearColor) { renderer3.getClearColor(this._oldClearColor); oldClearAlpha = renderer3.getClearAlpha(); renderer3.setClearColor(this.clearColor, this.clearAlpha); } if (this.clearDepth) { renderer3.clearDepth(); } renderer3.setRenderTarget(this.renderToScreen ? null : readBuffer); if (this.clear) renderer3.clear(renderer3.autoClearColor, renderer3.autoClearDepth, renderer3.autoClearStencil); renderer3.render(this.scene, this.camera); if (this.clearColor) { renderer3.setClearColor(this._oldClearColor, oldClearAlpha); } if (this.overrideMaterial !== void 0) { 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) { return Function.toString.call(fn).indexOf("[native code]") !== -1; } // 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 _cache = 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 _cache !== "undefined") { if (_cache.has(Class2)) return _cache.get(Class2); _cache.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 hslToRgb(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(" + hslToRgb(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(" + hslToRgb(_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 = { Linear: { None: function(amount) { return amount; } }, Quadratic: { 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: { 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: { 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: { 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: { In: function(amount) { return 1 - Math.cos(amount * Math.PI / 2); }, Out: function(amount) { return Math.sin(amount * Math.PI / 2); }, InOut: function(amount) { return 0.5 * (1 - Math.cos(Math.PI * amount)); } }, Exponential: { 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: { 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: { 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: { In: function(amount) { var s = 1.70158; return amount * amount * ((s + 1) * amount - s); }, Out: function(amount) { var s = 1.70158; return --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: { 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; } } }; var now3; if (typeof self === "undefined" && typeof process !== "undefined" && process.hrtime) { now3 = function() { var time = process.hrtime(); return time[0] * 1e3 + time[1] / 1e6; }; } else if (typeof self !== "undefined" && self.performance !== void 0 && self.performance.now !== void 0) { now3 = self.performance.now.bind(self.performance); } else if (Date.now !== void 0) { now3 = Date.now; } else { now3 = function() { return new Date().getTime(); }; } var now$1 = now3; var Group2 = function() { function Group3() { this._tweens = {}; this._tweensAddedDuringUpdate = {}; } Group3.prototype.getAll = function() { var _this = this; return Object.keys(this._tweens).map(function(tweenId) { return _this._tweens[tweenId]; }); }; Group3.prototype.removeAll = function() { this._tweens = {}; }; Group3.prototype.add = function(tween) { this._tweens[tween.getId()] = tween; this._tweensAddedDuringUpdate[tween.getId()] = tween; }; Group3.prototype.remove = function(tween) { delete this._tweens[tween.getId()]; delete this._tweensAddedDuringUpdate[tween.getId()]; }; Group3.prototype.update = function(time, preserve) { if (time === void 0) { time = now$1(); } 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 Group3; }(); 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 = function() { function Sequence2() { } Sequence2.nextId = function() { return Sequence2._nextId++; }; Sequence2._nextId = 0; return Sequence2; }(); var mainGroup = new Group2(); var Tween = 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._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._id = Sequence.nextId(); this._isChainStopped = 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(properties, duration) { this._valuesEnd = Object.create(properties); if (duration !== void 0) { this._duration = duration; } return this; }; Tween2.prototype.duration = function(d) { this._duration = d; return this; }; Tween2.prototype.start = function(time) { 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._isChainStopped = false; this._startTime = time !== void 0 ? typeof time === "string" ? now$1() + parseFloat(time) : time : now$1(); this._startTime += this._delayTime; this._setupProperties(this._object, this._valuesStart, this._valuesEnd, this._valuesStartRepeat); return this; }; Tween2.prototype._setupProperties = function(_object, _valuesStart, _valuesEnd, _valuesStartRepeat) { 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; } endValues = endValues.map(this._handleRelativeValue.bind(this, startValue)); _valuesEnd[property] = [startValue].concat(endValues); } if ((propType === "object" || startValueIsArray) && startValue && !isInterpolationList) { _valuesStart[property] = startValueIsArray ? [] : {}; for (var prop in startValue) { _valuesStart[property][prop] = startValue[prop]; } _valuesStartRepeat[property] = startValueIsArray ? [] : {}; this._setupProperties(startValue, _valuesStart[property], _valuesEnd[property], _valuesStartRepeat[property]); } else { if (typeof _valuesStart[property] === "undefined") { _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 = now$1(); } 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 = now$1(); } 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) { this._group = group; return this; }; Tween2.prototype.delay = function(amount) { this._delayTime = amount; return this; }; Tween2.prototype.repeat = function(times) { this._initialRepeat = times; this._repeat = times; return this; }; Tween2.prototype.repeatDelay = function(amount) { this._repeatDelayTime = amount; return this; }; Tween2.prototype.yoyo = function(yoyo) { this._yoyo = yoyo; return this; }; Tween2.prototype.easing = function(easingFunction) { this._easingFunction = easingFunction; return this; }; Tween2.prototype.interpolation = function(interpolationFunction) { 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.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 = now$1(); } 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); } this._goToEnd = false; if (time < this._startTime) { return true; } if (this._onStartCallbackFired === false) { if (this._onStartCallback) { this._onStartCallback(this._object); } this._onStartCallbackFired = 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] = 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); } 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); } 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); } else { 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 VERSION = "18.6.4"; 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); var exports = { Easing, Group: Group2, Interpolation, now: now$1, Sequence, nextId, Tween, VERSION, getAll, removeAll: removeAll4, add: add4, remove, update: update2 }; var tween_esm_default = exports; // node_modules/three-render-objects/dist/three-render-objects.module.js 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}\n\n.scene-container canvas:focus {\n outline: none;\n}"; styleInject(css_248z); function _defineProperty3(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _slicedToArray5(arr, i) { return _arrayWithHoles5(arr) || _iterableToArrayLimit5(arr, i) || _unsupportedIterableToArray5(arr, i) || _nonIterableRest5(); } function _toConsumableArray4(arr) { return _arrayWithoutHoles4(arr) || _iterableToArray4(arr) || _unsupportedIterableToArray5(arr) || _nonIterableSpread4(); } function _arrayWithoutHoles4(arr) { if (Array.isArray(arr)) return _arrayLikeToArray5(arr); } function _arrayWithHoles5(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 _iterableToArrayLimit5(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } 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 _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 _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."); } var three2 = window.THREE ? window.THREE : { WebGLRenderer, Scene, PerspectiveCamera, Raycaster, TextureLoader, Vector2, Vector3, Box3, Color, Mesh, SphereGeometry, MeshBasicMaterial, BackSide, EventDispatcher, MOUSE, Quaternion, Spherical, Clock }; var threeRenderObjects = index2({ 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": [] }, 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 }, hoverFilter: { "default": function _default9() { return true; }, triggerUpdate: false }, 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 ? accessor_fn_module_default(state.tooltipContent)(topObject) || "" : ""; state.hoverObj = topObject; } } tween_esm_default.update(); } return this; }, getPointerPos: function getPointerPos(state) { var _state$pointerPos = state.pointerPos, x2 = _state$pointerPos.x, y2 = _state$pointerPos.y; return { x: x2, y: y2 }; }, 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_esm_default.Tween(camPos).to(finalPos, transitionDuration).easing(tween_esm_default.Easing.Quadratic.Out).onUpdate(setCameraPos).start(); new tween_esm_default.Tween(camLookAt).to(finalLookAt, transitionDuration / 3).easing(tween_esm_default.Easing.Quadratic.Out).onUpdate(setLookAt).start(); } return this; } return Object.assign({}, camera3.position, { lookAt: getLookAt() }); function setCameraPos(pos) { var x2 = pos.x, y2 = pos.y, z2 = pos.z; if (x2 !== void 0) camera3.position.x = x2; if (y2 !== void 0) camera3.position.y = y2; if (z2 !== void 0) camera3.position.z = z2; } 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 = _slicedToArray5(_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, x2, y2, z2) { var vec = new three2.Vector3(x2, y2, z2); vec.project(this.camera()); return { 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, x2, y2) { var relCoords = new three2.Vector2(x2 / state.width * 2 - 1, -(y2 / 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; } }, 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(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 = 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) { 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("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.module.js 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(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 _objectSpread23(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; i % 2 ? ownKeys3(Object(source), true).forEach(function(key) { _defineProperty4(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys3(Object(source)).forEach(function(key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } function _defineProperty4(obj, key, value) { 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) || _unsupportedIterableToArray6(arr) || _nonIterableSpread5(); } function _arrayWithoutHoles5(arr) { if (Array.isArray(arr)) return _arrayLikeToArray6(arr); } function _iterableToArray5(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 _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 linkKapsule(kapsulePropName, kapsuleType) { var dummyK = new kapsuleType(); 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(["cameraPosition", "postProcessingComposer"].map(function(p) { return _defineProperty4({}, p, bindRenderObjs.linkMethod(p)); })).concat([{ graph2ScreenCoords: bindRenderObjs.linkMethod("getScreenCoords"), screen2GraphCoords: bindRenderObjs.linkMethod("getSceneCoords") }])); var _3dForceGraph = index2({ 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; } }, 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(); }, camera: function camera2(state) { return state.renderObjs.camera(); }, renderer: function renderer2(state) { return state.renderObjs.renderer(); }, controls: function controls2(state) { return state.renderObjs.controls(); }, tbControls: function tbControls2(state) { return state.renderObjs.tbControls(); }, _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; return { forceGraph: new threeForcegraph(), renderObjs: threeRenderObjects({ controlType, rendererConfig, extraRenderers }) }; }, 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(new PointerEvent("pointerup", { pointerType: "touch" })); } renderer3.domElement.classList.remove("grabbable"); }); } }); state.renderObjs.objects([ new three3.AmbientLight(12303291), new three3.DirectionalLight(16777215, 0.6), state.forceGraph ]).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 ? accessor_fn_module_default(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/settings/categories/GroupSettings.ts var GroupSettings = class { constructor(groups) { this.groups = []; this.groups = groups || this.groups; } }; var NodeGroup = class { constructor(query, color) { this.query = query; this.color = color; } static getRegex(query) { return new RegExp(query); } static matches(query, node) { return node.path.startsWith(this.sanitizeQuery(query)); } static sanitizeQuery(query) { const trimmedQuery = query.trim(); if (trimmedQuery.startsWith("./")) return trimmedQuery.slice(1); else return trimmedQuery; } }; // src/util/EventBus.ts var import_obsidian = require("obsidian"); var EventBus = class extends import_obsidian.Events { constructor() { super(); } }; var EventBus_default = new EventBus(); // src/views/graph/ForceGraph.ts var ForceGraph2 = class { constructor(rootHtmlElement, isLocalGraph) { this.highlightedNodes = /* @__PURE__ */ new Set(); this.highlightedLinks = /* @__PURE__ */ new Set(); this.getGraphData = () => { if (this.isLocalGraph && Graph3dPlugin.openFileState.value) { this.graph = Graph3dPlugin.globalGraph.clone().getLocalGraph(Graph3dPlugin.openFileState.value); } else { this.graph = Graph3dPlugin.globalGraph.clone(); } return this.graph; }; this.refreshGraphData = () => { this.instance.graphData(this.getGraphData()); }; this.onSettingsStateChanged = (data) => { if (data.currentPath === "display.nodeSize") { this.instance.nodeRelSize(data.newValue); } else if (data.currentPath === "display.linkWidth") { this.instance.linkWidth(data.newValue); } else if (data.currentPath === "display.particleSize") { this.instance.linkDirectionalParticleWidth(Graph3dPlugin.getSettings().display.particleSize); } this.instance.refresh(); }; this.createNodes = () => { this.instance.nodeColor((node) => this.getNodeColor(node)).nodeVisibility(this.doShowNode).onNodeHover(this.onNodeHover); }; this.getNodeColor = (node) => { if (this.isHighlightedNode(node)) { return node === this.hoveredNode ? Graph3dPlugin.theme.interactiveAccentHover : Graph3dPlugin.theme.interactiveAccent; } else { let color = Graph3dPlugin.theme.textMuted; Graph3dPlugin.getSettings().groups.groups.forEach((group) => { if (NodeGroup.matches(group.query, node)) color = group.color; }); return color; } }; this.doShowNode = (node) => { return Graph3dPlugin.getSettings().filters.doShowOrphans || node.links.length > 0; }; this.onNodeHover = (node) => { if (!node && !this.highlightedNodes.size || node && this.hoveredNode === node) return; this.clearHighlights(); if (node) { this.highlightedNodes.add(node.id); node.neighbors.forEach((neighbor) => this.highlightedNodes.add(neighbor.id)); const nodeLinks = this.graph.getLinksWithNode(node.id); if (nodeLinks) nodeLinks.forEach((link) => this.highlightedLinks.add(link)); } this.hoveredNode = node || null; this.updateHighlight(); }; this.isHighlightedLink = (link) => { return this.highlightedLinks.has(link); }; this.isHighlightedNode = (node) => { return this.highlightedNodes.has(node.id); }; this.createLinks = () => { this.instance.linkWidth((link) => this.isHighlightedLink(link) ? Graph3dPlugin.getSettings().display.linkThickness * 1.5 : Graph3dPlugin.getSettings().display.linkThickness).linkDirectionalParticles((link) => this.isHighlightedLink(link) ? Graph3dPlugin.getSettings().display.particleCount : 0).linkDirectionalParticleWidth(Graph3dPlugin.getSettings().display.particleSize).onLinkHover(this.onLinkHover).linkColor((link) => this.isHighlightedLink(link) ? Graph3dPlugin.theme.interactiveAccent : Graph3dPlugin.theme.textMuted); }; this.onLinkHover = (link) => { this.clearHighlights(); if (link) { this.highlightedLinks.add(link); this.highlightedNodes.add(link.source); this.highlightedNodes.add(link.target); } this.updateHighlight(); }; this.clearHighlights = () => { this.highlightedNodes.clear(); this.highlightedLinks.clear(); }; this.rootHtmlElement = rootHtmlElement; this.isLocalGraph = isLocalGraph; this.createGraph(); this.initListeners(); } initListeners() { Graph3dPlugin.settingsState.onChange(this.onSettingsStateChanged); if (this.isLocalGraph) Graph3dPlugin.openFileState.onChange(this.refreshGraphData); EventBus_default.on("graph-changed", this.refreshGraphData); } createGraph() { this.createInstance(); this.createNodes(); this.createLinks(); } createInstance() { const [width, height] = [ this.rootHtmlElement.innerWidth, this.rootHtmlElement.innerHeight ]; this.instance = _3dForceGraph()(this.rootHtmlElement).graphData(this.getGraphData()).nodeLabel((node) => `
${node.name}
`).nodeRelSize(Graph3dPlugin.getSettings().display.nodeSize).backgroundColor(rgba(0, 0, 0, 0)).width(width).height(height); } update_dimensions() { const [width, height] = [ this.rootHtmlElement.offsetWidth, this.rootHtmlElement.offsetHeight ]; this.set_dimensions(width, height); } set_dimensions(width, height) { this.instance.width(width); this.instance.height(height); } updateHighlight() { this.instance.nodeColor(this.instance.nodeColor()).linkColor(this.instance.linkColor()).linkDirectionalParticles(this.instance.linkDirectionalParticles()); } getInstance() { return this.instance; } }; // src/views/atomics/TreeItem.ts var TreeItem = class extends HTMLDivElement { constructor($inner, children) { super(); this.appendSelf = () => { ["graph-control-section", "tree-item"].forEach((className) => this.classList.add(className)); const $self = createDiv({ cls: "tree-item-self" }); $self.addEventListener("click", () => { this.toggleCollapse(); }); const $inner = createDiv({ cls: "tree-item-inner" }); $inner.append(this.$inner); $self.append($inner); this.append($self); }; this.appendChildren = () => { const $children = createDiv({ cls: "tree-item-children" }); this.childrenBuilders.forEach((build) => build($children)); this.append($children); }; this.toggleCollapse = (doCollapse) => { if (doCollapse === void 0) { doCollapse = !this.classList.contains("is-collapsed"); } this.classList.toggle("is-collapsed", doCollapse); }; this.$inner = $inner; this.childrenBuilders = children; } async connectedCallback() { this.appendSelf(); this.appendChildren(); } }; try { if (customElements.get("tree-item") === void 0) { customElements.define("tree-item", TreeItem, { extends: "div" }); } } catch (e) { } // src/views/atomics/SimpleSliderSetting.ts var import_obsidian2 = require("obsidian"); var SimpleSliderSetting = (containerEl, options, onChange13) => { const slider = new import_obsidian2.Setting(containerEl).setName(options.name).setClass("mod-slider").addSlider((slider2) => { slider2.setLimits(options.stepOptions.min, options.stepOptions.max, options.stepOptions.step).setValue(options.value).onChange(async (value) => { onChange13(value); }); }); return slider; }; var DEFAULT_SLIDER_STEP_OPTIONS = { min: 1, max: 20, step: 1 }; var SimpleSliderSetting_default = SimpleSliderSetting; // src/views/settings/categories/DisplaySettingsView.ts var DisplaySettingsView = (displaySettings, containerEl) => { NodeSizeSetting(displaySettings, containerEl); LinkThicknessSetting(displaySettings, containerEl); ParticleSizeSetting(displaySettings, containerEl); ParticleCountSetting(displaySettings, containerEl); }; var NodeSizeSetting = (displaySettings, containerEl) => { const options = { name: "Node Size", value: displaySettings.value.nodeSize, stepOptions: DEFAULT_SLIDER_STEP_OPTIONS }; return SimpleSliderSetting_default(containerEl, options, (value) => { displaySettings.value.nodeSize = value; }); }; var LinkThicknessSetting = (displaySettings, containerEl) => { const options = { name: "Link Thickness", value: displaySettings.value.linkThickness, stepOptions: DEFAULT_SLIDER_STEP_OPTIONS }; return SimpleSliderSetting_default(containerEl, options, (value) => { displaySettings.value.linkThickness = value; }); }; var ParticleSizeSetting = (displaySettings, containerEl) => { const options = { name: "Particle Size", value: displaySettings.value.particleSize, stepOptions: DEFAULT_SLIDER_STEP_OPTIONS }; return SimpleSliderSetting_default(containerEl, options, (value) => { displaySettings.value.particleSize = value; }); }; var ParticleCountSetting = (displaySettings, containerEl) => { const options = { name: "Particle Count", value: displaySettings.value.particleCount, stepOptions: DEFAULT_SLIDER_STEP_OPTIONS }; return SimpleSliderSetting_default(containerEl, options, (value) => { displaySettings.value.particleCount = value; }); }; var DisplaySettingsView_default = DisplaySettingsView; // src/settings/categories/FilterSettings.ts var FilterSettings = class { constructor(doShowOrphans) { this.doShowOrphans = true; this.doShowOrphans = doShowOrphans || this.doShowOrphans; } }; // src/settings/categories/DisplaySettings.ts var DisplaySettings = class { constructor(nodeSize, linkThickness, particleSize, particleCount) { this.nodeSize = 4; this.linkThickness = 5; this.particleSize = 6; this.particleCount = 4; this.nodeSize = nodeSize || this.nodeSize; this.linkThickness = linkThickness || this.linkThickness; this.particleSize = particleSize || this.particleSize; this.particleCount = particleCount || this.particleCount; } }; // src/views/settings/GraphSettingsView.ts var import_obsidian5 = 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, proxy: this.val.__getProxy, previousValue, newValue: this.val } ]); } createSubState(key, type) { const subStateKeys = key.split("."), 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") { if (subStateValue instanceof type) { return new _State(subStateValue.__getTarget); } else { throw new Error(`Substate ${key} of state ${this.id} is not of type ${type.name}`); } } else throw new Error("SubStates of properties that are Primitives are not supported yet."); } 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/views/settings/categories/GroupSettingsView.ts var import_obsidian3 = require("obsidian"); // src/views/atomics/ColorPicker.ts var ColorPicker = (containerEl, value, onChange13) => { const input = document.createElement("input"); input.type = "color"; input.value = value; input.addEventListener("change", () => { onChange13(input.value); }); containerEl.appendChild(input); }; var ColorPicker_default = ColorPicker; // src/views/settings/categories/GroupSettingsView.ts var GroupSettingsView = (groupSettings, containerEl) => { NodeGroups(groupSettings, containerEl); AddNodeGroupButton(groupSettings, containerEl); groupSettings.onChange((change) => { if (change.currentPath === "groups" && change.type === "add" || change.type === "delete") { containerEl.empty(); NodeGroups(groupSettings, containerEl); AddNodeGroupButton(groupSettings, containerEl); } }); }; var NodeGroups = (groupSettings, containerEl) => { var _a; (_a = containerEl.querySelector(".node-group-container")) == null ? void 0 : _a.remove(); const nodeGroupContainerEl = containerEl.createDiv({ cls: "graph-color-groups-container" }); groupSettings.value.groups.forEach((group, index5) => { const groupState = groupSettings.createSubState(`value.groups.${index5}`, NodeGroup); GroupSettingItem(groupState, nodeGroupContainerEl, () => { groupSettings.value.groups.splice(index5, 1); }); }); }; var AddNodeGroupButton = (groupSettings, containerEl) => { var _a; (_a = containerEl.querySelector(".graph-color-button-container")) == null ? void 0 : _a.remove(); const buttonContainer = containerEl.createDiv({ cls: "graph-color-button-container" }); new import_obsidian3.ButtonComponent(buttonContainer).setClass("mod-cta").setButtonText("Add Group").onClick(() => { groupSettings.value.groups.push(new NodeGroup("", Graph3dPlugin.theme.textMuted)); containerEl.empty(); GroupSettingsView(groupSettings, containerEl); }); }; var GroupSettingItem = (group, containerEl, onDelete) => { const groupEl = containerEl.createDiv({ cls: "graph-color-group" }); new import_obsidian3.TextComponent(groupEl).setValue(group.value.query).onChange((value) => { group.value.query = value; }); ColorPicker_default(groupEl, group.value.color, (value) => { group.value.color = value; }); new import_obsidian3.ExtraButtonComponent(groupEl).setIcon("cross").setTooltip("Delete Group").onClick(onDelete); }; var GroupSettingsView_default = GroupSettingsView; // src/views/settings/categories/FilterSettingsView.ts var import_obsidian4 = require("obsidian"); var FilterSettingsView = (filterSettings, containerEl) => { new import_obsidian4.Setting(containerEl).setName("Show Orphans").addToggle((toggle) => { toggle.setValue(filterSettings.value.doShowOrphans || false).onChange(async (value) => { filterSettings.value.doShowOrphans = value; }); }); }; var FilterSettingsView_default = FilterSettingsView; // src/views/settings/GraphSettingsView.ts var GraphSettingsView = class extends HTMLDivElement { constructor() { super(...arguments); this.isCollapsedState = new State(true); this.callbackUnregisterHandles = []; this.onIsCollapsedChanged = (stateChange) => { const collapsed = stateChange.newValue; this.toggleCollapsed(collapsed); }; this.onSettingsButtonClicked = () => { this.isCollapsedState.value = !this.isCollapsedState.value; }; } async connectedCallback() { this.classList.add("graph-settings-view"); this.settingsButton = new import_obsidian5.ExtraButtonComponent(this).setIcon("settings").setTooltip("Open graph settings").onClick(this.onSettingsButtonClicked); this.graphControls = this.createDiv({ cls: "graph-controls" }); this.appendGraphControlsItems(this.graphControls.createDiv({ cls: "control-buttons" })); this.appendSetting(Graph3dPlugin.settingsState.createSubState("value.filters", FilterSettings), "Filters", FilterSettingsView_default); this.appendSetting(Graph3dPlugin.settingsState.createSubState("value.groups", GroupSettings), "Groups", GroupSettingsView_default); this.appendSetting(Graph3dPlugin.settingsState.createSubState("value.display", DisplaySettings), "Display", DisplaySettingsView_default); this.initListeners(); this.toggleCollapsed(this.isCollapsedState.value); } initListeners() { EventBus_default.on("did-reset-settings", () => { this.disconnectedCallback(); this.connectedCallback(); }); this.callbackUnregisterHandles.push(this.isCollapsedState.onChange(this.onIsCollapsedChanged)); } toggleCollapsed(collapsed) { if (collapsed) { this.settingsButton.setDisabled(false); this.graphControls.classList.add("hidden"); } else { this.settingsButton.setDisabled(true); this.graphControls.classList.remove("hidden"); } } appendGraphControlsItems(containerEl) { this.appendResetButton(containerEl); this.appendMinimizeButton(containerEl); } appendResetButton(containerEl) { new import_obsidian5.ExtraButtonComponent(containerEl).setIcon("eraser").setTooltip("Reset to default").onClick(() => EventBus_default.trigger("do-reset-settings")); } appendMinimizeButton(containerEl) { new import_obsidian5.ExtraButtonComponent(containerEl).setIcon("x").setTooltip("Close").onClick(() => this.isCollapsedState.value = true); } appendSetting(setting, title, view) { const header = document.createElement("header"); header.classList.add("graph-control-section-header"); header.innerHTML = title; const item = new TreeItem(header, [ (containerEl) => view(setting, containerEl) ]); item.classList.add("is-collapsed"); this.graphControls.append(item); } async disconnectedCallback() { this.empty(); this.callbackUnregisterHandles.forEach((handle) => handle()); } }; try { if (customElements.get("graph-settings-view") == null) { customElements.define("graph-settings-view", GraphSettingsView, { extends: "div" }); } } catch (e) { } // src/views/graph/Graph3dView.ts var Graph3dView = class extends import_obsidian6.ItemView { constructor(leaf, isLocalGraph = false) { super(leaf); this.isLocalGraph = isLocalGraph; } onload() { super.onload(); const viewContent = this.getViewContent(); if (viewContent) { viewContent.classList.add("graph-3d-view"); this.appendGraph(viewContent); const settings = new GraphSettingsView(); viewContent.appendChild(settings); } else { console.error("Could not find view content"); } } onunload() { super.onunload(); console.log("Unloading 3D Graph"); this.forceGraph.getInstance()._destructor(); } getDisplayText() { return "3D-Graph"; } getViewType() { return "3d_graph_view"; } onResize() { super.onResize(); const viewContent = this.getViewContent(); if (viewContent) { this.forceGraph.update_dimensions(); } } getViewContent() { return this.containerEl.querySelector(".view-content"); } appendGraph(viewContent) { this.forceGraph = new ForceGraph2(viewContent, this.isLocalGraph); this.forceGraph.getInstance().onNodeClick((node, mouseEvent) => { const clickedNodeFile = this.app.vault.getFiles().find((f) => f.path === node.path); if (clickedNodeFile) { if (this.isLocalGraph) { this.app.workspace.getLeaf(false).openFile(clickedNodeFile); } else { this.leaf.openFile(clickedNodeFile); } } }); } }; // src/settings/GraphSettings.ts var GraphSettings = class { constructor(filterOptions, groupOptions, displayOptions) { this.filters = filterOptions; this.groups = groupOptions; this.display = displayOptions; } reset() { this.filters = new FilterSettings(); this.groups = new GroupSettings(); this.display = new DisplaySettings(); } }; var DEFAULT_SETTINGS = () => new GraphSettings(new FilterSettings(), new GroupSettings(), new DisplaySettings()); // src/graph/Link.ts var Link = class { constructor(sourceId, targetId) { this.source = sourceId; this.target = targetId; } static createLinkIndex(links) { const linkIndex = /* @__PURE__ */ new Map(); links.forEach((link, index5) => { var _a; if (!linkIndex.has(link.source)) { linkIndex.set(link.source, /* @__PURE__ */ new Map()); } (_a = linkIndex.get(link.source)) == null ? void 0 : _a.set(link.target, index5); }); return linkIndex; } static createFromCache(cache, nodes, nodeIndex) { const links = Object.keys(cache).map((node1Id) => { return Object.keys(cache[node1Id]).map((node2Id) => { const [node1Index, node2Index] = [ nodeIndex.get(node1Id), nodeIndex.get(node2Id) ]; if (node1Index !== void 0 && node2Index !== void 0) { return nodes[node1Index].addNeighbor(nodes[node2Index]); } return null; }).flat(); }).flat().filter((link, index5, self2) => link && link.source !== link.target && index5 === self2.findIndex((l) => l && l.source === link.source && l.target === link.target)); return [links, Link.createLinkIndex(links)]; } }; // 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; } static createFromFiles(files) { const nodeMap = /* @__PURE__ */ new Map(); return [ files.map((file, index5) => { const node = new Node(file.name, file.path); if (!nodeMap.has(node.id)) { nodeMap.set(node.id, index5); return node; } return null; }).filter((node) => node !== null), nodeMap ]; } addNeighbor(neighbor) { if (!this.isNeighborOf(neighbor)) { const link = new Link(this.id, neighbor.id); this.neighbors.push(neighbor); this.addLink(link); neighbor.neighbors.push(this); neighbor.addLink(link); return link; } return null; } addLink(link) { if (!this.links.some((l) => l.source === link.source && l.target === link.target)) { this.links.push(link); } } isNeighborOf(node) { if (node instanceof Node) return this.neighbors.includes(node); else return this.neighbors.some((neighbor) => neighbor.id === node); } }; // src/graph/Graph.ts var _Graph = class { constructor(nodes, links, nodeIndex, linkIndex) { this.clone = () => { return new _Graph(structuredClone(this.nodes), structuredClone(this.links), structuredClone(this.nodeIndex), structuredClone(this.linkIndex)); }; this.update = (app) => { const newGraph = _Graph.createFromApp(app); this.nodes.splice(0, this.nodes.length, ...newGraph.nodes); this.links.splice(0, this.nodes.length, ...newGraph.links); this.nodeIndex.clear(); newGraph.nodeIndex.forEach((value, key) => { this.nodeIndex.set(key, value); }); this.linkIndex.clear(); newGraph.linkIndex.forEach((value, key) => { this.linkIndex.set(key, value); }); }; this.nodes = nodes; this.links = links; this.nodeIndex = nodeIndex || /* @__PURE__ */ new Map(); this.linkIndex = linkIndex || /* @__PURE__ */ new Map(); } getNodeById(id) { const index5 = this.nodeIndex.get(id); if (index5 !== void 0) { return this.nodes[index5]; } return null; } getLinkByIds(sourceNodeId, targetNodeId) { const sourceLinkMap = this.linkIndex.get(sourceNodeId); if (sourceLinkMap) { const index5 = sourceLinkMap.get(targetNodeId); if (index5 !== void 0) { return this.links[index5]; } } return null; } getLinksFromNode(sourceNodeId) { const sourceLinkMap = this.linkIndex.get(sourceNodeId); if (sourceLinkMap) { return Array.from(sourceLinkMap.values()).map((index5) => this.links[index5]); } return []; } getLinksWithNode(nodeId) { var _a, _b; if ((_b = (_a = this.links[0]) == null ? void 0 : _a.source) == null ? void 0 : _b.id) { return this.links.filter((link) => link.source.id === nodeId || link.target.id === nodeId); } else { return this.links.filter((link) => link.source === nodeId || link.target === nodeId); } } getLocalGraph(nodeId) { const node = this.getNodeById(nodeId); if (node) { const nodes = [node, ...node.neighbors]; const links = []; const nodeIndex = /* @__PURE__ */ new Map(); nodes.forEach((node2, index5) => { nodeIndex.set(node2.id, index5); }); nodes.forEach((node2, index5) => { const filteredLinks = node2.links.filter((link) => nodeIndex.has(link.target) && nodeIndex.has(link.source)).map((link) => { if (!links.includes(link) && nodeIndex.has(link.target) && nodeIndex.has(link.source)) links.push(link); return link; }); node2.links.splice(0, node2.links.length, ...filteredLinks); }); const linkIndex = Link.createLinkIndex(links); return new _Graph(nodes, links, nodeIndex, linkIndex); } else { return new _Graph([], [], /* @__PURE__ */ new Map(), /* @__PURE__ */ new Map()); } } }; var Graph = _Graph; Graph.createFromApp = (app) => { const [nodes, nodeIndex] = Node.createFromFiles(app.vault.getFiles()), [links, linkIndex] = Link.createFromCache(app.metadataCache.resolvedLinks, nodes, nodeIndex); return new _Graph(nodes, links, nodeIndex, linkIndex); }; // src/util/ObsidianTheme.ts var ObsidianTheme = class { constructor(root) { this.backgroundPrimary = getComputedStyle(root).getPropertyValue("--background-primary").trim(); this.backgroundPrimaryAlt = getComputedStyle(root).getPropertyValue("--background-primary-alt").trim(); this.backgroundSecondary = getComputedStyle(root).getPropertyValue("--background-secondary").trim(); this.backgroundSecondaryAlt = getComputedStyle(root).getPropertyValue("--background-secondary-alt").trim(); this.backgroundModifierBorder = getComputedStyle(root).getPropertyValue("--background-modifier-border").trim(); this.backgroundModifierSuccess = getComputedStyle(root).getPropertyValue("--background-modifier-success").trim(); this.backgroundModifierError = getComputedStyle(root).getPropertyValue("--background-modifier-error").trim(); this.textAccent = getComputedStyle(root).getPropertyValue("--text-accent").trim(); this.textAccentHover = getComputedStyle(root).getPropertyValue("--text-accent-hover").trim(); this.textNormal = getComputedStyle(root).getPropertyValue("--text-normal").trim(); this.textMuted = getComputedStyle(root).getPropertyValue("--text-muted").trim(); this.textFaint = getComputedStyle(root).getPropertyValue("--text-faint").trim(); this.interactiveAccent = getComputedStyle(root).getPropertyValue("--interactive-accent").trim(); this.interactiveAccentHover = getComputedStyle(root).getPropertyValue("--interactive-accent-hover").trim(); } }; // src/util/ShallowCompare.ts var shallowCompare = (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) => obj2.hasOwnProperty(key) && shallowCompare(obj1[key], obj2[key])); } else return obj1 == obj2; }; var ShallowCompare_default = shallowCompare; // src/main.ts var _Graph3dPlugin = class extends import_obsidian7.Plugin { constructor() { super(...arguments); this.callbackUnregisterHandles = []; this.onGraphCacheReady = () => { _Graph3dPlugin.cacheIsReady.value = true; this.onGraphCacheChanged(); }; this.onGraphCacheChanged = () => { if (_Graph3dPlugin.cacheIsReady.value && !ShallowCompare_default(this._resolvedCache, this.app.metadataCache.resolvedLinks)) { this._resolvedCache = structuredClone(this.app.metadataCache.resolvedLinks); _Graph3dPlugin.globalGraph = Graph.createFromApp(this.app); } }; this.onDoResetSettings = () => { _Graph3dPlugin.settingsState.value.reset(); EventBus_default.trigger("did-reset-settings"); }; this.openLocalGraph = () => { var _a; const newFilePath = (_a = this.app.workspace.getActiveFile()) == null ? void 0 : _a.path; if (newFilePath) { _Graph3dPlugin.openFileState.value = newFilePath; this.openGraph(true); } else { new import_obsidian7.Notice("No file is currently open"); } }; this.openGlobalGraph = () => { this.openGraph(false); }; this.openGraph = (isLocalGraph) => { const leaf = this.app.workspace.getLeaf(isLocalGraph); if (_Graph3dPlugin.cacheIsReady.value) { leaf == null ? void 0 : leaf.open(new Graph3dView(leaf, isLocalGraph)); } else { _Graph3dPlugin.queuedGraphs.push([leaf, isLocalGraph]); } }; } async onload() { await this.init(); this.addRibbonIcon("glasses", "3D Graph", 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 }); } async init() { await this.loadSettings(); this.initStates(); this.initListeners(); } initStates() { _Graph3dPlugin.settingsState = new State(this.settings); _Graph3dPlugin.theme = new ObsidianTheme(this.app.workspace.containerEl); _Graph3dPlugin.app = this.app; } initListeners() { this.callbackUnregisterHandles.push(_Graph3dPlugin.settingsState.onChange(() => this.saveSettings())); EventBus_default.on("do-reset-settings", this.onDoResetSettings); this.registerEvent(this.app.workspace.on("file-menu", (menu, file) => { if (!file) return; menu.addItem((item) => { item.setTitle("Open in local 3D Graph").setIcon("glasses").onClick(() => this.openLocalGraph()); }); })); this.registerEvent(this.app.workspace.on("file-open", (file) => { if (file) _Graph3dPlugin.openFileState.value = file.path; })); this.callbackUnregisterHandles.push(_Graph3dPlugin.cacheIsReady.onChange((isReady) => { if (isReady) { this.openQueuedGraphs(); } })); this.app.metadataCache.on("resolved", this.onGraphCacheReady); this.app.metadataCache.on("resolve", this.onGraphCacheChanged); } openQueuedGraphs() { _Graph3dPlugin.queuedGraphs.forEach(([leaf, isLocalGraph]) => { leaf == null ? void 0 : leaf.open(new Graph3dView(leaf, isLocalGraph)); }); _Graph3dPlugin.queuedGraphs = []; } async loadSettings() { var _a; const loadedData = await this.loadData(), defaultSettings = DEFAULT_SETTINGS(); if (loadedData == null ? void 0 : loadedData.display) { Object.assign(defaultSettings.display, loadedData.display); } if (loadedData == null ? void 0 : loadedData.filters) { Object.assign(defaultSettings.filters, loadedData.filters); } if ((_a = loadedData == null ? void 0 : loadedData.groups) == null ? void 0 : _a.groups) { defaultSettings.groups.groups = loadedData.groups.groups.map((groupObj) => Object.assign(new NodeGroup("", ""), groupObj)); } this.settings = defaultSettings; } async saveSettings() { await this.saveData(this.settings); } onunload() { super.onunload(); this.callbackUnregisterHandles.forEach((handle) => handle()); EventBus_default.off("do-reset-settings", this.onDoResetSettings); } static getSettings() { return _Graph3dPlugin.settingsState.value; } }; var Graph3dPlugin = _Graph3dPlugin; Graph3dPlugin.openFileState = new State(void 0); Graph3dPlugin.cacheIsReady = new State(false); Graph3dPlugin.queuedGraphs = []; /** * @license * Copyright 2010-2022 Three.js Authors * SPDX-License-Identifier: MIT */